diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 6667199b97..0e971e5d09 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -336,6 +336,8 @@ namespace OpenRA foreach (var t in TraitsImplementing()) t.OnOwnerChanged(this, oldOwner, newOwner); + World.Selection.OnOwnerChanged(this, oldOwner, newOwner); + if (wasInWorld) World.Add(this); } diff --git a/OpenRA.Game/Selection.cs b/OpenRA.Game/Selection.cs index 0122dce5e4..6777fd0dbe 100644 --- a/OpenRA.Game/Selection.cs +++ b/OpenRA.Game/Selection.cs @@ -50,6 +50,29 @@ namespace OpenRA ns.SelectionChanged(); } + public void Remove(Actor a) + { + if (actors.Remove(a)) + { + UpdateHash(); + foreach (var ns in worldNotifySelection) + ns.SelectionChanged(); + } + } + + internal void OnOwnerChanged(Actor a, Player oldOwner, Player newOwner) + { + if (!actors.Contains(a)) + return; + + // Remove the actor from the original owners selection + // Call UpdateHash directly for everyone else so watchers can account for the owner change if needed + if (oldOwner == a.World.LocalPlayer) + Remove(a); + else + UpdateHash(); + } + public bool Contains(Actor a) { return actors.Contains(a);