1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 01:12:39 +01:00

Codechange: remove unused parameter and unneeded heap allocation

This commit is contained in:
Rubidium
2026-01-03 16:13:31 +01:00
committed by rubidium42
parent e9e7e4af51
commit 13cf05c941
3 changed files with 8 additions and 16 deletions

View File

@@ -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<Vehicle> v;
if (!purchase_window) {
v = std::unique_ptr<Vehicle>(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;

View File

@@ -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);

View File

@@ -122,8 +122,8 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> 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<RailVehicleInfo>().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<RailVehicleInfo>().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<AircraftVehicleInfo>().subtype & AIR_CTOL ? 2 : 3; break;
default: NOT_REACHED(); // Safe due to IsDepotTile()