From 136e9f6bf6160676e29fc16b07709168c1ee282e Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Fri, 6 Mar 2020 12:00:59 -0800
Subject: [PATCH] Fix maximum age safety checks in generateAge().

---
 src/js/generateNewSlaveJS.js | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/js/generateNewSlaveJS.js b/src/js/generateNewSlaveJS.js
index aefa3922ab4..db80b929d1c 100644
--- a/src/js/generateNewSlaveJS.js
+++ b/src/js/generateNewSlaveJS.js
@@ -1284,17 +1284,14 @@ window.GenerateNewSlave = (function() {
 		} else if (V.pedo_mode === 1 && V.one_time_age_overrides_pedo_mode === 0 && V.activeSlaveOneTimeMaxAge > 18) {
 			V.activeSlaveOneTimeMaxAge = 18;
 		}
-		if (V.retirementAge < V.activeSlaveOneTimeMaxAge) {
-			V.activeSlaveOneTimeMaxAge = (V.retirementAge - 1);
-		}
+		V.activeSlaveOneTimeMaxAge = Math.min(V.retirementAge - 1, V.activeSlaveOneTimeMaxAge);
+		V.activeSlaveOneTimeMinAge = Math.min(V.retirementAge - 1, V.activeSlaveOneTimeMinAge);
 		if (V.activeSlaveOneTimeMinAge < V.minimumSlaveAge) {
 			V.activeSlaveOneTimeMinAge = V.minimumSlaveAge;
 		} else if (V.pedo_mode === 1 && V.one_time_age_overrides_pedo_mode === 0) {
 			V.activeSlaveOneTimeMinAge = V.minimumSlaveAge;
 		}
-		if (V.activeSlaveOneTimeMaxAge < V.activeSlaveOneTimeMinAge) {
-			V.activeSlaveOneTimeMaxAge = V.activeSlaveOneTimeMinAge;
-		}
+		V.activeSlaveOneTimeMaxAge = Math.max(V.activeSlaveOneTimeMaxAge, V.activeSlaveOneTimeMinAge);
 		if (V.activeSlaveOneTimeMaxAge >= 30 && V.arcologies[0].FSMaturityPreferentialist !== "unset" && V.ageAdjustOverride !== 1) {
 			V.activeSlaveOneTimeMaxAge += 10;
 		}
-- 
GitLab