From 7c6da0ae6d24e27a2b4ef8ab594a8f8b1d5c55ed Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 12 Apr 2026 00:04:09 +0100 Subject: [PATCH] Codechange: make TownAcceptanceEffect a scoped enum --- src/cargotype.h | 21 ++++----- src/newgrf/newgrf_act0_cargo.cpp | 12 ++--- src/newgrf_town.cpp | 16 +++---- src/saveload/afterload.cpp | 18 ++++---- src/saveload/oldloader_sl.cpp | 8 ++-- src/saveload/town_sl.cpp | 14 +++--- src/script/api/script_cargo.cpp | 2 +- src/script/api/script_cargo.hpp | 12 ++--- src/script/api/script_town.cpp | 6 +-- src/script/api/script_townlist.cpp | 4 +- src/table/cargo_const.h | 70 +++++++++++++++--------------- src/town.h | 4 +- src/town_cmd.cpp | 10 ++--- src/town_cmd.h | 2 +- src/town_gui.cpp | 4 +- 15 files changed, 102 insertions(+), 101 deletions(-) diff --git a/src/cargotype.h b/src/cargotype.h index c9e69c0416..f2fd963670 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -19,18 +19,19 @@ #include "core/bitmath_func.hpp" /** Town growth effect when delivering cargo. */ -enum TownAcceptanceEffect : uint8_t { - TAE_BEGIN = 0, - TAE_NONE = TAE_BEGIN, ///< Cargo has no effect. - TAE_PASSENGERS, ///< Cargo behaves passenger-like. - TAE_MAIL, ///< Cargo behaves mail-like. - TAE_GOODS, ///< Cargo behaves goods/candy-like. - TAE_WATER, ///< Cargo behaves water-like. - TAE_FOOD, ///< Cargo behaves food/fizzy-drinks-like. - TAE_END, ///< End of town effects. - NUM_TAE = TAE_END, ///< Amount of town effects. +enum class TownAcceptanceEffect : uint8_t { + Begin = 0, + None = TownAcceptanceEffect::Begin, ///< Cargo has no effect. + Passengers, ///< Cargo behaves passenger-like. + Mail, ///< Cargo behaves mail-like. + Goods, ///< Cargo behaves goods/candy-like. + Water, ///< Cargo behaves water-like. + Food, ///< Cargo behaves food/fizzy-drinks-like. + End, ///< End of town effects. }; +DECLARE_INCREMENT_DECREMENT_OPERATORS(TownAcceptanceEffect) + /** Town effect when producing cargo. */ enum TownProductionEffect : uint8_t { TPE_NONE, ///< Town will not produce this cargo type. diff --git a/src/newgrf/newgrf_act0_cargo.cpp b/src/newgrf/newgrf_act0_cargo.cpp index c3ff6c56a2..f7dd92e4ab 100644 --- a/src/newgrf/newgrf_act0_cargo.cpp +++ b/src/newgrf/newgrf_act0_cargo.cpp @@ -145,15 +145,15 @@ static ChangeInfoResult CargoReserveInfo(uint first, uint last, int prop, ByteRe uint8_t substitute_type = buf.ReadByte(); switch (substitute_type) { - case 0x00: cs->town_acceptance_effect = TAE_PASSENGERS; break; - case 0x02: cs->town_acceptance_effect = TAE_MAIL; break; - case 0x05: cs->town_acceptance_effect = TAE_GOODS; break; - case 0x09: cs->town_acceptance_effect = TAE_WATER; break; - case 0x0B: cs->town_acceptance_effect = TAE_FOOD; break; + case 0x00: cs->town_acceptance_effect = TownAcceptanceEffect::Passengers; break; + case 0x02: cs->town_acceptance_effect = TownAcceptanceEffect::Mail; break; + case 0x05: cs->town_acceptance_effect = TownAcceptanceEffect::Goods; break; + case 0x09: cs->town_acceptance_effect = TownAcceptanceEffect::Water; break; + case 0x0B: cs->town_acceptance_effect = TownAcceptanceEffect::Food; break; default: GrfMsg(1, "CargoChangeInfo: Unknown town growth substitute value {}, setting to none.", substitute_type); [[fallthrough]]; - case 0xFF: cs->town_acceptance_effect = TAE_NONE; break; + case 0xFF: cs->town_acceptance_effect = TownAcceptanceEffect::None; break; } break; } diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp index 319a0cdc84..cbc68e3192 100644 --- a/src/newgrf_town.cpp +++ b/src/newgrf_town.cpp @@ -113,14 +113,14 @@ static uint16_t TownHistoryHelper(const Town *t, CargoLabel label, uint period, case 0xC9: return TownHistoryHelper(this->t, CT_MAIL, LAST_MONTH, &Town::SuppliedHistory::transported) >> 8; case 0xCA: return this->t->GetPercentTransported(GetCargoTypeByLabel(CT_PASSENGERS)); case 0xCB: return this->t->GetPercentTransported(GetCargoTypeByLabel(CT_MAIL)); - case 0xCC: return this->t->received[TAE_FOOD].new_act; - case 0xCD: return GB(this->t->received[TAE_FOOD].new_act, 8, 8); - case 0xCE: return this->t->received[TAE_WATER].new_act; - case 0xCF: return GB(this->t->received[TAE_WATER].new_act, 8, 8); - case 0xD0: return this->t->received[TAE_FOOD].old_act; - case 0xD1: return GB(this->t->received[TAE_FOOD].old_act, 8, 8); - case 0xD2: return this->t->received[TAE_WATER].old_act; - case 0xD3: return GB(this->t->received[TAE_WATER].old_act, 8, 8); + case 0xCC: return this->t->received[TownAcceptanceEffect::Food].new_act; + case 0xCD: return GB(this->t->received[TownAcceptanceEffect::Food].new_act, 8, 8); + case 0xCE: return this->t->received[TownAcceptanceEffect::Water].new_act; + case 0xCF: return GB(this->t->received[TownAcceptanceEffect::Water].new_act, 8, 8); + case 0xD0: return this->t->received[TownAcceptanceEffect::Food].old_act; + case 0xD1: return GB(this->t->received[TownAcceptanceEffect::Food].old_act, 8, 8); + case 0xD2: return this->t->received[TownAcceptanceEffect::Water].old_act; + case 0xD3: return GB(this->t->received[TownAcceptanceEffect::Water].old_act, 8, 8); case 0xD4: return this->t->road_build_months; case 0xD5: return this->t->fund_buildings_months; } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index ca534423bf..2d517f6a91 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2334,14 +2334,14 @@ bool AfterLoadGame() s->awarded = CompanyID::Invalid(); // not awarded to anyone const CargoSpec *cs = CargoSpec::Get(s->cargo_type); switch (cs->town_acceptance_effect) { - case TAE_PASSENGERS: - case TAE_MAIL: + case TownAcceptanceEffect::Passengers: + case TownAcceptanceEffect::Mail: /* Town -> Town */ s->src.type = s->dst.type = SourceType::Town; if (Town::IsValidID(s->src.ToTownID()) && Town::IsValidID(s->dst.ToTownID())) continue; break; - case TAE_GOODS: - case TAE_FOOD: + case TownAcceptanceEffect::Goods: + case TownAcceptanceEffect::Food: /* Industry -> Town */ s->src.type = SourceType::Industry; s->dst.type = SourceType::Town; @@ -2360,8 +2360,8 @@ bool AfterLoadGame() s->remaining = 24 - s->remaining; // convert "age of awarded subsidy" to "remaining" const CargoSpec *cs = CargoSpec::Get(s->cargo_type); switch (cs->town_acceptance_effect) { - case TAE_PASSENGERS: - case TAE_MAIL: { + case TownAcceptanceEffect::Passengers: + case TownAcceptanceEffect::Mail: { /* Town -> Town */ const Station *ss = Station::GetIfValid(s->src.id); const Station *sd = Station::GetIfValid(s->dst.id); @@ -2933,12 +2933,12 @@ bool AfterLoadGame() /* Set the default cargo requirement for town growth */ switch (_settings_game.game_creation.landscape) { case LandscapeType::Arctic: - if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_WINTER; + if (FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect::Food) != nullptr) t->goal[TownAcceptanceEffect::Food] = TOWN_GROWTH_WINTER; break; case LandscapeType::Tropic: - if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_DESERT; - if (FindFirstCargoWithTownAcceptanceEffect(TAE_WATER) != nullptr) t->goal[TAE_WATER] = TOWN_GROWTH_DESERT; + if (FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect::Food) != nullptr) t->goal[TownAcceptanceEffect::Food] = TOWN_GROWTH_DESERT; + if (FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect::Water) != nullptr) t->goal[TownAcceptanceEffect::Water] = TOWN_GROWTH_DESERT; break; default: diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index 035b3f737a..73f4063c14 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -607,10 +607,10 @@ static const OldChunks town_chunk[] = { OCL_NULL( 2 ), ///< pct_pass_transported / pct_mail_transported, now computed on the fly - OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_FOOD].new_act ), - OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_WATER].new_act ), - OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_FOOD].old_act ), - OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TAE_WATER].old_act ), + OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TownAcceptanceEffect::Food].new_act ), + OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TownAcceptanceEffect::Water].new_act ), + OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TownAcceptanceEffect::Food].old_act ), + OCL_SVAR( OC_TTD | OC_UINT16, Town, received[TownAcceptanceEffect::Water].old_act ), OCL_SVAR( OC_UINT8, Town, road_build_months ), OCL_SVAR( OC_UINT8, Town, fund_buildings_months ), diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index 3344294ef0..7873a393cb 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -258,9 +258,9 @@ public: void Load(Town *t) const override { - size_t length = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? static_cast(TAE_END) : SlGetStructListLength(TAE_END); + size_t length = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? to_underlying(TownAcceptanceEffect::End) : SlGetStructListLength(to_underlying(TownAcceptanceEffect::End)); for (size_t i = 0; i < length; i++) { - SlObject(&t->received[i], this->GetLoadDescription()); + SlObject(&t->received[static_cast(i)], this->GetLoadDescription()); } } }; @@ -333,12 +333,12 @@ static const SaveLoad _town_desc[] = { SLEG_CONDVAR( "supplied[CT_MAIL].new_act", _old_mail_supplied[THIS_MONTH].transported, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLEG_CONDVAR( "supplied[CT_MAIL].new_act", _old_mail_supplied[THIS_MONTH].transported, SLE_UINT32, SLV_9, SLV_165), - SLE_CONDVARNAME(Town, received[TAE_FOOD].old_act, "received[TE_FOOD].old_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), - SLE_CONDVARNAME(Town, received[TAE_WATER].old_act, "received[TE_WATER].old_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), - SLE_CONDVARNAME(Town, received[TAE_FOOD].new_act, "received[TE_FOOD].new_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), - SLE_CONDVARNAME(Town, received[TAE_WATER].new_act, "received[TE_WATER].new_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), + SLE_CONDVARNAME(Town, received[TownAcceptanceEffect::Food].old_act, "received[TE_FOOD].old_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), + SLE_CONDVARNAME(Town, received[TownAcceptanceEffect::Water].old_act, "received[TE_WATER].old_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), + SLE_CONDVARNAME(Town, received[TownAcceptanceEffect::Food].new_act, "received[TE_FOOD].new_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), + SLE_CONDVARNAME(Town, received[TownAcceptanceEffect::Water].new_act, "received[TE_WATER].new_act", SLE_UINT16, SL_MIN_VERSION, SLV_165), - SLE_CONDARR(Town, goal, SLE_UINT32, NUM_TAE, SLV_165, SL_MAX_VERSION), + SLE_CONDARR(Town, goal, SLE_UINT32, to_underlying(TownAcceptanceEffect::End), SLV_165, SL_MAX_VERSION), SLE_CONDSSTR(Town, text, SLE_STR | SLF_ALLOW_CONTROL, SLV_168, SL_MAX_VERSION), diff --git a/src/script/api/script_cargo.cpp b/src/script/api/script_cargo.cpp index 1a9e88eecc..e4eb1098df 100644 --- a/src/script/api/script_cargo.cpp +++ b/src/script/api/script_cargo.cpp @@ -25,7 +25,7 @@ /* static */ bool ScriptCargo::IsValidTownEffect(TownEffect towneffect_type) { - return (towneffect_type >= (TownEffect)TAE_BEGIN && towneffect_type < (TownEffect)TAE_END); + return (towneffect_type >= (TownEffect)TownAcceptanceEffect::Begin && towneffect_type < (TownEffect)TownAcceptanceEffect::End); } /* static */ std::optional ScriptCargo::GetName(CargoType cargo_type) diff --git a/src/script/api/script_cargo.hpp b/src/script/api/script_cargo.hpp index 6c9087111b..687aa4b58c 100644 --- a/src/script/api/script_cargo.hpp +++ b/src/script/api/script_cargo.hpp @@ -47,12 +47,12 @@ public: */ enum TownEffect { /* Note: these values represent part of the in-game TownEffect enum */ - TE_NONE = ::TAE_NONE, ///< This cargo has no effect on a town - TE_PASSENGERS = ::TAE_PASSENGERS, ///< This cargo supplies passengers to a town - TE_MAIL = ::TAE_MAIL, ///< This cargo supplies mail to a town - TE_GOODS = ::TAE_GOODS, ///< This cargo supplies goods to a town - TE_WATER = ::TAE_WATER, ///< This cargo supplies water to a town - TE_FOOD = ::TAE_FOOD, ///< This cargo supplies food to a town + TE_NONE = to_underlying(::TownAcceptanceEffect::None), ///< This cargo has no effect on a town + TE_PASSENGERS = to_underlying(::TownAcceptanceEffect::Passengers), ///< This cargo supplies passengers to a town + TE_MAIL = to_underlying(::TownAcceptanceEffect::Mail), ///< This cargo supplies mail to a town + TE_GOODS = to_underlying(::TownAcceptanceEffect::Goods), ///< This cargo supplies goods to a town + TE_WATER = to_underlying(::TownAcceptanceEffect::Water), ///< This cargo supplies water to a town + TE_FOOD = to_underlying(::TownAcceptanceEffect::Food), ///< This cargo supplies food to a town }; /** diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index fdd9ccd090..af01085e93 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -128,7 +128,7 @@ const Town *t = ::Town::Get(town_id); - return t->received[towneffect_id].old_act; + return t->received[static_cast(towneffect_id)].old_act; } /* static */ bool ScriptTown::SetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id, SQInteger goal) @@ -149,7 +149,7 @@ const Town *t = ::Town::Get(town_id); - switch (t->goal[towneffect_id]) { + switch (t->goal[static_cast(towneffect_id)]) { case TOWN_GROWTH_WINTER: if (TileHeight(t->xy) >= GetSnowLine() && t->cache.population > 90) return 1; return 0; @@ -158,7 +158,7 @@ if (GetTropicZone(t->xy) == TropicZone::Desert && t->cache.population > 60) return 1; return 0; - default: return t->goal[towneffect_id]; + default: return t->goal[static_cast(towneffect_id)]; } } diff --git a/src/script/api/script_townlist.cpp b/src/script/api/script_townlist.cpp index a2e834f0f4..eec56c481b 100644 --- a/src/script/api/script_townlist.cpp +++ b/src/script/api/script_townlist.cpp @@ -20,7 +20,7 @@ ScriptTownList::ScriptTownList(HSQUIRRELVM vm) ScriptTownEffectList::ScriptTownEffectList() { - for (int i = TAE_BEGIN; i < TAE_END; i++) { - this->AddItem(i); + for (TownAcceptanceEffect i = TownAcceptanceEffect::Begin; i < TownAcceptanceEffect::End; ++i) { + this->AddItem(to_underlying(i)); } } diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h index 328fe8893a..f70d92b52f 100644 --- a/src/table/cargo_const.h +++ b/src/table/cargo_const.h @@ -55,48 +55,48 @@ /** Cargo types available by default. */ static const CargoSpec _default_cargo[] = { - MK( 0, CT_PASSENGERS, 152, 1, 0x400, 3185, 0, 24, false, TAE_PASSENGERS, PASSENGERS, PASSENGER, STR_PASSENGERS, CargoClasses({CargoClass::Passengers})), - MK( 1, CT_COAL, 6, 16, 0x100, 5916, 7, 255, true, TAE_NONE, COAL, COAL, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})), - MK( 2, CT_MAIL, 15, 4, 0x200, 4550, 20, 90, false, TAE_MAIL, MAIL, MAIL, STR_BAGS, CargoClasses({CargoClass::Mail})), + MK( 0, CT_PASSENGERS, 152, 1, 0x400, 3185, 0, 24, false, TownAcceptanceEffect::Passengers, PASSENGERS, PASSENGER, STR_PASSENGERS, CargoClasses({CargoClass::Passengers})), + MK( 1, CT_COAL, 6, 16, 0x100, 5916, 7, 255, true, TownAcceptanceEffect::None, COAL, COAL, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})), + MK( 2, CT_MAIL, 15, 4, 0x200, 4550, 20, 90, false, TownAcceptanceEffect::Mail, MAIL, MAIL, STR_BAGS, CargoClasses({CargoClass::Mail})), /* Oil in temperate and arctic */ - MK( 3, CT_OIL, 174, 16, 0x100, 4437, 25, 255, true, TAE_NONE, OIL, OIL, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})), + MK( 3, CT_OIL, 174, 16, 0x100, 4437, 25, 255, true, TownAcceptanceEffect::None, OIL, OIL, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})), /* Oil in subtropic */ - MK( 3, CT_OIL, 174, 16, 0x100, 4892, 25, 255, true, TAE_NONE, OIL, OIL, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})), - MK( 4, CT_LIVESTOCK, 208, 3, 0x100, 4322, 4, 18, true, TAE_NONE, LIVESTOCK, LIVESTOCK, STR_ITEMS, CargoClasses({CargoClass::PieceGoods, CargoClass::NonPotable})), - MK( 5, CT_GOODS, 194, 8, 0x200, 6144, 5, 28, true, TAE_GOODS, GOODS, GOODS, STR_CRATES, CargoClasses({CargoClass::Express})), - MK( 6, CT_GRAIN, 191, 16, 0x100, 4778, 4, 40, true, TAE_NONE, GRAIN, GRAIN, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), - MK( 6, CT_WHEAT, 191, 16, 0x100, 4778, 4, 40, true, TAE_NONE, WHEAT, WHEAT, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), - MK( 6, CT_MAIZE, 191, 16, 0x100, 4322, 4, 40, true, TAE_NONE, MAIZE, MAIZE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), + MK( 3, CT_OIL, 174, 16, 0x100, 4892, 25, 255, true, TownAcceptanceEffect::None, OIL, OIL, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})), + MK( 4, CT_LIVESTOCK, 208, 3, 0x100, 4322, 4, 18, true, TownAcceptanceEffect::None, LIVESTOCK, LIVESTOCK, STR_ITEMS, CargoClasses({CargoClass::PieceGoods, CargoClass::NonPotable})), + MK( 5, CT_GOODS, 194, 8, 0x200, 6144, 5, 28, true, TownAcceptanceEffect::Goods, GOODS, GOODS, STR_CRATES, CargoClasses({CargoClass::Express})), + MK( 6, CT_GRAIN, 191, 16, 0x100, 4778, 4, 40, true, TownAcceptanceEffect::None, GRAIN, GRAIN, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), + MK( 6, CT_WHEAT, 191, 16, 0x100, 4778, 4, 40, true, TownAcceptanceEffect::None, WHEAT, WHEAT, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), + MK( 6, CT_MAIZE, 191, 16, 0x100, 4322, 4, 40, true, TownAcceptanceEffect::None, MAIZE, MAIZE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), /* Wood in temperate and arctic */ - MK( 7, CT_WOOD, 84, 16, 0x100, 5005, 15, 255, true, TAE_NONE, WOOD, WOOD, STR_TONS, CargoClasses({CargoClass::PieceGoods})), + MK( 7, CT_WOOD, 84, 16, 0x100, 5005, 15, 255, true, TownAcceptanceEffect::None, WOOD, WOOD, STR_TONS, CargoClasses({CargoClass::PieceGoods})), /* Wood in subtropic */ - MK( 7, CT_WOOD, 84, 16, 0x100, 7964, 15, 255, true, TAE_NONE, WOOD, WOOD, STR_TONS, CargoClasses({CargoClass::PieceGoods})), - MK( 8, CT_IRON_ORE, 184, 16, 0x100, 5120, 9, 255, true, TAE_NONE, IRON_ORE, IRON_ORE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})), - MK( 9, CT_STEEL, 10, 16, 0x100, 5688, 7, 255, true, TAE_NONE, STEEL, STEEL, STR_TONS, CargoClasses({CargoClass::PieceGoods})), - MK( 10, CT_VALUABLES, 202, 2, 0x100, 7509, 1, 32, true, TAE_NONE, VALUABLES, VALUABLES, STR_BAGS, CargoClasses({CargoClass::Armoured})), - MK( 10, CT_GOLD, 202, 8, 0x100, 5802, 10, 40, true, TAE_NONE, GOLD, GOLD, STR_BAGS, CargoClasses({CargoClass::Armoured})), - MK( 10, CT_DIAMONDS, 202, 2, 0x100, 5802, 10, 255, true, TAE_NONE, DIAMONDS, DIAMOND, STR_BAGS, CargoClasses({CargoClass::Armoured})), - MK( 11, CT_PAPER, 10, 16, 0x100, 5461, 7, 60, true, TAE_NONE, PAPER, PAPER, STR_TONS, CargoClasses({CargoClass::PieceGoods})), - MK( 12, CT_FOOD, 48, 16, 0x100, 5688, 0, 30, true, TAE_FOOD, FOOD, FOOD, STR_TONS, CargoClasses({CargoClass::Express, CargoClass::Refrigerated, CargoClass::Potable})), - MK( 13, CT_FRUIT, 208, 16, 0x100, 4209, 0, 15, true, TAE_NONE, FRUIT, FRUIT, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Refrigerated, CargoClass::Potable})), - MK( 14, CT_COPPER_ORE, 184, 16, 0x100, 4892, 12, 255, true, TAE_NONE, COPPER_ORE, COPPER_ORE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})), - MK( 15, CT_WATER, 10, 16, 0x100, 4664, 20, 80, true, TAE_WATER, WATER, WATER, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::Potable})), - MK( 16, CT_RUBBER, 6, 16, 0x100, 4437, 2, 20, true, TAE_NONE, RUBBER, RUBBER, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})), - MK( 17, CT_SUGAR, 6, 16, 0x100, 4437, 20, 255, true, TAE_NONE, SUGAR, SUGAR, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), - MK( 18, CT_TOYS, 174, 2, 0x100, 5574, 25, 255, true, TAE_NONE, TOYS, TOY, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), - MK( 19, CT_BATTERIES, 208, 4, 0x100, 4322, 2, 30, true, TAE_NONE, BATTERIES, BATTERY, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), - MK( 20, CT_CANDY, 194, 5, 0x200, 6144, 8, 40, true, TAE_GOODS, SWEETS, SWEETS, STR_BAGS, CargoClasses({CargoClass::Express})), - MK( 21, CT_TOFFEE, 191, 16, 0x100, 4778, 14, 60, true, TAE_NONE, TOFFEE, TOFFEE, STR_TONS, CargoClasses({CargoClass::Bulk})), - MK( 22, CT_COLA, 84, 16, 0x100, 4892, 5, 75, true, TAE_NONE, COLA, COLA, STR_LITERS, CargoClasses({CargoClass::Liquid})), - MK( 23, CT_COTTON_CANDY, 184, 16, 0x100, 5005, 10, 25, true, TAE_NONE, CANDYFLOSS, CANDYFLOSS, STR_TONS, CargoClasses({CargoClass::Bulk})), - MK( 24, CT_BUBBLES, 10, 1, 0x100, 5077, 20, 80, true, TAE_NONE, BUBBLES, BUBBLE, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), - MK( 25, CT_PLASTIC, 202, 16, 0x100, 4664, 30, 255, true, TAE_NONE, PLASTIC, PLASTIC, STR_LITERS, CargoClasses({CargoClass::Liquid})), - MK( 26, CT_FIZZY_DRINKS, 48, 2, 0x100, 6250, 30, 50, true, TAE_FOOD, FIZZY_DRINKS, FIZZY_DRINK, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), + MK( 7, CT_WOOD, 84, 16, 0x100, 7964, 15, 255, true, TownAcceptanceEffect::None, WOOD, WOOD, STR_TONS, CargoClasses({CargoClass::PieceGoods})), + MK( 8, CT_IRON_ORE, 184, 16, 0x100, 5120, 9, 255, true, TownAcceptanceEffect::None, IRON_ORE, IRON_ORE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})), + MK( 9, CT_STEEL, 10, 16, 0x100, 5688, 7, 255, true, TownAcceptanceEffect::None, STEEL, STEEL, STR_TONS, CargoClasses({CargoClass::PieceGoods})), + MK( 10, CT_VALUABLES, 202, 2, 0x100, 7509, 1, 32, true, TownAcceptanceEffect::None, VALUABLES, VALUABLES, STR_BAGS, CargoClasses({CargoClass::Armoured})), + MK( 10, CT_GOLD, 202, 8, 0x100, 5802, 10, 40, true, TownAcceptanceEffect::None, GOLD, GOLD, STR_BAGS, CargoClasses({CargoClass::Armoured})), + MK( 10, CT_DIAMONDS, 202, 2, 0x100, 5802, 10, 255, true, TownAcceptanceEffect::None, DIAMONDS, DIAMOND, STR_BAGS, CargoClasses({CargoClass::Armoured})), + MK( 11, CT_PAPER, 10, 16, 0x100, 5461, 7, 60, true, TownAcceptanceEffect::None, PAPER, PAPER, STR_TONS, CargoClasses({CargoClass::PieceGoods})), + MK( 12, CT_FOOD, 48, 16, 0x100, 5688, 0, 30, true, TownAcceptanceEffect::Food, FOOD, FOOD, STR_TONS, CargoClasses({CargoClass::Express, CargoClass::Refrigerated, CargoClass::Potable})), + MK( 13, CT_FRUIT, 208, 16, 0x100, 4209, 0, 15, true, TownAcceptanceEffect::None, FRUIT, FRUIT, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Refrigerated, CargoClass::Potable})), + MK( 14, CT_COPPER_ORE, 184, 16, 0x100, 4892, 12, 255, true, TownAcceptanceEffect::None, COPPER_ORE, COPPER_ORE, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::NonPotable})), + MK( 15, CT_WATER, 10, 16, 0x100, 4664, 20, 80, true, TownAcceptanceEffect::Water, WATER, WATER, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::Potable})), + MK( 16, CT_RUBBER, 6, 16, 0x100, 4437, 2, 20, true, TownAcceptanceEffect::None, RUBBER, RUBBER, STR_LITERS, CargoClasses({CargoClass::Liquid, CargoClass::NonPotable})), + MK( 17, CT_SUGAR, 6, 16, 0x100, 4437, 20, 255, true, TownAcceptanceEffect::None, SUGAR, SUGAR, STR_TONS, CargoClasses({CargoClass::Bulk, CargoClass::Potable})), + MK( 18, CT_TOYS, 174, 2, 0x100, 5574, 25, 255, true, TownAcceptanceEffect::None, TOYS, TOY, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), + MK( 19, CT_BATTERIES, 208, 4, 0x100, 4322, 2, 30, true, TownAcceptanceEffect::None, BATTERIES, BATTERY, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), + MK( 20, CT_CANDY, 194, 5, 0x200, 6144, 8, 40, true, TownAcceptanceEffect::Goods, SWEETS, SWEETS, STR_BAGS, CargoClasses({CargoClass::Express})), + MK( 21, CT_TOFFEE, 191, 16, 0x100, 4778, 14, 60, true, TownAcceptanceEffect::None, TOFFEE, TOFFEE, STR_TONS, CargoClasses({CargoClass::Bulk})), + MK( 22, CT_COLA, 84, 16, 0x100, 4892, 5, 75, true, TownAcceptanceEffect::None, COLA, COLA, STR_LITERS, CargoClasses({CargoClass::Liquid})), + MK( 23, CT_COTTON_CANDY, 184, 16, 0x100, 5005, 10, 25, true, TownAcceptanceEffect::None, CANDYFLOSS, CANDYFLOSS, STR_TONS, CargoClasses({CargoClass::Bulk})), + MK( 24, CT_BUBBLES, 10, 1, 0x100, 5077, 20, 80, true, TownAcceptanceEffect::None, BUBBLES, BUBBLE, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), + MK( 25, CT_PLASTIC, 202, 16, 0x100, 4664, 30, 255, true, TownAcceptanceEffect::None, PLASTIC, PLASTIC, STR_LITERS, CargoClasses({CargoClass::Liquid})), + MK( 26, CT_FIZZY_DRINKS, 48, 2, 0x100, 6250, 30, 50, true, TownAcceptanceEffect::Food, FIZZY_DRINKS, FIZZY_DRINK, STR_ITEMS, CargoClasses({CargoClass::PieceGoods})), /* Void slot in temperate */ - MK(0xFF, CT_INVALID, 1, 0, 0x100, 5688, 0, 30, true, TAE_NONE, NOTHING, NOTHING, STR_TONS, CargoClasses({})), + MK(0xFF, CT_INVALID, 1, 0, 0x100, 5688, 0, 30, true, TownAcceptanceEffect::None, NOTHING, NOTHING, STR_TONS, CargoClasses({})), /* Void slot in arctic */ - MK(0xFF, CT_INVALID, 184, 0, 0x100, 5120, 9, 255, true, TAE_NONE, NOTHING, NOTHING, STR_TONS, CargoClasses({})), + MK(0xFF, CT_INVALID, 184, 0, 0x100, 5120, 9, 255, true, TownAcceptanceEffect::None, NOTHING, NOTHING, STR_TONS, CargoClasses({})), }; diff --git a/src/town.h b/src/town.h index ef152cf9ef..4cc7403460 100644 --- a/src/town.h +++ b/src/town.h @@ -129,8 +129,8 @@ struct Town : TownPool::PoolItem<&_town_pool> { SuppliedCargoes supplied{}; ///< Cargo statistics about supplied cargo. AcceptedCargoes accepted{}; ///< Cargo statistics about accepted cargo. - std::array, NUM_TAE> received{}; ///< Cargo statistics about received cargotypes. - std::array goal{}; ///< Amount of cargo required for the town to grow. + EnumClassIndexContainer, to_underlying(TownAcceptanceEffect::End)>, TownAcceptanceEffect> received{}; ///< Cargo statistics about received cargotypes. + EnumClassIndexContainer, TownAcceptanceEffect> goal{}; ///< Amount of cargo required for the town to grow. ValidHistoryMask valid_history = 0; ///< Mask of valid history records. EncodedString text{}; ///< General text with additional information. diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d8a7a1e101..3fe2a65ea7 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2033,12 +2033,12 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi /* Set the default cargo requirement for town growth */ switch (_settings_game.game_creation.landscape) { case LandscapeType::Arctic: - if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_WINTER; + if (FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect::Food) != nullptr) t->goal[TownAcceptanceEffect::Food] = TOWN_GROWTH_WINTER; break; case LandscapeType::Tropic: - if (FindFirstCargoWithTownAcceptanceEffect(TAE_FOOD) != nullptr) t->goal[TAE_FOOD] = TOWN_GROWTH_DESERT; - if (FindFirstCargoWithTownAcceptanceEffect(TAE_WATER) != nullptr) t->goal[TAE_WATER] = TOWN_GROWTH_DESERT; + if (FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect::Food) != nullptr) t->goal[TownAcceptanceEffect::Food] = TOWN_GROWTH_DESERT; + if (FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect::Water) != nullptr) t->goal[TownAcceptanceEffect::Water] = TOWN_GROWTH_DESERT; break; default: @@ -3182,7 +3182,7 @@ CommandCost CmdTownCargoGoal(DoCommandFlags flags, TownID town_id, TownAcceptanc { if (_current_company != OWNER_DEITY) return CMD_ERROR; - if (tae < TAE_BEGIN || tae >= TAE_END) return CMD_ERROR; + if (tae < TownAcceptanceEffect::Begin || tae >= TownAcceptanceEffect::End) return CMD_ERROR; Town *t = Town::GetIfValid(town_id); if (t == nullptr) return CMD_ERROR; @@ -3923,7 +3923,7 @@ static void UpdateTownGrowth(Town *t) if (t->fund_buildings_months == 0) { /* Check if all goals are reached for this town to grow (given we are not funding it) */ - for (int i = TAE_BEGIN; i < TAE_END; i++) { + for (TownAcceptanceEffect i = TownAcceptanceEffect::Begin; i < TownAcceptanceEffect::End; i++) { switch (t->goal[i]) { case TOWN_GROWTH_WINTER: if (TileHeight(t->xy) >= GetSnowLine() && t->received[i].old_act == 0 && t->cache.population > 90) return; diff --git a/src/town_cmd.h b/src/town_cmd.h index 955841b6c8..de928bd194 100644 --- a/src/town_cmd.h +++ b/src/town_cmd.h @@ -15,7 +15,7 @@ #include "town.h" #include "town_type.h" -enum TownAcceptanceEffect : uint8_t; +enum class TownAcceptanceEffect : uint8_t; using HouseID = uint16_t; std::tuple CmdFoundTown(DoCommandFlags flags, TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32_t townnameparts, const std::string &text); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index c241d4b338..adf3e7e5c5 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -413,7 +413,7 @@ public: } bool first = true; - for (int i = TAE_BEGIN; i < TAE_END; i++) { + for (TownAcceptanceEffect i = TownAcceptanceEffect::Begin; i < TownAcceptanceEffect::End; i++) { if (this->town->goal[i] == 0) continue; if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue; if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TropicZone::Desert || this->town->cache.population <= 60)) continue; @@ -537,7 +537,7 @@ public: uint aimed_height = static_cast(1 + CargoSpec::town_production_cargoes[TPE_PASSENGERS].size() + CargoSpec::town_production_cargoes[TPE_MAIL].size()) * GetCharacterHeight(FS_NORMAL); bool first = true; - for (int i = TAE_BEGIN; i < TAE_END; i++) { + for (TownAcceptanceEffect i = TownAcceptanceEffect::Begin; i < TownAcceptanceEffect::End; i++) { if (this->town->goal[i] == 0) continue; if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue; if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TropicZone::Desert || this->town->cache.population <= 60)) continue;