From da8eb68d9d37361f0a8b1e1479f1302a839f6f67 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 14 Jul 2024 11:40:18 +0100 Subject: [PATCH] AI prefers resources near to a refinery, rather than the idle harvester. When HarvesterBotModule is ordering idle harvesters to nearby resources, it previously scanned from the harvester's current location. Instead, it now scans from the location of the nearest refinery. As the harvester will likely make many runs between the resource and the refinery, it is better to choose a location near the refinery. This will minimise overall distance travelled to harvest the resource patch. --- OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index fcd8b13476..d213a05e82 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -50,6 +50,7 @@ namespace OpenRA.Mods.Common.Traits { public readonly Actor Actor; public readonly Harvester Harvester; + public readonly DockClientManager DockClientManager; public readonly Parachutable Parachutable; public readonly Mobile Mobile; public int NoResourcesCooldown { get; set; } @@ -58,6 +59,7 @@ namespace OpenRA.Mods.Common.Traits { Actor = actor; Harvester = actor.Trait(); + DockClientManager = actor.Trait(); Parachutable = actor.TraitOrDefault(); Mobile = actor.TraitOrDefault(); } @@ -203,6 +205,9 @@ namespace OpenRA.Mods.Common.Traits Target FindNextResource(Actor actor, HarvesterTraitWrapper harv) { + // Prefer resource nearby to the nearest drop off point, otherwise scan from the current location. + var scanFromActor = harv.DockClientManager.ClosestDock(null, ignoreOccupancy: true)?.Actor ?? actor; + var targets = resourceTypesByCell .Where(kvp => harv.Harvester.Info.Resources.Contains(kvp.Value) && @@ -238,7 +243,7 @@ namespace OpenRA.Mods.Common.Traits } var path = harv.Mobile.PathFinder.FindPathToTargetCells( - actor, actor.Location, targets, BlockedByActor.Stationary, + actor, scanFromActor.Location, targets, BlockedByActor.Stationary, loc => { // Avoid areas with enemies.