mirror of https://github.com/OpenTTD/OpenTTD
Add: Setting for scaling time in cargo payment calculations
parent
acaceb45ba
commit
9543aabeb0
|
@ -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 <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 */
|
||||
|
|
|
@ -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<uint16_t, uint32_t>(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<uint16_t>(dist) | (ClampTo<uint8_t>(num_pieces) << 16) | (ClampTo<uint8_t>(transit_periods) << 24);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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); }
|
||||
|
|
Loading…
Reference in New Issue