diff --git a/OpenRA.Mods.RA/Activities/AttackMoveActivity.cs b/OpenRA.Mods.RA/Activities/AttackMoveActivity.cs index fcaa5a6a78..43054a7cf6 100644 --- a/OpenRA.Mods.RA/Activities/AttackMoveActivity.cs +++ b/OpenRA.Mods.RA/Activities/AttackMoveActivity.cs @@ -20,42 +20,24 @@ namespace OpenRA.Mods.RA.Activities { const int ScanInterval = 7; - int scanTicks; - bool hasMoved; Activity inner; + int scanTicks; AutoTarget autoTarget; public AttackMoveActivity(Actor self, Activity inner) { this.inner = inner; autoTarget = self.TraitOrDefault(); - hasMoved = false; } public override Activity Tick(Actor self) { - if (autoTarget != null) + if (autoTarget != null && --scanTicks <= 0) { - // If the actor hasn't moved since the activity was issued - if (!hasMoved) - autoTarget.ResetScanTimer(); - - if (--scanTicks <= 0) - { - var attackActivity = autoTarget.ScanAndAttack(self); - if (attackActivity != null) - { - if (!hasMoved) - return attackActivity; - - self.QueueActivity(false, attackActivity); - } - scanTicks = ScanInterval; - } + autoTarget.ScanAndAttack(self); + scanTicks = ScanInterval; } - hasMoved = true; - if (inner == null) return NextActivity; diff --git a/OpenRA.Mods.RA/Attack/AttackBase.cs b/OpenRA.Mods.RA/Attack/AttackBase.cs index 046925c518..dd5fd1053e 100644 --- a/OpenRA.Mods.RA/Attack/AttackBase.cs +++ b/OpenRA.Mods.RA/Attack/AttackBase.cs @@ -134,7 +134,7 @@ namespace OpenRA.Mods.RA return; self.SetTargetLine(target, Color.Red); - self.QueueActivity(false, AttackTarget(target, true)); + AttackTarget(target, order.Queued, true); } } @@ -160,12 +160,15 @@ namespace OpenRA.Mods.RA public Armament ChooseArmamentForTarget(Target t) { return Armaments.FirstOrDefault(a => a.Weapon.IsValidAgainst(t, self.World, self)); } - public Activity AttackTarget(Target target, bool allowMove) + public void AttackTarget(Target target, bool queued, bool allowMove) { if (!target.IsValidFor(self)) - return null; + return; - return GetAttackActivity(self, target, allowMove); + if (!queued) + self.CancelActivity(); + + self.QueueActivity(GetAttackActivity(self, target, allowMove)); } public bool IsReachableTarget(Target target, bool allowMove) diff --git a/OpenRA.Mods.RA/AutoTarget.cs b/OpenRA.Mods.RA/AutoTarget.cs index c0510222e5..9eaf2acbed 100644 --- a/OpenRA.Mods.RA/AutoTarget.cs +++ b/OpenRA.Mods.RA/AutoTarget.cs @@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA Aggressor = attacker; if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend)) - self.QueueActivity(false, Attack(self, Aggressor)); + Attack(self, Aggressor); } public void TickIdle(Actor self) @@ -111,13 +111,7 @@ namespace OpenRA.Mods.RA var allowMovement = info.AllowMovement && Stance != UnitStance.Defend; if (at == null || !at.IsReachableTarget(at.Target, allowMovement)) - { - var act = ScanAndAttack(self); - if (act != null) - { - self.QueueActivity(false, act); - } - } + ScanAndAttack(self); } public void Tick(Actor self) @@ -138,25 +132,19 @@ namespace OpenRA.Mods.RA return currentTarget; } - public void ResetScanTimer() - { - nextScanTime = 0; - } - - public Activity ScanAndAttack(Actor self) + public void ScanAndAttack(Actor self) { var targetActor = ScanForTarget(self, null); if (targetActor != null) - return Attack(self, targetActor); - return null; + Attack(self, targetActor); } - Activity Attack(Actor self, Actor targetActor) + void Attack(Actor self, Actor targetActor) { TargetedActor = targetActor; var target = Target.FromActor(targetActor); self.SetTargetLine(target, Color.Red, false); - return attack.AttackTarget(target, info.AllowMovement && Stance != UnitStance.Defend); + attack.AttackTarget(target, false, info.AllowMovement && Stance != UnitStance.Defend); } Actor ChooseTarget(Actor self, WRange range)