Drop targets when switching to a more restrictive stance.
This commit is contained in:
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
{
|
||||
return new LeapAttack(self, newTarget, allowMove, this, info);
|
||||
return new LeapAttack(self, newTarget, allowMove, forceAttack, this, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,18 +75,20 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
|
||||
{
|
||||
return new ChargeAttack(this, newTarget);
|
||||
return new ChargeAttack(this, newTarget, forceAttack);
|
||||
}
|
||||
|
||||
class ChargeAttack : Activity
|
||||
class ChargeAttack : Activity, IActivityNotifyStanceChanged
|
||||
{
|
||||
readonly AttackTesla attack;
|
||||
readonly Target target;
|
||||
readonly bool forceAttack;
|
||||
|
||||
public ChargeAttack(AttackTesla attack, Target target)
|
||||
public ChargeAttack(AttackTesla attack, Target target, bool forceAttack)
|
||||
{
|
||||
this.attack = attack;
|
||||
this.target = target;
|
||||
this.forceAttack = forceAttack;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -114,6 +116,26 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
QueueChild(self, new ChargeFire(attack, target));
|
||||
return this;
|
||||
}
|
||||
|
||||
void IActivityNotifyStanceChanged.StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance)
|
||||
{
|
||||
// Cancel non-forced targets when switching to a more restrictive stance if they are no longer valid for auto-targeting
|
||||
if (newStance > oldStance || forceAttack)
|
||||
return;
|
||||
|
||||
if (target.Type == TargetType.Actor)
|
||||
{
|
||||
var a = target.Actor;
|
||||
if (!autoTarget.HasValidTargetPriority(self, a.Owner, a.GetEnabledTargetTypes()))
|
||||
Cancel(self, true);
|
||||
}
|
||||
else if (target.Type == TargetType.FrozenActor)
|
||||
{
|
||||
var fa = target.FrozenActor;
|
||||
if (!autoTarget.HasValidTargetPriority(self, fa.Owner, fa.TargetTypes))
|
||||
Cancel(self, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChargeFire : Activity
|
||||
|
||||
Reference in New Issue
Block a user