diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 30dc187486..4d7117ef63 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -51,42 +51,42 @@ namespace OpenRA readonly IFogVisibilityModifier[] fogVisibilities; - FactionInfo ChooseCountry(World world, string name, bool requireSelectable = true) + static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true) { - var selectableCountries = world.Map.Rules.Actors["world"].Traits + var selectableFactions = world.Map.Rules.Actors["world"].Traits .WithInterface().Where(f => !requireSelectable || f.Selectable) .ToList(); - var selected = selectableCountries.FirstOrDefault(f => f.InternalName == name) - ?? selectableCountries.Random(world.SharedRandom); + var selected = selectableFactions.FirstOrDefault(f => f.InternalName == name) + ?? selectableFactions.Random(world.SharedRandom); // Don't loop infinite for (var i = 0; i <= 10 && selected.RandomFactionMembers.Any(); i++) { - var race = selected.RandomFactionMembers.Random(world.SharedRandom); - selected = selectableCountries.FirstOrDefault(f => f.InternalName == race); + var faction = selected.RandomFactionMembers.Random(world.SharedRandom); + selected = selectableFactions.FirstOrDefault(f => f.InternalName == faction); if (selected == null) - throw new YamlException("Unknown race: {0}".F(race)); + throw new YamlException("Unknown faction: {0}".F(faction)); } return selected; } - FactionInfo ChooseDisplayCountry(World world, string race) + static FactionInfo ChooseDisplayFaction(World world, string factionName) { - var countries = world.Map.Rules.Actors["world"].Traits - .WithInterface().ToArray(); + var factions = world.Map.Rules.Actors["world"].Traits.WithInterface().ToArray(); - return countries.FirstOrDefault(f => f.InternalName == race) ?? countries.First(); + return factions.FirstOrDefault(f => f.InternalName == factionName) ?? factions.First(); } public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr) { + string botType; + World = world; InternalName = pr.Name; PlayerReference = pr; - string botType = null; // Real player or host-created bot if (client != null) @@ -95,8 +95,8 @@ namespace OpenRA Color = client.Color; PlayerName = client.Name; botType = client.Bot; - Faction = ChooseCountry(world, client.Race, !pr.LockFaction); - DisplayFaction = ChooseDisplayCountry(world, client.Race); + Faction = ChooseFaction(world, client.Race, !pr.LockFaction); + DisplayFaction = ChooseDisplayFaction(world, client.Race); } else { @@ -108,22 +108,20 @@ namespace OpenRA Playable = pr.Playable; Spectating = pr.Spectating; botType = pr.Bot; - Faction = ChooseCountry(world, pr.Faction, false); - DisplayFaction = ChooseDisplayCountry(world, pr.Faction); + Faction = ChooseFaction(world, pr.Faction, false); + DisplayFaction = ChooseDisplayFaction(world, pr.Faction); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); Shroud = PlayerActor.Trait(); - fogVisibilities = PlayerActor.TraitsImplementing() - .ToArray(); + fogVisibilities = PlayerActor.TraitsImplementing().ToArray(); // Enable the bot logic on the host IsBot = botType != null; if (IsBot && Game.IsHost) { - var logic = PlayerActor.TraitsImplementing() - .FirstOrDefault(b => b.Info.Name == botType); + var logic = PlayerActor.TraitsImplementing().FirstOrDefault(b => b.Info.Name == botType); if (logic == null) Log.Write("debug", "Invalid bot type: {0}", botType); else @@ -193,7 +191,7 @@ namespace OpenRA public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right) { Player a, b; - if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b)) + if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b)) return false; return a == b;