diff --git a/OpenRA.Mods.Common/Activities/CaptureActor.cs b/OpenRA.Mods.Common/Activities/CaptureActor.cs index 03d9bb654d..9ffc7fe0ee 100644 --- a/OpenRA.Mods.Common/Activities/CaptureActor.cs +++ b/OpenRA.Mods.Common/Activities/CaptureActor.cs @@ -136,9 +136,10 @@ namespace OpenRA.Mods.Common.Activities base.OnActorDispose(self); } - protected override void OnCancel(Actor self) + public override void Cancel(Actor self, bool keepQueue = false) { CancelCapture(self); + base.Cancel(self, keepQueue); } void CancelCapture(Actor self) diff --git a/OpenRA.Mods.Common/Activities/Enter.cs b/OpenRA.Mods.Common/Activities/Enter.cs index 6e4a1ba86e..a8f26db520 100644 --- a/OpenRA.Mods.Common/Activities/Enter.cs +++ b/OpenRA.Mods.Common/Activities/Enter.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Activities public abstract class Enter : Activity { - enum EnterState { Approaching, Waiting, Entering, Exiting } + enum EnterState { Approaching, Entering, Exiting } readonly IMove move; readonly Color? targetLineColor; @@ -57,12 +57,6 @@ namespace OpenRA.Mods.Common.Activities /// protected virtual void OnEnterComplete(Actor self, Actor targetActor) { } - /// - /// Called when the activity is cancelled to allow subclasses to clean up their own state. - /// - protected virtual void OnCancel(Actor self) { } - - Activity moveActivity; public override Activity Tick(Actor self) { // Update our view of the target @@ -86,10 +80,10 @@ namespace OpenRA.Mods.Common.Activities // We need to wait for movement to finish before transitioning to // the next state or next activity - if (moveActivity != null) + if (ChildActivity != null) { - moveActivity = ActivityUtils.RunActivity(self, moveActivity); - if (moveActivity != null) + ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); + if (ChildActivity != null) return this; } @@ -97,7 +91,6 @@ namespace OpenRA.Mods.Common.Activities switch (lastState) { case EnterState.Approaching: - case EnterState.Waiting: { // NOTE: We can safely cancel in this case because we know the // actor has finished any in-progress move activities @@ -111,12 +104,10 @@ namespace OpenRA.Mods.Common.Activities // We are not next to the target - lets fix that if (target.Type != TargetType.Invalid && !move.CanEnterTargetNow(self, target)) { - lastState = EnterState.Approaching; - // Target lines are managed by this trait, so we do not pass targetLineColor var initialTargetPosition = (useLastVisibleTarget ? lastVisibleTarget : target).CenterPosition; - moveActivity = ActivityUtils.RunActivity(self, move.MoveToTarget(self, target, initialTargetPosition)); - break; + QueueChild(self, move.MoveToTarget(self, target, initialTargetPosition), true); + return this; } // We are next to where we thought the target should be, but it isn't here @@ -128,7 +119,7 @@ namespace OpenRA.Mods.Common.Activities if (TryStartEnter(self, target.Actor)) { lastState = EnterState.Entering; - moveActivity = ActivityUtils.RunActivity(self, move.MoveIntoTarget(self, target)); + QueueChild(self, move.MoveIntoTarget(self, target), true); return this; } @@ -137,8 +128,7 @@ namespace OpenRA.Mods.Common.Activities if (IsCanceling) return NextActivity; - lastState = EnterState.Waiting; - break; + return this; } case EnterState.Entering: @@ -149,8 +139,8 @@ namespace OpenRA.Mods.Common.Activities OnEnterComplete(self, target.Actor); lastState = EnterState.Exiting; - moveActivity = ActivityUtils.RunActivity(self, move.MoveIntoWorld(self, self.Location)); - break; + QueueChild(self, move.MoveIntoWorld(self, self.Location), true); + return this; } case EnterState.Exiting: @@ -159,15 +149,5 @@ namespace OpenRA.Mods.Common.Activities return this; } - - public override void Cancel(Actor self, bool keepQueue = false) - { - OnCancel(self); - - if (!IsCanceling && moveActivity != null) - moveActivity.Cancel(self); - - base.Cancel(self, keepQueue); - } } } diff --git a/OpenRA.Mods.Common/Activities/EnterTransport.cs b/OpenRA.Mods.Common/Activities/EnterTransport.cs index dc4e09788b..6fc335ab5d 100644 --- a/OpenRA.Mods.Common/Activities/EnterTransport.cs +++ b/OpenRA.Mods.Common/Activities/EnterTransport.cs @@ -68,14 +68,16 @@ namespace OpenRA.Mods.Common.Activities }); } - protected override void OnCancel(Actor self) + protected override void OnLastRun(Actor self) { passenger.Unreserve(self); } - protected override void OnLastRun(Actor self) + public override void Cancel(Actor self, bool keepQueue = false) { passenger.Unreserve(self); + + base.Cancel(self, keepQueue); } } @@ -84,23 +86,21 @@ namespace OpenRA.Mods.Common.Activities readonly string type; readonly Passenger passenger; - Activity enterTransport; - public EnterTransports(Actor self, Target primaryTarget) { passenger = self.Trait(); if (primaryTarget.Type == TargetType.Actor) type = primaryTarget.Actor.Info.Name; - enterTransport = new EnterTransport(self, primaryTarget); + QueueChild(self, new EnterTransport(self, primaryTarget)); } public override Activity Tick(Actor self) { - if (enterTransport != null) + if (ChildActivity != null) { - enterTransport = ActivityUtils.RunActivity(self, enterTransport); - if (enterTransport != null) + ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); + if (ChildActivity != null) return this; } @@ -126,19 +126,11 @@ namespace OpenRA.Mods.Common.Activities if (transport != null) { - enterTransport = ActivityUtils.RunActivity(self, new EnterTransport(self, Target.FromActor(transport))); + QueueChild(self, ActivityUtils.RunActivity(self, new EnterTransport(self, Target.FromActor(transport))), true); return this; } return NextActivity; } - - public override void Cancel(Actor self, bool keepQueue = false) - { - if (!IsCanceling && enterTransport != null) - enterTransport.Cancel(self); - - base.Cancel(self, keepQueue); - } } }