From fd2e0fd24d3e32bf99597dc1bc69d0fbe6dea034 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Fri, 19 Nov 2021 20:21:35 -0500
Subject: [PATCH] Fix charging for the wrong incubator upgrade, and some
 associated type stuff.

---
 devTools/types/FC/gameState.d.ts              |  2 ++
 src/facilities/facilityRetrievalWorkaround.js | 19 +++++++++-------
 src/facilities/incubator/incubatorInteract.js | 22 +++++++++----------
 3 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/devTools/types/FC/gameState.d.ts b/devTools/types/FC/gameState.d.ts
index 8ecaf5d2105..d5217a28ac6 100644
--- a/devTools/types/FC/gameState.d.ts
+++ b/devTools/types/FC/gameState.d.ts
@@ -92,6 +92,8 @@ declare namespace FC {
 		milkmaidHealthBonus?: number;
 
 		activeSlave: Zeroable<SlaveState>;
+		readySlave: Zeroable<SlaveState>;
+		newSlavePool: Array<FC.SlaveState>
 		event?: InstanceType<typeof App.Events.BaseEvent>;
 		AS: number;
 		seed?: string;
diff --git a/src/facilities/facilityRetrievalWorkaround.js b/src/facilities/facilityRetrievalWorkaround.js
index fdb317722d8..864638388ab 100644
--- a/src/facilities/facilityRetrievalWorkaround.js
+++ b/src/facilities/facilityRetrievalWorkaround.js
@@ -1,7 +1,6 @@
-// @ts-nocheck
 /**
  * Currently setup for the Incubator and Nursery
- * @param {string} facility 
+ * @param {string} facility
  * @returns {DocumentFragment}
  */
 App.UI.facilityRetrievalWorkaround = function(facility) {
@@ -49,7 +48,7 @@ App.UI.facilityRetrievalWorkaround = function(facility) {
 
 	return node;
 
-	function animalBabyWarning (slave) {
+	function animalBabyWarning(slave) {
 		if (slave.father === -8) {
 			Dialog.setup("Attention");
 			const frag = new DocumentFragment();
@@ -70,9 +69,13 @@ App.UI.facilityRetrievalWorkaround = function(facility) {
 			$(Dialog.body()).empty().append(frag);
 			Dialog.open();
 		}
-	};
+	}
 
-	function parent (slave, type) {
+	/**
+	 * @param {FC.SlaveState} slave
+	 * @param {"father"|"mother"} type
+	 */
+	function parent(slave, type) {
 		const r = new DocumentFragment();
 		const missingTableEntry = V.missingTable[slave[type]];
 		const missingSlave = missingTableEntry ? `Your former slave, ${missingTableEntry.slaveName}.` : `Unknown.`;
@@ -109,9 +112,9 @@ App.UI.facilityRetrievalWorkaround = function(facility) {
 			r.append(missingSlave);
 		}
 		return r;
-	};
+	}
 
-	function checkOrgans (slave) {
+	function checkOrgans(slave) {
 		if (V.incubator.organs.length > 0) {
 			for (const organ of V.incubator.organs.filter(o => o.ID === slave.ID)) {
 				const newOrgan = {type: organ.type, weeksToCompletion: organ.weeksToCompletion, ID: slave.ID};
@@ -123,5 +126,5 @@ App.UI.facilityRetrievalWorkaround = function(facility) {
 				V.incubator.organs.deleteAt(organ);
 			}
 		}
-	};
+	}
 };
diff --git a/src/facilities/incubator/incubatorInteract.js b/src/facilities/incubator/incubatorInteract.js
index 3b257558f23..967c764ed41 100644
--- a/src/facilities/incubator/incubatorInteract.js
+++ b/src/facilities/incubator/incubatorInteract.js
@@ -1,4 +1,3 @@
-// @ts-nocheck
 App.UI.incubator = function() {
 	V.nextButton = "Back to Main";
 	V.nextLink = "Main";
@@ -1030,7 +1029,6 @@ App.UI.incubator = function() {
 
 	function tankSettings() {
 		const el = new DocumentFragment();
-		let cost;
 		let p;
 		let r = [];
 		let row;
@@ -1119,7 +1117,7 @@ App.UI.incubator = function() {
 		if (V.incubator.upgrade.speed === 52) {
 			row.append(`It has been upgraded with perfected growth accelerants; children grow at the rate of 1 week to 1 year.`);
 		} else if (V.incubator.upgrade.speed === 18) {
-			cost = Math.trunc(500000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(500000 * V.upgradeMultiplierArcology);
 			row.append(`It has been upgraded with advanced experimental growth accelerants; children grow at the rate of 3 weeks to 1 year. `);
 			row.append(
 				choice(
@@ -1134,7 +1132,7 @@ App.UI.incubator = function() {
 				)
 			);
 		} else if (V.incubator.upgrade.speed === 9) {
-			cost = Math.trunc(75000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(75000 * V.upgradeMultiplierArcology);
 			row.append(`It has been upgraded with advanced growth accelerants; children grow at the rate of 6 weeks to 1 year. `);
 			row.append(
 				choice(
@@ -1149,7 +1147,7 @@ App.UI.incubator = function() {
 				)
 			);
 		} else if (V.incubator.upgrade.speed === 6) {
-			cost = Math.trunc(30000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(30000 * V.upgradeMultiplierArcology);
 			row.append(`It has been upgraded with growth accelerants; children grow at the rate of 9 weeks to 1 year. `);
 			row.append(
 				choice(
@@ -1164,7 +1162,7 @@ App.UI.incubator = function() {
 				)
 			);
 		} else if (V.incubator.upgrade.speed === 5) {
-			cost = Math.trunc(30000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(30000 * V.upgradeMultiplierArcology);
 			row.append(`The incubation tanks are basic; children grow at the rate of 12 weeks to 1 year. `);
 			row.append(
 				choice(
@@ -1208,7 +1206,7 @@ App.UI.incubator = function() {
 			}
 			row.append(App.UI.DOM.generateLinksStrip(linkArray));
 		} else {
-			cost = Math.trunc(20000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(20000 * V.upgradeMultiplierArcology);
 			row.append(`There are no systems in place to control a growing child's weight; they will likely come out emaciated from the rapid growth. `);
 			row.append(
 				choice(
@@ -1255,7 +1253,7 @@ App.UI.incubator = function() {
 
 			row.append(App.UI.DOM.generateLinksStrip(linkArray));
 		} else {
-			cost = Math.trunc(20000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(20000 * V.upgradeMultiplierArcology);
 			row.append(`There are no systems in place to control a growing child's musculature; they will likely come out frail and weak from the rapid growth. `);
 			row.append(
 				choice(
@@ -1371,7 +1369,7 @@ App.UI.incubator = function() {
 			p.append(row);
 			el.append(p);
 		} else {
-			cost = Math.trunc(50000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(50000 * V.upgradeMultiplierArcology);
 			row.append(`There are no systems in place to control a growing child's reproductive capability. `);
 			row.append(
 				choice(
@@ -1395,7 +1393,7 @@ App.UI.incubator = function() {
 		if (V.incubator.upgrade.organs === 1) {
 			row.append(`Surgical tools have been added to the tank to be able to extract tissue samples from the occupant.`);
 		} else if (V.organFarmUpgrade >= 1) {
-			cost = Math.trunc(10000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(10000 * V.upgradeMultiplierArcology);
 			row.append(`The tanks lack the ability to extract tissue samples to be used by the organ fabricator. `);
 			row.append(
 				choice(
@@ -1441,7 +1439,7 @@ App.UI.incubator = function() {
 			}
 			row.append(App.UI.DOM.generateLinksStrip(linkArray));
 		} else if (V.growthStim === 1) {
-			cost = Math.trunc(20000 * V.upgradeMultiplierArcology);
+			const cost = Math.trunc(20000 * V.upgradeMultiplierArcology);
 			row.append(`There are no systems in place to control a growing child's height. `);
 			row.append(
 				choice(
@@ -1484,7 +1482,7 @@ App.UI.incubator = function() {
 				} else if (V.incubator.upgrade.growthStims < 1) {
 					row.append(`${incubatorNameCaps} lacks advanced monitoring and stimulant injection systems. Construction not possible.`);
 				} else {
-					cost = Math.trunc(2000000 * V.upgradeMultiplierArcology);
+					const cost = Math.trunc(2000000 * V.upgradeMultiplierArcology);
 					row.append(
 						choice(
 							`Manufacture and install this subsystem`,
-- 
GitLab