From 42f04139a2dfb12ebd1fa918e7411afefabf29f0 Mon Sep 17 00:00:00 2001 From: beezm Date: Wed, 5 Aug 2026 21:31:04 -0400 Subject: [PATCH] refactor: extract FindPath seam (no behavior change) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- Tools/Scripts/MapGenerator.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Tools/Scripts/MapGenerator.cs b/Tools/Scripts/MapGenerator.cs index 9cd2f17..adc69a5 100644 --- a/Tools/Scripts/MapGenerator.cs +++ b/Tools/Scripts/MapGenerator.cs @@ -653,8 +653,8 @@ public partial class MapGenerator : TextureRect Vector2 startPos = highwayNodes[i].Position; Vector2 endPos = highwayNodes[(i + 1) % highwayNodes.Count].Position; - Vector2[] rawPath = astar.GetPointPath( - new Vector2I((int)startPos.X, (int)startPos.Y), + Vector2[] rawPath = FindPath(astar, + new Vector2I((int)startPos.X, (int)startPos.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 ); @@ -744,8 +744,8 @@ public partial class MapGenerator : TextureRect else { // Attempt the connection. (If it freezes here, we know exactly which town caused it!) - countyPath = astar.GetPointPath( - new Vector2I((int)bestUnconnected.Position.X, (int)bestUnconnected.Position.Y), + countyPath = FindPath(astar, + new Vector2I((int)bestUnconnected.Position.X, (int)bestUnconnected.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!"); } + /// + /// 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. + /// + 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 Vector2I FindClosestPixel(Vector2 pos, HashSet set) {