From c7e0bc4c082ebf347d3ae7a72616c99b748ac11c Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Sun, 21 May 2023 15:02:27 +0300 Subject: [PATCH] Add missing carryall checks --- OpenRA.Mods.Common/Activities/PickupUnit.cs | 2 +- OpenRA.Mods.Common/Traits/AutoCarryall.cs | 13 +++++++------ OpenRA.Mods.Common/Traits/Carryall.cs | 6 +++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/PickupUnit.cs b/OpenRA.Mods.Common/Activities/PickupUnit.cs index c265230587..344498bc9b 100644 --- a/OpenRA.Mods.Common/Activities/PickupUnit.cs +++ b/OpenRA.Mods.Common/Activities/PickupUnit.cs @@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Activities protected override void OnFirstRun(Actor self) { // The cargo might have become invalid while we were moving towards it. - if (cargo == null || cargo.IsDead || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self)) + if (cargo == null || cargo.IsDead || carryable.IsTraitDisabled || carryall.Carryable != cargo || !cargo.AppearsFriendlyTo(self)) return; self.World.AddFrameEndTask(w => diff --git a/OpenRA.Mods.Common/Traits/AutoCarryall.cs b/OpenRA.Mods.Common/Traits/AutoCarryall.cs index 189a4e0672..39a7a182e0 100644 --- a/OpenRA.Mods.Common/Traits/AutoCarryall.cs +++ b/OpenRA.Mods.Common/Traits/AutoCarryall.cs @@ -106,30 +106,31 @@ namespace OpenRA.Mods.Common.Traits { readonly Actor cargo; readonly Carryable carryable; - readonly CarryallInfo carryallInfo; + readonly Carryall carryall; public FerryUnit(Actor self, Actor cargo) { this.cargo = cargo; carryable = cargo.Trait(); - carryallInfo = self.Trait().Info; + carryall = self.Trait(); } protected override void OnFirstRun(Actor self) { if (!cargo.IsDead) - QueueChild(new PickupUnit(self, cargo, 0, carryallInfo.TargetLineColor)); + QueueChild(new PickupUnit(self, cargo, 0, carryall.Info.TargetLineColor)); } public override bool Tick(Actor self) { - if (cargo.IsDead) + // Cargo may have become invalid or PickupUnit cancelled. + if (carryall.Carryable == null || carryall.Carryable.IsDead) return true; - var dropRange = carryallInfo.DropRange; + var dropRange = carryall.Info.DropRange; var destination = carryable.Destination; if (destination != null) - self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, destination.Value), dropRange, carryallInfo.TargetLineColor)); + self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, destination.Value), dropRange, carryall.Info.TargetLineColor)); return true; } diff --git a/OpenRA.Mods.Common/Traits/Carryall.cs b/OpenRA.Mods.Common/Traits/Carryall.cs index 653c0350d9..8f03af54c8 100644 --- a/OpenRA.Mods.Common/Traits/Carryall.cs +++ b/OpenRA.Mods.Common/Traits/Carryall.cs @@ -256,7 +256,11 @@ namespace OpenRA.Mods.Common.Traits public virtual void UnreserveCarryable(Actor self) { if (Carryable != null && Carryable.IsInWorld && !Carryable.IsDead) - Carryable.Trait().UnReserve(Carryable); + { + var carryable = Carryable.Trait(); + if (carryable.Carrier == self) + carryable.UnReserve(Carryable); + } Carryable = null; State = CarryallState.Idle;