Avoid units continuing to follow the unattackable targets
This commit is contained in:
@@ -43,6 +43,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
this.target = target;
|
||||
this.forceAttack = forceAttack;
|
||||
this.targetLineColor = targetLineColor;
|
||||
ChildHasPriority = false;
|
||||
|
||||
aircraft = self.Trait<Aircraft>();
|
||||
attackAircraft = self.Trait<AttackAircraft>();
|
||||
@@ -73,6 +74,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (!IsCanceling && !HasArmamentsFor(target))
|
||||
Cancel(self, true);
|
||||
|
||||
if (!TickChild(self))
|
||||
return false;
|
||||
|
||||
returnToBase = false;
|
||||
|
||||
// Refuse to take off if it would land immediately again.
|
||||
@@ -198,6 +205,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
|
||||
}
|
||||
}
|
||||
|
||||
bool HasArmamentsFor(Target target)
|
||||
{
|
||||
return !attackAircraft.IsTraitDisabled && attackAircraft.ChooseArmamentsForTarget(target, forceAttack).Any();
|
||||
}
|
||||
}
|
||||
|
||||
sealed class FlyAttackRun : Activity
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
this.target = target;
|
||||
this.targetLineColor = targetLineColor;
|
||||
this.forceAttack = forceAttack;
|
||||
ChildHasPriority = false;
|
||||
|
||||
attackTraits = self.TraitsImplementing<AttackFrontal>().ToArray().Where(t => !t.IsTraitDisabled);
|
||||
revealsShroud = self.TraitsImplementing<RevealsShroud>().ToArray();
|
||||
@@ -94,15 +95,15 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (!IsCanceling && !HasArmamentsFor(target))
|
||||
Cancel(self, true);
|
||||
|
||||
if (!TickChild(self))
|
||||
return false;
|
||||
|
||||
if (IsCanceling)
|
||||
return true;
|
||||
|
||||
if (!attackTraits.Any())
|
||||
{
|
||||
Cancel(self);
|
||||
return false;
|
||||
}
|
||||
|
||||
target = RecalculateTarget(self, out var targetIsHiddenActor);
|
||||
|
||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||
@@ -273,5 +274,10 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (targetLineColor != null)
|
||||
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
|
||||
}
|
||||
|
||||
bool HasArmamentsFor(Target target)
|
||||
{
|
||||
return attackTraits.Any(attack => attack.ChooseArmamentsForTarget(target, forceAttack).Any());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,6 +263,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.targetLineColor = targetLineColor;
|
||||
this.source = source;
|
||||
isAircraft = self.Info.HasTraitInfo<AircraftInfo>();
|
||||
ChildHasPriority = false;
|
||||
|
||||
// The target may become hidden between the initial order request and the first tick (e.g. if queued)
|
||||
// Moving to any position (even if quite stale) is still better than immediately giving up
|
||||
@@ -288,6 +289,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (!IsCanceling && !HasArmamentsFor(target))
|
||||
Cancel(self, true);
|
||||
|
||||
if (!TickChild(self))
|
||||
return false;
|
||||
|
||||
returnToBase = false;
|
||||
|
||||
if (IsCanceling)
|
||||
@@ -440,6 +447,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
|
||||
}
|
||||
}
|
||||
|
||||
bool HasArmamentsFor(Target target)
|
||||
{
|
||||
return !attack.IsTraitDisabled && attack.ChooseArmamentsForTarget(target, forceAttack).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user