From ad3722e19fa055a9c8b55bf8b668b6ccf38153dd Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Thu, 20 Aug 2020 23:03:17 +0200 Subject: [PATCH] Add support for circumventing the target scan limit in AttackMove --- OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs | 5 +++-- OpenRA.Mods.Common/Traits/AutoTarget.cs | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs b/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs index 20446b308a..745b9a1fde 100644 --- a/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs +++ b/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs @@ -56,8 +56,9 @@ namespace OpenRA.Mods.Common.Activities // We are currently not attacking, so scan for new targets. if (autoTarget != null && (ChildActivity == null || runningInnerActivity)) { - // ScanForTarget already limits the scanning rate for performance so we don't need to do that here. - target = autoTarget.ScanForTarget(self, false, true); + // Use the standard ScanForTarget rate limit while we are running the inner move activity to save performance. + // Override the rate limit if our attack activity has completed so we can immediately acquire a new target instead of moving. + target = autoTarget.ScanForTarget(self, false, true, !runningInnerActivity); // Cancel the current inner activity and queue attack activities if we find a new target. if (target.Type != TargetType.Invalid) diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index ba30ef64c1..2d68b6f673 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -279,15 +279,16 @@ namespace OpenRA.Mods.Common.Traits --nextScanTime; } - public Target ScanForTarget(Actor self, bool allowMove, bool allowTurn) + public Target ScanForTarget(Actor self, bool allowMove, bool allowTurn, bool ignoreScanInterval = false) { - if (nextScanTime <= 0 && ActiveAttackBases.Any()) + if ((ignoreScanInterval || nextScanTime <= 0) && ActiveAttackBases.Any()) { foreach (var dat in disableAutoTarget) if (dat.DisableAutoTarget(self)) return Target.Invalid; - nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval); + if (!ignoreScanInterval) + nextScanTime = self.World.SharedRandom.Next(Info.MinimumScanTimeInterval, Info.MaximumScanTimeInterval); foreach (var ab in ActiveAttackBases) {