From 7bbe23337708a06bfa5a55ff24198bb3f3d092e3 Mon Sep 17 00:00:00 2001 From: Tabytac <45774869+tabytac@users.noreply.github.com> Date: Wed, 16 Apr 2025 20:15:26 +0100 Subject: [PATCH] Feature: Add setting to disable vehicle intro date randomisation --- src/engine.cpp | 7 ++++++- src/lang/english.txt | 3 +++ src/settingentry_gui.cpp | 2 ++ src/settings_type.h | 1 + src/table/settings/game_settings.ini | 6 ++++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/engine.cpp b/src/engine.cpp index 102a284c63..2cfb7d4a97 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -737,7 +737,12 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym /* Don't randomise the start-date in the first two years after gamestart to ensure availability * of engines in early starting games. * Note: TTDP uses fixed 1922 */ - e->intro_date = ei->base_intro <= TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (TimerGameCalendar::Date)GB(r, 0, 9) + ei->base_intro; + TimerGameCalendar::Date begin_random_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1); + if (_settings_game.vehicle.vehicle_intro_randomisation && ei->base_intro > begin_random_date) { + e->intro_date = ei->base_intro + GB(r, 0, 9); + } else { + e->intro_date = ei->base_intro; + } if (e->intro_date <= TimerGameCalendar::date) { TimerGameCalendar::YearMonthDay intro_ymd = TimerGameCalendar::ConvertDateToYMD(e->intro_date); int aging_months = aging_ymd.year.base() * 12 + aging_ymd.month; diff --git a/src/lang/english.txt b/src/lang/english.txt index 811c38810f..164ccd58ff 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1508,6 +1508,9 @@ STR_CONFIG_SETTING_WARN_OLD_VEHICLE_HELPTEXT :When enabled, a STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES :Vehicles never expire: {STRING2} STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES_HELPTEXT :When enabled, all vehicle models remain available forever after their introduction +STR_CONFIG_SETTING_VEHICLE_INTRO_RANDOMISATION :Randomise vehicle introduction dates: {STRING2} +STR_CONFIG_SETTING_VEHICLE_INTRO_RANDOMISATION_HELPTEXT :When enabled, randomises vehicle introduction dates by up to one and a half years + STR_CONFIG_SETTING_TIMEKEEPING_UNITS :Timekeeping: {STRING2} STR_CONFIG_SETTING_TIMEKEEPING_UNITS_HELPTEXT :Select the timekeeping units of the game. This cannot be changed later.{}{}Calendar-based is the classic OpenTTD experience, with a year consisting of 12 months, and each month having 28-31 days.{}{}In Wallclock-based time, cargo production and financials are instead based on one-minute increments, which is about as long as a 30 day month takes in Calendar-based mode. These are grouped into 12-minute periods, equivalent to a year in Calendar-based mode.{}{}In either mode there is always a classic calendar, which is used for introduction dates of vehicles, houses, and other infrastructure ###length 2 diff --git a/src/settingentry_gui.cpp b/src/settingentry_gui.cpp index e48572e13f..2a26bb6e2a 100644 --- a/src/settingentry_gui.cpp +++ b/src/settingentry_gui.cpp @@ -807,6 +807,8 @@ SettingsContainer &GetSettingsTree() orders->Add(new SettingEntry("gui.quick_goto")); orders->Add(new SettingEntry("gui.stop_location")); } + + vehicles->Add(new SettingEntry("vehicle.vehicle_intro_randomisation")); } SettingsPage *limitations = main->Add(new SettingsPage(STR_CONFIG_SETTING_LIMITATIONS)); diff --git a/src/settings_type.h b/src/settings_type.h index f6dd5bc98c..0af676e622 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -511,6 +511,7 @@ struct VehicleSettings { uint8_t freight_trains; ///< value to multiply the weight of cargo by bool dynamic_engines; ///< enable dynamic allocation of engine data bool never_expire_vehicles; ///< never expire vehicles + bool vehicle_intro_randomisation; ///< randomise the introduction dates of vehicles uint8_t extend_vehicle_life; ///< extend vehicle life by this many years uint8_t road_side; ///< the side of the road vehicles drive on uint8_t plane_crashes; ///< number of plane crashes, 0 = none, 1 = reduced, 2 = normal diff --git a/src/table/settings/game_settings.ini b/src/table/settings/game_settings.ini index 0a946940d4..6b54e8ddbf 100644 --- a/src/table/settings/game_settings.ini +++ b/src/table/settings/game_settings.ini @@ -241,6 +241,12 @@ def = false str = STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES strhelp = STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES_HELPTEXT +[SDT_BOOL] +var = vehicle.vehicle_intro_randomisation +def = true +str = STR_CONFIG_SETTING_VEHICLE_INTRO_RANDOMISATION +strhelp = STR_CONFIG_SETTING_VEHICLE_INTRO_RANDOMISATION_HELPTEXT + [SDT_VAR] var = vehicle.max_trains type = SLE_UINT16