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.
This commit is contained in:
SamuXarick 2024-04-19 15:07:36 +01:00
parent 5bee2c4ab8
commit a57c3e1f22
1 changed files with 13 additions and 0 deletions

View File

@ -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<uint>::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