From 02becd50c52d30d2fb241f9bf2da21a28a7d46f3 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 28 Jun 2026 17:07:13 +0100 Subject: [PATCH] Codechange: make TownFounding a scoped enum --- src/script/api/script_town.cpp | 4 ++-- src/settings_table.cpp | 2 +- src/table/settings/economy_settings.ini | 6 +++--- src/toolbar_gui.cpp | 4 ++-- src/town_cmd.cpp | 4 ++-- src/town_gui.cpp | 4 ++-- src/town_type.h | 10 ++++------ 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index 6e4080da4a..691a628c6c 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -296,11 +296,11 @@ ScriptObjectRef counter(name); EnforceDeityOrCompanyModeValid(false); - EnforcePrecondition(false, ScriptCompanyMode::IsDeity() || _settings_game.economy.found_town != TF_FORBIDDEN); + EnforcePrecondition(false, ScriptCompanyMode::IsDeity() || _settings_game.economy.found_town != TownFounding::Forbidden); EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, size == TOWN_SIZE_SMALL || size == TOWN_SIZE_MEDIUM || size == TOWN_SIZE_LARGE) EnforcePrecondition(false, ScriptCompanyMode::IsDeity() || size != TOWN_SIZE_LARGE); - if (ScriptCompanyMode::IsDeity() || _settings_game.economy.found_town == TF_CUSTOM_LAYOUT) { + if (ScriptCompanyMode::IsDeity() || _settings_game.economy.found_town == TownFounding::CustomLayout) { EnforcePrecondition(false, layout >= ROAD_LAYOUT_ORIGINAL && layout <= ROAD_LAYOUT_RANDOM); } else { /* The layout parameter is ignored for AIs when custom layouts is disabled. */ diff --git a/src/settings_table.cpp b/src/settings_table.cpp index 848fea9022..35bb61a01d 100644 --- a/src/settings_table.cpp +++ b/src/settings_table.cpp @@ -386,7 +386,7 @@ static void AircraftRangeChanged(int32_t) static void TownFoundingChanged(int32_t) { - if (_game_mode != GameMode::Editor && _settings_game.economy.found_town == TF_FORBIDDEN) { + if (_game_mode != GameMode::Editor && _settings_game.economy.found_town == TownFounding::Forbidden) { CloseWindowById(WindowClass::FoundTown, 0); } else { InvalidateWindowData(WindowClass::FoundTown, 0); diff --git a/src/table/settings/economy_settings.ini b/src/table/settings/economy_settings.ini index 3b1ba21531..4bb6e27fd3 100644 --- a/src/table/settings/economy_settings.ini +++ b/src/table/settings/economy_settings.ini @@ -73,9 +73,9 @@ var = economy.found_town type = SLE_UINT8 from = SaveLoadVersion::FoundTown flags = SettingFlag::GuiDropdown -def = TF_FORBIDDEN -min = TF_BEGIN -max = TF_END - 1 +def = TownFounding::Forbidden +min = TownFounding::Forbidden +max = TownFounding::CustomLayout interval = 1 str = STR_CONFIG_SETTING_TOWN_FOUNDING strhelp = STR_CONFIG_SETTING_TOWN_FOUNDING_HELPTEXT diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 46b5004152..ee6067fb38 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -493,7 +493,7 @@ static CallBackFunction ToolbarTownClick(Window *w) { DropDownList list; list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, TownMenuEntries::ShowDirectory)); - if (_settings_game.economy.found_town != TF_FORBIDDEN) list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_FOUND_TOWN, TownMenuEntries::ShowFoundTown)); + if (_settings_game.economy.found_town != TownFounding::Forbidden) list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_FOUND_TOWN, TownMenuEntries::ShowFoundTown)); if (_settings_game.economy.place_houses != PlaceHouses::Forbidden) list.push_back(MakeDropDownListStringItem(STR_SCENEDIT_TOWN_MENU_PACE_HOUSE, TownMenuEntries::ShowPlaceHouses)); PopupMainToolbarMenu(w, WID_TN_TOWNS, std::move(list), 0); @@ -512,7 +512,7 @@ static CallBackFunction MenuClickTown(int index) switch (TownMenuEntries(index)) { case TownMenuEntries::ShowDirectory: ShowTownDirectory(); break; case TownMenuEntries::ShowFoundTown: // Setting could be changed when the dropdown was open - if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow(); + if (_settings_game.economy.found_town != TownFounding::Forbidden) ShowFoundTownWindow(); break; case TownMenuEntries::ShowPlaceHouses: // Setting could be changed when the dropdown was open if (_settings_game.economy.place_houses != PlaceHouses::Forbidden) ShowBuildHousePicker(nullptr); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 9a563d9911..9fa6519602 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2175,10 +2175,10 @@ std::tuple CmdFoundTown(DoCommandFlags flags, TileIn /* Some things are allowed only in the scenario editor and for game scripts. */ if (_game_mode != GameMode::Editor && _current_company != OWNER_DEITY) { - if (_settings_game.economy.found_town == TF_FORBIDDEN) return { CMD_ERROR, 0, TownID::Invalid() }; + if (_settings_game.economy.found_town == TownFounding::Forbidden) return { CMD_ERROR, 0, TownID::Invalid() }; if (size == TownSize::Large) return { CMD_ERROR, 0, TownID::Invalid() }; if (random_location) return { CMD_ERROR, 0, TownID::Invalid() }; - if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT && layout != _settings_game.economy.town_layout) { + if (_settings_game.economy.found_town != TownFounding::CustomLayout && layout != _settings_game.economy.town_layout) { return { CMD_ERROR, 0, TownID::Invalid() }; } } else if (_current_company == OWNER_DEITY && random_location) { diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 9191a9a5d6..434fed90d6 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -1176,7 +1176,7 @@ public: this->GetWidget(WID_TF_TOWN_ACTION_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL); this->GetWidget(WID_TF_TOWN_EXPAND_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL); this->GetWidget(WID_TF_SIZE_SEL)->SetDisplayedPlane(SZSP_VERTICAL); - if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT) { + if (_settings_game.economy.found_town != TownFounding::CustomLayout) { this->GetWidget(WID_TF_ROAD_LAYOUT_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL); } else { this->GetWidget(WID_TF_ROAD_LAYOUT_SEL)->SetDisplayedPlane(0); @@ -1200,7 +1200,7 @@ public: void UpdateButtons(bool check_availability) { if (check_availability && _game_mode != GameMode::Editor) { - if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT) this->town_layout = _settings_game.economy.town_layout; + if (_settings_game.economy.found_town != TownFounding::CustomLayout) this->town_layout = _settings_game.economy.town_layout; this->ReInit(); } diff --git a/src/town_type.h b/src/town_type.h index e101c7682a..dca2668ad2 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -101,12 +101,10 @@ enum class TownExpandMode : uint8_t { using TownExpandModes = EnumBitSet; /** Town founding setting values. It needs to be 8bits, because we save and load it as such */ -enum TownFounding : uint8_t { - TF_BEGIN = 0, ///< Used for iterations and limit testing - TF_FORBIDDEN = 0, ///< Forbidden - TF_ALLOWED, ///< Allowed - TF_CUSTOM_LAYOUT, ///< Allowed, with custom town layout - TF_END, ///< Used for iterations and limit testing +enum class TownFounding : uint8_t { + Forbidden, ///< Forbidden + Allowed, ///< Allowed + CustomLayout, ///< Allowed, with custom town layout }; /** Town cargo generation modes */