diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 08fd04c46a..007da9185c 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -69,27 +69,19 @@ bool IsArticulatedEngine(EngineID engine_type) /** * Count the number of articulated parts of an engine. * @param engine_type The engine to get the number of parts of. - * @param purchase_window Whether we are in the scope of the purchase window or not, i.e. whether we cannot allocate vehicles. * @return The number of parts. */ -uint CountArticulatedParts(EngineID engine_type, bool purchase_window) +uint CountArticulatedParts(EngineID engine_type) { if (!EngInfo(engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine)) return 0; - /* If we can't allocate a vehicle now, we can't allocate it in the command - * either, so it doesn't matter how many articulated parts there are. */ - if (!Vehicle::CanAllocateItem()) return 0; - - std::unique_ptr v; - if (!purchase_window) { - v = std::unique_ptr(Vehicle::Create()); - v->engine_type = engine_type; - v->owner = _current_company; - } + Vehicle v(VehicleID::Invalid()); + v.engine_type = engine_type; + v.owner = _current_company; uint i; for (i = 1; i < MAX_ARTICULATED_PARTS; i++) { - if (GetNextArticulatedPart(i, engine_type, v.get()) == EngineID::Invalid()) break; + if (GetNextArticulatedPart(i, engine_type, &v) == EngineID::Invalid()) break; } return i - 1; diff --git a/src/articulated_vehicles.h b/src/articulated_vehicles.h index 8eb5cbc9e1..112f9026f9 100644 --- a/src/articulated_vehicles.h +++ b/src/articulated_vehicles.h @@ -13,7 +13,7 @@ #include "vehicle_type.h" #include "engine_type.h" -uint CountArticulatedParts(EngineID engine_type, bool purchase_window); +uint CountArticulatedParts(EngineID engine_type); CargoArray GetCapacityOfArticulatedParts(EngineID engine); CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine); void AddArticulatedParts(Vehicle *first); diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index f50f2682e3..b53ae1e1ad 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -122,8 +122,8 @@ std::tuple CmdBuildVehicle(D /* Check whether the number of vehicles we need to build can be built according to pool space. */ uint num_vehicles; switch (type) { - case VEH_TRAIN: num_vehicles = (e->VehInfo().railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid, false); break; - case VEH_ROAD: num_vehicles = 1 + CountArticulatedParts(eid, false); break; + case VEH_TRAIN: num_vehicles = (e->VehInfo().railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid); break; + case VEH_ROAD: num_vehicles = 1 + CountArticulatedParts(eid); break; case VEH_SHIP: num_vehicles = 1; break; case VEH_AIRCRAFT: num_vehicles = e->VehInfo().subtype & AIR_CTOL ? 2 : 3; break; default: NOT_REACHED(); // Safe due to IsDepotTile()