code:
:: DefaultRules [script]
// this code applies RA rules onto slaves

window.DefaultRules = (function() {
	"use strict";
	let V;
	let r;

	function DefaultRules(slave) {
		V = State.variables;
		r = "";
		let rule = MergeRules(slave);

		if (Object.keys(rule).length === 0) return r; // no rules apply

		AssignJobToSlave(slave, rule);
		if(slave.fuckdoll === 0) {
			ProcessClothing(slave, rule);
			ProcessCollar(slave, rule);
			ProcessEyewear(slave, rule);
			ProcessDildos(slave, rule);
			ProcessDickAccessories(slave, rule);
			ProcessAnalAccessories(slave, rule);
			ProcessShoes(slave, rule);
			ProcessBellyAccessories(slave, rule);
		}
		ProcessBellyImplant(slave, rule);
		if (isFertile(slave))
			ProcessFertilityDrugs(slave, rule);
		ProcessAssetGrowthDrugs(slave, rule);
		ProcessOtherDrugs(slave, rule);
		ProcessDiet(slave, rule);
		ProcessCuratives(slave, rule);
		ProcessAphrodisiacs(slave, rule);
		ProcessPenisHormones(slave, rule);
		ProcessFemaleHormones(slave, rule);
		ProcessPregnancyDrugs(slave, rule);
		if(slave.fuckdoll === 0) {
			ProcessLivingStandard(slave, rule);
			ProcessSpeech(slave, rule);
			ProcessRelationship(slave, rule);
			ProcessRelease(slave, rule);
			ProcessPunishment(slave, rule);
			ProcessReward(slave, rule);
		}
		ProcessDietCum(slave, rule);
		ProcessDietMilk(slave, rule);
		ProcessTeeth(slave, rule);
		ProcessStyle(slave, rule);
		ProcessPiercings(slave, rule);
		ProcessSmartPiercings(slave, rule);
		ProcessTattoos(slave, rule);
		ProcessPorn(slave, rule);
		return r;
	}

	function MergeRules(slave) {
		// merge all rules applying on a slave into one big rule
		const rules = V.defaultRules
			.filter(rule => ruleAppliesP(rule.condition, slave))
			.map(rule => ProcessAssignments(slave, Object.assign({}, rule.set)));
		return mergeRules(rules);
	}

	function ProcessAssignments(slave, rule) {
		// Before merging rules, we process assignments for each rule separately so we can remove slaves from facilities when they no longer qualify, even if the final "winning" rule assigns them elsewhere
		// We also ignore inapplicable assignments for the current slave, so we only merge assignments that are valid
		switch (rule.setAssignment) {
			case "no default setting":
				delete rule.setAssignment;
				break;

			case "rest":
			case "please you":
				// slaves always qualify for this assignment
				break;

			case "live with your Head Girl":
				if ((V.HGSuiteSlaves < 1 && slave.indentureRestrictions <= 0))
					break;
				else {
					RAFacilityRemove(slave, rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "be confined in the arcade":
				if ((V.arcadeSlaves < V.arcade && slave.indentureRestrictions <= 0 && slave.breedingMark != 1))
					break;
				else {
					RAFacilityRemove(slave, rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "serve in the master suite":
				if ((V.masterSuiteSlaves < V.masterSuite && (slave.devotion > 20 || slave.trust < -50 || (slave.devotion >= -50 && slave.trust < -20))))
					break;
				else {
					RAFacilityRemove(slave, rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "get treatment in the clinic":
				if ((V.clinicSlaves < V.clinic && (slave.health < 20 || (slave.chem > 15 && V.Nurse !== 0 && V.clinicUpgradeFilters == 1)) || ((slave.bellyImplant > -1) && (V.bellyImplants == 1)) || slave.preg > 1))
					break;
				else {
					RAFacilityRemove(slave, rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "rest in the spa":
				if ((V.spaSlaves < V.spa) && (slave.health < 20) || (slave.trust < 60) || (slave.devotion <= 60) || (slave.fetish == "mindbroken") && (slave.devotion >= -20))
					break;
				else {
					RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "work in the brothel":
				if ((V.brothelSlaves < V.brothel && (slave.devotion > 50 || slave.trust > 50 || slave.trust < -50 || (slave.devotion >= -50 && slave.trust < -20)) && slave.breedingMark != 1))
					break;
				else {
					RAFacilityRemove(slave, rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "serve in the club":
				if ((V.clubSlaves < V.club && (slave.devotion > 50 || slave.trust > 50 || slave.trust < -50 || (slave.devotion >= -50 && slave.trust < -20)) && slave.breedingMark != 1))
					break;
				else {
					RAFacilityRemove(slave, rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "work in the dairy":
				if ((V.dairy > V.dairySlaves+V.bioreactorsXY+V.bioreactorsXX+V.bioreactorsHerm+V.bioreactorsBarren)) {
					if ((slave.indentureRestrictions > 0) && (V.dairyRestraintsSetting > 1))
						break;
					else if (((slave.indentureRestrictions > 1) && (V.dairyRestraintsSetting > 0)) || (slave.breedingMark == 1 && V.dairyRestriantsSettings > 0) || ((V.dairyPregSetting > 0) && ((slave.bellyImplant != -1) || (slave.broodmother !== 0))))
						break;
					else {
						if ((slave.lactation > 0 || ((V.dairySlimMaintainUpgrade === 0 || V.dairySlimMaintain === 0) && (slave.boobs > 300 || slave.dick === 0 || V.dairyImplantsSetting == 1) && V.dairyImplantsSetting != 2)) || (slave.balls > 0)) {
							if ((slave.devotion > 20) || ((slave.devotion >= -50) && (slave.trust < -20)) || (slave.trust < -50) || (slave.amp == 1) || (V.dairyRestraintsUpgrade == 1)) {
								if ((V.dairyStimulatorsSetting < 2) || (slave.anus > 2) || (V.dairyPrepUpgrade == 1)) {
									if ((V.dairyPregSetting < 2) || (slave.vagina > 2) || (slave.ovaries === 0) || (V.dairyPrepUpgrade == 1))
										break;
									else {
										RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
										delete rule.setAssignment;
									}
								} else {
									RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
									delete rule.setAssignment;
								}
							} else {
								RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
								delete rule.setAssignment;
							}
						} else {
							RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
							delete rule.setAssignment;
						}
					}
				}
				break;

			case "work as a servant":
				if ((V.servantsQuartersSlaves < V.servantsQuarters && canSee(slave) && canWalk(slave) && (slave.devotion >= -20 || slave.trust < -20 || (slave.devotion >= -50 && slave.trust <= 20))))
					break;
				else {
					RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "learn in the schoolroom":
				if ((V.schoolroomSlaves < V.schoolroom && slave.fetish != "mindbroken" && (slave.devotion >= -20 || slave.trust < -50 || (slave.devotion >= -50 && slave.trust < -20))))
					if ((slave.intelligenceImplant < 1) || (slave.voice !== 0 && slave.accent+V.schoolroomUpgradeLanguage > 2) || (slave.oralSkill <= 10+V.schoolroomUpgradeSkills*20) || (slave.whoreSkill <= 10+V.schoolroomUpgradeSkills*20) || (slave.entertainSkill <= 10+V.schoolroomUpgradeSkills*20) || (slave.analSkill < 10+V.schoolroomUpgradeSkills*20) || ((slave.vagina >= 0) && (slave.vaginalSkill < 10+V.schoolroomUpgradeSkills*20)))
						break;
					else {
						RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
						delete rule.setAssignment;
					}
				else {
					RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "be confined in the cellblock":
				if ((V.cellblockSlaves < V.cellblock && ((slave.devotion < -20 && slave.trust >= -20) || (slave.devotion < -50 && slave.trust >= -50))))
					break;
				else {
					RAFacilityRemove(slave,rule); // before deleting rule.setAssignment
					delete rule.setAssignment;
				}
				break;

			case "take classes":
				if (slave.intelligenceImplant !== 1 && slave.fetish != "mindbroken" && (slave.devotion >= -20 || slave.trust < -50 || (slave.trust < -20 && slave.devotion >= -50)))
					break;
				else
					delete rule.setAssignment;
				break;

			case "choose her own job":
				if ((slave.fetish != "mindbroken"))
					break;
				else
					delete rule.setAssignment;
				break;

			case "get milked":
				if ((slave.lactation > 0 || slave.balls > 0))
					break;
				else
					delete rule.setAssignment;
				break;

			case "be a servant":
				if ((canWalk(slave) && canSee(slave) && (slave.devotion >= -20 || slave.trust < -50 || (slave.trust < -20 && slave.devotion >= -50))))
					break;
				else
					delete rule.setAssignment;
				break;

			case "work a glory hole":
				if (slave.indentureRestrictions <= 0 && slave.breedingMark != 1)
					break;
				else
					delete rule.setAssignment;
				break;

			case "whore":
			case "serve the public":
			case "stay confined":
				if ((slave.fuckdoll === 0) && slave.breedingMark != 1)
					break;
				else
					delete rule.setAssignment;
				break;

			default:
				r += `<span class="red">raWidgets missing case for assignment 'V.{rule.setAssignment}'</span>.`;
				break;
		}
		return rule;
	}

	function AssignJobToSlave(slave, rule) {
		// place slave on assignment defined by the rule
		if ((rule.setAssignment !== undefined && rule.setAssignment != "no default setting")) {
			if (((rule.setAssignment == "choose her own job" && !slave.choosesOwnAssignment) || rule.setAssignment != slave.assignment)) {
				switch (rule.setAssignment) {
					case "live with your Head Girl":
						r += `<br>${slave.slaveName} has been automatically assigned to live in your Head Girl's private suite.`;
						break;
					case "be confined in the arcade":
						r += `<br>${slave.slaveName} has been automatically assigned to be confined in ${V.arcadeName}.`;
						break;
					case "serve in the master suite":
						r += `<br>${slave.slaveName} has been automatically assigned to {V.masterSuiteName}.`;
						break;
					case "get treatment in the clinic":
						r += `<br>${slave.slaveName} has been automatically assigned to get treatment in {V.clinicName}.`;
						break;
					case "rest in the spa":
						r += `<br>${slave.slaveName} has been automatically assigned to rest in ${V.spaName}.`;
						break;
					case "work in the brothel":
						r += `<br>${slave.slaveName} has been automatically assigned to work in ${V.brothelName}.`;
						break;
					case "serve in the club":
						r += `<br>${slave.slaveName} has been automatically assigned to serve in ${V.clubName}.`;
						break;
					case "work in the dairy":
						r += `<br>${slave.slaveName} has been automatically assigned to be milked in ${V.dairyName}.`;
						break;
					case "work as a servant":
						r += `<br>${slave.slaveName} has been automatically assigned to work in ${V.servantsQuartersName}.`;
						break;
					case "work as a servant":
						r += `<br>${slave.slaveName} has been automatically assigned to work in ${V.servantsQuartersName}.`;
						break;
					case "learn in the schoolroom":
						r += `<br>${slave.slaveName} has been automatically assigned to study in ${V.schoolroomName}.`;
						break;
					case "be confined in the cellblock":
						r += `<br>${slave.slaveName} has been automatically assigned to be confined in ${V.cellblockName}.`;
						break;
					case "choose her own job":
						r += `<br>${slave.slaveName} is now allowed to select her own assignments.`;
						break;
					default:
						r += `<br>${slave.slaveName} has been automatically assigned to ${rule.setAssignment}.`;
						break;
				}
				assignJob(slave, rule.setAssignment);
			}
		}
	}

	function ProcessClothing(slave, rule) {
		// apply clothes to slave
		if ((rule.clothes !== undefined) && (rule.clothes !== "no default setting")) {
			if ((rule.clothes == "choosing her own clothes")) {
				if ((slave.choosesOwnClothes === 0)) {
					slave.clothes = "choosing her own clothes";
					slave.choosesOwnClothes = 1;
					r += `<br>${slave.slaveName} is now allowed to choose her own clothes.`;
				}
			} else if ((slave.clothes !== rule.clothes)) {
				slave.clothes = rule.clothes;
				slave.choosesOwnClothes = 0;
				r += `<br>${slave.slaveName} is now wearing ${slave.clothes}.`;
			}
		}
	}

	function ProcessCollar(slave, rule) {
		// apply collar to slave
		if ((rule.collar !== undefined) && (rule.collar != "no default setting")) {
			if ((slave.collar !== rule.collar)) {
				r += '<br>';
				if ((rule.collar == "preg biometrics" && slave.preg <= -1)) {
					slave.collar = "none";
					r += `${slave.slaveName} cannot utilize preg biometrics.`;
				} else if ((rule.collar == "massive dildo gag" && slave.oralSkill <= 50)) {
					slave.collar = "none";
					r += `${slave.slaveName} lacks the oral skill to successfully keep the massive dildo gag in her throat.`;
				} else
					slave.collar = rule.collar;
				if ((slave.collar == "none"))
					r += `${slave.slaveName} has been given no collar.`;
				else
					r += `${slave.slaveName} has been given a slave.collar collar.`;
			}
		}
	}

	function ProcessEyewear(slave, rule) {
		// apply glasses, contacts to slave
		if ((rule.eyewear !== undefined) && (rule.eyewear !== "no default setting")) {
			switch (rule.eyewear) {
				case "correct with glasses":
					if (slave.eyes == -1) {
						if (slave.eyewear != "corrective glasses") {
							slave.eyewear = "corrective glasses";
							V.cash -= V.modCost;
							r += `<br>${slave.slaveName} has been given corrective glasses.`;
						}
					} else {
						if (slave.eyewear != "none") {
							slave.eyewear = "none";
							r += `<br>${slave.slaveName}'s eyewear has been removed.`;
						}
					}
					break;

				case "correct with contacts":
					if (slave.eyes == -1) {
						if (slave.eyewear != "corrective contacts") {
							slave.eyewear = "corrective contacts";
							V.cash -= V.modCost;
							r += `<br>${slave.slaveName} has been given corrective contacts.`;
						}
					} else {
						if (slave.eyewear != "none") {
							slave.eyewear = "none";
							r += `<br>${slave.slaveName}'s eyewear has been removed.`;
						}
					}
					break;

				case "blur with glasses":
					if (slave.eyes > -1) {
						if (slave.eyewear != "blurring glasses") {
							slave.eyewear = "blurring glasses";
							V.cash -= V.modCost;
							r += `<br>${slave.slaveName} has been given blurring glasses.`;
						}
					} else {
						if (slave.eyewear != "none") {
							slave.eyewear = "none";
							r += `<br>${slave.slaveName}'s eyewear has been removed.`;
						}
					}
					break;

				case "blur with contacts":
					if (slave.eyes > -1) {
						if (slave.eyewear != "blurring contacts") {
							slave.eyewear = "blurring contacts";
							V.cash -= V.modCost;
							r += `<br>${slave.slaveName} has been given blurring contacts.`;
						}
					} else {
						if (slave.eyewear != "none") {
							slave.eyewear = "none";
							r += `<br>Since ${slave.slaveName}'s eyewear has been removed.`;
						}
					}
					break;

				case "universal glasses":
					if (slave.eyes == -1) {
						if (slave.eyewear != "corrective glasses") {
							slave.eyewear = "corrective glasses";
							V.cash -= V.modCost;
							r += `<br>${slave.slaveName} has been given corrective glasses.`;
						}
					} else {
						if (slave.eyewear != "glasses") {
							slave.eyewear = "glasses";
							V.cash -= V.modCost;
							r += `<br>${slave.slaveName} has been given decorative glasses.`;
						}
					}
					break;

				default:
					if (slave.eyewear != "none") {
						slave.eyewear = "none";
						r += `<br>${slave.slaveName}'s eyewear has been removed.`;
					}
					break;
			}
		}
	}

	function ProcessDildos(slave, rule) {
		// apply vaginal dildos to slave
		if (slave.vagina === 0)
			ProcessVVirginDildos(slave, rule);
		else if ((slave.vagina > 0) && (slave.anus === 0))
			ProcessAVirginDildos(slave, rule);
		else if (slave.vagina > 0)
			ProcessNonVirginDildos(slave, rule);
	}

	function ProcessVVirginDildos(slave, rule) {
		// apply vaginal dildos to varginal virgins
		if ((rule.virginAccessory !== undefined) && (rule.virginAccessory !== "no default setting")) {
			if (slave.vaginalAccessory !== rule.virginAccessory) {
				slave.vaginalAccessory = rule.virginAccessory;
				switch (slave.vaginalAccessory) {
					case "huge dildo":
						r += `<br>${slave.slaveName} is a virgin and has been given a`;
						if (slave.vagina >= 2)
							r += `massive dildo to permanently gape her cunt.`;
						else {
							r += `large dildo for her pussy, since it must be stretched before it can accommodate a huge one.`;
							slave.vaginalAccessory = "large dildo";
						}
						break;

					case "long dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so the virgin ${slave.slaveName} has been given a standard length dildo for her pussy.`;
							slave.vaginalAccessory = "dildo";
						}
						break;

					case "long, large dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so the virgin ${slave.slaveName} has been given a standard length large dildo for her pussy.`;
							slave.vaginalAccessory = "large dildo";
						}
						break;

					case "long, huge dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so the virgin ${slave.slaveName} has been given a standard length huge dildo for her pussy.`;
							slave.vaginalAccessory = "huge dildo";
						} else {
							r += `<br>slave.slaveName is a virgin and has been given a`;
							if (slave.vagina >= 2)
								r += `massive and oversized dildo to permanently gape her cunt.`;
							else {
								r += `long, large dildo for her pussy, since it must be stretched before it can accommodate a huge one.`;
								slave.vaginalAccessory = "long, large dildo";
							}
						}
						break;

					case "none":
						r += `<br>${slave.slaveName} is a virgin and has been instructed not to use a vaginal accessory.`;
						break;

					default:
						r += `<br>${slave.slaveName} is a virgin and has been given a ${slave.vaginalAccessory} for her pussy.`;
						break;
				}
			}
		}
	}

	function ProcessAVirginDildos(slave, rule) {
		// apply vaginal dildos to anal virgins
		if ((rule.aVirginAccessory !== undefined) && (rule.aVirginAccessory !== "no default setting")) {
			if (slave.vaginalAccessory !== rule.aVirginAccessory) {
				slave.vaginalAccessory = rule.aVirginAccessory;
				switch (slave.vaginalAccessory) {
					case "huge dildo":
						r += `<br>${slave.slaveName} is a virgin and has been given a`;
						if (slave.vagina >= 2)
							r += `massive dildo to permanently gape her cunt.`;
						else {
							r += `large dildo for her pussy, since it must be stretched before it can accommodate a huge one.`;
							slave.vaginalAccessory = "large dildo";
						}
						break;

					case "long dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so the virgin ${slave.slaveName} has been given a standard length dildo for her pussy.`;
							slave.vaginalAccessory = "dildo";
						}
						break;

					case "long, large dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so the virgin ${slave.slaveName} has been given a standard length large dildo for her pussy.`;
							slave.vaginalAccessory = "large dildo";
						}
						break;

					case "long, huge dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so the virgin ${slave.slaveName} has been given a standard length huge dildo for her pussy.`;
							slave.vaginalAccessory = "huge dildo";
						} else {
							r += `<br>${slave.slaveName} is a virgin and has been given a`;
							if (slave.vagina >= 2)
								r += `massive and oversized dildo to permanently gape her cunt.`;
							else {
								r += `long, large dildo for her pussy, since it must be stretched before it can accommodate a huge one.`;
								slave.vaginalAccessory = "long, large dildo";
							}
						}
						break;

					case "none":
						r += `<br>slave.slaveName is a virgin and has been instructed not to use a vaginal accessory.`;
						break;

					default:
						r += `<br>slave.slaveName is a virgin and has been given a slave.vaginalAccessory for her pussy.`;
						break;
				}
			}
		}
	}

	function ProcessNonVirginDildos(slave, rule) {
		// apply vaginal dildos to non-virgins
		if ((rule.vaginalAccessory !== undefined) && (rule.vaginalAccessory !== "no default setting")) {
			if (slave.vaginalAccessory !== rule.vaginalAccessory) {
				slave.vaginalAccessory = rule.vaginalAccessory;
				switch (slave.vaginalAccessory) {
					case "huge dildo":
						r += `<br>${slave.slaveName} has been given a`;
						if (slave.vagina >= 2)
							r += `massive dildo to permanently gape her cunt.`;
						else {
							r += `large dildo for her pussy, since it must be stretched before it can accommodate a huge one.`;
							slave.vaginalAccessory = "large dildo";
						}
						break;

					case "long dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so ${slave.slaveName} has been given a standard length dildo for her pussy.`;
							slave.vaginalAccessory = "dildo";
						}
						break;

					case "long, large dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so ${slave.slaveName} has been given a standard length large dildo for her pussy.`;
							slave.vaginalAccessory = "large dildo";
						}
						break;

					case "long, huge dildo":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of cervix penetrating dildos on marked slaves, so ${slave.slaveName} has been given a standard length huge dildo for her pussy.`;
							slave.vaginalAccessory = "huge dildo";
						} else {
							r += `<br>${slave.slaveName} has been given a`;
							if (slave.vagina >= 2)
								r += `massive and oversized dildo to permanently gape her cunt.`;
							else {
								r += `long, large dildo for her pussy, since it must be stretched before it can accommodate a huge one.`;
								slave.vaginalAccessory = "long, large dildo";
							}
						}
						break;
					case "none":
						r += `<br>${slave.slaveName} has been instructed not to use a vaginal accessory.`;
						break;

					default:
						r += `<br>${slave.slaveName} has been given a slave.vaginalAccessory for her pussy.`;
						break;
				}
			}
		}
	}

	function ProcessDickAccessories(slave, rule) {
		// apply dick accessories to slave
		if ((slave.dick > 0)) {
			if (slave.anus === 0) {
				if ((rule.aVirginDickAccessory !== undefined) && (rule.aVirginDickAccessory !== "no default setting")) {
					if ((slave.dickAccessory !== rule.aVirginDickAccessory)) {
						slave.dickAccessory = rule.aVirginDickAccessory;
						if (slave.dickAccessory == "none")
							r += `<br>${slave.slaveName} is a virgin and has been instructed not to wear a dick accessory.`;
						else
							r += `<br>${slave.slaveName} is a virgin and has been given a ${slave.dickAccessory} accessory for her cock.`;
					}
				}
			} else {
				if ((rule.dickAccessory !== undefined) && (rule.dickAccessory !== "no default setting")) {
					if ((slave.dickAccessory !== rule.dickAccessory)) {
						slave.dickAccessory = rule.dickAccessory;
						if (slave.dickAccessory == "none")
							r += `<br>${slave.slaveName} has been instructed not to wear a dick accessory.`;
						else
							r += `<br>${slave.slaveName} has been given a slave.dickAccessory accessory for her cock.`;
					}
				}
			}
		}
	}

	function ProcessShoes(slave, rule) {
		// apply shoes to slave
		if ((rule.shoes !== undefined) && (rule.shoes !== "no default setting")) {
			if ((slave.shoes !== rule.shoes)) {
				if ((slave.amp != 1)) {
					slave.shoes = rule.shoes;
					r += `<br>${slave.slaveName}'s shoes have been set to ${slave.shoes}.`;
				}
			}
		}
	}

	function ProcessBellyAccessories(slave, rule) {
		// apply belly accessories to slave
		if ((rule.bellyAccessory !== undefined) && (rule.bellyAccessory !== "no default setting")) {
			if ((slave.bellyAccessory !== rule.bellyAccessory)) {
				if ((slave.belly >= 1500 || slave.weight >= 130) && setup.fakeBellies.includes(rule.bellyAccessory)) {
					r += `<br>${slave.slaveName}'s natural belly is too big to properly wear an empathy belly.`;
					slave.bellyAccessory = "none";
				} else {
					slave.bellyAccessory = rule.bellyAccessory;
					if (slave.bellyAccessory == "none")
						r += `<br>${slave.slaveName} has been instructed not to wear a torso accessory.`;
					else
						r += `<br>${slave.slaveName} has been given ${slave.bellyAccessory} to wear.`;
				}
			}
		}
	}

	function ProcessAnalAccessories(slave, rule) {
		// apply buttplugs to slave
		if ((slave.vaginalAccessory !== "anal chastity") && (slave.vaginalAccessory !== "combined chastity") && (slave.dickAccessory !== "anal chastity") && (slave.dickAccessory !== "combined chastity")) {
			if (slave.anus === 0)
				ProcessAnalVirginButtplugs(slave, rule);
			else
				ProcessNonVirginButtplugs(slave, rule);
		}
	}

	function ProcessAnalVirginButtplugs(slave, rule) {
		// apply buttplugs to virgins
		if ((rule.aVirginButtplug !== undefined) && (rule.aVirginButtplug !== "no default setting")) {
			if ((slave.buttplug !== rule.aVirginButtplug)) {
				slave.buttplug = rule.aVirginButtplug;
				switch (slave.buttplug) {
					case "huge plug":
						r += `<br>${slave.slaveName} is an anal virgin and has been given a`;
						if ((slave.anus >= 2))
							r += `massive plug to permanently gape her asshole.`;
						else {
							slave.buttplug = "large plug";
							r += `large buttplug for her asshole, since it must be stretched before it can accommodate a huge one.`;
						}
						break;

					case "long plug":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of anal plugs that can damage a growing fetus on marked slaves, so the anal virgin ${slave.slaveName} has been given a standard length plug for her anus.`;
							slave.buttplug = "plug";
						}
						break;

					case "long, large plug":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of anal plugs that can damage a growing fetus on marked slaves, so the anal virgin ${slave.slaveName} has been given a standard length large plug for her anus.`;
							slave.buttplug = "large plug";
						}
						break;

					case "long, huge plug":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of anal plugs that can damage a growing fetus on marked slaves, so the anal virgin ${slave.slaveName} has been given a standard length huge plug for her anus.`;
							slave.buttplug = "huge plug";
						} else {
							r += `<br>slave.slaveName is an anal virgin and has been given a`;
							if (slave.anus >= 2)
								r += `massive and oversized plug to permanently gape her asshole.`;
							else {
								r += `long, large buttplug for her asshole, since it must be stretched before it can accommodate a huge one.`;
								slave.buttplug = "long, large plug";
							}
						}
						break;

					case "none":
						r += `<br>${slave.slaveName} is an anal virgin and has been instructed not to use an anal accessory.`;
						break;

					default:
						r += `<br>${slave.slaveName} is an anal virgin and has been given a slave.buttplug for her asshole.`;
						break;
				}
			}
		}
	}

	function ProcessNonVirginButtplugs(slave, rule) {
		// apply buttplugs to non-virgins
		if ((rule.buttplug !== undefined) && (rule.buttplug !== "no default setting")) {
			if ((slave.buttplug !== rule.buttplug)) {
				slave.buttplug = rule.buttplug;
				switch (slave.buttplug) {
					case "huge plug":
						r += `<br>${slave.slaveName} has been given a`;
						if ((slave.anus >= 2))
							r += `massive plug to permanently gape her asshole.`;
						else {
							slave.buttplug = "large plug";
							r += `large buttplug for her asshole, since it must be stretched before it can accommodate a huge one.`;
						}
						break;

					case "long plug":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of anal plugs that can damage a growing fetus on marked slaves, so ${slave.slaveName} has been given a standard length plug for her anus.`;
							slave.buttplug = "plug";
						}
						break;

					case "long, large plug":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of anal plugs that can damage a growing fetus on marked slaves, so ${slave.slaveName} has been given a standard length large plug for her anus.`;
							slave.buttplug = "large plug";
						}
						break;

					case "long, huge plug":
						if (slave.breedingMark == 1) {
							r += `<br>Breeding regulations forbid the use of anal plugs that can damage a growing fetus on marked slaves, so ${slave.slaveName} has been given a standard length huge plug for her anus.`;
							slave.buttplug = "huge plug";
						} else {
							r += `<br>${slave.slaveName} has been given a`;
							if (slave.anus >= 2)
								r += `massive and oversized plug to permanently gape her asshole.`;
							else {
								r += `long, large buttplug for her asshole, since it must be stretched before it can accommodate a huge one.`;
								slave.buttplug = "long, large plug";
							}
						}
						break;

					case "none":
						r += `<br>${slave.slaveName} has been instructed not to use an anal accessory.`;
						break;

					default:
						r += `<br>${slave.slaveName} has been given a slave.buttplug for her asshole.`;
						break;
				}
			}
		}
	}

	function ProcessBellyImplant(slave, rule) {
		// Here is belly implant size control, it's used in Surgery Degradation passage to setup devotion and trust changes.
		// silent calls to surgery degradation have been replaced with a js function, which is less hacky
		if ((rule.bellyImplantVol !== undefined) && slave.bellyImplant >= 0 && rule.bellyImplantVol >= 0) {
			r += "<br>";
			if (slave.health > -10 ) {
				let diff = rule.bellyImplantVol - slave.bellyImplant;
				if (diff >= 5000 && slave.bellyPain === 0 && slave.health > 50) {
					r += `${slave.slaveName}'s belly is way too small, so she has been directed to have intensive belly implant filling procedures throughout this week.`;
					slave.bellyImplant += 1000;
					slave.bellyPain += 2;
					BellySurgery(slave, diff);
				} else if (diff >= 500 && slave.bellyPain < 2 ) {
					r += `${slave.slaveName}'s belly has not reached the desired size, so she has been directed to have belly implant filling procedures throughout this week.`;
					slave.bellyImplant += 500;
					slave.bellyPain += 1;
					BellySurgery(slave, diff);
				} else if (diff <= -5000 ) {
					r += `${slave.slaveName}'s belly is way too big, so she has been directed to have intensive belly implant draining procedures throughout this week.`;
					slave.bellyImplant -= 1000;
					BellySurgery(slave, diff);
				} else if (diff <= -500 ) {
					r += `${slave.slaveName}'s belly is too big, so she has been directed to have belly implant draining procedures throughout this week.`;
					slave.bellyImplant -= 500;
					BellySurgery(slave, diff);
				}
			} else {
				r += `${slave.slaveName} is not healthy enough to safely adjust her belly implant.`;
			}
		}
	}

	function BellySurgery(slave, volume) {
		// this is a port of the belly implant portion of surgeryDegradation.tw
		// that way, we don't have to use ugly hacks
		// the original still exists, and may be worth replacing
		if (volume > 0) { // bellyUp
			SetBellySize(slave);
			if (slave.bellyPain === 1) {
				if (slave.devotion > 50) {
					slave.devotion += 4;
				} else if (slave.devotion >= -20) {
					slave.trust -= 5;
				} else {
					slave.trust -= 10;
					slave.devotion -= 5;
				}
			} else if (slave.bellyPain === 2) {
				if (slave.devotion > 50) {
					slave.devotion += 2;
				} else if (slave.devotion >= -20) {
					slave.trust -= 7;
				} else {
					slave.trust -= 12;
					slave.devotion -= 7;
				}
			}
		} else { // bellyDown
			if (slave.bellyImplant < 0)
				slave.bellyImplant = 0;
			SetBellySize(slave);
			if (slave.devotion > 50) {
				slave.devotion += 3;
				slave.trust += 3;
			} else if (slave.devotion >= -20) {
				slave.trust += 2;
			} else {
				slave.devotion += 1;
				slave.trust -= 10;
			}
		}
	}

	function ProcessFertilityDrugs(slave, rule) {
		// Fertility
		if ((rule.preg !== undefined) && (rule.preg !== "no default setting")) {
			if ((rule.preg == -1)) {
				if (slave.preg !== -1) {
					r += `<br>${slave.slaveName} is fertile, so she has been put on the appropriate contraceptive regime.`;
					slave.preg = -1;
				}
				if (slave.drugs == "fertility drugs" || slave.drugs == "super fertility drugs") {
					slave.drugs = "no drugs";
				}
			} else if ((rule.preg === 0)) {
				if (slave.preg !== 0) {
					r += `<br>${slave.slaveName} is fertile, so she has been taken off contraceptives.`;
					slave.preg = 0;
				}
				if (slave.drugs == "fertility drugs" || slave.drugs == "super fertility drugs") {
					slave.drugs = "no drugs";
				}
			} else if ((rule.preg == 1)) {
				if (slave.preg !== 0 || slave.drugs !== "fertility drugs" || slave.hormones !== 0) {
					slave.preg = 0;
					slave.drugs = "fertility drugs";
					slave.hormones = 0;
					r += `<br>${slave.slaveName} is fertile, so she has been put on the appropriate fertility regime.`;
				}
			} else if ((rule.preg == 2)) {
				if (slave.preg !== 0 || slave.drugs !== "fertility drugs" || slave.hormones !== 2) {
					slave.preg = 0;
					slave.drugs = "fertility drugs";
					slave.hormones = 2;
					r += `<br>${slave.slaveName} is fertile, so she has been put on the appropriate fertility regime.`;
				}
			} else if ((rule.preg == 3) && slave.indentureRestrictions < 1) {
				if (slave.preg !== 0 || slave.drugs !== "super fertility drugs" || slave.hormones !== 0) {
					slave.preg = 0;
					slave.drugs = "super fertility drugs";
					slave.hormones = 0;
					r += `<br>${slave.slaveName} is fertile, so she has been put on the appropriate fertility regime.`;
				}
			} else if ((rule.preg == 4) && slave.indentureRestrictions < 1) {
				if (slave.preg !== 0 || slave.drugs !== "super fertility drugs" || slave.hormones !== 2) {
					slave.preg = 0;
					slave.drugs = "super fertility drugs";
					slave.hormones = 2;
					r += `<br>${slave.slaveName} is fertile, so she has been put on the appropriate fertility regime.`;
				}
			}
		}
	}

	function ProcessAssetGrowthDrugs(slave, rule) {
		// Asset Growth
		const growth_drugs = new Set(["breast injections", "intensive breast injections", "breast redistributors", "butt injections", "intensive butt injections", "butt redistributors", "lip injections", "lip atrophiers", "penis enhancement", "intensive penis enhancement", "penis atrophiers", "testicle enhancement", "intensive testicle enhancement", "testicle atrophiers", "hyper breast injections", "hyper butt injections", "hyper penis enhancement", "hyper testicle enhancement"]);
		if ((slave.drugs == "super fertility drugs" || slave.drugs == "fertility drugs") && isFertile(slave)) {
			r += `<br>slave.slaveName is on slave.drugs and will not be considered for drug enhancement until that regime is complete.`;
			return;
		} else if ((rule.growth_boobs == "no default setting" && rule.growth_butt == "no default setting" && rule.growth_lips == "no default setting" && rule.growth_dick == "no default setting" && rule.growth_dick == "no default setting" && rule.growth_balls == "no default setting")) {
			return;
		}
		if (slave.assignmentVisible) { // More resource intensive version with prioritizing. Possible to give this a toggle rather than basing it on visibility.
			let _priorities = [];
			if (rule.growth_boobs != "no default setting") {
				let _priority;
				if (slave.boobs < rule.growth_boobs) {
					_priority = {drug: "breast injections", weight: (rule.growth_boobs-slave.boobs)/rule.growth_boobs};
					_priorities.push(_priority);
				} else if ((slave.boobs > rule.growth_boobs+200) && slave.weight < 100 && (V.arcologies[0].FSSlimnessEnthusiastResearch == 1)) {
					_priority = {
						drug: "breast redistributors",
						weight: (1+((slave.boobs-slave.boobsImplant-rule.growth_boobs)/rule.growth_boobs)) };
					_priorities.push(_priority);
				}
			}
			if (rule.growth_butt != "no default setting") {
				let _priority;
				if (slave.butt < rule.growth_butt) {
					_priority = {drug: "butt injections", weight: (rule.growth_butt-slave.butt)/rule.growth_butt};
					_priorities.push(_priority);
				} else if ((Math.trunc(slave.butt) > rule.growth_butt) && slave.weight < 100 && (V.arcologies[0].FSSlimnessEnthusiastResearch == 1)) {
					_priority = {
						drug: "butt redistributors",
						weight: (1+((slave.butt-slave.buttImplant-rule.growth_butt)/rule.growth_butt)) };
					_priorities.push(_priority);
				}
			}
			if (rule.growth_lips != "no default setting") {
				let _priority;
				if (slave.lips < rule.growth_lips) {
					_priority = {drug: "lip injections", weight: (rule.growth_lips-slave.lips)/rule.growth_lips};
					_priorities.push(_priority);
				} else if ((slave.lips > rule.growth_lips) && (V.arcologies[0].FSSlimnessEnthusiastResearch == 1)) {
					_priority = {
						drug: "lip atrophiers",
						weight: (1+((slave.lips-slave.lipsImplant-rule.growth_lips)/rule.growth_lips))};
					_priorities.push(_priority);
				}
			}
			if (rule.growth_dick != "no default setting" && slave.dick) {
				let _priority;
				if (slave.dick < rule.growth_dick) {
					_priority = {drug: "penis enhancement", weight: (rule.growth_dick-slave.dick)/rule.growth_dick};
					_priorities.push(_priority);
				} else if ((slave.dick > rule.growth_dick) && (V.arcologies[0].FSSlimnessEnthusiastResearch == 1)) {
					_priority = {
						drug: "penis atrophiers",
						weight: (1+((slave.dick-rule.growth_dick)/rule.growth_dick))};
					_priorities.push(_priority);
				}
			}
			if (rule.growth_balls != "no default setting" && slave.balls) {
				let _priority;
				if (slave.balls < rule.growth_balls) {
					_priority = {drug: "testicle enhancement", weight: (rule.growth_balls-slave.balls)/rule.growth_balls};
					_priorities.push(_priority);
				} else if ((slave.balls > rule.growth_balls) && (V.arcologies[0].FSSlimnessEnthusiastResearch == 1)) {
					_priority = {
						drug: "testicle atrophiers",
						weight: (1+((slave.balls-rule.growth_balls)/rule.growth_balls))};
					_priorities.push(_priority);
				}
			}
			if (_priorities.length > 1) {
				_priorities = _priorities.sort(function(a, b){if(a.weight > b.weight) return -1; if(a.weight < b.weight) return 1; return 0;});
				if (slave.drugs != _priorities[0].drug) {
					slave.drugs = _priorities[0].drug;
					r += `<br>${slave.slaveName} has been put on `;
					if (rule.growth_intensity && slave.drugs != "lip injections" && slave.health > 0) {
						slave.drugs = "intensive " + slave.drugs;
						r += `${slave.drugs}, since she's healthy enough to take them, and `;
					} else {
						r += `${slave.drugs}, since`;
					}
					r += `that part of her body is ${Math.trunc(_priorities[0].weight*100)}>>% `;
					if (_priorities[0].weight < 1) r+= "below ";
					else r+= "above ";
					r += "the targeted size.";
				}
				return;
			} else if (_priorities.length > 0) {
				if (slave.drugs != _priorities[0].drug) {
					slave.drugs = _priorities[0].drug;
					r += `<br>${slave.slaveName} has been put on `;
					if (rule.growth_intensity && slave.drugs != "lip injections" && slave.health > 0) {
						slave.drugs = "intensive " + slave.drugs;
						r += `${slave.drugs}, since she's healthy enough to take them, and `;
					} else
						r += `${slave.drugs}, since `;
					r += `that is the only part of her body that does not meet the targeted size.`;
				}
				return;
			} else if (growth_drugs.has(slave.drugs)) {
				slave.drugs = "no drugs";
				r += `<br>${slave.slaveName}'s body has met all relevant growth targets, so her pharmaceutical regime has been ended.`;
				return;
			}
		} else {
			let _hyper;
			if (V.arcologies[0].FSAssetExpansionistResearch == 1)
				_hyper = "hyper ";
			else
				_hyper = "";
			if (rule.growth_boobs != "no default setting") {
				if (slave.boobs < rule.growth_boobs) {
					if (slave.drugs != _hyper + "breast injections") {
						slave.drugs = _hyper + "breast injections";
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					}
					return;
				}
			}
			if (rule.growth_butt != "no default setting") {
				if (slave.butt < rule.growth_butt) {
					if (slave.drugs != _hyper + "butt injections") {
						slave.drugs = _hyper + "butt injections";
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					}
					return;
				}
			}
			if (rule.growth_lips != "no default setting") {
				if (slave.lips < rule.growth_lips) {
					if (slave.drugs != "lip injections") {
						slave.drugs = "lip injections";
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					}
					return;
				}
			}
			if (rule.growth_dick != "no default setting" && slave.dick) {
				if (slave.dick < rule.growth_dick) {
					if (slave.drugs != _hyper + "penis enhancement") {
						slave.drugs = _hyper + "penis enhancement";
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					}
					return;
				}
			}
			if (rule.growth_balls != "no default setting" && slave.balls) {
				if (slave.balls < rule.growth_balls) {
					if (slave.drugs != _hyper + "testicle enhancement") {
						slave.drugs = _hyper + "testicle enhancement";
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					}
					return;
				}
			}
			if (V.arcologies[0].FSSlimnessEnthusiastResearch == 1) {
				if (rule.growth_boobs != "no default setting") {
					if (slave.boobs-slave.boobsImplant > rule.growth_boobs+200 && slave.weight < 100) {
						if (slave.drugs != "breast redistributors") {
							slave.drugs = "breast redistributors";
							r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
						}
						return;
					}
				}
				if (rule.growth_butt != "no default setting") {
					if (Math.trunc(slave.butt-slave.buttImplant) > rule.growth_butt && slave.weight < 100) {
						if (slave.drugs != "butt redistributors") {
							slave.drugs = "butt redistributors";
							r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
						}
						return;
					}
				}
				if (rule.growth_lips != "no default setting") {
					if (slave.lips-slave.lipsImplant > rule.growth_lips) {
						if (slave.drugs != "lip atrophiers") {
							slave.drugs = "lip atrophiers";
							r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
						}
						return;
					}
				}
				if (rule.growth_dick != "no default setting" && slave.dick) {
					if (slave.dick > rule.growth_dick) {
						if (slave.drugs != "penis atrophiers") {
							slave.drugs = "penis atrophiers";
							r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
						}
						return;
					}
				}
				if (rule.growth_balls != "no default setting" && slave.balls) {
					if (slave.balls > rule.growth_balls) {
						if (slave.drugs != "testicle atrophiers") {
							slave.drugs = "testicle atrophiers";
							r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
						}
						return;
					}
				}
			}
			if (growth_drugs.has(slave.drugs)) {
				slave.drugs = "no drugs";
				r += `<br>${slave.slaveName} has met all relevant growth targets, so her pharmaceutical regime has been ended.`;
				return;
			}
		}
	}

	function ProcessOtherDrugs(slave, rule) {
		// Other Drugs
		const drugs = new Set(["psychosuppressants", "no drugs", "steroids", "hormone enhancers", "hormone blockers", "anti-aging cream", "growth stimulants", "sag-B-gone", "male hormone injections", "female hormone injections", "none"]);
		if (drugs.has(rule.drug)) {
			if (drugs.has(slave.drugs) && (slave.drugs != rule.drug)) {
				switch (rule.drug) {
				case "anti-aging cream":
					if (slave.visualAge > 18) {
						slave.drugs = rule.drug ;
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					} else {
						slave.drugs = "no drugs" ;
						r += `<br>${slave.slaveName} cannot benefit from her assigned drug and has been defaulted to ${slave.drugs}.`;
					}
					break;

				case "growth stimulants":
					if (slave.height < 274 && slave.height < Math.clamp((Height.mean(slave) * 1.25),0,274)) {
						slave.drugs = rule.drug;
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					} else {
						slave.drugs = "no drugs" ;
						r += `<br>${slave.slaveName} cannot benefit from her assigned drug and has been defaulted to ${slave.drugs}.`;
					}
					break;

				case "sag-B-gone":
					if (slave.boobs > 250 && slave.boobShape != "saggy") {
						slave.drugs = rule.drug;
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					} else {
						slave.drugs = "no drugs";
						r += `<br>${slave.slaveName} cannot benefit from her assigned drug and has been defaulted to ${slave.drugs}.`;
					}
					break;

				case "female hormone injections":
					if (slave.breedingMark != 1 && (slave.ovaries == 1 || slave.mpreg == 1) && slave.pubertyXX === 0) {
						slave.drugs = rule.drug ;
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					} else {
						slave.drugs = "no drugs" ;
						r += `<br>${slave.slaveName} cannot benefit from her assigned drug and has been defaulted to ${slave.drugs}.`;
					}
					break;

				case "male hormone injections":
					if (slave.breedingMark != 1 && slave.balls > 0 && slave.pubertyXY === 0) {
						slave.drugs = rule.drug ;
						r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					} else {
						slave.drugs = "no drugs" ;
						r += `<br>${slave.slaveName} cannot benefit from her assigned drug and has been defaulted to ${slave.drugs}.`;
					}
					break;

				default:
					slave.drugs = rule.drug ;
					r += `<br>${slave.slaveName} has been put on ${slave.drugs}.`;
					break;
				}
			}
		}
	}

	function ProcessDiet(slave, rule) {
		// Diet Setting
		if ((rule.diet !== undefined) && (rule.diet !== "no default setting")) {
			/*
			if ((slave.boobs >= 1600) && (slave.muscles <= 5) && (slave.amp != 1) && ((rule.muscles == "no default setting") || (rule.muscles === 0))) {
				if ((slave.diet !== "muscle building")) {
					slave.diet = "muscle building"
					r += `<br>${slave.slaveName} has big tits and no back muscles, so she's been assigned to gain some.`
				}
			} else if ((slave.boobs >= 1600) && (slave.muscles > 5) && (slave.diet == "muscle building") && ((rule.muscles == "no default setting") || (rule.muscles === 0))) {
			*/
			if ((slave.boobs >= 1600) && (slave.muscles > 5) && (slave.diet == "muscle building") && ((rule.muscles == "no default setting") || (rule.muscles === 0))) {
				slave.diet = "healthy";
				r += `<br>${slave.slaveName} has huge boobs, but she already has the back muscles to bear them, so she's been assigned to stop working out so hard.`;
			} else if ((rule.dietGrowthSupport == 1) && ((slave.drugs == "breast injections") || (slave.drugs == "butt injections")) && (slave.weight <= 95)) {
				if (slave.diet !== "fattening") {
					slave.diet = "fattening";
					r += `<br>${slave.slaveName} is on drugs designed to expand major body parts, so she's been put on a fattening diet to provide her body as much fuel for growth as possible.`;
				}
			} else {
				if (!(isNaN(rule.diet))) {
					if ((slave.weight > rule.diet)) {
						if ((slave.diet !== "restricted")) {
							slave.diet = "restricted";
							r += `<br>${slave.slaveName} is too fat so her diet has been set to restricted.`;
						}
						if ((V.arcologies[0].FSSlimnessEnthusiastResearch == 1 && (slave.drugs == "no drugs" || slave.drugs == "none"))) {
							slave.drugs = "appetite suppressors";
							r += `<br>${slave.slaveName} is too fat so she will be given weight loss pills.`;
						}
					} else if ((slave.weight < rule.diet)) {
						if ((slave.diet !== "fattening")) {
							slave.diet = "fattening";
							r += `<br>${slave.slaveName} is too skinny so her diet has been set to fattening.`;
						}
						if ((slave.drugs == "appetite suppressors")) {
							slave.drugs = "no drugs";
							r += `<br>${slave.slaveName} is too skinny so she will no longer be given weight loss pills.`;
						}
					} else if ((rule.muscles !== undefined) && (rule.muscles !== "no default setting") && (slave.amp != 1)) {
						if ((slave.muscles >= rule.muscles+8)) {
							if ((slave.diet !== "slimming")) {
								slave.diet = "slimming";
								r += `<br>${slave.slaveName} has been put on a slimming exercise regime.`;
							}
						} else if ((slave.muscles <= rule.muscles-2)) {
							if ((slave.diet !== "muscle building")) {
								slave.diet = "muscle building";
								r += `<br>${slave.slaveName} has been put on a muscle building exercise regime.`;
							}
						} else {
							if ((slave.diet !== "healthy")) {
								slave.diet = "healthy";
								r += `<br>${slave.slaveName} is at the target weight, so her diet has been normalized.`;
							}
						}
					} else {
						if ((slave.diet !== "healthy")) {
							slave.diet = "healthy";
							r += `<br>${slave.slaveName} is at the target weight, so her diet has been normalized.`;
						}
						if ((slave.drugs == "appetite suppressors")) {
							slave.drugs = "no drugs";
							r += `<br>${slave.slaveName} is at the target weight, so she will no longer be given weight loss pills.`;
						}
					}
				} else if ((rule.diet == "attractive")) {
					if (((slave.weight > 95) || ((slave.weight > 30) && (slave.hips < 2)))) {
						if ((slave.diet !== "restricted")) {
							slave.diet = "restricted";
							r += `<br>${slave.slaveName} is too fat so her diet has been set to restricted.`;
						}
						if ((V.arcologies[0].FSSlimnessEnthusiastResearch == 1 && (slave.drugs == "no drugs" || slave.drugs == "none"))) {
							slave.drugs = "appetite suppressors";
							r += `<br>${slave.slaveName} is too fat so she will be given weight loss pills.`;
						}
					} else if (((slave.weight < -95) || ((slave.weight < -30) && (slave.hips > -2)))) {
						if ((slave.diet !== "fattening")) {
							slave.diet = "fattening";
							r += `<br>${slave.slaveName} is too skinny so her diet has been set to fattening.`;
						}
						if ((slave.drugs == "appetite suppressors")) {
							slave.drugs = "no drugs";
							r += `<br>${slave.slaveName} is too skinny so she will no longer be given weight loss pills.`;
						}
					} else if ((rule.muscles !== undefined) && (rule.muscles !== "no default setting") && (slave.amp != 1)) {
						if ((slave.muscles >= rule.muscles+8)) {
							if ((slave.diet !== "slimming")) {
								slave.diet = "slimming";
								r += `<br>${slave.slaveName} has been put on a slimming exercise regime.`;
							}
						} else if ((slave.muscles <= rule.muscles-2)) {
							if ((slave.diet !== "muscle building")) {
								slave.diet = "muscle building";
								r += `<br>${slave.slaveName} has been put on a muscle building exercise regime.`;
							}
						} else {
							if ((slave.diet !== "healthy")) {
								slave.diet = "healthy";
								r += `<br>${slave.slaveName} is at the target weight, so her diet has been normalized.`;
							}
							if ((slave.drugs == "appetite suppressors")) {
								slave.drugs = "no drugs";
								r += `<br>${slave.slaveName} is at the target weight, so she will no longer be given weight loss pills.`;
							}
						}
					} else {
						if ((slave.diet !== "healthy")) {
							slave.diet = "healthy";
							r += `<br>${slave.slaveName} is at the target weight, so her diet has been normalized.`;
						}
						if ((slave.drugs == "appetite suppressors")) {
							slave.drugs = "no drugs";
							r += `<br>${slave.slaveName} is at the target weight, so she will no longer be given weight loss pills.`;
						}
					}
				} else if ((rule.diet == "XX")) {
					if ((slave.diet !== "XX")) {
						slave.diet = "XX";
						r += `<br>${slave.slaveName} has been put on a diet that favors feminine development.`;
					}
				} else if ((rule.diet == "XY")) {
					if ((slave.diet !== "XY")) {
						slave.diet = "XY";
						r += `<br>${slave.slaveName} has been put on a diet that favors masculine development.`;
					}
				} else if ((rule.diet == "XXY")) {
					if (slave.balls > 0 && (slave.ovaries == 1 || slave.mpreg == 1)) {
						if ((slave.diet !== "XXY")) {
							slave.diet = "XXY";
							r += `<br>${slave.slaveName} has been put on a diet that enhances a herm's unique sexuality.`;
						}
					} else {
						if ((slave.diet !== "healthy")) {
							slave.diet = "healthy";
							r += `<br>${slave.slaveName} has been put on a standard diet since she is not a hermaphrodite.`;
						}
					}
				} else if ((rule.diet == "cleansing")) {
					if (((slave.diet !== "cleansing") && (slave.health < 100))) {
						slave.diet = "cleansing";
						r += `<br>${slave.slaveName} has been put on a diet of cleansers.`;
					}
				} else if ((rule.diet == "fertility")) {
					if (canGetPregnant(slave)) {
						if ((slave.diet !== "fertility")) {
							slave.diet = "fertility";
							r += `<br>${slave.slaveName} has been put on a diet to enhance fertility.`;
						}
					} else {
						if ((slave.diet !== "healthy")) {
							slave.diet = "healthy";
							if (slave.pregKnown === 0 && slave.preg > 0) {
								r += `<br>${slave.slaveName} has been put on a standard diet since tests reveal she has become pregnant.`;
								slave.pregKnown = 1;
							} else {
								r += `<br>${slave.slaveName} has been put on a standard diet since she is currently unable to become pregnant.`;
							}
						}
					}
				} else if ((rule.diet == "cum production")) {
					if ((slave.balls > 0)) {
						if ((slave.diet !== "cum production")) {
							slave.diet = "cum production";
							r += `<br>${slave.slaveName} has been put on a diet to promote cum production.`;
						}
					} else {
						if ((slave.diet !== "healthy")) {
							slave.diet = "healthy";
							r += `<br>${slave.slaveName} has been put on a standard diet since she is no longer able to produce cum.`;
						}
					}
				}
			}
		} else if ((rule.muscles !== undefined) && (rule.muscles !== "no default setting") && (slave.amp != 1)) { // no diet rule, muscles only
			if ((slave.muscles >= rule.muscles+8)) {
				if ((slave.diet !== "slimming")) {
					slave.diet = "slimming";
					r += `<br>${slave.slaveName} has been put on a slimming exercise regime.`;
				}
			} else if ((slave.muscles <= rule.muscles-2)) {
				if ((slave.diet !== "muscle building")) {
					slave.diet = "muscle building";
					r += `<br>${slave.slaveName} has been put on a muscle building exercise regime.`;
				}
			} else {
				if ((slave.diet !== "healthy")) {
					slave.diet = "healthy";
					r += `<br>${slave.slaveName} has achieved the target musculature, so her exercise regime has been normalized.`;
				}
			}
		}
	}

	function ProcessCuratives(slave, rule) {
		if ((rule.curatives !== undefined) && (rule.curatives !== "no default setting")) {
			if (slave.curatives !== rule.curatives) {
				if (rule.curatives === 2) {
					if (slave.health > 100) {
						if ((slave.curatives != 1)) {
							r += `<br>${slave.slaveName} has been put on preventatives, since curatives cannot improve her health further.`;
							slave.curatives = 1;
						}
					} else {
						r += `<br>${slave.slaveName} has been put on curatives.`;
						slave.curatives = rule.curatives;
					}
				} else {
					r += `<br>${slave.slaveName} has been ${rule.curatives > 0 ? `put on preventatives` : `taken off health drugs`}`;
					slave.curatives = rule.curatives;
				}
			}
		}
	}

	function ProcessAphrodisiacs(slave, rule) {
		if ((rule.aphrodisiacs !== undefined) && (rule.aphrodisiacs != "no default setting")) {
			if (slave.aphrodisiacs != rule.aphrodisiacs) {
				r += `<br>${slave.slaveName} has been ${rule.aphrodisiacs > 0 ? `put on the proper` : `taken off`} aphrodisiacs.`;
				slave.aphrodisiacs = rule.aphrodisiacs;
			}
		}
	}

	function ProcessPenisHormones(slave, rule) {
		if ((slave.dick > 0)) {
			if ((slave.balls === 0)) {
				if ((rule.gelding !== undefined) && (rule.gelding !== "no default setting")) {
					if ((slave.hormones !== rule.gelding)) {
						const _oldHormones = slave.hormones;
						slave.hormones = rule.gelding;
						if (slave.indentureRestrictions >= 2) {
							slave.hormones = Math.clamp(slave.hormones, -1, 1);
						}
						if (slave.hormones != _oldHormones) {
							r += `<br>${slave.slaveName} is a gelding, so she has been put on the appropriate hormonal regime.`;
						}
					}
				}
			} else if ((slave.balls > 0)) {
				if ((rule.XY !== undefined) && (rule.XY !== "no default setting")) {
					if ((slave.hormones !== rule.XY)) {
						if ((slave.assignment != "recruit girls")) {
							if ((slave.assignment != "be the Wardeness")) {
								if ((slave.assignment != "be the Madam")) {
									const _oldHormones = slave.hormones;
									slave.hormones = rule.XY;
									if (slave.indentureRestrictions >= 2) {
										slave.hormones = Math.clamp(slave.hormones, -1, 1);
									}
									if (slave.hormones != _oldHormones) {
										r += `<br>${slave.slaveName} is a shemale, so she has been put on the appropriate hormonal regime.`;
									}
								}
							}
						}
					}
				}
			}
		}
	}

	function ProcessFemaleHormones(slave, rule) {
		if ((slave.vagina > -1) && (slave.dick === 0) && (rule.XX !== undefined) && (rule.XX !== "no default setting")) {
			if ((slave.hormones !== rule.XX)) {
				const _oldHormones = slave.hormones;
				slave.hormones = rule.XX;
				if (slave.indentureRestrictions >= 2) {
					slave.hormones = Math.clamp(slave.hormones, -1, 1);
				}
				if (slave.hormones != _oldHormones) {
					r += `<br>${slave.slaveName} is a female, so she has been put on the appropriate hormonal regime.`;
				}
			}
		}
	}

	function ProcessPregnancyDrugs(slave, rule) {
		if (slave.pregKnown == 1 && rule.pregSpeed != "no default setting" && slave.breedingMark != 1 && slave.indentureRestrictions < 1 && slave.broodmother === 0) {
			if (rule.pregSpeed == "slow" && slave.preg < 35) {
				slave.pregControl = "slow gestation";
				r += `<br>slave.slaveName is pregnant, so she has been put on the gestation slowing agents.`;
			} else if (rule.pregSpeed == "fast" && slave.preg < 35 && slave.health > -50) {
				slave.pregControl = "speed up";
				r += `<br>slave.slaveName is pregnant, so she has been put on rapid gestation  agents. CAUTION! Can be dangerous. Clinic supervision is recommended.`;
			} else if (rule.pregSpeed == "suppress" && slave.preg > 34 && slave.health > -50) {
				slave.pregControl = "labor supressors";
				r += `<br>slave.slaveName is ready to birth, so she has been put on labor suppressing agents.`;
			} else if (rule.pregSpeed == "stimulate" && slave.preg >= 37 && slave.health > -50) {
				slave.labor = 1;
				slave.induce = 1;
				V.birthee = 1;
				r += `<br>slave.slaveName is ready to birth, so her labor has been stimulated.`;
			} else if (rule.pregSpeed == "fast" && slave.pregControl == "speed up" && slave.health <= -50) {
				slave.pregControl = "none";
				r += `<br>slave.slaveName is on rapid gestation agents and dangerously unhealthy, so her agent regimen has been stopped.`;
			} else if (rule.pregSpeed == "suppress" && slave.pregControl == "labor supressors" && slave.health <= -50) {
				slave.pregControl = "none";
				r += `<br>slave.slaveName is on labor suppression agents and unhealthy, so her agent regimen has been stopped.`;
			}
		}
	}

	function ProcessLivingStandard(slave, rule) {
		if ((rule.livingRules !== undefined) && (rule.livingRules !== "no default setting")) {
			if (setup.facilityCareers.includes(slave.assignment)) {
				r += `<br>${slave.slaveName}'s living standards are controlled by her assignment.`;
			} else if (((slave.assignment == "be your Head Girl") && (V.HGSuite == 1)) || ((slave.assignment == "guard you") && (V.dojo > 1))) {
				r += `<br>${slave.slaveName} has a private room.`;
			} else if ((slave.fetish == "mindbroken")) {
				if ((slave.livingRules !== "spare")) {
					slave.livingRules = "spare";
					r += `<br>Since ${slave.slaveName} is mindbroken her living standard has been set to spare.`;
				}
			} else if (slave.livingRules !== rule.livingRules) {
				if (rule.livingRules !== "luxurious") {
					if (V.roomsPopulation <= V.rooms-0.5) {
						slave.livingRules = rule.livingRules;
						r += `<br>${slave.slaveName}'s living standard has been set to ${rule.livingRules}.`;
						if (slave.relationship >= 4)
							V.roomsPopulation += 0.5;
						else
							V.roomsPopulation += 1;
					} else {
						slave.livingRules = "normal";
						r += `<br>${slave.slaveName}'s living standard has been set to normal, since there is no room for her to occupy.`;
					}
				} else {
					slave.livingRules = rule.livingRules;
					r += `<br>${slave.slaveName}'s living standard has been set to ${rule.livingRules}.`;
				}
			}
		}
	}

	function ProcessSpeech(slave, rule) {
		if ((rule.speechRules !== undefined) && (rule.speechRules !== "no default setting")) {
			if ((slave.fetish == "mindbroken")) {
				if ((slave.speechRules !== "restrictive")) {
					slave.speechRules = "restrictive";
					r += `<br>Since ${slave.slaveName} is mindbroken her speech rules have been set to restrictive.`;
				}
			} else if ((slave.speechRules !== rule.speechRules)) {
				slave.speechRules = rule.speechRules;
				r += `<br>${slave.slaveName}'s speech rules have been set to ${rule.speechRules}.`;
			}
		}
	}

	function ProcessRelationship(slave, rule) {
		if ((slave.fetish !== "mindbroken")) {
			if ((rule.relationshipRules !== undefined) && (rule.relationshipRules !== "no default setting")) {
				if ((slave.relationshipRules !== rule.relationshipRules )) {
					slave.relationshipRules = rule.relationshipRules ;
					r += `<br>${slave.slaveName}'s relationship rules have been set to ${rule.relationshipRules}.`;
				}
			}
		}
	}

	function ProcessRelease(slave, rule) {
		if ((rule.releaseRules !== undefined) && (rule.releaseRules !== "no default setting")) {
			let _release = 0;
			if (rule.releaseRules === "restrictive" &&
				!(["serve the public", "serve in the club", "whore", "work in the brothel", "please you", "serve in the master suite", "be a subordinate slave", "work a glory hole", "be confined in the arcade", "get milked", "work in the dairy", "be your Head Girl"].contains(slave.assignment)))
				_release = 1;
			else
				_release = 1;
			if ((slave.fetish == "mindbroken") && (slave.releaseRules !== "permissive")) {
				slave.releaseRules = "permissive";
				r += `<br>Since ${slave.slaveName} is mindbroken her masturbation rules have been set to permissive.`;
			} else if ((slave.amp === 1 || slave.fuckdoll > 0) && (slave.releaseRules === "masturbation")) {
				slave.releaseRules = "restrictive";
				r += `<br>Since ${slave.slaveName} is unable to masturbate, her masturbation rules have been set to restrictive.`;
			} else if ((_release !== 0) && (slave.releaseRules !== rule.releaseRules)) {
				slave.releaseRules = rule.releaseRules;
				r += `<br>${slave.slaveName}'s masturbation rules have been set to ${rule.releaseRules}.`;
			}
		}
	}

	function ProcessPunishment(slave, rule) {
		if ((rule.standardPunishment !== undefined) && (rule.standardPunishment !== "no default setting")) {
			if ((slave.standardPunishment !== rule.standardPunishment)) {
				slave.standardPunishment = rule.standardPunishment ;
				r += `<br>${slave.slaveName}'s typical punishment has been updated to ${rule.standardPunishment}.`;
			}
		}
	}

	function ProcessReward(slave, rule) {
		if ((rule.standardReward !== undefined) && (rule.standardReward !== "no default setting")) {
			if ((slave.standardReward !== rule.standardReward)) {
				slave.standardReward = rule.standardReward ;
				r += `<br>${slave.slaveName}'s typical reward has been updated to ${rule.standardReward}.`;
			}
		}
	}

	function ProcessDietCum(slave, rule) {
		if ((rule.dietCum !== undefined) && (rule.dietCum !== "no default setting")) {
			if (slave.dietCum != rule.dietCum) {
				slave.dietCum = rule.dietCum;
				if (slave.dietCum == 2) {
					r += `<br>${slave.slaveName} has been put on a diet based on cum.`;
					slave.dietMilk = 0;
				}
				if (slave.dietCum == 1)
					r += `<br>${slave.slaveName} has had cum added to her diet.`;
				else
					r += `<br>${slave.slaveName} has had cum removed from her diet.`;
			}
		}
	}

	function ProcessDietMilk(slave, rule) {
		if ((rule.dietMilk !== undefined) && (rule.dietMilk !== "no default setting")) {
			if (slave.dietMilk != rule.dietMilk) {
				slave.dietMilk = rule.dietMilk;
				if (slave.dietMilk == 2) {
					r += `<br>${slave.slaveName} has been put on a diet based on human milk.`;
					slave.dietCum = 0;
				}
				if (slave.dietMilk == 1)
					r += `<br>${slave.slaveName} has had human milk added to her diet.`;
				else
					r += `<br>${slave.slaveName} has had human milk removed from her diet.`;
			}
		}
	}

	function ProcessTeeth(slave, rule) {
		if ((rule.teeth !== undefined) && (rule.teeth !== "no default setting")) {
			if ((rule.teeth == "universal")) {
				if ((slave.teeth == "crooked")) {
					slave.teeth = "straightening braces";
					V.cash -= V.surgeryCost;
					r += `<br>${slave.slaveName} has been given braces for her crooked teeth.`;
				} else if ((slave.teeth == "normal")) {
					slave.teeth = "cosmetic braces";
					V.cash -= V.surgeryCost;
					r += `<br>${slave.slaveName} has been given cosmetic braces.`;
				}
			} else if ((rule.teeth == "straighten")) {
				if ((slave.teeth == "crooked")) {
					slave.teeth = "straightening braces";
					V.cash -= V.surgeryCost;
					r += `<br>${slave.slaveName} has been given braces for her crooked teeth.`;
				} else if ((slave.teeth == "cosmetic braces")) {
					slave.teeth = "normal";
					r += `<br>${slave.slaveName} has gotten her braces off, since her teeth are straight.`;
				}
			} else if ((rule.teeth == "none")) {
				if ((slave.teeth == "straightening braces")) {
					slave.teeth = "crooked";
					r += `<br>${slave.slaveName} has gotten her braces off.`;
				} else if ((slave.teeth == "cosmetic braces")) {
					slave.teeth = "normal";
					r += `<br>${slave.slaveName} has gotten her braces off.`;
				}
			}
		}
	}

	function ProcessStyle(slave, rule) {
		if (rule.eyeColor !== undefined && (rule.eyeColor !== "no default setting")) {
			if ((slave.eyeColor !== rule.eyeColor)) {
				slave.eyeColor = rule.eyeColor;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName} has been given ${slave.eyeColor} contact lenses.`;
			}
		}

		if (rule.makeup !== undefined && (rule.makeup !== "no default setting")) {
			if ((slave.makeup !== rule.makeup)) {
				slave.makeup = rule.makeup;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName} has been assigned the standard makeup.`;
			}
		}

		if ((slave.amp != 1)) {
			if (rule.nails !== undefined && (rule.nails !== "no default setting")) {
				if ((slave.nails !== rule.nails)) {
					slave.nails = rule.nails;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName} has been assigned the standard nails.`;
				}
			}
		}

		if (rule.hColor !== undefined && (rule.hColor !== "no default setting")) {
			if (slave.bald != 1) {
				if ((slave.hColor !== rule.hColor)) {
					slave.hColor = rule.hColor;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s hair has been dyed ${rule.hColor}.`;
				}
			}
		}

		if (rule.hStyle !== undefined && (rule.hStyle !== "no default setting")) {
			if (slave.bald != 1) {
				if ((slave.hStyle !== rule.hStyle)) {
					slave.hStyle = rule.hStyle;
					V.cash -= V.modCost;
					if ((rule.hStyle == "shaved")) {
						slave.hLength = 0;
						r += `<br>${slave.slaveName}'s hair has been shaved.`;
					} else
						r += `<br>${slave.slaveName}'s hair has been restyled.`;
				}
			}
		}

		if (rule.hLength !== undefined && (rule.hLength !== "no default setting")) {
			if (slave.bald != 1) {
				if ((slave.hLength !== rule.hLength)) {
					if ((slave.hLength > rule.hLength)) {
						V.cash -= V.modCost;
						r += `<br>${slave.slaveName}'s hair has been cut; it `;
					} else {
						V.cash -= V.modCost*Math.trunc((rule.hLength-slave.hLength)/10);
						r += `<br>${slave.slaveName} has been given extensions; her hair `;
					}
				r += `is now rule.hLength cm long.`;
				slave.hLength = rule.hLength;
				}
			}
		}

		if (rule.pubicHColor !== undefined && (rule.pubicHColor !== "no default setting")) {
			if (slave.pubicHStyle != "bald" && slave.pubicHStyle != "hairless") {
				if ((slave.pubicHColor !== rule.pubicHColor)) {
					slave.pubicHColor = rule.pubicHColor;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s pubic hair, if present, has been dyed ${rule.pubicHColor}.`;
				}
			}
		}

		if (rule.pubicHStyle !== undefined && (rule.pubicHStyle !== "no default setting")) {
			if (slave.pubicHStyle != "bald" && slave.pubicHStyle != "hairless") {
				if ((slave.pubicHStyle !== rule.pubicHStyle)) {
					slave.pubicHStyle = rule.pubicHStyle;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s pubic hair has been restyled; it is now ${rule.pubicHStyle}.`;
				}
			}
		}

		if (rule.underArmHColor !== undefined && (rule.underArmHColor !== "no default setting")) {
			if (slave.underArmHStyle != "bald" && slave.underArmHStyle != "hairless") {
				if ((slave.underArmHColor !== rule.underArmHColor)) {
					slave.underArmHColor = rule.underArmHColor;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s underarm hair, if present, has been dyed ${rule.underArmHColor}.`;
				}
			}
		}

		if (rule.underArmHStyle !== undefined && (rule.underArmHStyle !== "no default setting")) {
			if (slave.underArmHStyle != "bald" && slave.underArmHStyle != "hairless") {
				if ((slave.underArmHStyle !== rule.underArmHStyle)) {
					slave.underArmHStyle = rule.underArmHStyle;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s underarm hair has been restyled; it is now ${rule.underArmHStyle}.`;
				}
			}
		}
	}

	function ProcessPiercings(slave, rule) {
		if (rule.nipplesPiercing !== undefined && (rule.nipplesPiercing !== "no default setting")) {
			if ((slave.nipplesPiercing !== rule.nipplesPiercing)) {
				if ((rule.nipplesPiercing === 0)) {
					slave.nipplesPiercing = 0;
					r += `<br>${slave.slaveName}'s nipple piercings have been removed.`;
				} else if (slave.nipples !== "fuckable") {
					slave.nipplesPiercing = rule.nipplesPiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s nipples have been pierced.`;
				} else {
					r += `<br>${slave.slaveName}'s nipples are inverted and cannot be pierced.`;
				}
			}
		}

		if (rule.areolaePiercing !== undefined && (rule.areolaePiercing !== "no default setting")) {
			if ((slave.areolaePiercing !== rule.areolaePiercing)) {
				if ((rule.areolaePiercing === 0)) {
					slave.areolaePiercing = 0;
					r += `<br>${slave.slaveName}'s areolae piercings have been removed.`;
				} else {
					slave.areolaePiercing = rule.areolaePiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s areolae have been given stud piercings.`;
				}
			}
		}

		if (rule.clitPiercing !== undefined && (rule.clitPiercing !== "no default setting")) {
			if ((slave.clitPiercing !== rule.clitPiercing)) {
				if ((rule.clitPiercing === 0)) {
					slave.clitPiercing = 0;
					if (slave.dick > 0)
						r += `<br>${slave.slaveName}'s frenulum piercing has been removed.`;
					else
						r += `<br>${slave.slaveName}'s clit piercing has been removed.`;

				} else if ((slave.vagina != -1) || (slave.dick !== 0)) {
					slave.clitPiercing = rule.clitPiercing;
					if (slave.dick > 0)
						r += `<br>${slave.slaveName}'s frenulum has been pierced.`;
					else
						r += `<br>${slave.slaveName}'s clit has been pierced.`;

					if (rule.clitPiercing == 3)
						V.cash -= 1000;
					else
						V.cash -= V.modCost;
				}
			}
		}

		if ((slave.vagina != -1)) {
			if (rule.vaginaPiercing !== undefined && (rule.vaginaPiercing !== "no default setting")) {
				if ((slave.vaginaPiercing !== rule.vaginaPiercing)) {
					if ((rule.vaginaPiercing === 0)) {
						slave.vaginaPiercing = 0;
						r += `<br>${slave.slaveName}'s labia piercings have been removed.`;
					} else {
						slave.vaginaPiercing = rule.vaginaPiercing;
						V.cash -= V.modCost;
						r += `<br>${slave.slaveName}'s pussylips have been pierced.`;
					}
				}
			}
		}

		if ((slave.dick > 0)) {
			if (rule.dickPiercing !== undefined && (rule.dickPiercing !== "no default setting")) {
				if ((slave.dickPiercing !== rule.dickPiercing)) {
					if ((rule.dickPiercing === 0)) {
						slave.dickPiercing = 0;
						r += `<br>${slave.slaveName}'s shaft piercings have been removed.`;
					} else {
						slave.dickPiercing = rule.dickPiercing;
						V.cash -= V.modCost;
						r += `<br>${slave.slaveName}'s shaft has been pierced.`;
					}
				}
			}
		}

		if (rule.anusPiercing !== undefined && (rule.anusPiercing !== "no default setting")) {
			if ((slave.anusPiercing !== rule.anusPiercing)) {
				if ((rule.anusPiercing === 0)) {
					slave.anusPiercing = 0;
					r += `<br>${slave.slaveName}'s asshole piercings have been removed.`;
				} else {
					slave.anusPiercing = rule.anusPiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s asshole has been pierced.`;
				}
			}
		}

		if (rule.lipsPiercing !== undefined && (rule.lipsPiercing !== "no default setting")) {
			if ((slave.lipsPiercing !== rule.lipsPiercing)) {
				if ((rule.lipsPiercing === 0)) {
					slave.lipsPiercing = 0;
					r += `<br>${slave.slaveName}'s lip piercings have been removed.`;
				} else {
					slave.lipsPiercing = rule.lipsPiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s lips have been pierced.`;
				}
			}
		}

		if (rule.tonguePiercing !== undefined && (rule.tonguePiercing !== "no default setting")) {
			if ((slave.tonguePiercing !== rule.tonguePiercing)) {
				if ((rule.tonguePiercing === 0)) {
					slave.tonguePiercing = 0;
					r += `<br>${slave.slaveName}'s tongue piercings have been removed.`;
				} else {
					slave.tonguePiercing = rule.tonguePiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s tongue has been pierced.`;
				}
			}
		}

		if (rule.earPiercing !== undefined && (rule.earPiercing !== "no default setting")) {
			if ((slave.earPiercing !== rule.earPiercing)) {
				if ((rule.earPiercing === 0)) {
					slave.earPiercing = 0;
					r += `<br>${slave.slaveName}'s ear piercings have been removed.`;
				} else {
					slave.earPiercing = rule.earPiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s ears have been pierced.`;
				}
			}
		}

		if (rule.nosePiercing !== undefined && (rule.nosePiercing !== "no default setting")) {
			if ((slave.nosePiercing !== rule.nosePiercing)) {
				if ((rule.nosePiercing === 0)) {
					slave.nosePiercing = 0;
					r += `<br>${slave.slaveName}'s nose piercing has been removed.`;
				} else {
					slave.nosePiercing = rule.nosePiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s nose has been pierced.`;
				}
			}
		}

		if (rule.eyebrowPiercing !== undefined && (rule.eyebrowPiercing !== "no default setting")) {
			if ((slave.eyebrowPiercing !== rule.eyebrowPiercing)) {
				if ((rule.eyebrowPiercing === 0)) {
					slave.eyebrowPiercing = 0;
					r += `<br>${slave.slaveName}'s eyebrow piercings have been removed.`;
				} else {
					slave.eyebrowPiercing = rule.eyebrowPiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s eyebrows have been pierced.`;
				}
			}
		}

		if (rule.navelPiercing !== undefined && (rule.navelPiercing !== "no default setting")) {
			if ((slave.navelPiercing !== rule.navelPiercing)) {
				if ((rule.navelPiercing === 0)) {
					slave.navelPiercing = 0;
					r += `<br>${slave.slaveName}'s navel piercing have been removed.`;
				} else {
					slave.navelPiercing = rule.navelPiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s navel has been pierced.`;
				}
			}
		}

		if (rule.corsetPiercing !== undefined && (rule.corsetPiercing !== "no default setting")) {
			if ((slave.corsetPiercing !== rule.corsetPiercing)) {
				if ((rule.corsetPiercing === 0)) {
					slave.corsetPiercing = 0;
					r += `<br>${slave.slaveName}'s corset piercings have been removed.`;
				} else {
					slave.corsetPiercing = rule.corsetPiercing;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName} has been given a set of corset piercings.`;
				}
			}
		}
	}

	function ProcessSmartPiercings(slave, rule) {
		if ((slave.clitPiercing == 3)) {
			let _used = 0;
			if (rule.clitSetting !== undefined && (rule.clitSetting !== "no default setting")) {
				if (slave.clitSetting !== rule.clitSetting) {
					slave.clitSetting = rule.clitSetting;
					_used = 1;
					r += `<br>${slave.slaveName}'s smart piercing has been set to ${slave.clitSetting}.`;
				} else if (slave.fetishStrength < 100) {
					_used = 1;
				}
			}
			if (_used === 0) {
				if (rule.clitSettingEnergy !== undefined && (rule.clitSettingEnergy !== "no default setting")) {
					if (slave.energy < rule.clitSettingEnergy) {
						if (slave.clitSetting !== "all") {
							r += `<br>${slave.slaveName}'s smart piercing has been set to enhance libido.`;
						}
						slave.clitSetting = "all";
						_used = 1;
					} else if (slave.energy >= rule.clitSettingEnergy + 10) {
						if (slave.clitSetting !== "none") {
							r += `<br>${slave.slaveName}'s smart piercing has been set to suppress libido.`;
						}
						slave.clitSetting = "none";
						_used = 1;
					}
				}
			}
			if (_used === 0) {
				if (rule.clitSettingXY !== undefined && (rule.clitSettingXY !== "no default setting")) {
					if (slave.attrXY < rule.clitSettingXY) {
						if (slave.clitSetting !== "men") {
							r += `<br>${slave.slaveName}'s smart piercing has been set to encourage attraction to men.`;
						}
						slave.clitSetting = "men";
						_used = 1;
					} else if (slave.attrXY >= rule.clitSettingXY + 10) {
						if (slave.clitSetting !== "anti-men") {
							r += `<br>${slave.slaveName}'s smart piercing has been set to discourage attraction to men.`;
						}
						slave.clitSetting = "anti-men";
						_used = 1;
					}
				}
			}
			if (_used === 0) {
				if (rule.clitSettingXX !== undefined && (rule.clitSettingXX !== "no default setting")) {
					if (slave.attrXX < rule.clitSettingXX) {
						if (slave.clitSetting !== "women") {
							r += `<br>${slave.slaveName}'s smart piercing has been set to encourage attraction to women.`;
						}
						slave.clitSetting = "women";
						_used = 1;
					} else if (slave.attrXX >= rule.clitSettingXX + 10) {
						if (slave.clitSetting !== "anti-women") {
							r += `<br>${slave.slaveName}'s smart piercing has been set to discourage attraction to women.`;
						}
						slave.clitSetting = "anti-women";
						_used = 1;
					}
				}
			}
		}
	}

	function ProcessTattoos(slave, rule) {
		if (rule.boobsTat !== undefined && (rule.boobsTat !== "no default setting")) {
			if ((slave.boobsTat !== rule.boobsTat)) {
				slave.boobsTat = rule.boobsTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s chest has been tattooed.`;
			}
		}

		if (rule.buttTat !== undefined && (rule.buttTat !== "no default setting")) {
			if ((slave.buttTat !== rule.buttTat)) {
				slave.buttTat = rule.buttTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s butt has been tattooed.`;
			}
		}

		if (rule.vaginaTat !== undefined && (rule.vaginaTat !== "no default setting")) {
			if ((slave.vaginaTat !== rule.vaginaTat)) {
				slave.vaginaTat = rule.vaginaTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s abdomen has been tattooed.`;
			}
		}

		if ((slave.dick > 0)) {
			if (rule.dickTat !== undefined && (rule.dickTat !== "no default setting")) {
				if ((slave.dickTat !== rule.dickTat)) {
					slave.dickTat = rule.dickTat;
					V.cash -= V.modCost;
					r += `<br>${slave.slaveName}'s dick has been tattooed.`;
				}
			}
		}

		if (rule.lipsTat !== undefined && (rule.lipsTat !== "no default setting")) {
			if ((slave.lipsTat !== rule.lipsTat)) {
				slave.lipsTat = rule.lipsTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s face has been tattooed.`;
			}
		}

		if (rule.anusTat !== undefined && (rule.anusTat !== "no default setting")) {
			if ((slave.anusTat !== rule.anusTat)) {
				slave.anusTat = rule.anusTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s asshole has been modded.`;
			}
		}

		if (rule.shouldersTat !== undefined && (rule.shouldersTat !== "no default setting")) {
			if ((slave.shouldersTat !== rule.shouldersTat)) {
				slave.shouldersTat = rule.shouldersTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s shoulders have been tattooed.`;
			}
		}

		if (rule.armsTat !== undefined && (rule.armsTat !== "no default setting")) {
			if ((slave.armsTat !== rule.armsTat)) {
				slave.armsTat = rule.armsTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s arms have been tattooed.`;
			}
		}

		if (rule.legsTat !== undefined && (rule.legsTat !== "no default setting")) {
			if ((slave.legsTat !== rule.legsTat)) {
				slave.legsTat = rule.legsTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s legs have been tattooed.`;
			}
		}

		if (rule.stampTat !== undefined && (rule.stampTat !== "no default setting")) {
			if ((slave.stampTat !== rule.stampTat)) {
				slave.stampTat = rule.stampTat;
				V.cash -= V.modCost;
				r += `<br>${slave.slaveName}'s lower back has been tattooed.`;
			}
		}
		if ((rule.autoBrand == 1)) {
			if ((slave.brand === 0)) {
				if ((slave.health > -20)) {
					slave.brand = V.brandDesign;
					slave.brandLocation = V.brandTarget;
					if ((slave.devotion < 18))
						slave.devotion -= 5;
					slave.trust -= 5;
					slave.health -= 10;
					r += `<br>${slave.slaveName} has been branded, with <span class="gold">fear</span>${slave.devotion < 18? `, <span class="mediumorchid">regard,</span>`:``} and <span class="red">health</span> consequences.`;
				}
			}
		}
	}

	function ProcessPorn(slave, rule) {
		if ((rule.pornFameSpending !== undefined) && (rule.pornFameSpending !== "no default setting")) {
			if ((slave.prestige < 3)) {
				if ((slave.pornFameSpending !== rule.pornFameSpending)) {
					slave.pornFameSpending = rule.pornFameSpending;
					r += `<br>${slave.slaveName}'s porn publicity has been corrected.`;
				}
			}
		}
	}

	return DefaultRules;
})();


code:
:: SFJS [script]

window.simpleWorldEconomyCheck = function() {
	var n1 = 4;
	var n2 = 3;
	var n3 = 2;
	if(State.variables.economy === .5) {
		return n1;
	} else if(State.variables.economy === 1.5) {
		return n3;
	} else {
		return n2;
	}
}

window.HSM = function() {
	if (State.variables.PC.hacking <= -100)
		return 1.5;
	else if (State.variables.PC.hacking <= -75)
		return 1.35;
	else if (State.variables.PC.hacking <= -50)
		return 1.25;
	else if (State.variables.PC.hacking <= -25)
		return 1.15;
	else if (State.variables.PC.hacking < 0)
		return 1.10;
	else if (State.variables.PC.hacking === 0)
		return 1;
	else if (State.variables.PC.hacking <= 10)
		return .97;
	else if (State.variables.PC.hacking <= 25)
		return .95;
	else if (State.variables.PC.hacking <= 50)
		return .90;
	else if (State.variables.PC.hacking <= 75)
		return .85;
	else if (State.variables.PC.hacking < 100)
		return .80;
	else if (State.variables.PC.hacking >= 100)
		return .75;
	}

repo_name: Akane/fc


code:
:: SetBellySize [script]

window.SetBellySize = function SetBellySize(slave) {
	let _implantSize
	WombNormalizePreg(slave) /*now with support for legacy code that advance pregnancy by setting .preg++ */

	if (slave.bellyImplant > 0)
		_implantSize = slave.bellyImplant
	else
		_implantSize = 0

	if (slave.inflation == 3)
		slave.bellyFluid = 10000
	else if (slave.inflation == 2)
		slave.bellyFluid = 5000
	else if (slave.inflation == 1)
		slave.bellyFluid = 2000
	else
		slave.bellyFluid = 0

	slave.belly = slave.bellyPreg+slave.bellyFluid+_implantSize
}


code:
:: accordionJS.tw [script]
/* Accordion 000-250-006 */

/*
 * We're making changes to the DOM, so we need to make them *after* everything has been generated
 * Sticking this all in postdisplay calls reduces the chance of there being a timing conflict
 *   with other scripts, since anything poking the DOM here will be done last
 *
 * Dev Note: The accordion mod should be able to turn *anything* into an accordion. This iteration
 *   is configured tightly for the end of week report runs, but it shouldn't be that hard to adapt for
 *   other uses, like character bios. For now, I'll see what other extra-long passages of cosmetic text
 *   might benefit.
 *
 * 000-250-006 03092017
*/

postdisplay["doAccordionSet"] = function (content) {
    if (variables().useAccordion == 1) {
        Array.prototype.slice.call(document.querySelectorAll('.macro-include'))
        .forEach(function(element) {
            element.classList.add('accHidden');
        });
    }
}

postdisplay["doAccordion"] = function (content) {
    var acc = document.getElementsByClassName("accordion");
    var i;

    for (i = 0; i < acc.length; i += 1) {
        acc[i].onclick = function () {
            this.classList.toggle("active");
            var panel = this.nextElementSibling;
            if (panel.style.maxHeight) {
                panel.style.maxHeight = null;
            } else {
                panel.style.maxHeight = 2*panel.scrollHeight + "px";
            }
        };
    }
};


code:
:: 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.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.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.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 };
};