From b5efc979963235d9f961d4cfba2bdcba4e7651b7 Mon Sep 17 00:00:00 2001 From: alzeih Date: Sun, 13 Mar 2011 10:42:23 +1300 Subject: [PATCH] Fix #604 --- OpenRA.Game/Player.cs | 51 +++++++++++++------------------ OpenRA.Mods.RA/CreateMPPlayers.cs | 4 +-- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index c0ef69661d..ccc9bd3d74 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -42,43 +42,36 @@ namespace OpenRA public Shroud Shroud { get { return World.LocalShroud; }} public World World { get; private set; } - public Player(World world, PlayerReference pr, int index) - { - World = world; - - Index = index; - Palette = "player" + index; - - ColorRamp = pr.ColorRamp; - ClientIndex = 0; /* it's a map player, "owned" by host */ - - PlayerName = InternalName = pr.Name; - NonCombatant = pr.NonCombatant; - Country = world.GetCountries() - .FirstOrDefault(c => pr.Race == c.Race) - ?? world.GetCountries().Random(world.SharedRandom); - - PlayerRef = pr; - - PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); - } - public Player(World world, Session.Client client, PlayerReference pr, int index) { World = world; Index = index; Palette = "player" + index; - ColorRamp = client.ColorRamp; - PlayerName = client.Name; - InternalName = pr.Name; - Country = world.GetCountries() - .FirstOrDefault(c => client != null && client.Country == c.Race) - ?? world.GetCountries().Random(world.SharedRandom); - - ClientIndex = client.Index; PlayerRef = pr; + + if (client != null) + { + ClientIndex = client.Index; + ColorRamp = client.ColorRamp; + PlayerName = client.Name; + Country = world.GetCountries() + .FirstOrDefault(c => client.Country == c.Race) + ?? world.GetCountries().Random(world.SharedRandom); + } + else + { + ClientIndex = 0; /* it's a map player, "owned" by host */ + ColorRamp = pr.ColorRamp; + PlayerName = pr.Name; + NonCombatant = pr.NonCombatant; + + Country = world.GetCountries() + .FirstOrDefault(c => pr.Race == c.Race) + ?? world.GetCountries().Random(world.SharedRandom); + } + PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); } diff --git a/OpenRA.Mods.RA/CreateMPPlayers.cs b/OpenRA.Mods.RA/CreateMPPlayers.cs index 7f885afaba..a9a67acb19 100644 --- a/OpenRA.Mods.RA/CreateMPPlayers.cs +++ b/OpenRA.Mods.RA/CreateMPPlayers.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA // create the unplayable map players -- neutral, shellmap, scripted, etc. foreach (var kv in w.Map.Players.Where(p => !p.Value.Playable)) { - var player = new Player(w, kv.Value, mapPlayerIndex--); + var player = new Player(w, null, kv.Value, mapPlayerIndex--); w.AddPlayer(player); if (kv.Value.OwnsWorld) w.WorldActor.Owner = player; @@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA /* todo: pick a random name from the pool */ - var player = new Player(w, w.Map.Players[slot.MapPlayer], playerIndex++); + var player = new Player(w, null, w.Map.Players[slot.MapPlayer], playerIndex++); w.AddPlayer(player); /* activate the bot option that's selected! */