:: AssayJS [script]

window.isSlim = function(slave) {
	var slim = false;
	var ArcologyZero = State.variables.arcologies[0];

	if ((slave.boobs < 500) && (slave.butt < 3)) {
		if ((slave.muscles <= 30) && (ArcologyZero.FSPhysicalIdealist === "unset") && (slave.weight <= 10) && (ArcologyZero.FSHedonisticDecadence === "unset")) {
			slim = true;
		} else if (ArcologyZero.FSPhysicalIdealist !== "unset") {
			if ((ArcologyZero.FSPhysicalIdealistStrongFat === 1) && (slave.weight <= 30)) { 
				slim = true;
			} 
		} else if ((ArcologyZero.FSHedonisticDecadence !== "unset") && (slave.weight <= 30)) { 
			if (ArcologyZero.FSHedonisticDecadenceStrongFat === 1) { 
				slim = true;
			} else if (slave.muscles <= 30) {
				slim = true;
			}
		}
	}

	return slim;
};

window.isStacked = function(slave) {
	return (slave.butt > 4) && (slave.boobs > 800);
};

window.isModded = function(slave) {
	var tatScore = TatScore(slave);
	var piercingScore = PiercingScore(slave);
	var modScore = piercingScore+tatScore;

	return ((modScore > 15) || (piercingScore > 8) && (tatScore > 5));
};

window.isUnmodded = function(slave) {
	var tatScore = TatScore(slave);
	var piercingScore = PiercingScore(slave);

	return !isModded(slave) && (slave.corsetPiercing === 0) && (piercingScore < 3) && (tatScore < 2);
};

window.isXY = function(slave) {
	return (slave.dick > 0);
};

window.isYoung = function(slave) {
	return (slave.visualAge < 30);
};

window.isPreg = function(slave) {
	return ((slave.bellyPreg >= 5000) || (slave.bellyImplant >= 5000));
};

window.isNotPreg = function(slave) {
	return !isPreg(slave) && (slave.belly < 100) && (slave.weight < 30) && !setup.fakeBellies.includes(slave.bellyAccessory);
};

window.isPure = function(slave) {
	return ((slave.boobsImplant === 0) && (slave.buttImplant === 0) && (slave.waist >= -95) && (slave.lipsImplant === 0) && (slave.faceImplant < 30) && (slave.bellyImplant === -1) && (Math.abs(slave.shouldersImplant) < 2) && (Math.abs(slave.hipsImplant) < 2));
};

window.modScore = function modScore(slave) {
	const V = State.variables;
	V.piercingScore = PiercingScore(slave);
	V.tatScore = TatScore(slave);
	V.modScore = V.tatScore + V.piercingScore;
};

window.PiercingScore = function(slave) {
	var piercingScore = 0;

	if (slave.earPiercing > 0) {
		piercingScore += slave.earPiercing*0.75-0.5;
	}
	if (slave.nosePiercing > 0) {
		piercingScore += slave.nosePiercing*0.75-0.5;
	}
	if (slave.eyebrowPiercing > 0) {
		piercingScore += slave.eyebrowPiercing*0.75-0.5;
	}
	if (slave.navelPiercing > 0) {
		piercingScore += slave.navelPiercing*0.75-0.5;
	}
	if (slave.corsetPiercing > 0) {
		piercingScore += slave.corsetPiercing*0.75+0.5;
	}
	if (slave.nipplesPiercing > 0) {
		piercingScore += slave.nipplesPiercing*0.75-0.25;
	}
	if (slave.areolaePiercing > 0) {
		piercingScore += slave.areolaePiercing*0.75+0.5;
	}
	if (slave.lipsPiercing > 0) {
		piercingScore += slave.lipsPiercing*0.75-0.25;
	}
	if (slave.tonguePiercing > 0 ) {
		piercingScore += slave.tonguePiercing*0.75-0.25;
	}
	if (slave.clitPiercing === 3) {
		piercingScore += 1.25; /* smart piercing */
	} else if (slave.clitPiercing > 0) {
		piercingScore += slave.clitPiercing*0.75-0.25;
	}
	if (slave.vaginaPiercing > 0) {
		piercingScore += slave.vaginaPiercing*0.75-0.25;
	}
	if (slave.dickPiercing > 0) {
		piercingScore += slave.dickPiercing*0.75-0.25;
	}
	if (slave.anusPiercing > 0) {
		piercingScore += slave.anusPiercing*0.75-0.25;
	}
	return piercingScore;
};

window.TatScore = function(slave) {
	var tatScore = 0;

	if (slave.boobsTat !== 0) {
		tatScore += 1.25;
	}
	if (slave.buttTat !== 0) {
		tatScore += 1.25;
	}
	if (slave.lipsTat !== 0) {
		tatScore += 1.25;
	}
	if (slave.shouldersTat !== 0) {
		tatScore += 1;
	}
	if (slave.backTat !== 0) {
		tatScore += 1.25;
	}
	if (slave.armsTat !== 0) {
		tatScore += 1;
	}
	if (slave.legsTat !== 0) {
		tatScore += 1;
	}
	if (slave.stampTat !== 0) {
		tatScore += 1;
	}
	if (slave.vaginaTat !== 0) {
		tatScore += 1;
	}
	if (slave.dickTat !== 0) {
		tatScore += 1;
	}
	if (slave.bellyTat !== 0) {
		if (((slave.preg > 30) && (slave.pregType >= 20)) || (slave.belly >= 300000)) {
			tatScore += 0.75;
		} else if (((slave.preg > 20) && (slave.pregType >= 20)) || ((slave.preg > 30) && (slave.pregType >= 10)) || (slave.belly >= 150000)) {
			tatScore += 1;
		} else if ((slave.belly >= 10000) || (slave.bellyImplant >= 8000)) {
			tatScore += 1;
		} else if (((slave.preg >= 10) && (slave.pregType >= 20)) || ((slave.preg > 10) && (slave.pregType >= 10)) || (slave.belly >= 5000)) {
			tatScore += 0.5;
		} else if (slave.belly >= 1500) {
			tatScore += 0.25;
		} else {
			tatScore += 0.1;
		}
	}
	if (slave.anusTat === "bleached") {
		tatScore += 0.5;
	} else if (slave.anusTat !== 0) {
		tatScore += 1.25;
	}

	return tatScore;
};

window.slimPass = function(slave) {
	var slimPass = 0;
	var ArcologyZero = State.variables.arcologies[0];

	if (ArcologyZero.FSSlimnessEnthusiastLaw === 1) {
		if ((slave.boobs < 300) && (slave.butt <= 1) && (slave.waist <= 10)) {
			State.variables.slimPass = 1;
			if ((ArcologyZero.FSPhysicalIdealist === "unset") && (ArcologyZero.FSHedonisticDecadenceStrongFat === 0) && (slave.muscles > 30)) { /*muscle check*/
				slimPass = 0;
			}
			if (State.variables.slimPass === 1) {
				if ((ArcologyZero.FSHedonisticDecadence !== "unset") || (ArcologyZero.FSPhysicalIdealistStrongFat === 1)) { /*weight check*/
					if (slave.weight > 30) {
						slimPass = 0;
					}
				} else if (slave.weight > 10) {
					slimPass = 0;
				}
			}
		}
	}

	return slimPass;
};

window.sameAssignmentP = function sameAssignmentP(A, B) {
	return A.assignment === B.assignment;
};

window.haveRelationP = function haveRelationP(slave, target) {
	return slave.relationTarget === target.ID;
};

window.haveRelationshipP = function haveRelationshipP(slave, target) {
	return slave.relationshipTarget === target.ID;
};

window.isRivalP = function isRivalP(slave, target) {
	return slave.rivalryTarget === target.ID;
};

window.supremeRaceP = function supremeRaceP(slave) {
	return State.variables.arcologies[0].FSSupremacistRace === slave.race;
};

window.inferiorRaceP = function inferiorRaceP(slave) {
	return State.variables.arcologies[0].FSSubjugationistRace === slave.race;
};

window.isLeaderP = function isLeaderP(slave) {
	const V = State.variables;
	const leaders = [V.HeadGirl, V.Bodyguard, V.Recruiter, V.Concubine, V.Nurse, V.Attendant, V.Matron, V.Madam, V.DJ, V.Milkmaid, V.Stewardess, V.Schoolteacher, V.Wardeness];
	return leaders.some(leader => leader.ID && leader.ID === slave.ID);
};

// helper function returning PC's title
window.properTitle = function properTitle() {
	const PC = State.variables.PC;
	if (PC.customTitle) return PC.customTitle;
	else if (PC.title !== 0) return "Sir";
	else return "Ma'am";
};

