From b70c56927fadc150d8236f9f3184b5202095d58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 22 Jun 2014 13:30:04 +0200 Subject: [PATCH 1/3] add a new Lint check for map players --- OpenRA.Mods.RA/Lint/CheckPlayers.cs | 39 ++++++++++++++++++++++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + 2 files changed, 40 insertions(+) create mode 100644 OpenRA.Mods.RA/Lint/CheckPlayers.cs diff --git a/OpenRA.Mods.RA/Lint/CheckPlayers.cs b/OpenRA.Mods.RA/Lint/CheckPlayers.cs new file mode 100644 index 0000000000..5c5bacd985 --- /dev/null +++ b/OpenRA.Mods.RA/Lint/CheckPlayers.cs @@ -0,0 +1,39 @@ +#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 CheckPlayers : ILintPass + { + public void Run(Action emitError, Action emitWarning, Map map) + { + var playerNames = map.Players.Values.Select(p => p.Name); + foreach (var player in map.Players) + foreach (var ally in player.Value.Allies) + if (!playerNames.Contains(ally)) + emitError("Allies contains player {0} that is not in list.".F(ally)); + + foreach (var player in map.Players) + foreach (var enemy in player.Value.Enemies) + if (!playerNames.Contains(enemy)) + emitError("Enemies contains player {0} that is not in list.".F(enemy)); + + var races = map.Rules.Actors["world"].Traits.WithInterface().Select(c => c.Race); + foreach (var player in map.Players) + if (!string.IsNullOrWhiteSpace(player.Value.Race) && player.Value.Race != "Random" && !races.Contains(player.Value.Race)) + emitError("Invalid race {0} chosen for player {1}.".F(player.Value.Race, player.Value.Name)); + } + } +} + diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 57b9325943..ee29ef2a2c 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -516,6 +516,7 @@ + From 6eabd080b88b7ce9e7e52554d32c79fcf1401b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 22 Jun 2014 13:30:09 +0200 Subject: [PATCH 2/3] StyleCop --- OpenRA.Game/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index a6bba831d9..d68ee59fc8 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -48,7 +48,7 @@ namespace OpenRA static CountryInfo ChooseCountry(World world, string name) { var selectableCountries = world.Map.Rules.Actors["world"].Traits - .WithInterface().Where( c => c.Selectable ) + .WithInterface().Where(c => c.Selectable) .ToArray(); return selectableCountries.FirstOrDefault(c => c.Race == name) From 4587ce6cd2931e71b4f6c969cd1e90827ff6abfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 22 Jun 2014 13:34:09 +0200 Subject: [PATCH 3/3] fix remaining errors spotted by new player lint check --- mods/d2k/maps/shellmap/map.yaml | 2 +- mods/ra/maps/allies-02-classic/map.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mods/d2k/maps/shellmap/map.yaml b/mods/d2k/maps/shellmap/map.yaml index 6ee8364212..985053afae 100644 --- a/mods/d2k/maps/shellmap/map.yaml +++ b/mods/d2k/maps/shellmap/map.yaml @@ -26,7 +26,7 @@ Players: PlayerReference@Neutral: Name: Neutral OwnsWorld: True - Race: allies + Race: atreides Actors: Actor0: spicebloom diff --git a/mods/ra/maps/allies-02-classic/map.yaml b/mods/ra/maps/allies-02-classic/map.yaml index 62af7a2df5..626301ef1c 100644 --- a/mods/ra/maps/allies-02-classic/map.yaml +++ b/mods/ra/maps/allies-02-classic/map.yaml @@ -35,25 +35,25 @@ Players: Race: soviet ColorRamp: 3,255,127 Allies: BadGuy - Enemies: England,Greece + Enemies: Greece PlayerReference@France: Name: France Race: allies ColorRamp: 115,115,143 - Allies: England,Greece + Allies: Greece Enemies: USSR,BadGuy PlayerReference@Neutral: Name: Neutral OwnsWorld: True NonCombatant: True Race: allies - Enemies: England,Greece + Enemies: Greece PlayerReference@BadGuy: Name: BadGuy Race: soviet ColorRamp: 3,255,127 Allies: USSR - Enemies: England,Greece + Enemies: Greece PlayerReference@Greece: Name: Greece Playable: True @@ -65,7 +65,7 @@ Players: ColorRamp: 161,134,200 LockSpawn: True LockTeam: True - Allies: France,England + Allies: France Enemies: USSR,BadGuy Actors: