From 75736cb127335393576f3ede2dbe4b6d8cb2ed7c Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 29 Jan 2016 02:26:45 +0100 Subject: [PATCH 1/3] Clean up Harvester and FindResources unblocking --- OpenRA.Mods.Common/Activities/FindResources.cs | 15 ++++----------- OpenRA.Mods.Common/Traits/Harvester.cs | 11 ----------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/FindResources.cs b/OpenRA.Mods.Common/Activities/FindResources.cs index 2fe14e0451..07600143c1 100644 --- a/OpenRA.Mods.Common/Activities/FindResources.cs +++ b/OpenRA.Mods.Common/Activities/FindResources.cs @@ -67,17 +67,10 @@ namespace OpenRA.Mods.Common.Activities if (!harv.IsEmpty) return deliver; - var cachedPosition = self.Location; - harv.UnblockRefinery(self); - - // Only do this if UnblockRefinery did nothing. - if (self.Location == cachedPosition) - { - var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell); - var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5); - self.QueueActivity(mobile.MoveTo(moveTo, 1)); - self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); - } + var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell); + var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5); + self.QueueActivity(mobile.MoveTo(moveTo, 1)); + self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); var randFrames = self.World.SharedRandom.Next(100, 175); return ActivityUtils.SequenceActivities(NextActivity, new Wait(randFrames), this); diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index b1c81497a0..3050955dc7 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -215,17 +215,6 @@ namespace OpenRA.Mods.Common.Traits var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5); self.QueueActivity(mobile.MoveTo(moveTo, 1)); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); - - var territory = self.World.WorldActor.TraitOrDefault(); - if (territory != null) - territory.ClaimResource(self, moveTo); - - var notify = self.TraitsImplementing(); - var next = new FindResources(self); - foreach (var n in notify) - n.MovingToResources(self, moveTo, next); - - self.QueueActivity(next); } } } From 1f35a1c0101e7e15be853b37dcaabad586f5cea2 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 29 Jan 2016 02:30:06 +0100 Subject: [PATCH 2/3] Let harvesters tick idle for a while before queueing Wait activity --- OpenRA.Mods.Common/Traits/Harvester.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 3050955dc7..77c2e393d0 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -57,6 +57,12 @@ 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.")] + public readonly int WaitDuration = 25; + [VoiceReference] public readonly string HarvestVoice = "Action"; [VoiceReference] public readonly string DeliverVoice = "Action"; @@ -239,6 +245,7 @@ namespace OpenRA.Mods.Common.Traits } } + int idleDuration; public void TickIdle(Actor self) { // Should we be intelligent while idle? @@ -252,9 +259,16 @@ namespace OpenRA.Mods.Common.Traits } UnblockRefinery(self); + idleDuration += 1; - // Wait for a bit before becoming idle again: - self.QueueActivity(new Wait(10)); + // Wait a bit before queueing Wait activity + if (idleDuration > Info.MaxIdleDuration) + { + idleDuration = 0; + + // Wait for a bit before becoming idle again: + self.QueueActivity(new Wait(Info.WaitDuration)); + } } // Returns true when unloading is complete From ed3c0799d3c7b4932f16c3f6c6b9ce5f65665978 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 29 Jan 2016 02:27:43 +0100 Subject: [PATCH 3/3] Do not consider waiting harvesters to be idle --- OpenRA.Mods.Common/AI/HackyAI.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/AI/HackyAI.cs b/OpenRA.Mods.Common/AI/HackyAI.cs index a31ed06dab..4cdcb37f07 100644 --- a/OpenRA.Mods.Common/AI/HackyAI.cs +++ b/OpenRA.Mods.Common/AI/HackyAI.cs @@ -702,9 +702,7 @@ namespace OpenRA.Mods.Common.AI { var act = harvester.GetCurrentActivity(); - // A Wait activity is technically idle: - if ((act.GetType() != typeof(Wait)) && - (act.NextActivity == null || act.NextActivity.GetType() != typeof(FindResources))) + if (act.NextActivity == null || act.NextActivity.GetType() != typeof(FindResources)) continue; }