Unknown race -> Random; make it actually work, too.

This commit is contained in:
Chris Forbes
2010-03-18 13:18:41 +13:00
parent c17459310a
commit 8a05af72b3
4 changed files with 14 additions and 8 deletions

View File

@@ -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;

View File

@@ -86,5 +86,11 @@ namespace OpenRA
d.Add( k, ret = createFn( k ) );
return ret;
}
public static T Random<T>(this IEnumerable<T> ts, Thirdparty.Random r)
{
var xs = ts.ToArray();
return xs[r.Next(xs.Length)];
}
}
}

View File

@@ -89,8 +89,8 @@ namespace OpenRA
}
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()

View File

@@ -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
});