TBTR: Fix TemplateVehicle allocation check in CmdReplaceTemplateVehicle
This commit is contained in:
@@ -175,15 +175,8 @@ void SetupTemplateVehicleFromVirtual(TemplateVehicle *tmp, TemplateVehicle *prev
|
||||
// create a full TemplateVehicle based train according to a virtual train
|
||||
TemplateVehicle* TemplateVehicleFromVirtualTrain(Train *virt)
|
||||
{
|
||||
if (!virt) return nullptr;
|
||||
|
||||
Train *init_virt = virt;
|
||||
|
||||
int len = CountVehiclesInChain(virt);
|
||||
if (!TemplateVehicle::CanAllocateItem(len)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TemplateVehicle *tmp;
|
||||
TemplateVehicle *prev = nullptr;
|
||||
for (; virt; virt = virt->Next()) {
|
||||
|
@@ -1143,6 +1143,10 @@ CommandCost CmdReplaceTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
||||
|
||||
Train* train = Train::From(vehicle);
|
||||
|
||||
if (!TemplateVehicle::CanAllocateItem(CountVehiclesInChain(train))) {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
||||
bool should_execute = (flags & DC_EXEC) != 0;
|
||||
|
||||
if (should_execute) {
|
||||
@@ -1167,10 +1171,6 @@ CommandCost CmdReplaceTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
||||
|
||||
template_vehicle = TemplateVehicleFromVirtualTrain(train);
|
||||
|
||||
if (template_vehicle == nullptr) {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
||||
if (restore_flags) {
|
||||
template_vehicle->reuse_depot_vehicles = reuse_depot_vehicles;
|
||||
template_vehicle->keep_remaining_vehicles = keep_remaining_vehicles;
|
||||
|
Reference in New Issue
Block a user