Merge pull request #9581 from matija-hustic/attackmove_defendstance

Gets AttackMove to work with 'Defend' stance
This commit is contained in:
Matthias Mailänder
2015-10-11 21:28:35 +02:00
2 changed files with 21 additions and 15 deletions

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)

View File

@@ -2200,9 +2200,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (engineVersion < 20151005) if (engineVersion < 20151005)
{ {
// Move certain properties from Parachutable to new WithParachute trait // Units with AutoHeal have it replaced by AutoTarget
// Add dependency traits to actors implementing Parachutable
// Make otherwise targetable parachuting actors untargetable
var heal = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AutoHeal")); var heal = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AutoHeal"));
if (heal != null) if (heal != null)
{ {
@@ -2219,6 +2217,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
node.Value.Nodes.Remove(heal); node.Value.Nodes.Remove(heal);
} }
// Units with AttackMedic have it replaced by an appropriate AttackFrontal
var atkmedic = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AttackMedic")); var atkmedic = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AttackMedic"));
if (atkmedic != null) if (atkmedic != null)
{ {