diff --git a/src/engine.cpp b/src/engine.cpp index 7334564e39..db5ef0e5fe 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -578,6 +578,18 @@ static bool IsWagon(EngineID index) return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON; } +static void RetireEngineIfPossible(Engine *e, int age_threshold) +{ + if (_settings_game.vehicle.no_expire_vehicles_after > 0) { + YearMonthDay ymd; + ConvertDateToYMD(e->intro_date, &ymd); + if ((ymd.year * 12) + ymd.month + age_threshold >= _settings_game.vehicle.no_expire_vehicles_after * 12) return; + } + + e->company_avail = 0; + AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); +} + /** * Update #Engine::reliability and (if needed) update the engine GUIs. * @param e %Engine to update. @@ -592,8 +604,7 @@ static void CalcEngineReliability(Engine *e) uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12); if (retire_early != 0 && age >= retire_early_max_age) { /* Early retirement is enabled and we're past the date... */ - e->company_avail = 0; - AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); + RetireEngineIfPossible(e, retire_early_max_age); } } @@ -608,12 +619,11 @@ static void CalcEngineReliability(Engine *e) uint max = e->reliability_max; e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; } else { + e->reliability = e->reliability_final; /* time's up for this engine. * We will now completely retire this design */ - e->company_avail = 0; - e->reliability = e->reliability_final; /* Kick this engine out of the lists */ - AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); + RetireEngineIfPossible(e, e->duration_phase_1 + e->duration_phase_2 + e->duration_phase_3); } SetWindowClassesDirty(WC_BUILD_VEHICLE); // Update to show the new reliability SetWindowClassesDirty(WC_REPLACE_VEHICLE); diff --git a/src/lang/english.txt b/src/lang/english.txt index 40dcc6431c..8e311d82ba 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1326,6 +1326,10 @@ STR_CONFIG_SETTING_WARN_INCOME_LESS :Warn if a vehic STR_CONFIG_SETTING_WARN_INCOME_LESS_HELPTEXT :When enabled, a news message gets sent when a vehicle has not made any profit within a calendar year 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_NO_EXPIRE_VEHICLES_AFTER :No vehicles expire after: {STRING2} +STR_CONFIG_SETTING_NO_EXPIRE_VEHICLES_AFTER_HELPTEXT :Vehicles which would otherwise expire after this year remain available forever +STR_CONFIG_SETTING_NO_EXPIRE_VEHICLES_AFTER_VALUE :{NUM} +STR_CONFIG_SETTING_NO_EXPIRE_VEHICLES_AFTER_ZERO :Off 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 STR_CONFIG_SETTING_AUTORENEW_MONTHS :Autorenew when vehicle is {STRING2} maximum age diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 6edebb4e4c..6a71f92c1c 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1848,6 +1848,7 @@ static SettingsContainer &GetSettingsTree() limitations->Add(new SettingEntry("construction.chunnel")); limitations->Add(new SettingEntry("station.never_expire_airports")); limitations->Add(new SettingEntry("vehicle.never_expire_vehicles")); + limitations->Add(new SettingEntry("vehicle.no_expire_vehicles_after")); 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 6c4cb0a754..b27a2d32fa 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -540,6 +540,7 @@ struct VehicleSettings { uint8 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 + Year no_expire_vehicles_after; ///< do not expire vehicles ater this year byte extend_vehicle_life; ///< extend vehicle life by this many years byte road_side; ///< the side of the road vehicles drive on uint8 plane_crashes; ///< number of plane crashes, 0 = none, 1 = reduced, 2 = normal diff --git a/src/table/settings.ini b/src/table/settings.ini index c28bcc1f7d..a1253291e7 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -1379,6 +1379,21 @@ def = false str = STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES strhelp = STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES_HELPTEXT +[SDT_VAR] +base = GameSettings +var = vehicle.no_expire_vehicles_after +type = SLE_INT32 +guiflags = SGF_NO_NETWORK | SGF_0ISDISABLED +def = 0 +min = MIN_YEAR +max = MAX_YEAR +interval = 1 +str = STR_CONFIG_SETTING_NO_EXPIRE_VEHICLES_AFTER +strhelp = STR_CONFIG_SETTING_NO_EXPIRE_VEHICLES_AFTER_HELPTEXT +strval = STR_CONFIG_SETTING_NO_EXPIRE_VEHICLES_AFTER_VALUE +cat = SC_EXPERT +patxname = ""vehicle.no_expire_vehicles_after"" + ;; vehicle.exact_intro_date [SDT_NULL] length = 1