harvester Harvest order works with queues

fix for autocarryable harvesters

Make use of QueueActivity's own handling of order.Queued
This commit is contained in:
tovl
2019-02-09 23:30:23 +01:00
committed by reaperrr
parent 307a87cd9e
commit 3bfa32ca33
3 changed files with 45 additions and 39 deletions

View File

@@ -49,14 +49,17 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
return this;
}
if (IsCanceling) if (IsCanceling)
return NextActivity; return NextActivity;
if (harv.IsFull) if (harv.IsFull)
{ return NextActivity;
// HACK: DeliverResources is ignored if there are queued activities, so discard NextActivity
return ActivityUtils.SequenceActivities(self, new DeliverResources(self));
}
var closestHarvestablePosition = ClosestHarvestablePos(self); var closestHarvestablePosition = ClosestHarvestablePos(self);
@@ -65,30 +68,29 @@ namespace OpenRA.Mods.Common.Activities
if (!closestHarvestablePosition.HasValue) if (!closestHarvestablePosition.HasValue)
{ {
if (!harv.IsEmpty) if (!harv.IsEmpty)
return new DeliverResources(self); return NextActivity;
harv.LastSearchFailed = true; harv.LastSearchFailed = true;
var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell); var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell);
var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5); var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5);
self.QueueActivity(mobile.MoveTo(moveTo, 1));
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
n.MovingToResources(self, moveTo, this); n.MovingToResources(self, moveTo, new FindResources(self));
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
var randFrames = self.World.SharedRandom.Next(100, 175); var randFrames = self.World.SharedRandom.Next(100, 175);
QueueChild(self, mobile.MoveTo(moveTo, 1), true);
// Avoid creating an activity cycle QueueChild(self, new Wait(randFrames));
var next = NextActivity; return this;
NextActivity = null;
return ActivityUtils.SequenceActivities(self, next, new Wait(randFrames), this);
} }
else
{
// Attempt to claim the target cell // Attempt to claim the target cell
if (!claimLayer.TryClaimCell(self, closestHarvestablePosition.Value)) if (!claimLayer.TryClaimCell(self, closestHarvestablePosition.Value))
return ActivityUtils.SequenceActivities(self, new Wait(25), this); {
QueueChild(self, new Wait(25), true);
return this;
}
harv.LastSearchFailed = false; harv.LastSearchFailed = false;
@@ -97,11 +99,12 @@ namespace OpenRA.Mods.Common.Activities
harv.LastOrderLocation = closestHarvestablePosition; harv.LastOrderLocation = closestHarvestablePosition;
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
n.MovingToResources(self, closestHarvestablePosition.Value, this); n.MovingToResources(self, closestHarvestablePosition.Value, new FindResources(self));
self.SetTargetLine(Target.FromCell(self.World, closestHarvestablePosition.Value), Color.Red, false); self.SetTargetLine(Target.FromCell(self.World, closestHarvestablePosition.Value), Color.Red, false);
return ActivityUtils.SequenceActivities(self, mobile.MoveTo(closestHarvestablePosition.Value, 1), new HarvestResource(self), this); QueueChild(self, mobile.MoveTo(closestHarvestablePosition.Value, 1), true);
} QueueChild(self, new HarvestResource(self));
return this;
} }
/// <summary> /// <summary>

View File

@@ -36,6 +36,12 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
return this;
}
if (IsCanceling) if (IsCanceling)
{ {
claimLayer.RemoveClaim(self); claimLayer.RemoveClaim(self);
@@ -56,7 +62,10 @@ namespace OpenRA.Mods.Common.Activities
var current = facing.Facing; var current = facing.Facing;
var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings); var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
if (desired != current) if (desired != current)
return ActivityUtils.SequenceActivities(self, new Turn(self, desired), this); {
QueueChild(self, new Turn(self, desired), true);
return this;
}
} }
var resource = resLayer.Harvest(self.Location); var resource = resLayer.Harvest(self.Location);
@@ -71,7 +80,8 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
t.Harvested(self, resource); t.Harvested(self, resource);
return ActivityUtils.SequenceActivities(self, new Wait(harvInfo.BaleLoadDelay), this); QueueChild(self, new Wait(harvInfo.BaleLoadDelay), true);
return this;
} }
} }
} }

View File

@@ -397,9 +397,6 @@ namespace OpenRA.Mods.Common.Traits
LinkProc(self, OwnerLinkedProc = null); LinkProc(self, OwnerLinkedProc = null);
idleSmart = true; idleSmart = true;
if (!order.Queued)
self.CancelActivity();
CPos loc; CPos loc;
if (order.Target.Type != TargetType.Invalid) if (order.Target.Type != TargetType.Invalid)
{ {
@@ -416,7 +413,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(Target.FromCell(self.World, loc), Color.Red); self.SetTargetLine(Target.FromCell(self.World, loc), Color.Red);
// FindResources takes care of calling INotifyHarvesterAction // FindResources takes care of calling INotifyHarvesterAction
self.QueueActivity(new FindResources(self)); self.QueueActivity(order.Queued, new FindResources(self));
LastOrderLocation = loc; LastOrderLocation = loc;
@@ -442,11 +439,7 @@ namespace OpenRA.Mods.Common.Traits
idleSmart = true; idleSmart = true;
self.SetTargetLine(order.Target, Color.Green); self.SetTargetLine(order.Target, Color.Green);
self.QueueActivity(order.Queued, new DeliverResources(self));
if (!order.Queued)
self.CancelActivity();
self.QueueActivity(new DeliverResources(self));
foreach (var n in notifyHarvesterAction) foreach (var n in notifyHarvesterAction)
n.MovingToRefinery(self, targetActor, null); n.MovingToRefinery(self, targetActor, null);