Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add domain checks to HierarchicalPathFinder #21164

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ static Grid GetGrid(CPos cellInGrid, Grid mapBounds)
if (targetAbstractCell == null)
return PathFinder.NoPath;

RebuildDomains();
var targetDomain = abstractDomains[targetAbstractCell.Value];

// Unlike the target cell, the source cell is allowed to be an unreachable location.
// Instead, what matters is whether any cell adjacent to the source cell can be reached.
var sourcesWithReachableNodes = new List<(CPos Source, CPos AdjacentSource)>(sources.Count);
Expand All @@ -752,6 +755,11 @@ static Grid GetGrid(CPos cellInGrid, Grid mapBounds)
var sourceAbstractCell = AbstractCellForLocalCell(source);
if (sourceAbstractCell != null)
{
// If the source and target belong to different domains, there is no path.
var sourceDomain = abstractDomains[sourceAbstractCell.Value];
if (sourceDomain != targetDomain)
continue;

sourcesWithReachableNodes.Add((source, source));
var sourceEdge = EdgeFromLocalToAbstract(source, sourceAbstractCell.Value);
if (sourceEdge != null)
Expand All @@ -770,6 +778,11 @@ static Grid GetGrid(CPos cellInGrid, Grid mapBounds)
if (adjacentSourceAbstractCell == null)
continue;

// If the source and target belong to different domains, there is no path.
var adjacentSourceDomain = abstractDomains[adjacentSourceAbstractCell.Value];
if (adjacentSourceDomain != targetDomain)
continue;

sourcesWithReachableNodes.Add((source, adjacentSource));
var sourceEdge = EdgeFromLocalToAbstract(adjacentSource, adjacentSourceAbstractCell.Value);
if (sourceEdge != null)
Expand Down Expand Up @@ -886,6 +899,13 @@ static Grid GetGrid(CPos cellInGrid, Grid mapBounds)
if (sourceAbstractCell == null)
return FindPath(self, new[] { source }, target, check, heuristicWeightPercentage, customCost, ignoreActor, laneBias, pathFinderOverlay);

// If the source and target belong to different domains, there is no path.
RebuildDomains();
var targetDomain = abstractDomains[targetAbstractCell.Value];
RoosterDragon marked this conversation as resolved.
Show resolved Hide resolved
var sourceDomain = abstractDomains[sourceAbstractCell.Value];
if (sourceDomain != targetDomain)
return PathFinder.NoPath;

var targetEdge = EdgeFromLocalToAbstract(target, targetAbstractCell.Value);
var sourceEdge = EdgeFromLocalToAbstract(source, sourceAbstractCell.Value);

Expand Down