From a57c3e1f2232faeae094e1965e41d037914ecc02 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:07:36 +0100 Subject: [PATCH] Fix #12193: [NPF] Don't use the entire docking area when computing closest station tile Update CalcClosestStationTile to handle docking stations differently. It will only take into consideration the tiles that pass IsShipDestinationTile test. This part is called by NPF. --- src/pathfinder/pathfinder_func.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pathfinder/pathfinder_func.h b/src/pathfinder/pathfinder_func.h index 2271d60490..ad265e14f0 100644 --- a/src/pathfinder/pathfinder_func.h +++ b/src/pathfinder/pathfinder_func.h @@ -65,6 +65,19 @@ inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, Stati /* If the rail station is (temporarily) not present, use the station sign to drive near the station */ if (ta.tile == INVALID_TILE) return st->xy; + if (station_type == STATION_DOCK) { + uint closest_dist = std::numeric_limits::max(); + TileIndex closest_tile; + for (const TileIndex &docking_tile : ta) { + if (!IsDockingTile(docking_tile) || !IsShipDestinationTile(docking_tile, station)) continue; + const uint dist = DistanceManhattan(docking_tile, tile); + if (dist >= closest_dist) continue; + closest_dist = dist; + closest_tile = docking_tile; + } + return closest_tile; + } + uint minx = TileX(ta.tile); // topmost corner of station uint miny = TileY(ta.tile); uint maxx = minx + ta.w - 1; // lowermost corner of station