mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Codechange: Use range-for and iterator to populate default cargo table.
This commit is contained in:
parent
280dce9543
commit
fd2dd4397f
@ -41,35 +41,33 @@ void SetupCargoForClimate(LandscapeID l)
|
|||||||
{
|
{
|
||||||
assert(l < lengthof(_default_climate_cargo));
|
assert(l < lengthof(_default_climate_cargo));
|
||||||
|
|
||||||
/* Reset and disable all cargo types */
|
|
||||||
std::fill(std::begin(CargoSpec::array), std::end(CargoSpec::array), CargoSpec{});
|
|
||||||
|
|
||||||
_cargo_mask = 0;
|
_cargo_mask = 0;
|
||||||
|
|
||||||
for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
|
/* Copy from default cargo by label or index. */
|
||||||
CargoLabel cl = _default_climate_cargo[l][i];
|
auto insert = std::begin(CargoSpec::array);
|
||||||
|
for (const CargoLabel &cl : _default_climate_cargo[l]) {
|
||||||
|
|
||||||
/* Bzzt: check if cl is just an index into the cargo table */
|
/* Check if value is an index into the cargo table */
|
||||||
if (cl < lengthof(_default_cargo)) {
|
if (cl < lengthof(_default_cargo)) {
|
||||||
/* Copy the indexed cargo */
|
/* Copy the default cargo by index. */
|
||||||
CargoSpec *cargo = CargoSpec::Get(i);
|
*insert = _default_cargo[cl];
|
||||||
*cargo = _default_cargo[cl];
|
} else {
|
||||||
if (cargo->bitnum != INVALID_CARGO_BITNUM) SetBit(_cargo_mask, i);
|
/* Search for label in default cargo types and copy if found. */
|
||||||
continue;
|
auto found = std::find_if(std::begin(_default_cargo), std::end(_default_cargo), [&cl](const CargoSpec &cs) { return cs.label == cl; });
|
||||||
}
|
if (found != std::end(_default_cargo)) {
|
||||||
|
*insert = *found;
|
||||||
/* Loop through each of the default cargo types to see if
|
} else {
|
||||||
* the label matches */
|
/* Index or label is invalid, this should not happen. */
|
||||||
for (uint j = 0; j < lengthof(_default_cargo); j++) {
|
NOT_REACHED();
|
||||||
if (_default_cargo[j].label == cl) {
|
|
||||||
*CargoSpec::Get(i) = _default_cargo[j];
|
|
||||||
|
|
||||||
/* Populate the available cargo mask */
|
|
||||||
SetBit(_cargo_mask, i);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (insert->IsValid()) SetBit(_cargo_mask, insert->Index());
|
||||||
|
++insert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Reset and disable remaining cargo types. */
|
||||||
|
std::fill(insert, std::end(CargoSpec::array), CargoSpec{});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user