Skip to content

Commit

Permalink
Merge HeliAttack into FlyAttack
Browse files Browse the repository at this point in the history
And polish CanHover FlyAttack behavior:

- Get rid of direct TickFacing usage
- Fix that the CanHover facing/altitude update would override
  TakeOff child of Fly
- Streamline the queueing of child activities
- Get rid of a direct FlyTick in favor of relying on Fly activity
- Pull queueing of TakeOff out of the if-else
  • Loading branch information
reaperrr authored and pchote committed Jun 8, 2019
1 parent a7617b2 commit 979ed1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 197 deletions.
25 changes: 20 additions & 5 deletions OpenRA.Mods.Common/Activities/Air/FlyAttack.cs
Expand Up @@ -150,14 +150,29 @@ public override Activity Tick(Actor self)
return this;
}

if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraft.Info.MinAirborneAltitude)
var delta = attackAircraft.GetTargetPosition(pos, target) - pos;
var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing;
var isAirborne = self.World.Map.DistanceAboveTerrain(pos).Length >= aircraft.Info.MinAirborneAltitude;

if (!isAirborne)
QueueChild(self, new TakeOff(self), true);

if (attackAircraft != null && target.IsInRange(self.CenterPosition, attackAircraft.GetMinimumRange()))
QueueChild(self, new FlyTimed(ticksUntilTurn, self), true);
if (!aircraft.Info.CanHover)
{
if (target.IsInRange(pos, attackAircraft.GetMinimumRange()))
QueueChild(self, new FlyTimed(ticksUntilTurn, self), true);

QueueChild(self, new Fly(self, target, checkTarget.CenterPosition, Color.Red), true);
QueueChild(self, new FlyTimed(ticksUntilTurn, self));
QueueChild(self, new Fly(self, target, target.CenterPosition, Color.Red), true);
QueueChild(self, new FlyTimed(ticksUntilTurn, self));
}
else
{
var minimumRange = attackAircraft.GetMinimumRangeVersusTarget(target);
if (!target.IsInRange(pos, lastVisibleMaximumRange) || target.IsInRange(pos, minimumRange))
QueueChild(self, new Fly(self, target, minimumRange, lastVisibleMaximumRange, target.CenterPosition, Color.Red), true);
else if (isAirborne) // Don't use 'else' to avoid conflict with TakeOff
Fly.VerticalTakeOffOrLandTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude);
}

return this;
}
Expand Down
189 changes: 0 additions & 189 deletions OpenRA.Mods.Common/Activities/Air/HeliAttack.cs

This file was deleted.

3 changes: 0 additions & 3 deletions OpenRA.Mods.Common/Traits/Air/AttackAircraft.cs
Expand Up @@ -37,9 +37,6 @@ public AttackAircraft(Actor self, AttackAircraftInfo info)

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack)
{
if (aircraftInfo.CanHover)
return new HeliAttack(self, newTarget, forceAttack);

return new FlyAttack(self, newTarget, forceAttack);
}

Expand Down

0 comments on commit 979ed1b

Please sign in to comment.