diff --git a/src/cargotype.cpp b/src/cargotype.cpp index b8714696ba..1128618670 100644 --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -22,7 +22,6 @@ #include "safeguards.h" CargoSpec CargoSpec::array[NUM_CARGO]; -std::array, NUM_TPE> CargoSpec::town_production_cargoes{}; /** * Bitmask of cargo types available. This includes phony cargoes like regearing cargoes. @@ -241,7 +240,7 @@ void InitializeSortedCargoSpecs() _standard_cargo_mask = 0; uint8_t nb_standard_cargo = 0; for (const auto &cargo : _sorted_cargo_specs) { - assert(cargo->town_production_effect != INVALID_TPE); + assert(cargo->town_production_effect != TownProductionEffect::Invalid); CargoSpec::town_production_cargoes[cargo->town_production_effect].push_back(cargo); if (cargo->classes.Test(CargoClass::Special)) break; nb_standard_cargo++; diff --git a/src/cargotype.h b/src/cargotype.h index f2fd963670..a49f409416 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -20,7 +20,7 @@ /** Town growth effect when delivering cargo. */ enum class TownAcceptanceEffect : uint8_t { - Begin = 0, + Begin = 0, ///< Used for iteration. None = TownAcceptanceEffect::Begin, ///< Cargo has no effect. Passengers, ///< Cargo behaves passenger-like. Mail, ///< Cargo behaves mail-like. @@ -33,17 +33,17 @@ enum class TownAcceptanceEffect : uint8_t { DECLARE_INCREMENT_DECREMENT_OPERATORS(TownAcceptanceEffect) /** Town effect when producing cargo. */ -enum TownProductionEffect : uint8_t { - TPE_NONE, ///< Town will not produce this cargo type. - TPE_PASSENGERS, ///< Cargo behaves passenger-like for production. - TPE_MAIL, ///< Cargo behaves mail-like for production. - NUM_TPE, +enum class TownProductionEffect : uint8_t { + None, ///< Town will not produce this cargo type. + Passengers, ///< Cargo behaves passenger-like for production. + Mail, ///< Cargo behaves mail-like for production. + End, ///< End marker. /** * Invalid town production effect. Used as a sentinel to indicate if a NewGRF has explicitly set an effect. * This does not 'exist' after cargo types are finalised. */ - INVALID_TPE, + Invalid, }; /** Cargo classes. */ @@ -85,7 +85,7 @@ struct CargoSpec { bool is_freight; ///< Cargo type is considered to be freight (affects train freight multiplier). TownAcceptanceEffect town_acceptance_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies. - TownProductionEffect town_production_effect = INVALID_TPE; ///< The effect on town cargo production. + TownProductionEffect town_production_effect = TownProductionEffect::Invalid; ///< The effect on town cargo production. uint16_t town_production_multiplier = TOWN_PRODUCTION_DIVISOR; ///< Town production multiplier, if commanded by TownProductionEffect. CargoCallbackMasks callback_mask; ///< Bitmask of cargo callbacks that have to be called @@ -192,7 +192,7 @@ struct CargoSpec { static IterateWrapper Iterate(size_t from = 0) { return IterateWrapper(from); } /** List of cargo specs for each Town Product Effect. */ - static std::array, NUM_TPE> town_production_cargoes; + static inline EnumClassIndexContainer, to_underlying(TownProductionEffect::End)>, TownProductionEffect> town_production_cargoes{}; private: static CargoSpec array[NUM_CARGO]; ///< Array holding all CargoSpecs diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index bc21e050c9..ca95240763 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -2431,7 +2431,7 @@ struct CargoesRow { for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) { CargoType cargo_type = cargo_fld->u.cargo.vertical_cargoes[i]; TownProductionEffect tpe = CargoSpec::Get(cargo_type)->town_production_effect; - if (tpe == TPE_PASSENGERS || tpe == TPE_MAIL) cargo_fld->ConnectCargo(cargo_type, true); + if (tpe == TownProductionEffect::Passengers || tpe == TownProductionEffect::Mail) cargo_fld->ConnectCargo(cargo_type, true); } } } @@ -2677,7 +2677,7 @@ struct IndustryCargoesWindow : public Window { for (const CargoType cargo_type : cargoes) { if (!IsValidCargoType(cargo_type)) continue; TownProductionEffect tpe = CargoSpec::Get(cargo_type)->town_production_effect; - if (tpe == TPE_PASSENGERS || tpe == TPE_MAIL) return true; + if (tpe == TownProductionEffect::Passengers || tpe == TownProductionEffect::Mail) return true; } return false; } diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 97aa81c4e7..8dde6715b6 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -943,12 +943,12 @@ static void FinaliseEngineArray() void FinaliseCargoArray() { for (CargoSpec &cs : CargoSpec::array) { - if (cs.town_production_effect == INVALID_TPE) { + if (cs.town_production_effect == TownProductionEffect::Invalid) { /* Set default town production effect by cargo label. */ switch (cs.label.base()) { - case CT_PASSENGERS.base(): cs.town_production_effect = TPE_PASSENGERS; break; - case CT_MAIL.base(): cs.town_production_effect = TPE_MAIL; break; - default: cs.town_production_effect = TPE_NONE; break; + case CT_PASSENGERS.base(): cs.town_production_effect = TownProductionEffect::Passengers; break; + case CT_MAIL.base(): cs.town_production_effect = TownProductionEffect::Mail; break; + default: cs.town_production_effect = TownProductionEffect::None; break; } } if (!cs.IsValid()) { diff --git a/src/newgrf/newgrf_act0_cargo.cpp b/src/newgrf/newgrf_act0_cargo.cpp index f7dd92e4ab..c3905172a0 100644 --- a/src/newgrf/newgrf_act0_cargo.cpp +++ b/src/newgrf/newgrf_act0_cargo.cpp @@ -174,12 +174,12 @@ static ChangeInfoResult CargoReserveInfo(uint first, uint last, int prop, ByteRe uint8_t substitute_type = buf.ReadByte(); switch (substitute_type) { - case 0x00: cs->town_production_effect = TPE_PASSENGERS; break; - case 0x02: cs->town_production_effect = TPE_MAIL; break; + case 0x00: cs->town_production_effect = TownProductionEffect::Passengers; break; + case 0x02: cs->town_production_effect = TownProductionEffect::Mail; break; default: GrfMsg(1, "CargoChangeInfo: Unknown town production substitute value {}, setting to none.", substitute_type); [[fallthrough]]; - case 0xFF: cs->town_production_effect = TPE_NONE; break; + case 0xFF: cs->town_production_effect = TownProductionEffect::None; break; } break; } diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 3ad7f48ba9..1bc88655fb 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -238,8 +238,8 @@ bool FindSubsidyPassengerRoute() if (!Subsidy::CanAllocateItem()) return false; /* Pick a random TPE_PASSENGER type */ - uint32_t r = RandomRange(static_cast(CargoSpec::town_production_cargoes[TPE_PASSENGERS].size())); - CargoType cargo_type = CargoSpec::town_production_cargoes[TPE_PASSENGERS][r]->Index(); + uint32_t r = RandomRange(static_cast(CargoSpec::town_production_cargoes[TownProductionEffect::Passengers].size())); + CargoType cargo_type = CargoSpec::town_production_cargoes[TownProductionEffect::Passengers][r]->Index(); const Town *src = Town::GetRandom(); if (src->cache.population < SUBSIDY_PAX_MIN_POPULATION || @@ -285,7 +285,7 @@ bool FindSubsidyTownCargoRoute() } /* Passenger subsidies are not handled here. */ - for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_PASSENGERS]) { + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TownProductionEffect::Passengers]) { town_cargo_produced[cs->Index()] = 0; } diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h index f70d92b52f..348a9513c3 100644 --- a/src/table/cargo_const.h +++ b/src/table/cargo_const.h @@ -49,7 +49,7 @@ * @param classes Classes of this cargo type. @see CargoClass */ #define MK(bt, label, colour, weight, mult, ip, td1, td2, freight, tae, str_plural, str_singular, str_volume, classes) \ - {label, bt, PixelColour{colour}, PixelColour{colour}, weight, mult, classes, ip, {td1, td2}, freight, tae, INVALID_TPE, TOWN_PRODUCTION_DIVISOR, CargoCallbackMasks{}, \ + {label, bt, PixelColour{colour}, PixelColour{colour}, weight, mult, classes, ip, {td1, td2}, freight, tae, TownProductionEffect::Invalid, TOWN_PRODUCTION_DIVISOR, CargoCallbackMasks{}, \ MK_STR_CARGO_PLURAL(str_plural), MK_STR_CARGO_SINGULAR(str_singular), str_volume, MK_STR_QUANTITY(str_plural), MK_STR_ABBREV(str_plural), \ MK_SPRITE(str_plural), nullptr, nullptr, 0} diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 3fe2a65ea7..a28c4dbd3a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -631,8 +631,8 @@ static void TileLoop_Town(TileIndex tile) switch (_settings_game.economy.town_cargogen_mode) { case TCGM_ORIGINAL: /* Original (quadratic) cargo generation algorithm */ - TownGenerateCargoOriginal(t, TPE_PASSENGERS, hs->population, stations); - TownGenerateCargoOriginal(t, TPE_MAIL, hs->mail_generation, stations); + TownGenerateCargoOriginal(t, TownProductionEffect::Passengers, hs->population, stations); + TownGenerateCargoOriginal(t, TownProductionEffect::Mail, hs->mail_generation, stations); break; case TCGM_BITCOUNT: @@ -640,8 +640,8 @@ static void TileLoop_Town(TileIndex tile) /* Reduce generation rate to a 1/4, using tile bits to spread out distribution. * As tick counter is incremented by 256 between each call, we ignore the lower 8 bits. */ if (GB(TimerGameTick::counter, 8, 2) == GB(tile.base(), 0, 2)) { - TownGenerateCargoBinomial(t, TPE_PASSENGERS, hs->population, stations); - TownGenerateCargoBinomial(t, TPE_MAIL, hs->mail_generation, stations); + TownGenerateCargoBinomial(t, TownProductionEffect::Passengers, hs->population, stations); + TownGenerateCargoBinomial(t, TownProductionEffect::Mail, hs->mail_generation, stations); } break; @@ -747,12 +747,12 @@ static void AddProducedCargo_Town(TileIndex tile, CargoArray &produced) } } else { if (hs->population > 0) { - for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_PASSENGERS]) { + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TownProductionEffect::Passengers]) { produced[cs->Index()]++; } } if (hs->mail_generation > 0) { - for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_MAIL]) { + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TownProductionEffect::Mail]) { produced[cs->Index()]++; } } @@ -1980,7 +1980,7 @@ void UpdateTownRadius(Town *t) */ void UpdateTownMaxPass(Town *t) { - for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_PASSENGERS]) { + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TownProductionEffect::Passengers]) { uint32_t production = ScaleByCargoScale(t->cache.population >> 3, true); if (production == 0) continue; @@ -1988,7 +1988,7 @@ void UpdateTownMaxPass(Town *t) supplied.history[LAST_MONTH].production = production; } - for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_MAIL]) { + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TownProductionEffect::Mail]) { uint32_t production = ScaleByCargoScale(t->cache.population >> 4, true); if (production == 0) continue; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index adf3e7e5c5..8cdc24a70f 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -399,7 +399,7 @@ public: StringID str_last_period = TimerGameEconomy::UsingWallclockUnits() ? STR_TOWN_VIEW_CARGO_LAST_MINUTE_MAX : STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX; - for (auto tpe : {TPE_PASSENGERS, TPE_MAIL}) { + for (auto tpe : {TownProductionEffect::Passengers, TownProductionEffect::Mail}) { for (const CargoSpec *cs : CargoSpec::town_production_cargoes[tpe]) { CargoType cargo_type = cs->Index(); auto it = this->town->GetCargoSupplied(cargo_type); @@ -534,7 +534,7 @@ public: */ uint GetDesiredInfoHeight(int width) const { - uint aimed_height = static_cast(1 + CargoSpec::town_production_cargoes[TPE_PASSENGERS].size() + CargoSpec::town_production_cargoes[TPE_MAIL].size()) * GetCharacterHeight(FS_NORMAL); + uint aimed_height = static_cast(1 + CargoSpec::town_production_cargoes[TownProductionEffect::Passengers].size() + CargoSpec::town_production_cargoes[TownProductionEffect::Mail].size()) * GetCharacterHeight(FS_NORMAL); bool first = true; for (TownAcceptanceEffect i = TownAcceptanceEffect::Begin; i < TownAcceptanceEffect::End; i++) { @@ -1645,8 +1645,8 @@ static CargoTypes GetProducedCargoOfHouse(const HouseSpec *hs) } } else { /* Cargo is not controlled by NewGRF, town production effect is used instead. */ - for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_PASSENGERS]) SetBit(produced, cs->Index()); - for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TPE_MAIL]) SetBit(produced, cs->Index()); + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TownProductionEffect::Passengers]) SetBit(produced, cs->Index()); + for (const CargoSpec *cs : CargoSpec::town_production_cargoes[TownProductionEffect::Mail]) SetBit(produced, cs->Index()); } return produced; }