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)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
return this;
}
if (IsCanceling)
return NextActivity;
if (harv.IsFull)
{
// HACK: DeliverResources is ignored if there are queued activities, so discard NextActivity
return ActivityUtils.SequenceActivities(self, new DeliverResources(self));
}
return NextActivity;
var closestHarvestablePosition = ClosestHarvestablePos(self);
@@ -65,43 +68,43 @@ namespace OpenRA.Mods.Common.Activities
if (!closestHarvestablePosition.HasValue)
{
if (!harv.IsEmpty)
return new DeliverResources(self);
return NextActivity;
harv.LastSearchFailed = true;
var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell);
var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5);
self.QueueActivity(mobile.MoveTo(moveTo, 1));
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);
var randFrames = self.World.SharedRandom.Next(100, 175);
// Avoid creating an activity cycle
var next = NextActivity;
NextActivity = null;
return ActivityUtils.SequenceActivities(self, next, new Wait(randFrames), this);
QueueChild(self, mobile.MoveTo(moveTo, 1), true);
QueueChild(self, new Wait(randFrames));
return this;
}
else
// Attempt to claim the target cell
if (!claimLayer.TryClaimCell(self, closestHarvestablePosition.Value))
{
// Attempt to claim the target cell
if (!claimLayer.TryClaimCell(self, closestHarvestablePosition.Value))
return ActivityUtils.SequenceActivities(self, new Wait(25), this);
harv.LastSearchFailed = false;
// If not given a direct order, assume ordered to the first resource location we find:
if (!harv.LastOrderLocation.HasValue)
harv.LastOrderLocation = closestHarvestablePosition;
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
n.MovingToResources(self, closestHarvestablePosition.Value, this);
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, new Wait(25), true);
return this;
}
harv.LastSearchFailed = false;
// If not given a direct order, assume ordered to the first resource location we find:
if (!harv.LastOrderLocation.HasValue)
harv.LastOrderLocation = closestHarvestablePosition;
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
n.MovingToResources(self, closestHarvestablePosition.Value, new FindResources(self));
self.SetTargetLine(Target.FromCell(self.World, closestHarvestablePosition.Value), Color.Red, false);
QueueChild(self, mobile.MoveTo(closestHarvestablePosition.Value, 1), true);
QueueChild(self, new HarvestResource(self));
return this;
}
/// <summary>

View File

@@ -36,6 +36,12 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
return this;
}
if (IsCanceling)
{
claimLayer.RemoveClaim(self);
@@ -56,7 +62,10 @@ namespace OpenRA.Mods.Common.Activities
var current = facing.Facing;
var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
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);
@@ -71,7 +80,8 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
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);
idleSmart = true;
if (!order.Queued)
self.CancelActivity();
CPos loc;
if (order.Target.Type != TargetType.Invalid)
{
@@ -416,7 +413,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(Target.FromCell(self.World, loc), Color.Red);
// FindResources takes care of calling INotifyHarvesterAction
self.QueueActivity(new FindResources(self));
self.QueueActivity(order.Queued, new FindResources(self));
LastOrderLocation = loc;
@@ -442,11 +439,7 @@ namespace OpenRA.Mods.Common.Traits
idleSmart = true;
self.SetTargetLine(order.Target, Color.Green);
if (!order.Queued)
self.CancelActivity();
self.QueueActivity(new DeliverResources(self));
self.QueueActivity(order.Queued, new DeliverResources(self));
foreach (var n in notifyHarvesterAction)
n.MovingToRefinery(self, targetActor, null);