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