From a3371fccc6f9f3cac4656aaebfa2c14d0356f4ae Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 26 Nov 2023 11:32:26 +0000 Subject: [PATCH] Remove Cheats/ExtraCheats distinction It is not necessary as there is no longer a need to preserve the size/order of struct Cheats --- src/cheat.cpp | 9 --------- src/cheat_func.h | 1 - src/cheat_gui.cpp | 6 +++--- src/cheat_type.h | 10 +--------- src/misc_cmd.cpp | 10 +++++----- src/sl/cheat_sl.cpp | 6 +++--- src/station_cmd.cpp | 2 +- src/town_cmd.cpp | 14 +++++++------- 8 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/cheat.cpp b/src/cheat.cpp index fc3f8b9904..e22484e025 100644 --- a/src/cheat.cpp +++ b/src/cheat.cpp @@ -17,7 +17,6 @@ /** All the cheats. */ Cheats _cheats; -ExtraCheats _extra_cheats; std::map _unknown_cheats; @@ -25,7 +24,6 @@ std::map _unknown_cheats; void InitializeCheats() { memset(&_cheats, 0, sizeof(Cheats)); - memset(&_extra_cheats, 0, sizeof(ExtraCheats)); _unknown_cheats.clear(); } @@ -43,12 +41,5 @@ bool CheatHasBeenUsed() if (cht->been_used) return true; } - cht = (Cheat*)&_extra_cheats; - cht_last = &cht[sizeof(_extra_cheats) / sizeof(Cheat)]; - - for (; cht != cht_last; cht++) { - if (cht->been_used) return true; - } - return false; } diff --git a/src/cheat_func.h b/src/cheat_func.h index 248601372d..6d26e71c4a 100644 --- a/src/cheat_func.h +++ b/src/cheat_func.h @@ -13,7 +13,6 @@ #include "cheat_type.h" extern Cheats _cheats; -extern ExtraCheats _extra_cheats; void ShowCheatWindow(); diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 65bc4b2b0f..349ddc39b5 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -196,10 +196,10 @@ static const CheatEntry _cheats_ui[] = { {CNM_LOCAL_ONLY, SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat }, {CNM_LOCAL_ONLY, SLE_UINT8, STR_CHEAT_EDIT_MAX_HL, &_settings_game.construction.map_height_limit, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat }, {CNM_LOCAL_ONLY, SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_date_ymd.year, &_cheats.change_date.been_used, &ClickChangeDateCheat }, - {CNM_ALL, SLF_ALLOW_CONTROL, STR_CHEAT_INFLATION_COST, &_economy.inflation_prices, &_extra_cheats.inflation_cost.been_used, nullptr }, - {CNM_ALL, SLF_ALLOW_CONTROL, STR_CHEAT_INFLATION_INCOME, &_economy.inflation_payment, &_extra_cheats.inflation_income.been_used, nullptr }, + {CNM_ALL, SLF_ALLOW_CONTROL, STR_CHEAT_INFLATION_COST, &_economy.inflation_prices, &_cheats.inflation_cost.been_used, nullptr }, + {CNM_ALL, SLF_ALLOW_CONTROL, STR_CHEAT_INFLATION_INCOME, &_economy.inflation_payment, &_cheats.inflation_income.been_used, nullptr }, {CNM_ALL, SLE_BOOL, STR_CHEAT_STATION_RATING, &_cheats.station_rating.value, &_cheats.station_rating.been_used, nullptr }, - {CNM_ALL, SLE_BOOL, STR_CHEAT_TOWN_RATING, &_extra_cheats.town_rating.value, &_extra_cheats.town_rating.been_used, nullptr }, + {CNM_ALL, SLE_BOOL, STR_CHEAT_TOWN_RATING, &_cheats.town_rating.value, &_cheats.town_rating.been_used, nullptr }, }; static bool IsCheatAllowed(CheatNetworkMode mode) diff --git a/src/cheat_type.h b/src/cheat_type.h index a1f9b0820e..5318b15112 100644 --- a/src/cheat_type.h +++ b/src/cheat_type.h @@ -18,11 +18,6 @@ struct Cheat { bool value; ///< tells if the bool cheat is active or not }; -/** - * WARNING! Do _not_ remove entries in Cheats struct or change the order - * of the existing ones! Would break downward compatibility. - * Only add new entries at the end of the struct! - */ struct Cheats { Cheat magic_bulldozer; ///< dynamite industries, objects Cheat switch_company; ///< change to another company @@ -33,9 +28,7 @@ struct Cheats { Cheat setup_prod; ///< setup raw-material production in game Cheat edit_max_hl; ///< edit the maximum heightlevel; this is a cheat because of the fact that it needs to reset NewGRF game state and doing so as a simple configuration breaks the expectation of many Cheat station_rating; ///< Fix station ratings at 100% -}; - -struct ExtraCheats { + /* non-trunk cheats follow */ Cheat inflation_cost; ///< inflation cost factor Cheat inflation_income; ///< inflation income factor Cheat town_rating; ///< 100% town local authority rating @@ -60,6 +53,5 @@ enum CheatNumbers { }; extern Cheats _cheats; -extern ExtraCheats _extra_cheats; #endif /* CHEAT_TYPE_H */ diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index 7ac498ed4f..7e1080456f 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -267,11 +267,11 @@ CommandCost CmdCheatSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint case CHT_INFLATION_INCOME: if (flags & DC_EXEC) { - _extra_cheats.inflation_income.been_used = true; + _cheats.inflation_income.been_used = true; _economy.inflation_payment = Clamp(p2, 1 << 16, MAX_INFLATION); if (_economy.inflation_payment > _economy.inflation_prices) { _economy.inflation_prices = _economy.inflation_payment; - _extra_cheats.inflation_cost.been_used = true; + _cheats.inflation_cost.been_used = true; } RecomputePrices(); SetWindowDirty(WC_CHEATS, 0); @@ -280,11 +280,11 @@ CommandCost CmdCheatSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint case CHT_INFLATION_COST: if (flags & DC_EXEC) { - _extra_cheats.inflation_cost.been_used = true; + _cheats.inflation_cost.been_used = true; _economy.inflation_prices = Clamp(p2, 1 << 16, MAX_INFLATION); if (_economy.inflation_payment > _economy.inflation_prices) { _economy.inflation_payment = _economy.inflation_prices; - _extra_cheats.inflation_income.been_used = true; + _cheats.inflation_income.been_used = true; } RecomputePrices(); SetWindowDirty(WC_CHEATS, 0); @@ -296,7 +296,7 @@ CommandCost CmdCheatSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint break; case CHT_TOWN_RATING: - cht = &_extra_cheats.town_rating; + cht = &_cheats.town_rating; break; default: diff --git a/src/sl/cheat_sl.cpp b/src/sl/cheat_sl.cpp index 70bf021559..75d4a09a96 100644 --- a/src/sl/cheat_sl.cpp +++ b/src/sl/cheat_sl.cpp @@ -26,10 +26,10 @@ struct ExtraCheatNameDesc { }; static ExtraCheatNameDesc _extra_cheat_descs[] = { - { "inflation_cost", &_extra_cheats.inflation_cost }, - { "inflation_income", &_extra_cheats.inflation_income }, + { "inflation_cost", &_cheats.inflation_cost }, + { "inflation_income", &_cheats.inflation_income }, { "station_rating", &_cheats.station_rating }, - { "town_rating", &_extra_cheats.town_rating }, + { "town_rating", &_cheats.town_rating }, }; static const SaveLoad _cheats_desc[] = { diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 7dee8bd99c..2524c507a6 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -799,7 +799,7 @@ static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reus ZoningTownAuthorityRatingChange(); } SetBit((*st)->town->have_ratings, _current_company); - if (_extra_cheats.town_rating.value) { + if (_cheats.town_rating.value) { (*st)->town->ratings[_current_company] = RATING_MAXIMUM; } } diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 4ec3104b57..6ff073c523 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -823,7 +823,7 @@ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags) if (rating > t->ratings[_current_company] && !(flags & DC_NO_TEST_TOWN_RATING) && !_cheats.magic_bulldozer.value - && !_extra_cheats.town_rating.value + && !_cheats.town_rating.value && _settings_game.difficulty.town_council_tolerance != TOWN_COUNCIL_PERMISSIVE) { SetDParam(0, t->index); return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS); @@ -3386,7 +3386,7 @@ CommandCost CmdTownRating(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (!Company::IsValidID(company_id)) return CMD_ERROR; int16 new_rating = Clamp((int16)GB(p2, 0, 16), RATING_MINIMUM, RATING_MAXIMUM); - if (_extra_cheats.town_rating.value) { + if (_cheats.town_rating.value) { new_rating = RATING_MAXIMUM; } if (flags & DC_EXEC) { @@ -3960,7 +3960,7 @@ static void ForAllStationsNearTown(Town *t, Func func) static void UpdateTownRating(Town *t) { - if (_extra_cheats.town_rating.value) return; + if (_cheats.town_rating.value) return; /* Increase company ratings if they're low */ for (const Company *c : Company::Iterate()) { @@ -4294,13 +4294,13 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags) /* if magic_bulldozer cheat is active, town doesn't penalize for removing stuff */ if (t == nullptr || (flags & DC_NO_MODIFY_TOWN_RATING) || !Company::IsValidID(_current_company) || - ((_cheats.magic_bulldozer.value || _extra_cheats.town_rating.value) && add < 0)) { + ((_cheats.magic_bulldozer.value || _cheats.town_rating.value) && add < 0)) { return; } const int prev_rating = GetRating(t); int rating = prev_rating; - if (_extra_cheats.town_rating.value) { + if (_cheats.town_rating.value) { rating = RATING_MAXIMUM; } else if (add < 0) { if (rating > max) { @@ -4329,7 +4329,7 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags) void UpdateAllTownRatings() { - if (_extra_cheats.town_rating.value) { + if (_cheats.town_rating.value) { for (Town *t : Town::Iterate()) { if (Company::IsValidID(_local_company) && HasBit(t->have_ratings, _local_company) && t->ratings[_local_company] <= 0) { ZoningTownAuthorityRatingChange(); @@ -4356,7 +4356,7 @@ CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType { /* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */ if (t == nullptr || !Company::IsValidID(_current_company) || - _cheats.magic_bulldozer.value || _extra_cheats.town_rating.value || (flags & DC_NO_TEST_TOWN_RATING)) { + _cheats.magic_bulldozer.value || _cheats.town_rating.value || (flags & DC_NO_TEST_TOWN_RATING)) { return CommandCost(); }