Skip to content

Commit

Permalink
Improve ReturnToBase Activity.cs adherance
Browse files Browse the repository at this point in the history
And make it use child activities for queueability.
  • Loading branch information
reaperrr committed Mar 10, 2019
1 parent 679d830 commit d44ddae
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs
Expand Up @@ -129,6 +129,12 @@ public override Activity Tick(Actor self)
if (IsCanceling || self.IsDead)
return NextActivity;

if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
return this;
}

if (dest == null || dest.IsDead || !Reservable.IsAvailableFor(dest, self))
dest = ReturnToBase.ChooseResupplier(self, true);

Expand All @@ -150,28 +156,29 @@ public override Activity Tick(Actor self)
if (distanceFromResupplier > distanceLength)
{
var randomPosition = WVec.FromPDF(self.World.SharedRandom, 2) * distanceLength / 1024;

var target = Target.FromPos(nearestResupplier.CenterPosition + randomPosition);

return ActivityUtils.SequenceActivities(self,
new HeliFly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green),
this);
QueueChild(self, new HeliFly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
}

return this;
}
else
return ActivityUtils.SequenceActivities(self,
new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green),
new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport),
this);
{
QueueChild(self, new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
QueueChild(self, new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport));
return this;
}
}
else if (nearestResupplier == null && aircraft.Info.VTOL && aircraft.Info.LandWhenIdle)
{
// Using Queue instead of QueueChild here is intentional, as we want VTOLs with LandWhenIdle to land and stay there in this situation
Cancel(self);
if (aircraft.Info.TurnToLand)
return ActivityUtils.SequenceActivities(self, new Turn(self, aircraft.Info.InitialFacing), new HeliLand(self, true));
Queue(self, new Turn(self, aircraft.Info.InitialFacing));

return new HeliLand(self, true);
Queue(self, new HeliLand(self, true));
return NextActivity;
}
else
{
Expand Down Expand Up @@ -219,7 +226,9 @@ public override Activity Tick(Actor self)
if (!abortOnResupply)
landingProcedures.Add(NextActivity);

return ActivityUtils.SequenceActivities(self, landingProcedures.ToArray());
ChildActivity = ActivityUtils.SequenceActivities(self, landingProcedures.ToArray());

return this;
}
}
}

0 comments on commit d44ddae

Please sign in to comment.