window.newSlave = function newSlave(slave) {
	const V = State.variables;

	if (slave.override_Eye_Color != 1) {
		switch (slave.eyeColor) {
			case "blind blue":
				slave.origEye = "deep blue";
				break;
			case "milky white":
			case "implant":
				slave.origEye = jsEither(["blue", "green", "brown", "hazel", "light blue", "light green", "dark green", "dark blue"]);
				break;
			default:
				slave.origEye = slave.eyeColor;
				break;
		}
	}

	if (slave.override_Race != 1) {
		slave.origRace = slave.race;
	}
	if (slave.override_H_Color != 1) {
		slave.origHColor = slave.hColor;
	}
	if (slave.override_Arm_H_Color != 1) {
		slave.underArmHColor = slave.hColor;
	}
	if (slave.override_Pubic_H_Color != 1) {
		slave.pubicHColor = slave.hColor;
	}
	if (slave.override_Brow_H_Color != 1) {
		slave.eyebrowHColor = slave.hColor;
	}
	if (slave.override_Skin != 1) {
		slave.origSkin = slave.skin;
	}

	slave.override_Race = 0;
	slave.override_H_Color = 0;
	slave.override_Arm_H_Color = 0;
	slave.override_Pubic_H_Color = 0;
	slave.override_Brow_H_Color = 0;
	slave.override_Skin = 0;
	slave.override_Eye_Color = 0;

	if (V.surnamesForbidden === 1) {
		slave.slaveSurname = 0;
	}

	if (slave.preg > 0) {
		slave.pregWeek = slave.preg;
	} else {
		slave.pregWeek = 0;
	}

	if (V.familyTesting === 1) {
		slave.sisters = 0;
		slave.daughters = 0;
		if (slave.mother === -1 || slave.father === -1) {
			V.PC.daughters += 1;
		}
		if (areSisters(V.PC, slave) > 0) {
			V.PC.sisters += 1;
		}
		for (let k = 0; k < V.slaves.length; k++) {
			if (V.slaves[k].mother === slave.ID || V.slaves[k].father === slave.ID) {
				slave.daughters++;
			}
			if (slave.mother === V.slaves[k].ID || slave.father === V.slaves[k].ID) {
				V.slaves[k].daughters++;
			}
			if (areSisters(V.slaves[k], slave) > 0) {
				slave.sisters++;
				V.slaves[k].sisters++;
			}
		}
	}

	if (slave.dick > 0 &&
		slave.balls > 0 &&
		slave.devotion <= 50 &&
		(slave.fetish !== "buttslut" || slave.fetishKnown !== 1) &&
		slave.sexualFlaw !== "hates women") {
		V.REFeminizationCheckinIDs.push(slave.ID);
	}
	if (slave.actualAge > 35 && slave.face < 40 && slave.analSkill <= 30) {
		V.REMILFCheckinIDs.push(slave.ID);
	}
	if (slave.attrXY <= 60 && slave.attrXX > 60 ) {
		V.REOrientationCheckinIDs.push(slave.ID);
	}
	if (slave.face < -10) {
		V.REUglyCheckinIDs.push(slave.ID);
	}
	if (slave.anus < 2) {
		V.REButtholeCheckinIDs.push(slave.ID);
	}
	if (slave.boobs < 800) {
		V.REReductionCheckinIDs.push(slave.ID);
	}

	if (slave.fuckdoll > 0) {
		slave.pronoun = "it";
		slave.possessivePronoun = "its";
		slave.possessive = "its";
		slave.object = "it";
		slave.objectReflexive = "itself";
		slave.noun = "toy";
	} else if (slave.dick > 0 && slave.vagina === -1 && V.diversePronouns === 1) {
		slave.pronoun = "he";
		slave.possessivePronoun = "his";
		slave.possessive = "his";
		slave.object = "him";
		slave.objectReflexive = "himself";
		slave.noun = "boy";
	} else {
		slave.pronoun = "she";
		slave.possessivePronoun = "hers";
		slave.possessive = "her";
		slave.object = "her";
		slave.objectReflexive = "herself";
		slave.noun = "girl";
	}

	SetBellySize(slave);
	addSlave(slave);

	if (slave.origin !== "She was your slave, but you freed her, which she repaid by participating in a coup attempt against you. It failed, and she is again your chattel." && slave.ID !== V.boomerangSlave.ID) {
		V.genePool.push(slave);
	} else {
		if (V.genePool.findIndex(function(s) { return s.ID === slave.ID; }) === -1) {
			V.genePool.push(slave);
		}
	}

	/* add to facilities array if needed */
	if (slave.assignment !== "rest") {
		assignJob(slave, slave.assignment);
	}

	/** do not run the Rules Assistant before adding the new slave to the slaves list! **/
	if (V.ui !== "start" && V.universalRulesNewSlavesRA === 1 && V.rulesAssistantAuto !== 0) {
		DefaultRules(slave);
	}
};

window.addSlave = function addSlave(slave) {
	State.variables.slaves.push(slave);
	State.variables.slaveIndices[slave.ID] = State.variables.slaves.length - 1;
};
window.removeSlave = function removeSlave(index) {
	const ret = State.variables.slaves.deleteAt(index);
	State.variables.slaveIndices = slaves2indices();
	return ret;
};
window.slaves2indices = function slaves2indices() {
	const obj = {};
	State.variables.slaves.forEach((slave, i) => obj[slave.ID] = i);
	return obj;
};
window.getSlave = function getSlave(ID) {
	const index = State.variables.slaveIndices[ID];
	if (index === undefined) return undefined;
	else return State.variables.slaves[index];
};
window.getPronouns = function getPronouns(slave) {
	return {
		pronoun: slave.pronoun,
		possessivePronoun: slave.possessivePronoun,
		possessive: slave.possessive,
		object: slave.object,
		objectReflexive: slave.objectReflexive,
		noun: slave.noun };
};

window.SlavePronouns = function SlavePronouns(slave) {
	const V = State.variables;
	var pronouns = getPronouns(slave);
	V.pronoun = pronouns.pronoun;
	V.pronounCap = capFirstChar(pronouns.pronoun);
	V.possessive = pronouns.possessive;
	V.possessiveCap = capFirstChar(pronouns.possessive);
	V.object = pronouns.object;
};

window.WrittenMaster = function WrittenMaster(slave) {
	const V = State.variables;
	if (slave !== undefined)
		Enunciate(slave);
	else if (V.titleEnunciate === undefined)
		Enunciate(V.activeSlave);
	return V.writtenTitle;
};

window.Enunciate = function Enunciate(slave) {
	const V = State.variables;
	if (SlaveStatsChecker.checkForLisp(slave)) {
		if (V.PC.customTitleLisp !== undefined)
			V.titleEnunciate = V.PC.customTitleLisp;
		else if (V.PC.title !== 0)
			V.titleEnunciate = "Mathter";
		else
			V.titleEnunciate = "Mithtreth";
		if (V.allowFamilyTitles === 1) {
			if (slave.father === -1) {
				if (slave.actualAge < 4 && slave.physicalAge < 4)
					V.titleEnunciate = "Dadda";
				else if (slave.actualAge < 9)
					V.titleEnunciate = "Daddy";
				else
					V.titleEnunciate = "Dad";
			} else if (slave.mother === -1) {
				if (slave.actualAge < 4 && slave.physicalAge < 4)
					V.titleEnunciate = "Mama";
				else if (slave.actualAge < 9)
					V.titleEnunciate = "Mommy";
				else
					V.titleEnunciate = "Mom";
			} else if (V.PC.mother === slave.ID || V.PC.father === slave.ID) {
				if (V.PC.title === 1)
					V.titleEnunciate = "Thon";
				else if (V.PC.title === 0)
					V.titleEnunciate = "Daughter";
			} else if (areSisters(slave, V.PC) > 0) {
				if (V.PC.title === 1) {
					if (slave.actualAge < 18)
						V.titleEnunciate = "Bro";
					else
						V.titleEnunciate = "Brother";
				} else if (V.PC.title === 0) {
					if (slave.actualAge < 18)
						V.titleEnunciate = "Thith";
					else
						V.titleEnunciate = "Thithter";
				}
			}
		}
		if (slave.customTitleLisp && slave.customTitleLisp !== "")
			V.titleEnunciate = slave.customTitleLisp;
		V.sayEnunciate = "lisp";
		V.sEnunciate = "th";
		V.SEnunciate = "Th";
		V.ssEnunciate = "th";
		V.cEnunciate = "th";
		V.ccEnunciate = "th";
		V.zEnunciate = "th";
		V.shEnunciate = "th";
		V.ShEnunciate = "Th";
		V.xEnunciate = "kth";
	} else {
		if (V.PC.customTitle !== undefined)
			V.titleEnunciate = V.PC.customTitle;
		else if (V.PC.title !== 0)
			V.titleEnunciate = "Master";
		else
			V.titleEnunciate = "Mistress";
		if (V.allowFamilyTitles === 1) {
			if (slave.father === -1) {
				if (slave.actualAge < 4 && slave.physicalAge < 4)
					V.titleEnunciate = "Dadda";
				else if (slave.actualAge < 9)
					V.titleEnunciate = "Daddy";
				else
					V.titleEnunciate = "Dad";
			} else if (slave.mother === -1) {
				if (slave.actualAge < 4 && slave.physicalAge < 4)
					V.titleEnunciate = "Mama";
				else if (slave.actualAge < 9)
					V.titleEnunciate = "Mommy";
				else
					V.titleEnunciate = "Mom";
			} else if (V.PC.mother === slave.ID || V.PC.father === slave.ID) {
				if (V.PC.title === 1)
					V.titleEnunciate = "Son";
				else if (V.PC.title === 0)
					V.titleEnunciate = "Daughter";
			} else if (areSisters(slave, V.PC) > 0) {
				if (V.PC.title === 1) {
					if (slave.actualAge < 18)
						V.titleEnunciate = "Bro";
					else
						V.titleEnunciate = "Brother";
				} else if (V.PC.title === 0) {
					if (slave.actualAge < 18)
						V.titleEnunciate = "Sis";
					else
						V.titleEnunciate = "Sister";
				}
			}
		}
		if (slave.customTitle !== undefined && slave.customTitle !== "")
			V.titleEnunciate = slave.customTitle;
		if (V.PC.customTitle !== undefined)
			V.writtenTitle = V.PC.customTitle;
		else if (V.PC.title !== 0)
			V.writtenTitle = "Master";
		else
			V.writtenTitle = "Mistress";
		if (slave.customTitle !== undefined && slave.customTitle !== "" && slave.rudeTitle === 0)
			V.writtenTitle = slave.customTitle;
		V.sayEnunciate = "say";
		V.sEnunciate = "s";
		V.SEnunciate = "S";
		V.ssEnunciate = "ss";
		V.cEnunciate = "c";
		V.ccEnunciate = "cc";
		V.zEnunciate = "z";
		V.shEnunciate = "sh";
		V.ShEnunciate = "Sh";
		V.xEnunciate = "x";
	}
};

