mirror of https://github.com/OpenTTD/OpenTTD
Fix #11528: Added possibility to build tracks through bridges/tunnels without laying unnecessary pieces.
parent
a678bb263d
commit
7b9e5dc4e0
|
@ -886,22 +886,40 @@ 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 (;;) {
|
||||||
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);
|
/* Check if hopping bridge/tunnel (#11528). */
|
||||||
|
if (IsDiagonalTrackdir(trackdir) && GetTileType(tile) == MP_TUNNELBRIDGE && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
|
||||||
if (ret.Failed()) {
|
/* If the building direction is the same as the bridge/tunnel direction, skip building tracks until the bridge/tunnel ends. */
|
||||||
last_error = std::move(ret);
|
if (GetTunnelBridgeDirection(tile) == TrackdirToExitdir(trackdir)) {
|
||||||
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
|
redundant_track = true; // Either above tunnel or below bridge and perpendicular, which means unnecessary to build.
|
||||||
if (fail_on_obstacle) return last_error;
|
skip = true;
|
||||||
if (had_success) break; // Keep going if we haven't constructed any rail yet, skipping the start of the drag
|
} 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.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Ownership errors are more important. */
|
if (!skip) {
|
||||||
if (last_error.GetErrorMessage() == STR_ERROR_OWNED_BY && remove) break;
|
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);
|
||||||
} else {
|
|
||||||
had_success = true;
|
if (ret.Failed()) {
|
||||||
total_cost.AddCost(ret.GetCost());
|
last_error = std::move(ret);
|
||||||
|
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
|
||||||
|
if (fail_on_obstacle) return last_error;
|
||||||
|
if (had_success) break; // Keep going if we haven't constructed any rail yet, skipping the start of the drag
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ownership errors are more important. */
|
||||||
|
if (last_error.GetErrorMessage() == STR_ERROR_OWNED_BY && remove) break;
|
||||||
|
} else {
|
||||||
|
had_success = true;
|
||||||
|
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;
|
||||||
|
|
Loading…
Reference in New Issue