From 018777472a2c86d27af997ce1568cf7b804b8585 Mon Sep 17 00:00:00 2001 From: Gustas Date: Sat, 21 Oct 2023 23:20:44 +0300 Subject: [PATCH] Fix harvesters teleporting when produced And allow to interrupt actor creation child activities --- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 16 ++++++++-------- OpenRA.Mods.Common/Traits/Mobile.cs | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 0f395084d7..afe1af773d 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -1236,7 +1236,6 @@ namespace OpenRA.Mods.Common.Traits public AssociateWithAirfieldActivity(Actor self, int delay, CPos[] rallyPoint) { aircraft = self.Trait(); - IsInterruptible = false; this.delay = delay; this.rallyPoint = rallyPoint; } @@ -1245,25 +1244,26 @@ namespace OpenRA.Mods.Common.Traits { var host = aircraft.GetActorBelow(); if (host != null) + { aircraft.MakeReservation(host); + // Freshly created aircraft shouldn't block the exit, so we allow them to yield their reservation. + aircraft.AllowYieldingReservation(); + } + if (delay > 0) QueueChild(new Wait(delay)); } public override bool Tick(Actor self) { - if (!aircraft.Info.TakeOffOnCreation) - { - // Freshly created aircraft shouldn't block the exit, so we allow them to yield their reservation - aircraft.AllowYieldingReservation(); + if (!aircraft.Info.TakeOffOnCreation || IsCanceling) return true; - } - if (rallyPoint != null && aircraft.Info.TakeOffOnCreation) + if (rallyPoint != null && rallyPoint.Length > 0) { foreach (var cell in rallyPoint) - self.QueueActivity(new AttackMoveActivity(self, () => aircraft.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed))); + QueueChild(new AttackMoveActivity(self, () => aircraft.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed))); } else if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length <= aircraft.LandAltitude.Length) QueueChild(new TakeOff(self)); diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index fc5a867016..6d59c7b112 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -979,7 +979,6 @@ namespace OpenRA.Mods.Common.Traits public LeaveProductionActivity(Actor self, int delay, CPos[] rallyPoint, ReturnToCellActivity returnToCell) { mobile = self.Trait(); - IsInterruptible = false; this.delay = delay; this.rallyPoint = rallyPoint; this.returnToCell = returnToCell; @@ -987,14 +986,15 @@ namespace OpenRA.Mods.Common.Traits protected override void OnFirstRun(Actor self) { + // It is vital that ReturnToCell is queued first as it needs the power to intercept a possible cancellation of this activity. if (returnToCell != null) - self.QueueActivity(returnToCell); + QueueChild(returnToCell); else if (delay > 0) - self.QueueActivity(new Wait(delay)); + QueueChild(new Wait(delay)); if (rallyPoint != null) foreach (var cell in rallyPoint) - self.QueueActivity(new AttackMoveActivity(self, () => mobile.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed))); + QueueChild(new AttackMoveActivity(self, () => mobile.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed))); } }