window.fetishChangeChance = function fetishChangeChance(slave) {
	const V = State.variables;
	var chance = 0, sex = 0;

	if (slave.clitSetting !== slave.fetish) {
		if (slave.balls) {
			sex = V.potencyAge - slave.actualAge;
		}
		else if (slave.ovaries || slave.mpreg) {
			sex = V.fertilityAge - slave.actualAge;
		}
		chance = Math.trunc(Math.clamp((slave.devotion/4)-(slave.fetishStrength/4)-(Math.max(sex,0)*10), 0, 100));
	}

	return chance;
};

window.SlaveFullName = function SlaveFullName(slave) {
	const V = State.variables;
	const pair = slave.slaveSurname ? [slave.slaveName, slave.slaveSurname] : [slave.slaveName];
	if (V.surnameOrder !== 1 && ["Cambodian", "Chinese", "Hungarian", "Japanese", "Korean", "Mongolian", "Taiwanese", "Vietnamese"].includes(slave.nationality))
		pair.reverse();
	return pair.join(" ");
};

window.PlayerName = function PlayerName() {
	const V = State.variables;
	const surnamesFirstCountries = [
		"Cambodian",
		"Chinese",
		"Hungarian",
		"Japanese",
		"Korean",
		"Mongolian",
		"Taiwanese",
		"Vietnamese"];
	let names = [V.PC.name, V.PC.surname || ""];

	if ((V.surnameOrder !== 1) && (surnamesFirstCountries.includes(V.PC.nationality)))
		names.reverse();
	return names.join(" ").trim();
};

