From c8dfc1838063dbdd8b112ec9cb1c091fc46c3d68 Mon Sep 17 00:00:00 2001 From: J0anJosep Date: Sat, 22 Apr 2023 21:40:20 +0200 Subject: [PATCH] Change: Deal with autoreplacements in extended rail depots. As the autoreplace flag is set, only lift and tryplacing in the original command for autoreplacing and not in any recursive calls to move, buy, refit and sell commands. # Conflicts: # src/autoreplace_cmd.cpp --- src/autoreplace_cmd.cpp | 34 +++++++++++++++++++++++++++++++--- src/depot_gui.cpp | 2 +- src/lang/english.txt | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index eaa1e1f5cd..d94249e188 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -30,6 +30,8 @@ #include "train_cmd.h" #include "vehicle_cmd.h" #include "depot_map.h" +#include "train_placement.h" +#include "news_func.h" #include "table/strings.h" @@ -816,8 +818,14 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlag flags, VehicleID veh_id) if (cost.Failed()) return cost; assert(free_wagon || v->IsStoppedInDepot()); + if (flags & DC_EXEC) v->StopServicing(); - if (IsExtendedDepotTile(v->tile)) UpdateExtendedDepotReservation(v, false); + TrainPlacement train_placement; + if (v->type == VEH_TRAIN) { + train_placement.LiftTrain(Train::From(v), flags); + } else if (IsExtendedDepotTile(v->tile)) { + UpdateExtendedDepotReservation(v, false); + } /* Start autoreplacing the vehicle. */ flags |= DC_AUTOREPLACE; @@ -845,10 +853,30 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlag flags, VehicleID veh_id) assert(ret.GetCost() == cost.GetCost()); } - if (IsExtendedDepotTile(v->tile)) UpdateExtendedDepotReservation(v, true); + /* Check whether the train can be placed on tracks. */ + bool platform_error = false; + + /* Autoreplacing is done. */ + flags &= ~DC_AUTOREPLACE; + + if (v->type == VEH_TRAIN) { + if (cost.Succeeded() && (flags & DC_EXEC) != 0) { + train_placement.LookForPlaceInDepot(Train::From(v), false); + if (train_placement.info < PI_WONT_LEAVE) { + platform_error = true; + if (v->owner == _local_company && v->IsFrontEngine()) { + SetDParam(0, v->index); + AddVehicleAdviceNewsItem(STR_ADVICE_PLATFORM_TYPE + train_placement.info - PI_ERROR_BEGIN, v->index); + } + } + } + train_placement.PlaceTrain(Train::From(v), flags); + } else if (IsExtendedDepotTile(v->tile)) { + UpdateExtendedDepotReservation(v, true); + } /* Restart the vehicle */ - if (!was_stopped) cost.AddCost(DoCmdStartStopVehicle(v, false)); + if (!platform_error && !was_stopped) cost.AddCost(DoCmdStartStopVehicle(v, false)); assert(cost.Failed() || !nothing_to_do); return cost; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index f7e745517d..e9efecf796 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -840,7 +840,7 @@ struct DepotWindow : Window { break; case WID_D_AUTOREPLACE: - Command::Post(tile, this->type); + Command::Post(STR_ERROR_CAN_T_REPLACE_VEHICLES, tile, this->type); break; } diff --git a/src/lang/english.txt b/src/lang/english.txt index 3566245a4c..3c8b2a95c9 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -5161,6 +5161,7 @@ STR_ERROR_DEPOT_EXTENDING_PLATFORMS :{WHITE}Extendin STR_ERROR_DEPOT_EXTENDED_RAIL_DEPOT_IS_NOT_FREE :{WHITE}Extended rail depot has a reserved tile and can't be converted STR_ERROR_CAN_T_START_STOP_VEHICLES :{WHITE}Can't start at least one vehicle in the depot... +STR_ERROR_CAN_T_REPLACE_VEHICLES :{WHITE}Can't replace vehicles in the depot... STR_ERROR_CAN_T_RENAME_DEPOT :{WHITE}Can't rename depot... STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT :{WHITE}... must be stopped inside a depot