diff --git a/OpenRA.Mods.Common/Traits/AutoCarryall.cs b/OpenRA.Mods.Common/Traits/AutoCarryall.cs index d7c930ca81..c1204aaa60 100644 --- a/OpenRA.Mods.Common/Traits/AutoCarryall.cs +++ b/OpenRA.Mods.Common/Traits/AutoCarryall.cs @@ -10,6 +10,7 @@ #endregion using System.Linq; +using OpenRA.Activities; using OpenRA.Mods.Common.Activities; using OpenRA.Traits; @@ -42,8 +43,7 @@ namespace OpenRA.Mods.Common.Traits if (ReserveCarryable(self, carryable)) { - self.QueueActivity(false, new PickupUnit(self, carryable, 0)); - self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, destination), Info.DropRange)); + self.QueueActivity(false, new FerryUnit(self, carryable)); return true; } @@ -96,11 +96,35 @@ namespace OpenRA.Mods.Common.Traits if (IsBestAutoCarryallForCargo(self, p.Actor) && ReserveCarryable(self, p.Actor)) { busy = true; - self.QueueActivity(false, new PickupUnit(self, p.Actor, 0)); - self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, p.Trait.Destination.Value), Info.DropRange)); + self.QueueActivity(false, new FerryUnit(self, p.Actor)); break; } } } + + class FerryUnit : Activity + { + readonly Actor cargo; + + public FerryUnit(Actor self, Actor cargo) + { + this.cargo = cargo; + } + + protected override void OnFirstRun(Actor self) + { + QueueChild(new PickupUnit(self, cargo, 0)); + } + + public override bool Tick(Actor self) + { + var dropRange = self.Trait().Info.DropRange; + var destination = cargo.Trait().Destination; + if (destination != null) + self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, destination.Value), dropRange)); + + return true; + } + } } }