From c6f0b792d320894ec3385730277d84d1540e50e7 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 27 Jul 2010 21:09:43 +1200 Subject: [PATCH] Do the right thing when stances change --- OpenRA.Game/Network/UnitOrders.cs | 7 ++++++- OpenRA.Game/Traits/World/Shroud.cs | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 1891575719..aba47aeba1 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -66,9 +66,14 @@ namespace OpenRA.Network case "SetStance": { var targetPlayer = order.Player.World.players[order.TargetLocation.X]; + var oldStance = order.Player.Stances[targetPlayer]; order.Player.Stances[targetPlayer] = (Stance)order.TargetLocation.Y; + + if (targetPlayer == world.LocalPlayer) + world.WorldActor.traits.Get().UpdatePlayerStance(world, order.Player, oldStance, order.Player.Stances[targetPlayer]); + Game.Debug("{0} has set diplomatic stance vs {1} to {2}".F( - order.Player.PlayerName, targetPlayer.PlayerName, (Stance)order.TargetLocation.Y)); + order.Player.PlayerName, targetPlayer.PlayerName, order.Player.Stances[targetPlayer])); break; } default: diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 8b06b08199..34893af6e1 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -101,6 +101,24 @@ namespace OpenRA.Traits Dirty(); } + + public void UpdatePlayerStance(World w, Player player, Stance oldStance, Stance newStance) + { + if (oldStance == newStance) + return; + + // No longer our ally; remove unit vis + if (oldStance == Stance.Ally) + { + var toRemove = new List(vis.Select(a => a.Key).Where(a => a.Owner == player)); + foreach (var a in toRemove) + RemoveActor(a); + } + // Is now our ally; add unit vis + if (newStance == Stance.Ally) + foreach (var a in w.Queries.OwnedBy[player]) + AddActor(a); + } public static IEnumerable GetVisOrigins(Actor a) { @@ -135,7 +153,9 @@ namespace OpenRA.Traits public void UpdateActor(Actor a) { - if (a.Owner == null || a.Owner != a.Owner.World.LocalPlayer) return; + if (a.Owner == null || a.Owner.World.LocalPlayer == null + || a.Owner.Stances[a.Owner.World.LocalPlayer] != Stance.Ally) return; + RemoveActor(a); AddActor(a); }