window.PCTitle = function PCTitle() {
	const V = State.variables;
	let titles = [];

	V.PCTitle = PlayerName();

	if (V.cheater === 1) {
		V.PCTitle = (V.PCTitle + " the Cheater");
	} else if (V.arcologies[0].FSRestart > 10) {
		V.PCTitle = (V.PCTitle + " of the Societal Elite");
	} else if (V.rep > 18000) {
		V.PCTitle = (V.PCTitle + " the Great");
	} else if (V.rep > 17000) {
		V.PCTitle = ("the exalted " + V.PCTitle);
	} else if (V.rep > 16000) {
		V.PCTitle = ("the illustrious " + V.PCTitle);
	} else if (V.rep > 15000) {
		V.PCTitle = ("the prestigious " + V.PCTitle);
	} else if (V.rep > 14000) {
		V.PCTitle = ("the renowned " + V.PCTitle);
	} else if (V.rep > 13000) {
		V.PCTitle = ("the famed " + V.PCTitle);
	} else if (V.rep > 12000) {
		V.PCTitle = ("the celebrated " + V.PCTitle);
	} else if (V.rep > 11000) {
		V.PCTitle = ("the honored " + V.PCTitle);
	} else if (V.rep > 10000) {
		V.PCTitle = ("the acclaimed " + V.PCTitle);
	} else if (V.rep > 9000) {
		V.PCTitle = ("the eminent " + V.PCTitle);
	} else if (V.rep > 8250) {
		V.PCTitle = ("the prominent " + V.PCTitle);
	} else if (V.rep > 7500) {
		V.PCTitle = ("the distinguished " + V.PCTitle);
	} else if (V.rep > 6750) {
		V.PCTitle = ("the admired " + V.PCTitle);
	} else if (V.rep > 6000) {
		V.PCTitle = ("the esteemed " + V.PCTitle);
	} else if (V.rep > 5250) {
		V.PCTitle = ("the respected " + V.PCTitle);
	} else if (V.rep > 4500) {
		V.PCTitle = ("the known " + V.PCTitle);
	} else if (V.rep > 3750) {
		V.PCTitle = ("the recognized " + V.PCTitle);
	} else if (V.rep > 3000) {
		V.PCTitle = ("the rumored " + V.PCTitle);
	}

	V.PCTitle = (V.PCTitle + ", ");

	if (V.PC.name === "FC Dev") {
		titles.push("the Creator");
	}

	if (V.plot === 1) {
		if (V.invasionVictory === 3) {
			if (V.PC.title === 1) {
				titles.push("Hero of the City");
			} else {
				titles.push("Heroine of the City");
			}
		} else if (V.invasionVictory === 2) {
			titles.push("Defender of the City");
		}
		if (V.daughtersVictory === 3) {
			titles.push("Destroyer of the Daughters");
		} else if (V.daughtersVictory === 2) {
			if (V.PC.title === 1) {
				titles.push("Victor over the Daughters");
			} else {
				titles.push("Victrix over the Daughters");
			}
		}
	}

	if (V.mercenaries >= 5) {
		if (V.mercenariesTitle === "Evocati") {
			titles.push("Princeps of the " + V.mercenariesTitle);
		} else if (V.mercenariesTitle === "Knights") {
			if (V.PC.title === 1) {
				titles.push("Lord Commander of the " + V.mercenariesTitle);
			} else {
				titles.push("Lady Commander of the " + V.mercenariesTitle);
			}
		} else if (V.mercenariesTitle === "Immortals") {
			titles.push("Tyrant of the " + V.mercenariesTitle);
		} else {
			titles.push("Commander of the " + V.mercenariesTitle);
		}
	} else if (V.mercenaries >= 1) {
		titles.push("Commander of the Mercenaries");
	}

	if (V.dispensary === 1) {
		if (V.PC.title === 1) {
			titles.push("Pharmacologos");
		} else {
			titles.push("Pharmacologes");
		}
	}

	if (V.arcologies[0].FSSupremacist >= V.FSLockinLevel * 0.9) {
		titles.push("Grand Champion of the Blood");
	} else if (V.arcologies[0].FSSupremacist >= V.FSLockinLevel * 0.6) {
		titles.push("Champion of the Blood");
	} else if (V.arcologies[0].FSSupremacist >= V.FSLockinLevel * 0.3) {
		titles.push("Defender of the Blood");
	}

	if (V.arcologies[0].FSSubjugationist >= V.FSLockinLevel * 0.9) {
		titles.push("Grand Overseer of the Inferior Race");
	} else if (V.arcologies[0].FSSubjugationist >= V.FSLockinLevel * 0.6) {
		titles.push("Overseer of the Inferior Race");
	} else if (V.arcologies[0].FSSubjugationist >= V.FSLockinLevel * 0.3) {
		titles.push("Subduer of the Inferior Race");
	}

	if (V.arcologies[0].FSGenderRadicalist >= V.FSLockinLevel * 0.9) {
		titles.push("Buttfucker of All Slaves");
	} else if (V.arcologies[0].FSGenderRadicalist >= V.FSLockinLevel * 0.6) {
		titles.push("Sodomizer of the Traps");
	} else if (V.arcologies[0].FSGenderRadicalist >= V.FSLockinLevel * 0.3) {
		if (V.PC.title === 1) {
			titles.push("Penetrator of the Sissies");
		} else {
			titles.push("Penetratrix of the Sissies");
		}
	}

	if (V.arcologies[0].FSGenderFundamentalist >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("Father to the City");
		} else {
			titles.push("Mother to the City");
		}
	} else if (V.arcologies[0].FSGenderFundamentalist >= V.FSLockinLevel * 0.6) {
		titles.push("Defender of Women");
	} else if (V.arcologies[0].FSGenderFundamentalist >= V.FSLockinLevel * 0.3) {
		titles.push("Restorer of Morals");
	}

	if (V.arcologies[0].FSPaternalist >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("Protector to All Slaves");
		} else {
			titles.push("Protectrix to All Slaves");
		}
	} else if (V.arcologies[0].FSPaternalist >= V.FSLockinLevel * 0.6) {
		if (V.PC.title === 1) {
			titles.push("Benefactor of Slaves");
		} else {
			titles.push("Benefactrix of Slaves");
		}
	} else if (V.arcologies[0].FSPaternalist >= V.FSLockinLevel * 0.3) {
		titles.push("Pursuer of Justice");
	}

	if (V.arcologies[0].FSRepopulationFocus >= V.FSLockinLevel * 0.9) {
		titles.push("the Savior of the Future");
	} else if (V.arcologies[0].FSRepopulationFocus >= V.FSLockinLevel * 0.6) {
		titles.push("the Holder of the Future");
	} else if (V.arcologies[0].FSRepopulationFocus >= V.FSLockinLevel * 0.3) {
		titles.push("the Repopulist");
	}

	if (V.arcologies[0].FSDegradationist >= V.FSLockinLevel * 0.9) {
		titles.push("Holder of the Rod and the Lash");
	} else if (V.arcologies[0].FSDegradationist >= V.FSLockinLevel * 0.6) {
		titles.push("Subduer of Slaves");
	} else if (V.arcologies[0].FSDegradationist >= V.FSLockinLevel * 0.3) {
		titles.push("Pursuer of Justice");
	}

	if (V.arcologies[0].FSBodyPurist >= V.FSLockinLevel * 0.9) {
		titles.push("the Purifier of the Breasts");
	} else if (V.arcologies[0].FSBodyPurist >= V.FSLockinLevel * 0.6) {
		titles.push("the Discerning");
	} else if (V.arcologies[0].FSBodyPurist >= V.FSLockinLevel * 0.3) {
		titles.push("the Tasteful");
	}

	if (V.arcologies[0].FSAssetExpansionist >= V.FSLockinLevel * 0.9) {
		titles.push("the Expander of the Breasts");
	} else if (V.arcologies[0].FSAssetExpansionist >= V.FSLockinLevel * 0.6) {
		titles.push("the Expander");
	} else if (V.arcologies[0].FSAssetExpansionist >= V.FSLockinLevel * 0.3) {
		if (V.PC.title === 1) {
			titles.push("the Implantor");
		} else {
			titles.push("the Implantrix");
		}
	}

	if (V.arcologies[0].FSPastoralist >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("the Master of Stock");
		} else {
			titles.push("the Mistress of Stock");
		}
	} else if (V.arcologies[0].FSPastoralist >= V.FSLockinLevel * 0.6) {
		titles.push("the Rancher");
	} else if (V.arcologies[0].FSPastoralist >= V.FSLockinLevel * 0.3) {
		titles.push("the Farmer");
	}

	if (V.arcologies[0].FSPhysicalIdealist >= V.FSLockinLevel * 0.9) {
		titles.push("beloved of Brodin");
	} else if (V.arcologies[0].FSPhysicalIdealist >= V.FSLockinLevel * 0.6) {
		if (V.PC.title === 1) {
			titles.push("he of the godlike Body");
		} else {
			titles.push("she of the godlike Body");
		}
	} else if (V.arcologies[0].FSPhysicalIdealist >= V.FSLockinLevel * 0.3) {
		titles.push("advancer of Gains");
	}

	if (V.arcologies[0].FSHedonisticDecadence >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("Master of Softness");
		} else {
			titles.push("Lady of Softness");
		}
	} else if (V.arcologies[0].FSHedonisticDecadence >= V.FSLockinLevel * 0.6) {
		titles.push("Thickness Enthusiast");
	} else if (V.arcologies[0].FSHedonisticDecadence >= V.FSLockinLevel * 0.3) {
		titles.push("the Feeder");
	}

	if (V.arcologies[0].FSMaturityPreferentialist >= V.FSLockinLevel * 0.9) {
		titles.push("Grand Preserver of MILFS");
	} else if (V.arcologies[0].FSMaturityPreferentialist >= V.FSLockinLevel * 0.6) {
		titles.push("Fucker of MILFS");
	} else if (V.arcologies[0].FSMaturityPreferentialist >= V.FSLockinLevel * 0.3) {
		if (V.PC.title === 1) {
			titles.push("he of the notorious MILF preference");
		} else {
			titles.push("she of the notorious MILF preference");
		}
	}

	if (V.arcologies[0].FSYouthPreferentialist >= V.FSLockinLevel * 0.9) {
		titles.push("Keeper of the Magnificent Young Harem");
	} else if (V.arcologies[0].FSYouthPreferentialist >= V.FSLockinLevel * 0.6) {
		titles.push("Keeper of Virgins");
	} else if (V.arcologies[0].FSYouthPreferentialist >= V.FSLockinLevel * 0.3) {
		titles.push("the Virginbreaker");
	}

	if (V.arcologies[0].FSChattelReligionistLaw === 1) {
		titles.push("the Prophet");
	} else if (V.arcologies[0].FSChattelReligionist >= V.FSLockinLevel * 0.9) {
		titles.push("Keeper of the Blade and Chalice");
	} else if (V.arcologies[0].FSChattelReligionist >= V.FSLockinLevel * 0.6) {
		titles.push("Champion of the Faith");
	} else if (V.arcologies[0].FSChattelReligionist >= V.FSLockinLevel * 0.3) {
		titles.push("the Holy");
	}

	if (V.arcologies[0].FSRomanRevivalist >= V.FSLockinLevel * 0.9) {
		titles.push("First Consul");
	} else if (V.arcologies[0].FSRomanRevivalist >= V.FSLockinLevel * 0.6) {
		titles.push("Aedile");
	} else if (V.arcologies[0].FSRomanRevivalist >= V.FSLockinLevel * 0.3) {
		titles.push("Quaestor");
	}

	if (V.arcologies[0].FSAztecRevivalist >= V.FSLockinLevel * 0.9) {
		titles.push("Tlatcani");
	} else if (V.arcologies[0].FSAztecRevivalist >= V.FSLockinLevel * 0.6) {
		titles.push("Cihuacoatl");
	} else if (V.arcologies[0].FSAztecRevivalist >= V.FSLockinLevel * 0.3) {
		titles.push("Tlatoani");
	}

	if (V.arcologies[0].FSEgyptianRevivalist >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("the Living God");
		} else {
			titles.push("the Living Goddess");
		}
	} else if (V.arcologies[0].FSEgyptianRevivalist >= V.FSLockinLevel * 0.6) {
		titles.push("Pharaoh");
	} else if (V.arcologies[0].FSEgyptianRevivalist >= V.FSLockinLevel * 0.3) {
		if (V.PC.title === 1) {
			titles.push("Prince of the Nile");
		} else {
			titles.push("Princess of the Nile");
		}
	}

	if (V.arcologies[0].FSEdoRevivalist >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("Emperor and Descendant of Amaterasu");
		} else {
			titles.push("Amaterasu Reborn");
		}
	} else if (V.arcologies[0].FSEdoRevivalist >= V.FSLockinLevel * 0.6) {
		titles.push("Shogun");
	} else if (V.arcologies[0].FSEdoRevivalist >= V.FSLockinLevel * 0.3) {
		titles.push("Daimyo");
	}

	if (V.arcologies[0].FSArabianRevivalist >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("Caliph");
		} else {
			titles.push("Handmaiden of Allah");
		}
	} else if (V.arcologies[0].FSArabianRevivalist >= V.FSLockinLevel * 0.6) {
		if (V.PC.title === 1) {
			titles.push("Sultan");
		} else {
			titles.push("Sultana");
		}
	} else if (V.arcologies[0].FSArabianRevivalist >= V.FSLockinLevel * 0.3) {
		titles.push("Beloved of Allah");
	}

	if (V.arcologies[0].FSChineseRevivalist >= V.FSLockinLevel * 0.9) {
		if (V.PC.title === 1) {
			titles.push("Emperor and Holder of the Mandate of Heaven");
		} else {
			titles.push("Empress and Holder of the Mandate of Heaven");
		}
	} else if (V.arcologies[0].FSChineseRevivalist >= V.FSLockinLevel * 0.6) {
		if (V.PC.title === 1) {
			titles.push("Emperor");
		} else {
			titles.push("Empress");
		}
	} else if (V.arcologies[0].FSChineseRevivalist >= V.FSLockinLevel * 0.3) {
		if (V.PC.title === 1) {
			titles.push("Governor of the Province");
		} else {
			titles.push("Governess of the Province");
		}
	}

	if (V.brothelSlaves >= 15) {
		if (V.PC.title === 1) {
			titles.push("Procurator of the Brothel");
		} else {
			titles.push("Procuratrix of the Brothel");
		}
	}

	if (V.clubSlaves >= 15) {
		titles.push("First on the Club");
	}
	if (V.dairySlaves >= 15) {
		titles.push("Keeper of the Cattle");
	}
	if (V.cumSlaves >= 15) {
		if (V.PC.title === 1) {
			titles.push("Extractor of the Ejaculate");
		} else {
			titles.push("Extractrix of the Ejaculate");
		}
	}
	if (V.servantsQuartersSlaves >= 15) {
		if (V.PC.title === 1) {
			titles.push("Director of the Servants");
		} else {
			titles.push("Directrix of the Servants");
		}
	}
	if (V.schoolroomSlaves >= 10) {
		if (V.PC.title === 1) {
			titles.push("Educator of the Slaves");
		} else {
			titles.push("Educatrix of the Slaves");
		}
	}
	if (V.spaSlaves >= 10) {
		titles.push("Order of the Bath");
	}
	if (V.arcadeSlaves >= 15) {
		titles.push("Comptroller of the Arcade");
	}
	if (V.nurserySlave >= 10) {
		titles.push("Caretaker of the Infants");
	}

	let schoolsPresent = [], schoolsPerfected = [], schoolTitle = "";
	if (V.TSS.schoolProsperity >= 10) {
		schoolsPerfected.push("The Slave School");
	} else if (V.TSS.schoolPresent === 1) {
		schoolsPresent.push("The Slave School");
	}
	if (V.GRI.schoolProsperity >= 10) {
		schoolsPerfected.push("The Growth Research Institute");
	} else if (V.GRI.schoolPresent === 1) {
		schoolsPresent.push("The Growth Research Institute");
	}
	if (V.SCP.schoolProsperity >= 10) {
		schoolsPerfected.push("St. Claver Preparatory");
	} else if (V.SCP.schoolPresent === 1) {
		schoolsPresent.push("St. Claver Preparatory");
	}
	if (V.LDE.schoolProsperity >= 10) {
		schoolsPerfected.push("L'École des Enculées");
	} else if (V.LDE.schoolPresent === 1) {
		schoolsPresent.push("L'École des Enculées");
	}
	if (V.TGA.schoolProsperity >= 10) {
		schoolsPerfected.push("The Gymnasium-Academy");
	} else if (V.TGA.schoolPresent === 1) {
		schoolsPresent.push("The Gymnasium-Academy");
	}
	if (V.HA.schoolProsperity >= 10) {
		schoolsPerfected.push("The Hippolyta Academy");
	} else if (V.HA.schoolPresent === 1) {
		schoolsPresent.push("The Hippolyta Academy");
	}
	if (V.TCR.schoolProsperity >= 10) {
		schoolsPerfected.push("The Cattle Ranch");
	} else if (V.TCR.schoolPresent === 1) {
		schoolsPresent.push("The Cattle Ranch");
	}
	if (schoolsPerfected.length > 0) {
		if (V.PC.title === 1) {
			schoolTitle = "Benefactor of ";
		} else {
			schoolTitle = "Benefactrix of ";
		}
		if (schoolsPerfected.length === 1) {
			schoolTitle += schoolsPerfected[0];
		} else if (schoolsPerfected.length === 2) {
			schoolTitle += schoolsPerfected[0] + " and " + schoolsPerfected[1];
		} else {
			schoolsPerfected[schoolsPerfected.length - 1] = "and " + schoolsPerfected[schoolsPerfected.length - 1];
			schoolTitle += schoolsPerfected.join(", ");
		}
		titles.push(schoolTitle);
	}

	if (schoolsPresent.length > 0) {
		schoolTitle = "Supporter of ";
		if (schoolsPresent.length === 1) {
			schoolTitle += schoolsPresent[0];
		} else if (schoolsPresent.length === 2) {
			schoolTitle += schoolsPresent[0] + " and " + schoolsPresent[1];
		} else {
			schoolsPresent[schoolsPresent.length - 1] = "and " + schoolsPresent[schoolsPresent.length - 1];
			schoolTitle += schoolsPresent.join(", ");
		}
		titles.push(schoolTitle);
	}

	if (V.TFS.schoolProsperity >= 10) {
		titles.push("Honorary Sibling of the Futanari Sisters");
	} else if (V.TFS.schoolPresent === 1) {
		if (V.PC.title === 1) {
			titles.push("Protector of the Futanari Sisters");
		} else {
			titles.push("Protectrix of the Futanari Sisters");
		}
	}

	if (V.slaves.length > 50) {
		if (V.PC.title === 1) {
			titles.push("Master of Slaves");
		} else {
			titles.push("Mistress of Slaves");
		}
	} else if (V.slaves.length > 40) {
		titles.push("Holder of Slaves");
	} else if (V.slaves.length > 30) {
		titles.push("Keeper of Slaves");
	} else if (V.slaves.length > 20) {
		titles.push("Manager of Slaves");
	} else if (V.slaves.length > 10) {
		titles.push("owner of slaves");
	}

	if (V.corpValue > 500000) {
		titles.push("Corporate Titan");
	} else if (V.corpValue > 250000) {
		titles.push("corporate innovator");
	} else if (V.corpValue > 100000) {
		titles.push("corporate founder");
	} else if (V.corpValue > 0) {
		if (V.PC.title === 1) {
			titles.push("noted corporate businessman");
		} else {
			titles.push("noted corporate businesswoman");
		}
	}

	if (V.rep > 18000) {
		if (V.PC.title === 1) {
			titles.push("unquestioned Master of the Arcology");
		} else {
			titles.push("unquestioned Mistress of the Arcology");
		}
	} else if (V.rep > 15000) {
		if (V.PC.title === 1) {
			titles.push("Lord of the Arcology");
		} else {
			titles.push("Lady of the Arcology");
		}
	} else if (V.rep > 12000) {
		titles.push("Ruler of the Arcology");
	} else if (V.rep > 9000) {
		titles.push("chief officer of the arcology");
	} else {
		titles.push("owner of the arcology");
	}

	if (titles.length === 1) {
		V.PCTitle += titles[0];
	} else if (titles.length === 2) {
		V.PCTitle += titles[0] + " and " + titles[1];
	} else {
		titles[titles.length - 1] = "and " + titles[titles.length - 1];
		V.PCTitle += titles.join(", ");
	}
};

