From ab196a23e671e53baa4bf8e8b245cce2b1d0cb7a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 26 Jan 2020 14:25:54 +0000 Subject: [PATCH] Fix AttackFollow ignoring allowMove flag when auto-targeting. --- OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs | 11 ++++++++++- OpenRA.Mods.Common/Traits/AutoTarget.cs | 6 +++--- OpenRA.Mods.Common/TraitsInterfaces.cs | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs index 3562037ca0..dbd7c2627b 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs @@ -42,6 +42,7 @@ namespace OpenRA.Mods.Common.Traits Activity requestedTargetPresetForActivity; bool opportunityForceAttack; bool opportunityTargetIsPersistentTarget; + bool scanningForOpportunityTarget; public void SetRequestedTarget(Actor self, Target target, bool isForceAttack = false) { @@ -137,7 +138,10 @@ namespace OpenRA.Mods.Common.Traits if (!IsAiming && Info.OpportunityFire && autoTarget != null && !autoTarget.IsTraitDisabled && autoTarget.Stance >= UnitStance.Defend) { + scanningForOpportunityTarget = true; OpportunityTarget = autoTarget.ScanForTarget(self, false, false); + scanningForOpportunityTarget = false; + opportunityForceAttack = false; opportunityTargetIsPersistentTarget = false; @@ -182,8 +186,13 @@ namespace OpenRA.Mods.Common.Traits opportunityTargetIsPersistentTarget = false; } - bool IDisableAutoTarget.DisableAutoTarget(Actor self) + bool IDisableAutoTarget.DisableAutoTarget(Actor self, bool allowMove) { + // HACK: Disable standard AutoTarget scanning, which we want to be + // controlled by the opportunity target logic in this trait + if (!allowMove && !scanningForOpportunityTarget) + return true; + return RequestedTarget.Type != TargetType.Invalid || (opportunityTargetIsPersistentTarget && OpportunityTarget.Type != TargetType.Invalid); } diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index 1dcaef4172..49079ee4e2 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -236,8 +236,9 @@ namespace OpenRA.Mods.Common.Traits if (attacker.Disposed) return; + var allowMove = allowMovement && Stance > UnitStance.Defend; foreach (var dat in disableAutoTarget) - if (dat.DisableAutoTarget(self)) + if (dat.DisableAutoTarget(self, allowMove)) return; if (!attacker.IsInWorld) @@ -249,7 +250,6 @@ namespace OpenRA.Mods.Common.Traits } // Don't fire at an invisible enemy when we can't move to reveal it - var allowMove = allowMovement && Stance > UnitStance.Defend; if (!allowMove && !attacker.CanBeViewedByPlayer(self.Owner)) return; @@ -293,7 +293,7 @@ namespace OpenRA.Mods.Common.Traits nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval); foreach (var dat in disableAutoTarget) - if (dat.DisableAutoTarget(self)) + if (dat.DisableAutoTarget(self, allowMove)) return Target.Invalid; foreach (var ab in ActiveAttackBases) diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 34eb4df2bb..21f0c6560b 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -310,7 +310,7 @@ namespace OpenRA.Mods.Common.Traits [RequireExplicitImplementation] public interface IDisableAutoTarget { - bool DisableAutoTarget(Actor self); + bool DisableAutoTarget(Actor self, bool allowMove); } [RequireExplicitImplementation]