From e4700a06d25bc63be7821bc698ae36000ddf109a Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Sun, 21 Mar 2021 21:09:15 -0400 Subject: [PATCH] js --- src/facilities/surgery/analyzePregnancy.js | 319 ++++++++++----------- src/pregmod/analyzePregnancy.tw | 10 +- 2 files changed, 159 insertions(+), 170 deletions(-) diff --git a/src/facilities/surgery/analyzePregnancy.js b/src/facilities/surgery/analyzePregnancy.js index fb97c87c8b1..cdab21ff671 100644 --- a/src/facilities/surgery/analyzePregnancy.js +++ b/src/facilities/surgery/analyzePregnancy.js @@ -1,188 +1,185 @@ -/** - * - * @param {App.Entity.Fetus} fetus - */ - -globalThis.fetusAbnormalities = function(fetus) { - const div = App.UI.DOM.makeElement("div", null, "indent"); - - const abnormalitySpans = []; - for (const gene in fetus.genetics.geneticQuirks) { - const geneObj = App.Data.genes.get(gene); - const quirkName = (geneObj && geneObj.abbreviation) ? geneObj.abbreviation : gene; - const quirkColor = (geneObj && geneObj.goodTrait) ? "green" : "red"; - if (fetus.genetics.geneticQuirks[gene] === 2 || typeof fetus.genetics.geneticQuirks[gene] === "string") { // String check is for heterochromia - abnormalitySpans.push(App.UI.DOM.makeElement("span", quirkName, quirkColor)); - } else if (fetus.genetics.geneticQuirks[gene] === 1 && V.geneticMappingUpgrade >= 2) { - abnormalitySpans.push(App.UI.DOM.makeElement("span", quirkName, "yellow")); - } - } - if (abnormalitySpans.length > 0) { - div.append("Detected abnormalities: "); - App.Events.addNode(div, abnormalitySpans); +globalThis.analyzePregnancies = function(mother) { + const el = new DocumentFragment(); + for (let i = 0; i < mother.womb.length; i++) { + el.append(scanFetus(i)); + App.UI.DOM.appendNewElement("hr", el); } - return div; -}; + return el; -globalThis.scanFetus = function(mother, fetus) { - const el = new DocumentFragment(); - let linkArray = []; - if (mother.womb[_ap].age >= 2) { - App.UI.DOM.appendNewElement("div", el, `Ova: ${mother.womb[_ap].genetics.name}`); - App.UI.DOM.appendNewElement("div", el, `Age: ${Math.trunc(mother.womb[_ap].age * 1000) / 1000}`); - if (V.geneticMappingUpgrade >= 1) { - App.UI.DOM.appendNewElement("div", el, `Gender: ${mother.womb[_ap].genetics.gender}`); - App.UI.DOM.appendNewElement("div", el, `Father ID: ${mother.womb[_ap].genetics.father}`); - App.UI.DOM.appendNewElement("div", el, `Father Name: ${(mother.womb[_ap].genetics.fatherName) ? mother.womb[_ap].genetics.fatherName : `name not registered`}`); + function scanFetus(i) { + const el = new DocumentFragment(); + const fetus = mother.womb[i]; + let linkArray = []; + if (fetus.age >= 2) { + App.UI.DOM.appendNewElement("div", el, `Ova: ${fetus.genetics.name}`); + App.UI.DOM.appendNewElement("div", el, `Age: ${Math.trunc(fetus.age * 1000) / 1000}`); + if (V.geneticMappingUpgrade >= 1) { + App.UI.DOM.appendNewElement("div", el, `Gender: ${fetus.genetics.gender}`); + App.UI.DOM.appendNewElement("div", el, `Father ID: ${fetus.genetics.father}`); + App.UI.DOM.appendNewElement("div", el, `Father Name: ${(fetus.genetics.fatherName) ? fetus.genetics.fatherName : `name not registered`}`); - App.UI.DOM.appendNewElement("div", el, `Mother ID: ${mother.womb[_ap].genetics.mother}`); - App.UI.DOM.appendNewElement("div", el, `Mother Name: ${(mother.womb[_ap].genetics.motherName) ? mother.womb[_ap].genetics.motherName : `name not registered`}`); - App.UI.DOM.appendNewElement("div", el, `Nationality: ${mother.womb[_ap].genetics.nationality}`); - App.UI.DOM.appendNewElement("div", el, `Race: ${capFirstChar(mother.womb[_ap].genetics.race)}`); - App.UI.DOM.appendNewElement("div", el, `Skin tone: ${capFirstChar(mother.womb[_ap].genetics.skin)}`); - App.UI.DOM.appendNewElement("div", el, `Intelligence index: ${mother.womb[_ap].genetics.intelligence} out of 100`); - App.UI.DOM.appendNewElement("div", el, `Face index: ${mother.womb[_ap].genetics.face} out of 100`); - App.UI.DOM.appendNewElement("div", el, `Eye Color: ${capFirstChar(mother.womb[_ap].genetics.eyeColor)}`); - App.UI.DOM.appendNewElement("div", el, `Hair Color: ${capFirstChar(mother.womb[_ap].genetics.hColor)}`); + App.UI.DOM.appendNewElement("div", el, `Mother ID: ${fetus.genetics.mother}`); + App.UI.DOM.appendNewElement("div", el, `Mother Name: ${(fetus.genetics.motherName) ? fetus.genetics.motherName : `name not registered`}`); + App.UI.DOM.appendNewElement("div", el, `Nationality: ${fetus.genetics.nationality}`); + App.UI.DOM.appendNewElement("div", el, `Race: ${capFirstChar(fetus.genetics.race)}`); + App.UI.DOM.appendNewElement("div", el, `Skin tone: ${capFirstChar(fetus.genetics.skin)}`); + App.UI.DOM.appendNewElement("div", el, `Intelligence index: ${fetus.genetics.intelligence} out of 100`); + App.UI.DOM.appendNewElement("div", el, `Face index: ${fetus.genetics.face} out of 100`); + App.UI.DOM.appendNewElement("div", el, `Eye Color: ${capFirstChar(fetus.genetics.eyeColor)}`); + App.UI.DOM.appendNewElement("div", el, `Hair Color: ${capFirstChar(fetus.genetics.hColor)}`); - if (mother.womb[_ap].genetics.underArmHStyle === "hairless" && mother.womb[_ap].genetics.pubicHStyle === "hairless") { - App.UI.DOM.appendNewElement("div", el, `Body hair: None`); - } else if (mother.womb[_ap].genetics.underArmHStyle === "hairless") { - App.UI.DOM.appendNewElement("div", el, `Body hair: Lacks underarm hair`); - } else if (mother.womb[_ap].genetics.pubicHStyle === "hairless") { - App.UI.DOM.appendNewElement("div", el, `Body hair: Lacks pubic hair`); + if (fetus.genetics.underArmHStyle === "hairless" && fetus.genetics.pubicHStyle === "hairless") { + App.UI.DOM.appendNewElement("div", el, `Body hair: None`); + } else if (fetus.genetics.underArmHStyle === "hairless") { + App.UI.DOM.appendNewElement("div", el, `Body hair: Lacks underarm hair`); + } else if (fetus.genetics.pubicHStyle === "hairless") { + App.UI.DOM.appendNewElement("div", el, `Body hair: Lacks pubic hair`); + } + if (fetus.genetics.markings === "freckles" || fetus.genetics.markings === "heavily freckled") { + App.UI.DOM.appendNewElement("div", el, `Markings: ${capFirstChar(fetus.genetics.markings)}`); + } + el.append(fetusAbnormalities()); + } else { + if (fetus.age > 13) { + App.UI.DOM.appendNewElement("div", el, `Gender: ${fetus.genetics.gender}`); + } + if (fetus.age > 5) { + App.UI.DOM.appendNewElement("div", el, `Father ID: ${fetus.genetics.father}`); + App.UI.DOM.appendNewElement("div", el, `Father Name: ${fetus.genetics.fatherName}`); + App.UI.DOM.appendNewElement("div", el, `Mother ID: ${fetus.genetics.mother}`); + App.UI.DOM.appendNewElement("div", el, `Mother Name: ${fetus.genetics.motherName}`); + } } - if (mother.womb[_ap].genetics.markings === "freckles" || mother.womb[_ap].genetics.markings === "heavily freckled") { - App.UI.DOM.appendNewElement("div", el, `Markings: ${capFirstChar(mother.womb[_ap].genetics.markings)}`); + if (V.incubator.capacity > 0 || V.nursery > 0) { + App.UI.DOM.appendNewElement("div", el, `Reserved: ${fetus.reserve}`); } - el.append(fetusAbnormalities(mother.womb[_ap])); - } else { - if (mother.womb[_ap].age > 13) { - App.UI.DOM.appendNewElement("div", el, `Gender: ${mother.womb[_ap].genetics.gender}`); + + App.UI.DOM.appendNewElement("div", el, `Rename: `) + .append(App.UI.DOM.makeTextBox( + fetus.genetics.name, + (v) => fetus.genetics.name = v + )); + if (fetus.age < 4 && (V.arcologies[0].FSRestart === "unset" || V.eugenicsFullControl === 1 || mother.breedingMark === 0 || V.propOutcome === 0 || (fetus.fatherID !== -1 && fetus.fatherID !== -6))) { + linkArray.push(App.UI.DOM.link( + "Terminate ovum", + () => { + WombRemoveFetus(mother, i); + if (mother.preg === 0) { + mother.pregWeek = -1; + } + } + )); + if (V.surgeryUpgrade === 1) { + linkArray.push(App.UI.DOM.link( + "Transplant ovum", + () => { + V.donatrix = mother; + V.wombIndex = i; + V.nextLink = "Analyze Pregnancy"; + }, + [], + "Ova Transplant Workaround" + )); + } + App.UI.DOM.appendNewElement("div", el, App.UI.DOM.generateLinksStrip(linkArray)); } - if (mother.womb[_ap].age > 5) { - App.UI.DOM.appendNewElement("div", el, `Father ID: ${mother.womb[_ap].genetics.father}`); - App.UI.DOM.appendNewElement("div", el, `Father Name: ${mother.womb[_ap].genetics.fatherName}`); - App.UI.DOM.appendNewElement("div", el, `Mother ID: ${mother.womb[_ap].genetics.mother}`); - App.UI.DOM.appendNewElement("div", el, `Mother Name: ${mother.womb[_ap].genetics.motherName}`); + if (V.incubator.capacity > 0) { + if (fetus.reserve === "incubator") { + App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( + `Don't keep this child in ${V.incubator.name}`, + () => { + fetus.reserve = ""; + }, + [], + passage() + )); + } else if ((V.incubator.capacity - V.incubator.tanks.length) - FetusGlobalReserveCount("incubator") > 0) { + App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( + `Keep this child in ${V.incubator.name}`, + () => { + fetus.reserve = "incubator"; + }, + [], + passage() + )); + } else { + App.UI.DOM.appendNewElement("div", el, `There is not enough free space to keep this child in ${V.incubator.name}.`); + } } - } - if (V.incubator.capacity > 0 || V.nursery > 0) { - App.UI.DOM.appendNewElement("div", el, `Reserved: ${mother.womb[_ap].reserve}`); - } - - App.UI.DOM.appendNewElement("div", el, `Rename: `) - .append(App.UI.DOM.makeTextBox( - mother.womb[_ap].genetics.name, - (v) => mother.womb[_ap].genetics.name = v - )); - if (mother.womb[_ap].age < 4 && (V.arcologies[0].FSRestart === "unset" || V.eugenicsFullControl === 1 || mother.breedingMark === 0 || V.propOutcome === 0 || (mother.womb[_ap].fatherID !== -1 && mother.womb[_ap].fatherID !== -6))) { + if (V.nursery > 0) { + if (fetus.reserve === "nursery") { + App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( + `Don't keep this child in ${V.nurseryName}`, + () => { + fetus.reserve = ""; + }, + [], + passage() + )); + } else if ((V.nursery - V.cribs.length) - FetusGlobalReserveCount("nursery") > 0) { + App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( + `Keep this child in ${V.nurseryName}`, + () => { + fetus.reserve = "nursery"; + }, + [], + passage() + )); + } else { + App.UI.DOM.appendNewElement("div", el, `There is not enough free space to keep this child in ${V.nurseryName}.`); + } + } + } else { + linkArray = []; + App.UI.DOM.appendNewElement("div", el, `Unidentified ova found, no detailed data available.`); + App.UI.DOM.appendNewElement("div", el, `Age: too early for scan.`); linkArray.push(App.UI.DOM.link( - "Terminate ovum", + `Terminate ovum`, () => { - WombRemoveFetus(mother, _ap); + WombRemoveFetus(mother, i); if (mother.preg === 0) { mother.pregWeek = -1; } - } + }, + [], + passage() )); + if (V.surgeryUpgrade === 1) { linkArray.push(App.UI.DOM.link( - "Transplant ovum", + `Transplant ovum`, () => { V.donatrix = mother; - V.wombIndex = _ap; - V.nextLink = "Analyze Pregnancy" + V.wombIndex = i; + V.nextLink = "Analyze Pregnancy"; }, [], - "Ova Transplant Workaround" + `Ova Transplant Workaround` )); } - App.UI.DOM.appendNewElement("div", el, App.UI.DOM.generateLinksStrip(linkArray)); } - if (V.incubator.capacity > 0) { - if (mother.womb[_ap].reserve === "incubator") { - App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( - `Don't keep this child in ${V.incubator.name}`, - () => { - mother.womb[_ap].reserve = ""; - _reservedChildren--; - }, - [], - passage() - )); - } else if (_freeTanks - _reservedChildren > 0) { - App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( - `Keep this child in ${V.incubator.name}`, - () => { - if (mother.womb[_ap].reserve === "nursery") { - _reservedChildrenNursery--; - } - mother.womb[_ap].reserve = "incubator"; - _reservedChildren++; - }, - [], - passage() - )); - } else { - App.UI.DOM.appendNewElement("div", el, `There is not enough free space to keep this child in ${V.incubator.name}.`); + return el; + + function fetusAbnormalities() { + const div = App.UI.DOM.makeElement("div", null); + + const abnormalitySpans = []; + for (const gene in fetus.genetics.geneticQuirks) { + const geneObj = App.Data.genes.get(gene); + const quirkName = (geneObj && geneObj.abbreviation) ? geneObj.abbreviation : gene; + const quirkColor = (geneObj && geneObj.goodTrait) ? "green" : "red"; + if (fetus.genetics.geneticQuirks[gene] === 2 || typeof fetus.genetics.geneticQuirks[gene] === "string") { // String check is for heterochromia + abnormalitySpans.push(App.UI.DOM.makeElement("span", quirkName, quirkColor)); + } else if (fetus.genetics.geneticQuirks[gene] === 1 && V.geneticMappingUpgrade >= 2) { + abnormalitySpans.push(App.UI.DOM.makeElement("span", quirkName, "yellow")); + } } - } - if (V.nursery > 0) { - if (mother.womb[_ap].reserve === "nursery") { - App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( - `Don't keep this child in ${V.nurseryName}`, - () => { - mother.womb[_ap].reserve = ""; - _reservedChildrenNursery--; - }, - [], - passage() - )); - } else if (_freeCribs - _reservedChildrenNursery > 0) { - App.UI.DOM.appendNewElement("div", el, App.UI.DOM.link( - `Keep this child in ${V.nurseryName}`, - () => { - if (mother.womb[_ap].reserve === "incubator") { - _reservedChildren--; - } - mother.womb[_ap].reserve = "nursery"; - _reservedChildrenNursery++; - }, - [], - passage() - )); - } else { - App.UI.DOM.appendNewElement("div", el, `There is not enough free space to keep this child in ${V.nurseryName}.`); + if (abnormalitySpans.length > 0) { + div.append("Detected abnormalities: "); + App.Events.addNode(div, abnormalitySpans); } - } - } else { - linkArray = []; - App.UI.DOM.appendNewElement("div", el, `Unidentified ova found, no detailed data available.`); - App.UI.DOM.appendNewElement("div", el, `Age: too early for scan.`); - linkArray.push(App.UI.DOM.link( - `Terminate ovum`, - () => { - WombRemoveFetus(mother, _ap); - if (mother.preg === 0) { - mother.pregWeek = -1; - } - }, - [], - passage() - )); - - if (V.surgeryUpgrade === 1) { - linkArray.push(App.UI.DOM.link( - `Transplant ovum`, - () => { - V.donatrix = mother; - V.wombIndex = _ap; - V.nextLink = "Analyze Pregnancy"; - }, - [], - `Ova Transplant Workaround` - )); + return div; } } -} +}; + diff --git a/src/pregmod/analyzePregnancy.tw b/src/pregmod/analyzePregnancy.tw index cab9250bf18..79f3582c7d3 100644 --- a/src/pregmod/analyzePregnancy.tw +++ b/src/pregmod/analyzePregnancy.tw @@ -9,8 +9,6 @@ <<run App.Utils.setLocalPronouns(getSlave($AS))>> <<set _WL = getSlave($AS).womb.length, _incubatorReservations = WombReserveCount(getSlave($AS), "incubator"), _nurseryReservations = WombReserveCount(getSlave($AS), "nursery"), _freeTanks = $incubator.capacity - $incubator.tanks.length, _freeCribs = $nursery - $cribs.length>> -<<set _reservedChildren = FetusGlobalReserveCount("incubator")>> -<<set _reservedChildrenNursery = FetusGlobalReserveCount("nursery")>> <p class="scene-intro"> <<= getSlave($AS).slaveName>> is <<if getSlave($AS).devotion < 20>>restrained<<else>>comfortably reclined<</if>> with $his stomach prepped for examination. $He shudders slightly at the cold touch of the sensor against $his skin. @@ -67,15 +65,12 @@ <<if _incubatorReservations > 0>> <<link "Remove all of $his children from $incubator.name" "Analyze Pregnancy">> <<run WombChangeReserveType(getSlave($AS), "incubator", "")>> - <<set _reservedChildren -= _incubatorReservations>> <</link>> | <</if>> <<if _incubatorReservations < _WL && (_reservedChildren + _WL - _incubatorReservations <= _freeTanks)>> <<link "Keep all of $his children in $incubator.name" "Analyze Pregnancy">> <<run WombChangeReserveType(getSlave($AS), "nursery", "incubator")>> <<run WombChangeReserveType(getSlave($AS), "", "incubator")>> - <<set _reservedChildrenNursery -= _nurseryReservations>> - <<set _reservedChildren += _WL - _incubatorReservations>> <</link>> <<elseif _incubatorReservations < _WL>> There is not enough free space in <<= $incubator.name>> for the rest of $his children. @@ -88,15 +83,12 @@ <<if _nurseryReservations > 0>> <<link "Remove all of $his children from $nurseryName" "Analyze Pregnancy">> <<run WombChangeReserveType(getSlave($AS), "nursery", "")>> - <<set _reservedChildrenNursery -= _nurseryReservations>> <</link>> | <</if>> - <<if _nurseryReservations < _WL && (_reservedChildrenNursery + _WL - _nurseryReservations <= _freeCribs)>> + <<if _nurseryReservations < _WL && (FetusGlobalReserveCount("nursery") + _WL - _nurseryReservations <= _freeCribs)>> <<link "Keep all of $his children in $nurseryName" "Analyze Pregnancy">> <<run WombChangeReserveType(getSlave($AS), "incubator", "nursery")>> <<run WombChangeReserveType(getSlave($AS), "", "nursery")>> - <<set _reservedChildren -= _incubatorReservations>> - <<set _reservedChildrenNursery += _WL - _nurseryReservations>> <</link>> <<elseif _nurseryReservations < _WL>> There is not enough free space in $nurseryName for the rest of $his children. -- GitLab