From 2f7d225b194151245a7616899ffafba6b30708da Mon Sep 17 00:00:00 2001 From: AviationGamerX <76180779+AviationGamerX@users.noreply.github.com> Date: Sat, 14 Sep 2024 22:41:44 +0300 Subject: [PATCH 1/7] Update english.txt Changed Max loan texts to fit the new percentage setting change --- src/lang/english.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index ff5607a337..c379d1befa 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1273,9 +1273,9 @@ STR_CONFIG_SETTING_SECONDS_VALUE :{COMMA}{NBSP}se STR_CONFIG_SETTING_INFINITE_MONEY :Infinite money: {STRING2} STR_CONFIG_SETTING_INFINITE_MONEY_HELPTEXT :Allow unlimited spending and disable bankruptcy of companies -STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :Maximum initial loan: {STRING2} -STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Maximum amount a company can loan (without taking inflation into account). If set to "No loan", no money will be available unless provided by a Game Script or the "Infinite money" setting -STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{CURRENCY_LONG} +STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :Maximum initial loan percentage: {STRING2} +STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Maximum percentage a company can loan. If set to "No loan", no money will be available unless provided by a Game Script or the "Infinite money" setting +STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{NUM}% ###setting-zero-is-special STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :No loan From 0c3ece739650c16caecbe88991b2c2ceabbb1fee Mon Sep 17 00:00:00 2001 From: AviationGamerX <76180779+AviationGamerX@users.noreply.github.com> Date: Sat, 14 Sep 2024 22:55:57 +0300 Subject: [PATCH 2/7] Update settings_type.h: Difficulity Struct Addition Added a new variable that holds the new percentage of max loan --- src/settings_type.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/settings_type.h b/src/settings_type.h index ae6f22c42e..8fea3a0039 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -101,6 +101,7 @@ struct DifficultySettings { uint8_t number_towns; ///< the amount of towns uint8_t industry_density; ///< The industry density. @see IndustryDensity uint32_t max_loan; ///< the maximum initial loan + uint32_t max_loan_percentage; ///< the percentage increase/decrease of the default maximum intial loan uint8_t initial_interest; ///< amount of interest (to pay over the loan) uint8_t vehicle_costs; ///< amount of money spent on vehicle running cost uint8_t competitor_speed; ///< the speed at which the AI builds From f883bd67bc9fc22d284846ffa592e52cf8d9e8a5 Mon Sep 17 00:00:00 2001 From: AviationGamerX <76180779+AviationGamerX@users.noreply.github.com> Date: Tue, 17 Sep 2024 01:01:48 +0300 Subject: [PATCH 3/7] Update difficulty_settings.ini: replaced max_loan with max_loan_percentage and made max_loan update after the percentage is changed --- src/table/settings/difficulty_settings.ini | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/table/settings/difficulty_settings.ini b/src/table/settings/difficulty_settings.ini index 4e8e1044a9..358e613cef 100644 --- a/src/table/settings/difficulty_settings.ini +++ b/src/table/settings/difficulty_settings.ini @@ -8,7 +8,7 @@ ; and in the savegame PATS chunk. [pre-amble] -const std::array _old_diff_settings{"max_no_competitors", "competitor_start_time", "number_towns", "industry_density", "max_loan", "initial_interest", "vehicle_costs", "competitor_speed", "competitor_intelligence", "vehicle_breakdowns", "subsidy_multiplier", "construction_cost", "terrain_type", "quantity_sea_lakes", "economy", "line_reverse_mode", "disasters", "town_council_tolerance"}; +const std::array _old_diff_settings{"max_no_competitors", "competitor_start_time", "number_towns", "industry_density", "max_loan_percentage", "initial_interest", "vehicle_costs", "competitor_speed", "competitor_intelligence", "vehicle_breakdowns", "subsidy_multiplier", "construction_cost", "terrain_type", "quantity_sea_lakes", "economy", "line_reverse_mode", "disasters", "town_council_tolerance"}; uint16_t _old_diff_custom[GAME_DIFFICULTY_NUM]; uint8_t _old_diff_level; ///< Old difficulty level from old savegames @@ -106,15 +106,16 @@ strval = STR_FUNDING_ONLY cat = SC_BASIC [SDT_VAR] -var = difficulty.max_loan +var = difficulty.max_loan_percentage type = SLE_UINT32 from = SLV_97 -flags = SF_NEWGAME_ONLY | SF_SCENEDIT_TOO | SF_GUI_CURRENCY | SF_GUI_0_IS_SPECIAL -def = 300000 -min = LOAN_INTERVAL -max = MAX_LOAN_LIMIT -pre_cb = [](auto &new_value) { new_value = (new_value + LOAN_INTERVAL / 2) / LOAN_INTERVAL * LOAN_INTERVAL; return true; } -interval = LOAN_INTERVAL +flags = SF_NEWGAME_ONLY | SF_SCENEDIT_TOO | SF_GUI_0_IS_SPECIAL +def = 100 +min = 10 +max = 6000000 +pre_cb = [](auto &new_value) { new_value = (new_value + 10 / 2) / 10 * 10; return true; } +post_cb = [](auto &new_value) { difficulity.max_loan = ((new_value/100)* 300000) * GetCurrency().rate; return true;} +interval = 10 str = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN strhelp = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT strval = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE From 310f84fd17b489f0303c559f97e677758f50d6d2 Mon Sep 17 00:00:00 2001 From: AviationGamerX <76180779+AviationGamerX@users.noreply.github.com> Date: Tue, 17 Sep 2024 01:04:04 +0300 Subject: [PATCH 4/7] Update settings_gui.cpp: Changed max_loan to percentage --- src/settings_gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index fb5c08ec86..61539ca817 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2104,7 +2104,7 @@ static SettingsContainer &GetSettingsTree() accounting->Add(new SettingEntry("difficulty.infinite_money")); accounting->Add(new SettingEntry("economy.inflation")); accounting->Add(new SettingEntry("difficulty.initial_interest")); - accounting->Add(new SettingEntry("difficulty.max_loan")); + accounting->Add(new SettingEntry("difficulty.max_loan_percentage")); accounting->Add(new SettingEntry("difficulty.subsidy_multiplier")); accounting->Add(new SettingEntry("difficulty.subsidy_duration")); accounting->Add(new SettingEntry("economy.feeder_payment_share")); From 9cdd217e536a46625fa8b48f9f89691040f30039 Mon Sep 17 00:00:00 2001 From: AviationGamerX <76180779+AviationGamerX@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:21:31 +0300 Subject: [PATCH 5/7] removed "newvalue" in post_cb, and added "_settings_game" to define where difficulty is from (also corrected misspeslling "difficulity" to "difficulty") --- src/table/settings/difficulty_settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/table/settings/difficulty_settings.ini b/src/table/settings/difficulty_settings.ini index 358e613cef..4955a7ed14 100644 --- a/src/table/settings/difficulty_settings.ini +++ b/src/table/settings/difficulty_settings.ini @@ -114,7 +114,7 @@ def = 100 min = 10 max = 6000000 pre_cb = [](auto &new_value) { new_value = (new_value + 10 / 2) / 10 * 10; return true; } -post_cb = [](auto &new_value) { difficulity.max_loan = ((new_value/100)* 300000) * GetCurrency().rate; return true;} +post_cb = [](auto) { _settings_game.difficulty.max_loan = ((_settings_game.difficulty.max_loan_percentage/100)* 300000) * GetCurrency().rate;} interval = 10 str = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN strhelp = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT From 42301884ce55791c1cf749a47aa0b908ef61a961 Mon Sep 17 00:00:00 2001 From: AviationGamerX <76180779+AviationGamerX@users.noreply.github.com> Date: Wed, 2 Oct 2024 23:19:57 +0300 Subject: [PATCH 6/7] Replaced max_loan with a function that calculates the max_loan from the max_loan_percentage (added some includes in where they were used) And replaced other uses of max_loan with max_loan_percentage. --- src/company_base.h | 10 ++++++++++ src/economy.cpp | 3 ++- src/saveload/afterload.cpp | 3 ++- src/saveload/compat/settings_sl_compat.h | 2 +- src/saveload/oldloader_sl.cpp | 4 ++-- src/saveload/settings_sl.cpp | 2 +- src/settings_type.h | 4 ++-- src/table/settings/difficulty_settings.ini | 5 ++--- 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/company_base.h b/src/company_base.h index 24f9051fc2..e43d3ec209 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -17,6 +17,7 @@ #include "timer/timer_game_economy.h" #include "settings_type.h" #include "group.h" +#include "currency.h" static const Money COMPANY_MAX_LOAN_DEFAULT = INT64_MIN; @@ -189,6 +190,15 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> { static void PostDestructor(size_t index); }; +/** +* Function to get the max loan from the saved percentage in the settings (inline makes it avoid many unwanted errors) +*/ +inline uint32_t GetMaxLoanFromPercentage() +{ + return ((_settings_game.difficulty.max_loan_percentage / 100) * 300000) * GetCurrency().rate; +} + + Money CalculateCompanyValue(const Company *c, bool including_loan = true); Money CalculateHostileTakeoverValue(const Company *c); diff --git a/src/economy.cpp b/src/economy.cpp index cd99094239..19e07aba12 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -33,6 +33,7 @@ #include "sound_func.h" #include "autoreplace_func.h" #include "company_gui.h" +#include "company_base.h" #include "signs_base.h" #include "subsidy_base.h" #include "subsidy_func.h" @@ -762,7 +763,7 @@ bool AddInflation(bool check_year) void RecomputePrices() { /* Setup maximum loan as a rounded down multiple of LOAN_INTERVAL. */ - _economy.max_loan = ((uint64_t)_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / LOAN_INTERVAL * LOAN_INTERVAL; + _economy.max_loan = ((uint64_t)GetMaxLoanFromPercentage() * _economy.inflation_prices >> 16) / LOAN_INTERVAL * LOAN_INTERVAL; /* Setup price bases */ for (Price i = PR_BEGIN; i < PR_END; i++) { diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index e1d06532bb..df41ee96c1 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -62,6 +62,7 @@ #include "../timer/timer_game_calendar.h" #include "../timer/timer_game_economy.h" #include "../timer/timer_game_tick.h" +#include "../company_base.h" #include "saveload_internal.h" @@ -2293,7 +2294,7 @@ bool AfterLoadGame() * So taking the 16 bit fractional part into account there are plenty of bits left * for unmodified savegames ... */ - uint64_t aimed_inflation = (_economy.old_max_loan_unround << 16 | _economy.old_max_loan_unround_fract) / _settings_game.difficulty.max_loan; + uint64_t aimed_inflation = (_economy.old_max_loan_unround << 16 | _economy.old_max_loan_unround_fract) / GetMaxLoanFromPercentage(); /* ... well, just clamp it then. */ if (aimed_inflation > MAX_INFLATION) aimed_inflation = MAX_INFLATION; diff --git a/src/saveload/compat/settings_sl_compat.h b/src/saveload/compat/settings_sl_compat.h index 37005b98e2..b1a5b7666f 100644 --- a/src/saveload/compat/settings_sl_compat.h +++ b/src/saveload/compat/settings_sl_compat.h @@ -32,7 +32,7 @@ const SaveLoadCompat _settings_sl_compat[] = { SLC_NULL(1, SLV_97, SLV_110), SLC_VAR("difficulty.number_towns"), SLC_VAR("difficulty.industry_density"), - SLC_VAR("difficulty.max_loan"), + SLC_VAR("difficulty.max_loan_percentage"), SLC_VAR("difficulty.initial_interest"), SLC_VAR("difficulty.vehicle_costs"), SLC_VAR("difficulty.competitor_speed"), diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index ea9c97c212..166cd22ad5 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -1471,7 +1471,7 @@ static const OldChunks game_difficulty_chunk[] = { OCL_NULL( 2), // competitor_start_time OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, number_towns ), OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, industry_density ), - OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, DifficultySettings, max_loan ), + OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, DifficultySettings, max_loan_percentage ), OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, initial_interest ), OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, vehicle_costs ), OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, competitor_speed ), @@ -1490,7 +1490,7 @@ static const OldChunks game_difficulty_chunk[] = { static bool LoadOldGameDifficulty(LoadgameState *ls, int) { bool ret = LoadChunk(ls, &_settings_game.difficulty, game_difficulty_chunk); - _settings_game.difficulty.max_loan *= 1000; + _settings_game.difficulty.max_loan_percentage *= 1000; return ret; } diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp index 0d09ec4cd9..e5bb21fa22 100644 --- a/src/saveload/settings_sl.cpp +++ b/src/saveload/settings_sl.cpp @@ -63,7 +63,7 @@ void HandleOldDiffCustom(bool savegame) continue; } - int32_t value = (int32_t)((name == "max_loan" ? 1000 : 1) * _old_diff_custom[i++]); + int32_t value = (int32_t)((name == "max_loan_percentage" ? 1000 : 1) * _old_diff_custom[i++]); sd->AsIntSetting()->MakeValueValidAndWrite(savegame ? &_settings_game : &_settings_newgame, value); } } diff --git a/src/settings_type.h b/src/settings_type.h index 8fea3a0039..a710338744 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -100,8 +100,7 @@ struct DifficultySettings { uint16_t competitors_interval; ///< the interval (in minutes) between adding competitors uint8_t number_towns; ///< the amount of towns uint8_t industry_density; ///< The industry density. @see IndustryDensity - uint32_t max_loan; ///< the maximum initial loan - uint32_t max_loan_percentage; ///< the percentage increase/decrease of the default maximum intial loan + uint32_t max_loan_percentage; ///< the percentage of the maximum intial loan uint8_t initial_interest; ///< amount of interest (to pay over the loan) uint8_t vehicle_costs; ///< amount of money spent on vehicle running cost uint8_t competitor_speed; ///< the speed at which the AI builds @@ -638,4 +637,5 @@ inline GameSettings &GetGameSettings() return (_game_mode == GM_MENU) ? _settings_newgame : _settings_game; } + #endif /* SETTINGS_TYPE_H */ diff --git a/src/table/settings/difficulty_settings.ini b/src/table/settings/difficulty_settings.ini index 4955a7ed14..5e552d81ff 100644 --- a/src/table/settings/difficulty_settings.ini +++ b/src/table/settings/difficulty_settings.ini @@ -111,11 +111,10 @@ type = SLE_UINT32 from = SLV_97 flags = SF_NEWGAME_ONLY | SF_SCENEDIT_TOO | SF_GUI_0_IS_SPECIAL def = 100 -min = 10 +min = 100 max = 6000000 pre_cb = [](auto &new_value) { new_value = (new_value + 10 / 2) / 10 * 10; return true; } -post_cb = [](auto) { _settings_game.difficulty.max_loan = ((_settings_game.difficulty.max_loan_percentage/100)* 300000) * GetCurrency().rate;} -interval = 10 +interval = 100 str = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN strhelp = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT strval = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE From 7a1a36344ae2b6c113dedfa3eb1ed594f25652dd Mon Sep 17 00:00:00 2001 From: AviationGamerX <76180779+AviationGamerX@users.noreply.github.com> Date: Thu, 3 Oct 2024 00:15:06 +0300 Subject: [PATCH 7/7] FInalized everything, made the setting values accept only in 100% intervals. And changed English texts to fit the new changes. --- src/company_base.h | 2 +- src/lang/english.txt | 2 +- src/lang/english_US.txt | 6 +++--- src/table/settings/difficulty_settings.ini | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/company_base.h b/src/company_base.h index e43d3ec209..461a88a340 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -195,7 +195,7 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> { */ inline uint32_t GetMaxLoanFromPercentage() { - return ((_settings_game.difficulty.max_loan_percentage / 100) * 300000) * GetCurrency().rate; + return ((_settings_game.difficulty.max_loan_percentage / 100) * (300000 * GetCurrency().rate)); } diff --git a/src/lang/english.txt b/src/lang/english.txt index a420327c6e..a1c876908e 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1274,7 +1274,7 @@ STR_CONFIG_SETTING_INFINITE_MONEY :Infinite money: STR_CONFIG_SETTING_INFINITE_MONEY_HELPTEXT :Allow unlimited spending and disable bankruptcy of companies STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :Maximum initial loan percentage: {STRING2} -STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Maximum percentage a company can loan. If set to "No loan", no money will be available unless provided by a Game Script or the "Infinite money" setting +STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Sets the maximum loan a company can loan. Default maximum loan is at 100%. If set to "No loan", no money will be available unless provided by a Game Script or the "Infinite money" setting STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{NUM}% ###setting-zero-is-special STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :No loan diff --git a/src/lang/english_US.txt b/src/lang/english_US.txt index 80c0f8396e..97382c3ff9 100644 --- a/src/lang/english_US.txt +++ b/src/lang/english_US.txt @@ -1273,9 +1273,9 @@ STR_CONFIG_SETTING_SECONDS_VALUE :{COMMA}{NBSP}se STR_CONFIG_SETTING_INFINITE_MONEY :Infinite money: {STRING} STR_CONFIG_SETTING_INFINITE_MONEY_HELPTEXT :Allow unlimited spending and disable bankruptcy of companies -STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :Maximum initial loan: {STRING} -STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Maximum amount a company can loan (without taking inflation into account). If set to "No loan", no money will be available unless provided by a Game Script or the "Infinite money" setting -STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{CURRENCY_LONG} +STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :Maximum initial loan percentage: {STRING} +STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Sets the maximum loan a company can loan. Default maximum loan is at 100%. If set to "No loan", no money will be available unless provided by a Game Script or the "Infinite money" setting +STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{NUM}% ###setting-zero-is-special STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :No loan diff --git a/src/table/settings/difficulty_settings.ini b/src/table/settings/difficulty_settings.ini index 5e552d81ff..0619214ce2 100644 --- a/src/table/settings/difficulty_settings.ini +++ b/src/table/settings/difficulty_settings.ini @@ -113,7 +113,7 @@ flags = SF_NEWGAME_ONLY | SF_SCENEDIT_TOO | SF_GUI_0_IS_SPECIAL def = 100 min = 100 max = 6000000 -pre_cb = [](auto &new_value) { new_value = (new_value + 10 / 2) / 10 * 10; return true; } +pre_cb = [](auto &new_value) { new_value = (new_value + 100 / 2) / 100 * 100; return true; } interval = 100 str = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN strhelp = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT