diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 1417c0f793..143a757dae 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -352,4 +352,29 @@ constexpr int RoundDivSU(int a, uint b) uint32_t IntSqrt(uint32_t num); +/** + * Scale a number by the required percentage. + * + * Calculation is performed in the type U of the num parameter. + * The result is clamped to the limits of type T if needed. + * + * @param num The number to scale. + * @param percentage The percentage value. 100% = don't scale. + * @return The number scaled by the percentage value. + */ +template +constexpr T ScaleByPercentage(U num, uint16_t percentage) +{ + U scaled; + /* We might not need to do anything. */ + if (percentage == 100) { + scaled = num; + } else { + scaled = (num * static_cast(percentage)) / 100; + } + + /* Make sure the value fits resulting type T. */ + return ClampTo(scaled); +} + #endif /* MATH_FUNC_HPP */ diff --git a/src/economy.cpp b/src/economy.cpp index 840822b10c..600e403ea0 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -984,6 +984,9 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16_t transit_per return 0; } + /* Scale transit periods according to the game setting. NewGRFs callbacks operate on scaled value for compatibility. */ + transit_periods = ScaleByPercentage(transit_periods, _settings_game.economy.payment_time_scale); + /* Use callback to calculate cargo profit, if available */ if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) { uint32_t var18 = ClampTo(dist) | (ClampTo(num_pieces) << 16) | (ClampTo(transit_periods) << 24); diff --git a/src/lang/english.txt b/src/lang/english.txt index c6b6af7c2b..4e7e2bd2c2 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1520,6 +1520,9 @@ STR_CONFIG_SETTING_MINUTES_PER_YEAR_VALUE :{NUM} ###setting-zero-is-special STR_CONFIG_SETTING_MINUTES_PER_YEAR_FROZEN :0 (calendar time frozen) +STR_CONFIG_SETTING_PAYMENT_TIME_SCALE :Time scale for cargo payments: {STRING2} +STR_CONFIG_SETTING_PAYMENT_TIME_SCALE_HELPTEXT :Adjusts the time scale factor (in percentage) in the cargo payment calculations. A lower value means faster deliveries, resulting in higher payments. + STR_CONFIG_SETTING_AUTORENEW_VEHICLE :Autorenew vehicle when it gets old: {STRING2} STR_CONFIG_SETTING_AUTORENEW_VEHICLE_HELPTEXT :When enabled, a vehicle nearing its end of life gets automatically replaced when the renew conditions are fulfilled diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index f335d10a18..02acb96638 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2093,6 +2093,7 @@ static SettingsContainer &GetSettingsTree() accounting->Add(new SettingEntry("economy.infrastructure_maintenance")); accounting->Add(new SettingEntry("difficulty.vehicle_costs")); accounting->Add(new SettingEntry("difficulty.construction_cost")); + accounting->Add(new SettingEntry("economy.payment_time_scale")); } SettingsPage *vehicles = main->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES)); diff --git a/src/settings_type.h b/src/settings_type.h index e9c6a60038..f7331a6958 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -560,6 +560,7 @@ struct EconomySettings { bool infrastructure_maintenance; ///< enable monthly maintenance fee for owner infrastructure TimekeepingUnits timekeeping_units; ///< time units to use for the game economy, either calendar or wallclock uint16_t minutes_per_calendar_year; ///< minutes per calendar year. Special value 0 means that calendar time is frozen. + uint16_t payment_time_scale; ///< percentage of delivery time to use for payment calculations }; struct LinkGraphSettings { diff --git a/src/table/settings/economy_settings.ini b/src/table/settings/economy_settings.ini index 96cf16eaf3..91fdcf5c81 100644 --- a/src/table/settings/economy_settings.ini +++ b/src/table/settings/economy_settings.ini @@ -315,3 +315,16 @@ strval = STR_CONFIG_SETTING_MINUTES_PER_YEAR_VALUE pre_cb = [](auto) { return _game_mode == GM_MENU || _settings_game.economy.timekeeping_units == 1; } post_cb = ChangeMinutesPerYear cat = SC_BASIC + +[SDT_VAR] +var = economy.payment_time_scale +type = SLE_UINT16 +def = 100 +min = 0 +max = 50000 +interval = 10 +str = STR_CONFIG_SETTING_PAYMENT_TIME_SCALE +strhelp = STR_CONFIG_SETTING_PAYMENT_TIME_SCALE_HELPTEXT +strval = STR_CONFIG_SETTING_PERCENTAGE +cat = SC_EXPERT +post_cb = [](auto) { InvalidateWindowData(WC_PAYMENT_RATES, 0); }