:: Multiple Organ Implant [nobr]

You head down to your <<if $surgeryUpgrade == 1>>heavily upgraded and customized remote surgery<<else>>remote surgery<</if>> and start having the slaves with <<if ($completedOrgans.length > 0) && ($limbsCompleted > 0)>>organs or limbs <<elseif ($completedOrgans.length > 1)>>organs <<elseif ($limbsCompleted > 1)>>sets of limbs <</if>>that are ready be sent down.

/* builds a list for each slave and adds the appropriate organs to it */
<<for _i = 0; _i < $slaves.length; _i++>>
	<<set $activeSlave = $slaves[_i]>>
	<<set _slaveOrgans = {
		penis: 0,
		testicles: 0,
		scrotum: 0,
		pigTesticles: 0,
		dogTesticles: 0,
		foreskin: 0,
		ovaries: 0,
		prostate: 0,
		pigOvaries: 0,
		dogOvaries: 0,
		eyes: 0,
		voicebox: 0,
		mpreg: 0,
		mpregPig: 0,
		mpregDog: 0
		}>>
	<<for _j = 0; _j < $completedOrgans.length; _j++>>
		<<if $activeSlave.ID == $completedOrgans[_j].ID>>
			<<if $completedOrgans[_j].type == "penis">>
				<<set _slaveOrgans.penis = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "testicles">>
				<<set _slaveOrgans.testicles = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "scrotum">>
				<<set _slaveOrgans.scrotum = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "pigTesticles">>
				<<set _slaveOrgans.pigTesticles = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "dogTesticles">>
				<<set _slaveOrgans.dogTesticles = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "foreskin">>
				<<set _slaveOrgans.foreskin = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "ovaries">>
				<<set _slaveOrgans.ovaries = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "prostate">>
				<<set _slaveOrgans.prostate = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "pigOvaries">>
				<<set _slaveOrgans.pigOvaries = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "dogOvaries">>
				<<set _slaveOrgans.dogOvaries = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "eyes">>
				<<set _slaveOrgans.eyes = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "voicebox">>
				<<set _slaveOrgans.voicebox = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "mpreg">>
				<<set _slaveOrgans.mpreg = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "mpregPig">>
				<<set _slaveOrgans.mpregPig = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<elseif $completedOrgans[_j].type == "mpregDog">>
				<<set _slaveOrgans.mpregDog = $completedOrgans[_j]>>
				<<set $completedOrgans.deleteAt(_j),_j-->>
			<<else>>
				<br>Error: unrecognized organ.
			<</if>>
		<</if>>
	<</for>>
	/* read _slaveOrgans and install them when appropriate */
	/* order here is important, do not change it without good reason */
	/* eyes */
	<<if _slaveOrgans.eyes != 0>>
		<<if ($activeSlave.eyes == -2) && $activeSlave.origEye != "implant">>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.eyes to 1>>
			<<set $activeSlave.eyeColor to $activeSlave.origEye>>
			/* no way to salvage original eye color */
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<set $surgeryType = "unblind">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.origEye == "implant">>
			<<set $cash -= $surgeryCost>>
			<<set $stockpile.ocularImplant++>>
			<<set $activeSlave.eyes to 1>>
			<<set _oldEyes = $genePool.find(function(s) { return s.ID = $activeSlave.ID; })>>
			<<set $activeSlave.origEye = _oldEyes.origEye>>
			<<set $activeSlave.eyeColor to $activeSlave.origEye>>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<set $surgeryType = "newEyes">>
			<<include "Surgery Degradation">>
		<<else>>
			<br><hr>
			@@.red;Could not implant eyes on $activeSlave.slaveName: she is not blind.@@
			<<set $completedOrgans.push(_slaveOrgans.eyes)>>
		<</if>>
	<</if>>
	/* voice */
	<<if _slaveOrgans.voicebox != 0>>
		<<if ($activeSlave.voice == 0)>>
			<<set $cash -= $surgeryCost>>
			<<if $activeSlave.ovaries == 1 && $activeSlave.hormoneBalance >= 200>>
				<<set $activeSlave.voice = 3>>
			<<elseif ($activeSlave.balls > 0) || ($activeSlave.hormoneBalance < -20)>>
				<<set $activeSlave.voice = 1>>
			<<else>>
				<<set $activeSlave.voice = 2>>
			<</if>>
			<<set $activeSlave.health -= 10>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 10>>
			<</if>>
			<<set $surgeryType = "restoreVoice">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<else>>
			<br><hr>
			@@.red;Could not implant eyes on $activeSlave.slaveName: she is not a mute.@@
			<<set $completedOrgans.push(_slaveOrgans.voicebox)>>
		<</if>>
	<</if>>
	/* foreskin */
	<<if _slaveOrgans.foreskin != 0>>
		<<if ($activeSlave.foreskin == 0)>>
			<<set $cash -= $surgeryCost>>
			<<if $activeSlave.dick > 0>>
				<<set $activeSlave.foreskin = $activeSlave.penis>>
			<<else>>
				<<set $activeSlave.foreskin = $activeSlave.clit>>
			<</if>>
			<<set $activeSlave.health -= 10>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 10>>
			<</if>>
			<<set $surgeryType = "addForeskin">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<else>>
			<br><hr>
			@@.red;Could not implant eyes on $activeSlave.slaveName: she already has foreskin.@@
			<<set $completedOrgans.push(_slaveOrgans.foreskin)>>
		<</if>>
	<</if>>
	/* prostate */
	<<if _slaveOrgans.prostate != 0>>
		<<if ($activeSlave.prostate == 0)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.prostate = 1>>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<set $surgeryType = "addProstate">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<else>>
			<br><hr>
			@@.red;Could not implant eyes on $activeSlave.slaveName: she already has a prostate.@@
			<<set $completedOrgans.push(_slaveOrgans.prostate)>>
		<</if>>
	<</if>>
	/* ovaries */
	<<if _slaveOrgans.ovaries != 0>>
		<<if ($activeSlave.ovaries == 0) && ($activeSlave.vagina >= 0) && ($activeSlave.mpreg == 0) && ($activeSlave.bellyImplant == -1)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.ovaries = 1>>
			<<set $activeSlave.eggType = "human">>
			<<set $activeSlave.preg = 0>>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXX == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyAgeXX = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyXX = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "addOvaries">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.ovaries == 1>>
			<br><hr>
			@@.red;Could not implant ovaries on $activeSlave.slaveName: she already has ovaries.@@
			<<set $completedOrgans.push(_slaveOrgans.ovaries)>>
		<<elseif $activeSlave.vagina < 0>>
			<br><hr>
			@@.red;Could not implant ovaries on $activeSlave.slaveName: she lacks a vagina.@@
			<<set $completedOrgans.push(_slaveOrgans.ovaries)>>
		<<elseif $activeSlave.bellyImplant >= 0>>
			<br><hr>
			@@.red;Could not implant ovaries on $activeSlave.slaveName: she has a fillable abdominal implant.@@
			<<set $completedOrgans.push(_slaveOrgans.ovaries)>>
		<<elseif $activeSlave.mpreg != 0>>
			<br><hr>
			@@.red;Could not implant ovaries on $activeSlave.slaveName: she has an anal womb.@@
			<<set $completedOrgans.push(_slaveOrgans.ovaries)>>
		<</if>>
	<</if>>
	/* pig ovaries */
	<<if _slaveOrgans.pigOvaries != 0>>
		<<if ($activeSlave.ovaries == 0) && ($activeSlave.vagina >= 0) && ($activeSlave.mpreg == 0) && ($activeSlave.bellyImplant == -1)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.ovaries = 1>>
			<<set $activeSlave.eggType = "pig">>
			<<set $activeSlave.preg = 0>>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXX == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyAgeXX = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyXX = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "addPigOvaries">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.ovaries == 1>>
			<br><hr>
			@@.red;Could not implant pig ovaries on $activeSlave.slaveName: she already has ovaries.@@
			<<set $completedOrgans.push(_slaveOrgans.pigOvaries)>>
		<<elseif $activeSlave.vagina < 0>>
			<br><hr>
			@@.red;Could not implant pig ovaries on $activeSlave.slaveName: she lacks a vagina.@@
			<<set $completedOrgans.push(_slaveOrgans.pigOvaries)>>
		<<elseif $activeSlave.bellyImplant >= 0>>
			<br><hr>
			@@.red;Could not implant pig ovaries on $activeSlave.slaveName: she has a fillable abdominal implant.@@
			<<set $completedOrgans.push(_slaveOrgans.pigOvaries)>>
		<<elseif $activeSlave.mpreg != 0>>
			<br><hr>
			@@.red;Could not implant pig ovaries on $activeSlave.slaveName: she has an anal womb.@@
			<<set $completedOrgans.push(_slaveOrgans.pigOvaries)>>
		<</if>>
	<</if>>
	/* dog ovaries */
	<<if _slaveOrgans.dogOvaries != 0>>
		<<if ($activeSlave.ovaries == 0) && ($activeSlave.vagina >= 0) && ($activeSlave.mpreg == 0) && ($activeSlave.bellyImplant == -1)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.ovaries = 1>>
			<<set $activeSlave.eggType = "dog">>
			<<set $activeSlave.preg = 0>>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXX == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyAgeXX = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyXX = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "addDogOvaries">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.ovaries == 1>>
			<br><hr>
			@@.red;Could not implant dog ovaries on $activeSlave.slaveName: she already has ovaries.@@
			<<set $completedOrgans.push(_slaveOrgans.dogOvaries)>>
		<<elseif $activeSlave.vagina < 0>>
			<br><hr>
			@@.red;Could not implant dog ovaries on $activeSlave.slaveName: she lacks a vagina.@@
			<<set $completedOrgans.push(_slaveOrgans.dogOvaries)>>
		<<elseif $activeSlave.bellyImplant >= 0>>
			<br><hr>
			@@.red;Could not implant dog ovaries on $activeSlave.slaveName: she has a fillable abdominal implant.@@
			<<set $completedOrgans.push(_slaveOrgans.dogOvaries)>>
		<<elseif $activeSlave.mpreg != 0>>
			<br><hr>
			@@.red;Could not implant dog ovaries on $activeSlave.slaveName: she has an anal womb.@@
			<<set $completedOrgans.push(_slaveOrgans.dogOvaries)>>
		<</if>>
	<</if>>
	/* male preg */
	<<if _slaveOrgans.mpreg != 0>>
		<<if ($activeSlave.ovaries == 0) && ($activeSlave.vagina < 0) && ($activeSlave.mpreg == 0) && ($activeSlave.bellyImplant == -1)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.mpreg = 1>>
			<<set $activeSlave.eggType = "human">>
			<<set $activeSlave.preg = 0>>
			<<set $activeSlave.health -= 40>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXX == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyAgeXX = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyXX = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "mpreg">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.ovaries == 1>>
			<br><hr>
			@@.red;Could not implant anal womb on $activeSlave.slaveName: she has ovaries.@@
			<<set $completedOrgans.push(_slaveOrgans.mpreg)>>
		<<elseif $activeSlave.vagina < 0>>
			<br><hr>
			@@.red;Could not implant anal womb on $activeSlave.slaveName: she has a vagina.@@
			<<set $completedOrgans.push(_slaveOrgans.mpreg)>>
		<<elseif $activeSlave.bellyImplant >= 0>>
			<br><hr>
			@@.red;Could not implant anal womb on $activeSlave.slaveName: she has a fillable abdominal implant.@@
			<<set $completedOrgans.push(_slaveOrgans.mpreg)>>
		<<elseif $activeSlave.mpreg == 1>>
			<br><hr>
			@@.red;Could not implant anal womb on $activeSlave.slaveName: she already has an anal womb.@@
			<<set $completedOrgans.push(_slaveOrgans.mpreg)>>
		<</if>>
	<</if>>
	/* male pig preg */
	<<if _slaveOrgans.mpregPig != 0>>
		<<if ($activeSlave.ovaries == 0) && ($activeSlave.vagina < 0) && ($activeSlave.mpreg == 0) && ($activeSlave.bellyImplant == -1)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.mpreg = 1>>
			<<set $activeSlave.eggType = "pig">>
			<<set $activeSlave.preg = 0>>
			<<set $activeSlave.health -= 40>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXX == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyAgeXX = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyXX = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "mpregPig">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.ovaries == 1>>
			<br><hr>
			@@.red;Could not implant pig anal womb on $activeSlave.slaveName: she has ovaries.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregPig)>>
		<<elseif $activeSlave.vagina < 0>>
			<br><hr>
			@@.red;Could not implant pig anal womb on $activeSlave.slaveName: she has a vagina.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregPig)>>
		<<elseif $activeSlave.bellyImplant >= 0>>
			<br><hr>
			@@.red;Could not implant pig anal womb on $activeSlave.slaveName: she has a fillable abdominal implant.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregPig)>>
		<<elseif $activeSlave.mpreg != 0>>
			<br><hr>
			@@.red;Could not implant pig anal womb on $activeSlave.slaveName: she already has an anal womb.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregPig)>>
		<</if>>
	<</if>>
	/* male dog preg */
	<<if _slaveOrgans.mpregDog != 0>>
		<<if ($activeSlave.ovaries == 0) && ($activeSlave.vagina < 0) && ($activeSlave.mpreg == 0) && ($activeSlave.bellyImplant == -1)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.mpreg = 1>>
			<<set $activeSlave.eggType = "dog">>
			<<set $activeSlave.preg = 0>>
			<<set $activeSlave.health -= 40>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXX == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyAgeXX = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $fertilityAge>>
						<<set $activeSlave.pubertyXX = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "mpregDog">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.ovaries == 1>>
			<br><hr>
			@@.red;Could not implant dop anal womb on $activeSlave.slaveName: she has ovaries.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregDog)>>
		<<elseif $activeSlave.vagina < 0>>
			<br><hr>
			@@.red;Could not implant dog anal womb on $activeSlave.slaveName: she has a vagina.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregDog)>>
		<<elseif $activeSlave.bellyImplant >= 0>>
			<br><hr>
			@@.red;Could not implant dog anal womb on $activeSlave.slaveName: she has a fillable abdominal implant.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregDog)>>
		<<elseif $activeSlave.mpreg != 0>>
			<br><hr>
			@@.red;Could not implant dog anal womb on $activeSlave.slaveName: she already has an anal womb.@@
			<<set $completedOrgans.push(_slaveOrgans.mpregDog)>>
		<</if>>
	<</if>>
	/* penis */
	<<if _slaveOrgans.penis != 0>>
		<<if $activeSlave.dick == 0>>
			<<set $cash -= $surgeryCost>>
			<<if $activeSlave.prostate == 0>>
				<<set $activeSlave.prostate = 1>>
			<</if>>
			<<set $activeSlave.dick to 2>>
			<<set $activeSlave.clit to 0>>
			<<set $activeSlave.foreskin to $activeSlave.dick>>
			<<set $activeSlave.health -= 20>>
			<<set $surgeryType = "addDick">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<else>>
			@@.red;Could not implant penis on $activeSlave.slaveName: she already has a penis.@@
			<<set $completedOrgans.push(_slaveOrgans.penis)>>
		<</if>>
	<</if>>
	/* testicles */
	<<if _slaveOrgans.testicles != 0>>
		<<if ($activeSlave.dick >= 1) && ($activeSlave.balls == 0)>>
			<<set $cash -= $surgeryCost>>
			<<if $activeSlave.prostate == 0>>
				<<set $activeSlave.prostate = 1>>
			<</if>>
			<<set $activeSlave.balls to 2>>
			<<set $activeSlave.ballType = "human">>
			<<set $activeSlave.scrotum to 2>>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXY == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $potencyAge>>
						<<set $activeSlave.pubertyAgeXY = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $potencyAge>>
						<<set $activeSlave.pubertyXY = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "addBalls">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.dick == 0>>
			<br><hr>
			@@.red;Could not implant testicles on $activeSlave.slaveName: she lacks a penis.@@
			<<set $completedOrgans.push(_slaveOrgans.testicles)>>
		<<else>>
			<br><hr>
			@@.red;Could not implant testicles on $activeSlave.slaveName: she already has testicles.@@
			<<set $completedOrgans.push(_slaveOrgans.testicles)>>
		<</if>>
	<</if>>
	/* pig testicles */
	<<if _slaveOrgans.pigTesticles != 0>>
		<<if ($activeSlave.dick >= 1) && ($activeSlave.balls == 0)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.balls = 3>>
			<<set $activeSlave.scrotum = 3>>
			<<set $activeSlave.ballType = "pig">>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXY == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $potencyAge>>
						<<set $activeSlave.pubertyAgeXY = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $potencyAge>>
						<<set $activeSlave.pubertyXY = 1>>
					<</if>>
				<</if>>
			<</if>>
			<<set $surgeryType = "addPigBalls">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.dick == 0>>
			<br><hr>
			@@.red;Could not implant pig testicles on $activeSlave.slaveName: she lacks a penis.@@
			<<set $completedOrgans.push(_slaveOrgans.pigTesticles)>>
		<<else>>
			<br><hr>
			@@.red;Could not implant pig testicles on $activeSlave.slaveName: she already has testicles.@@
			<<set $completedOrgans.push(_slaveOrgans.pigTesticles)>>
		<</if>>
	<</if>>
	/* dog testicles */
	<<if _slaveOrgans.dogTesticles != 0>>
		<<if ($activeSlave.dick >= 0) && ($activeSlave.balls == 0)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.balls = 2>>
			<<set $activeSlave.ballType = "dog">>
			<<set $activeSlave.scrotum = 2>>
			<<set $activeSlave.health -= 20>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 20>>
			<</if>>
			<<if $activeSlave.pubertyXY == 0>>
				<<if $precociousPuberty == 1>>
					<<if $activeSlave.physicalAge >= $potencyAge>>
						<<set $activeSlave.pubertyAgeXY = ($activeSlave.physicalAge+1)>>
					<</if>>
				<<else>>
					<<if $activeSlave.physicalAge >= $potencyAge>>
						<<set $activeSlave.pubertyXY = 1>>
					<</if>>
				<</if>>
			<</if>>
			<br><hr>
			<<set $surgeryType = "addDogBalls">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.dick == 0>>
			<br><hr>
			@@.red;Could not implant dog testicles on $activeSlave.slaveName: she lacks a penis.@@
			<<set $completedOrgans.push(_slaveOrgans.dogTesticles)>>
		<<else>>
			<br><hr>
			@@.red;Could not implant dog testicles on $activeSlave.slaveName: she already has testicles.@@
			<<set $completedOrgans.push(_slaveOrgans.dogTesticles)>>
		<</if>>
	<</if>>
	/* scrotum */
	<<if _slaveOrgans.scrotum != 0>>
		<<if ($activeSlave.scrotum == 0) && ($activeSlave.balls >= 1)>>
			<<set $cash -= $surgeryCost>>
			<<set $activeSlave.scrotum to $activeSlave.balls>>
			<<set $activeSlave.health -= 10>>
			<<if $organFarmUpgrade == 2>>
				<<set $activeSlave.chem += 10>>
			<</if>>
			<<set $surgeryType = "addScrotum">>
			<br><hr>
			<<include "Surgery Degradation">>
		<<elseif $activeSlave.balls == 0>>
			<br><hr>
			@@.red;Could not implant scrotum on $activeSlave.slaveName: she lacks testicles.@@
			<<set $completedOrgans.push(_slaveOrgans.scrotum)>>
		<<else>>
			<br><hr>
			@@.red;Could not implant scrotum on $activeSlave.slaveName: she already has a scrotum.@@
			<<set $completedOrgans.push(_slaveOrgans.scrotum)>>
		<</if>>
	<</if>>
	/* finished checking _slaveOrgans */
	/* limbs */
	<<if $slaves[_i].amp != 0>>
		<<for _l = 0; _l < $limbs.length; _l++>>
			<<if ($limbs[_l].ID == $slaves[_i].ID) && ($limbs[_l].weeksToCompletion <= 0)>>
				<<set $activeSlave = $slaves[_i]>>
				<<switch $limbs[_l].type>>
				<<case "simple">>
					<<set $activeSlave.amp = -1>>
					<<set $surgeryType = "basicPLimbs">>
				<<case "sex">>
					<<set $activeSlave.amp = -2>>
					<<set $surgeryType = "sexPLimbs">>
				<<case "beauty">>
					<<set $activeSlave.amp = -3>>
					<<set $surgeryType = "beautyPLimbs">>
				<<case "combat">>
					<<set $activeSlave.amp = -4>>
					<<set $surgeryType = "combatPLimbs">>
				<<case "cyber">>
					<<set $activeSlave.amp = -5>>
					<<set $surgeryType = "cyberPLimbs">>
				<</switch>>
				
				<<set $cash -= $surgeryCost>>
				<<set $activeSlave.health -= 10>>
				<br><hr>
				<<include "Surgery Degradation">>
				<<set $limbs.deleteAt(_l)>>

				<<set $slaves[_i] = $activeSlave>>
				<<break>>
			<</if>>
		<</for>>
	<</if>>
	/* updates the interrogated slave */
	<<set $slaves[_i] = $activeSlave>>
<</for>> /* end of the $slaves loop */

/* This needs to be down here to over-ride any Surgery Degradation calls */
<<set $nextButton = "Continue">>
<<set $nextLink = "Main">>

/* Clean-up */
<<set $limbsCompleted = 0>>
<<for _i = 0; _i < $limbs.length; _i++>>
	<<if $limbs[_i].weeksToCompletion <= 0>>
		<<set $limbsCompleted++>>
	<</if>>
<</for>>