window.PoliteRudeTitle = function PoliteRudeTitle(slave) {
	const V = State.variables, PC = V.PC, s = V.sEnunciate, ss = V.ssEnunciate;

	var r = "";
	if (slave.nationality === "Japanese") {
		if (slave.trust > 0) {
			r += `${PC.name}${PC.title > 0 ? "kun" : "chan"}`;
		} else {
			r += (PC.surname ? PC.surname : `${PC.name}${s}an`);
		}
	} else {
		if (slave.intelligence+slave.intelligenceImplant < -95) {
			r += V.titleEnunciate;
		} else if (slave.intelligence+slave.intelligenceImplant > 50) {
			r += (PC.title > 0 ? `Ma${s}ter` : `Mi${s}tre${ss}`);
		} else if (slave.trust > 0) {
			r += PC.name;
		} else {
			r += (PC.surname ? PC.surname : PC.name);
		}
	}
	return r;
};

window.SlaveTitle = function SlaveTitle(slave) {
	const V = State.variables;
	let r = "";
	if (V.newDescriptions === 1) {
		if (slave.dick > 0 && slave.balls > 0 && slave.boobs > 300 && slave.vagina > -1 && slave.ovaries === 1) {
			if (jsRandom(1,100) > 50) {
				r = "futanari";
			} else {
				r = "herm";
			}
		} else if (slave.dick > 0 && slave.balls === 0 && slave.boobs > 300 && slave.vagina > -1 && slave.ovaries === 1) {
			r = "dickgirl";
		} else if (slave.dick > 0 && slave.vagina > -1 && slave.ovaries === 0) {
			r = "shemale";
		} else if (slave.dick > 0 && slave.balls === 0 && slave.vagina === -1 && slave.ovaries === 0) {
			r = "eunuch";
		} else if (slave.dick > 0 && slave.balls > 0 && slave.vagina === -1 && slave.ovaries === 0) {
			if (slave.face > 10 && slave.hips > -1 && slave.shoulders < 1 && slave.faceShape !== "masculine") {
				r = "trap";
			} else if (slave.boobs > 800) {
				r = "tittyboy";
			} else if (slave.dick === 1 && slave.balls === 1) {
				r = "sissy";
			} else if (slave.dick > 1 && slave.balls > 1 && slave.height < 165 && slave.muscles < 5 && slave.visualAge < 19 && slave.faceShape !== "masculine") {
				r = "twink";
			} else if (slave.dick > 1 && slave.balls > 1 && slave.height < 160 && slave.muscles < 5 && slave.visualAge < 19) {
				r = "boytoy";
			} else if (slave.muscles > 95 && slave.height >= 185) {
				r = "titan";
			} else if (slave.muscles > 30) {
				r = "muscleboy";
			} else {
				r = "slaveboy";
			}
		} else if (slave.dick === 0 && slave.balls === 0 && slave.vagina > -1) {
			if ((slave.shoulders > slave.hips || slave.faceShape === "masculine") && slave.boobs < 400 && slave.genes === "XY") {
				r = "cuntboy";
			} else if (slave.ovaries === 0 && slave.genes === "XY") {
				r = "tranny";
			} else if (slave.weight > 10 && slave.boobs > 800 && slave.birthsTotal > 0 && slave.physicalAge > 59) {
				r = "GMILF";
			} else if (slave.weight > 10 && slave.boobs > 800 && slave.birthsTotal > 0 && slave.physicalAge > 35) {
				r = "MILF";
			} else if (slave.lips > 70 && slave.boobs > 2000 && slave.butt > 3) {
				r = "bimbo";
			} else if (slave.hips > 1 && slave.boobs > 2000 && slave.butt > 3 && slave.waist < 50) {
				r = "hourglass";
			} else if (slave.muscles > 95 && slave.height >= 185) {
				r = "amazon";
			} else if (slave.muscles > 30) {
				r = "musclegirl";
			} else {
				r = "slavegirl";
			}
		} else if (slave.dick === 0 && slave.balls === 0 && slave.vagina === -1) {
			r = "neuter";
		} else if (slave.dick === 0 && slave.vagina === -1) {
			r = "ballslave";
		} else {
			r = "slave";
		}

		if (slave.visualAge < 13) {
			if (slave.genes === "XY" && slave.vagina === -1) {
				r = "shota " + r;
			} else {
				r = "loli " + r;
			}
		}

		if (slave.dick > 9 && slave.balls > 9 && slave.boobs > 12000) {
			r = "hyper " + r;
		}

		if (slave.boobs > 4000 && slave.lactation > 0) {
			if (slave.physicalAge < 13) {
				r = r + " calf";
			} else {
				r = r + " cow";
			}
		} else if (slave.lactation > 0) {
			r = "milky " + r;
		}

		if (slave.boobs > 20000) {
			r = "supermassive titted " + r;
		} else if (slave.boobs > 10000) {
			r = "giant titted " + r;
		} else if (slave.boobs > 4000) {
			r = "huge titted " + r;
		} else if (slave.boobs > 1000) {
			r = "busty " + r;
		}

		if (slave.dick > 5 && slave.balls > 5) {
			r = "womb filling " + r;
		} else if (slave.dick > 5) {
			r = "well hung " + r;
		}

		if (slave.butt >= 12) {
			r = "colossal assed " + r;
		} else if (slave.butt >= 12) {
			r = "massive assed " + r;
		} else if (slave.butt >= 8) {
			r = "fat assed " + r;
		} else if (slave.butt >= 6) {
			r = "bottom heavy " + r;
		} else if (slave.butt >= 4) {
			r = "big bottomed " + r;
		}

		if (slave.weight > 10 && slave.weight < 100 && slave.boobs > 5000 && slave.butt > 5 && slave.hips >= 2 && slave.bellyPreg >= 30000 && slave.births >= 10) {
			r = r + "fertility goddess";
		} else if (slave.births >= 6) {
			r = r + " broodmother";
		} else if (slave.births >= 3) {
			r = r + " breeder";
		}

		if (slave.indenture > -1) {
			r = "indentured " + r;
		}

		if (slave.preg > 10 && slave.pregKnown === 1) {
			r = "pregnant " + r;
		} else if (slave.bellyFluid >= 5000) {
			r = "bloated " + r;
		} else if (slave.belly >= 5000) {
			r = "gravid " + r;
		}

		if (slave.fuckdoll > 0) {
			r = r + " fuckdoll";
		}
	} else {
		r = "slave"; /* I don't tihnk there is an 'else'? */
		if ((slave.dick === 0) && (slave.vagina === -1)) { /* NULLS */
			r = "null";
				if ((slave.lactation > 0) && (slave.boobs > 2000)) {
					r = r + " cow";
				} else if ((slave.boobsImplant > 0) && (slave.buttImplant > 0)) {
					r = r + " bimbo ";
				} else if (slave.boobs > 6000) {
					r = r + " boob";
				} else if (slave.butt > 6) {
					r = r + " ass";
				} else if ((slave.muscles > 30) && (slave.height < 185)) {
						r = r + " muscle";
				}
					if (slave.visualAge > 55) {
						r = r + "GILF";
					} else if (slave.visualAge > 35) {
						r = r + "MILF";
					} else if (slave.visualAge >= 25) {
						r = r + "slave";
					} else {
						r = r + "girl";
					}
		}

		if ((slave.dick === 0) && (slave.vagina !== -1)) { /* FEMALES */
			if (slave.visualAge > 55) {
				r = "GILF";
			} else if (slave.visualAge > 35) {
				r = "MILF";
			} else if (slave.visualAge >= 25) {
				r = "slave";
			} else {
				r = "slavegirl";
			}
				if ((slave.muscles > 30) && (slave.height < 185)) {
					r = "muscle " + r;
				} else if ((slave.lactation > 0) && (slave.boobs > 2000)) {
					r = r + " cow";
				} else if ((slave.boobsImplant > 0) && (slave.buttImplant > 0)) {
					r = r + " bimbo";
				} else if (slave.boobs > 6000) {
					r = "boob" + r;
				} else if (slave.butt > 6) {
					r = "ass" + r;
				}
		}

		if ((slave.dick !== 0) && (slave.vagina !== -1)) {
				if (slave.balls > 0) { /* FUTANARI: cock & balls & vagina */
					r = "futanari ";
				} else { /* FUTANARI: cock & vagina */
					r = "futa ";
				}
					if ((slave.lactation > 0) && (slave.boobs > 2000)) {
						r = r + "cow";
					} else if ((slave.boobsImplant > 0) && (slave.buttImplant > 0)) {
						r = r + "bimbo ";
					} else if (slave.boobs > 6000) {
						r = r + "boob";
					} else if (slave.butt > 6) {
						r = r + "ass";
					} else if ((slave.muscles > 30) && (slave.height < 185)) {
						r = r + "muscle";
					}
						if (slave.visualAge > 55) {
							r = r + "GILF";
						} else if (slave.visualAge > 35) {
							r = r + "MILF";
						} else if (slave.visualAge >= 25) {
							r = r + "slave";
						} else {
							r = r + "girl";
						}
							if (slave.dick > 5 && slave.balls > 5 && slave.boobs > 5000) {
								r = "hyper " + r;
							}
		}

		if ((slave.dick !== 0) && (slave.vagina === -1) && (slave.balls > 0) && (slave.boobs > 300) && (slave.butt > 2)) { /* SHEMALES: cock & balls, T&A above minimum */
			if (slave.visualAge > 55) {
				r = "sheGILF";
			} else if (slave.visualAge > 35) {
				r = "sheMILF";
			} else if (slave.visualAge >= 25) {
				r = "shemale";
			} else {
				r = "tgirl";
			}
				if ((slave.muscles > 30) && (slave.height < 185)) {
					r = "muscle" + r;
				} else if ((slave.lactation > 0) && (slave.boobs > 2000)) {
					r = r + " cow";
				} else if ((slave.boobsImplant > 0) && (slave.buttImplant > 0)) {
					r = r + " bimbo";
				} else if (slave.boobs > 6000) {
					r = "topheavy " + r;
				} else if (slave.butt > 6) {
					r = "bottomheavy " + r;
				}
		}

		if ((slave.boobs < 300) || (slave.butt < 2)) {
			if ((slave.dick !== 0) && (slave.vagina === -1) && (slave.balls > 0)) {
				if ((slave.shoulders < 1) || (slave.muscles <= 30)) {
					if ((slave.faceShape === "masculine") || (slave.faceShape === "androgynous")) { /* SISSIES: feminine shoulders or muscles, masculine faces */
						if (slave.visualAge > 55) {
							r = "sissyGILF";
						} else if (slave.visualAge > 35) {
							r = "sissyMILF";
						} else {
							r = "sissy";
						}
					} else { /* TRAPS: feminine shoulders or muscles, feminine faces */
						if (slave.visualAge > 55) {
							r = "trapGILF";
						} else if (slave.visualAge > 35) {
							r = "trapMILF";
						} else if (slave.visualAge >= 25) {
							r = "trap";
						} else {
							r = "trapgirl";
						}
					}
						if (slave.lactation > 0) {
							r = r + " cow";
						} else if ((slave.boobsImplant > 0) && (slave.buttImplant > 0)) {
							r = r + " bimbo";
						}
				}
			}
		}

		if ((slave.boobs < 300) || (slave.butt < 2)) {
			if ((slave.dick !== 0) && (slave.vagina === -1) && (slave.balls > 0)) {
				if ((slave.shoulders > 1) || (slave.muscles >= 30)) {	/* BITCHES: masculine shoulders or muscles */
					r = "bitch";
						if ((slave.muscles > 30) && (slave.height < 185)) {
							r = "muscle" + r;
						} else if (slave.lactation > 0) {
							r = r + "cow";
						} else if ((slave.boobsImplant > 0) && (slave.buttImplant > 0)) {
							r = "bimbo " + r;
						}
						if (slave.visualAge > 55) {
							r = "aged " + r;
						} else if (slave.visualAge > 35) {
							r = "mature " + r;
						} else if (slave.visualAge < 25) {
							r = "young " + r;
						}
				}
			}
		}

		if ((slave.dick !== 0) && (slave.vagina === -1) && (slave.balls === 0)) {
			r = "dick";
				if (slave.visualAge > 55) {
					r = r + "GILF";
				} else if (slave.visualAge > 35) {
					r = r + "MILF";
				} else if (slave.visualAge >= 25) {
					r = r + "slave";
				} else {
					r = r + "girl";
				}
					if ((slave.muscles > 30) && (slave.height < 185)) {
						r = "muscle" + r;
					} else if ((slave.lactation > 0) && (slave.boobs > 2000)) {
						r = r + " cow";
					} else if ((slave.boobsImplant > 0) && (slave.buttImplant > 0)) {
						r = r + " bimbo";
					} else if (slave.boobs > 6000) {
						r = "boob " + r;
					} else if (slave.butt > 6) {
						r = "ass " + r;
					}
		}

		if ((slave.muscles > 30) && (slave.height > 185)) {
			r = "amazon " + r;
		} else if ((slave.muscles < 30) && (slave.height > 185)) {
			r = "statuesque " + r;
		} else if ((slave.boobs < 800) && (slave.height < 150)) {
			r = "petite " + r;
		} else if ((slave.boobs > 800) && (slave.height < 150)) {
			r = "shortstack " + r;
		}

		if (slave.births >= 5) {
			r = r + " broodmother";
		} else if (slave.births >= 2) {
			r = r + " breeder";
		}

		if (slave.indenture > -1) {
			r = "indentured " + r;
		}

		if (slave.preg > 10 && slave.pregKnown === 1) {
			r = "pregnant " + r;
		} else if (slave.bellyFluid >= 5000) {
			r = "bloated " + r;
		} else if (slave.belly >= 5000) {
			r = "gravid " + r;
		}

		if (slave.fuckdoll > 0) {
			r = r + " fuckdoll";
		}
	}
	return r;
};

