diff --git a/OpenRA.Mods.Common/Traits/CaptureManager.cs b/OpenRA.Mods.Common/Traits/CaptureManager.cs index 484e559e18..f639c154f5 100644 --- a/OpenRA.Mods.Common/Traits/CaptureManager.cs +++ b/OpenRA.Mods.Common/Traits/CaptureManager.cs @@ -36,10 +36,13 @@ namespace OpenRA.Mods.Common.Traits [Desc("Condition granted when being captured by another actor.")] public readonly string BeingCapturedCondition = null; + [Desc("Should units friendly to the capturing actor auto-target this actor while it is being captured?")] + public readonly bool PreventsAutoTarget = true; + public virtual object Create(ActorInitializer init) { return new CaptureManager(this); } } - public class CaptureManager : INotifyCreated, INotifyCapture, ITick + public class CaptureManager : INotifyCreated, INotifyCapture, ITick, IPreventsAutoTarget { readonly CaptureManagerInfo info; ConditionManager conditionManager; @@ -63,6 +66,8 @@ namespace OpenRA.Mods.Common.Traits int beingCapturedToken = ConditionManager.InvalidConditionToken; bool enteringCurrentTarget; + HashSet currentCaptors = new HashSet(); + public bool BeingCaptured { get; private set; } public CaptureManager(CaptureManagerInfo info) @@ -176,6 +181,7 @@ namespace OpenRA.Mods.Common.Traits if (currentTarget != null) CancelCapture(self, currentTarget, currentTargetManager); + targetManager.currentCaptors.Add(self); currentTarget = target; currentTargetManager = targetManager; currentTargetDelay = 0; @@ -244,6 +250,7 @@ namespace OpenRA.Mods.Common.Traits currentTargetManager = null; currentTargetDelay = 0; enteringCurrentTarget = false; + targetManager.currentCaptors.Remove(self); } void ITick.Tick(Actor self) @@ -262,5 +269,10 @@ namespace OpenRA.Mods.Common.Traits foreach (var w in currentTargetManager.progressWatchers) w.Update(currentTarget, self, currentTarget, currentTargetDelay, currentTargetTotal); } + + bool IPreventsAutoTarget.PreventsAutoTarget(Actor self, Actor attacker) + { + return info.PreventsAutoTarget && currentCaptors.Any(c => attacker.AppearsFriendlyTo(c)); + } } }