mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::visit for SetupCargoForClimate. (#13103)
parent
fc8685d618
commit
fcac5479f1
|
@ -72,21 +72,24 @@ void SetupCargoForClimate(LandscapeID l)
|
||||||
auto insert = std::begin(CargoSpec::array);
|
auto insert = std::begin(CargoSpec::array);
|
||||||
for (const auto &cl : _default_climate_cargo[l]) {
|
for (const auto &cl : _default_climate_cargo[l]) {
|
||||||
|
|
||||||
/* Check if value is an index into the cargo table */
|
struct visitor {
|
||||||
if (std::holds_alternative<int>(cl)) {
|
const CargoSpec &operator()(const int &index)
|
||||||
|
{
|
||||||
/* Copy the default cargo by index. */
|
/* Copy the default cargo by index. */
|
||||||
*insert = _default_cargo[std::get<int>(cl)];
|
return _default_cargo[index];
|
||||||
} else {
|
}
|
||||||
|
const CargoSpec &operator()(const CargoLabel &label)
|
||||||
|
{
|
||||||
/* Search for label in default cargo types and copy if found. */
|
/* Search for label in default cargo types and copy if found. */
|
||||||
CargoLabel label = std::get<CargoLabel>(cl);
|
auto found = std::ranges::find(_default_cargo, label, &CargoSpec::label);
|
||||||
auto found = std::find_if(std::begin(_default_cargo), std::end(_default_cargo), [&label](const CargoSpec &cs) { return cs.label == label; });
|
if (found != std::end(_default_cargo)) return *found;
|
||||||
if (found != std::end(_default_cargo)) {
|
|
||||||
*insert = *found;
|
|
||||||
} else {
|
|
||||||
/* Index or label is invalid, this should not happen. */
|
/* Index or label is invalid, this should not happen. */
|
||||||
NOT_REACHED();
|
NOT_REACHED();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
*insert = std::visit(visitor{}, cl);
|
||||||
|
|
||||||
if (insert->IsValid()) {
|
if (insert->IsValid()) {
|
||||||
SetBit(_cargo_mask, insert->Index());
|
SetBit(_cargo_mask, insert->Index());
|
||||||
|
|
Loading…
Reference in New Issue