window.DegradingName = function DegradingName(slave) {
	const V = State.variables;
	const leadershipPosition = [
		"be the Attendant",
		"be the Matron",
		"be the Stewardess",
		"be the Milkmaid",
		"be the DJ",
		"be your Concubine",
		"be the Madam",
		"be the Schoolteacher",
		"be the Wardeness",
		"be the Nurse",
		"be your Head Girl",
		"guard you",
		"recruit girls"];
	let names = [];
	let suffixes = [];

	if (slave.fuckdoll > 0) {
		slave.slaveName = "Fuckdoll No. " + slave.ID;
		slave.slaveSurname = 0;
	} else if (slave.assignment === "work in the dairy" && V.dairyRestraintsSetting >= 2) {
		slave.slaveName = "Bioreactor No. " + slave.ID;
		slave.slaveSurname = 0;
	} else {	
		if (V.seeRace === 1) {
			switch (slave.race) {
				case "white":
					names.push("Pale", "White");
					break;
				case "asian":
					names.push("Asian", "Yellow");
					break;
				case "latina":
					names.push("Brown", "Latina");
					break;
				case "black":
					names.push("Black", "Dark");
					break;
				case "pacific islander":
					names.push("Islander", "Pacific", "Sea");
					break;
				case "malay":
					names.push("Cinnamon", "Pinoy", "Spice");
					break;
				case "southern european":
					names.push("Mediterranean", "Olive");
					break;
				case "amerindian":
					names.push("Indian", "Reservation");
					break;
				case "semitic":
					names.push("Semite", "Semitic");
					break;
				case "middle eastern":
					names.push("Arab", "Sand");
					break;
				case "indo-aryan":
					names.push("Brown", "Indian");
					break;
				case "mixed race":
					names.push("Mixed", "Mulatto", "Mutt");
					break;
			}
		}
		names.push(slave.hColor);
		if (slave.eyes === -2) {
			names.push("Blind", "Eyeless", "Sightless");
		}
		if (slave.hears === -2) {
			names.push("Deaf", "Earless", "Unhearing");
		}
		if (slave.boobs >= 2000) {
			suffixes.push("Boob", "Boobs", "Titty");
		}
		if (slave.boobs < 500 && slave.butt < 3) {
			names.push("Girly", "Slim", "Thin");
		}
		if (slave.boobs < 300) {
			names.push("Flat");
		}
		if (slave.anus > 2 || slave.vagina > 2) {
			names.push("Gaping", "Hallway", "Slit", "Wideopen");
		}
		if (slave.weight > 160) {
			names.push("Blimp", "Cow", "Fat", "Fatass", "Whale");
		} else if (slave.weight > 30) {
			names.push("Chubby", "Fat", "Whale");
		} else if (slave.weight <= -30) {
			names.push("Bony", "Rail", "Skinny");
		}
		if (slave.muscles > 30) {
			names.push("Huge", "Muscles", "Ripped", "Strong");
		}
		if (slave.fetishKnown === 1) {
			if (slave.fetish === "buttslut") {
				names.push("Anal", "Sodomy");
			} 
			if (slave.fetish === "cumslut") {
				names.push("Cum", "Dicksuck", "Sucker");
			}
			if (slave.fetish === "humiliation") {
				names.push("Rape");
			}
			if (slave.fetish === "masochist") {
				names.push("Pain", "Rape", "Struggle");
			}
			if (slave.fetish === "pregnancy") {
				names.push("Fertile");
			}
		}
		if (slave.boobs*slave.lactation > 1000) {
			names.push("Creamy", "Milky");
			suffixes.push("Cow");
		}
		if (slave.oralSkill <= 30 && slave.analSkill <= 30) {
			names.push("Cheap", "Fail", "Gutter");
		}
		if (slave.nipples === "fuckable") {
			names.push("Nipplefuck", "Nipplecunt");
		} else if (slave.nipples !== "tiny" && slave.nipples !== "cute") {
			names.push("Pointy", "Titclit");
			suffixes.push("Nipples");
		}
		if (slave.visualAge > 35) {
			names.push("Mature");
			suffixes.push("Cougar", "MILF");
		} else if (slave.visualAge < 25) {
			names.push("Girly", "Thin", "Young");
		}
		if (slave.amp === 1) {
			names.push("Stumpy");
			suffixes.push("Stumpy");
		}
		if (slave.boobsImplant > 1000 || slave.buttImplant > 3) {
			names.push("Fake", "Plastic", "Silicone");
		}
		if (slave.dick > 5 && slave.balls > 5) {
			names.push("Potent");
			suffixes.push("Cannon", "Daddy");
		}
		if (slave.preg > 30) {
			if (slave.broodmother === 2) {
				names.push("Bursting", "Seeded");
				suffixes.push("Factory", "Nursery");
			} else if (slave.broodmother === 1) {
				names.push("Bloated", "Stuffed");
				suffixes.push("Breeder", "Factory");
			}
		}
		if (slave.bellyPreg >= 450000) {
			names.push("Bulging", "Squirming");
		}
		if (slave.bellyPreg >= 5000) {
			names.push("Preg");
			suffixes.push("Belly", "Mommy");
		}
		if (slave.belly > 150000) {
			suffixes.push("Balloon");
		}
		if (slave.belly > 1500) {
			suffixes.push("Belly");
		}
		if (slave.dick > 0) {
			if (slave.dick > 4) {
				names.push("Dangle", "Hung");
				suffixes.push("Cock", "Dick");
			}
			if (slave.balls === 0) {
				names.push("Cut", "Gelded", "Soft");
			} else {
				names.push("Erect", "Hard", "Stiff");
			}
		}
		if (slave.dick === 1) {
			names.push("Micro", "Tiny");
			suffixes.push("Bitch");
		}
		if (slave.height >= 185) {
			names.push("Tall", "Top");
			suffixes.push("Tower");
		} else if (slave.height < 150) {
			names.push("Stumpy", "Tiny");
			suffixes.push("Shortstack", "Stumpy");
		}
		if (slave.whoreSkill > 95) {
			names.push("Money", "Street");
			suffixes.push("Whore");
		}
		if (slave.entertainSkill > 95) {
			names.push("Easy", "Club");
			suffixes.push("Slut");
		}
		if (slave.oralSkill > 95) {
			names.push("Suck");
			suffixes.push("Throat");
		}
		if (slave.vaginalSkill > 95) {
			suffixes.push("Channel", "Kegel", "Pussy");
		}
		if (slave.analSkill > 95) {
			suffixes.push("Asspussy", "Sphincter");
		}
		if (slave.intelligence+slave.intelligenceImplant > 50) {
			names.push("Bright", "Clever", "Smart");
			if (slave.intelligenceImplant >= 15) {
				names.push("College", "Graduate", "Nerdy");
			}
		} else if (slave.intelligence+slave.intelligenceImplant < -50) {
			names.push("Cretin", "Dumb", "Retarded", "Stupid");
		}
		if (slave.vagina === 1 && slave.vaginaSkill <= 10) {
			names.push("Fresh", "New", "Tight");
		}
		if (slave.devotion < -75) {
			names.push("Angry", "Biter", "Caged");
		} else if (slave.devotion < -50) {
			names.push("Cell", "Cuffs");
		} else if (slave.devotion < -20) {
			names.push("Bag", "Box");
		} else if (slave.devotion <= 20) {
			names.push("Sad", "Whiner");
		} else if (slave.devotion > 50) {
			names.push("Prize");
			if (slave.visualAge > 35) {
				names.push("Queen");
			} else if (slave.visualAge < 25) {
				names.push("Princess");
			}
		}
		if (slave.trust < -50) {
			names.push("Screaming");
			suffixes.push("Sobber");
		} else if (slave.trust < -20) {
			names.push("Crying");
			suffixes.push("Meat", "Tears", "Thing", "Weeper");
		} else if (slave.trust < 20) {
			names.push("Begging");
		}

		if (slave.dick === 0) {
			if (slave.vagina === -1) {
				suffixes.push("Null");
			} else {
				if (slave.visualAge < 25) {
					suffixes.push("Girl");
				}
			}
		} else {
			if (slave.vagina !== -1) {
				suffixes.push("Futa");
			} else {
				if (slave.balls > 0) {
					if (slave.boobs > 300 && slave.butt > 2) { /* SHEMALES: cock & balls, T&A above minimum */
						suffixes.push("Shemale");
					} else {
						if (slave.shoulders < 1 && slave.muscles <= 30) {
							if (slave.faceShape === "masculine" || slave.faceShape === "androgynous") { /* SISSIES: feminine shoulders or muscles, masculine faces */
								suffixes.push("Sissy");
							} else { /* TRAPS: feminine shoulders or muscles, feminine faces */
								suffixes.push("Trap");
							}
						} else { /* BITCHES: masculine shoulders or muscles */
							suffixes.push("Bitch");
						}
					}
				} else {
					if (slave.visualAge > 35) {
						suffixes.push("DickMILF");
					} else if (slave.visualAge >= 25) {
						suffixes.push("Dickslave");
					} else {
						suffixes.push("Dickgirl");
					}
				}
			}
		}
		if (slave.anus > 0) {
			suffixes.push("Anus", "Asshole", "Backdoor", "Butt", "Butthole");
		}
		if (slave.anus === 1) {
			suffixes.push("Tightass", "Tightbutt");
		}
		if (slave.vagina > 0) {
			suffixes.push("Cunt", "Pussy", "Vagina");
		}
		if (slave.boobs < 500 && slave.butt < 3 && slave.dick > 0) {
			suffixes.push("Bitch", "Bottom", "Sissy", "Trap");
		}
		if (slave.energy > 95) {
			suffixes.push("Fuck", "Fuckaddict", "Nympho", "Sexaddict");
		}
		if (slave.fetishKnown === 1) {
			if (slave.fetish === "humiliation") {
				suffixes.push("Rapebait", "Showgirl");
			}
			if (slave.fetish === "submissive") {
				suffixes.push("Bottom", "Fuckee", "Rapebait");
			}
			if (slave.fetish === "dom") {
				suffixes.push("Dom", "Fucker", "Top");
			}
			if (slave.fetish === "pregnancy") {
				suffixes.push("Breeder", "Mommy");
			}
			if (slave.fetish === "boobs") {
				suffixes.push("Boob", "Boobie", "Tit", "Titty");
			}
		}
		if (slave.births >= 2) {
			suffixes.push("Breeder");
			if (slave.births >= 5) {
				suffixes.push("Broodmother");
			}
		}
		if (slave.areolae > 2) {
			suffixes.push("Areolas", "Headlights");
		}
		if (slave.lips > 40) {
			suffixes.push("Lips", "Pillows");
		}
		if (slave.labia > 1) {
			suffixes.push("Curtains", "Flower", "Lips");
		}
		if (slave.breedingMark === 1 && V.propOutcome === 1) {
			suffixes.push("Breeder", "Oven", "Womb");
		}
		if (slave.butt > 5) {
			suffixes.push("Ass", "Bottom", "Butt");
		}
		if (slave.vagina === 0) {
			suffixes.push("Virgin");
		}

		slave.slaveName = jsEither(names);
	}
	if (leadershipPosition.includes(slave.assignment)) {
		switch (slave.assignment) {
			case "be the Attendant":
				slave.slaveName = jsEither(["Bath", "Spa"]);
				break;
			case "be the Matron":
				slave.slaveName = jsEither(["Nursery", "Matron"]);
				break;
			case "be the Stewardess":
				slave.slaveName = jsEither(["Servant", "Maid"]);
				break;
			case "be the Milkmaid":
				if (V.cumSlaves > 3) {
					slave.slaveName = jsEither(["Fucker", "Milker"]);
				} else {
					slave.slaveName = jsEither(["Dairy", "Farm"]);
				}
				break;
			case "be the DJ":
				slave.slaveName = jsEither(["Bass", "Booth"]);
				break;
			case "be your Concubine":
				slave.slaveName = jsEither(["Bed", "Master"]);
				break;
			case "be the Madam":
				slave.slaveName = jsEither(["Madam", "Pimp"]);
				break;
			case "be the Schoolteacher":
				slave.slaveName = jsEither(["Classroom", "Teacher"]);
				break;
			case "be the Wardeness":
				slave.slaveName = jsEither(["Jail", "Prison"]);
				break;
			case "be the Nurse":
				slave.slaveName = jsEither(["Clinic", "Nurse"]);
				break;
			case "be your Head Girl":
				slave.slaveName = jsEither(["Chief", "Head"]);
				break;
			case "guard you":
				slave.slaveName = jsEither(["Battle", "Guard"]);
				break;
			case "recruit girls":
				slave.slaveName = jsEither(["Cam", "Recruiter"]);
				break;
		}
	}
	let surname = jsEither(suffixes);
	if (typeof surname === "string" && surname.toLowerCase() === slave.slaveName.toLowerCase()) {
		DegradingName(slave);
	}
	slave.slaveSurname = surname;
};

