diff --git a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs index 29e588a96a..f39a6e1f12 100644 --- a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs +++ b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs @@ -414,7 +414,7 @@ namespace OpenRA.Mods.Common.Pathfinder { var src = accessibleCells.First(); using (var search = GetLocalPathSearch( - null, new[] { src }, src, customCost, null, BlockedByActor.None, false, grid, 100)) + null, new[] { src }, src, customCost, null, BlockedByActor.None, false, grid, 100, null, false, null)) { var localCellsInRegion = search.ExpandAll(); var abstractCell = AbstractCellForLocalCells(localCellsInRegion, gridLayer); @@ -725,7 +725,7 @@ namespace OpenRA.Mods.Common.Pathfinder /// public List FindPath(Actor self, IReadOnlyCollection sources, CPos target, BlockedByActor check, int heuristicWeightPercentage, Func customCost, - Actor ignoreActor, bool laneBias, PathFinderOverlay pathFinderOverlay) + Actor ignoreActor, bool inReverse, bool laneBias, PathFinderOverlay pathFinderOverlay) { if (costEstimator == null) return PathFinder.NoPath; @@ -812,8 +812,9 @@ namespace OpenRA.Mods.Common.Pathfinder { using (var fromSrc = GetLocalPathSearch( self, sourcesWithPathableNodes, target, customCost, ignoreActor, check, laneBias, null, heuristicWeightPercentage, - heuristic: Heuristic(reverseAbstractSearch, estimatedSearchSize, sourcesWithPathableNodes, unpathableNodes), - recorder: pathFinderOverlay?.RecordLocalEdges(self))) + Heuristic(reverseAbstractSearch, estimatedSearchSize, sourcesWithPathableNodes, unpathableNodes), + inReverse, + pathFinderOverlay?.RecordLocalEdges(self))) return fromSrc.FindPath(); } } @@ -825,7 +826,7 @@ namespace OpenRA.Mods.Common.Pathfinder /// public List FindPath(Actor self, CPos source, CPos target, BlockedByActor check, int heuristicWeightPercentage, Func customCost, - Actor ignoreActor, bool laneBias, PathFinderOverlay pathFinderOverlay) + Actor ignoreActor, bool inReverse, bool laneBias, PathFinderOverlay pathFinderOverlay) { if (costEstimator == null) return PathFinder.NoPath; @@ -851,7 +852,9 @@ namespace OpenRA.Mods.Common.Pathfinder List localPath; using (var search = GetLocalPathSearch( self, new[] { source }, target, customCost, ignoreActor, check, laneBias, gridToSearch, heuristicWeightPercentage, - recorder: pathFinderOverlay?.RecordLocalEdges(self))) + null, + inReverse, + pathFinderOverlay?.RecordLocalEdges(self))) localPath = search.FindPath(); if (localPath.Count > 0) @@ -872,7 +875,7 @@ namespace OpenRA.Mods.Common.Pathfinder // Call the other overload which can handle this scenario. var sourceAbstractCell = AbstractCellForLocalCell(source); if (sourceAbstractCell == null) - return FindPath(self, new[] { source }, target, check, heuristicWeightPercentage, customCost, ignoreActor, laneBias, pathFinderOverlay); + return FindPath(self, new[] { source }, target, check, heuristicWeightPercentage, customCost, ignoreActor, inReverse, laneBias, pathFinderOverlay); // If the source and target belong to different domains, there is no path. RebuildDomains(); @@ -903,13 +906,14 @@ namespace OpenRA.Mods.Common.Pathfinder using (var fromSrc = GetLocalPathSearch( self, new[] { source }, target, customCost, ignoreActor, check, laneBias, null, heuristicWeightPercentage, - heuristic: Heuristic(reverseAbstractSearch, estimatedSearchSize, null, null), - recorder: pathFinderOverlay?.RecordLocalEdges(self))) + Heuristic(reverseAbstractSearch, estimatedSearchSize, null, null), + inReverse, + pathFinderOverlay?.RecordLocalEdges(self))) using (var fromDest = GetLocalPathSearch( self, new[] { target }, source, customCost, ignoreActor, check, laneBias, null, heuristicWeightPercentage, - heuristic: Heuristic(forwardAbstractSearch, estimatedSearchSize, null, null), - inReverse: true, - recorder: pathFinderOverlay?.RecordLocalEdges(self))) + Heuristic(forwardAbstractSearch, estimatedSearchSize, null, null), + !inReverse, + pathFinderOverlay?.RecordLocalEdges(self))) return PathSearch.FindBidiPath(fromDest, fromSrc); } } @@ -1258,9 +1262,9 @@ namespace OpenRA.Mods.Common.Pathfinder PathSearch GetLocalPathSearch( Actor self, IEnumerable srcs, CPos dst, Func customCost, Actor ignoreActor, BlockedByActor check, bool laneBias, Grid? grid, int heuristicWeightPercentage, - Func heuristic = null, - bool inReverse = false, - PathSearch.IRecorder recorder = null) + Func heuristic, + bool inReverse, + PathSearch.IRecorder recorder) { return PathSearch.ToTargetCell( world, locomotor, self, srcs, dst, check, heuristicWeightPercentage, diff --git a/OpenRA.Mods.Common/Traits/World/PathFinder.cs b/OpenRA.Mods.Common/Traits/World/PathFinder.cs index 8b02271720..5dd524b5cf 100644 --- a/OpenRA.Mods.Common/Traits/World/PathFinder.cs +++ b/OpenRA.Mods.Common/Traits/World/PathFinder.cs @@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits Actor ignoreActor = null, bool laneBias = true) { - return FindPathToTarget(self, sources.ToList(), target, check, customCost, ignoreActor, laneBias); + return FindPathToTarget(self, sources.ToList(), target, check, customCost, ignoreActor, false, laneBias); } /// @@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits if (sourceIsAccessible) { // As both ends are accessible, we can freely swap them. - path = FindPathToTarget(self, targetsList, source, check, customCost, ignoreActor, laneBias); + path = FindPathToTarget(self, targetsList, source, check, customCost, ignoreActor, true, laneBias); } else { @@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Traits List FindPathToTarget( Actor self, List sources, CPos target, BlockedByActor check, - Func customCost, Actor ignoreActor, bool laneBias) + Func customCost, Actor ignoreActor, bool inReverse, bool laneBias) { if (sources.Count == 0) return NoPath; @@ -181,7 +181,7 @@ namespace OpenRA.Mods.Common.Traits // If the target cell is inaccessible, bail early. // The destination cell must allow movement and also have a reachable movement cost. if (!PathSearch.CellAllowsMovement(self.World, locomotor, target, customCost) - || locomotor.MovementCostToEnterCell(self, target, check, ignoreActor) == PathGraph.MovementCostForUnreachableCell) + || locomotor.MovementCostToEnterCell(self, target, check, ignoreActor, inReverse) == PathGraph.MovementCostForUnreachableCell) return NoPath; // When searching from only one source cell, some optimizations are possible. @@ -201,12 +201,12 @@ namespace OpenRA.Mods.Common.Traits // Use a hierarchical path search, which performs a guided bidirectional search. return GetHierarchicalPathFinder(locomotor, check, ignoreActor).FindPath( - self, source, target, check, DefaultHeuristicWeightPercentage, customCost, ignoreActor, laneBias, pathFinderOverlay); + self, source, target, check, DefaultHeuristicWeightPercentage, customCost, ignoreActor, inReverse, laneBias, pathFinderOverlay); } // Use a hierarchical path search, which performs a guided unidirectional search. return GetHierarchicalPathFinder(locomotor, check, ignoreActor).FindPath( - self, sources, target, check, DefaultHeuristicWeightPercentage, customCost, ignoreActor, laneBias, pathFinderOverlay); + self, sources, target, check, DefaultHeuristicWeightPercentage, customCost, ignoreActor, inReverse, laneBias, pathFinderOverlay); } HierarchicalPathFinder GetHierarchicalPathFinder(Locomotor locomotor, BlockedByActor check, Actor ignoreActor)