Add missing carryall checks

This commit is contained in:
Gustas
2023-05-21 15:02:27 +03:00
committed by Pavel Penev
parent a69417f0a6
commit c7e0bc4c08
3 changed files with 13 additions and 8 deletions

View File

@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Activities
protected override void OnFirstRun(Actor self) protected override void OnFirstRun(Actor self)
{ {
// The cargo might have become invalid while we were moving towards it. // 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; return;
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>

View File

@@ -106,30 +106,31 @@ namespace OpenRA.Mods.Common.Traits
{ {
readonly Actor cargo; readonly Actor cargo;
readonly Carryable carryable; readonly Carryable carryable;
readonly CarryallInfo carryallInfo; readonly Carryall carryall;
public FerryUnit(Actor self, Actor cargo) public FerryUnit(Actor self, Actor cargo)
{ {
this.cargo = cargo; this.cargo = cargo;
carryable = cargo.Trait<Carryable>(); carryable = cargo.Trait<Carryable>();
carryallInfo = self.Trait<Carryall>().Info; carryall = self.Trait<Carryall>();
} }
protected override void OnFirstRun(Actor self) protected override void OnFirstRun(Actor self)
{ {
if (!cargo.IsDead) 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) 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; return true;
var dropRange = carryallInfo.DropRange; var dropRange = carryall.Info.DropRange;
var destination = carryable.Destination; var destination = carryable.Destination;
if (destination != null) 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; return true;
} }

View File

@@ -256,7 +256,11 @@ namespace OpenRA.Mods.Common.Traits
public virtual void UnreserveCarryable(Actor self) public virtual void UnreserveCarryable(Actor self)
{ {
if (Carryable != null && Carryable.IsInWorld && !Carryable.IsDead) if (Carryable != null && Carryable.IsInWorld && !Carryable.IsDead)
Carryable.Trait<Carryable>().UnReserve(Carryable); {
var carryable = Carryable.Trait<Carryable>();
if (carryable.Carrier == self)
carryable.UnReserve(Carryable);
}
Carryable = null; Carryable = null;
State = CarryallState.Idle; State = CarryallState.Idle;