From 7b2c143df076673f46cc0d26952cbbd6ff8d61d0 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 28 Dec 2023 18:08:39 +0000 Subject: [PATCH] Fix: Prevent underflow if engine base life is less than 8 years. --- src/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine.cpp b/src/engine.cpp index bbccfa6ffd..1481bb6b92 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -724,7 +724,7 @@ void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32_t se r = Random(); e->reliability_final = GB(r, 16, 14) + 0x3FFF; e->duration_phase_1 = GB(r, 0, 5) + 7; - e->duration_phase_2 = GB(r, 5, 4) + ei->base_life.base() * 12 - 96; + e->duration_phase_2 = std::max(0, int(GB(r, 5, 4)) + ei->base_life.base() * 12 - 96); e->duration_phase_3 = GB(r, 9, 7) + 120; RestoreRandomSeeds(saved_seeds);