diff --git a/OpenRA.Server/Server.cs b/OpenRA.Server/Server.cs index 38e7f32e01..a2517fa4a5 100644 --- a/OpenRA.Server/Server.cs +++ b/OpenRA.Server/Server.cs @@ -108,7 +108,7 @@ namespace OpenRA.Server Index = newConn.PlayerIndex, PaletteIndex = ChooseFreePalette(), Name = "Player {0}".F(1 + newConn.PlayerIndex), - Race = "allies", /* hack */ + Country = "allies", /* hack */ State = Session.ClientState.NotReady }); @@ -249,7 +249,7 @@ namespace OpenRA.Server return true; } - GetClient(conn).Race = s; + GetClient(conn).Country = s; SyncLobbyInfo(); return true; }}, diff --git a/OpenRa.FileFormats/Session.cs b/OpenRa.FileFormats/Session.cs index 87a459764a..9e8f3ea0f1 100644 --- a/OpenRa.FileFormats/Session.cs +++ b/OpenRa.FileFormats/Session.cs @@ -21,7 +21,7 @@ namespace OpenRa.FileFormats { public int Index; public int PaletteIndex; - public string Race; + public string Country; public int SpawnPoint; public string Name; public ClientState State; diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 30aa72dcf0..7aee82ff15 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -153,10 +153,10 @@ namespace OpenRa { DrawDownloadBar(); - chromeCollection = "chrome-" + world.LocalPlayer.Race; - radarCollection = "radar-" + world.LocalPlayer.Race; - paletteCollection = "palette-" + world.LocalPlayer.Race; - digitCollection = "digits-" + world.LocalPlayer.Race; + chromeCollection = "chrome-" + world.LocalPlayer.Country.Race; + radarCollection = "radar-" + world.LocalPlayer.Country.Race; + paletteCollection = "palette-" + world.LocalPlayer.Country.Race; + digitCollection = "digits-" + world.LocalPlayer.Country.Race; buttons.Clear(); @@ -362,9 +362,13 @@ namespace OpenRa void CycleRace(bool left) { - // hack - var newRace = Game.world.LocalPlayer.Race == "allies" ? "soviet" : "allies"; - Game.IssueOrder(Order.Chat("/race " + newRace)); + var countries = Game.world.GetCountries(); + var nextCountry = countries.Concat(countries) + .SkipWhile(c => c != Game.world.LocalPlayer.Country) + .Skip(1) + .First(); + + Game.IssueOrder(Order.Chat("/race " + nextCountry)); } void CycleReady(bool left) @@ -467,7 +471,7 @@ namespace OpenRa paletteRect.Bottom+Game.viewport.Location.Y - 5), Player.PlayerColors[client.PaletteIndex].c); lineRenderer.Flush(); - renderer.DrawText(client.Race, new int2(r.Left + 220, y), Color.White); + renderer.DrawText(client.Country, new int2(r.Left + 220, y), Color.White); renderer.DrawText(client.State.ToString(), new int2(r.Left + 290, y), Color.White); renderer.DrawText((client.SpawnPoint == 0)? "-" : client.SpawnPoint.ToString(), new int2(r.Left + 410, y), Color.White); y += 30; @@ -569,7 +573,7 @@ namespace OpenRa string[] tabKeys = { "normal", "ready", "selected" }; var producing = queue.CurrentItem(groupName); var index = q.Key == currentTab ? 2 : (producing != null && producing.Done) ? 1 : 0; - var race = world.LocalPlayer.Race; + var race = world.LocalPlayer.Country.Race; rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer,"tabs-"+tabKeys[index], race+"-"+q.Key), new float2(x, y), "chrome"); buttons.Add(Pair.New(new RectangleF(x, y, tabWidth, tabHeight), @@ -850,7 +854,7 @@ namespace OpenRa var allBuildables = Rules.TechTree.AllBuildables(world.LocalPlayer, queueName) .Where(a => a.Traits.Contains()) - .Where(a => a.Traits.Get().Owner.Contains(world.LocalPlayer.Race)) + .Where(a => a.Traits.Get().Owner.Contains(world.LocalPlayer.Country.Race)) .OrderBy(a => a.Traits.Get().TechLevel); var queue = world.LocalPlayer.PlayerActor.traits.Get(); diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index 27faa536a5..e4bc8e6019 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -39,7 +39,7 @@ namespace OpenRa.GameRules var bi = info.Traits.GetOrDefault(); if( bi == null ) return false; - if( !bi.Owner.Contains( player.Race ) ) + if( !bi.Owner.Contains( player.Country.Race ) ) return false; foreach( var p in bi.Prerequisites ) diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index 7c0d089f91..b1515d6a6e 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -16,7 +16,7 @@ namespace OpenRa public int Kills; public string PlayerName; public string InternalName; - public string Race; + public CountryInfo Country; public readonly int Index; public int Cash = 10000; public int Ore = 0; @@ -62,7 +62,8 @@ namespace OpenRa this.PaletteIndex = client != null ? client.PaletteIndex : index; this.PlayerName = client != null ? client.Name : "Player {0}".F(index+1); - this.Race = client != null ? client.Race : "allies"; + this.Country = world.GetCountries().FirstOrDefault( c => client != null && client.Country == c.Name ) + ?? world.GetCountries().First(); } void UpdatePower() @@ -177,10 +178,10 @@ namespace OpenRa PlayerName = client.Name; } - if (Race != client.Race) + if (Country.Name != client.Country) { - Game.chat.AddLine(this, "is now playing {0}".F(client.Race)); - Race = client.Race; + Game.chat.AddLine(this, "is now playing {0}".F(client.Country)); + Country = PlayerActor.World.GetCountries().First(c => c.Name == client.Country); } if (PaletteIndex != client.PaletteIndex) diff --git a/OpenRa.Game/Sound.cs b/OpenRa.Game/Sound.cs index fe274692c5..0cfbbfb32c 100644 --- a/OpenRa.Game/Sound.cs +++ b/OpenRa.Game/Sound.cs @@ -109,7 +109,8 @@ namespace OpenRa return; } - var variants = (voicedUnit.Owner.Race == "allies") + // todo: fix this + var variants = (voicedUnit.Owner.Country.Race == "allies") ? vi.AlliedVariants : vi.SovietVariants; var variant = variants[voicedUnit.ActorID % variants.Length]; diff --git a/OpenRa.Game/Traits/SupportPowers/SupportPower.cs b/OpenRa.Game/Traits/SupportPowers/SupportPower.cs index 89e13913a9..ff13b22316 100644 --- a/OpenRa.Game/Traits/SupportPowers/SupportPower.cs +++ b/OpenRa.Game/Traits/SupportPowers/SupportPower.cs @@ -48,7 +48,7 @@ namespace OpenRa.Traits var buildings = Rules.TechTree.GatherBuildings(self.Owner); var effectivePrereq = Info.Prerequisites .Select(a => a.ToLowerInvariant()) - .Where(a => Rules.Info[a].Traits.Get().Owner.Contains(self.Owner.Race)); + .Where(a => Rules.Info[a].Traits.Get().Owner.Contains(self.Owner.Country.Race)); if (Info.GivenAuto) { @@ -80,7 +80,7 @@ namespace OpenRa.Traits var buildings = Rules.TechTree.GatherBuildings(Owner); var effectivePrereq = Info.Prerequisites .Select(a => a.ToLowerInvariant()) - .Where(a => Rules.Info[a].Traits.Get().Owner.Contains(Owner.Race)); + .Where(a => Rules.Info[a].Traits.Get().Owner.Contains(Owner.Country.Race)); if (Info.Prerequisites.Count() == 0) return Owner.GetPowerState() == PowerState.Normal; diff --git a/OpenRa.Game/Traits/World/Country.cs b/OpenRa.Game/Traits/World/Country.cs index 35e1e5795d..b21d8ca844 100644 --- a/OpenRa.Game/Traits/World/Country.cs +++ b/OpenRa.Game/Traits/World/Country.cs @@ -5,7 +5,7 @@ using System.Text; namespace OpenRa.Traits { - class CountryInfo : ITraitInfo + public class CountryInfo : ITraitInfo { public readonly string Name = null; public readonly string Race = null; diff --git a/OpenRa.Game/WorldUtils.cs b/OpenRa.Game/WorldUtils.cs index 46ad76a93a..6709a59fe0 100755 --- a/OpenRa.Game/WorldUtils.cs +++ b/OpenRa.Game/WorldUtils.cs @@ -186,5 +186,10 @@ namespace OpenRa !isX ? Game.SharedRandom.Next(w.Map.YOffset, w.Map.YOffset + w.Map.Height) : (edge ? w.Map.YOffset : w.Map.YOffset + w.Map.Height)); } + + public static IEnumerable GetCountries(this World w) + { + return w.WorldActor.Info.Traits.WithInterface(); + } } }