Skip to content

Commit

Permalink
Fix attack behaviour of disabled units.
Browse files Browse the repository at this point in the history
  • Loading branch information
extmind authored and pchote committed Mar 30, 2019
1 parent 19977bb commit 522dad3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
11 changes: 10 additions & 1 deletion OpenRA.Mods.Common/Activities/Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
Expand Down Expand Up @@ -200,8 +201,16 @@ protected virtual AttackStatus TickAttack(Actor self, AttackFrontal attack)
}

attackStatus |= AttackStatus.Attacking;
attack.DoAttack(self, target, armaments);
DoAttack(self, attack, armaments);

return AttackStatus.Attacking;
}

protected virtual void DoAttack(Actor self, AttackFrontal attack, IEnumerable<Armament> armaments)
{
if (!attack.IsTraitPaused)
foreach (var a in armaments)
a.CheckFire(self, facing, target);
}
}
}
8 changes: 4 additions & 4 deletions OpenRA.Mods.Common/Traits/Attack/AttackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ protected virtual bool CanAttack(Actor self, Target target)
return true;
}

public virtual void DoAttack(Actor self, Target target, IEnumerable<Armament> armaments = null)
public virtual void DoAttack(Actor self, Target target)
{
if (armaments == null && !CanAttack(self, target))
if (!CanAttack(self, target))
return;

foreach (var a in armaments ?? Armaments)
foreach (var a in Armaments)
a.CheckFire(self, facing, target);
}

Expand Down Expand Up @@ -350,7 +350,7 @@ public IEnumerable<Armament> ChooseArmamentsForTarget(Target t, bool forceAttack

public void AttackTarget(Target target, bool queued, bool allowMove, bool forceAttack = false)
{
if (IsTraitDisabled || IsTraitPaused)
if (IsTraitDisabled)
return;

if (!target.IsValidFor(self))
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ WVec PortOffset(Actor self, FirePort p)
return coords.Value.LocalToWorld(p.Offset.Rotate(bodyOrientation));
}

public override void DoAttack(Actor self, Target target, IEnumerable<Armament> armaments = null)
public override void DoAttack(Actor self, Target target)
{
if (!CanAttack(self, target))
return;
Expand Down
7 changes: 6 additions & 1 deletion OpenRA.Mods.D2k/Traits/AttackSwallow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AttackSwallow(Actor self, AttackSwallowInfo info)
Info = info;
}

public override void DoAttack(Actor self, Target target, IEnumerable<Armament> armaments = null)
public override void DoAttack(Actor self, Target target)
{
// This is so that the worm does not launch an attack against a target that has reached solid rock
if (target.Type != TargetType.Actor || !CanAttack(self, target))
Expand Down Expand Up @@ -86,6 +86,11 @@ protected override Target RecalculateTarget(Actor self, out bool targetIsHiddenA
targetIsHiddenActor = false;
return target;
}

protected override void DoAttack(Actor self, AttackFrontal attack, IEnumerable<Armament> armaments)
{
attack.DoAttack(self, target);
}
}
}
}

0 comments on commit 522dad3

Please sign in to comment.