code:
:: Nursery [nobr jump-to-safe jump-from-safe]

<<set $nextButton = "Back to Main", $nextLink = "Main", $returnTo = "Nursery", $encyclopedia = "Nursery">>
<<set $targetAgeNursery = Number($targetAgeNursery) || $minimumSlaveAge>>
<<set $targetAgeNursery = Math.clamp($targetAgeNursery, $minimumSlaveAge, 42)>>

<<set $nurseryChildren = $cribs.length, _freecribs = $nursery - $nurseryChildren, _NL = App.Entity.facilities.nursery.employeesIDs().size, _SL = $slaves.length, _eligibility = 0, _reservedChildren = FetusGlobalReserveCount("incubator"), _reservedChildrenNursery = FetusGlobalReserveCount("nursery")>>

	<<set _nurseryNameCaps = capFirstChar($nurseryName)>>
	_nurseryNameCaps
	<<switch $nurseryDecoration>>
		<<case "Roman Revivalist">>
			is run with the Roman dream in mind, with wide open windows exposing the babies to the elements. The sleek marble halls bring a sense of serenity and duty as wet nurses wander the halls.
		<<case "Neo Imperialist">>
			is modeled as an ultra high-tech nursing area, with omnipresent advanced machinery monitoring every heartbeat of the babies within, the soft glow of machines pulsating against the banners of your family crest lining the walls.
		<<case "Aztec Revivalist">>
			is lined head to toe in illustrious Aztec gold. Tiny but notable subscripts lay in plaques to honor the mothers who died giving birth, the children of said mothers, alive or dead, are tirelessly watched over to tend to their every need.
		<<case "Egyptian Revivalist">>
			is decorated by sleek, sandstone tablets, golden statues, and even grander Egyptian wall sculptures, many of them depicting the conception, birth, and raising of a child. Each babe is reverently wrapped in linen covers as they drift to sleep to the stories of mighty pharaohs and prosperous palaces.
		<<case "Edo Revivalist">>
			is minimalistic in nature, but the errant paintings of cherry blossoms and vibrant Japanese maples give a certain peaceful air as the caretakers do their duties.
		<<case "Arabian Revivalist">>
			is decorated wall to wall with splendorous carvings and religious Hamsas meant to protect the fostering children.
		<<case "Chinese Revivalist">>
			is ripe with Chinese spirit. Depictions of colorful dragons and oriental designs grace the halls, rooms, and cribs of the babies who reside inside.
		<<case "Chattel Religionist">>
			is decorated with childish religious cartoons and artistic tapestries of slaves bowing in submission, their themes always subsiding varying degrees of sexual worship. The caretakers that wander the halls obediently wear their habits, and never waste a moment to tenderly lull the children to sleep with stories of their prophet.
		<<case "Degradationist">>
			is bare and sullen. The cries of the neglected children destined for slavery trying to find comfort in their burlap coverings echo the halls, while those that await freedom are raised among luxury and are taught to look down on their less fortunate peers.
		<<case "Repopulation Focus">>
			is designed to be very open and public; a showing testament to your arcology's repopulation efforts. For those old enough to support them, they are strapped with big, but body warming, empathy bellies as to remind them of their destiny.
		<<case "Eugenics">>
			is of utmost quality without a single pleasantry missing — if the parents are of the elite blood of course. While there are rare stragglers of unworthy genes, the child populace overall is pampered with warm rooms and plentiful small toys.
		<<case "Asset Expansionist">>
			is not so much decorated as it is intelligently staffed. Every passerby, slave or not, burns the image of their jiggling asses and huge, wobbling tits into the minds of the children.
		<<case "Transformation Fetishist">>
			is kept simple and clean. From their toys down to the nursemaids, the babies are exposed to the wonders of body transformation whenever possible.
		<<case "Gender Radicalist">>
			is decorated by cheery cartoon depictions of slaves of many shapes, sizes, and genitals, all of them undeniably feminine. The elated smiles and yips of the nurses getting reamed constantly instill the appreciation of nice, pliable buttholes.
		<<case "Gender Fundamentalist">>
			is simply designed and painted with soft feminine colors. The staff heavily encourage the children to play dress up and house, subtly sculpting their minds to proper gender norms and properly put them in line if they try to do otherwise.
		<<case "Physical Idealist">>
			is furnished with kiddy health books and posters; their caretakers making painstakingly sure that the importance is drilled into their heads at a young age. Their food is often littered with vitamins and supplements to keep the children growing strong.
		<<case "Supremacist">>
			is designed and structured to give those of $arcologies[0].FSSupremacistRace ethnicity the limelight of the nursery, while the others stay sectioned off and neglected to the world.
		<<case "Subjugationist">>
			is made to foster and raise the young children of $arcologies[0].FSSubjugationistRace ethnicity. They are reminded of their place with every failure and are encouraged to submissively follow their stereotypes at a ripe young age.
		<<case "Paternalist">>
			is well-stocked and by Paternalistic customs, constantly swaddle the children with love and attention. With the warm colors and sound of child laughter, to the untrained eye, the children actually seem free.
		<<case "Pastoralist">>
			is decorated to make the children grow up thinking that a life focused on breast milk, cum, and other human secretions are part of the norm. The milky tits swaying above their cow-patterned cribs certainly help with that.
		<<case "Maturity Preferentialist">>
			decorations remind the kids to respect those curvy and mature. The older nurserymaids are always flattered whenever the children try to act like adults and take care of the younger toddlers for them.
		<<case "Youth Preferentialist">>
			is making young children the center of attention, their rooms supplied with plenty of toys, blankets, and surrogate mothers at their beck and call.
		<<case "Body Purist">>
			is decorated to be very clean cut and sterilized with perfect corners and curves; symbolic of the human figure. Nursery maids are encouraged to show off their natural assets to show the children what the appropriate body should be.
		<<case "Slimness Enthusiast">>
			constantly encourages the kids to try and keep their slim and cute physiques. They are given perfectly metered meals to make this possible.	/* TODO: tie this in to food system */
		<<case "Hedonistic">>
			would make any toddler drool in amazement. Meals and naps every other hour, cribs stalked with toys and blankets, and plush slaves carry them to and fro without preamble. A delicious layer of baby fat is the ideal figure of a baby, and they couldn't be happier.
		<<case "Intellectual Dependency">>
			/* TODO: */
		<<case "Slave Professionalism">>
			/* TODO: */
		<<case "Petite Admiration">>
			has large photos and paintings on the walls depicting small, petite children enjoying $nurseryName's amenities and having fun together.
		<<case "Statuesque Glorification">>
			has large photos and paintings on the walls depicting tall children enjoying $nurseryName's amenities and having fun together.	/* TODO: rewrite so it's not so similar? */
		<<default>>
			is as comfortable and child-friendly as it needs to be. They have everything they need to grow into a proper slave.
	<</switch>>

	<<if $MatronID>>
		<<setLocalPronouns _S.Matron>>
	<</if>>

	<<if _NL > 2>>
		_nurseryNameCaps is bustling with activity. Nannies are busily moving about, feeding babies and changing diapers.
	<<elseif _NL > 0>>
		_nurseryNameCaps is working steadily. Nannies are moving about, cleaning up and feeding hungry children.
		<<set $nannyInfluence = 1>>
	<<elseif $MatronID>>
		_S.Matron.slaveName is alone in $nurseryName, and keeps the place clean and looks after the children $himself.
	<<elseif (_NL <= 0) && ($nurseryChildren <= 0)>>
		_nurseryNameCaps is empty and quiet.

			<<link "Decommission the Nursery" "Main">>
				<<set $nursery = 0, $nurseryNannies = 0, $nannyInfluence = 0, $nurseryDecoration = "standard", $cribs = [], _reservedChildrenNursery = 0>>
				<<for _i = 0; _i < $slaves.length; _i++>>
					<<run WombCleanGenericReserve($slaves[_i], "nursery", 9999)>>
				<</for>>
			<</link>>

	<</if>>

	/* <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'nannies')" id="tab nannies">Nannies</button> */
	<button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'pregnant-slaves')" id="tab pregnant-slaves">Pregnant Slaves</button>
	<button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'children')" id="tab children">Children</button>

/*

	*/
		<<set _Tmult0 = Math.trunc($nurseryNannies*1000*$upgradeMultiplierArcology)>>

It can support $nurseryNannies <<if $nurseryNannies != 1>>nannies<<else>>nanny<</if>>.
		There <<if _NL == 1>>is<<else>>are<</if>> _NL <<if _NL != 1>>nannies<<else>>nanny<</if>> in $nurseryName.
		<<if $nurseryChildren > 0 && _NL < 1 && (!_S.Matron)>>

				You must have a Matron or at least one nanny to be able to influence the children's upbringing

		<</if>>
		<<if $nurseryNannies < 5>>

				[[Expand the nursery|Nursery][cashX(forceNeg(_Tmult0), "capEx"), $nurseryNannies += 1, $PC.skill.engineering += .1]]

					Costs <<print cashFormat(_Tmult0)>> and will increase upkeep costs

		<<else>>

				_nurseryNameCaps can support a maximum of 5 slaves

		<</if>>

			<<if _NL > 0>>
				<<includeDOM removeFacilityWorkers("nursery", "rest", "rest")>>
			<</if>>

			<<if _S.Matron>>
				<<if $MatronIgnoresFlaws != 1>>
					_S.Matron.slaveName will attempt to fix flaws in nannies serving under $him.

						[[Ignore flaws|Nursery][$MatronIgnoresFlaws = 1]]

				<<else>>
					_S.Matron.slaveName has been instructed to ignore flaws in the nannies serving under $him.

						[[Fix flaws|Nursery][$MatronIgnoresFlaws = 0]]

				<</if>>
			<</if>>

			<<includeDOM App.UI.SlaveList.stdFacilityPage(App.Entity.facilities.nursery)>>

		/*

*/

		Reserve an eligible mother-to-be's child to be placed in a room upon birth. Of $nursery rooms, <<print _freecribs>> <<if _freecribs == 1>>is<<else>>are<</if>> unoccupied. Of those, _reservedChildrenNursery room<<if _reservedChildrenNursery == 1>> is<<else>>s are<</if>> reserved.

		<<if (0 < _SL)>>
			<<set $sortNurseryList = $sortNurseryList || 'Unsorted'>>

				Sorting:

			''$sortNurseryList.''
			<<link "Sort by Name">>
				<<set $sortNurseryList = 'Name'>>
				<<replace "#ql-nursery-sort">>$sortNurseryList<</replace>>
				<>
			<</link>> |
			<<link "Sort by Reserved Nursery Spots">>
				<<set $sortNurseryList = 'Reserved Nursery Spots'>>
				<<replace "#ql-nursery-sort">>$sortNurseryList<</replace>>
				<>
			<</link>> |
			<<link "Sort by Pregnancy Week">>
				<<set $sortNurseryList = 'Pregnancy Week'>>
				<<replace "#ql-nursery-sort">>$sortNurseryList<</replace>>
				<>
			<</link>> |
			<<link "Sort by Number of Children">>
				<<set $sortNurseryList = 'Number of Children'>>
				<<replace "#ql-nursery-sort">>$sortNurseryList<</replace>>
				<>
			<</link>>

		<</if>>

			<<for _u = 0; _u < _SL; _u++>>
				<<setLocalPronouns $slaves[_u]>>
				<<if $slaves[_u].preg > 0 && $slaves[_u].broodmother == 0 && $slaves[_u].pregKnown == 1 && $slaves[_u].eggType == "human">>
					<<if $slaves[_u].assignment == "work in the dairy" && $dairyPregSetting > 0>>
					<<else>>
						<<set _slaveId = "slave-" + $slaves[_u].ID>>
						<<set _WL = $slaves[_u].womb.length>>
						<<set _reservedNursery = WombReserveCount($slaves[_u], "nursery")>>
						<<set _reservedIncubator = WombReserveCount($slaves[_u], "incubator")>>
						<<set _pregWeek = $slaves[_u].pregWeek>>
						<<set _slaveName = SlaveFullName($slaves[_u])>>

						<<print "[[_slaveName|Slave Interact][$AS = $slaves[" + _u + "].ID, $nextLink = passage()]]">> is <<= numberWithPluralOne($slaves[_u].pregWeek, "week")>> pregnant with
						<<if $slaves[_u].pregSource == 0 || $slaves[_u].preg <= 5>>someone's<<if $slaves[_u].preg <= 5>>, though it is too early to tell whose,<</if>>
						<<elseif $slaves[_u].pregSource == -1>>your
						<<elseif $slaves[_u].pregSource == -2>>a citizen's
						<<elseif $slaves[_u].pregSource == -3>>your Master's
						<<elseif $slaves[_u].pregSource == -4>>another arcology owner's
						<<elseif $slaves[_u].pregSource == -5>>your client's
						<<elseif $slaves[_u].pregSource == -6>>the Societal Elite's
						<<elseif $slaves[_u].pregSource == -7>>the lab's
						<<elseif $slaves[_u].pregSource == -9>>the Futanari Sisters'
						<<else>>
							<<set _t = $slaveIndices[$slaves[_u].pregSource]>>
							<<if def _t>>
								<<print $slaves[_t].slaveName>>'s
							<</if>>
						<</if>>
						<<if _WL > 1>>_WL babies<<else>>baby<</if>>.
						<<if _reservedNursery > 0>>
							<<set _childrenReservedNursery = 1>>
							<<if _WL == 1>>
								$His child will be placed in $nurseryName.
							<<elseif _reservedNursery < _WL>>
								_reservedNursery of $his children will be placed in $nurseryName.
							<<elseif _WL == 2>>
								Both of $his children will be placed in $nurseryName.
							<<else>>
								All _reservedNursery of $his children will be placed in $nurseryName.
							<</if>>
							<<if (_reservedIncubator + _reservedNursery < _WL) && (_reservedChildrenNursery < _freecribs)>>

								<<print "[[Keep another child|Nursery][WombAddToGenericReserve($slaves[" + _u + "], 'nursery', 1)]]">>
								<<if _reservedNursery > 0>>
									| <<print "[[Keep one less child|Nursery][WombCleanGenericReserve($slaves[" + _u + "], 'nursery', 1)]]">>
								<</if>>
								<<if _reservedNursery > 1>>
									| <<print "[[Keep none of " + $his + " children|Nursery][WombCleanGenericReserve($slaves[" + _u + "], 'nursery', 9999)]]">>
								<</if>>
								<<if (_reservedChildrenNursery + _WL - _reservedNursery) <= _freecribs>>
									| <<print "[[Keep the rest of " + $his + " children|Nursery][WombAddToGenericReserve($slaves[" + _u + "], 'nursery', 9999)]]">>
								<</if>>
							<<elseif (_reservedNursery == _WL) || (_reservedChildrenNursery == _freecribs) || (_reservedIncubator + _reservedNursery == _WL)>>

								<<print "[[Keep one less child|Nursery][WombCleanGenericReserve($slaves[" + _u + "], 'nursery', 1)]]">>
								<<if _reservedNursery > 1>>
									| <<print "[[Keep none of " + $his + " children|Nursery][WombCleanGenericReserve($slaves[" + _u + "], 'nursery', 9999)]]">>
								<</if>>
							<</if>>
						<<elseif (_reservedChildrenNursery < _freecribs) && (_freecribs > _WL)>>
							<<if _WL - _reservedIncubator == 0>>

									$His children are already reserved for $incubatorName

								<<print "[[Keep " + $his + " " + ((_WL > 1) ? "children" : "child") + " here instead|Nursery][WombChangeReserveType($slaves[" + _u + "], 'incubator', 'nursery')]]">>
							<<else>>
								You have <<if _freecribs == 1>>an<</if>> @@.lime;available room<<if _freecribs > 1>>s<</if>>.@@

								<<print "[[Keep "+ ((_WL > 1) ? "a" : "the") +" child|Nursery][WombAddToGenericReserve($slaves[" + _u + "], 'nursery', 1)]]">>
								<<if (_WL > 1) && (_reservedChildrenNursery + _WL - _reservedNursery) <= _freecribs>>
									| <<print "[[Keep all of " + $his + " children|Nursery][WombAddToGenericReserve($slaves[" + _u + "], 'nursery', 9999)]]">>
								<</if>>
							<</if>>
						<<elseif _reservedChildrenNursery == _freecribs>>

							You have @@.red;no room for $his offspring.@@
						<</if>>
						<<set _eligibility = 1>>

					<</if>>
				<</if>>
			<</for>>

		<>

			Target age for release: <<textbox "$targetAgeNursery" $targetAgeNursery "Nursery">>
			[[Minimum Legal Age|Nursery][$targetAgeNursery = $minimumSlaveAge]] |
			[[Average Age of Fertility|Nursery][$targetAgeNursery = $fertilityAge]] |
			[[Average Age of Potency|Nursery][$targetAgeNursery = $potencyAge]] |
			[[Legal Adulthood|Nursery][$targetAgeNursery = 18]]

				Setting will not be applied to rooms in use.

		It can support $nursery child<<if $nursery != 1>>ren<</if>>. There <<if $nurseryChildren == 1>>is<<else>>are<</if>> currently $nurseryChildren room<<if $nurseryChildren != 1>>s<</if>> in use in $nurseryName.
		<<if $nursery < 50>>

				[[Add another room|Nursery][cashX(forceNeg(Math.trunc(5000*$upgradeMultiplierArcology)), "nursery"), $nursery += 5]]

					Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology))>> and will increase upkeep costs

				<<if _freecribs == 0>>
					All of the rooms are currently occupied by growing children.
				<</if>>

		<<else>>

				_nurseryNameCaps can support a maximum of 50 children

		<</if>>

		<<if $nursery > 1 && _reservedChildrenNursery < _freecribs>>

				[[Remove a room|Nursery][cashX(forceNeg(Math.trunc(1000*$upgradeMultiplierArcology)), "nursery"), $nursery -= 5]]

					Costs <<print cashFormat(Math.trunc(1000*$upgradeMultiplierArcology))>> and will reduce upkeep costs

		<</if>>

