Merge pull request #7169 from pchote/revert-attackmove

Closes #7128
This commit is contained in:
Matthias Mailänder
2014-12-22 09:43:42 +01:00
3 changed files with 17 additions and 44 deletions

View File

@@ -20,42 +20,24 @@ namespace OpenRA.Mods.RA.Activities
{ {
const int ScanInterval = 7; const int ScanInterval = 7;
int scanTicks;
bool hasMoved;
Activity inner; Activity inner;
int scanTicks;
AutoTarget autoTarget; AutoTarget autoTarget;
public AttackMoveActivity(Actor self, Activity inner) public AttackMoveActivity(Actor self, Activity inner)
{ {
this.inner = inner; this.inner = inner;
autoTarget = self.TraitOrDefault<AutoTarget>(); autoTarget = self.TraitOrDefault<AutoTarget>();
hasMoved = false;
} }
public override Activity Tick(Actor self) 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 autoTarget.ScanAndAttack(self);
if (!hasMoved) scanTicks = ScanInterval;
autoTarget.ResetScanTimer();
if (--scanTicks <= 0)
{
var attackActivity = autoTarget.ScanAndAttack(self);
if (attackActivity != null)
{
if (!hasMoved)
return attackActivity;
self.QueueActivity(false, attackActivity);
}
scanTicks = ScanInterval;
}
} }
hasMoved = true;
if (inner == null) if (inner == null)
return NextActivity; return NextActivity;

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Mods.RA
return; return;
self.SetTargetLine(target, Color.Red); 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 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)) 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) public bool IsReachableTarget(Target target, bool allowMove)

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA
Aggressor = attacker; Aggressor = attacker;
if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend)) 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) public void TickIdle(Actor self)
@@ -111,13 +111,7 @@ namespace OpenRA.Mods.RA
var allowMovement = info.AllowMovement && Stance != UnitStance.Defend; var allowMovement = info.AllowMovement && Stance != UnitStance.Defend;
if (at == null || !at.IsReachableTarget(at.Target, allowMovement)) if (at == null || !at.IsReachableTarget(at.Target, allowMovement))
{ ScanAndAttack(self);
var act = ScanAndAttack(self);
if (act != null)
{
self.QueueActivity(false, act);
}
}
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -138,25 +132,19 @@ namespace OpenRA.Mods.RA
return currentTarget; return currentTarget;
} }
public void ResetScanTimer() public void ScanAndAttack(Actor self)
{
nextScanTime = 0;
}
public Activity ScanAndAttack(Actor self)
{ {
var targetActor = ScanForTarget(self, null); var targetActor = ScanForTarget(self, null);
if (targetActor != null) if (targetActor != null)
return Attack(self, targetActor); Attack(self, targetActor);
return null;
} }
Activity Attack(Actor self, Actor targetActor) void Attack(Actor self, Actor targetActor)
{ {
TargetedActor = targetActor; TargetedActor = targetActor;
var target = Target.FromActor(targetActor); var target = Target.FromActor(targetActor);
self.SetTargetLine(target, Color.Red, false); 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) Actor ChooseTarget(Actor self, WRange range)