Gets AttackMove to work with 'Defend' stance

This commit is contained in:
Matija Hustić
2015-10-09 23:22:59 +02:00
parent 50679cd6c4
commit 2a0a7541ba

View File

@@ -104,8 +104,9 @@ namespace OpenRA.Mods.Common.Traits
return; return;
Aggressor = attacker; Aggressor = attacker;
if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend)) var allowMove = info.AllowMovement && Stance != UnitStance.Defend;
Attack(self, Aggressor); if (at == null || !at.IsReachableTarget(at.Target, allowMove))
Attack(self, Aggressor, allowMove);
} }
public void TickIdle(Actor self) public void TickIdle(Actor self)
@@ -113,9 +114,9 @@ namespace OpenRA.Mods.Common.Traits
if (Stance < UnitStance.Defend || !info.TargetWhenIdle) if (Stance < UnitStance.Defend || !info.TargetWhenIdle)
return; return;
var allowMovement = info.AllowMovement && Stance != UnitStance.Defend; var allowMove = info.AllowMovement && Stance != UnitStance.Defend;
if (at == null || !at.IsReachableTarget(at.Target, allowMovement)) if (at == null || !at.IsReachableTarget(at.Target, allowMove))
ScanAndAttack(self, allowMovement); ScanAndAttack(self, allowMove);
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -143,15 +144,15 @@ namespace OpenRA.Mods.Common.Traits
{ {
var targetActor = ScanForTarget(self, null, allowMove); var targetActor = ScanForTarget(self, null, allowMove);
if (targetActor != null) if (targetActor != null)
Attack(self, targetActor); Attack(self, targetActor, allowMove);
} }
void Attack(Actor self, Actor targetActor) void Attack(Actor self, Actor targetActor, bool allowMove)
{ {
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);
attack.AttackTarget(target, false, info.AllowMovement && Stance != UnitStance.Defend); attack.AttackTarget(target, false, allowMove);
} }
Actor ChooseTarget(Actor self, WDist range, bool allowMove) Actor ChooseTarget(Actor self, WDist range, bool allowMove)
@@ -168,10 +169,16 @@ namespace OpenRA.Mods.Common.Traits
// Select only the first compatible armament for each actor: if this actor is selected // Select only the first compatible armament for each actor: if this actor is selected
// it will be thanks to the first armament anyways, since that is the first selection // it will be thanks to the first armament anyways, since that is the first selection
// criterion // criterion
.Select(a => new KeyValuePair<Armament, Actor>( .Select(a =>
attack.ChooseArmamentsForTarget(Target.FromActor(a), false) {
.Where(arm => allowMove || arm.MaxRange().Length > (a.CenterPosition - self.CenterPosition).Length) var target = Target.FromActor(a);
.FirstOrDefault(), a)) return new KeyValuePair<Armament, Actor>(
attack.ChooseArmamentsForTarget(target, false)
.Where(arm => allowMove
|| (target.IsInRange(self.CenterPosition, arm.MaxRange())
&& !target.IsInRange(self.CenterPosition, arm.Weapon.MinRange)))
.FirstOrDefault(), a);
})
.Where(kv => kv.Key != null && kv.Value.TraitOrDefault<AutoTargetIgnore>() == null) .Where(kv => kv.Key != null && kv.Value.TraitOrDefault<AutoTargetIgnore>() == null)
.GroupBy(kv => kv.Key, kv => kv.Value) .GroupBy(kv => kv.Key, kv => kv.Value)