Rules

		<<if $extremeUnderage>>
			<<if $nurserySex>>
				_nurseryNameCaps staff are ''allowed'' to molest the children. [[Forbid|Nursery][$nurserySex = 0]]
			<<else>>
				_nurseryNameCaps staff are ''not allowed'' to molest the children. [[Allow|Nursery][$nurserySex = 1]]
			<</if>>
		<</if>>

		<<if $nurseryWeight>>
			<<if $nurseryWeightSetting>>
				Food intake ''is'' being managed; children will be raised at a healthy weight.
				[[End managing|Nursery][$nurseryWeightSetting = 0]]
			<<else>>
				Food intake ''is not'' being managed; children may end up malnourished.
				[[Begin managing|Nursery][$nurseryWeightSetting = 1]]
			<</if>>
		<<else>>
			The amount of food the children eat ''is not'' being monitored, meaning they may end up becoming malnourished.
			[[Monitor the amount of food the children eat|Nursery][cashX(forceNeg(Math.trunc(1000*$upgradeMultiplierArcology)), "nursery"), $nurseryWeight = 1]]

				Requires a Matron or at least one nanny and costs <<print cashFormat(Math.trunc(1000*$upgradeMultiplierArcology))>> and will increase upkeep costs

		<</if>>

		<<if $nurseryMuscles>>
			<<if $nurseryMusclesSetting>>
				Exercise ''is'' being managed; children will be raised with average fitness.
				[[End managing|Nursery][$nurseryMusclesSetting = 0]]
			<<else>>
				Children ''are not'' getting any exercise; they may end up quite weak and frail.
				[[Begin managing|Nursery][$nurseryMusclesSetting = 1]]
			<</if>>
		<<else>>
			The children ''are not'' getting any exercise, meaning they will likely end up becoming fairly weak and frail.
			[[Allow the children to remain active|Nursery][cashX(forceNeg(Math.trunc(1000*$upgradeMultiplierArcology)), "nursery"), $nurseryMuscles = 1]]

				Requires a Matron or at least one nanny and costs <<print cashFormat(Math.trunc(1000*$upgradeMultiplierArcology))>> and will increase upkeep costs

		<</if>>

		<<if $nurseryUpgradeHormones>>
			<<if $nurseryHormonesSetting>>
				Artificial hormone levels ''are'' being managed; children may experience precocious puberty.
				[[Disable|Nursery][$nurseryHormonesSetting = 0]]
			<<else>>
				Artificial hormones ''are not'' being given; children will undergo normal puberty.
				[[Activate|Nursery][$nurseryHormonesSetting = 1]]
			<</if>>
		<<else>>
			The children ''are not'' being given any artificial hormones.
			[[Give the children growth hormones|Nursery][cashX(forceNeg(Math.trunc(1000*$upgradeMultiplierArcology)), "nursery"), $nurseryUpgradeHormones = 1, $nurseryHormonesSetting = 0]]

				Requires a Matron or at least one nanny and costs <<print cashFormat(Math.trunc(1000*$upgradeMultiplierArcology))>> and will increase upkeep costs

		<</if>>

		<<includeDOM App.Facilities.Nursery.childList()>>

	Rename $nurseryName: <<textbox "$nurseryName" $nurseryName "Nursery">>

		Use a noun or similar short phrase

<<run App.UI.SlaveList.ScrollPosition.restore()>>


