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