diff --git a/src/settings_table.cpp b/src/settings_table.cpp index 09c7fa2759..af503d6af8 100644 --- a/src/settings_table.cpp +++ b/src/settings_table.cpp @@ -247,7 +247,7 @@ static bool CanUpdateServiceInterval(VehicleType, int32_t &new_value) /* Test if the interval is valid */ int32_t interval = GetServiceIntervalClamped(new_value, vds->servint_ispercent); - return interval == new_value; + return new_value == 0 || interval == new_value; } static void UpdateServiceInterval(VehicleType type, int32_t new_value) @@ -290,6 +290,24 @@ static int32_t GetDefaultServiceInterval(const IntSettingDesc &sd, VehicleType t return sd.def; } +static std::tuple GetServiceIntervalRange(const IntSettingDesc &) +{ + VehicleDefaultSettings *vds; + if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) { + vds = &_settings_client.company.vehicle; + } else { + vds = &Company::Get(_current_company)->settings.vehicle; + } + + if (vds->servint_ispercent) return { MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT }; + + if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) { + return { MIN_SERVINT_MINUTES, MAX_SERVINT_MINUTES }; + } + + return { MIN_SERVINT_DAYS, MAX_SERVINT_DAYS }; +} + static void TrainAccelerationModelChanged(int32_t) { for (Train *t : Train::Iterate()) { diff --git a/src/table/settings/company_settings.ini b/src/table/settings/company_settings.ini index 2f84637cba..1f26d09a76 100644 --- a/src/table/settings/company_settings.ini +++ b/src/table/settings/company_settings.ini @@ -14,6 +14,7 @@ static void UpdateServiceInterval(VehicleType type, int32_t new_value); static void SettingsValueAbsolute(const IntSettingDesc &sd, uint first_param, int32_t value); static void ServiceIntervalSettingsValueText(const IntSettingDesc &sd, uint first_param, int32_t value); static int32_t GetDefaultServiceInterval(const IntSettingDesc &sd, VehicleType type); +static std::tuple GetServiceIntervalRange(const IntSettingDesc &sd); static const SettingVariant _company_settings_table[] = { [post-amble] @@ -103,6 +104,7 @@ pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_TRAIN, new_ post_cb = [](auto new_value) { UpdateServiceInterval(VEH_TRAIN, new_value); } def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_TRAIN); } val_cb = ServiceIntervalSettingsValueText +range_cb = GetServiceIntervalRange [SDT_VAR] var = vehicle.servint_roadveh @@ -119,6 +121,7 @@ pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_ROAD, new_v post_cb = [](auto new_value) { UpdateServiceInterval(VEH_ROAD, new_value); } def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_ROAD); } val_cb = ServiceIntervalSettingsValueText +range_cb = GetServiceIntervalRange [SDT_VAR] var = vehicle.servint_ships @@ -135,6 +138,7 @@ pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_SHIP, new_v post_cb = [](auto new_value) { UpdateServiceInterval(VEH_SHIP, new_value); } def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_SHIP); } val_cb = ServiceIntervalSettingsValueText +range_cb = GetServiceIntervalRange [SDT_VAR] var = vehicle.servint_aircraft @@ -151,3 +155,4 @@ pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_AIRCRAFT, n post_cb = [](auto new_value) { UpdateServiceInterval(VEH_AIRCRAFT, new_value); } def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_AIRCRAFT); } val_cb = ServiceIntervalSettingsValueText +range_cb = GetServiceIntervalRange