code:
App.Facilities.Nursery.ChildDatatypeCleanup = function(child) {
	childAgeDatatypeCleanup(child);
	childPhysicalDatatypeCleanup(child);
	childFaceDatatypeCleanup(child);
	childHairDatatypeCleanup(child);
	childBoobsDatatypeCleanup(child);
	childButtDatatypeCleanup(child);
	childPregnancyDatatypeCleanup(child);
	childBellyDatatypeCleanup(child);
	childGenitaliaDatatypeCleanup(child);
	childImplantsDatatypeCleanup(child);
	childPiercingsDatatypeCleanup(child);
	childTattooDatatypeCleanup(child);
	childCosmeticsDatatypeCleanup(child);
	childDietDatatypeCleanup(child);
	childPornDatatypeCleanup(child);
	childRelationDatatypeCleanup(child);
	childSkillsDatatypeCleanup(child);
	childStatCountDatatypeCleanup(child);
	childPreferencesDatatypeCleanup(child);
	childRulesDatatypeCleanup(child);
	childCustomStatsDatatypeCleanup(child);
	childMiscellaneousDatatypeCleanup(child);
	generatePronouns(child);

	function childAgeDatatypeCleanup(child) {

		child.birthWeek = Math.clamp(+child.birthWeek, 0, 51) || 0;
		if (child.age > 0) {
			child.actualAge = Math.clamp(+child.actualAge, V.minimumChildAge, Infinity) || child.age; /* if undefined, this sets to child.age */
			delete child.age;
		} else {
			child.actualAge = Math.clamp(+child.actualAge, V.minimumChildAge, Infinity) || 3;
		}
		child.visualAge = Math.max(+child.visualAge, 0) || child.actualAge;
		child.physicalAge = Math.max(+child.physicalAge, 0) || child.actualAge;
		child.ovaryAge = Math.max(+child.ovaryAge, 0) || child.physicalAge;
		child.pubertyAgeXX = Math.max(+child.pubertyAgeXX, 0) || V.fertilityAge;
		child.pubertyAgeXY = Math.max(+child.pubertyAgeXY, 0) || V.potencyAge;
	}

	function childPhysicalDatatypeCleanup(child) {
		if (typeof child.nationality !== "string") {
			child.nationality = "child";
		}
		if (typeof child.race !== "string") {
			nationalityToRace(child);
		}
		if (typeof child.origRace !== "string") {
			child.origRace = child.race;
		}
		if (typeof child.skin !== "string") {
			child.skin = "light";
		}
		if (typeof child.origSkin !== "string") {
			child.origSkin = child.skin;
		}
		if (typeof child.minorInjury !== "string") {
			child.minorInjury = 0;
		}
		if (typeof child.health === "number") {
			const condition = child.health;
			child.health = {};
			child.health.condition = condition;
		}
		child.health.condition = Math.clamp(+child.health.condition, -100, 100) || 0;
		child.health.shortDamage = Math.max(+child.health.shortDamage, 0) || 0;
		child.health.longDamage = Math.max(+child.health.longDamage, 0) || 0;
		child.health.illness = Math.max(+child.health.illness, 0) || 0;
		child.health.tired = Math.clamp(+child.health.tired, 0, 100) || 0;
		child.muscles = Math.clamp(+child.muscles, -100, 100) || 0;
		child.weight = Math.clamp(+child.weight, -100, 200) || 0;
		child.waist = Math.clamp(+child.waist, -100, 100) || 0;
		child.height = Math.round(Math.max(+child.height, 0)) || Math.round(Height.mean(child));
		child.shoulders = Math.clamp(+child.shoulders, -2, 2) || 0;
		child.hips = Math.clamp(+child.hips, -2, 3) || 0;
	}

	function childFaceDatatypeCleanup(child) {
		child.face = Math.clamp(+child.face, -100, 100) || 0;
		if (typeof child.faceShape !== "string") {
			child.faceShape = "normal";
		}
		if (child.lips !== 0) {
			child.lips = Math.clamp(+child.lips, 0, 100) || 15;
		}
	}

	function childHairDatatypeCleanup(child) {
		if (typeof child.hColor !== "string") {
			child.hColor = "brown";
		}
		if (typeof child.origHColor !== "string") {
			child.origHColor = child.hColor;
		}
		if (child.hLength !== 0) {
			child.hLength = Math.clamp(+child.hLength, 0, 300) || 60;
		}
		if (typeof child.hStyle !== "string") {
			child.hStyle = "long";
		}
		child.haircuts = Math.clamp(+child.haircuts, 0, 1) || 0;
		child.bald = Math.clamp(+child.bald, 0, 1) || 0;
		if (typeof child.pubicHColor !== "string") {
			child.pubicHColor = child.hColor;
		}
		if (typeof child.pubicHStyle !== "string") {
			child.pubicHStyle = "neat";
		}
		if (typeof child.underArmHColor !== "string") {
			child.underArmHColor = child.hColor;
		}
		if (typeof child.underArmHStyle !== "string") {
			child.underArmHStyle = "waxed";
		}
		if (typeof child.eyebrowHColor !== "string") {
			child.eyebrowHColor = child.hColor;
		}
		if (typeof child.eyebrowHStyle !== "string") {
			child.eyebrowHStyle = "natural";
		}
		if (typeof child.eyebrowFullness !== "string") {
			child.eyebrowFullness = "natural";
		}
	}

	function childBoobsDatatypeCleanup(child) {
		child.boobs = Math.max(+child.boobs, 100) || 200;
		if (typeof child.boobShape !== "string") {
			child.boobShape = "normal";
		}
		if (typeof child.nipples !== "string") {
			child.nipples = "cute";
		}
		if (typeof child.nipplesAccessory !== "string") {
			child.nipplesAccessory = "none";
		}
		child.areolae = Math.clamp(+child.areolae, 0, 4) || 0;
		if (typeof child.areolaeShape !== "string") {
			child.areolaeShape = "circle";
		}
		child.lactation = Math.clamp(+child.lactation, 0, 2) || 0;
		child.lactationAdaptation = Math.clamp(+child.lactationAdaptation, 0, 100) || 0;
	}

	function childButtDatatypeCleanup(child) {
		if (child.butt !== 0) {
			child.butt = Math.clamp(+child.butt, 0, 20) || 1;
		}
		child.anus = Math.clamp(+child.anus, 0, 4) || 0;
		child.analArea = Math.max(+child.analArea, 0) || 0;
	}

	function childPregnancyDatatypeCleanup(child) {
		child.induce = Math.clamp(+child.induce, 0, 1) || 0;
		child.labor = Math.clamp(+child.labor, 0, 1) || 0;
		if (child.hasOwnProperty("cSec")) {
			if (child.cSec > 0) {
				App.Medicine.Modification.addScar(child, "belly", "c-section");
			}
			delete child.cSec;
		}
		child.prematureBirth = Math.clamp(+child.prematureBirth, 0, 1) || 0;
		child.ovaries = Math.clamp(+child.ovaries, 0, 1) || 0;
		child.vasectomy = Math.clamp(+child.vasectomy, 0, 1) || 0;
		child.mpreg = Math.clamp(+child.mpreg, 0, 1) || 0;
		if (child.pregAdaptation !== 0) {
			child.pregAdaptation = Math.max(+child.pregAdaptation, 0) || 50;
		}
		child.pregSource = +child.pregSource || 0;
		if (typeof child.pregControl !== "string") {
			child.pregControl = "none";
		}
		child.fertPeak = Math.clamp(+child.fertPeak, 0, 4) || 0;
		WombNormalizePreg(child);
	}

	function childBellyDatatypeCleanup(child) {
		child.bellySag = Math.max(+child.bellySag, 0) || 0;
		child.bellySagPreg = Math.max(+child.bellySagPreg, 0) || child.bellySag;
		SetBellySize(child);
	}

	function childGenitaliaDatatypeCleanup(child) {
		child.vagina = Math.clamp(+child.vagina, -1, 10) || 0;
		child.vaginaLube = Math.clamp(+child.vaginaLube, 0, 2) || 0;
		child.labia = Math.clamp(+child.labia, 0, 3) || 0;
		child.clit = Math.clamp(+child.clit, 0, 5) || 0;
		child.foreskin = Math.max(+child.foreskin, 0) || 0;
		child.dick = Math.max(+child.dick, 0) || 0;
		if (child.dick && child.prostate !== 0) {
			child.prostate = Math.clamp(+child.prostate, 0, 3) || 1;
		} else {
			child.prostate = Math.clamp(+child.prostate, 0, 3) || 0;
		}
		child.balls = Math.max(+child.balls, 0) || 0;
		if (child.scrotum !== 0) {
			child.scrotum = Math.max(+child.scrotum, 0) || child.balls;
		}
	}

	function childImplantsDatatypeCleanup(child) {
		child.ageImplant = Math.clamp(+child.ageImplant, 0, 1) || 0;
		child.faceImplant = Math.clamp(+child.faceImplant, 0, 100) || 0;
		child.lipsImplant = Math.clamp(+child.lipsImplant, 0, 100) || 0;
		child.voiceImplant = Math.clamp(+child.voiceImplant, -1, 1) || 0;
		child.boobsImplant = Math.max(+child.boobsImplant, 0) || 0;
		if (child.boobsImplant === 0) {
			child.boobsImplantType = "none";
		} else if (child.boobsImplantType === "none") {
			child.boobsImplantType = "normal";
		}
		child.breastMesh = Math.clamp(+child.breastMesh, 0, 1) || 0;
		child.buttImplant = Math.clamp(+child.buttImplant, 0, 3) || 0;
		if (child.buttImplant === 0) {
			child.buttImplantType = "none";
		} else if (child.buttImplantType === "none") {
			child.buttImplantType = "normal";
		}
		child.earImplant = Math.clamp(+child.earImplant, 0, 1) || 0;
	}

	function childPiercingsDatatypeCleanup(child) {
		child.earPiercing = Math.clamp(+child.earPiercing, 0, 2) || 0;
		child.nosePiercing = Math.clamp(+child.nosePiercing, 0, 2) || 0;
		child.eyebrowPiercing = Math.clamp(+child.eyebrowPiercing, 0, 2) || 0;
		child.lipsPiercing = Math.clamp(+child.lipsPiercing, 0, 2) || 0;
		child.tonguePiercing = Math.clamp(+child.tonguePiercing, 0, 2) || 0;
		child.nipplesPiercing = Math.clamp(+child.nipplesPiercing, 0, 2) || 0;
		child.areolaePiercing = Math.clamp(+child.areolaePiercing, 0, 2) || 0;
		child.corsetPiercing = Math.clamp(+child.corsetPiercing, 0, 1) || 0;
		child.navelPiercing = Math.clamp(+child.navelPiercing, 0, 2) || 0;
		child.clitPiercing = Math.clamp(+child.clitPiercing, 0, 3) || 0;
		child.vaginaPiercing = Math.clamp(+child.vaginaPiercing, 0, 2) || 0;
		child.dickPiercing = Math.clamp(+child.dickPiercing, 0, 2) || 0;
		child.anusPiercing = Math.clamp(+child.anusPiercing, 0, 2) || 0;
	}

	function childTattooDatatypeCleanup(child) {
		if (typeof child.shouldersTat !== "string") {
			child.shouldersTat = 0;
		}
		if (typeof child.lipsTat !== "string") {
			child.lipsTat = 0;
		}
		if (typeof child.boobsTat !== "string") {
			child.boobsTat = 0;
		}
		if (typeof child.armsTat !== "string") {
			child.armsTat = 0;
		}
		if (typeof child.backTat !== "string") {
			child.backTat = 0;
		}
		if (typeof child.stampTat !== "string") {
			child.stampTat = 0;
		}
		if (typeof child.buttTat !== "string") {
			child.buttTat = 0;
		}
		if (typeof child.vaginaTat !== "string") {
			child.vaginaTat = 0;
		}
		if (typeof child.dickTat !== "string") {
			child.dickTat = 0;
		}
		if (typeof child.anusTat !== "string") {
			child.anusTat = 0;
		}
		if (typeof child.legsTat !== "string") {
			child.legsTat = 0;
		}
		if (typeof child.bellyTat !== "string") {
			child.bellyTat = 0;
		}
		if (typeof child.custom.tattoo !== "string") {
			child.custom.tattoo = "";
		}
	}

	function childCosmeticsDatatypeCleanup(child) {
		child.makeup = Math.clamp(+child.makeup, 0, 8) || 0;
		child.nails = Math.clamp(+child.nails, 0, 9) || 0;
		child.scars = Math.clamp(+child.scars, 0, 6) || 0;
		child.chastityAnus = Math.clamp(+child.chastityAnus, 0, 1) || 0;
		child.chastityPenis = Math.clamp(+child.chastityPenis, 0, 1) || 0;
		child.chastityVagina = Math.clamp(+child.chastityVagina, 0, 1) || 0;
		child.choosesOwnClothes = Math.clamp(+child.choosesOwnClothes, 0, 1) || 0;
		if (typeof child.clothes !== "string") {
			child.clothes = "no clothing";
		}
		if (typeof child.collar !== "string") {
			child.collar = "none";
		}
		if (typeof child.shoes !== "string") {
			child.shoes = "none";
		}
		if (typeof child.eyewear !== "string") {
			child.eyewear = "none";
		}
		if (typeof child.brand !== "object") {
			let brand = {};
			if (child.brand !== 0) {
				brand["left buttock"] = child.brand;
			}
			child.brand = brand;
		} else if (typeof child.brand === "object") { // Make sure key and value are strings
			for (let [key, value] of Object.entries(child.brand)) {
				if (typeof key !== "string" || typeof value !== "string") {
					delete child.brand[key];
				}
			}
		}
		if (typeof child.markings !== "string") {
			child.markings = "none";
		}
		if (typeof child.bellyAccessory !== "string") {
			child.bellyAccessory = "none";
		}
		if (typeof child.vaginalAccessory !== "string") {
			child.vaginalAccessory = "none";
		}
		if (typeof child.vaginalAttachment !== "string") {
			child.vaginalAttachment = "none";
		}
		if (typeof child.dickAccessory !== "string") {
			child.dickAccessory = "none";
		}
		if (typeof child.legAccessory !== "string") {
			child.legAccessory = "none";
		}
		if (typeof child.buttplug !== "string") {
			child.buttplug = "none";
		}
		if (typeof child.buttplugAttachment !== "string") {
			child.buttplugAttachment = "none";
		}
		if (typeof child.headAccessory !== "string") {
			child.headAccessory = "none";
		}
		if (typeof child.rearAccessory !== "string") {
			child.rearAccessory = "none";
		}
		if (typeof child.backAccessory !== "string") {
			child.backAccessory = "none";
		}
		if (typeof child.faceAccessory !== "string") {
			child.faceAccessory = "none";
		}
		if (typeof child.mouthAccessory !== "string") {
			child.mouthAccessory = "none";
		}
		switch(child.collar) {
			case "porcelain mask":
				child.faceAccessory = child.collar;
				child.collar = "none";
				break;
			case "bit gag":
			case "dildo gag":
			case "massive dildo gag":
			case "ball gag":
			case "ring gag":
				child.mouthAccessory = child.collar;
				child.collar = "none";
				break;
		}
	}

	function childDietDatatypeCleanup(child) {
		if (typeof child.diet !== "string") {
			child.diet = "healthy";
		}
		child.dietCum = Math.clamp(+child.dietCum, 0, 2) || 0;
		child.dietMilk = Math.clamp(+child.dietMilk, 0, 2) || 0;
		child.onDiet = Math.clamp(+child.onDiet, 0, 1) || 0;
		child.hormones = Math.clamp(+child.hormones, -2, 2) || 0;
		child.hormoneBalance = Math.clamp(+child.hormoneBalance, -400, 400) || 0;
		if (typeof child.drugs !== "string") {
			child.drugs = "no drugs";
		}
		child.aphrodisiacs = Math.clamp(+child.aphrodisiacs, 0, 2) || 0;
		child.curatives = Math.clamp(+child.curatives, 0, 2) || 0;
	}

	function childPornDatatypeCleanup(child) {
		child.porn.feed = Math.clamp(+child.porn.feed, 0, 1) || 0;
		child.porn.viewerCount = Math.max(+child.porn.viewerCount, 0) || 0;
		child.porn.spending = Math.max(+child.porn.spending, 0) || 0;
		child.porn.prestige = Math.clamp(+child.porn.prestige, 0, 3) || 0;
		if (typeof child.porn.prestigeDesc !== "string") {
			child.porn.prestigeDesc = 0;
		}
		if (typeof child.porn.fameType !== "string") {
			child.porn.fameType = "none";
		}
		if (typeof child.porn.focus !== "string") {
			child.porn.focus = "none";
		}
		for (const genre of App.Porn.getAllGenres()) {
			child.porn.fame[genre.fameVar] = Math.max(+child.porn.fame[genre.fameVar], 0) || 0;
		}
	}

	function childRelationDatatypeCleanup(child) {
		child.mother = +child.mother || 0;
		child.father = +child.father || 0;
		child.canRecruit = Math.clamp(+child.canRecruit, 0, 1) || 0;
		child.relationship = Math.clamp(+child.relationship, -3, 5) || 0;
		child.relationshipTarget = Math.max(+child.relationshipTarget, 0) || 0;
		child.rivalryTarget = Math.max(+child.rivalryTarget, 0) || 0;
		child.rivalry = Math.clamp(+child.rivalry, 0, 3) || 0;
	}

	function childSkillsDatatypeCleanup(child) {
		child.skill.oral = Math.clamp(+child.skill.oral, 0, 100) || 0;
		child.skill.vaginal = Math.clamp(+child.skill.vaginal, 0, 100) || 0;
		child.skill.anal = Math.clamp(+child.skill.anal, 0, 100) || 0;
		child.skill.whoring = Math.clamp(+child.skill.whoring, 0, 100) || 0;
		child.skill.entertainment = Math.clamp(+child.skill.entertainment, 0, 100) || 0;
		child.skill.combat = Math.clamp(+child.skill.combat, 0, 1) || 0;
		child.skill.headGirl = Math.clamp(+child.skill.headGirl, 0, 200) || 0;
		child.skill.recruiter = Math.clamp(+child.skill.recruiter, 0, 200) || 0;
		child.skill.bodyguard = Math.clamp(+child.skill.bodyguard, 0, 200) || 0;
		child.skill.madam = Math.clamp(+child.skill.madam, 0, 200) || 0;
		child.skill.DJ = Math.clamp(+child.skill.DJ, 0, 200) || 0;
		child.skill.nurse = Math.clamp(+child.skill.nurse, 0, 200) || 0;
		child.skill.teacher = Math.clamp(+child.skill.teacher, 0, 200) || 0;
		child.skill.attendant = Math.clamp(+child.skill.attendant, 0, 200) || 0;
		child.skill.matron = Math.clamp(+child.skill.matron, 0, 200) || 0;
		child.skill.stewardess = Math.clamp(+child.skill.stewardess, 0, 200) || 0;
		child.skill.milkmaid = Math.clamp(+child.skill.milkmaid, 0, 200) || 0;
		child.skill.farmer = Math.clamp(+child.skill.farmer, 0, 200) || 0;
		child.skill.wardeness = Math.clamp(+child.skill.wardeness, 0, 200) || 0;
		child.skill.servant = Math.clamp(+child.skill.servant, 0, 200) || 0;
		child.skill.entertainer = Math.clamp(+child.skill.entertainer, 0, 200) || 0;
		child.skill.whore = Math.clamp(+child.skill.whore, 0, 200) || 0;
	}

	function childStatCountDatatypeCleanup(child) {
		child.counter.oral = Math.max(+child.counter.oral, 0) || 0;
		child.counter.vaginal = Math.max(+child.counter.vaginal, 0) || 0;
		child.counter.anal = Math.max(+child.counter.anal, 0) || 0;
		child.counter.publicUse = Math.max(+child.counter.publicUse, 0) || 0;
		child.counter.mammary = Math.max(+child.counter.mammary, 0) || 0;
		child.counter.penetrative = Math.max(+child.counter.penetrative, 0) || 0;
		child.counter.pitKills = Math.max(+child.counter.pitKills, 0) || 0;
		child.counter.milk = Math.max(+child.counter.milk, 0) || 0;
		child.counter.cum = Math.max(+child.counter.cum, 0) || 0;
		child.counter.births = Math.max(+child.counter.births, 0) || 0;
		child.counter.birthsTotal = Math.max(+child.counter.birthsTotal, 0) || child.counter.births;
		child.counter.laborCount = Math.max(+child.counter.laborCount, 0) || child.counter.birthsTotal;
		child.counter.PCChildrenFathered = Math.max(+child.counter.PCChildrenFathered, 0) || 0;
		child.counter.PCKnockedUp = Math.max(+child.counter.PCKnockedUp, 0) || 0;
		child.bodySwap = Math.max(+child.bodySwap, 0) || 0;
	}

	function childPreferencesDatatypeCleanup(child) {
		child.energy = Math.clamp(+child.energy, 0, 100) || 0;
		child.need = Math.max(+child.need, 0) || 0;
		child.attrXY = Math.clamp(+child.attrXY, 0, 100) || 0;
		child.attrXX = Math.clamp(+child.attrXX, 0, 100) || 0;
		child.attrKnown = Math.clamp(+child.attrKnown, 0, 1) || 0;
		child.fetishStrength = Math.clamp(+child.fetishStrength, 0, 100) || 0;
		child.fetishKnown = Math.clamp(+child.fetishKnown, 0, 1) || 0;
	}

	function childRulesDatatypeCleanup(child) {
		child.breedingMark = Math.clamp(+child.breedingMark, 0, 1) || 0;
		child.rudeTitle = Math.clamp(+child.rudeTitle, 0, 1) || 0;
	}

	function childCustomStatsDatatypeCleanup(child) {
		if (typeof child.custom.label !== "string") {
			child.custom.label = "";
		}
		if (typeof child.custom.desc !== "string") {
			child.custom.desc = "";
		}
		if (typeof child.custom.title !== "string") {
			child.custom.title = "";
		}
		if (typeof child.custom.titleLisp !== "string") {
			child.custom.titleLisp = "";
		}
		if (child.custom.image !== null) {
			if (typeof child.custom.image.filename !== "string") {
				child.custom.image = null;
			}
		}
	}

	function childMiscellaneousDatatypeCleanup(child) {
		child.weekAcquired = Math.max(+child.weekAcquired, 0) || 0;
		child.prestige = Math.clamp(+child.prestige, 0, 3) || 0;
		child.devotion = Math.clamp(+child.devotion, -100, 100) || 0;
		child.oldDevotion = Math.clamp(+child.oldDevotion, -100, 100) || 0;
		child.trust = Math.clamp(+child.trust, -100, 100) || 0;
		child.oldTrust = Math.clamp(+child.oldTrust, -100, 100) || 0;
		child.chem = Math.max(+child.chem, 0) || 0;
		child.addict = Math.max(+child.addict, 0) || 0;
		child.intelligence = Math.clamp(+child.intelligence, -100, 100) || 0;
		child.intelligenceImplant = Math.clamp(+child.intelligenceImplant, 0, 30) || 0;
		child.premature = Math.clamp(+child.premature, 0, 1) || 0;
		child.training = Math.clamp(+child.training, 0, 150) || 0;
		child.hears = Math.clamp(+child.hears, -2, 0) || 0;
		child.smells = Math.clamp(+child.smells, -1, 0) || 0;
		child.tastes = Math.clamp(+child.tastes, -1, 0) || 0;
		if (typeof child.earwear !== "string") {
			child.earwear = "none";
		}
		if (child.voice !== 0) {
			child.voice = Math.clamp(+child.voice, 0, 3) || 1;
		}
		child.electrolarynx = Math.clamp(+child.electrolarynx, 0, 1) || 0;
		child.accent = Math.clamp(+child.accent, 0, 3) || 0;
	}
};

