From e005e9e314fec5f322ceb3a6d6e30b43dcafcd3c Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 17 Mar 2010 22:56:42 +1300 Subject: [PATCH] real player spawning --- OpenRA.Game/Game.cs | 7 ++++--- OpenRA.Game/Player.cs | 28 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 71f7396b07..b1f7576777 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -267,10 +267,11 @@ namespace OpenRA if( orderManager.GameStarted ) return; chat.Reset(); - // todo: only spawn a neutral player + a player for each client - for (int i = 0; i < 8; i++) - world.players[i] = new Player(world, i, LobbyInfo.Clients.FirstOrDefault(a => a.Index == i)); + world.AddPlayer(new Player(world, null)); // neutral player + foreach (var c in LobbyInfo.Clients) + world.AddPlayer(new Player(world, c)); + world.Queries = new World.AllQueries(world); foreach (var gs in world.WorldActor.traits.WithInterface()) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index a864811bfa..f019ad54dd 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -66,19 +66,29 @@ namespace OpenRA public Shroud Shroud; - public Player( World world, int index, Session.Client client ) + public Player( World world, Session.Client client ) { Shroud = new Shroud(this, world.Map); - this.PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this); - this.Index = index; - this.InternalName = "Multi{0}".F(index); + PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this); - var paletteIndex = client != null ? client.PaletteIndex : index; - this.Palette = PlayerColors[paletteIndex].a; - this.Color = PlayerColors[paletteIndex].c; - this.PlayerName = client != null ? client.Name : "Player {0}".F(index+1); - this.Country = world.GetCountries() + if (client != null) + { + Index = client.Index; + Palette = PlayerColors[client.PaletteIndex].a; + Color = PlayerColors[client.PaletteIndex].c; + PlayerName = client.Name; + InternalName = "Multi{0}".F(client.Index); + } + else + { + Index = -1; + PlayerName = InternalName = "Neutral"; + Palette = "neutral"; + Color = Color.Gray; // HACK HACK + } + + Country = world.GetCountries() .FirstOrDefault( c => client != null && client.Country == c.Name ) ?? world.GetCountries().First(); }