mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use max_element to find highest cargo amount.
This commit is contained in:
parent
3f853d8003
commit
7b0afec11f
|
@ -55,16 +55,10 @@
|
|||
|
||||
CargoArray cap = ::GetCapacityOfArticulatedParts(engine_id);
|
||||
|
||||
CargoID most_cargo = CT_INVALID;
|
||||
uint amount = 0;
|
||||
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
|
||||
if (cap[cid] > amount) {
|
||||
amount = cap[cid];
|
||||
most_cargo = cid;
|
||||
}
|
||||
}
|
||||
auto it = std::max_element(std::cbegin(cap), std::cend(cap));
|
||||
if (*it == 0) return CT_INVALID;
|
||||
|
||||
return most_cargo;
|
||||
return CargoID(std::distance(std::cbegin(cap), it));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id)
|
||||
|
|
|
@ -42,16 +42,10 @@ CargoID ScriptEventEnginePreview::GetCargoType()
|
|||
if (!this->IsEngineValid()) return CT_INVALID;
|
||||
CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
|
||||
|
||||
CargoID most_cargo = CT_INVALID;
|
||||
uint amount = 0;
|
||||
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
|
||||
if (cap[cid] > amount) {
|
||||
amount = cap[cid];
|
||||
most_cargo = cid;
|
||||
}
|
||||
}
|
||||
auto it = std::max_element(std::cbegin(cap), std::cend(cap));
|
||||
if (*it == 0) return CT_INVALID;
|
||||
|
||||
return most_cargo;
|
||||
return CargoID(std::distance(std::cbegin(cap), it));
|
||||
}
|
||||
|
||||
int32_t ScriptEventEnginePreview::GetCapacity()
|
||||
|
|
Loading…
Reference in New Issue