App.Facilities.Nursery.InfantDatatypeCleanup = function(child) {
	"use strict";

	ageDatatypeCleanup(child);
	physicalDatatypeCleanup(child);
	faceDatatypeCleanup(child);
	hairDatatypeCleanup(child);
	relationDatatypeCleanup(child);
	originDatatypeCleanup(child);
	generatePronouns(child);

	// old versions of FC assign overlapping IDs to infants and other slaves, which needs to be fixed
	// deconflict IDs between infants and older children/tank babies/adults by reassigning the infant's ID
	if (V.cribs.find((s) => s.ID === child.ID && (s.birthWeek !== child.birthWeek || s.actualAge !== child.actualAge)) !== undefined
	 || V.slaves.find((s) => s.ID === child.ID) !== undefined || V.tanks.find((s) => s.ID === child.ID) !== undefined) {
		child.ID = generateSlaveID();
	}

	function ageDatatypeCleanup(child) {
		child.birthWeek = Math.clamp(+child.birthWeek, 0, 51) || 0;
		child.actualAge = Math.clamp(+child.actualAge, V.minimumChildAge, Infinity) || 0;
	}

	function physicalDatatypeCleanup(child) {
		if (typeof child.nationality !== "string") {
			child.nationality = "child";
		}
		if (typeof child.race !== "string") {
			nationalityToRace(child);
		}
		if (typeof child.skin !== "string") {
			child.skin = "light";
		}
		child.weight = Math.clamp(+child.weight, -100, 200) || 0;
	}

	function faceDatatypeCleanup(child) {
		child.face = Math.clamp(+child.face, -100, 100) || 0;
		if (typeof child.faceShape !== "string") {
			child.faceShape = "normal";
		}
	}

	function hairDatatypeCleanup(child) {
		if (typeof child.hColor !== "string") {
			child.hColor = "brown";
		}
		if (typeof child.pubicHStyle !== "string") {
			child.pubicHStyle = "neat";
		}
		if (typeof child.eyebrowHColor !== "string") {
			child.eyebrowHColor = child.hColor;
		}
	}

	function relationDatatypeCleanup(child) {
		child.mother = +child.mother || 0;
		child.father = +child.father || 0;
	}

	function originDatatypeCleanup(child) {
		if (typeof child.origin !== "string") {
			child.origin = `${capFirstChar(child.pronoun)} was born and raised in your arcology. `;
		}
	}
};

repo_name: Welptard/fc

license: mit


code:
:: Nursery Discard Workaround [nobr]

$activeSlave.slaveName has been given away to another arcology to be raised, never to be seen again.

<<set $returnTo = "Main">>


code:
App.Data.Facilities.nursery = {
	baseName: "nursery",
	genericName: null,
	jobs: {
		nanny: {
			position: "nanny",
			assignment: Job.NURSERY,
			publicSexUse: false,
			fuckdollAccepted: false
		}
	},
	defaultJob: "nanny",
	manager: {
		position: "matron",
		assignment: Job.MATRON,
		careers: App.Data.misc.matronCareers,
		skill: "matron",
		publicSexUse: false,
		fuckdollAccepted: false,
		broodmotherAccepted: false,
		shouldWalk: true,
		shouldHold: true,
		shouldSee: true,
		shouldHear: true,
		shouldTalk: true,
		shouldThink: true,
		requiredDevotion: 51
	}
};

App.Entity.Facilities.NurseryNannyJob = class extends App.Entity.Facilities.FacilitySingleJob {
	/**
	 * @param {App.Entity.SlaveState} slave
	 * @returns {string[]}
	 */
	checkRequirements(slave) {
		let r = super.checkRequirements(slave);

		if (!App.Entity.Facilities.Job._isBrokenEnough(slave, 51, 21, -20, -95)) {
			r.push(App.Entity.Facilities.Job._stdBreakageMessage(slave));
		}

		return r;
	}

	/**
	 * @override
	 */
	get assignment() {
		return `work in ${this.facility.name}`;
	}
};

App.Entity.Facilities.Nursery = class extends App.Entity.Facilities.SingleJobFacility {
	constructor() {
		super(App.Data.Facilities.nursery,
			{
				nanny: new App.Entity.Facilities.NurseryNannyJob()
			});
	}

	// get capacity() {
	// 	return State.Variables.nurseryNannies;
	// }

	/** @override */
	occupancyReport(long) {
		return long
			? `${V.nurseryChildren}/${V.nursery} babies, ${this.hostedSlaves}/${V.nurseryNannies} nannies${this.manager.currentEmployee ? `, ${this.manager.desc.position}` : ""}`
			: `${V.nurseryChildren}/${V.nursery}, ${this.hostedSlaves}/${V.nurseryNannies}${this.manager.currentEmployee ? ", L" : ""}`;
	}
};

App.Entity.facilities.nursery = new App.Entity.Facilities.Nursery();


code:
:: Nursery Report [nobr]

<<includeDOM App.Facilities.Nursery.nurseryReport()>>


code:
:: Nursery Retrieval Workaround [nobr]

$readySlave.slaveName has been discharged from $nurseryName and is ready to become your slave.

<<set $nurseryChildren-->>
<<includeDOM App.Desc.longSlave($readySlave)>>
<<run newSlave($readySlave)>>
<<set $nextLink = "AS Dump">>
<<set $returnTo = "Main">>
/*	TODO:
<<if $nurseryOrgans.length > 0>>
	<<for _i = 0; _i < $nurseryOrgans.length; _i++>>
		<<if $nurseryOrgans[_i].ID == $activeSlave.ID>>
			<<set _newOrgan = {type: $nurseryOrgans[_i].type, weeksToCompletion: $nurseryOrgans[_i].weeksToCompletion, ID: $activeSlave.ID}>>
			<<if _newOrgan.weeksToCompletion <= 0>>
				<<set $completedOrgans.push($nurseryOrgans[_i])>>
			<<else>>
				<<set $organs.push(_newOrgan)>>
			<</if>>
			<<set $nurseryOrgans.deleteAt(_i), _i-->>
		<</if>>
	<</for>>
<</if>>
*/


code:
:: Previous Child In Line

<<silently>>

<<set $i = $cribs.findIndex(function(c) { return c.ID === $activeChild.ID; })>>
<<set $cribs[$i] = $activeChild>> /* save changes before switching */
<<if $i == 0>>
	<<set $activeChild = $cribs[$cribs.length - 1]>>
	<<if $activeChild.actualAge < 3>>
		<<goto "Infant Interact">>
	<<else>>
		<<goto "Child Interact">>
	<</if>>
<<else>>
	<<set $activeChild = $cribs[$i-1]>>
	<<if $activeChild.actualAge < 3>>
		<<goto "Infant Interact">>
	<<else>>
		<<goto "Child Interact">>
	<</if>>
<</if>>

<</silently>>


code:
App.Facilities.Nursery.fChildOral = function fChildOral(child) {
	"use strict";

	let r = ``;

	actX(child, "oral");// TODO: will this counts towards the total count?

	// TODO: all of this

	return r;
};

App.Facilities.Nursery.fChildVaginal = function fChildVaginal(child) {
	"use strict";

	let r = ``;

	actX(child, "vaginal");// TODO: will this counts towards the total count?

	// TODO: all of this

	return r;
};

App.Facilities.Nursery.fChildAnal = function fChildAnal(child) {
	"use strict";

	let r = ``;

	actX(child, "anal");

	// TODO: all of this

	return r;
};

