From e7f376dc58d5e13d9c57fd46a64cc77c8e64b10e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 5 Feb 2010 00:32:15 +1300 Subject: [PATCH] Fix player palette double-add bug --- OpenRa.Game/Chrome.cs | 4 ++++ OpenRa.Game/Game.cs | 2 ++ OpenRa.Game/Player.cs | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 360111e801..6f99aa8b4e 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -356,6 +356,10 @@ namespace OpenRa var d = left ? +1 : Player.PlayerColors.Count() - 1; var newIndex = ((int)Game.world.LocalPlayer.PaletteIndex + d) % Player.PlayerColors.Count(); + + Game.IssueOrder( + Order.Chat("color count " + Player.PlayerColors.Count())); + while (!PaletteAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.PaletteIndex) newIndex = (newIndex + d) % Player.PlayerColors.Count(); diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 353b16be24..1a4b6d4b8a 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -65,7 +65,9 @@ namespace OpenRa Timer.Time( "load rules: {0}" ); world = null; // trying to access the old world will NRE, rather than silently doing it wrong. + Player.ResetPlayerColorList(); world = new World(); + Game.world.ActorAdded += a => { if (a.Owner != null && a.Info.Traits.Contains()) diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index 9175be8555..a0986a69ab 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -30,8 +30,16 @@ namespace OpenRa public World World { get { return PlayerActor.World; } } public static List> PlayerColors = new List>(); + public static void ResetPlayerColorList() + { + // This is unsafe if the mapchange introduces/removes mods that defines new colors + // TODO: ensure that each player's palette index is reassigned appropriately + PlayerColors = new List>(); + } + public static void RegisterPlayerColor(string palette, string name, Color c) { + Log.Write("Adding player color {0}",name); PlayerColors.Add(new Tuple(palette, name, c)); } @@ -58,7 +66,7 @@ namespace OpenRa this.PlayerName = client != null ? client.Name : "Player {0}".F(index+1); this.Race = client != null ? (Race)client.Race : Race.Allies; } - + void UpdatePower() { var oldBalance = PowerProvided - PowerDrained;