1
0
Fork 0

Fix #11528: Moved to different logic to handle edge cases better.

pull/13861/head
John Taylor 2025-03-21 18:38:07 +01:00
parent 5941fb3257
commit 895c8c6a61
1 changed files with 10 additions and 13 deletions

View File

@ -886,25 +886,21 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
bool had_success = false; bool had_success = false;
bool redundant_track = false;
bool skip = false;
bool first_tile = true; bool first_tile = true;
TileIndex wormhole_end = INVALID_TILE;
CommandCost last_error = CMD_ERROR; CommandCost last_error = CMD_ERROR;
for (;;) { for (;;) {
/* Check if hopping bridge/tunnel (#11528). */ /* Check if hopping bridge/tunnel (#11528). */
if (IsDiagonalTrackdir(trackdir) && GetTileType(tile) == MP_TUNNELBRIDGE && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) { if (!first_tile && wormhole_end == INVALID_TILE && IsDiagonalTrackdir(trackdir) && GetTileType(tile) == MP_TUNNELBRIDGE && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
/* If the building direction is the same as the bridge/tunnel direction, skip building tracks until the bridge/tunnel ends. */ /* If the building direction is the same as the bridge/tunnel direction, skip building tracks until the bridge/tunnel ends. */
if (GetTunnelBridgeDirection(tile) == TrackdirToExitdir(trackdir)) { if (GetTunnelBridgeDirection(tile) == TrackdirToExitdir(trackdir)) {
redundant_track = true; // Either above tunnel or below bridge and perpendicular, which means unnecessary to build. wormhole_end = GetOtherTunnelBridgeEnd(tile);
skip = true; } else if (GetTunnelBridgeDirection(tile) == TrackdirToExitdir(ReverseTrackdir(trackdir))) {
} else if (redundant_track) {
redundant_track = false; // The tunnel/bridge has ended, the next track should be built.
} else if (!first_tile && GetTunnelBridgeDirection(tile) == TrackdirToExitdir(ReverseTrackdir(trackdir))) {
break; // Upon running into a bridge ramp from the underside, we should stop building tracks. break; // Upon running into a bridge ramp from the underside, we should stop building tracks.
} }
} }
if (!skip) { if (wormhole_end == INVALID_TILE) {
ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, TrackdirToTrack(trackdir)) : Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, TrackdirToTrack(trackdir), auto_remove_signals); ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, TrackdirToTrack(trackdir)) : Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, TrackdirToTrack(trackdir), auto_remove_signals);
if (ret.Failed()) { if (ret.Failed()) {
@ -924,15 +920,16 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
if (tile == end_tile) break; if (tile == end_tile) break;
/* Reset skip flag for the next tile after tunnel/bridge ending. */
if (wormhole_end == tile) {
wormhole_end = INVALID_TILE;
}
tile += ToTileIndexDiff(_trackdelta[trackdir]); tile += ToTileIndexDiff(_trackdelta[trackdir]);
/* toggle railbit for the non-diagonal tracks */ /* toggle railbit for the non-diagonal tracks */
if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0); if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0);
/* Reset skip flag for the next tile after tunnel/bridge ending. */
if (skip && !redundant_track) {
skip = false;
}
first_tile = false; first_tile = false;
} }