App.Facilities.Nursery.fChildImpreg = function fChildImpreg(child) {
	const bonus = jsRandom(6, 20);

	let r = ``;

	if (child.mpreg) {
		actX(child, "anal", (bonus + 1));
	} else {
		actX(child, "vaginal", (bonus + 1));
	}

	// TODO: all of this

	return r;
};


code:
/**
 * Displays a list of the children in the Nursery
 * @returns {DocumentFragment}
 */
App.Facilities.Nursery.childList = function childList() {
	const cribs = V.cribs;

	let frag = document.createDocumentFragment();
	let r = [];

	if (V.nurseryChildren) {
		App.UI.DOM.appendNewElement("h3", frag, `Children in ${V.nurseryName}`, "indent");

		const list = App.UI.DOM.appendNewElement("p", frag, '', "indent");

		for (const child of cribs) {
			const weeksOwned = V.week - child.weekAcquired;
			const weeksLeft = (V.targetAgeNursery * 52) - weeksOwned;
			const {he, him, He} = getPronouns(child);
			const hr = document.createElement("hr");

			hr.style.margin = "0";
			list.appendChild(hr);

			if (child.actualAge < 3) {
				$(list).append(App.UI.DOM.link(SlaveFullName(child), (id) => V.activeChild = getChild(id), [child.ID], "Infant Interact"));
				$(list).append(App.Facilities.Nursery.InfantSummary(child));
			} else {
				$(list).append(App.UI.DOM.link(SlaveFullName(child), (id) => V.activeChild = getChild(id), [child.ID], "Child Interact"));
				$(list).append(App.Facilities.Nursery.ChildSummary(child));
			}

			if (child.actualAge >= 18) {
				if (child.targetLocation === "freedom") {
					V.freedSlaves.push(child);
				}

				V.readySlave = cribs.pluck();
				r.push(`<<goto "Nursery Retrieval Workaround">>`);
				return r;
			}

			if (child.growTime <= 0 || child.actualAge >= V.targetAgeNursery) {
				const targetText = child.targetLocation === "slavery" ? `"Introduce ${him} to life as a slave"` : `"Set ${him} free"`;

				list.appendChild(document.createElement("br"));

				r.push(`${He} is ready to leave ${V.nurseryName} and ${child.targetLocation === "slavery" ? `join your ménage` : `become a free citizen`}. `);
				$(list).append(App.UI.DOM.passageLink(targetText, "Nursery Retrieval Workaround", () => { V.readySlave = child; }));
			} else {
				list.appendChild(document.createElement("br"));

				r.push(`${He} is to continue staying in ${V.nurseryName} for another ${years(weeksLeft)}. ${He} is destined for ${child.targetLocation} once ${he} is of age.`);
			}

			$(list).append(r.join(' '));

			r = [];	// reset for next child
		}
	}

	return frag;
};

/**
 * Converts the infant object into a new child object
 * @param {object} child
 * @returns {object}
 */
App.Facilities.Nursery.infantToChild = function infantToChild(child) {
	child.abortionTat = -1;
	child.accent = 0;
	child.addict = 0;
	child.ageImplant = 0;
	child.arm = {
		left: new App.Entity.LimbState(),
		right: new App.Entity.LimbState()
	};
	child.leg = {
		left: new App.Entity.LimbState(),
		right: new App.Entity.LimbState()
	};
	child.analArea = 0;
	child.anus = 0;
	child.anusPiercing = 0;
	child.anusTat = 0;
	child.aphrodisiacs = 0;
	child.areolae = 0;
	child.areolaePiercing = 0;
	child.areolaeShape = "circle";
	child.armAccessory = "none";
	child.armsTat = 0;
	child.attrKnown = 0;
	child.attrXX = 0;
	child.attrXY = 0;
	child.backAccessory = "none";
	child.backTat = 0;
	child.bald = 0;
	child.balls = 0;
	child.behavioralFlaw = "none";
	child.belly = 0;
	child.bellyAccessory = "none";
	child.bellyFluid = 0;
	child.bellyImplant = -1;
	child.bellyPreg = 0;
	child.bellySag = 0;
	child.bellySagPreg = 0;
	child.bellyTat = 0;
	child.bodySwap = 0;
	child.boobShape = "normal";
	child.boobs = jsRandom(200, 500);
	child.boobsImplant = 0;
	child.boobsImplantType = "none";
	child.boobsTat = 0;
	child.brand = {};
	child.breastMesh = 0;
	child.breedingMark = 0;
	child.butt = jsRandom(0, 3);
	child.buttImplant = 0;
	child.buttImplantType = "none";
	child.buttTat = 0;
	child.buttplug = "none";
	child.buttplugAttachment = "none";
	child.canRecruit = 0;
	child.chastityAnus = 0;
	child.chastityPenis = 0;
	child.chastityVagina = 0;
	child.chem = 0;
	child.choosesOwnClothes = 0;
	child.clit = jsRandom(0, 2);
	child.clitPiercing = 0;
	child.clone = 0;
	child.clothes = "no clothing";
	child.collar = "none";
	child.corsetPiercing = 0;
	child.counter = {
		PCChildrenFathered: 0,
		PCKnockedUp: 0,
		anal: 0,
		births: 0,
		birthsTotal: 0,
		cum: 0,
		laborCount: 0,
		mammary: 0,
		milk: 0,
		oral: 0,
		penetrative: 0,
		pitKills: 0,
		publicUse: 0,
		slavesFathered: 0,
		slavesKnockedUp: 0,
		vaginal: 0
	};
	child.curatives = 0;
	child.custom = {
		desc: "",
		hairVector: "",
		image: null,
		label: "",
		tattoo: "",
		title: "",
		titleLisp: ""
	};
	child.daughters = 0;
	child.devotion = 40;	// TODO:
	child.dick = 0;
	child.dickAccessory = "none";
	child.dickPiercing = 0;
	child.dickTat = 0;
	child.diet = "healthy";
	child.dietCum = 0;
	child.dietMilk = 0;
	child.drugs = "no drugs";
	child.earImplant = 0;
	child.earPiercing = 0;
	child.earShape = "normal";
	child.earT = "none";
	child.earTColor = "hairless";
	child.earwear = "none";
	child.electrolarynx = 0;
	child.energy = 0;
	child.eyebrowFullness = "natural";
	child.eyebrowHStyle = "natural";
	child.eyebrowPiercing = 0;
	child.eyewear = "none";
	child.faceImplant = 0;
	child.fertKnown = 1;
	child.fertPeak = 0;
	child.fetishKnown = 0;
	child.fetishStrength = 0;
	child.foreskin = 0;
	child.geneMods = {
		NCS: 0,
		rapidCellGrowth: 0
	};
	child.hLength = jsRandom(30, 70);
	child.hStyle = "long";
	child.haircuts = 0;
	child.headAccessory = "none";
	child.health = {};
	setHealth(child, jsRandom(80, 100), 0, 0, 0, 0);
	child.hears = 0;
	child.heels = 0;
	child.height = jsRandom(85, 105);
	child.hips = 0;
	child.hormoneBalance = 0;
	child.hormones = 0;
	child.horn = "none";
	child.hornColor = "none";
	child.induce = 0;
	child.induceLactation = 0;
	child.intelligence = 100;
	child.intelligenceImplant = 0;
	child.labia = jsRandom(0, 2);
	child.labor = 0;
	child.lactation = 0;
	child.lactationAdaptation = 0;
	child.lactationDuration = 0;
	child.rules = new App.Entity.RuleState();
	child.rules.lactation = "none";
	child.legAccessory = "none";
	child.legsTat = 0;
	child.lips = jsRandom(10, 30);
	child.lipsImplant = 0;
	child.lipsPiercing = 0;
	child.lipsTat = 0;
	child.rules.living = "normal";
	child.makeup = 0;
	child.markings = "none";
	child.minorInjury = 0;
	child.mpreg = 0;
	child.muscles = jsRandom(-10, 10);
	child.nails = 0;
	child.navelPiercing = 0;
	child.need = 0;
	child.nipples = "cute";
	child.nipplesAccessory = "none";
	child.nipplesPiercing = 0;
	child.nosePiercing = 0;
	child.oldDevotion = 0;
	child.oldTrust = 0;
	child.onDiet = 0;
	child.origRace = child.race;
	child.eye = new App.Entity.EyeState();
	child.eye.origColor = child.eyeColor;
	child.origHColor = child.hColor;
	child.origSkin = child.skin;
	child.ovaries = child.genes === "XX" ? 1 : 0;
	child.ovaryAge = child.actualAge;
	/* eslint-disable camelcase */
	child.override_Arm_H_Color = 0;
	child.override_Brow_H_Color = 0;
	child.override_Eye_Color = 0;
	child.override_H_Color = 0;
	child.override_Pubic_H_Color = 0;
	child.override_Race = 0;
	child.override_Skin = 0;
	/* eslint-enable camelcase */
	child.physicalAge = child.actualAge;
	child.porn = new App.Entity.SlavePornPerformanceState();
	child.pregAdaptation = 50;
	child.pregControl = "none";
	child.pregData = {
		drugsEffect: 1,
		fetusRate: [1, 1, 1, 0.64, 0.6513, 0.6459, 0.644, 0.6393, 0.58, 0.51],
		fetusSize: [1, 3, 16, 25.6, 51, 60, 67.5, 71.6, 129.5, 130],
		fetusWeek: [0, 9, 20, 20, 40, 52, 64, 80, 384, 99999],
		minLiveBirth: 32,
		normalBirth: 40,
		normalOvaMax: 1,
		normalOvaMin: 1,
		sizeType: 0,
		type: "human"
	};
	child.pregKnown = 0;
	child.pregSource = 0;
	child.pregType = 0;
	child.pregWeek = 0;
	child.premature = 0;
	child.prematureBirth = 0;
	child.prestige = 0;
	child.prostate = 0;
	child.pubertyAgeXX = 10;
	child.pubertyAgeXY = 12;
	child.pubertyXX = 1;
	child.pubicHColor = "black";
	child.pubicHStyle = "bushy";
	child.readyOva = 0;
	child.rearAccessory = "none";
	child.relationship = 0;
	child.rules.relationship = "restrictive";
	child.relationshipTarget = 0;
	child.rules.release = new App.Entity.ReleaseRulesState();
	child.rivalry = 0;
	child.rivalryTarget = 0;
	child.rudeTitle = 0;
	child.scar = {};
	child.scrotum = 0;
	child.shoes = "none";
	child.shoulders = 0;
	child.shouldersTat = 0;
	child.sisters = 0;
	child.skill = {
		DJ: 0,
		anal: 0,
		attendant: 0,
		bodyguard: 0,
		combat: 0,
		entertainer: 0,
		entertainment: 0,
		farmer: 0,
		headGirl: 0,
		madam: 0,
		matron: 0,
		milkmaid: 0,
		nurse: 0,
		oral: 0,
		recruiter: 0,
		servant: 0,
		stewardess: 0,
		teacher: 0,
		vaginal: 0,
		wardeness: 0,
		whore: 0,
		whoring: 8
	};
	child.smells = 0;
	child.rules.speech = "restrictive";
	child.stampTat = 0;
	child.rules.punishment = "situational";
	child.rules.reward = "situational";
	child.tail = "none";
	child.tailColor = "none";
	child.tailShape = "none";
	child.tastes = 0;
	child.teeth = "baby";
	child.tonguePiercing = 0;
	child.training = 0;
	child.trust = 0;
	child.underArmHStyle = "natural";
	child.vagina = child.genes === "XX" ? 0 : -1;
	child.vaginaLube = 0;
	child.vaginaPiercing = 0;
	child.vaginaTat = 0;
	child.vaginalAccessory = "none";
	child.vaginalAttachment = "none";
	child.vasectomy = 0;
	child.visualAge = child.actualAge;
	child.voice = 1;
	child.voiceImplant = 0;
	child.waist = 0;
	child.weeksLeft = 0;
	child.weight = jsRandom(-10, 10);
	child.womb = [];
	child.wombImplant = "none";
	resetEyeColor(child, "both");
	generatePronouns(child);

	return child;
};

/**
 * Allows the player to name the infant
 * FIXME: Does not currently work
 * @param {object} child
 * @returns {string}
 */
