From afd200874e30067930b965b3eefcef780b0a6f67 Mon Sep 17 00:00:00 2001
From: pregmodfan <pregmodfan@cock.li>
Date: Sun, 12 Apr 2020 03:02:23 +0300
Subject: [PATCH] incubator upgrade fixes, tweaks, balancing

---
 src/pregmod/incubator.tw           |  2 +-
 src/pregmod/incubatorReport.tw     | 22 +++++-----------------
 src/pregmod/incubatorWorkaround.tw | 10 ++++++++++
 3 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/pregmod/incubator.tw b/src/pregmod/incubator.tw
index e60fe46867b..7d9bf019ea7 100644
--- a/src/pregmod/incubator.tw
+++ b/src/pregmod/incubator.tw
@@ -441,7 +441,7 @@ Target age for release: <<textbox "$targetAge" $targetAge "Incubator">> [[Minimu
 			<</if>>
 			<<if ($incubatorPregAdaptationSetting == 1 && $tanks[$i].genes == "XX") || ($incubatorPregAdaptationSetting == 2 && $tanks[$i].genes == "XY") ||$incubatorPregAdaptationSetting == 3 >>
 				Probes and tubes inserted inside $his reproductive organs. Incubator working on them.
-				<<set _safecc = ($tanks[$i].pregAdaptation - 10) * 2000>>
+				<<set _safecc = ($tanks[$i].pregAdaptation - 5) * 2000>>
 				<<if _safecc > 300000>> /* Some bigger size descriptions may be unreachable by normal game mechanic, they are here just in case.*/
 					$His bloated form looks more like overinflated beachball made of overstretched skin of $his belly, with relative tiny body attached to it side. $He is completly dominated by it now. Process gone too far, so $his body can't maintain it's form with the belly as part of abdominal cavity. Now $his skin and tissues stretched enough for $his belly to bloat outside of any body boundaries and looked more attached to $his body then as a part of it. 
 				<<elseif _safecc > 150000>>
diff --git a/src/pregmod/incubatorReport.tw b/src/pregmod/incubatorReport.tw
index e0ee4b2b78c..96d9681316b 100644
--- a/src/pregmod/incubatorReport.tw
+++ b/src/pregmod/incubatorReport.tw
@@ -749,22 +749,12 @@
 
 	<<if ($incubatorPregAdaptationSetting == 1 && $tanks[_inc].genes == "XX") || ($incubatorPregAdaptationSetting == 2 && $tanks[_inc].genes == "XY") ||$incubatorPregAdaptationSetting == 3 >>
 		<br>Incubator working on $his abdomen and reproductive organs.
-		<<if $tanks[_inc].incubatorPregAdaptationPower == 1>>
-			<<set _targetVol = 45000>>
-		<<elseif $tanks[_inc].incubatorPregAdaptationPower == 2>>
-			<<set _targetVol = 100000>>
-		<<elseif $tanks[_inc].incubatorPregAdaptationPower == 3>>
-			<<set _targetVol = 150000>>
-		<<else>>
-			<<set _targetVol = 15000>>
-		<</if>>
-		<<set _weeksToFill = Math.round($tanks[_inc].growTime/$incubatorUpgradeSpeed);
-			_volToFill = (_targetVol - ($tanks[_inc].pregAdaptation*2000)) / _weeksToFill;
-			_weekVol = _volToFill / _weeksToFill>>
-		<<set _weeksVol *= 1 + ($incubatorReproductionSetting / 5);
-			_weekVol *= 1 + ($tanks[_inc].hormoneBalance / 1500) >> 
+		<<set _weekAdapt = isNaN($tanks[_inc].incubatorPregAdaptationInWeek) ? 0.01 : $tanks[_inc].incubatorPregAdaptationInWeek * $incubatorUpgradeSpeed>>
+		<<set _weekAdapt *= 1 + ($incubatorReproductionSetting / 5); _weekAdapt *= 1 + ($tanks[_inc].hormoneBalance / 1500)>> 
+		/*And now we done*/
+		<<set $tanks[_inc].pregAdaptation += _weekAdapt>> 
 		/* here goes side effect from intense and extreme settings: */
-		<<set _sideEffect = (random(0, 100) > ($tanks[_inc].incubatorPregAdaptationPower - 1) * ($incubatorUpgradeSpeed/2))>>
+		<<set _sideEffect = (random(0, 100) <= ($tanks[_inc].incubatorPregAdaptationPower - 1) * ($incubatorUpgradeSpeed/2))>>
 		<<if _sideEffect>>
 			<<set _eff = random (1, 9)>>
 			<<switch _eff>>
@@ -797,8 +787,6 @@
 				It reported about @@.red;emergency protocol activation@@ caused by overpressure to $his tissues and skin on the abdomen. It lost tone and will be sagged now.
 			<</switch>>
 		<</if>>
-		/*And now we done*/
-		<<set $tanks[_inc].pregAdaptation += _weekVol/2000>> 
 	<</if>>
 
 	<<set $tanks[_inc].weight = Math.clamp($tanks[_inc].weight, -100, 200)>>
diff --git a/src/pregmod/incubatorWorkaround.tw b/src/pregmod/incubatorWorkaround.tw
index 658e25694d6..ec8ade7be3a 100644
--- a/src/pregmod/incubatorWorkaround.tw
+++ b/src/pregmod/incubatorWorkaround.tw
@@ -3,6 +3,16 @@
 <<if $tanks.length < $incubator>>
 	<<set $activeChild.growTime = Math.trunc($targetAge*52)>>
 	<<set $activeChild.incubatorPregAdaptationPower = $incubatorPregAdaptationPower>>
+	<<if $incubatorPregAdaptationPower == 1>>
+		<<set _fullAdapt = 45000 / 2000>>
+	<<elseif $incubatorPregAdaptationPower == 2>>
+		<<set _fullAdapt = 100000 / 2000>>
+	<<elseif $incubatorPregAdaptationPower == 3>>
+		<<set _fullAdapt = 150000 / 2000>>
+	<<else>>
+		<<set _fullAdapt = 15000 / 2000>>
+	<</if>>
+	<<set $activeChild.incubatorPregAdaptationInWeek = (_fullAdapt - $activeChild.pregAdaptation) / $activeChild.growTime>>
 	<<set $tanks.push($activeChild)>>
 	<<set $incubatorSlaves++>>
 <</if>>
\ No newline at end of file
-- 
GitLab