From 3cfa96e7a6d2582ba27281da3a807993b555a830 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 20 Apr 2015 03:29:18 +1200 Subject: [PATCH] Fix random country display. --- OpenRA.Game/Map/PlayerReference.cs | 1 - OpenRA.Game/Player.cs | 15 +++++++-------- .../Traits/World/CreateMPPlayers.cs | 1 + .../Widgets/Logic/Ingame/GameInfoStatsLogic.cs | 4 ++-- .../Widgets/Logic/Lobby/LobbyUtils.cs | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/OpenRA.Game/Map/PlayerReference.cs b/OpenRA.Game/Map/PlayerReference.cs index 32fda208fa..c77da7606c 100644 --- a/OpenRA.Game/Map/PlayerReference.cs +++ b/OpenRA.Game/Map/PlayerReference.cs @@ -27,7 +27,6 @@ namespace OpenRA public bool LockRace = false; public string Race; - public string RaceFlagName; // ColorRamp naming retained for backward compatibility public bool LockColor = false; diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index bf42f68269..edec9601c9 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -38,6 +38,9 @@ namespace OpenRA public readonly int ClientIndex; public readonly PlayerReference PlayerReference; + // The country (including Random, etc) that was selected in the lobby + public readonly CountryInfo DisplayCountry; + public WinState WinState = WinState.Undefined; public bool IsBot; public int SpawnPoint; @@ -46,8 +49,6 @@ namespace OpenRA public Shroud Shroud; public World World { get; private set; } - string selectedCountryName; - CountryInfo ChooseCountry(World world, string name, bool requireSelectable = true) { var selectableCountries = world.Map.Rules.Actors["world"].Traits @@ -57,8 +58,6 @@ namespace OpenRA var selected = selectableCountries.FirstOrDefault(c => c.Race == name) ?? selectableCountries.Random(world.SharedRandom); - selectedCountryName = selected.Name; - // Don't loop infinite for (var i = 0; i <= 10 && selected.RandomRaceMembers.Any(); i++) { @@ -87,8 +86,8 @@ namespace OpenRA PlayerName = client.Name; botType = client.Bot; Country = ChooseCountry(world, client.Race, !pr.LockRace); - pr.Race = selectedCountryName; - pr.RaceFlagName = client.Race; + DisplayCountry = world.Map.Rules.Actors["world"].Traits + .WithInterface().First(c => c.Race == client.Race); } else { @@ -101,8 +100,8 @@ namespace OpenRA Spectating = pr.Spectating; botType = pr.Bot; Country = ChooseCountry(world, pr.Race, false); - pr.RaceFlagName = pr.Race; - pr.Race = Country.Name; + DisplayCountry = world.Map.Rules.Actors["world"].Traits + .WithInterface().First(c => c.Race == pr.Race); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); diff --git a/OpenRA.Mods.Common/Traits/World/CreateMPPlayers.cs b/OpenRA.Mods.Common/Traits/World/CreateMPPlayers.cs index 13b2a3c3ec..df6c85ab3a 100644 --- a/OpenRA.Mods.Common/Traits/World/CreateMPPlayers.cs +++ b/OpenRA.Mods.Common/Traits/World/CreateMPPlayers.cs @@ -50,6 +50,7 @@ namespace OpenRA.Mods.Common.Traits Name = "Everyone", NonCombatant = true, Spectating = true, + Race = "Random", Allies = w.Players.Where(p => !p.NonCombatant && p.Playable).Select(p => p.InternalName).ToArray() })); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 699bc7996a..13b390698c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -62,8 +62,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } else { - flag.GetImageName = () => pp.PlayerReference.RaceFlagName; - item.Get("FACTION").GetText = () => pp.PlayerReference.Race; + flag.GetImageName = () => pp.DisplayCountry.Race; + item.Get("FACTION").GetText = () => pp.DisplayCountry.Name; } var team = item.Get("TEAM"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 08e244ea0a..0f3731f979 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -467,7 +467,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var flag = template.Get("FLAG"); flag.GetImageCollection = () => "flags"; if (player.World.RenderPlayer != null && player.World.RenderPlayer.Stances[player] != Stance.Ally) - flag.GetImageName = () => player.PlayerReference.RaceFlagName; + flag.GetImageName = () => player.DisplayCountry.Race; else flag.GetImageName = () => player.Country.Race;