From 1e320141903d0cf68273c8d4b04af48bfd6c11d4 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 15 Oct 2011 13:00:19 +1300 Subject: [PATCH] add CountryInfo.Selectable --- OpenRA.Game/Map.cs | 2 +- OpenRA.Game/Player.cs | 20 +++++++++++-------- OpenRA.Game/Traits/World/Country.cs | 3 +-- OpenRA.Game/WorldUtils.cs | 5 ----- .../Widgets/Logic/CncLobbyLogic.cs | 1 + OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 1 + 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 54e54c229b..2f944ede06 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -410,7 +410,7 @@ namespace OpenRA Players.Clear(); var firstRace = OpenRA.Rules.Info["world"].Traits - .WithInterface().First().Race; + .WithInterface().First(c => c.Selectable).Race; Players.Add("Neutral", new PlayerReference { diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index c13ad166b7..9f18ac9946 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -39,6 +39,16 @@ namespace OpenRA public Shroud Shroud { get { return World.LocalShroud; }} public World World { get; private set; } + static CountryInfo ChooseCountry(World world, string name) + { + var selectableCountries = Rules.Info["world"].Traits + .WithInterface().Where( c => c.Selectable ) + .ToArray(); + + return selectableCountries.FirstOrDefault(c => c.Race == name) + ?? selectableCountries.Random(world.SharedRandom); + } + public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr) { World = world; @@ -53,10 +63,7 @@ namespace OpenRA ColorRamp = client.ColorRamp; PlayerName = client.Name; botType = client.Bot; - - Country = world.GetCountries() - .FirstOrDefault(c => client.Country == c.Race) - ?? world.GetCountries().Random(world.SharedRandom); + Country = ChooseCountry(world, client.Country); } else { @@ -66,10 +73,7 @@ namespace OpenRA PlayerName = pr.Name; NonCombatant = pr.NonCombatant; botType = pr.Bot; - - Country = world.GetCountries() - .FirstOrDefault(c => pr.Race == c.Race) - ?? world.GetCountries().Random(world.SharedRandom); + Country = ChooseCountry(world, pr.Race); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); diff --git a/OpenRA.Game/Traits/World/Country.cs b/OpenRA.Game/Traits/World/Country.cs index 0812aeae4a..f7b94d516e 100644 --- a/OpenRA.Game/Traits/World/Country.cs +++ b/OpenRA.Game/Traits/World/Country.cs @@ -14,8 +14,7 @@ namespace OpenRA.Traits { public readonly string Name = null; public readonly string Race = null; - - /* todo: icon,... */ + public readonly bool Selectable = true; } public class Country { /* we're only interested in the Info */ } diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 65a7191412..11f0bd7491 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -102,11 +102,6 @@ namespace OpenRA r.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom)); } - public static IEnumerable GetCountries(this World w) - { - return w.WorldActor.Info.Traits.WithInterface(); - } - public static float Gauss1D(this Thirdparty.Random r, int samples) { return Graphics.Util.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index 5dddda3ecd..f8914dfc60 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -153,6 +153,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic }; CountryNames = Rules.Info["world"].Traits.WithInterface() + .Where(c => c.Selectable) .ToDictionary(a => a.Race, a => a.Name); CountryNames.Add("random", "Any"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 087314ebab..65324903eb 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -104,6 +104,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; CountryNames = Rules.Info["world"].Traits.WithInterface() + .Where(c => c.Selectable) .ToDictionary(a => a.Race, a => a.Name); CountryNames.Add("random", "Random");