diff --git a/src/init/storyInit.tw b/src/init/storyInit.tw index fe57e8fd5caef1f4a15db68983d45255880d4923..59ca64997fe0d09e77550594135935994e46688d 100644 --- a/src/init/storyInit.tw +++ b/src/init/storyInit.tw @@ -25,8 +25,7 @@ You should have received a copy of the GNU General Public License along with thi /* this loop will take awhile, but should accurately adjust all needed variables on the kept slaves. */ <<for _i = 0; _i < _SL; _i++>> <<if $slaves[_i].assignment != "be imported">> - <<set $activeSlave = $slaves[_i]>> /* how I wish it didn't need to be $activeSlave */ - <<= removeActiveSlave()>> + <<run removeNonNGPSlave($slaves[_i])>> <<set _i--, _SL-->> <</if>> <</for>> diff --git a/src/js/removeActiveSlave.js b/src/js/removeActiveSlave.js index b28dc6a6760416185ae9760f12ebba966443083d..88ff9b9d5dc08e74b1e8547cc33596ce89b9753f 100644 --- a/src/js/removeActiveSlave.js +++ b/src/js/removeActiveSlave.js @@ -243,3 +243,120 @@ window.removeActiveSlave = function removeActiveSlave() { V.activeSlave = 0; } }; + +window.removeNonNGPSlave = function removeNonNGPSlave(removedSlave) { + "use strict"; + + const V = State.variables; + const ID = removedSlave.ID; + let LENGTH = V.slaves.length; + const INDEX = V.slaveIndices[ID]; + let missing = false; + + // Only bother if PC is being kept + if (V.freshPC !== 1) { + WombChangeID(V.PC, ID, V.missingParentID); + if (V.PC.pregSource === V.missingParentID) { + missing = true; + } + if (V.PC.mother === ID) { + V.PC.mother = V.missingParentID; + missing = true; + } + if (V.PC.father === ID) { + V.PC.father = V.missingParentID; + missing = true; + } + if (V.PC.sisters > 0) { + if (areSisters(V.PC, removedSlave) > 0) { + V.PC.sisters--; + } + } + if (V.PC.daughters > 0) { + if (removedSlave.father === -1 || removedSlave.mother === -1) { + V.PC.daughters--; + } + } + } + + if (INDEX >= 0 && INDEX < LENGTH) { + V.slaves.forEach(slave => { + if (slave.assignment == "be imported") { + WombChangeID(slave, ID, V.missingParentID); /* This check is complex, should be done in JS now, all needed will be done here. */ + WombChangeGeneID(slave, ID, V.missingParentID); + if (slave.pregSource === V.missingParentID) { + missing = true; + } + if (removedSlave.daughters > 0) { + if (slave.mother === ID) { + slave.mother = V.missingParentID; + } + if (slave.father === ID) { + slave.father = V.missingParentID; + } + missing = true; + } + if (slave.ID === removedSlave.relationTarget) { + slave.relation = 0; + slave.relationTarget = 0; + } + if (slave.milkSource !== 0) { + if (slave.milkSource === ID) { + slave.milkSource = 0; + slave.inflation = 0; + slave.inflationType = "none"; + slave.inflationMethod = 0; + } + } + if (slave.cumSource !== 0) { + if (slave.cumSource === ID) { + slave.cumSource = 0; + slave.inflation = 0; + slave.inflationType = "none"; + slave.inflationMethod = 0; + } + } + if (slave.ID === removedSlave.relationshipTarget) { + slave.relationship = 0; + slave.relationshipTarget = 0; + } + if (slave.ID === removedSlave.rivalryTarget) { + slave.rivalry = 0; + slave.rivalryTarget = 0; + } + } + }); + + + const _geneIndex = V.genePool.findIndex(function(s) { return s.ID === ID; }); + if (_geneIndex !== -1) { + let keep = false; + if (isImpregnatedBy(V.PC, removedSlave)) { /* did we impregnate the PC */ + keep = true; + } + if (!keep) { /* avoid going through this loop if possible */ + keep = V.slaves.some(slave => { + /* have we impregnated a slave that is not ourself? */ + return (slave.ID !== ID && isImpregnatedBy(slave, removedSlave)) + }); + } + if (!keep) { + V.genePool.deleteAt(_geneIndex); + } + } + if (missing) { + V.missingTable[V.missingParentID] = { + slaveName: removedSlave.slaveName, + slaveSurname: removedSlave.slaveSurname, + fullName: SlaveFullName(removedSlave), + dick : removedSlave.dick, + vagina : removedSlave.vagina, + ID : V.missingParentID + }; + V.missingParentID--; + } + + removeSlave(INDEX); + + } +}; \ No newline at end of file