window.SlaveSort = function SlaveSort(slaves, main=false) {
	const V = State.variables;
	if (main) {
		switch (V.sortSlavesBy) {
		case "name":
			if (V.sortSlavesOrder === "ascending")
				slaves = slaves.sort((a, b) => a.slaveName < b.slaveName ? -1 : 1);
			else
				slaves = slaves.sort((a, b) => a.slaveName > b.slaveName ? -1 : 1);
			break;
		case "assignment":
			if (V.sortSlavesOrder === "ascending")
				slaves = slaves.sort((a, b) => a.assignment < b.assignment ? -1 : 1);
			else
				slaves = slaves.sort((a, b) => a.assignment > b.assignment ? -1 : 1);
			break;
		case "seniority":
			if (V.sortSlavesOrder === "ascending")
				slaves = slaves.sort((a, b) => b.weekAcquired - a.weekAcquired);
			else
				slaves = slaves.sort((a, b) => a.weekAcquired - b.weekAcquired);
			break;
		case "actualAge":
			if (V.sortSlavesOrder === "ascending")
				slaves = slaves.sort((a, b) => a.actualAge - b.actualAge);
			else
				slaves = slaves.sort((a, b) => b.actualAge - a.actualAge);
			break;
		case "visualAge":
			if (V.sortSlavesOrder === "ascending")
				slaves = slaves.sort((a, b) => a.visualAge - b.visualAge);
			else
				slaves = slaves.sort((a, b) => b.visualAge - a.visualAge);
			break;
		case "physicalAge":
			if (V.sortSlavesOrder === "physicalAge")
				slaves = slaves.sort((a, b) => a.physicalAge - b.physicalAge);
			else
				slaves = slaves.sort((a, b) => b.physicalAge - a.physicalAge);
			break;
		default:
			if (V.sortSlavesOrder === "ascending")
				slaves = slaves.sort((a, b) => a.devotion - b.devotion);
			else
				slaves = slaves.sort((a, b) => b.devotion - a.devotion);
			break;
		}
		V.slaveIndices = slaves2indices();
	} else {
		V.slaveIndices = slaves2indices();
		filterInPlace(slaves, s => V.slaveIndices[s] !== undefined);
		slaves.sort((a, b) => V.slaveIndices[a] - V.slaveIndices[b]);
	}
};

