harvester Deliver order works with queues
This commit is contained in:
@@ -30,12 +30,17 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
movement = self.Trait<IMove>();
|
||||
harv = self.Trait<Harvester>();
|
||||
IsInterruptible = false;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (NextActivity != null)
|
||||
if (ChildActivity != null)
|
||||
{
|
||||
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
|
||||
return this;
|
||||
}
|
||||
|
||||
if (IsCanceling || isDocking)
|
||||
return NextActivity;
|
||||
|
||||
// Find the nearest best refinery if not explicitly ordered to a specific refinery:
|
||||
@@ -57,7 +62,10 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
// No refineries exist; check again after delay defined in Harvester.
|
||||
if (harv.LinkedProc == null)
|
||||
return ActivityUtils.SequenceActivities(self, new Wait(harv.Info.SearchForDeliveryBuildingDelay), this);
|
||||
{
|
||||
QueueChild(self, new Wait(harv.Info.SearchForDeliveryBuildingDelay), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
var proc = harv.LinkedProc;
|
||||
var iao = proc.Trait<IAcceptResources>();
|
||||
@@ -68,16 +76,19 @@ namespace OpenRA.Mods.Common.Activities
|
||||
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
|
||||
n.MovingToRefinery(self, proc, null);
|
||||
|
||||
return ActivityUtils.SequenceActivities(self, movement.MoveTo(proc.Location + iao.DeliveryOffset, 0), this);
|
||||
QueueChild(self, movement.MoveTo(proc.Location + iao.DeliveryOffset, 0), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!isDocking)
|
||||
{
|
||||
QueueChild(self, new Wait(10), true);
|
||||
isDocking = true;
|
||||
iao.OnDock(self, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
return ActivityUtils.SequenceActivities(self, new Wait(10), this);
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public abstract class HarvesterDockSequence : Activity
|
||||
{
|
||||
protected enum DockingState { Wait, Turn, Dock, Loop, Undock, Complete }
|
||||
protected enum DockingState { Wait, Turn, Dock, Loop, Undock, Complete, Finished }
|
||||
|
||||
protected readonly Actor Refinery;
|
||||
protected readonly Harvester Harv;
|
||||
@@ -47,34 +47,54 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (ChildActivity != null)
|
||||
{
|
||||
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
|
||||
return this;
|
||||
}
|
||||
|
||||
switch (dockingState)
|
||||
{
|
||||
case DockingState.Wait:
|
||||
return this;
|
||||
|
||||
case DockingState.Turn:
|
||||
dockingState = DockingState.Dock;
|
||||
QueueChild(self, new Turn(self, DockAngle), true);
|
||||
if (IsDragRequired)
|
||||
return ActivityUtils.SequenceActivities(self, new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this);
|
||||
return ActivityUtils.SequenceActivities(self, new Turn(self, DockAngle), this);
|
||||
QueueChild(self, new Drag(self, StartDrag, EndDrag, DragLength));
|
||||
return this;
|
||||
|
||||
case DockingState.Dock:
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
||||
nd.Docked(Refinery, self);
|
||||
|
||||
return OnStateDock(self);
|
||||
|
||||
case DockingState.Loop:
|
||||
if (!Refinery.IsInWorld || Refinery.IsDead || Harv.TickUnload(self, Refinery))
|
||||
dockingState = DockingState.Undock;
|
||||
|
||||
return this;
|
||||
|
||||
case DockingState.Undock:
|
||||
return OnStateUndock(self);
|
||||
|
||||
case DockingState.Complete:
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
||||
nd.Undocked(Refinery, self);
|
||||
|
||||
Harv.LastLinkedProc = Harv.LinkedProc;
|
||||
Harv.LinkProc(self, null);
|
||||
if (IsDragRequired)
|
||||
return ActivityUtils.SequenceActivities(self, new Drag(self, EndDrag, StartDrag, DragLength), NextActivity);
|
||||
QueueChild(self, new Drag(self, EndDrag, StartDrag, DragLength), true);
|
||||
|
||||
dockingState = DockingState.Finished;
|
||||
return this;
|
||||
|
||||
case DockingState.Finished:
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,12 +144,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!preventDock)
|
||||
{
|
||||
dockOrder.Queue(self, new CallFunc(() => dockedHarv = harv, false));
|
||||
dockOrder.Queue(self, DockSequence(harv, self));
|
||||
dockOrder.Queue(self, new CallFunc(() => dockedHarv = null, false));
|
||||
dockOrder.QueueChild(self, new CallFunc(() => dockedHarv = harv, false));
|
||||
dockOrder.QueueChild(self, DockSequence(harv, self));
|
||||
dockOrder.QueueChild(self, new CallFunc(() => dockedHarv = null, false));
|
||||
}
|
||||
|
||||
dockOrder.Queue(self, new CallFunc(() => harv.Trait<Harvester>().ContinueHarvesting(harv)));
|
||||
dockOrder.QueueChild(self, new CallFunc(() => harv.Trait<Harvester>().ContinueHarvesting(harv)));
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
|
||||
@@ -397,6 +397,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
LinkProc(self, OwnerLinkedProc = null);
|
||||
idleSmart = true;
|
||||
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
CPos loc;
|
||||
@@ -442,7 +443,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
self.SetTargetLine(order.Target, Color.Green);
|
||||
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.QueueActivity(new DeliverResources(self));
|
||||
|
||||
foreach (var n in notifyHarvesterAction)
|
||||
|
||||
Reference in New Issue
Block a user