Cancel carryall transport request when cancelling order.

This commit is contained in:
tovl
2019-07-21 17:37:47 +02:00
committed by teinarss
parent 9ac3d7507c
commit d9e1a68453
4 changed files with 33 additions and 8 deletions

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -21,12 +22,14 @@ namespace OpenRA.Mods.Common.Activities
readonly IMove movement; readonly IMove movement;
readonly Harvester harv; readonly Harvester harv;
readonly Actor targetActor; readonly Actor targetActor;
readonly INotifyHarvesterAction[] notifyHarvesterActions;
public DeliverResources(Actor self, Actor targetActor = null) public DeliverResources(Actor self, Actor targetActor = null)
{ {
movement = self.Trait<IMove>(); movement = self.Trait<IMove>();
harv = self.Trait<Harvester>(); harv = self.Trait<Harvester>();
this.targetActor = targetActor; this.targetActor = targetActor;
notifyHarvesterActions = self.TraitsImplementing<INotifyHarvesterAction>().ToArray();
} }
protected override void OnFirstRun(Actor self) protected override void OnFirstRun(Actor self)
@@ -57,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities
self.SetTargetLine(Target.FromActor(proc), Color.Green, false); self.SetTargetLine(Target.FromActor(proc), Color.Green, false);
if (self.Location != proc.Location + iao.DeliveryOffset) if (self.Location != proc.Location + iao.DeliveryOffset)
{ {
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var n in notifyHarvesterActions)
n.MovingToRefinery(self, proc); n.MovingToRefinery(self, proc);
QueueChild(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0)); QueueChild(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0));
@@ -68,5 +71,13 @@ namespace OpenRA.Mods.Common.Activities
iao.OnDock(self, this); iao.OnDock(self, this);
return true; return true;
} }
public override void Cancel(Actor self, bool keepQueue = false)
{
foreach (var n in notifyHarvesterActions)
n.MovementCancelled(self);
base.Cancel(self, keepQueue);
}
} }
} }

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -26,6 +27,7 @@ namespace OpenRA.Mods.Common.Activities
readonly BodyOrientation body; readonly BodyOrientation body;
readonly IMove move; readonly IMove move;
readonly CPos targetCell; readonly CPos targetCell;
readonly INotifyHarvesterAction[] notifyHarvesterActions;
public HarvestResource(Actor self, CPos targetCell) public HarvestResource(Actor self, CPos targetCell)
{ {
@@ -37,6 +39,7 @@ namespace OpenRA.Mods.Common.Activities
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>(); claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
resLayer = self.World.WorldActor.Trait<ResourceLayer>(); resLayer = self.World.WorldActor.Trait<ResourceLayer>();
this.targetCell = targetCell; this.targetCell = targetCell;
notifyHarvesterActions = self.TraitsImplementing<INotifyHarvesterAction>().ToArray();
} }
protected override void OnFirstRun(Actor self) protected override void OnFirstRun(Actor self)
@@ -55,7 +58,7 @@ namespace OpenRA.Mods.Common.Activities
// Move towards the target cell // Move towards the target cell
if (self.Location != targetCell) if (self.Location != targetCell)
{ {
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var n in notifyHarvesterActions)
n.MovingToResources(self, targetCell); n.MovingToResources(self, targetCell);
self.SetTargetLine(Target.FromCell(self.World, targetCell), Color.Red, false); self.SetTargetLine(Target.FromCell(self.World, targetCell), Color.Red, false);
@@ -84,7 +87,7 @@ namespace OpenRA.Mods.Common.Activities
harv.AcceptResource(self, resource); harv.AcceptResource(self, resource);
foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var t in notifyHarvesterActions)
t.Harvested(self, resource); t.Harvested(self, resource);
QueueChild(new Wait(harvInfo.BaleLoadDelay)); QueueChild(new Wait(harvInfo.BaleLoadDelay));
@@ -95,5 +98,13 @@ namespace OpenRA.Mods.Common.Activities
{ {
claimLayer.RemoveClaim(self); claimLayer.RemoveClaim(self);
} }
public override void Cancel(Actor self, bool keepQueue = false)
{
foreach (var n in notifyHarvesterActions)
n.MovementCancelled(self);
base.Cancel(self, keepQueue);
}
} }
} }

View File

@@ -141,6 +141,14 @@ namespace OpenRA.Mods.Common.Activities
return false; return false;
} }
public override void Cancel(Actor self, bool keepQueue = false)
{
foreach (var t in transportCallers)
t.MovementCancelled(self);
base.Cancel(self, keepQueue);
}
void OnResupplyEnding(Actor self) void OnResupplyEnding(Actor self)
{ {
if (aircraft != null) if (aircraft != null)

View File

@@ -365,11 +365,6 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(order.Target, Color.Green); self.SetTargetLine(order.Target, Color.Green);
self.QueueActivity(order.Queued, new FindAndDeliverResources(self, targetActor)); self.QueueActivity(order.Queued, new FindAndDeliverResources(self, targetActor));
} }
else if (order.OrderString == "Stop" || order.OrderString == "Move")
{
foreach (var n in notifyHarvesterAction)
n.MovementCancelled(self);
}
} }
PipType GetPipAt(int i) PipType GetPipAt(int i)