diff --git a/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs b/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs index 5336bc143e..8f60df95b6 100644 --- a/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs +++ b/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs @@ -36,6 +36,8 @@ namespace OpenRA.Mods.Common.Activities bool hasHarvestedCell; bool hasWaited; + public bool LastSearchFailed { get; private set; } + public FindAndDeliverResources(Actor self, Actor deliverActor = null) { harv = self.Trait(); @@ -86,7 +88,7 @@ namespace OpenRA.Mods.Common.Activities if (NextActivity != null) { // Interrupt automated harvesting after clearing the first cell. - if (!harvInfo.QueueFullLoad && (hasHarvestedCell || harv.LastSearchFailed)) + if (!harvInfo.QueueFullLoad && (hasHarvestedCell || LastSearchFailed)) return true; // Interrupt automated harvesting after first complete harvest cycle. @@ -95,7 +97,7 @@ namespace OpenRA.Mods.Common.Activities } // Are we full or have nothing more to gather? Deliver resources. - if (harv.IsFull || (!harv.IsEmpty && harv.LastSearchFailed)) + if (harv.IsFull || (!harv.IsEmpty && LastSearchFailed)) { QueueChild(new DeliverResources(self)); hasDeliveredLoad = true; @@ -103,7 +105,7 @@ namespace OpenRA.Mods.Common.Activities } // After a failed search, wait and sit still for a bit before searching again. - if (harv.LastSearchFailed && !hasWaited) + if (LastSearchFailed && !hasWaited) { QueueChild(new Wait(harv.Info.WaitDuration)); hasWaited = true; @@ -121,17 +123,17 @@ namespace OpenRA.Mods.Common.Activities { lastHarvestedCell = null; // Forces search from backup position. closestHarvestableCell = ClosestHarvestablePos(self); - harv.LastSearchFailed = !closestHarvestableCell.HasValue; + LastSearchFailed = !closestHarvestableCell.HasValue; } else - harv.LastSearchFailed = true; + LastSearchFailed = true; } else - harv.LastSearchFailed = false; + LastSearchFailed = false; // If no harvestable position could be found and we are at the refinery, get out of the way // of the refinery entrance. - if (harv.LastSearchFailed) + if (LastSearchFailed) { var lastproc = harv.LastLinkedProc ?? harv.LinkedProc; if (lastproc != null && !lastproc.Disposed) diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index 5b4d16c5fc..439568b52e 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -111,8 +111,10 @@ namespace OpenRA.Mods.Common.Traits { if (!h.Key.IsIdle) { - var act = h.Key.CurrentActivity; - if (!h.Value.Harvester.LastSearchFailed || act.NextActivity == null || !(act.NextActivity is FindAndDeliverResources)) + var act = h.Key.CurrentActivity as FindAndDeliverResources; + + // Ignore this actor if FindAndDeliverResources is working fine or it is performing a different activity + if (act == null || !act.LastSearchFailed) continue; } diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 85a69a736f..5771f16bd0 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -103,8 +103,6 @@ namespace OpenRA.Mods.Common.Traits int conditionToken = ConditionManager.InvalidConditionToken; HarvesterResourceMultiplier[] resourceMultipliers; - [Sync] - public bool LastSearchFailed; [Sync] public Actor OwnerLinkedProc = null;