diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index 7db2afe944..23ea3d34ef 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -125,6 +125,7 @@ namespace OpenRA.Mods.Common.Traits UnitStance stance; ConditionManager conditionManager; + IDisableAutoTarget[] disableAutoTarget; IEnumerable activeTargetPriorities; int conditionToken = ConditionManager.InvalidConditionToken; @@ -174,6 +175,7 @@ namespace OpenRA.Mods.Common.Traits .Where(Exts.IsTraitEnabled).Select(atp => atp.Info); conditionManager = self.TraitOrDefault(); + disableAutoTarget = self.TraitsImplementing().ToArray(); ApplyStanceCondition(self); } @@ -202,6 +204,10 @@ namespace OpenRA.Mods.Common.Traits if (attacker.Disposed) return; + foreach (var dat in disableAutoTarget) + if (dat.DisableAutoTarget(self)) + return; + if (!attacker.IsInWorld) { // If the aggressor is in a transport, then attack the transport instead @@ -250,6 +256,10 @@ namespace OpenRA.Mods.Common.Traits { nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval); + foreach (var dat in disableAutoTarget) + if (dat.DisableAutoTarget(self)) + return Target.Invalid; + foreach (var ab in ActiveAttackBases) { // If we can't attack right now, there's no need to try and find a target. @@ -379,8 +389,8 @@ namespace OpenRA.Mods.Common.Traits bool PreventsAutoTarget(Actor attacker, Actor target) { - foreach (var pat in target.TraitsImplementing()) - if (pat.PreventsAutoTarget(target, attacker)) + foreach (var deat in target.TraitsImplementing()) + if (deat.DisableEnemyAutoTarget(target, attacker)) return true; return false; diff --git a/OpenRA.Mods.Common/Traits/CaptureManager.cs b/OpenRA.Mods.Common/Traits/CaptureManager.cs index 5278e23836..b315bcfbc5 100644 --- a/OpenRA.Mods.Common/Traits/CaptureManager.cs +++ b/OpenRA.Mods.Common/Traits/CaptureManager.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits } } - public class CaptureManager : INotifyCreated, INotifyCapture, ITick, IPreventsAutoTarget + public class CaptureManager : INotifyCreated, INotifyCapture, ITick, IDisableEnemyAutoTarget { readonly CaptureManagerInfo info; ConditionManager conditionManager; @@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Traits w.Update(currentTarget, self, currentTarget, currentTargetDelay, currentTargetTotal); } - bool IPreventsAutoTarget.PreventsAutoTarget(Actor self, Actor attacker) + bool IDisableEnemyAutoTarget.DisableEnemyAutoTarget(Actor self, Actor attacker) { return info.PreventsAutoTarget && currentCaptors.Any(c => attacker.AppearsFriendlyTo(c)); } diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 4d6b62ed7e..7cc533b3af 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -297,9 +297,16 @@ namespace OpenRA.Mods.Common.Traits void ModifyTransformActorInit(Actor self, TypeDictionary init); } - public interface IPreventsAutoTarget + [RequireExplicitImplementation] + public interface IDisableEnemyAutoTarget { - bool PreventsAutoTarget(Actor self, Actor attacker); + bool DisableEnemyAutoTarget(Actor self, Actor attacker); + } + + [RequireExplicitImplementation] + public interface IDisableAutoTarget + { + bool DisableAutoTarget(Actor self); } [RequireExplicitImplementation]