1
0
Fork 0

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
pull/8480/head
J0anJosep 2023-04-22 21:40:20 +02:00
parent a0f0ece384
commit c8dfc18380
3 changed files with 33 additions and 4 deletions

View File

@ -30,6 +30,8 @@
#include "train_cmd.h" #include "train_cmd.h"
#include "vehicle_cmd.h" #include "vehicle_cmd.h"
#include "depot_map.h" #include "depot_map.h"
#include "train_placement.h"
#include "news_func.h"
#include "table/strings.h" #include "table/strings.h"
@ -816,8 +818,14 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlag flags, VehicleID veh_id)
if (cost.Failed()) return cost; if (cost.Failed()) return cost;
assert(free_wagon || v->IsStoppedInDepot()); 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. */ /* Start autoreplacing the vehicle. */
flags |= DC_AUTOREPLACE; flags |= DC_AUTOREPLACE;
@ -845,10 +853,30 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlag flags, VehicleID veh_id)
assert(ret.GetCost() == cost.GetCost()); 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 */ /* 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); assert(cost.Failed() || !nothing_to_do);
return cost; return cost;

View File

@ -840,7 +840,7 @@ struct DepotWindow : Window {
break; break;
case WID_D_AUTOREPLACE: case WID_D_AUTOREPLACE:
Command<CMD_DEPOT_MASS_AUTOREPLACE>::Post(tile, this->type); Command<CMD_DEPOT_MASS_AUTOREPLACE>::Post(STR_ERROR_CAN_T_REPLACE_VEHICLES, tile, this->type);
break; break;
} }

View File

@ -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_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_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_CAN_T_RENAME_DEPOT :{WHITE}Can't rename depot...
STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT :{WHITE}... must be stopped inside a depot STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT :{WHITE}... must be stopped inside a depot