From 4e4fcec23f0c20d213aa796e5db60c94b95a7b23 Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Mon, 23 Nov 2020 21:53:15 -0500 Subject: [PATCH] fix missing parent code, ty svorn --- src/npc/acquisition.js | 74 +++++++++++++----------------------------- 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/src/npc/acquisition.js b/src/npc/acquisition.js index e93beba9bf8..70a0994fb59 100644 --- a/src/npc/acquisition.js +++ b/src/npc/acquisition.js @@ -2,13 +2,17 @@ App.Intro.acquisition = function() { const el = new DocumentFragment(); const valueOwed = (V.saveImported === 1) ? 5000 : 50000; + /** @type {Map<number, number>} */ + const missingMap = new Map(); + const r = []; if (V.freshPC === 1 || V.saveImported === 0) { - PCsetup(); + PCSetup(); } - parentSetup(); + checkMissingParents(V.PC); + V.slaves.forEach(checkMissingParents); genepoolSetup(); if (V.plot === 1 && V.neighboringArcologies > 0) { V.arcologies.reduce((acc, val) => val.prosperity > acc.prosperity ? val : acc).rival = 1; @@ -35,7 +39,7 @@ App.Intro.acquisition = function() { if (valueOwed - valueGiven <= 5000) { break; } - const slave = generateFSslave(V.targetArcology.fs); + const slave = generateFSSlave(V.targetArcology.fs); const slaveCostValue = slaveCost(slave); if (["AztecRevivalist", "ChineseRevivalist", "NeoImperialist", "Eugenics", "SlaveProfessionalism"].includes(V.targetArcology.fs)) { valueGiven += slaveCostValue * 4; @@ -276,7 +280,7 @@ App.Intro.acquisition = function() { ); return el; - function PCsetup() { + function PCSetup() { V.PC.birthName = V.PC.slaveName; if (V.PC.slaveSurname) { V.PC.birthSurname = V.PC.slaveSurname; @@ -397,54 +401,22 @@ App.Intro.acquisition = function() { V.PC.ovaryAge = V.PC.physicalAge; } - function parentSetup() { - const pcMomFound = getSlave(V.PC.mother); - if (!pcMomFound && V.PC.mother > 0) { - const lostMom = V.PC.mother; - V.PC.mother = V.missingParentId; - for (const slave of V.slaves) { - if (slave.mother === lostMom) { - slave.mother = V.missingParentId; - } - } - V.missingParentId--; - } - - const pcDadFound = getSlave(V.PC.father); - if (!pcDadFound && V.PC.father > 0) { - const lostDad = V.PC.father; - V.PC.father = V.missingParentId; - for (const slave of V.slaves) { - if (slave.father === lostDad) { - slave.father = V.missingParentId; - } - } - V.missingParentId--; + /** @param {FC.HumanState} slave */ + function checkMissingParents(slave) { + const missingMom = missingMap.get(slave.mother); + if (missingMom) { + slave.mother = missingMom; + } else if (slave.mother > 0 && !getSlave(slave.mother)) { + missingMap.set(slave.mother, V.missingParentID); + V.missingParentID--; } - for (const slave of V.slaves) { - const slaveMomFound = getSlave(slave.mother); - const slaveDadFound = getSlave(slave.father); - if (!pcMomFound && V.PC.mother > 0) { - lostMom = V.PC.mother; - V.PC.mother = V.missingParentID; - for (const slave of V.slaves) { - if (slave.mother === lostMom) { - slave.mother = V.missingParentID; - } - } - V.missingParentID--; - } - if (!pcDadFound && V.PC.father > 0) { - lostDad = V.PC.father; - V.PC.father = V.missingParentID; - for (const slave of V.slaves) { - if (slave.father === lostDad) { - slave.father = V.missingParentID; - } - } - V.missingParentID--; - } + const missingDad = missingMap.get(slave.father); + if (missingDad) { + slave.father = missingDad; + } else if (slave.father > 0 && !getSlave(slave.father)) { + missingMap.set(slave.father, V.missingParentID); + V.missingParentID--; } } @@ -468,7 +440,7 @@ App.Intro.acquisition = function() { } } - function generateFSslave(FS) { + function generateFSSlave(FS) { let slave; switch (FS) { case "Supremacist": -- GitLab