From 33d9e48bcf7e1b8575951df5c7bffabbe92dbef6 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 30 Jan 2021 19:59:00 +0000 Subject: [PATCH] Add setting for inflation dates mode --- src/economy.cpp | 8 ++++++-- src/lang/english.txt | 2 ++ src/saveload/afterload.cpp | 4 ++++ src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 8 ++++++++ 8 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index 3ac618abae..9f66afd29b 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -768,7 +768,11 @@ bool AddInflation(bool check_year) * inflation doesn't add anything after that either; it even makes playing * it impossible due to the diverging cost and income rates. */ - if (check_year && (_cur_year < ORIGINAL_BASE_YEAR || _cur_year >= ORIGINAL_MAX_YEAR)) return true; + if (_settings_game.economy.inflation_fixed_dates) { + if (check_year && (_cur_year < ORIGINAL_BASE_YEAR || _cur_year >= ORIGINAL_MAX_YEAR)) return true; + } else { + if (check_year && (_cur_year - _settings_game.game_creation.starting_year) >= (ORIGINAL_MAX_YEAR - ORIGINAL_BASE_YEAR)) return true; + } if (_economy.inflation_prices == MAX_INFLATION || _economy.inflation_payment == MAX_INFLATION) return true; @@ -960,7 +964,7 @@ void StartupEconomy() _economy.infl_amount_pr = max(0, _settings_game.difficulty.initial_interest - 1); _economy.fluct = GB(Random(), 0, 8) + 168; - if (_settings_game.economy.inflation) { + if (_settings_game.economy.inflation && _settings_game.economy.inflation_fixed_dates) { /* Apply inflation that happened before our game start year. */ int months = (min(_cur_year, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR) * 12; for (int i = 0; i < months; i++) { diff --git a/src/lang/english.txt b/src/lang/english.txt index 4c6d059fd1..e1eb804224 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1248,6 +1248,8 @@ STR_CONFIG_SETTING_DISTANT_JOIN_STATIONS :Allow to join s STR_CONFIG_SETTING_DISTANT_JOIN_STATIONS_HELPTEXT :Allow adding parts to a station without directly touching the existing parts. Needs Ctrl+Click while placing the new parts STR_CONFIG_SETTING_INFLATION :Inflation: {STRING2} STR_CONFIG_SETTING_INFLATION_HELPTEXT :Enable inflation in the economy, where costs are slightly faster rising than payments +STR_CONFIG_SETTING_INFLATION_FIXED_DATES :Apply inflation from 1920 to 2090: {STRING2} +STR_CONFIG_SETTING_INFLATION_FIXED_DATES_HELPTEXT :If enabled, inflation is always applied from 1920 to 2090, regardless of the game start date. This is the inflation model used since OpenTTD 1.11.{}If disabled, inflation is applied from the game start date for 170 years. This is the inflation model used until OpenTTD 1.10. STR_CONFIG_SETTING_MAX_BRIDGE_LENGTH :Maximum bridge length: {STRING2} STR_CONFIG_SETTING_MAX_BRIDGE_LENGTH_HELPTEXT :Maximum length for building bridges STR_CONFIG_SETTING_MAX_BRIDGE_HEIGHT :Maximum bridge height: {STRING2} diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index ea8d7e4b7c..64077c18c3 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -3831,6 +3831,10 @@ bool AfterLoadGame() UpdateAllAnimatedTileSpeeds(); } + if (SlXvIsFeatureMissing(XSLFI_INFLATION_FIXED_DATES)) { + _settings_game.economy.inflation_fixed_dates = !IsSavegameVersionBefore(SLV_GS_INDUSTRY_CONTROL); + } + InitializeRoadGUI(); /* This needs to be done after conversion. */ diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index d14fecf73b..d162a49ca2 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -144,6 +144,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_NEWGRF_INFO_EXTRA, XSCF_NULL, 1, 1, "newgrf_info_extra", nullptr, nullptr, nullptr }, { XSLFI_INDUSTRY_CARGO_ADJ, XSCF_IGNORABLE_UNKNOWN, 1, 1, "industry_cargo_adj", nullptr, nullptr, nullptr }, { XSLFI_REALISTIC_TRAIN_BRAKING,XSCF_NULL, 1, 1, "realistic_train_braking", nullptr, nullptr, "VLKA" }, + { XSLFI_INFLATION_FIXED_DATES, XSCF_IGNORABLE_ALL, 1, 1, "inflation_fixed_dates", nullptr, nullptr, nullptr }, { XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker }; diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index 62ce068784..0e346e264d 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -98,6 +98,7 @@ enum SlXvFeatureIndex { XSLFI_NEWGRF_INFO_EXTRA, ///< Extra NewGRF info in savegame XSLFI_INDUSTRY_CARGO_ADJ, ///< Industry cargo adjustment patch XSLFI_REALISTIC_TRAIN_BRAKING, ///< Realistic train braking + XSLFI_INFLATION_FIXED_DATES, ///< Inflation is applied between fixed dates XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index bf5aca3fa5..a941345d48 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1798,6 +1798,7 @@ static SettingsContainer &GetSettingsTree() SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING)); { accounting->Add(new SettingEntry("economy.inflation")); + accounting->Add(new SettingEntry("economy.inflation_fixed_dates")); accounting->Add(new SettingEntry("economy.day_length_factor")); accounting->Add(new SettingEntry("difficulty.initial_interest")); accounting->Add(new SettingEntry("difficulty.max_loan")); diff --git a/src/settings_type.h b/src/settings_type.h index cfc15fb9a7..102b9815e3 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -571,6 +571,7 @@ struct VehicleSettings { /** Settings related to the economy. */ struct EconomySettings { bool inflation; ///< disable inflation + bool inflation_fixed_dates; ///< whether inflation is applied between fixed dates bool bribe; ///< enable bribing the local authority EconomyType type; ///< economy type (original/smooth/frozen) bool allow_shares; ///< allow the buying/selling of shares diff --git a/src/table/settings.ini b/src/table/settings.ini index eb458a3806..6a7fd0b0e8 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -2029,6 +2029,14 @@ str = STR_CONFIG_SETTING_INFLATION strhelp = STR_CONFIG_SETTING_INFLATION_HELPTEXT cat = SC_BASIC +[SDT_BOOL] +base = GameSettings +var = economy.inflation_fixed_dates +def = true +str = STR_CONFIG_SETTING_INFLATION_FIXED_DATES +strhelp = STR_CONFIG_SETTING_INFLATION_FIXED_DATES_HELPTEXT +patxname = ""inflation_fixed_dates.economy.inflation_fixed_dates"" + [SDT_VAR] base = GameSettings var = economy.day_length_factor