diff --git a/src/facilities/incubator/incubatorUtils.js b/src/facilities/incubator/incubatorUtils.js index 9c04341f013130b9f9dd35c4b79c9245e615ccbd..2765e9e43e2f09f77072fb68dd89c0ed88ff8c82 100644 --- a/src/facilities/incubator/incubatorUtils.js +++ b/src/facilities/incubator/incubatorUtils.js @@ -3,21 +3,19 @@ * @param {App.Entity.SlaveState|App.Entity.InfantState} child */ App.Facilities.Incubator.newChild = function(child) { - if (V.tanks.length < V.incubator) { - let fullAdapt; - child.growTime = Math.trunc(V.targetAge * 52); - child.incubatorPregAdaptationPower = V.incubatorPregAdaptationPower; - if (V.incubatorPregAdaptationPower === 1) { - fullAdapt = 45000 / 2000; - } else if (V.incubatorPregAdaptationPower === 2) { - fullAdapt = 100000 / 2000; - } else if (V.incubatorPregAdaptationPower === 3) { - fullAdapt = 150000 / 2000; - } else { - fullAdapt = 15000 / 2000; - } - child.incubatorPregAdaptationInWeek = (fullAdapt - child.pregAdaptation) / child.growTime; - V.tanks.push(child); - V.incubatorSlaves++; + let fullAdapt; + child.growTime = Math.trunc(V.targetAge * 52); + child.incubatorPregAdaptationPower = V.incubatorPregAdaptationPower; + if (V.incubatorPregAdaptationPower === 1) { + fullAdapt = 45000 / 2000; + } else if (V.incubatorPregAdaptationPower === 2) { + fullAdapt = 100000 / 2000; + } else if (V.incubatorPregAdaptationPower === 3) { + fullAdapt = 150000 / 2000; + } else { + fullAdapt = 15000 / 2000; } + child.incubatorPregAdaptationInWeek = (fullAdapt - child.pregAdaptation) / child.growTime; + V.tanks.push(child); + V.incubatorSlaves++; }; diff --git a/src/js/birth.js b/src/js/birth.js new file mode 100644 index 0000000000000000000000000000000000000000..2d7666b525bf062b92606397e95476b465866a8c --- /dev/null +++ b/src/js/birth.js @@ -0,0 +1,25 @@ +/** + * Sends newborns to incubator or nursery + * @param {App.Entity.SlaveState} mom + */ +globalThis.sendNewbornsToFacility = function(mom) { + let curBabies = mom.curBabies.length; + for (let cb = 0; cb < curBabies; cb++) { + // if there is no reserved children, code in loop will not trigger + if (mom.curBabies[cb].reserve === "incubator") { + if (V.tanks.length < V.incubator) { + App.Facilities.Incubator.newChild(generateChild(mom, mom.curBabies[cb], true)); + } + mom.curBabies.splice(mom.curBabies[cb], 1); + cb--; + curBabies--; + } else if (mom.curBabies[cb].reserve === "nursery") { + if (V.cribs.length < V.nursery) { + App.Facilities.Nursery.newChild(generateChild(mom, mom.curBabies[cb])); + } + mom.curBabies.splice(mom.curBabies[cb], 1); + cb--; + curBabies--; + } + } +}; diff --git a/src/npc/interaction/passage/birthStorm.tw b/src/npc/interaction/passage/birthStorm.tw index 7585fc43abfedbcf48f37a5991a6f2ce4e419260..8b796a8500b7a9387793ae1010615df8681095ee 100644 --- a/src/npc/interaction/passage/birthStorm.tw +++ b/src/npc/interaction/passage/birthStorm.tw @@ -208,21 +208,8 @@ The remote surgery allows the removal of the pregnancy generator through convent <<set _nursed = 1>> <</if>> - <<set $mom = getSlave($AS)>> <<if _cToIncub > 0 || _cToNursery > 0>> - <<for _cb = 0; _cb < _curBabies; _cb++>> /* if there is no reserved children, code in loop will not trigger */ - <<if $mom.curBabies[_cb].reserve == "incubator">> - <<run App.Facilities.Incubator.newChild(generateChild($mom, $mom.curBabies[_cb], 1))>> - <<run $mom.curBabies.splice($mom.curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <<elseif $mom.curBabies[_cb].reserve == "nursery">> - <<if $cribs.length < $nursery>> - <<run App.Facilities.Nursery.newChild(generateChild($mom, $mom.curBabies[_cb]))>> - <</if>> - <<run $mom.curBabies.splice($mom.curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <</if>> - <</for>> + <<run sendNewbornsToFacility(getSlave($AS))>> <</if>> <<else>> diff --git a/src/npc/interaction/passage/csec.tw b/src/npc/interaction/passage/csec.tw index b63b50ea6181b42a7bdf3872cba301a9da5400be..eda9862a2c6c6df361d894ecded20afba99495a4 100644 --- a/src/npc/interaction/passage/csec.tw +++ b/src/npc/interaction/passage/csec.tw @@ -179,23 +179,9 @@ Performing a cesarean section is trivial for the remote surgery to carry out. << <<set _nursed = 1>> <</if>> - <<set $mom = getSlave($AS)>> <<if _cToIncub > 0 || _cToNursery > 0>> - <<for _cb = 0; _cb < _curBabies; _cb++>> /* if there is no reserved children, code in loop will not trigger */ - <<if $mom.curBabies[_cb].reserve == "incubator">> - <<run App.Facilities.Incubator.newChild(generateChild($mom, $mom.curBabies[_cb], 1))>> - <<run $mom.curBabies.splice($mom.curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <<elseif $mom.curBabies[_cb].reserve == "nursery">> - <<if $cribs.length < $nursery>> - <<run App.Facilities.Nursery.newChild(generateChild($mom, $mom.curBabies[_cb]))>> - <</if>> - <<run $mom.curBabies.splice($mom.curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <</if>> - <</for>> + <<run sendNewbornsToFacility(getSlave($AS))>> <</if>> - <<set $AS = $mom.ID>> <<else>> /*No live babies. Placeholder */ diff --git a/src/pregmod/seBurst.tw b/src/pregmod/seBurst.tw index f5abd391987b782ed41d4840ec9ab54f74b8eb47..801b01f28780caf78c05223e519a077213de3a28 100644 --- a/src/pregmod/seBurst.tw +++ b/src/pregmod/seBurst.tw @@ -173,19 +173,7 @@ <</if>> <<if _cToIncub > 0 || _cToNursery > 0>> - <<for _cb = 0; _cb < _curBabies; _cb++>> /* if there is no reserved children, code in loop will not trigger */ - <<if $slaves[_b].curBabies[_cb].reserve == "incubator">> - <<run App.Facilities.Incubator.newChild(generateChild($slaves[_b], $slaves[_b].curBabies[_cb], 1))>> - <<run $slaves[_b].curBabies.splice($slaves[_b].curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <<elseif $slaves[_b].curBabies[_cb].reserve == "nursery">> - <<if $cribs.length < $nursery>> - <<run App.Facilities.Nursery.newChild(generateChild($slaves[_b], $slaves[_b].curBabies[_cb]))>> - <</if>> - <<run $slaves[_b].curBabies.splice($slaves[_b].curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <</if>> - <</for>> + <<run sendNewbornsToFacility($slaves[_b])>> <</if>> <<else>> life and <<if _curBabies <= 1>>that of $his child<<else>>those of $his children<</if>>. diff --git a/src/pregmod/sePlayerBirth.tw b/src/pregmod/sePlayerBirth.tw index 7d2df1d3f47770760a892a1e8a8b08e1cd3aef76..c9a587cbbe9219a7505e7dce49ff6bc22109a4f0 100644 --- a/src/pregmod/sePlayerBirth.tw +++ b/src/pregmod/sePlayerBirth.tw @@ -378,7 +378,9 @@ You arrange yourself to give birth, relaxing until your body urges you to begin <<if $PC.curBabies[0].reserve === "incubator">> @@.pink;You set <<if _gender == "XX">>her<<else>>him<</if>> aside for incubation.@@ - <<run App.Facilities.Incubator.newChild(generateChild($PC, $PC.curBabies[0], 1))>> + <<if $tanks.length < $incubator>> + <<run App.Facilities.Incubator.newChild(generateChild($PC, $PC.curBabies[0], true))>> + <</if>> <<elseif $PC.curBabies[0].reserve === "nursery">> @@.pink;You set <<if _gender == "XX">>her<<else>>him<</if>> aside for incubation.@@ <<if $cribs.length < $nursery>> @@ -428,7 +430,9 @@ You arrange yourself to give birth, relaxing until your body urges you to begin <</if>> <<if $PC.curBabies[_p].reserve == "incubator">> @@.pink;You set <<if $PC.curBabies[_p].genetics.gender == "XX">>her<<else>>him<</if>> aside for incubation.@@ - <<run App.Facilities.Incubator.newChild(generateChild($PC, $PC.curBabies[_p], 1))>> + <<if $tanks.length < $incubator>> + <<run App.Facilities.Incubator.newChild(generateChild($PC, $PC.curBabies[_p], true))>> + <</if>> <<run $PC.curBabies.splice($PC.curBabies[_p], 1)>> <<set _p--, _curBabies-->> <<elseif $PC.curBabies[_p].reserve == "nursery">> diff --git a/src/pregmod/widgets/seBirthWidgets.tw b/src/pregmod/widgets/seBirthWidgets.tw index 74a35b9535ec5d9a868a898c40f00d7be9c3f7c7..1fd091c6899123a7e12bae52342f49276df7393d 100644 --- a/src/pregmod/widgets/seBirthWidgets.tw +++ b/src/pregmod/widgets/seBirthWidgets.tw @@ -894,19 +894,7 @@ All in all, <br><br> <<if _curBabies > 1>>Of $his _curBabies child<<if _curBabies > 1>>ren<</if>>,<<else>>$His child<</if>> <<if _cToIncub > 0>><<if _curBabies > 1>>_cToIncub <</if>><<if _cToIncub === 1>>was<<else>>were<</if>> taken to $incubatorName<<if _cToNursery > 0>> and <</if>><</if>><<if _cToNursery > 0>><<if _curBabies > 1>>_cToNursery <</if>><<if _cToNursery === 1>>was<<else>>were<</if>> taken to $nurseryName<</if>>. <<if _cToIncub + _cToNursery > 0>> - <<for _cb = 0; _cb < _curBabies; _cb++>> /* if there are no reserved children, code in loop will not trigger */ - <<if $slaves[$i].curBabies[_cb].reserve == "incubator">> - <<run App.Facilities.Incubator.newChild(generateChild($slaves[$i], $slaves[$i].curBabies[_cb], 1))>> - <<run $slaves[$i].curBabies.splice($slaves[$i].curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <<elseif $slaves[$i].curBabies[_cb].reserve == "nursery">> - <<if $cribs.length < $nursery>> - <<run App.Facilities.Nursery.newChild(generateChild($slaves[$i], $slaves[$i].curBabies[_cb]))>> - <</if>> - <<run $slaves[$i].curBabies.splice($slaves[$i].curBabies[_cb], 1)>> - <<set _cb--, _curBabies-->> - <</if>> - <</for>> + <<run sendNewbornsToFacility($slaves[$i])>> <</if>> <<set _curBabies = $slaves[$i].curBabies.length>>