Let autocarryall switch destination when carryable switches destination.

This commit is contained in:
tovl
2019-07-17 23:27:17 +02:00
committed by teinarss
parent 231825d0d0
commit 0e62490d57

View File

@@ -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<Carryall>().Info.DropRange;
var destination = cargo.Trait<Carryable>().Destination;
if (destination != null)
self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, destination.Value), dropRange));
return true;
}
}
}
}