Skip to content
Snippets Groups Projects
removeSlave.js 6.86 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * Removes slave from the game
     * @param {App.Entity.SlaveState} slave
     */
    
    globalThis.removeSlave = function(slave) {
    	const AS_ID = slave.ID;
    
    vas's avatar
    vas committed
    	let LENGTH = V.slaves.length;
    	const INDEX = V.slaveIndices[AS_ID];
    	let missing = false;
    
    
    	WombChangeID(V.PC, AS_ID, V.missingParentID);
    	if (V.PC.pregSource === V.missingParentID) {
    		missing = true;
    	}
    
    klorpa's avatar
    klorpa committed
    
    
    vas's avatar
    vas committed
    	if (V.PC.mother === AS_ID) {
    		V.PC.mother = V.missingParentID;
    		missing = true;
    	}
    	if (V.PC.father === AS_ID) {
    		V.PC.father = V.missingParentID;
    		missing = true;
    	}
    	if (V.PC.sisters > 0) {
    
    		if (areSisters(V.PC, slave) > 0) {
    
    vas's avatar
    vas committed
    			V.PC.sisters--;
    		}
    	}
    	if (V.PC.daughters > 0) {
    
    		if (slave.father === -1 || slave.mother === -1) {
    
    vas's avatar
    vas committed
    			V.PC.daughters--;
    		}
    	}
    
    
    	V.favorites.delete(AS_ID);
    
    
    	V.researchLab.tasks = V.researchLab.tasks.filter((t) => t.slaveID !== AS_ID);
    
    
    vas's avatar
    vas committed
    	if (INDEX >= 0 && INDEX < LENGTH) {
    		if (V.incubator > 0) {
    			V.tanks.forEach(child => {
    				if (AS_ID === child.mother) {
    					child.mother = V.missingParentID;
    					missing = true;
    				}
    				if (AS_ID === child.father) {
    					child.father = V.missingParentID;
    					missing = true;
    				}
    			});
    		}
    
    kopareigns's avatar
    kopareigns committed
    		if (V.nursery > 0) {
    			V.cribs.forEach(child => {
    				if (AS_ID === child.mother) {
    					child.mother = V.missingParentID;
    					missing = true;
    				}
    				if (AS_ID === child.father) {
    					child.father = V.missingParentID;
    					missing = true;
    				}
    			});
    		}
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    		V.slaves.forEach(s => {
    			WombChangeID(s, AS_ID, V.missingParentID); /* This check is complex, should be done in JS now, all needed will be done here. */
    			WombChangeGeneID(s, AS_ID, V.missingParentID);
    			if (s.pregSource === V.missingParentID) {
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    			if (slave.daughters > 0) {
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    				if (s.mother === AS_ID) {
    					s.mother = V.missingParentID;
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    				if (s.father === AS_ID) {
    					s.father = V.missingParentID;
    
    vas's avatar
    vas committed
    				}
    				missing = true;
    			}
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    			if (slave.mother > 0 || slave.father > 0) {
    				if (slave.mother === s.ID || slave.father === s.ID) {
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    					s.daughters--;
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    			if (slave.sisters > 0) {
    				if (areSisters(slave, s) > 0) {
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    					s.sisters--;
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    			if (s.cumSource === AS_ID || s.milkSource === AS_ID) {
    				deflate(s);
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    			if (s.ID === slave.relationshipTarget) {
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    				s.relationship = 0;
    				s.relationshipTarget = 0;
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    			if (s.ID === slave.rivalryTarget) {
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    				s.rivalry = 0;
    				s.rivalryTarget = 0;
    
    vas's avatar
    vas committed
    			}
    			/* moved to saDevotion as a discovery event
    
    lowercasedonkey's avatar
    s  
    lowercasedonkey committed
    				if (s.origBodyOwnerID === AS_ID) {
    				s.origBodyOwnerID = 0;
    
    klorpa's avatar
    klorpa committed
    				}
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    			if (s.ID === slave.subTarget || slave.subTarget === s.ID) {
    
    				slave.subTarget = 0;
    				s.subTarget = 0;
    
    Blank's avatar
    Blank committed
    			}
    
    
    			if (s.partners.has(AS_ID)) {
    
    brickode's avatar
    brickode committed
    				missing = true;
    
    
    				s.partners.delete(AS_ID);
    
    brickode's avatar
    brickode committed
    				s.partners.add(V.missingParentID);
    
    vas's avatar
    vas committed
    		});
    
    		/* remove from Pit fighters list, if needed */
    
    brickode's avatar
    brickode committed
    		if (V.pit && V.pit.fighterIDs) {
    
    brickode's avatar
    brickode committed
    			V.pit.fighterIDs.delete(AS_ID);
    		}
    
    vas's avatar
    vas committed
    
    		/* remove from Coursing Association, if needed */
    
    ezsh's avatar
    ezsh committed
    		if (V.LurcherID === AS_ID) {
    			V.LurcherID = 0;
    
    vas's avatar
    vas committed
    		}
    
    		if (Array.isArray(V.personalAttention)) {
    
    Skriv's avatar
    Skriv committed
    			V.personalAttention.deleteWith(s => s.ID === AS_ID);
    			if (V.personalAttention.length === 0) {
    
    Arkerthan's avatar
    Arkerthan committed
    				resetPersonalAttention();
    
    Blank_Alt's avatar
    Blank_Alt committed
    		}
    
    
    Skriv's avatar
    Skriv committed
    		/* Remove from facility array or leadership role, if needed */
    
    		removeJob(slave, slave.assignment);
    
    vas's avatar
    vas committed
    
    		if (V.traitor !== 0) {
    
    			missing = true; /* no exceptions, fetus system relies on this */
    
    vas's avatar
    vas committed
    			if (AS_ID === V.traitor.pregSource) {
    				V.traitor.pregSource = 0;
    			}
    			if (V.traitor.mother === AS_ID) {
    				V.traitor.mother = V.missingParentID;
    			}
    			if (V.traitor.father === AS_ID) {
    				V.traitor.father = V.missingParentID;
    			}
    			if (V.traitor.origBodyOwnerID === AS_ID) {
    				V.traitor.origBodyOwnerID = 0;
    			}
    
    brickode's avatar
    brickode committed
    			if (V.traitor.partners.has(AS_ID)) {
    
    brickode's avatar
    brickode committed
    				missing = true;
    
    
    brickode's avatar
    brickode committed
    				V.traitor.partners.delete(AS_ID);
    				V.traitor.partners.add(V.missingParentID);
    
    vas's avatar
    vas committed
    		}
    		if (V.boomerangSlave !== 0) {
    
    vas's avatar
    vas committed
    			if (AS_ID === V.boomerangSlave.pregSource) {
    				V.boomerangSlave.pregSource = 0;
    			}
    			if (V.boomerangSlave.mother === AS_ID) {
    				V.boomerangSlave.mother = V.missingParentID;
    			}
    			if (V.boomerangSlave.father === AS_ID) {
    				V.boomerangSlave.father = V.missingParentID;
    			}
    			if (V.boomerangSlave.origBodyOwnerID === AS_ID) {
    
    Blank_Alt's avatar
    Blank_Alt committed
    				V.boomerangSlave.origBodyOwnerID = 0;
    
    brickode's avatar
    brickode committed
    			if (V.boomerangSlave.partners.has(AS_ID)) {
    
    brickode's avatar
    brickode committed
    				missing = true;
    
    
    brickode's avatar
    brickode committed
    				V.boomerangSlave.partners.delete(AS_ID);
    				V.boomerangSlave.partners.add(V.missingParentID);
    
    klorpa's avatar
    klorpa committed
    
    
    Skriv's avatar
    Skriv committed
    		V.organs.deleteWith(s => s.ID === AS_ID);
    		V.completedOrgans.deleteWith(s => s.ID === AS_ID);
    
    		for (let _o = 0; _o < V.adjustProsthetics.length; _o++) {
    
    Arkerthan's avatar
    Arkerthan committed
    			if (V.adjustProsthetics[_o].ID === AS_ID) {
    				V.adjustProsthetics.deleteAt(_o);
    				V.adjustProstheticsCompleted--;
    
    kopareigns's avatar
    kopareigns committed
    				_o--;
    			}
    
    klorpa's avatar
    klorpa committed
    
    
    Skriv's avatar
    Skriv committed
    		const _geneIndex = V.genePool.findIndex(s => s.ID === AS_ID);
    
    vas's avatar
    vas committed
    		if (_geneIndex !== -1) {
    			let keep = false;
    			if (V.traitor !== 0) {
    
    				if (isImpregnatedBy(V.traitor, slave) || V.traitor.ID === AS_ID) {
    
    brickode's avatar
    brickode committed
    					/* did we impregnate the traitor, or are we the traitor? */
    
    vas's avatar
    vas committed
    					keep = true;
    				}
    			}
    			if (V.boomerangSlave !== 0) {
    
    				if (isImpregnatedBy(V.boomerangSlave, slave) || V.boomerangSlave.ID === AS_ID) {
    
    brickode's avatar
    brickode committed
    					/* did we impregnate the boomerang, or are we the boomerang? */
    
    vas's avatar
    vas committed
    					keep = true;
    				}
    			}
    
    			if (isImpregnatedBy(V.PC, slave)) {
    
    brickode's avatar
    brickode committed
    				/* did we impregnate the PC */
    
    kopareigns's avatar
    kopareigns committed
    				keep = true;
    			}
    
    brickode's avatar
    brickode committed
    			if (!keep) {
    				/* avoid going through this loop if possible */
    
    vas's avatar
    vas committed
    				keep = V.slaves.some(slave => {
    
    klorpa's avatar
    klorpa committed
    					/* have we impregnated a slave that is not ourselves? */
    
    					return (slave.ID !== AS_ID && isImpregnatedBy(slave, slave));
    
    vas's avatar
    vas committed
    				});
    			}
    			if (!keep) {
    				V.genePool.deleteAt(_geneIndex);
    			}
    		}
    
    		Object.values(V.missingTable).forEach(s => {
    
    			if (s.mother === slave.ID || s.father === slave.ID) {
    
    				missing = true;
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    			}
    
    vas's avatar
    vas committed
    		if (missing) {
    
    kopareigns's avatar
    kopareigns committed
    			V.missingTable[V.missingParentID] = {
    
    				slaveName: slave.slaveName,
    				slaveSurname: slave.slaveSurname,
    				fullName: SlaveFullName(slave),
    				dick: slave.dick,
    				vagina: slave.vagina,
    
    				ID: V.missingParentID,
    
    				mother: slave.mother,
    				father: slave.father,
    				inbreedingCoeff: slave.inbreedingCoeff
    
    kopareigns's avatar
    kopareigns committed
    			};
    
    			if (V.traitor && V.traitor.ID === slave.ID) {
    
    brickode's avatar
    brickode committed
    				/* To link developing fetuses to their parent */
    
    klorpa's avatar
    klorpa committed
    				V.traitor.missingParentTag = V.missingParentID;
    
    			} else if (V.boomerangSlave && V.boomerangSlave.ID === slave.ID) {
    
    klorpa's avatar
    klorpa committed
    				V.boomerangSlave.missingParentTag = V.missingParentID;
    
    			Object.values(V.missingTable).forEach(s => {
    
    				if (s.mother === slave.ID) {
    
    					s.mother = V.missingParentID;
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    				}
    
    				if (s.father === slave.ID) {
    
    					s.father = V.missingParentID;
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    				}
    
    vas's avatar
    vas committed
    			V.missingParentID--;
    		}
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    		if (V.assignmentRecords[AS_ID]) {
    			delete V.assignmentRecords[AS_ID];
    		}
    
    
    i107760's avatar
    i107760 committed
    		// remove slaves from V.rulesToApplyOnce if needed
    		removeFromRulesToApplyOnce(slave);
    
    
    lowercasedonkey's avatar
    lowercasedonkey committed
    		V.slaves.deleteAt(INDEX);
    		V.slaveIndices = slaves2indices();
    
    		V.JobIDMap = makeJobIdMap(); /* need to call this once more to update count of resting slaves*/
    
    ezsh's avatar
    ezsh committed
    };