1
0
Fork 0
pull/11926/merge
dP 2024-01-30 18:44:29 +00:00 committed by GitHub
commit c21e616492
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 0 deletions

View File

@ -352,4 +352,29 @@ constexpr int RoundDivSU(int a, uint b)
uint32_t IntSqrt(uint32_t num); 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 <typename T, typename U>
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<U>(percentage)) / 100;
}
/* Make sure the value fits resulting type T. */
return ClampTo<T>(scaled);
}
#endif /* MATH_FUNC_HPP */ #endif /* MATH_FUNC_HPP */

View File

@ -987,6 +987,9 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16_t transit_per
return 0; return 0;
} }
/* Scale transit periods according to the game setting. NewGRFs callbacks operate on scaled value for compatibility. */
transit_periods = ScaleByPercentage<uint16_t, uint32_t>(transit_periods, _settings_game.economy.payment_time_scale);
/* Use callback to calculate cargo profit, if available */ /* Use callback to calculate cargo profit, if available */
if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) { if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
uint32_t var18 = ClampTo<uint16_t>(dist) | (ClampTo<uint8_t>(num_pieces) << 16) | (ClampTo<uint8_t>(transit_periods) << 24); uint32_t var18 = ClampTo<uint16_t>(dist) | (ClampTo<uint8_t>(num_pieces) << 16) | (ClampTo<uint8_t>(transit_periods) << 24);

View File

@ -1524,6 +1524,9 @@ STR_CONFIG_SETTING_MINUTES_PER_YEAR_VALUE :{NUM}
###setting-zero-is-special ###setting-zero-is-special
STR_CONFIG_SETTING_MINUTES_PER_YEAR_FROZEN :0 (calendar time frozen) 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 :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 STR_CONFIG_SETTING_AUTORENEW_VEHICLE_HELPTEXT :When enabled, a vehicle nearing its end of life gets automatically replaced when the renew conditions are fulfilled

View File

@ -2094,6 +2094,7 @@ static SettingsContainer &GetSettingsTree()
accounting->Add(new SettingEntry("economy.infrastructure_maintenance")); accounting->Add(new SettingEntry("economy.infrastructure_maintenance"));
accounting->Add(new SettingEntry("difficulty.vehicle_costs")); accounting->Add(new SettingEntry("difficulty.vehicle_costs"));
accounting->Add(new SettingEntry("difficulty.construction_cost")); 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)); SettingsPage *vehicles = main->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES));

View File

@ -561,6 +561,7 @@ struct EconomySettings {
bool infrastructure_maintenance; ///< enable monthly maintenance fee for owner infrastructure 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 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 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 { struct LinkGraphSettings {

View File

@ -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; } pre_cb = [](auto) { return _game_mode == GM_MENU || _settings_game.economy.timekeeping_units == 1; }
post_cb = ChangeMinutesPerYear post_cb = ChangeMinutesPerYear
cat = SC_BASIC 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); }