Fix #11528: Starting autorail dragging from existing track tiles resulted in adding non-continuous tracks.

This commit is contained in:
Koen Bussemaker 2025-03-24 20:23:08 +01:00
parent b96b26ef15
commit 42fbcec76f
2 changed files with 6 additions and 5 deletions

View File

@ -889,10 +889,11 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
CommandCost last_error = CMD_ERROR;
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);
if (!remove && ret.Failed() && ret.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) ret = CommandCost(); // Treat "already built" as success
if (ret.Failed()) {
last_error = std::move(ret);
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
if (!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
}

View File

@ -1024,12 +1024,12 @@ CommandCost CmdBuildLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex
}
CommandCost ret = Command<CMD_BUILD_ROAD>::Do(flags, tile, bits, rt, drd, TownID::Invalid());
if (ret.Failed() && ret.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) ret = CommandCost(); // Treat "already built" as success
if (ret.Failed()) {
last_error = std::move(ret);
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
if (is_ai) return last_error;
if (had_success) break; // Keep going if we haven't constructed any road yet, skipping the start of the drag
}
} else {
had_success = true;
/* Only pay for the upgrade on one side of the bridges and tunnels */