diff --git a/OpenRA.Mods.Common/Activities/DeliverUnit.cs b/OpenRA.Mods.Common/Activities/DeliverUnit.cs index d13c9768cd..8285bc867b 100644 --- a/OpenRA.Mods.Common/Activities/DeliverUnit.cs +++ b/OpenRA.Mods.Common/Activities/DeliverUnit.cs @@ -26,10 +26,9 @@ namespace OpenRA.Mods.Common.Activities readonly IFacing carryallFacing; readonly CPos destination; - enum DeliveryState { Transport, Land, Wait, Release, TakeOff, Aborted } + enum DeliveryState { Transport, Land, Wait, Release, TakeOff, Done, Aborted } DeliveryState state; - Activity innerActivity; public DeliverUnit(Actor self, CPos destination) { @@ -77,10 +76,11 @@ namespace OpenRA.Mods.Common.Activities public override Activity Tick(Actor self) { - if (innerActivity != null) + if (ChildActivity != null) { - innerActivity = ActivityUtils.RunActivity(self, innerActivity); - return this; + ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); + if (ChildActivity != null) + return this; } if (IsCanceling) @@ -98,10 +98,8 @@ namespace OpenRA.Mods.Common.Activities // Can't land, so wait at the target until something changes if (!targetLocation.HasValue) { - innerActivity = ActivityUtils.SequenceActivities(self, - new HeliFly(self, Target.FromCell(self.World, destination)), - new Wait(25)); - + QueueChild(self, new HeliFly(self, Target.FromCell(self.World, destination)), true); + QueueChild(self, new Wait(25)); return this; } @@ -117,14 +115,12 @@ namespace OpenRA.Mods.Common.Activities { var facing = (targetPosition - self.CenterPosition).Yaw.Facing; localOffset = carryall.CarryableOffset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(facing))); - innerActivity = ActivityUtils.SequenceActivities(self, - new HeliFly(self, Target.FromPos(targetPosition - body.LocalToWorld(localOffset))), - new Turn(self, facing)); - + QueueChild(self, new HeliFly(self, Target.FromPos(targetPosition - body.LocalToWorld(localOffset))), true); + QueueChild(self, new Turn(self, facing)); return this; } - innerActivity = new HeliFly(self, Target.FromPos(targetPosition)); + QueueChild(self, new HeliFly(self, Target.FromPos(targetPosition)), true); return this; } @@ -145,7 +141,7 @@ namespace OpenRA.Mods.Common.Activities var carryablePosition = self.CenterPosition + body.LocalToWorld(localOffset); if (self.World.Map.DistanceAboveTerrain(carryablePosition) != WDist.Zero) { - innerActivity = new HeliLand(self, false, -new WDist(carryall.CarryableOffset.Z)); + QueueChild(self, new HeliLand(self, false, -new WDist(carryall.CarryableOffset.Z)), true); return this; } @@ -155,7 +151,7 @@ namespace OpenRA.Mods.Common.Activities case DeliveryState.Wait: state = DeliveryState.Release; - innerActivity = new Wait(carryall.Info.UnloadingDelay, false); + QueueChild(self, new Wait(carryall.Info.UnloadingDelay, false), true); return this; case DeliveryState.Release: @@ -170,7 +166,9 @@ namespace OpenRA.Mods.Common.Activities return this; case DeliveryState.TakeOff: - return ActivityUtils.SequenceActivities(self, new HeliFly(self, Target.FromPos(self.CenterPosition)), NextActivity); + QueueChild(self, new HeliFly(self, Target.FromPos(self.CenterPosition)), true); + state = DeliveryState.Done; + return this; case DeliveryState.Aborted: carryall.UnreserveCarryable(self); @@ -205,13 +203,5 @@ namespace OpenRA.Mods.Common.Activities carryable.Detached(cargo); }); } - - public override void Cancel(Actor self, bool keepQueue = false) - { - if (!IsCanceling && innerActivity != null) - innerActivity.Cancel(self); - - base.Cancel(self); - } } } diff --git a/OpenRA.Mods.Common/Activities/PickupUnit.cs b/OpenRA.Mods.Common/Activities/PickupUnit.cs index 42c0a2f0b7..54147d9291 100644 --- a/OpenRA.Mods.Common/Activities/PickupUnit.cs +++ b/OpenRA.Mods.Common/Activities/PickupUnit.cs @@ -33,7 +33,6 @@ namespace OpenRA.Mods.Common.Activities enum PickupState { Intercept, LockCarryable, MoveToCarryable, Turn, Land, Wait, Pickup, Aborted } PickupState state; - Activity innerActivity; public PickupUnit(Actor self, Actor cargo, int delay) { @@ -52,10 +51,11 @@ namespace OpenRA.Mods.Common.Activities public override Activity Tick(Actor self) { - if (innerActivity != null) + if (ChildActivity != null) { - innerActivity = ActivityUtils.RunActivity(self, innerActivity); - return this; + ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); + if (ChildActivity != null) + return this; } if (cargo != carryall.Carryable) @@ -73,8 +73,7 @@ namespace OpenRA.Mods.Common.Activities switch (state) { case PickupState.Intercept: - innerActivity = movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4), - targetLineColor: Color.Yellow); + QueueChild(self, movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4), targetLineColor: Color.Yellow), true); state = PickupState.LockCarryable; return this; @@ -91,8 +90,7 @@ namespace OpenRA.Mods.Common.Activities var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset); if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0) { - // Run the first tick of the move activity immediately to avoid a one-frame pause - innerActivity = ActivityUtils.RunActivity(self, new HeliFly(self, Target.FromPos(targetPosition))); + QueueChild(self, new HeliFly(self, Target.FromPos(targetPosition)), true); return this; } @@ -103,7 +101,7 @@ namespace OpenRA.Mods.Common.Activities case PickupState.Turn: if (carryallFacing.Facing != carryableFacing.Facing) { - innerActivity = new Turn(self, carryableFacing.Facing); + QueueChild(self, new Turn(self, carryableFacing.Facing), true); return this; } @@ -122,7 +120,7 @@ namespace OpenRA.Mods.Common.Activities if (targetPosition.Z != self.CenterPosition.Z) { - innerActivity = new HeliLand(self, false, self.World.Map.DistanceAboveTerrain(targetPosition)); + QueueChild(self, new HeliLand(self, false, self.World.Map.DistanceAboveTerrain(targetPosition)), true); return this; } @@ -132,7 +130,7 @@ namespace OpenRA.Mods.Common.Activities case PickupState.Wait: state = PickupState.Pickup; - innerActivity = new Wait(delay, false); + QueueChild(self, new Wait(delay, false), true); return this; case PickupState.Pickup: @@ -158,13 +156,5 @@ namespace OpenRA.Mods.Common.Activities carryall.AttachCarryable(self, cargo); }); } - - public override void Cancel(Actor self, bool keepQueue = false) - { - if (!IsCanceling && innerActivity != null) - innerActivity.Cancel(self); - - base.Cancel(self, keepQueue); - } } }