Fix suboptimal paths on multiple droids pathfinding to same location.
On finding the optimal path for a droid, pathfinding was immediately terminated, on reaching the droid, without considering paths crossing the droid's tile. The next droid to pathfind to the same location would re-use the pathfinding map, which has a hole around where the previous droid was, which could lead to long detours (or not finding a path) if the previous droid/droids was/were in a 1-tile-wide/narrow passage.master
parent
4d0b5d749b
commit
c9a618cd82
|
@ -338,7 +338,8 @@ static PathCoord fpathAStarExplore(PathfindContext &context, PathCoord tileF)
|
|||
unsigned nearestDist = 0xFFFFFFFF;
|
||||
|
||||
// search for a route
|
||||
while (!context.nodes.empty())
|
||||
bool foundIt = false;
|
||||
while (!context.nodes.empty() && !foundIt)
|
||||
{
|
||||
PathNode node = fpathTakeNode(context.nodes);
|
||||
if (context.map[node.p.x + node.p.y*mapWidth].visited)
|
||||
|
@ -358,7 +359,7 @@ static PathCoord fpathAStarExplore(PathfindContext &context, PathCoord tileF)
|
|||
{
|
||||
// reached the target
|
||||
nearestCoord = node.p;
|
||||
break;
|
||||
foundIt = true; // Break out of loop, but not before inserting neighbour nodes, since the neighbours may be important if the context gets reused.
|
||||
}
|
||||
|
||||
// loop through possible moves in 8 directions to find a valid move
|
||||
|
|
Loading…
Reference in New Issue