diff --git a/src/road.cpp b/src/road.cpp index bde29e52b2..c9f19de8ff 100644 --- a/src/road.cpp +++ b/src/road.cpp @@ -941,7 +941,6 @@ static AyStar PublicRoadAyStar() finder.GetNeighbours = PublicRoad_GetNeighbours; finder.EndNodeCheck = PublicRoad_EndNodeCheck; finder.FoundEndNode = PublicRoad_FoundEndNode; - finder.max_search_nodes = 1 << 20; return finder; } @@ -949,6 +948,9 @@ static bool PublicRoadFindPath(AyStar& finder, const TileIndex from, TileIndex t { finder.user_target = reinterpret_cast(static_cast(to)); + uint distance = DistanceManhattan(from, to); + finder.max_search_nodes = Clamp(distance * distance * 64, 1 << 10, 1 << 20); + finder.Init(1 << _public_road_hash_size); AyStarNode start {};