1
0
Fork 0
pull/12974/merge
AviationGamerX 2025-01-30 00:34:06 +00:00 committed by GitHub
commit 7b657de482
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 35 additions and 22 deletions

View File

@ -17,6 +17,7 @@
#include "timer/timer_game_economy.h" #include "timer/timer_game_economy.h"
#include "settings_type.h" #include "settings_type.h"
#include "group.h" #include "group.h"
#include "currency.h"
static const Money COMPANY_MAX_LOAN_DEFAULT = INT64_MIN; 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); 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 CalculateCompanyValue(const Company *c, bool including_loan = true);
Money CalculateHostileTakeoverValue(const Company *c); Money CalculateHostileTakeoverValue(const Company *c);

View File

@ -33,6 +33,7 @@
#include "sound_func.h" #include "sound_func.h"
#include "autoreplace_func.h" #include "autoreplace_func.h"
#include "company_gui.h" #include "company_gui.h"
#include "company_base.h"
#include "signs_base.h" #include "signs_base.h"
#include "subsidy_base.h" #include "subsidy_base.h"
#include "subsidy_func.h" #include "subsidy_func.h"
@ -759,7 +760,7 @@ bool AddInflation(bool check_year)
void RecomputePrices() void RecomputePrices()
{ {
/* Setup maximum loan as a rounded down multiple of LOAN_INTERVAL. */ /* 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 */ /* Setup price bases */
for (Price i = PR_BEGIN; i < PR_END; i++) { for (Price i = PR_BEGIN; i < PR_END; i++) {

View File

@ -1285,9 +1285,9 @@ STR_CONFIG_SETTING_SECONDS_VALUE :{COMMA}{NBSP}se
STR_CONFIG_SETTING_INFINITE_MONEY :Infinite money: {STRING2} 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_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 :Maximum initial loan percentage: {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_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 :{CURRENCY_LONG} STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{NUM}%
###setting-zero-is-special ###setting-zero-is-special
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :No loan STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :No loan

View File

@ -1284,9 +1284,9 @@ STR_CONFIG_SETTING_SECONDS_VALUE :{COMMA}{NBSP}se
STR_CONFIG_SETTING_INFINITE_MONEY :Infinite money: {STRING} 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_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 :Maximum initial loan percentage: {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_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 :{CURRENCY_LONG} STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{NUM}%
###setting-zero-is-special ###setting-zero-is-special
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :No loan STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :No loan

View File

@ -63,6 +63,7 @@
#include "../timer/timer_game_calendar.h" #include "../timer/timer_game_calendar.h"
#include "../timer/timer_game_economy.h" #include "../timer/timer_game_economy.h"
#include "../timer/timer_game_tick.h" #include "../timer/timer_game_tick.h"
#include "../company_base.h"
#include "saveload_internal.h" #include "saveload_internal.h"
@ -2335,7 +2336,7 @@ bool AfterLoadGame()
* So taking the 16 bit fractional part into account there are plenty of bits left * So taking the 16 bit fractional part into account there are plenty of bits left
* for unmodified savegames ... * 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. */ /* ... well, just clamp it then. */
if (aimed_inflation > MAX_INFLATION) aimed_inflation = MAX_INFLATION; if (aimed_inflation > MAX_INFLATION) aimed_inflation = MAX_INFLATION;

View File

@ -32,7 +32,7 @@ const SaveLoadCompat _settings_sl_compat[] = {
SLC_NULL(1, SLV_97, SLV_110), SLC_NULL(1, SLV_97, SLV_110),
SLC_VAR("difficulty.number_towns"), SLC_VAR("difficulty.number_towns"),
SLC_VAR("difficulty.industry_density"), SLC_VAR("difficulty.industry_density"),
SLC_VAR("difficulty.max_loan"), SLC_VAR("difficulty.max_loan_percentage"),
SLC_VAR("difficulty.initial_interest"), SLC_VAR("difficulty.initial_interest"),
SLC_VAR("difficulty.vehicle_costs"), SLC_VAR("difficulty.vehicle_costs"),
SLC_VAR("difficulty.competitor_speed"), SLC_VAR("difficulty.competitor_speed"),

View File

@ -1472,7 +1472,7 @@ static const OldChunks game_difficulty_chunk[] = {
OCL_NULL( 2), // competitor_start_time 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, number_towns ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, industry_density ), 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, initial_interest ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, vehicle_costs ), OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, vehicle_costs ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, competitor_speed ), OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, DifficultySettings, competitor_speed ),
@ -1491,7 +1491,7 @@ static const OldChunks game_difficulty_chunk[] = {
static bool LoadOldGameDifficulty(LoadgameState *ls, int) static bool LoadOldGameDifficulty(LoadgameState *ls, int)
{ {
bool ret = LoadChunk(ls, &_settings_game.difficulty, game_difficulty_chunk); 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; return ret;
} }

View File

@ -63,7 +63,7 @@ void HandleOldDiffCustom(bool savegame)
continue; 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); sd->AsIntSetting()->MakeValueValidAndWrite(savegame ? &_settings_game : &_settings_newgame, value);
} }
} }

View File

@ -2106,7 +2106,7 @@ static SettingsContainer &GetSettingsTree()
accounting->Add(new SettingEntry("difficulty.infinite_money")); accounting->Add(new SettingEntry("difficulty.infinite_money"));
accounting->Add(new SettingEntry("economy.inflation")); accounting->Add(new SettingEntry("economy.inflation"));
accounting->Add(new SettingEntry("difficulty.initial_interest")); 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_multiplier"));
accounting->Add(new SettingEntry("difficulty.subsidy_duration")); accounting->Add(new SettingEntry("difficulty.subsidy_duration"));
accounting->Add(new SettingEntry("economy.feeder_payment_share")); accounting->Add(new SettingEntry("economy.feeder_payment_share"));

View File

@ -100,7 +100,7 @@ struct DifficultySettings {
uint16_t competitors_interval; ///< the interval (in minutes) between adding competitors uint16_t competitors_interval; ///< the interval (in minutes) between adding competitors
uint8_t number_towns; ///< the amount of towns uint8_t number_towns; ///< the amount of towns
uint8_t industry_density; ///< The industry density. @see IndustryDensity uint8_t industry_density; ///< The industry density. @see IndustryDensity
uint32_t max_loan; ///< the maximum initial 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 initial_interest; ///< amount of interest (to pay over the loan)
uint8_t vehicle_costs; ///< amount of money spent on vehicle running cost uint8_t vehicle_costs; ///< amount of money spent on vehicle running cost
uint8_t competitor_speed; ///< the speed at which the AI builds uint8_t competitor_speed; ///< the speed at which the AI builds
@ -636,4 +636,5 @@ inline GameSettings &GetGameSettings()
return (_game_mode == GM_MENU) ? _settings_newgame : _settings_game; return (_game_mode == GM_MENU) ? _settings_newgame : _settings_game;
} }
#endif /* SETTINGS_TYPE_H */ #endif /* SETTINGS_TYPE_H */

View File

@ -8,7 +8,7 @@
; and in the savegame PATS chunk. ; and in the savegame PATS chunk.
[pre-amble] [pre-amble]
const std::array<std::string, GAME_DIFFICULTY_NUM> _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<std::string, GAME_DIFFICULTY_NUM> _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]; uint16_t _old_diff_custom[GAME_DIFFICULTY_NUM];
uint8_t _old_diff_level; ///< Old difficulty level from old savegames uint8_t _old_diff_level; ///< Old difficulty level from old savegames
@ -107,15 +107,15 @@ strval = STR_FUNDING_ONLY
cat = SC_BASIC cat = SC_BASIC
[SDT_VAR] [SDT_VAR]
var = difficulty.max_loan var = difficulty.max_loan_percentage
type = SLE_UINT32 type = SLE_UINT32
from = SLV_97 from = SLV_97
flags = SF_NEWGAME_ONLY | SF_SCENEDIT_TOO | SF_GUI_CURRENCY | SF_GUI_0_IS_SPECIAL flags = SF_NEWGAME_ONLY | SF_SCENEDIT_TOO | SF_GUI_0_IS_SPECIAL
def = 300000 def = 100
min = LOAN_INTERVAL min = 100
max = MAX_LOAN_LIMIT max = 6000000
pre_cb = [](auto &new_value) { new_value = (new_value + LOAN_INTERVAL / 2) / LOAN_INTERVAL * LOAN_INTERVAL; return true; } pre_cb = [](auto &new_value) { new_value = (new_value + 100 / 2) / 100 * 100; return true; }
interval = LOAN_INTERVAL interval = 100
str = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN str = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN
strhelp = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT strhelp = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT
strval = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE strval = STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE