From 92b3dde789cd90d922e09a98cd3291eaf6c2b2e7 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sat, 10 May 2025 12:18:37 +0100 Subject: [PATCH] When pathing, prefer optimal paths over short distances. The default path weight of 125% allows paths up to 25% longer than the optimal path to be returned, which improves the performance of path searches. Over short distances, players are likely to be sensitive to suboptimal paths this can produce, so instead use a weight of 100% over short distances to ensure these paths are optimal. As the search area is limited, the additional performance impact is also capped. The hierarchical path finder already has a speculative check for short paths within a 20 cell area (twice the grid size of 10 cells), which allows it to skip a hierarchical search if a path within that area can be found. We can piggy back on this short path logic and use a weight of 100%. Over longer distances, players are less likely to notice the suboptimal paths, and the performance benefit is more noticeable, so continue to use the 125% weight in these scenarios. --- OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs index 65cc26e7bb..28d7bca440 100644 --- a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs +++ b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs @@ -849,9 +849,13 @@ namespace OpenRA.Mods.Common.Pathfinder pathFinderOverlay?.NewRecording(self, [source], target); + // For paths over a short distance, use a heuristic weight of 100% to force the shortest path to be returned. + // We do this as players are likely to be sensitive to suboptimal paths over short distances. + // So we prefer optimal paths over suboptimal ones. + // Since we have a limited search area, we don't mind the additional performance impact. List localPath; using (var search = GetLocalPathSearch( - self, [source], target, customCost, ignoreActor, check, laneBias, gridToSearch, heuristicWeightPercentage, + self, [source], target, customCost, ignoreActor, check, laneBias, gridToSearch, 100, null, inReverse, pathFinderOverlay?.RecordLocalEdges(self)))