diff --git a/OpenRA.Mods.Common/Activities/FindResources.cs b/OpenRA.Mods.Common/Activities/FindResources.cs index 5991920004..05e643aca7 100644 --- a/OpenRA.Mods.Common/Activities/FindResources.cs +++ b/OpenRA.Mods.Common/Activities/FindResources.cs @@ -67,22 +67,23 @@ namespace OpenRA.Mods.Common.Activities // or get out of the way and do not disturb. if (!closestHarvestablePosition.HasValue) { - if (!harv.IsEmpty) - return NextActivity; - harv.LastSearchFailed = true; + var lastproc = harv.LastLinkedProc ?? harv.LinkedProc; + if (lastproc != null && !lastproc.Disposed) + { + var deliveryLoc = lastproc.Location + lastproc.Trait().DeliveryOffset; + if (self.Location == deliveryLoc && harv.IsEmpty) + { + // Get out of the way: + var unblockCell = deliveryLoc + harv.Info.UnblockCell; + var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5); + self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Green, false); + QueueChild(self, mobile.MoveTo(moveTo, 1), true); + return this; + } + } - var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell); - var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5); - - foreach (var n in self.TraitsImplementing()) - 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); - QueueChild(self, mobile.MoveTo(moveTo, 1), true); - QueueChild(self, new Wait(randFrames)); - return this; + return NextActivity; } // Attempt to claim the target cell diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index c18c4b8dad..4d34acdec4 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -961,6 +961,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs index 3ca4054a40..503037acbf 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs @@ -148,8 +148,6 @@ namespace OpenRA.Mods.Common.Traits dockOrder.QueueChild(self, DockSequence(harv, self)); dockOrder.QueueChild(self, new CallFunc(() => dockedHarv = null, false)); } - - dockOrder.QueueChild(self, new CallFunc(() => harv.Trait().ContinueHarvesting(harv))); } void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 9be0846273..78a56a3c81 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -62,10 +62,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Search radius (in cells) from the last harvest order location to find more resources.")] public readonly int SearchFromOrderRadius = 12; - [Desc("Maximum duration of being idle before queueing a Wait activity.")] - public readonly int MaxIdleDuration = 25; - - [Desc("Duration to wait before becoming idle again.")] + [Desc("Duration to wait before searching for resources again.")] public readonly int WaitDuration = 25; [Desc("Find a new refinery to unload at if more than this many harvesters are already waiting.")] @@ -174,7 +171,6 @@ namespace OpenRA.Mods.Common.Traits public void ContinueHarvesting(Actor self) { // Move out of the refinery dock and continue harvesting - UnblockRefinery(self); self.QueueActivity(new FindResources(self)); } @@ -248,28 +244,6 @@ namespace OpenRA.Mods.Common.Traits UpdateCondition(self); } - public void UnblockRefinery(Actor self) - { - // Check that we're not in a critical location and being useless (refinery drop-off): - var lastproc = LastLinkedProc ?? LinkedProc; - if (lastproc != null && !lastproc.Disposed) - { - var deliveryLoc = lastproc.Location + lastproc.Trait().DeliveryOffset; - if (self.Location == deliveryLoc) - { - // Get out of the way: - var unblockCell = LastHarvestedCell ?? (deliveryLoc + Info.UnblockCell); - var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5); - - // FindResources takes care of calling INotifyHarvesterAction - self.QueueActivity(new FindResources(self)); - - self.QueueActivity(mobile.MoveTo(moveTo, 1)); - self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); - } - } - } - void INotifyBlockingMove.OnNotifyBlockingMove(Actor self, Actor blocking) { // I'm blocking someone else from moving to my location: @@ -303,17 +277,16 @@ namespace OpenRA.Mods.Common.Traits return; } - UnblockRefinery(self); - idleDuration += 1; - - // Wait a bit before queueing Wait activity - if (idleDuration > Info.MaxIdleDuration) + if (LastSearchFailed) { - idleDuration = 0; - - // Wait for a bit before becoming idle again: - self.QueueActivity(new Wait(Info.WaitDuration)); + // Wait a bit before searching again. + idleDuration += 1; + if (idleDuration <= Info.WaitDuration) + return; } + + idleDuration = 0; + self.QueueActivity(new FindResources(self)); } // Returns true when unloading is complete diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20190314/RefactorHarvesterIdle.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20190314/RefactorHarvesterIdle.cs new file mode 100644 index 0000000000..bb3717760c --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20190314/RefactorHarvesterIdle.cs @@ -0,0 +1,49 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class RefactorHarvesterIdle : UpdateRule + { + public override string Name { get { return "Refactor harvester idle behavior."; } } + public override string Description + { + get + { + return "The MaxIdleDuration parameter has been removed from the Harvester trait as part of a\n" + + " refactoring of harvester idling behavior."; + } + } + + readonly List locations = new List(); + + public override IEnumerable AfterUpdate(ModData modData) + { + if (locations.Any()) + yield return "The MaxIdleDuration parameter has been removed from the harvester logic on the following actors:\n" + + UpdateUtils.FormatMessageList(locations) + "\n\n"; + + locations.Clear(); + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + foreach (var t in actorNode.ChildrenMatching("Harvester")) + if (t.RemoveNodes("MaxIdleDuration") > 0) + locations.Add("{0} ({1})".F(actorNode.Key, actorNode.Location.Filename)); + + yield break; + } + } +} \ No newline at end of file diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 4810f699ef..4b97a8f865 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -123,6 +123,7 @@ namespace OpenRA.Mods.Common.UpdateRules new MakeMobilePausableConditional(), new StreamlineRepairableTraits(), new ReplaceSpecialMoveConsiderations(), + new RefactorHarvesterIdle(), }) };