From 259830777cc800beb0bb5a283bf4aff06f758ce1 Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Wed, 9 Jul 2025 16:04:38 -0400 Subject: [PATCH] Fix #14375: When loading config, validate timekeeping mode and minutes per year (#14405) --- src/settings_table.cpp | 9 +++++++++ src/table/settings/economy_settings.ini | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/settings_table.cpp b/src/settings_table.cpp index 434ec43f74..8eeccf90ea 100644 --- a/src/settings_table.cpp +++ b/src/settings_table.cpp @@ -667,6 +667,15 @@ static void ChangeMinutesPerYear(int32_t new_value) } } +/* Get the valid range of the "minutes per calendar year" setting. */ +static std::tuple GetMinutesPerYearRange(const IntSettingDesc &) +{ + /* Allow a non-default value only if using Wallclock timekeeping units. */ + if (_settings_newgame.economy.timekeeping_units == TKU_WALLCLOCK) return { CalendarTime::FROZEN_MINUTES_PER_YEAR, CalendarTime::MAX_MINUTES_PER_YEAR }; + + return { CalendarTime::DEF_MINUTES_PER_YEAR, CalendarTime::DEF_MINUTES_PER_YEAR }; +} + /** * Pre-callback check when trying to change the timetable mode. This is locked to Seconds when using wallclock units. * @param Unused. diff --git a/src/table/settings/economy_settings.ini b/src/table/settings/economy_settings.ini index e45bdbc006..332f542620 100644 --- a/src/table/settings/economy_settings.ini +++ b/src/table/settings/economy_settings.ini @@ -11,6 +11,7 @@ static void TownFoundingChanged(int32_t new_value); static void ChangeTimekeepingUnits(int32_t new_value); static void ChangeMinutesPerYear(int32_t new_value); +static std::tuple GetMinutesPerYearRange(const IntSettingDesc &sd); static constexpr std::initializer_list _place_houses{"forbidden"sv, "allowed"sv, "fully constructed"sv}; @@ -332,6 +333,7 @@ strhelp = STR_CONFIG_SETTING_MINUTES_PER_YEAR_HELPTEXT 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 +range_cb = GetMinutesPerYearRange cat = SC_BASIC [SDT_VAR]