From 1d6aee07d6cabf499024243e34ecca5e28bf9079 Mon Sep 17 00:00:00 2001 From: Tabytac <45774869+tabytac@users.noreply.github.com> Date: Wed, 16 Apr 2025 20:14:56 +0100 Subject: [PATCH 1/2] Add vehicle preview offer setting and update vehicle introduction logic --- src/engine.cpp | 3 ++- src/lang/english.txt | 3 +++ src/settingentry_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings/game_settings.ini | 7 +++++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/engine.cpp b/src/engine.cpp index 102a284c63..d94a05ebe9 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -966,6 +966,7 @@ static IntervalTimer _calendar_engines_daily({TimerGameCalend c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, TimerGameCalendar::date); } + if (!_settings_game.vehicle.offer_vehicle_preview) return; if (TimerGameCalendar::year >= _year_engine_aging_stops) return; for (Engine *e : Engine::Iterate()) { @@ -1160,7 +1161,7 @@ void CalendarEnginesMonthlyLoop() /* Do not introduce invalid engines */ if (!e->IsEnabled()) continue; - if (!e->flags.Test(EngineFlag::Available) && TimerGameCalendar::date >= (e->intro_date + CalendarTime::DAYS_IN_YEAR)) { + if (!e->flags.Test(EngineFlag::Available) && TimerGameCalendar::date >= (e->intro_date + (_settings_game.vehicle.offer_vehicle_preview ? CalendarTime::DAYS_IN_YEAR : 0))) { /* Introduce it to all companies */ NewVehicleAvailable(e); } else if (!e->flags.Any({EngineFlag::Available, EngineFlag::ExclusivePreview}) && TimerGameCalendar::date >= e->intro_date) { diff --git a/src/lang/english.txt b/src/lang/english.txt index 811c38810f..aae384933b 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_OFFER_VEHICLE_PREVIEW :Show vehicle previews: {STRING2} +STR_CONFIG_SETTING_OFFER_VEHICLE_PREVIEW_HELPTEXT :When enabled, the top performing company is sometimes offered a 1 year exclusive preview of a vehicle + 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..8d592714e1 100644 --- a/src/settingentry_gui.cpp +++ b/src/settingentry_gui.cpp @@ -820,6 +820,7 @@ SettingsContainer &GetSettingsTree() limitations->Add(new SettingEntry("construction.max_tunnel_length")); limitations->Add(new SettingEntry("station.never_expire_airports")); limitations->Add(new SettingEntry("vehicle.never_expire_vehicles")); + limitations->Add(new SettingEntry("vehicle.offer_vehicle_preview")); limitations->Add(new SettingEntry("vehicle.max_trains")); limitations->Add(new SettingEntry("vehicle.max_roadveh")); limitations->Add(new SettingEntry("vehicle.max_aircraft")); diff --git a/src/settings_type.h b/src/settings_type.h index f6dd5bc98c..7bfb81f511 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 offer_vehicle_preview; ///< offer vehicle preview to companies 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..055cf786d3 100644 --- a/src/table/settings/game_settings.ini +++ b/src/table/settings/game_settings.ini @@ -241,6 +241,13 @@ def = false str = STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES strhelp = STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES_HELPTEXT +[SDT_BOOL] +var = vehicle.offer_vehicle_preview +flags = SettingFlag::NoNetwork +def = true +str = STR_CONFIG_SETTING_OFFER_VEHICLE_PREVIEW +strhelp = STR_CONFIG_SETTING_OFFER_VEHICLE_PREVIEW_HELPTEXT + [SDT_VAR] var = vehicle.max_trains type = SLE_UINT16 From 324012593dc43fb45f68e6edc08d249940b36326 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 2/2] Add vehicle introduction randomisation setting and update logic --- src/engine.cpp | 6 +++++- src/lang/english.txt | 3 +++ src/settingentry_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings/game_settings.ini | 7 +++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/engine.cpp b/src/engine.cpp index d94a05ebe9..3814b056eb 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -737,7 +737,11 @@ 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; + if (_settings_game.vehicle.vehicle_intro_randomisation) { + 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; + } 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 aae384933b..45489c289d 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1511,6 +1511,9 @@ STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES_HELPTEXT :When enabled, a STR_CONFIG_SETTING_OFFER_VEHICLE_PREVIEW :Show vehicle previews: {STRING2} STR_CONFIG_SETTING_OFFER_VEHICLE_PREVIEW_HELPTEXT :When enabled, the top performing company is sometimes offered a 1 year exclusive preview of a vehicle +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 511 extra days from their original date + 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 8d592714e1..adb985d2dd 100644 --- a/src/settingentry_gui.cpp +++ b/src/settingentry_gui.cpp @@ -821,6 +821,7 @@ SettingsContainer &GetSettingsTree() limitations->Add(new SettingEntry("station.never_expire_airports")); limitations->Add(new SettingEntry("vehicle.never_expire_vehicles")); limitations->Add(new SettingEntry("vehicle.offer_vehicle_preview")); + limitations->Add(new SettingEntry("vehicle.vehicle_intro_randomisation")); limitations->Add(new SettingEntry("vehicle.max_trains")); limitations->Add(new SettingEntry("vehicle.max_roadveh")); limitations->Add(new SettingEntry("vehicle.max_aircraft")); diff --git a/src/settings_type.h b/src/settings_type.h index 7bfb81f511..7b686e00e8 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -512,6 +512,7 @@ struct VehicleSettings { bool dynamic_engines; ///< enable dynamic allocation of engine data bool never_expire_vehicles; ///< never expire vehicles bool offer_vehicle_preview; ///< offer vehicle preview to companies + 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 055cf786d3..ab59094b39 100644 --- a/src/table/settings/game_settings.ini +++ b/src/table/settings/game_settings.ini @@ -248,6 +248,13 @@ def = true str = STR_CONFIG_SETTING_OFFER_VEHICLE_PREVIEW strhelp = STR_CONFIG_SETTING_OFFER_VEHICLE_PREVIEW_HELPTEXT +[SDT_BOOL] +var = vehicle.vehicle_intro_randomisation +flags = SettingFlag::NoNetwork +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