window.slaveSortMinor = function slaveSortMinor(slaves) {
	slaves = slaves.sort((a, b) => a.slaveName < b.slaveName ? -1 : 1);
}

window.MenialPopCap = function MenialPopCap () {
	const V = State.variables;
	let popCap = 500;
	let r = "";

	for (let mwi = 20; mwi < V.sectors.length; mwi++) {
		if (V.sectors[mwi].type === "Pens") {
			popCap += 500;
		}
	}
	let overMenialCap = V.helots + V.fuckdolls + V.menialBioreactors - popCap;
	if (overMenialCap > 0) {
		let price = menialSlaveCost();
		if (V.helots > 0) {
			if (V.helots > overMenialCap) {
				V.cash += overMenialCap * price;
				V.menialDemandFactor -= overMenialCap;
				V.helots -= overMenialCap;
				overMenialCap = 0;
				r += "You don't have enough room for all your menials and are obliged to sell some.";
			} else {
				V.cash += V.helots * price;
				V.menialDemandFactor -= V.helots;
				overMenialCap -= V.helots;
				V.helots = 0;
				r += "You don't have enough room for your menials and are obliged to sell them.";
			}
		}
		if (overMenialCap > 0 && V.fuckdolls > 0) {
			if (V.fuckdolls > overMenialCap) {
				V.cash += overMenialCap * (price * 2);
				V.menialDemandFactor -= overMenialCap;
				V.fuckdolls -= overMenialCap;
				overMenialCap = 0;
				r += "You don't have enough room for all your fuckdolls and are obliged to sell some.";
			} else {
				V.cash += V.fuckdolls * (price * 2);
				V.menialDemandFactor -= V.fuckdolls;
				overMenialCap -= V.fuckdolls;
				V.fuckdolls = 0;
				r += "You don't have enough room for your fuckdolls and are obliged to sell them.";
			}
		}
		if (overMenialCap > 0 && V.menialBioreactors > 0) {
			V.cash += overMenialCap * (price - 100);
			V.menialDemandFactor -= overMenialCap;
			V.menialBioreactors -= overMenialCap;
			r += "You don't have enough room for all your menial bioreactors and are obliged to sell some.";
		}
	}
	V.PopCap = popCap;
	return r;
};

window.faceIncrease = function faceIncrease(slave, amount) {
	const pronouns = getPronouns(slave);
	const his = pronouns.possessive;
	const His = capFirstChar(his);
	let r = "";
	if (slave.face <= -95)
		r += `<span class="green">${His} face is no longer horrifying,</span> and is now merely ugly.`;
	else if (slave.face <= -40 && slave.face + amount > -40)
		r += `<span class="green">${His} face is no longer ugly,</span> and is now merely unattractive.`;
	else if (slave.face <= -10 && slave.face + amount > -10)
		r += `<span class="green">${His} face is no longer unattractive,</span> and is now somewhat tolerable.`;
	else if (slave.face <= 10 && slave.face + amount > 10)
		r += `<span class="green">${His} face is now decently attractive,</span> rather than merely tolerable.`;
	else if (slave.face <= 40 && slave.face + amount > 40)
		r += `<span class="green">${His} face is now quite beautiful,</span> rather than merely pretty.`;
	else if (slave.face <= 95 && slave.face + amount > 95)
		r += `<span class="green">${His} face is now perfect.</span> It's difficult to imagine how it could be any more beautiful.`;
	slave.face = Math.clamp(slave.face + amount,-100,100);
	if (slave.face > 95) slave.face = 100;
	return r;
};
