Skip to content
Snippets Groups Projects
Commit 724607f6 authored by lowercasedonkey's avatar lowercasedonkey
Browse files

move loop into function

parent 23a68dc2
No related branches found
No related tags found
No related merge requests found
...@@ -3,21 +3,19 @@ ...@@ -3,21 +3,19 @@
* @param {App.Entity.SlaveState|App.Entity.InfantState} child * @param {App.Entity.SlaveState|App.Entity.InfantState} child
*/ */
App.Facilities.Incubator.newChild = function(child) { App.Facilities.Incubator.newChild = function(child) {
if (V.tanks.length < V.incubator) { let fullAdapt;
let fullAdapt; child.growTime = Math.trunc(V.targetAge * 52);
child.growTime = Math.trunc(V.targetAge * 52); child.incubatorPregAdaptationPower = V.incubatorPregAdaptationPower;
child.incubatorPregAdaptationPower = V.incubatorPregAdaptationPower; if (V.incubatorPregAdaptationPower === 1) {
if (V.incubatorPregAdaptationPower === 1) { fullAdapt = 45000 / 2000;
fullAdapt = 45000 / 2000; } else if (V.incubatorPregAdaptationPower === 2) {
} else if (V.incubatorPregAdaptationPower === 2) { fullAdapt = 100000 / 2000;
fullAdapt = 100000 / 2000; } else if (V.incubatorPregAdaptationPower === 3) {
} else if (V.incubatorPregAdaptationPower === 3) { fullAdapt = 150000 / 2000;
fullAdapt = 150000 / 2000; } else {
} else { fullAdapt = 15000 / 2000;
fullAdapt = 15000 / 2000;
}
child.incubatorPregAdaptationInWeek = (fullAdapt - child.pregAdaptation) / child.growTime;
V.tanks.push(child);
V.incubatorSlaves++;
} }
child.incubatorPregAdaptationInWeek = (fullAdapt - child.pregAdaptation) / child.growTime;
V.tanks.push(child);
V.incubatorSlaves++;
}; };
/**
* 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--;
}
}
};
...@@ -208,21 +208,8 @@ The remote surgery allows the removal of the pregnancy generator through convent ...@@ -208,21 +208,8 @@ The remote surgery allows the removal of the pregnancy generator through convent
<<set _nursed = 1>> <<set _nursed = 1>>
<</if>> <</if>>
<<set $mom = getSlave($AS)>>
<<if _cToIncub > 0 || _cToNursery > 0>> <<if _cToIncub > 0 || _cToNursery > 0>>
<<for _cb = 0; _cb < _curBabies; _cb++>> /* if there is no reserved children, code in loop will not trigger */ <<run sendNewbornsToFacility(getSlave($AS))>>
<<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>>
<</if>> <</if>>
<<else>> <<else>>
......
...@@ -179,23 +179,9 @@ Performing a cesarean section is trivial for the remote surgery to carry out. << ...@@ -179,23 +179,9 @@ Performing a cesarean section is trivial for the remote surgery to carry out. <<
<<set _nursed = 1>> <<set _nursed = 1>>
<</if>> <</if>>
<<set $mom = getSlave($AS)>>
<<if _cToIncub > 0 || _cToNursery > 0>> <<if _cToIncub > 0 || _cToNursery > 0>>
<<for _cb = 0; _cb < _curBabies; _cb++>> /* if there is no reserved children, code in loop will not trigger */ <<run sendNewbornsToFacility(getSlave($AS))>>
<<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>>
<</if>> <</if>>
<<set $AS = $mom.ID>>
<<else>> <<else>>
/*No live babies. Placeholder */ /*No live babies. Placeholder */
......
...@@ -173,19 +173,7 @@ ...@@ -173,19 +173,7 @@
<</if>> <</if>>
<<if _cToIncub > 0 || _cToNursery > 0>> <<if _cToIncub > 0 || _cToNursery > 0>>
<<for _cb = 0; _cb < _curBabies; _cb++>> /* if there is no reserved children, code in loop will not trigger */ <<run sendNewbornsToFacility($slaves[_b])>>
<<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>>
<</if>> <</if>>
<<else>> <<else>>
life and <<if _curBabies <= 1>>that of $his child<<else>>those of $his children<</if>>. life and <<if _curBabies <= 1>>that of $his child<<else>>those of $his children<</if>>.
......
...@@ -378,7 +378,9 @@ You arrange yourself to give birth, relaxing until your body urges you to begin ...@@ -378,7 +378,9 @@ You arrange yourself to give birth, relaxing until your body urges you to begin
<<if $PC.curBabies[0].reserve === "incubator">> <<if $PC.curBabies[0].reserve === "incubator">>
@@.pink;You set <<if _gender == "XX">>her<<else>>him<</if>> aside for incubation.@@ @@.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">> <<elseif $PC.curBabies[0].reserve === "nursery">>
@@.pink;You set <<if _gender == "XX">>her<<else>>him<</if>> aside for incubation.@@ @@.pink;You set <<if _gender == "XX">>her<<else>>him<</if>> aside for incubation.@@
<<if $cribs.length < $nursery>> <<if $cribs.length < $nursery>>
...@@ -428,7 +430,9 @@ You arrange yourself to give birth, relaxing until your body urges you to begin ...@@ -428,7 +430,9 @@ You arrange yourself to give birth, relaxing until your body urges you to begin
<</if>> <</if>>
<<if $PC.curBabies[_p].reserve == "incubator">> <<if $PC.curBabies[_p].reserve == "incubator">>
@@.pink;You set <<if $PC.curBabies[_p].genetics.gender == "XX">>her<<else>>him<</if>> aside for incubation.@@ @@.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)>> <<run $PC.curBabies.splice($PC.curBabies[_p], 1)>>
<<set _p--, _curBabies-->> <<set _p--, _curBabies-->>
<<elseif $PC.curBabies[_p].reserve == "nursery">> <<elseif $PC.curBabies[_p].reserve == "nursery">>
......
...@@ -894,19 +894,7 @@ All in all, ...@@ -894,19 +894,7 @@ All in all,
<br><br> <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 _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>> <<if _cToIncub + _cToNursery > 0>>
<<for _cb = 0; _cb < _curBabies; _cb++>> /* if there are no reserved children, code in loop will not trigger */ <<run sendNewbornsToFacility($slaves[$i])>>
<<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>>
<</if>> <</if>>
<<set _curBabies = $slaves[$i].curBabies.length>> <<set _curBabies = $slaves[$i].curBabies.length>>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment