mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-27 15:39:32 +01:00
Codechange: Return pair from instead of optional out parameter. (#13166)
GetVehicleDefaultCapacity() has a pointer as an optional out parameter, but it is always used. Return a std::pair instead.
This commit is contained in:
parent
56510b5d7b
commit
e30c5e6b9e
@ -99,18 +99,15 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default (non-refitted) capacity of a specific EngineID.
|
* Returns the default (non-refitted) cargo and capacity of a specific EngineID.
|
||||||
* @param engine the EngineID of interest
|
* @param engine the EngineID of interest
|
||||||
* @param cargo_type returns the default cargo type, if needed
|
* @return cargo and capacity
|
||||||
* @return capacity
|
|
||||||
*/
|
*/
|
||||||
static inline uint16_t GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
|
static inline std::pair<CargoID, uint16_t> GetVehicleDefaultCapacity(EngineID engine)
|
||||||
{
|
{
|
||||||
const Engine *e = Engine::Get(engine);
|
const Engine *e = Engine::Get(engine);
|
||||||
CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO);
|
CargoID cargo = e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO;
|
||||||
if (cargo_type != nullptr) *cargo_type = cargo;
|
return {cargo, IsValidCargoID(cargo) ? e->GetDisplayDefaultCapacity() : 0};
|
||||||
if (!IsValidCargoID(cargo)) return 0;
|
|
||||||
return e->GetDisplayDefaultCapacity();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,9 +140,9 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
|
|||||||
CargoArray capacity{};
|
CargoArray capacity{};
|
||||||
const Engine *e = Engine::Get(engine);
|
const Engine *e = Engine::Get(engine);
|
||||||
|
|
||||||
CargoID cargo_type;
|
if (auto [cargo, cap] = GetVehicleDefaultCapacity(engine); IsValidCargoID(cargo)) {
|
||||||
uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
|
capacity[cargo] = cap;
|
||||||
if (cargo_type < NUM_CARGO) capacity[cargo_type] = cargo_capacity;
|
}
|
||||||
|
|
||||||
if (!e->IsGroundVehicle()) return capacity;
|
if (!e->IsGroundVehicle()) return capacity;
|
||||||
|
|
||||||
@ -155,8 +152,9 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
|
|||||||
EngineID artic_engine = GetNextArticulatedPart(i, engine);
|
EngineID artic_engine = GetNextArticulatedPart(i, engine);
|
||||||
if (artic_engine == INVALID_ENGINE) break;
|
if (artic_engine == INVALID_ENGINE) break;
|
||||||
|
|
||||||
cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
|
if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoID(cargo)) {
|
||||||
if (cargo_type < NUM_CARGO) capacity[cargo_type] += cargo_capacity;
|
capacity[cargo] += cap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return capacity;
|
return capacity;
|
||||||
@ -172,9 +170,9 @@ CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
|
|||||||
CargoTypes cargoes = 0;
|
CargoTypes cargoes = 0;
|
||||||
const Engine *e = Engine::Get(engine);
|
const Engine *e = Engine::Get(engine);
|
||||||
|
|
||||||
CargoID cargo_type;
|
if (auto [cargo, cap] = GetVehicleDefaultCapacity(engine); IsValidCargoID(cargo) && cap > 0) {
|
||||||
uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
|
SetBit(cargoes, cargo);
|
||||||
if (cargo_type < NUM_CARGO && cargo_capacity > 0) SetBit(cargoes, cargo_type);
|
}
|
||||||
|
|
||||||
if (!e->IsGroundVehicle()) return cargoes;
|
if (!e->IsGroundVehicle()) return cargoes;
|
||||||
|
|
||||||
@ -184,8 +182,9 @@ CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
|
|||||||
EngineID artic_engine = GetNextArticulatedPart(i, engine);
|
EngineID artic_engine = GetNextArticulatedPart(i, engine);
|
||||||
if (artic_engine == INVALID_ENGINE) break;
|
if (artic_engine == INVALID_ENGINE) break;
|
||||||
|
|
||||||
cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
|
if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoID(cargo) && cap > 0) {
|
||||||
if (cargo_type < NUM_CARGO && cargo_capacity > 0) SetBit(cargoes, cargo_type);
|
SetBit(cargoes, cargo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cargoes;
|
return cargoes;
|
||||||
|
Loading…
Reference in New Issue
Block a user