diff --git a/OpenRA.Mods.Common/Activities/FindResources.cs b/OpenRA.Mods.Common/Activities/FindResources.cs index 96eea3915f..5991920004 100644 --- a/OpenRA.Mods.Common/Activities/FindResources.cs +++ b/OpenRA.Mods.Common/Activities/FindResources.cs @@ -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()) - 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()) - 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()) + 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; } /// diff --git a/OpenRA.Mods.Common/Activities/HarvestResource.cs b/OpenRA.Mods.Common/Activities/HarvestResource.cs index 6d246b4eef..4ecdaac9a0 100644 --- a/OpenRA.Mods.Common/Activities/HarvestResource.cs +++ b/OpenRA.Mods.Common/Activities/HarvestResource.cs @@ -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()) t.Harvested(self, resource); - return ActivityUtils.SequenceActivities(self, new Wait(harvInfo.BaleLoadDelay), this); + QueueChild(self, new Wait(harvInfo.BaleLoadDelay), true); + return this; } } } diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index b6db5283a1..9be0846273 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -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);