Fixes AttackMove moving even if an enemy is within range.

This commit is contained in:
WolfGaming
2014-12-04 11:14:15 +00:00
parent fb6b9b8be5
commit a155c7b7ac
3 changed files with 44 additions and 17 deletions

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.RA
return;
self.SetTargetLine(target, Color.Red);
AttackTarget(target, order.Queued, true);
self.QueueActivity(false, AttackTarget(target, true));
}
}
@@ -143,15 +143,12 @@ namespace OpenRA.Mods.RA
public Armament ChooseArmamentForTarget(Target t) { return Armaments.FirstOrDefault(a => a.Weapon.IsValidAgainst(t, self.World, self)); }
public void AttackTarget(Target target, bool queued, bool allowMove)
public Activity AttackTarget(Target target, bool allowMove)
{
if (!target.IsValidFor(self))
return;
return null;
if (!queued)
self.CancelActivity();
self.QueueActivity(GetAttackActivity(self, target, allowMove));
return GetAttackActivity(self, target, allowMove);
}
public bool IsReachableTarget(Target target, bool allowMove)

View File

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

View File

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