From 9993a235a743bf28be50d96a0e48cf80ca277a30 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 8 Dec 2016 21:48:12 +0100 Subject: [PATCH] Convert ResupplyAircraft into a CompositeActivity --- .../Activities/Air/ResupplyAircraft.cs | 73 +++++++------------ 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs b/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs index 7068c907db..9a92ef28b7 100644 --- a/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs +++ b/OpenRA.Mods.Common/Activities/Air/ResupplyAircraft.cs @@ -16,59 +16,40 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Activities { - public class ResupplyAircraft : Activity + public class ResupplyAircraft : CompositeActivity { - readonly Aircraft aircraft; - Activity inner; + public ResupplyAircraft(Actor self) { } - public ResupplyAircraft(Actor self) + protected override void OnFirstRun(Actor self) { - aircraft = self.Trait(); + var aircraft = self.Trait(); + var host = aircraft.GetActorBelow(); + + if (host == null) + return; + + if (aircraft.IsPlane) + { + ChildActivity = ActivityUtils.SequenceActivities( + aircraft.GetResupplyActivities(host) + .Append(new AllowYieldingReservation(self)) + .Append(new WaitFor(() => NextInQueue != null || aircraft.ReservedActor == null)) + .ToArray()); + } + else + { + // Helicopters should take off from their helipad immediately after resupplying. + // HACK: Append NextInQueue to TakeOff to avoid moving to the Rallypoint (if NextInQueue is non-null). + ChildActivity = ActivityUtils.SequenceActivities( + aircraft.GetResupplyActivities(host) + .Append(new AllowYieldingReservation(self)) + .Append(new TakeOff(self)).Append(NextInQueue).ToArray()); + } } public override Activity Tick(Actor self) { - if (IsCanceled) - return NextActivity; - - if (inner == null) - { - var host = aircraft.GetActorBelow(); - - if (host == null) - return NextActivity; - - if (aircraft.IsPlane) - { - inner = ActivityUtils.SequenceActivities( - aircraft.GetResupplyActivities(host) - .Append(new AllowYieldingReservation(self)) - .Append(new WaitFor(() => NextInQueue != null || aircraft.ReservedActor == null)) - .ToArray()); - } - else - { - // Helicopters should take off from their helipad immediately after resupplying. - // HACK: Append NextInQueue to TakeOff to avoid moving to the Rallypoint (if NextInQueue is non-null). - inner = ActivityUtils.SequenceActivities( - aircraft.GetResupplyActivities(host) - .Append(new AllowYieldingReservation(self)) - .Append(new TakeOff(self)).Append(NextInQueue).ToArray()); - } - } - else - inner = ActivityUtils.RunActivity(self, inner); - - // The inner == NextInQueue check is needed here because of the TakeOff issue mentioned in the comment above. - return inner == null || inner == NextInQueue ? NextActivity : this; - } - - public override bool Cancel(Actor self) - { - if (!IsCanceled && inner != null && !inner.Cancel(self)) - return false; - - return base.Cancel(self); + return NextActivity; } } }