From 319a657454582cd2b379cde769dbe43839bb0eeb Mon Sep 17 00:00:00 2001 From: Kuhnovic <68320206+Kuhnovic@users.noreply.github.com> Date: Sat, 12 Apr 2025 16:09:10 +0200 Subject: [PATCH] Fix 42fbcec76f41: Fixed accidental changes to autorail/road AI behavior (#13968) * Revert 4bd72e4a7846af, Fix #11528: Starting autorail dragging from existing track tiles resulted in adding non-continuous tracks. * Fix 4bd72e4a7846af: Fixed accidental changes to autorail/road AI behavior --- src/rail_cmd.cpp | 4 ++-- src/road_cmd.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 1287eac16b..46ccda7303 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -888,11 +888,11 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile CommandCost last_error = CMD_ERROR; for (;;) { ret = remove ? Command::Do(flags, tile, TrackdirToTrack(trackdir)) : Command::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 (!remove && !fail_on_obstacle && last_error.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) had_success = true; if (ret.Failed()) { last_error = std::move(ret); - if (!remove) { + 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 } diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 211186114c..0d974bbdf5 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1020,12 +1020,13 @@ CommandCost CmdBuildLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex } CommandCost ret = Command::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 (!is_ai && ret.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) had_success = true; if (ret.Failed()) { last_error = std::move(ret); - 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 + 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 */