From 80e58e751aafdd033abae43b72b7dbd827deafe3 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 24 Sep 2025 22:45:18 +0100 Subject: [PATCH] Fix #14607: Bridge-over-station discrepancy depending on build order. (#14608) When building a custom station, the callback-derived tile layout is ignored during the bridge height test. This caused a discrepancy between building a station under a bridge vs building a bridge over the same station. Test the station tile layout callback during the bridge height test. --- src/station_cmd.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index ce85d755e2..c9a3924f87 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1480,14 +1480,23 @@ CommandCost CmdBuildRailStation(DoCommandFlags flags, TileIndex tile_org, RailTy RailStationTileLayout stl{statspec, numtracks, plat_len}; auto it = stl.begin(); TileIndex tile_track = tile_org; - for (uint i = 0; i != numtracks; ++i) { + for (uint i = 0; i != numtracks; ++i, tile_track += track_delta) { TileIndex tile = tile_track; - for (uint j = 0; j != plat_len; ++j) { - ret = IsRailStationBridgeAboveOk(tile, statspec, StationType::Rail, *it++ + axis); + for (uint j = 0; j != plat_len; ++j, tile += tile_delta, ++it) { + /* Don't check the layout if there's no bridge above anyway. */ + if (!IsBridgeAbove(tile)) continue; + + StationGfx gfx = *it + axis; + if (statspec != nullptr) { + uint32_t platinfo = GetPlatformInfo(AXIS_X, gfx, plat_len, numtracks, j, i, false); + /* As the station is not yet completely finished, the station does not yet exist. */ + uint16_t callback = GetStationCallback(CBID_STATION_BUILD_TILE_LAYOUT, platinfo, 0, statspec, nullptr, tile); + if (callback != CALLBACK_FAILED && callback <= UINT8_MAX) gfx = (callback & ~1) + axis; + } + + ret = IsRailStationBridgeAboveOk(tile, statspec, StationType::Rail, gfx); if (ret.Failed()) return ret; - tile += tile_delta; } - tile_track += track_delta; } /* Check if we can allocate a custom stationspec to this station */