1
0
Fork 0

Fix #11528: Added possibility to build tracks through bridges/tunnels without laying unnecessary pieces.

pull/13861/head
John Taylor 2025-03-21 15:31:51 +01:00
parent a678bb263d
commit 7b9e5dc4e0
1 changed files with 36 additions and 12 deletions

View File

@ -886,8 +886,25 @@ 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;
CommandCost last_error = CMD_ERROR; CommandCost last_error = CMD_ERROR;
for (;;) { for (;;) {
/* Check if hopping bridge/tunnel (#11528). */
if (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 (GetTunnelBridgeDirection(tile) == TrackdirToExitdir(trackdir)) {
redundant_track = true; // Either above tunnel or below bridge and perpendicular, which means unnecessary to build.
skip = true;
} else if (redundant_track) {
redundand_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.
}
}
if (!skip) {
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()) {
@ -903,6 +920,7 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
had_success = true; had_success = true;
total_cost.AddCost(ret.GetCost()); total_cost.AddCost(ret.GetCost());
} }
}
if (tile == end_tile) break; if (tile == end_tile) break;
@ -910,6 +928,12 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
/* 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;
} }
if (had_success) return total_cost; if (had_success) return total_cost;