Merge pull request #5769 from Mailaender/actor-lint

Added a new OpenRA.Lint check for invalid actor definitions
This commit is contained in:
Paul Chote
2014-06-28 22:00:40 +12:00
6 changed files with 41 additions and 96 deletions

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Lint
{ {
static int errors = 0; static int errors = 0;
// mimic Windows compiler error format
static void EmitError(string e) static void EmitError(string e)
{ {
Console.WriteLine("OpenRA.Lint(1,1): Error: {0}", e); Console.WriteLine("OpenRA.Lint(1,1): Error: {0}", e);
@@ -67,17 +68,9 @@ namespace OpenRA.Lint
maps = new[] { new Map(map) }; maps = new[] { new Map(map) };
foreach (var testMap in maps) foreach (var testMap in maps)
{
if (testMap.RuleDefinitions.Count < 1)
{ {
if (verbose) if (verbose)
Console.WriteLine("No custom rules detected. Omitting Map: {0}".F(testMap.Title)); Console.WriteLine("Testing map: {0}".F(testMap.Title));
continue;
}
if (verbose)
Console.WriteLine("Map: {0}".F(testMap.Title));
testMap.PreloadRules(); testMap.PreloadRules();
foreach (var customPassType in Game.modData.ObjectCreator foreach (var customPassType in Game.modData.ObjectCreator
@@ -88,14 +81,11 @@ namespace OpenRA.Lint
var customPass = (ILintPass)Game.modData.ObjectCreator var customPass = (ILintPass)Game.modData.ObjectCreator
.CreateBasic(customPassType); .CreateBasic(customPassType);
if (verbose)
Console.WriteLine("Pass: {0}".F(customPassType.ToString()));
customPass.Run(EmitError, EmitWarning, testMap); customPass.Run(EmitError, EmitWarning, testMap);
} }
catch (Exception e) catch (Exception e)
{ {
EmitError("Failed with exception: {0}".F(e)); EmitError("{0} failed with exception: {0}".F(customPassType, e));
} }
} }
} }

View File

@@ -0,0 +1,28 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class CheckActors : ILintPass
{
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
{
var actorTypes = map.Actors.Value.Values.Select(a => a.Type);
foreach (var actor in actorTypes)
if (!map.Rules.Actors.Keys.Contains(actor.ToLowerInvariant()))
emitError("Actor {0} is not defined by any rule.".F(actor));
}
}
}

View File

@@ -518,6 +518,7 @@
<Compile Include="Activities\MoveWithinRange.cs" /> <Compile Include="Activities\MoveWithinRange.cs" />
<Compile Include="Lint\CheckPlayers.cs" /> <Compile Include="Lint\CheckPlayers.cs" />
<Compile Include="Player\ProvidesCustomPrerequisite.cs" /> <Compile Include="Player\ProvidesCustomPrerequisite.cs" />
<Compile Include="Lint\CheckActors.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj"> <ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -439,7 +439,7 @@ Actors:
Actor167: powr Actor167: powr
Location: 54,74 Location: 54,74
Owner: Allies Owner: Allies
Actor39: pbox.e1 Actor39: pbox
Location: 70,89 Location: 70,89
Owner: Allies Owner: Allies
AlliedTechnologyCenter: miss AlliedTechnologyCenter: miss
@@ -452,10 +452,10 @@ Actors:
Actor150: apwr Actor150: apwr
Location: 94,90 Location: 94,90
Owner: Allies Owner: Allies
Actor35: pbox.e1 Actor35: pbox
Location: 68,85 Location: 68,85
Owner: Allies Owner: Allies
Actor178: pbox.e1 Actor178: pbox
Location: 77,76 Location: 77,76
Owner: Allies Owner: Allies
Actor300: brik Actor300: brik
@@ -495,7 +495,7 @@ Actors:
AlliedWarFactory1: weap AlliedWarFactory1: weap
Location: 75,81 Location: 75,81
Owner: Allies Owner: Allies
Actor156: pbox.e1 Actor156: pbox
Location: 52,71 Location: 52,71
Owner: Allies Owner: Allies
Actor343: brik Actor343: brik
@@ -628,10 +628,10 @@ Actors:
Location: 82,69 Location: 82,69
Owner: Allies Owner: Allies
Facing: 0 Facing: 0
Actor30: pbox.e1 Actor30: pbox
Location: 47,77 Location: 47,77
Owner: Allies Owner: Allies
Actor29: pbox.e1 Actor29: pbox
Location: 42,75 Location: 42,75
Owner: Allies Owner: Allies
Actor217: sbag Actor217: sbag
@@ -1001,7 +1001,7 @@ Actors:
Actor212: brik Actor212: brik
Location: 61,80 Location: 61,80
Owner: Allies Owner: Allies
Actor361: pbox.e1 Actor361: pbox
Location: 71,96 Location: 71,96
Owner: Allies Owner: Allies
Actor365: hpad Actor365: hpad
@@ -1016,7 +1016,7 @@ Actors:
Actor193: fix Actor193: fix
Location: 69,70 Location: 69,70
Owner: Allies Owner: Allies
Actor42: pbox.e1 Actor42: pbox
Location: 67,70 Location: 67,70
Owner: Allies Owner: Allies
Actor262: fenc Actor262: fenc
@@ -1217,7 +1217,7 @@ Actors:
LstUnload: waypoint LstUnload: waypoint
Location: 60,93 Location: 60,93
Owner: Neutral Owner: Neutral
Actor184: pbox.e1 Actor184: pbox
Location: 96,79 Location: 96,79
Owner: Allies Owner: Allies
Paradrop1: waypoint Paradrop1: waypoint

View File

@@ -459,43 +459,6 @@ PBOX:
FallbackRange: 6c0 FallbackRange: 6c0
AutoTarget: AutoTarget:
# Legacy definitions to keep compatibility with outdated maps
PBOX.E1:
Inherits: PBOX
-Buildable:
RenderBuilding:
Image: PBOX
PBOX.E3:
Inherits: PBOX
-Buildable:
RenderBuilding:
Image: PBOX
PBOX.E4:
Inherits: PBOX
-Buildable:
RenderBuilding:
Image: PBOX
PBOX.E7:
Inherits: PBOX
-Buildable:
RenderBuilding:
Image: PBOX
PBOX.SHOK:
Inherits: PBOX
-Buildable:
RenderBuilding:
Image: PBOX
PBOX.SNIPER:
Inherits: PBOX
-Buildable:
RenderBuilding:
Image: PBOX
HBOX: HBOX:
Inherits: ^Building Inherits: ^Building
Tooltip: Tooltip:
@@ -545,43 +508,6 @@ HBOX:
PortYaws: 0, 176, 341, 512, 682, 853 PortYaws: 0, 176, 341, 512, 682, 853
PortCones: 86, 86, 86, 86, 86, 86 PortCones: 86, 86, 86, 86, 86, 86
# Legacy definitions to keep compatibility with outdated maps
HBOX.E1:
Inherits: HBOX
-Buildable:
RenderBuilding:
Image: HBOX
HBOX.E3:
Inherits: HBOX
-Buildable:
RenderBuilding:
Image: HBOX
HBOX.E4:
Inherits: HBOX
-Buildable:
RenderBuilding:
Image: HBOX
HBOX.E7:
Inherits: HBOX
-Buildable:
RenderBuilding:
Image: HBOX
HBOX.SHOK:
Inherits: HBOX
-Buildable:
RenderBuilding:
Image: HBOX
HBOX.SNIPER:
Inherits: HBOX
-Buildable:
RenderBuilding:
Image: HBOX
GUN: GUN:
Inherits: ^Building Inherits: ^Building
Buildable: Buildable: