Refactor TakeOff

- Make it self-contained by moving actual take-off
  from 'Fly' to this
- Make 'moveToRallyPoint' a simple boolean
- Make AttackMove to rally point a child activity
- Make TakeOff uninterruptible
This commit is contained in:
reaperrr
2019-05-23 18:45:37 +02:00
committed by Paul Chote
parent 4f8f8cfb9d
commit ce3d7c98ad
4 changed files with 74 additions and 48 deletions

View File

@@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Activities
Target target;
Target lastVisibleTarget;
bool useLastVisibleTarget;
bool soundPlayed;
public Fly(Actor self, Target t, WPos? initialTargetPosition = null, Color? targetLineColor = null)
{
@@ -103,6 +102,13 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -110,6 +116,13 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceling)
return NextActivity;
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
if (dat <= aircraft.LandAltitude)
{
QueueChild(self, new TakeOff(self, target), true);
return this;
}
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
@@ -126,25 +139,6 @@ namespace OpenRA.Mods.Common.Activities
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return NextActivity;
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
// We are taking off, so remove influence in ground cells.
if (dat <= aircraft.LandAltitude)
{
if (!soundPlayed && aircraft.Info.TakeoffSounds.Length > 0)
{
Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition);
soundPlayed = true;
}
aircraft.RemoveInfluence();
}
// If we're a VTOL, rise before flying forward
if (aircraft.Info.VTOL)
if (VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude))
return this;
var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;
var delta = checkTarget.CenterPosition - self.CenterPosition;
var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing;
@@ -188,10 +182,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
// Don't turn until we've reached the cruise altitude
if (dat < aircraft.Info.CruiseAltitude)
desiredFacing = aircraft.Facing;
else if (!aircraft.Info.CanHover)
if (!aircraft.Info.CanHover)
{
// Using the turn rate, compute a hypothetical circle traced by a continuous turn.
// If it contains the destination point, it's unreachable without more complex manuvering.