From 8a05af72b37fa01c641c4b9a721fd7756a653293 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 18 Mar 2010 13:18:41 +1300 Subject: [PATCH] Unknown race -> Random; make it actually work, too. --- OpenRA.Game/Chrome.cs | 8 ++++---- OpenRA.Game/Exts.cs | 6 ++++++ OpenRA.Game/Player.cs | 6 +++--- OpenRA.Game/Server/Server.cs | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index b60827e972..d1590a1842 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -397,16 +397,16 @@ namespace OpenRA void CycleRace(bool left) { - var countries = Game.world.GetCountries(); + var countries = new[] { "Random" }.Concat(Game.world.GetCountries().Select(c => c.Name)); var nextCountry = countries - .SkipWhile(c => c.Name != Game.LocalClient.Country) + .SkipWhile(c => c != Game.LocalClient.Country) .Skip(1) .FirstOrDefault(); if (nextCountry == null) nextCountry = countries.First(); - Game.IssueOrder(Order.Chat("/race " + nextCountry.Name)); + Game.IssueOrder(Order.Chat("/race " + nextCountry)); } void CycleReady(bool left) @@ -511,7 +511,7 @@ namespace OpenRA paletteRect.Bottom+Game.viewport.Location.Y - 5), Player.PlayerColors[client.PaletteIndex].c); lineRenderer.Flush(); - f.DrawText(rgbaRenderer, client.Country ?? "Unknown", new int2(r.Left + 220, y), Color.White); + f.DrawText(rgbaRenderer, client.Country, new int2(r.Left + 220, y), Color.White); f.DrawText(rgbaRenderer, client.State.ToString(), new int2(r.Left + 290, y), Color.White); f.DrawText(rgbaRenderer, (client.SpawnPoint == 0) ? "-" : client.SpawnPoint.ToString(), new int2(r.Left + 410, y), Color.White); y += 30; diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 6da6b1e8b7..0555cbbbdc 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -86,5 +86,11 @@ namespace OpenRA d.Add( k, ret = createFn( k ) ); return ret; } + + public static T Random(this IEnumerable ts, Thirdparty.Random r) + { + var xs = ts.ToArray(); + return xs[r.Next(xs.Length)]; + } } } diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index f019ad54dd..ba5c4a4298 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -87,10 +87,10 @@ namespace OpenRA Palette = "neutral"; Color = Color.Gray; // HACK HACK } - + Country = world.GetCountries() - .FirstOrDefault( c => client != null && client.Country == c.Name ) - ?? world.GetCountries().First(); + .FirstOrDefault(c => client != null && client.Country == c.Name) + ?? world.GetCountries().Random(world.SharedRandom); } void UpdatePower() diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 0ff00ce6dc..5f8189067e 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -147,7 +147,7 @@ namespace OpenRA.Server Index = newConn.PlayerIndex, PaletteIndex = ChooseFreePalette(), Name = "Player {0}".F(1 + newConn.PlayerIndex), - Country = "", /* hack */ + Country = "Random", State = Session.ClientState.NotReady });