Skip to content

Commit

Permalink
Disable AutoTarget damage response if targeting a persistent fallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed May 17, 2019
1 parent 8d8b81c commit c3d75b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions OpenRA.Mods.Common/Activities/Air/FlyAttack.cs
Expand Up @@ -68,6 +68,7 @@ public override Activity Tick(Actor self)
{
attackAircraft.OpportunityTarget = attackAircraft.RequestedTarget;
attackAircraft.OpportunityForceAttack = attackAircraft.RequestedForceAttack;
attackAircraft.OpportunityTargetIsPersistentTarget = true;
}

attackAircraft.RequestedTarget = Target.Invalid;
Expand Down
1 change: 1 addition & 0 deletions OpenRA.Mods.Common/Activities/Air/HeliAttack.cs
Expand Up @@ -66,6 +66,7 @@ public override Activity Tick(Actor self)
{
attackAircraft.OpportunityTarget = attackAircraft.RequestedTarget;
attackAircraft.OpportunityForceAttack = attackAircraft.RequestedForceAttack;
attackAircraft.OpportunityTargetIsPersistentTarget = true;
}

attackAircraft.RequestedTarget = Target.Invalid;
Expand Down
17 changes: 16 additions & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs
Expand Up @@ -29,14 +29,16 @@ public class AttackFollowInfo : AttackBaseInfo
public override object Create(ActorInitializer init) { return new AttackFollow(init.Self, this); }
}

public class AttackFollow : AttackBase, INotifyOwnerChanged
public class AttackFollow : AttackBase, INotifyOwnerChanged, IDisableAutoTarget
{
public new readonly AttackFollowInfo Info;
public Target RequestedTarget;
public bool RequestedForceAttack;
public int RequestedTargetLastTick;
public Target OpportunityTarget;
public bool OpportunityForceAttack;
public bool OpportunityTargetIsPersistentTarget;

Mobile mobile;
AutoTarget autoTarget;

Expand Down Expand Up @@ -74,7 +76,10 @@ protected bool CanAimAtTarget(Actor self, Target target, bool forceAttack)
protected override void Tick(Actor self)
{
if (IsTraitDisabled)
{
RequestedTarget = OpportunityTarget = Target.Invalid;
OpportunityTargetIsPersistentTarget = false;
}

if (RequestedTargetLastTick != self.World.WorldTick)
{
Expand Down Expand Up @@ -106,6 +111,7 @@ protected override void Tick(Actor self)
{
OpportunityTarget = autoTarget.ScanForTarget(self, false, false);
OpportunityForceAttack = false;
OpportunityTargetIsPersistentTarget = false;

if (OpportunityTarget.Type != TargetType.Invalid)
IsAiming = CanAimAtTarget(self, OpportunityTarget, OpportunityForceAttack);
Expand Down Expand Up @@ -139,12 +145,20 @@ public override void OnQueueAttackActivity(Actor self, Target target, bool queue
public override void OnStopOrder(Actor self)
{
RequestedTarget = OpportunityTarget = Target.Invalid;
OpportunityTargetIsPersistentTarget = false;
base.OnStopOrder(self);
}

void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
RequestedTarget = OpportunityTarget = Target.Invalid;
OpportunityTargetIsPersistentTarget = false;
}

bool IDisableAutoTarget.DisableAutoTarget(Actor self)
{
return RequestedTarget.Type != TargetType.Invalid ||
(OpportunityTargetIsPersistentTarget && OpportunityTarget.Type != TargetType.Invalid);
}

class AttackActivity : Activity
Expand Down Expand Up @@ -198,6 +212,7 @@ public override Activity Tick(Actor self)
{
attack.OpportunityTarget = attack.RequestedTarget;
attack.OpportunityForceAttack = attack.RequestedForceAttack;
attack.OpportunityTargetIsPersistentTarget = true;
}

attack.RequestedTarget = Target.Invalid;
Expand Down

0 comments on commit c3d75b0

Please sign in to comment.