From c11db7d5934085070e94da6486c702f9de4bb882 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 6 Dec 2022 17:28:28 +0000 Subject: [PATCH] Change: Clear last variant when engine becomes unavailable. --- src/engine.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/engine.cpp b/src/engine.cpp index 3e8aeeab49..a55fac9b7e 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -562,6 +562,18 @@ static bool IsWagon(EngineID index) return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON; } +/** + * Ensure engine is not set as the last used variant for any other engine. + * @param engine_id Engine being removed. + * @param type Type of engine. + */ +static void ClearLastVariant(EngineID engine_id, VehicleType type) +{ + for (Engine *e : Engine::IterateType(type)) { + if (e->display_last_variant == engine_id) e->display_last_variant = INVALID_ENGINE; + } +} + /** * Update #Engine::reliability and (if needed) update the engine GUIs. * @param e %Engine to update. @@ -577,6 +589,7 @@ static void CalcEngineReliability(Engine *e) if (retire_early != 0 && age >= retire_early_max_age) { /* Early retirement is enabled and we're past the date... */ e->company_avail = 0; + ClearLastVariant(e->index, e->type); AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); } } @@ -597,6 +610,7 @@ static void CalcEngineReliability(Engine *e) e->company_avail = 0; e->reliability = e->reliability_final; /* Kick this engine out of the lists */ + ClearLastVariant(e->index, e->type); AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); } SetWindowClassesDirty(WC_BUILD_VEHICLE); // Update to show the new reliability @@ -750,6 +764,7 @@ static void DisableEngineForCompany(EngineID eid, CompanyID company) } if (company == _local_company) { + ClearLastVariant(e->index, e->type); AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); } }