App.Facilities.Nursery.nameChild = function nameChild(child) {
	const PC = V.PC;
	const arcology = V.arcologies[0];
	const girl = child.genes === "XX" ? "girl" : "boy";

	let r = ``;
	/** @type {App.Entity.SlaveState} */
	let father = 0;
	/** @type {App.Entity.SlaveState} */
	let mother = 0;

	const {him, his, he} = getPronouns(child);

	if (child.father === -1 && child.mother === -1) {
		father = PC;
		mother = PC;
	} else {
		if (child.father === -1) {
			father = PC;
			mother = getSlave(child.mother);
		} else if (child.mother === -1) {
			father = getSlave(child.father);
			mother = PC;
		} else {
			father = getSlave(child.father);
			mother = getSlave(child.mother);
		}
	}

	function newChildName(child) {
		child.birthName = generateName(child.nationality, child.race, child.genes === "XY");

		if (child.genes === "XY" && !V.allowMaleSlaveNames && isMaleName(child.birthName, child.nationality, child.race)) {
			child.slaveName = generateName(child.nationality, child.race, false);
		} else {
			child.slaveName = child.birthName;
		}
	}

	r += `You can name the new child, if you so desire. `;

	r += `<br><<textbox "${child.slaveName}" ${child.slaveName}>>`;
	r += App.UI.passageLink("Commit name", "Nursery Workaround", `${child.birthName = child.slaveName}, ${App.UI.replace("#naming", `You instruct ${V.assistant.name} to register the new ${girl} as "${child.slaveName}" in the slave registry.`)}`);
	r += `<br>`;
	r += App.UI.passageLink(`Have your PA assign ${him} a random name`, "Nursery Workaround", `${App.UI.replace("#naming", `${newChildName(child)}
${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.`)}`);

	if (arcology.FSPastoralist !== "unset") {
		if (child.lactation > 0) {
			r += `

			<<link "Have your PA assign ${him} a random cow name">>
			<<replace "#naming">>`;
			child.slaveName = setup.cowSlaveNames.random();
			child.birthName = child.slaveName;
			r += `${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.
			<</replace>>
			<</link>>`;
		}
	}
	if (arcology.FSChattelReligionist !== "unset") {
		r += `

		<<link "Have your PA assign ${him} a random devotional name">>
			<<replace "#naming">>`;
		child.slaveName = setup.chattelReligionistSlaveNames.random();
		child.birthName = child.slaveName;
		r += `${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.
			<</replace>>
		<</link>>`;
	}
	if (arcology.FSRomanRevivalist !== "unset") {
		r += `

		<<link "Have your PA assign ${him} a random Roman name">>
			<<replace "#naming">>`;
		child.slaveName = setup.romanSlaveNames.random();
		child.birthName = child.slaveName;
		r += `${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.
			<</replace>>
		<</link>>`;
	} else if (arcology.FSAztecRevivalist !== "unset") {
		r += `

		<<link "Have your PA assign ${him} a random Aztec name">>
			<<replace "#naming">>`;
		child.slaveName = setup.aztecSlaveNames.random();
		child.birthName = child.slaveName;
		r += `${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.
			<</replace>>
		<</link>>`;
	} else if (arcology.FSEgyptianRevivalist !== "unset") {
		r += `

		<<link "Have your PA assign ${him} a random ancient Egyptian name">>
			<<replace "#naming">>`;
		child.slaveName = setup.ancientEgyptianSlaveNames.random();
		child.birthName = child.slaveName;
		r += `${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.
			<</replace>>
		<</link>>`;
	} else if (arcology.FSEdoRevivalist !== "unset") {
		r += `

		<<link "Have your PA assign ${him} a random feudal Japanese name">>
			<<replace "#naming">>`;
		child.slaveName = setup.edoSlaveNames.random();
		child.birthName = child.slaveName;
		r += `${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.
			<</replace>>
		<</link>>`;
	}
	if (arcology.FSDegradationist !== "unset") {
		r += `

		<<link "Have your PA assign ${him} a degrading name">>
			<<replace "#naming">>`;
		DegradingName(child);
		child.birthName = child.slaveName;
		r += `${V.assistant.name} registers the new ${girl} as "${child.slaveName}" in your registry.
			<</replace>>
		<</link>>`;
	}
	if (mother !== PC && mother !== 0) {
		const {He2, he2, his2} = getPronouns(mother).appendSuffix('2');
		if (mother.ID === V.ConcubineID) {
			r += `

			<<link "Permit your Concubine to name _his2 daughter">>
				<<replace "#naming">>`;
			parentNames(mother, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${mother.slaveName} picks a name ${he2} thinks you might find attractive; from now on ${his2} daughter will be known as "${child.slaveName}".
				<</replace>>
			<</link>>`;
		} else if (mother.relationship === -3 && mother.devotion >= -20) {
			r += `

			<<link "Permit your wife to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(mother, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${mother.slaveName} picks a name suitable for your daughter; from now on ${he2} will be known as "${child.slaveName}".
				<</replace>>
			<</link>>`;
		} else if (mother.ID === V.BodyguardID) {
			r += `

			<<link "Permit your bodyguard to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(mother, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${mother.slaveName} decides on "${child.slaveName}" for ${his2} daughter. ${He2} hopes you'll find it fitting ${his} station.
				<</replace>>
			<</link>>`;
		} else if (mother.ID === V.HeadGirlID) {
			r += `

			<<link "Permit your Head Girl to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(mother, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${mother.slaveName} decides on "${child.slaveName}" for ${his2} daughter, and hopes it will be a name your other slaves will learn to respect.
				<</replace>>
			<</link>>`;
		} else if (mother.devotion > 50 && mother.trust > 50) {
			r += `

			<<link "Permit ${his} devoted mother to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(mother, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${mother.slaveName} picks a name ${he2} hopes you'll like; from now on ${his2} daughter will be known as "${child.slaveName}".
				<</replace>>
			<</link>>`;
		}
	}
	if (father !== PC && father !== 0 && father !== mother) {
		const {He2, he2, his2} = getPronouns(father).appendSuffix('2');
		if (father.ID === V.ConcubineID) {
			r += `

			<<link "Permit your Concubine to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(father, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${father.slaveName} picks a name ${he2} thinks you might find attractive; from now on ${his2} daughter will be known as "${child.slaveName}".
				<</replace>>
			<</link>>`;
		} else if (father.relationship === -3 && father.devotion >= -20) {
			r += `

			<<link "Permit your wife to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(father, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${father.slaveName} picks a name suitable for your daughter; from now on ${he} will be known as "${child.slaveName}".
				<</replace>>
			<</link>>`;
		} else if (father.ID === V.BodyguardID) {
			r += `

			<<link "Permit your bodyguard to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(father, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${father.slaveName} decides on "${child.slaveName}" for ${his2} daughter. ${He2} hopes you'll find it fitting ${his} station.
				<</replace>>
			<</link>>`;
		} else if (father.ID === V.HeadGirlID) {
			r += `

			<<link "Permit your Head Girl to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(father, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${father.slaveName} decides on "${child.slaveName}" for ${his2} daughter, and hopes it will be a name your other slaves will learn to respect.
				<</replace>>
			<</link>>`;
		} else if (father.devotion > 50 && father.trust > 50) {
			r += `

			<<link "Permit ${his} devoted father to name ${his2} daughter">>
				<<replace "#naming">>`;
			parentNames(father, child);
			child.birthName = child.slaveName;
			r += `After some careful consideration, ${father.slaveName} picks a name ${he2} hopes you'll like; from now on ${his2} daughter will be known as "${child.slaveName}".
				<</replace>>
			<</link>>`;
		}
	}

	return r;
};

/**
 * Adds an infant to a the cribs
 * @param {App.Entity.InfantState} child
 */
App.Facilities.Nursery.newChild = function newChild(child) {
	child.ID = generateSlaveID();

	child.actualAge = 0;
	child.birthWeek = 0;

	if (child.override_Race !== 1) {
		child.origRace = child.race;
	}

	if (child.override_H_Color !== 1) {
		child.hColor = getGeneticHairColor(child);
	}
	if (child.override_Arm_H_Color !== 1) {
		child.underArmHColor = getGeneticHairColor(child);
	}
	if (child.override_Pubic_H_Color !== 1) {
		child.pubicHColor = getGeneticHairColor(child);
	}
	if (child.override_Brow_H_Color !== 1) {
		child.eyebrowHColor = getGeneticHairColor(child);
	}
	if (child.override_Skin !== 1) {
		child.origSkin = getGeneticSkinColor(child);
	}
	/* eslint-disable camelcase*/
	child.override_Race = 0;
	child.override_H_Color = 0;
	child.override_Arm_H_Color = 0;
	child.override_Pubic_H_Color = 0;
	child.override_Brow_H_Color = 0;
	child.override_Skin = 0;
	child.override_Eye_Color = 0;
	/* eslint-enable */

	child.arm = {
		left: new App.Entity.LimbState(),
		right: new App.Entity.LimbState()
	};
	child.leg = {
		left: new App.Entity.LimbState(),
		right: new App.Entity.LimbState()
	};

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

	if (child.clone !== 0) {
		child.canRecruit = 0;
	}
	generatePronouns(child);
	child.origin = `$He was born and raised in your arcology. `;
	child.targetLocation = "slavery";
	child.growTime = V.targetAgeNursery * 52;
	V.cribs.push(child);
	V.cribsIndices = App.Facilities.Nursery.cribsToIndices();
	V.nurseryChildren++;
};

/**
 * @param {App.Entity.ChildState[]} [cribs]
 * @returns {object.<number, number>}
 */
App.Facilities.Nursery.cribsToIndices = function cribsToIndices(cribs = V.cribs) {
	return cribs.reduce((acc, child, i) => { acc[child.ID] = i; return acc; }, {});
};

/**
 * Returns index in the children array for the given ID
 * @param {number} id child's ID
 * @returns {number}
 */
App.Facilities.Nursery.childIndexForID = function childIndexForID(id) {
	return V.cribsIndices[id];
};

/**
 * Removes the child using the child's ID
 * @param {number} index
 * @returns {Array}
 */
App.Facilities.Nursery.removeChild = function removeChild(index) {
	return V.cribs.deleteAt(index);
};

/**
 * Displays a list of slaves with children eligible for the Nursery
 * FIXME: Does not currently work
 * @returns {string}
 */
App.Facilities.Nursery.nurserySort = function nurserySort() {
	const PC = V.PC;
	const SL = V.slaves.length;
	const arcology = V.arcologies[0];
	const freeCribs = (V.nursery - V.cribs.length);

	let r = ``;
	let eligibility = 0;
	let sortNurseryList = V.sortNurseryList || "Unsorted";
	let nurseryHasReservedChildren = false;
	let reservedChildrenNursery = FetusGlobalReserveCount("nursery");

	r += `<br><i>Sorting:</i> <b><span id="ql-nursery-sort">${sortNurseryList}</span>.</b> `;
	r += `${App.UI.passageLink("Sort by Name", "Nursery", `${sortNurseryList = "Name"}, ${App.UI.replace(`#ql-nursery-sort`, sortNurseryList)}, ${byName()}`)} | `;
	r += `${App.UI.passageLink("Sort by Reserved Nursery Spots", "Nursery", `${sortNurseryList = "Reserved Nursery Spots"}, ${App.UI.replace(`#ql-nursery-sort`)} ${sortNurseryList}, ${byReservedSpots()}`)} | `;
	r += `${App.UI.passageLink("Sort by Pregnancy Week", "Nursery", `${sortNurseryList = "Pregnancy Week"}, ${App.UI.replace(`#ql-nursery-sort`, sortNurseryList)}, ${byPregnancyWeek()}`)} | `;
	r += `${App.UI.passageLink("Sort by Number of Children", "Nursery", `${sortNurseryList = "Number of Children"}, ${App.UI.replace(`#ql-nursery-sort`, sortNurseryList)}, ${byPregnancyCount()}`)}`;
	r += `<br>`;

	r += `<div id="ql-nursery">`;

	for (let i = 0; i < SL; i++) {
		const slave = V.slaves[i];
		const {His, his} = getPronouns(slave);

		App.Utils.setLocalPronouns(slave);

		if (slave.preg > 0 && !slave.broodmother && slave.pregKnown && slave.eggType === "human") {
			if (slave.assignment !== Job.DAIRY && V.dairyPregSetting <= 0) {
				const slaveID = "slave-" + slave.ID;
				const WL = slave.womb.length;
				const reservedNursery = WombReserveCount(slave, "nursery");
				const reservedIncubator = WombReserveCount(slave, "incubator");
				const pregWeek = slave.pregWeek;
				const slaveName = SlaveFullName(slave);

				r += `<div class="possible" @id="${slaveID}" @data-preg-count="${WL}" @data-reserved-spots="${reservedNursery}" @data-preg-week="${pregWeek}" @data-name="${slaveName}">`;

				r += `${App.UI.SlaveDescriptionDialog(slave)} is ${pregWeek} weeks pregnant with `;

				switch (slave.pregSource) {
					case 0:
						r += `someone's${slave.preg <= 5 ? `, though it is too early to tell whose,` : ``}`;
						break;
					case -1:
						r += `your`;
						break;
					case -2:
						r += `a citizen's`;
						break;
					case -3:
						r += `your Master's`;
						break;
					case -4:
						r += `another arcology owner's`;
						break;
					case -5:
						r += `your client's`;
						break;
					case -6:
						r += `the Societal Elite's`;
						break;
					case -7:
						r += `the lab's`;
						break;
					case -9:
						r += `the Futanari Sister's`;
						break;
					default:
						if (slave.preg <= 5) {
							r += `someone's, though it is too early to tell whose,`;
						} else {
							let t = V.slaveIndices[slave.pregSource];
							if (jsDef(t)) {
								r += `${V.slaves[t].slaveName}'s`;
							}
						}
						break;
				}
				r += ` ${WL > 1 ? `babies` : `baby`}. `;

				if (reservedNursery > 0) {
					nurseryHasReservedChildren = true;
					if (WL === 1) {
						r += `${His} child will be placed in ${V.nurseryName}. `;
					} else if (reservedNursery < WL) {
						r += `${reservedNursery} of ${his} children will be placed in ${V.nurseryName}. `;
					} else if (WL === 2) {
						r += `Both of ${his} children will be placed in ${V.nurseryName}. `;
					} else {
						r += `All ${reservedNursery} of ${his} children will be placed in ${V.nurseryName}. `;
					}

					if ((reservedIncubator + reservedNursery < WL) && (reservedChildrenNursery < freeCribs)) {
						r += `<br>    `;
						r += App.UI.passageLink("Keep another child", "Nursery", `${WombAddToGenericReserve(slave, "nursery", 1)}`);
						if (reservedNursery > 0) {
							r += ` | ${App.UI.passageLink("Keep one less child", "Nursery", `${WombCleanGenericReserve(slave, "nursery", 1)}`)}`;
						}
						if (reservedNursery > 1) {
							r += ` | ${App.UI.passageLink(`Keep none of ${his} children`, "Nursery", `${WombCleanGenericReserve(slave, "nursery", 9999)}`)}`;
						}
						if (reservedChildrenNursery + WL - reservedNursery <= freeCribs) {
							r += ` | ${App.UI.passageLink(`Keep the rest of ${his} children`, "Nursery", `${WombAddToGenericReserve(slave, "nursery", 9999)}`)}`;
						}
					} else if (reservedNursery === WL || reservedChildrenNursery === freeCribs || reservedIncubator + reservedNursery === WL) {
						r += `<br>    `;
						r += App.UI.passageLink("Keep one less child", "Nursery", `${WombCleanGenericReserve(slave, "nursery", 1)}`);
						if (reservedNursery > 1) {
							r += ` | ${App.UI.passageLink(`Keep none of ${his} children`, "Nursery", `${WombCleanGenericReserve(slave, "nursery", 9999)}`)}`;
						}
					}
				} else if (reservedChildrenNursery < freeCribs && freeCribs > WL) {
					if (WL - reservedIncubator === 0) {
						r += `<i>${His} children are already reserved for ${V.incubatorName}</i>`;
						r += `<br>    `;
						r += App.UI.passageLink(`Keep ${his} child${WL > 1 ? `ren` : ``} here instead`, "Nursery", `${WombAddToGenericReserve(slave, "nursery", 1)}`);
					} else {
						r += `You have ${freeCribs === 1 ? `an ` : ``}available room${freeCribs > 1 ? `s` : ``}. `;
						r += `<br>    `;
						r += App.UI.passageLink(`Keep ${WL > 1 ? `a` : `the`} child`, "Nursery", `${WombAddToGenericReserve(slave, "nursery", 1)}`);
						if (WL > 1 && (reservedChildrenNursery + WL - reservedNursery <= freeCribs)) {
							r += ` | ${App.UI.passageLink(`Keep all of ${his} children`, "Nursery", `${WombAddToGenericReserve(slave, "nursery", 9999)}`)}`;
						}
					}
				} else if (reservedChildrenNursery === freeCribs) {
					r += `<br>    `;
					r += `You have <span class="red">no room for ${his} offspring.</span> `;
				}

				eligibility = 1;
				r += `</div>`;
			}
		}
	}

	r += `</div>`;

	$('div#ql-nursery').ready(byPreviousSort);

	if (!eligibility) {
		r += `<br>`;
		r += `<i>You have no pregnant slave bearing eligible children</i>`;
	}

	if (PC.pregKnown && (arcology.FSRestart === "unset" || V.eugenicsFullControl || (PC.pregSource !== -1 && PC.pregSource !== -6))) {
		const WL = PC.womb.length;

		let reservedIncubator = WombReserveCount(PC, "incubator");
		let reservedNursery = WombReserveCount(PC, "nursery");

		r += `<br><b><span class="pink">You're pregnant</span></b> and going to have ${WL === 1 ? `a baby. ` : pregNumberName(WL, 1)} `;

		if (reservedNursery > 0) {
			nurseryHasReservedChildren = true;
			if (WL === 1) {
				r += `Your child will be placed in ${V.nurseryName}.`;
			} else if (reservedNursery < WL) {
				r += `${reservedNursery} of your children will be placed in ${V.nurseryName}.`;
			} else if (WL === 2) {
				r += `Both of your children will be placed in ${V.nurseryName}.`;
			} else {
				r += `All ${reservedNursery} of your children will be placed in ${V.nurseryName}.`;
			}

			if (reservedNursery < WL && reservedChildrenNursery < freeCribs && reservedNursery - reservedIncubator > 0) {
				r += `<br>    `;
				r += App.UI.passageLink("Keep another child", "Nursery", `${reservedNursery += 1}, ${reservedChildrenNursery += 1}`);
				if (reservedNursery > 0) {
					r += ` | ${App.UI.passageLink("Keep one less child", "Nursery", `${reservedNursery -= 1}, ${reservedChildrenNursery -= 1}`)}`;
				}

				if (reservedNursery > 1) {
					r += ` | ${App.UI.passageLink("Keep none of your children", "Nursery", `${reservedChildrenNursery -= reservedNursery}, ${reservedChildrenNursery = 0}`)}`;
				}

				if (reservedChildrenNursery + WL - reservedNursery <= freeCribs) {
					r += ` | ${App.UI.passageLink("Keep the rest of your children", "Nursery", `${reservedChildrenNursery += (WL - reservedNursery)}, ${reservedNursery += (WL - reservedNursery)}`)}`;
				}
			} else if (reservedNursery === WL || reservedChildrenNursery === freeCribs || reservedNursery - reservedIncubator >= 0) {
				r += `<br>    `;
				r += App.UI.passageLink("Keep one less child", "Nursery", `${reservedNursery -= 1}, ${reservedChildrenNursery -= 1}`);
				if (reservedNursery > 1) {
					r += App.UI.passageLink("Keep none of your children", "Nursery", `${reservedChildrenNursery -= reservedNursery}, ${reservedNursery = 0}`);
				}
			}
		} else if (reservedChildrenNursery < freeCribs) {
			if (WL - reservedIncubator === 0) {
				r += `<i>Your child${WL > 1 ? `ren are` : ` is`} already reserved for ${V.incubatorName}</i>`;
				r += App.UI.passageLink(`Keep your child${WL > 1 ? `ren` : ``} here instead`, "Nursery", `${reservedNursery += WL}, ${reservedIncubator = 0}`);
			} else {
				r += `You have ${freeCribs === 1 ? `an ` : ``}available room${freeCribs > 1 ? `s` : ``}. `;
				r += `<br>    `;
				r += App.UI.passageLink(`Keep ${WL > 1 ? `a` : `your`} child`, "Nursery", `${reservedNursery += 1}, ${reservedChildrenNursery += 1}`);
				if (WL > 1 && (reservedChildrenNursery + WL - reservedNursery <= freeCribs)) {
					r += ` | ${App.UI.passageLink("Keep all of your children", "Nursery", `${reservedChildrenNursery += WL}, ${reservedNursery += WL}`)}`;
				}
			}
		} else if (reservedChildrenNursery === freeCribs) {
			r += `<br>    `;
			r += `You have <span class="red">no room for your offspring.</span> `;
		}
	}

	if (reservedChildrenNursery || nurseryHasReservedChildren) {
		r += `<br>`;
		r += App.UI.passageLink("Clear all reserved children", "Nursery", `${V.slaves.forEach((slave) => WombCleanGenericReserve(slave, "nursery", 9999))}, ${WombCleanGenericReserve(PC, "nursery", 9999)}`);
	}

	function byName() {
		let sortedNurseryPossibles = $('#ql-nursery div.possible').detach();
		sortedNurseryPossibles = sortDomObjects(sortedNurseryPossibles, 'data-name');
		$(sortedNurseryPossibles).appendTo($('#ql-nursery'));
	}

	function byReservedSpots() {
		let sortedNurseryPossibles = $('#ql-nursery div.possible').detach();
		sortedNurseryPossibles = sortDomObjects(sortedNurseryPossibles, 'data-reserved-spots');
		$(sortedNurseryPossibles).appendTo($('#ql-nursery'));
	}

	function byPregnancyWeek() {
		let sortedNurseryPossibles = $('#ql-nursery div.possible').detach();
		sortedNurseryPossibles = sortDomObjects(sortedNurseryPossibles, 'data-preg-week');
		$(sortedNurseryPossibles).appendTo($('#ql-nursery'));
	}

	function byPregnancyCount() {
		let sortedNurseryPossibles = $('#ql-nursery div.possible').detach();
		sortedNurseryPossibles = sortDomObjects(sortedNurseryPossibles, 'data-preg-count');
		$(sortedNurseryPossibles).appendTo($('#ql-nursery'));
	}

	function byPreviousSort() {
		let sort = V.sortNurseryList;
		if (sort !== 'unsorted') {
			if (sort === 'Name') {
				sortNurseryPossiblesByName();
			} else if (sort === 'Reserved Nursery Spots') {
				sortNurseryPossiblesByReservedSpots();
			} else if (sort === 'Pregnancy Week') {
				sortNurseryPossiblesByPregnancyWeek();
			} else if (sort === 'Number of Children') {
				sortNurseryPossiblesByPregnancyCount();
			}
		}
	}

	return r;
};


code:
App.Data.Facilities.penthouse = {
	baseName: "penthouse",
	genericName: "Penthouse",
	jobs: {
		rest: {
			position: "Rest",
			assignment: Job.REST,
			publicSexUse: false,
			fuckdollAccepted: true
		},
		chooseOwn: {
			position: "Choose own",
			assignment: Job.CHOICE,
			publicSexUse: false,
			fuckdollAccepted: false
		},
		fucktoy: {
			position: "Fucktoy",
			assignment: Job.FUCKTOY,
			publicSexUse: false,
			fuckdollAccepted: true
		},
		classes: {
			position: "Classes",
			assignment: Job.CLASSES,
			publicSexUse: false,
			fuckdollAccepted: false
		},
		houseServant: {
			position: "House Servant",
			assignment: Job.HOUSE,
			publicSexUse: false,
			fuckdollAccepted: false
		},
		whore: {
			position: "Whore",
			assignment: Job.WHORE,
			publicSexUse: true,
			fuckdollAccepted: false
		},
		publicServant: {
			position: "Public Servant",
			assignment: Job.PUBLIC,
			publicSexUse: true,
			fuckdollAccepted: false
		},
		subordinateSlave: {
			position: "Subordinate slave",
			assignment: Job.SUBORDINATE,
			publicSexUse: false,
			fuckdollAccepted: false
		},
		cow: {
			position: "Milked",
			assignment: Job.MILKED,
			publicSexUse: false,
			fuckdollAccepted: false
		},
		gloryhole: {
			position: "Gloryhole",
			assignment: Job.GLORYHOLE,
			publicSexUse: false,
			fuckdollAccepted: true
		},
		confinement: {
			position: "Confinement",
			assignment: Job.CONFINEMENT,
			publicSexUse: false,
			fuckdollAccepted: true
		}
	},
	defaultJob: "rest",
	manager: {
		position: "Recruiter",
		assignment: Job.RECRUITER,
		careers: App.Data.misc.recruiterCareers,
		skill: "recruiter",
		publicSexUse: false,
		fuckdollAccepted: false,
		broodmotherAccepted: false,
		shouldWalk: true,
		shouldHold: false,
		shouldSee: true,
		shouldHear: true,
		shouldTalk: true,
		shouldThink: true,
		requiredDevotion: 51
	}
};

App.Entity.Facilities.PenthouseJobs = {
	Classes: class extends App.Entity.Facilities.Job {
		checkRequirements(slave) {
			let r = super.checkRequirements(slave);
			if (slave.intelligenceImplant >= 15) {
				r.push(`${slave.slaveName} already has a basic education.`);
			}
			if (!App.Entity.Facilities.Job._isBrokenEnough(slave, -20, -50, -20, -51)) {
				r.push(`${slave.slaveName} is too resistant to learn.`);
			}

			if (slave.fetish === "mindbroken") {
				r.push(`${slave.slaveName}'s mind is fundamentally broken and can't learn.`);
			}
			return r;
		}
	},
	HouseServant: class extends App.Entity.Facilities.Job {
		checkRequirements(slave) {
			let r = super.checkRequirements(slave);

			if (!App.Entity.Facilities.Job._isBrokenEnough(slave, -20, -50, -19, -51)) {
				r.push(App.Entity.Facilities.Job._stdBreakageMessage(slave));
			}

			if (!canWalk(slave)) {
				r.push(`${slave.slaveName} can't walk and would be unable to properly clean.`);
			}
			if (!canSee(slave)) {
				r.push(`${slave.slaveName} is blind and would be unable to properly clean.`);
			}

			return r;
		}
	},

	SubordinateSlave: class extends App.Entity.Facilities.Job {
		checkRequirements(slave) {
			let r = super.checkRequirements(slave);
			if (!App.Entity.Facilities.Job._isBrokenEnough(slave, -20, -50, -19, -51)) {
				r.push(App.Entity.Facilities.Job._stdBreakageMessage(slave));
			}
			return r;
		}

		assignmentLinkElement(ID, passage, callback, linkText) {
			linkText = linkText || this.desc.position;
			return App.UI.DOM.assignmentLink(slaveStateById(ID), this.desc.assignment, "Subordinate Targeting",
				(slave, assignment) => {
					if (callback) {
						callback(slave, assignment);
					}
					V.AS = ID;
					V.returnTo = passage;
				}, linkText);
		}
	},
	Cow: class extends App.Entity.Facilities.Job {
		checkRequirements(slave) {
			let r = super.checkRequirements(slave);
			if ((slave.lactation <= 0) && (slave.balls <= 0)) {
				r.push(`${slave.slaveName} is not lactating` + ((V.seeDicks > 0) ? ' or producing semen.' : '.'));
			}
			return r;
		}
	},
};

App.Entity.Facilities.Penthouse = class extends App.Entity.Facilities.Facility {
	constructor() {
		super(App.Data.Facilities.penthouse, {
			classes: new App.Entity.Facilities.PenthouseJobs.Classes(),
			houseServant: new App.Entity.Facilities.PenthouseJobs.HouseServant(),
			subordinateSlave: new App.Entity.Facilities.PenthouseJobs.SubordinateSlave(),
			cow: new App.Entity.Facilities.PenthouseJobs.Cow(),
		});
	}

	/** Facility slave capacity
	 * @override
	 * @returns {number} */
	get capacity() {
		return V.dormitory;
	}

	/** Number of already hosted slaves
	 * @returns {number} */
	get hostedSlaves() {
		return V.dormitoryPopulation;
	}

	/** Penthouse can be overcrowded, so it always has free space
	 * @returns {boolean} */
	get hasFreeSpace() {
		return true;
	}
};

App.Entity.facilities.penthouse = new App.Entity.Facilities.Penthouse();


code:
.pit-intro,
.pit-section {
	margin-bottom: 1em;
}

.kill-slave-options,
.kill-slave-relations,
.kill-slave-cancel,
.pit-assign,
.pit-rename {
	margin-top: 1em;
}


code:
App.Facilities.Pit.pit = function() {
	const frag = new DocumentFragment();
	const nameCaps = capFirstChar(V.pit.name);

	V.nextButton = "Back to Main";
	V.nextLink = "Main";
	V.returnTo = "Pit";
	V.encyclopedia = "Pit";

	App.UI.DOM.appendNewElement("div", frag, intro(), "pit-intro");
	frag.appendChild(audience());

	if (V.pit.slaveFightingBodyguard) {
		App.UI.DOM.appendNewElement("div", frag, scheduled());
	} else {
		frag.append(fighters(), lethality());

		App.UI.DOM.appendNewElement("div", frag, App.UI.SlaveList.listSJFacilitySlaves(App.Entity.facilities.pit, passage(), false, {assign: "Select a slave to fight", remove: "Cancel a slave's fight", transfer: ""}), "pit-assign");
	}

	App.UI.DOM.appendNewElement("div", frag, rename(), "pit-rename");

	App.UI.SlaveList.ScrollPosition.restore();

	return frag;

	function intro() {
		const frag = new DocumentFragment();

		const desc = App.UI.DOM.appendNewElement("div", frag);
		const link = App.UI.DOM.makeElement("div", '', "indent");
		const note = App.UI.DOM.makeElement("div", '', "note");

		const count = App.Entity.facilities.pit.totalEmployeesCount;

		desc.append(`${nameCaps} is clean and ready, `);

		if (count > 2) {
			desc.append(`with a pool of slaves assigned to fight in the next week's bout.`);
		} else if (count === 1) {
			desc.append(`but only one slave is assigned to the week's bout.`);
		} else if (count > 0) {
			desc.append(`with slaves assigned to the week's bout.`);
		} else {
			desc.append(`but no slaves are assigned to fight.`);
		}

		link.append(App.UI.DOM.passageLink(`Decommission ${V.pit.name}`, "Main", () => {
			V.pit = null;

			// FIXME: fix this
			// @ts-ignore
			App.Arcology.cellUpgrade(V.building, App.Arcology.Cell.Market, "Pit", "Markets");
		}));

		note.append(`${properTitle()}, slaves assigned here can continue their usual duties.`);

		desc.appendChild(link);
		desc.appendChild(note);

		return frag;
	}

	function audience() {
		const mainDiv = document.createElement("div");
		const linkSpan = document.createElement("span");

		const links = [];

		if (V.pit.audience === "none") {
			mainDiv.append(`Fights here are strictly private.`);

			links.push(
				App.UI.DOM.link("Open them for free", () => {
					V.pit.audience = "free";

					App.UI.DOM.replace(mainDiv, audience);
				}),
				App.UI.DOM.link("Open them and charge admission", () => {
					V.pit.audience = "paid";

					App.UI.DOM.replace(mainDiv, audience);
				})
			);
		} else if (V.pit.audience === "free") {
			mainDiv.append(`Fights here are free and open to the public.`);

			links.push(
				App.UI.DOM.link("Close them", () => {
					V.pit.audience = "none";

					App.UI.DOM.replace(mainDiv, audience);
				}),
				App.UI.DOM.link("Charge admission", () => {
					V.pit.audience = "paid";

					App.UI.DOM.replace(mainDiv, audience);
				})
			);
		} else {
			mainDiv.append(`Admission is charged to the fights here.`);

			links.push(
				App.UI.DOM.link("Close them", () => {
					V.pit.audience = "none";

					App.UI.DOM.replace(mainDiv, audience);
				}),
				App.UI.DOM.link("Stop charging admission", () => {
					V.pit.audience = "free";

					App.UI.DOM.replace(mainDiv, audience);
				})
			);
		}

		linkSpan.append(App.UI.DOM.generateLinksStrip(links));
		mainDiv.appendChild(linkSpan);

		return mainDiv;
	}

	function fighters() {
		const mainDiv = document.createElement("div");
		const linkSpan = document.createElement("span");

		const links = [];

		if (S.Bodyguard || V.activeCanine || V.activeHooved || V.activeFeline) {
			if (V.pit.bodyguardFights) {
				mainDiv.append(`Your bodyguard ${S.Bodyguard.slaveName} will fight a slave selected from the pool at random.`);

				links.push(App.UI.DOM.link("Make both slots random", () => {
					V.pit.bodyguardFights = false;
					V.pit.animal = null;

					if (V.pit.fighterIDs.includes(V.BodyguardID)) {
						V.pit.fighterIDs.delete(V.BodyguardID);
					}

					App.UI.DOM.replace(mainDiv, fighters);
				}));

				// if (V.activeCanine || V.activeHooved || V.activeFeline) {
				// 	links.push(App.UI.DOM.link("Have a slave fight an animal", () => {
				// 		V.pit.bodyguardFights = false;
				// 		V.pit.animal = null;

				// 		if (V.pit.fighterIDs.includes(V.BodyguardID)) {
				// 			V.pit.fighterIDs.delete(V.BodyguardID);
				// 		}

				// 		App.UI.DOM.replace(mainDiv, fighters);
				// 	}));
				// }
			} else {
				if (V.pit.animal) {
					mainDiv.append(`A random slave will fight an animal.`);

					links.push(
						App.UI.DOM.link("Have them fight another slave", () => {
							V.pit.bodyguardFights = false;
							V.pit.animal = null;

							App.UI.DOM.replace(mainDiv, fighters);
						}),
						App.UI.DOM.link("Have them fight your bodyguard", () => {
							V.pit.bodyguardFights = true;
							V.pit.animal = null;

							App.UI.DOM.replace(mainDiv, fighters);
						}));
				} else {
					mainDiv.append(`Two fighters will be selected from the pool at random.`);

					if (S.Bodyguard) {
						links.push(
							App.UI.DOM.link("Guarantee your bodyguard a slot", () => {
								V.pit.bodyguardFights = true;
								V.pit.animal = null;

								App.UI.DOM.replace(mainDiv, fighters);
							})
						);
					}

					// if (V.activeCanine || V.activeHooved || V.activeFeline) {
					// 	links.push(
					// 		App.UI.DOM.link("Have a slave fight an animal", () => {
					// 			V.pit.bodyguardFights = false;
					// 			V.pit.animal = new FC.Facilities.Animal();

					// 			App.UI.DOM.replace(mainDiv, fighters);
					// 		})
					// 	);
					// }
				}
			}
		} else {
			mainDiv.append(`Two fighters will be selected from the pool at random.`);
		}

		linkSpan.append(App.UI.DOM.generateLinksStrip(links));
		mainDiv.append(linkSpan);

		return mainDiv;
	}

	function lethality() {
		const mainDiv = document.createElement("div");
		const linkSpan = document.createElement("span");

		if (V.pit.lethal) {
			if (V.pit.animal) {
				mainDiv.append(`The fighter will be armed with a sword and will fight to the death. `);

				linkSpan.append(
					App.UI.DOM.link("Nonlethal", () => {
						V.pit.lethal = false;

						App.UI.DOM.replace(mainDiv, lethality);
					})
				);
			} else {
				mainDiv.append(`Fighters will be armed with swords, and fights will be to the death. `);

				linkSpan.append(
					App.UI.DOM.link("Nonlethal", () => {
						V.pit.lethal = false;

						App.UI.DOM.replace(mainDiv, lethality);
					})
				);
			}
		} else {
			if (V.pit.animal) {
				mainDiv.append(`The slave will be restrained and will try to avoid becoming the animal's plaything. `);

				linkSpan.append(
					App.UI.DOM.link("Lethal", () => {
						V.pit.lethal = true;

						App.UI.DOM.replace(mainDiv, lethality);
					})
				);
			} else {
				mainDiv.append(`Fighters will use their fists and feet, and fights will be to submission. `);

				linkSpan.append(
					App.UI.DOM.link("Lethal", () => {
						V.pit.lethal = true;

						App.UI.DOM.replace(mainDiv, lethality);
					})
				);
			}
		}

		mainDiv.appendChild(linkSpan);

		if (!V.pit.lethal && !V.pit.animal) {
			mainDiv.appendChild(virginities());
		}

		function virginities() {
			const mainDiv = document.createElement("div");
			const boldSpan = App.UI.DOM.makeElement("span", ``, "bold");
			const linkSpan = document.createElement("span");

			const links = [];

			if (V.pit.virginities === "neither") {
				boldSpan.append(`No`);
				mainDiv.append(boldSpan, ` virginities of the loser will be respected.`);

				links.push(
					App.UI.DOM.link("Vaginal", () => {
						V.pit.virginities = "vaginal";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("Anal", () => {
						V.pit.virginities = "anal";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("All", () => {
						V.pit.virginities = "all";

						App.UI.DOM.replace(mainDiv, virginities);
					})
				);
			} else if (V.pit.virginities === "vaginal") {
				boldSpan.append(`Vaginal`);
				mainDiv.append(boldSpan, ` virginity of the loser will be respected.`);

				links.push(
					App.UI.DOM.link("Neither", () => {
						V.pit.virginities = "neither";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("Anal", () => {
						V.pit.virginities = "anal";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("All", () => {
						V.pit.virginities = "all";

						App.UI.DOM.replace(mainDiv, virginities);
					})
				);
			} else if (V.pit.virginities === "anal") {
				boldSpan.append(`Anal`);
				mainDiv.append(boldSpan, ` virginity of the loser will be respected.`);

				links.push(
					App.UI.DOM.link("Neither", () => {
						V.pit.virginities = "neither";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("Vaginal", () => {
						V.pit.virginities = "vaginal";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("All", () => {
						V.pit.virginities = "all";

						App.UI.DOM.replace(mainDiv, virginities);
					})
				);
			} else {
				boldSpan.append(`All`);
				mainDiv.append(boldSpan, ` virginities of the loser will be respected.`);

				links.push(
					App.UI.DOM.link("Neither", () => {
						V.pit.virginities = "neither";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("Vaginal", () => {
						V.pit.virginities = "vaginal";

						App.UI.DOM.replace(mainDiv, virginities);
					}),
					App.UI.DOM.link("Anal", () => {
						V.pit.virginities = "anal";

						App.UI.DOM.replace(mainDiv, virginities);
					})
				);
			}

			linkSpan.append(App.UI.DOM.generateLinksStrip(links));
			mainDiv.appendChild(linkSpan);

			return mainDiv;
		}

		return mainDiv;
	}

	function scheduled() {
		const mainDiv = document.createElement("div");
		const linkSpan = document.createElement("span");

		mainDiv.append(`You have scheduled one of your slaves to fight to the death this week. `, linkSpan);

		linkSpan.append(App.UI.DOM.link("Cancel it", () => {
			V.pit.slaveFightingBodyguard = null;

			App.UI.DOM.replace(mainDiv, scheduled);
		}));

		mainDiv.appendChild(linkSpan);

		return mainDiv;
	}

	function rename() {
		const frag = new DocumentFragment();

		const renameDiv = App.UI.DOM.makeElement("div", '', "pit-rename");
		const renameNote = App.UI.DOM.makeElement("span", '', "note");

		renameDiv.append(`Rename ${V.pit.name}: `);
		renameNote.append(` Use a noun or similar short phrase`);

		renameDiv.append(App.UI.DOM.makeTextBox(V.pit.name, newName => {
			V.pit.name = newName;
		}));

		renameDiv.append(renameNote);

		frag.append(renameDiv);

		return frag;
	}
};

App.Facilities.Pit.init = function() {
	/** @type {FC.Facilities.Pit} */
	V.pit = {
		name: "the Pit",

		animal: null,
		audience: "free",
		bodyguardFights: false,
		fighterIDs: [],
		fought: false,
		lethal: false,
		slaveFightingBodyguard: null,
		virginities: "neither",
	};
};