refactor: extract FindPath seam (no behavior change)

Every road path search — highway, branch, county — now goes through one
function instead of three direct GetPointPath calls. The function body is
exactly the call it replaced, so behaviour is unchanged.

This exists so the next commit's pathfinding change can be judged on its own:
if the generated map changes after this point, it was the heuristic, not a
refactor slip.

Routing is untouched: which towns connect, loop order, Prim's daisy-chain,
tier assignment and the abandon protocol all deal only in town positions and
never touch the grid.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stewart Howe 2026-08-05 21:31:04 -04:00
parent d72ffc0183
commit 42f04139a2

View file

@ -653,7 +653,7 @@ public partial class MapGenerator : TextureRect
Vector2 startPos = highwayNodes[i].Position; Vector2 startPos = highwayNodes[i].Position;
Vector2 endPos = highwayNodes[(i + 1) % highwayNodes.Count].Position; Vector2 endPos = highwayNodes[(i + 1) % highwayNodes.Count].Position;
Vector2[] rawPath = astar.GetPointPath( Vector2[] rawPath = FindPath(astar,
new Vector2I((int)startPos.X, (int)startPos.Y), new Vector2I((int)startPos.X, (int)startPos.Y),
new Vector2I((int)endPos.X, (int)endPos.Y) new Vector2I((int)endPos.X, (int)endPos.Y)
); );
@ -688,7 +688,7 @@ public partial class MapGenerator : TextureRect
} }
} }
Vector2[] bossPath = astar.GetPointPath( Vector2[] bossPath = FindPath(astar,
new Vector2I((int)snowBoss.Position.X, (int)snowBoss.Position.Y), bestPixel new Vector2I((int)snowBoss.Position.X, (int)snowBoss.Position.Y), bestPixel
); );
@ -744,7 +744,7 @@ public partial class MapGenerator : TextureRect
else else
{ {
// Attempt the connection. (If it freezes here, we know exactly which town caused it!) // Attempt the connection. (If it freezes here, we know exactly which town caused it!)
countyPath = astar.GetPointPath( countyPath = FindPath(astar,
new Vector2I((int)bestUnconnected.Position.X, (int)bestUnconnected.Position.Y), new Vector2I((int)bestUnconnected.Position.X, (int)bestUnconnected.Position.Y),
new Vector2I((int)bestConnected.Position.X, (int)bestConnected.Position.Y) new Vector2I((int)bestConnected.Position.X, (int)bestConnected.Position.Y)
); );
@ -769,6 +769,19 @@ public partial class MapGenerator : TextureRect
GD.Print("[A*] Logistics Network Complete!"); GD.Print("[A*] Logistics Network Complete!");
} }
/// <summary>
/// The one place a road path is actually searched for.
///
/// Every road — highway, branch, county — comes through here, so this is the single
/// seam where pathfinding can be changed without touching any routing decision
/// (which towns connect, in what order, at which tier). Those all live above and
/// only ever deal in town positions.
/// </summary>
private Vector2[] FindPath(AStarGrid2D astar, Vector2I from, Vector2I to)
{
return astar.GetPointPath(from, to);
}
private float GetSeaLevel(float t) => Mathf.Lerp(0.26f, 0.15f, Mathf.Clamp(t, 0f, 1f)); private float GetSeaLevel(float t) => Mathf.Lerp(0.26f, 0.15f, Mathf.Clamp(t, 0f, 1f));
private Vector2I FindClosestPixel(Vector2 pos, HashSet<Vector2I> set) { private Vector2I FindClosestPixel(Vector2 pos, HashSet<Vector2I> set) {