code:
:: StoryJS [script]

/*config.history.tracking = false;*/
window.variableAsNumber = function(x, defaultValue, minValue, maxValue) {
	x = Number(x)
	if (x != x) {//NaN
		return defaultValue || 0;//In case the default value was not supplied.
	}
	if (x < minValue) {//Works even if minValue is undefined.
		return minValue;
	}
	if (x > maxValue) {//Works even if maxValue is undefined.
		return maxValue;
	}
	return x;
};
window.isSexuallyPure = function(slave) {
	if (!slave) {
		return null;
	}
	if (slave.vagina < 1 && slave.anus < 1 && !slave.analCount && !slave.vaginalCount && !slave.oralCount) {
		return true;
	} else {
		return false;
	}
};
if (typeof interpolate == "undefined") {
	var interpolate = function(x0,y0,x1,y1,x) {
		if(x <= x0) {
			return y0;
		} else if(x >= x1) {
			return y1;
		} else {
			return (x - x0) * ((y1 - y0) / (x1 - x0)) + y0;
		}
	};
	window.interpolate = interpolate;
}
config.history.maxStates = 1;

config.saves.autosave = "autosave";
window.isFullyPotent = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.dick > 0 && slave.balls > 0 && slave.hormones <= 0) {
		return true;
	} else {
		return false;
	}
};

/* mousetrap v1.5.3 craig.is/killing/mice */
(function(C,r,g){function t(a,b,h){a.addEventListener?a.addEventListener(b,h,!1):a.attachEvent("on"+b,h)}function x(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return l[a.which]?l[a.which]:p[a.which]?p[a.which]:String.fromCharCode(a.which).toLowerCase()}function D(a){var b=[];a.shiftKey&&b.push("shift");a.altKey&&b.push("alt");a.ctrlKey&&b.push("ctrl");a.metaKey&&b.push("meta");return b}function u(a){return"shift"==a||"ctrl"==a||"alt"==a||
"meta"==a}function y(a,b){var h,c,e,g=[];h=a;"+"===h?h=["+"]:(h=h.replace(/\+{2}/g,"+plus"),h=h.split("+"));for(e=0;e<h.length;++e)c=h[e],z[c]&&(c=z[c]),b&&"keypress"!=b&&A[c]&&(c=A[c],g.push("shift")),u(c)&&g.push(c);h=c;e=b;if(!e){if(!k){k={};for(var m in l)95<m&&112>m||l.hasOwnProperty(m)&&(k[l[m]]=m)}e=k[h]?"keydown":"keypress"}"keypress"==e&&g.length&&(e="keydown");return{key:c,modifiers:g,action:e}}function B(a,b){return null===a||a===r?!1:a===b?!0:B(a.parentNode,b)}function c(a){function b(a){a=
a||{};var b=!1,n;for(n in q)a[n]?b=!0:q[n]=0;b||(v=!1)}function h(a,b,n,f,c,h){var g,e,l=[],m=n.type;if(!d._callbacks[a])return[];"keyup"==m&&u(a)&&(b=[a]);for(g=0;g<d._callbacks[a].length;++g)if(e=d._callbacks[a][g],(f||!e.seq||q[e.seq]==e.level)&&m==e.action){var k;(k="keypress"==m&&!n.metaKey&&!n.ctrlKey)||(k=e.modifiers,k=b.sort().join(",")===k.sort().join(","));k&&(k=f&&e.seq==f&&e.level==h,(!f&&e.combo==c||k)&&d._callbacks[a].splice(g,1),l.push(e))}return l}function g(a,b,n,f){d.stopCallback(b,
b.target||b.srcElement,n,f)||!1!==a(b,n)||(b.preventDefault?b.preventDefault():b.returnValue=!1,b.stopPropagation?b.stopPropagation():b.cancelBubble=!0)}function e(a){"number"!==typeof a.which&&(a.which=a.keyCode);var b=x(a);b&&("keyup"==a.type&&w===b?w=!1:d.handleKey(b,D(a),a))}function l(a,c,n,f){function e(c){return function(){v=c;++q[a];clearTimeout(k);k=setTimeout(b,1E3)}}function h(c){g(n,c,a);"keyup"!==f&&(w=x(c));setTimeout(b,10)}for(var d=q[a]=0;d<c.length;++d){var p=d+1===c.length?h:e(f||
y(c[d+1]).action);m(c[d],p,f,a,d)}}function m(a,b,c,f,e){d._directMap[a+":"+c]=b;a=a.replace(/\s+/g," ");var g=a.split(" ");1<g.length?l(a,g,b,c):(c=y(a,c),d._callbacks[c.key]=d._callbacks[c.key]||[],h(c.key,c.modifiers,{type:c.action},f,a,e),d._callbacks[c.key][f?"unshift":"push"]({callback:b,modifiers:c.modifiers,action:c.action,seq:f,level:e,combo:a}))}var d=this;a=a||r;if(!(d instanceof c))return new c(a);d.target=a;d._callbacks={};d._directMap={};var q={},k,w=!1,p=!1,v=!1;d._handleKey=function(a,
c,e){var f=h(a,c,e),d;c={};var k=0,l=!1;for(d=0;d<f.length;++d)f[d].seq&&(k=Math.max(k,f[d].level));for(d=0;d<f.length;++d)f[d].seq?f[d].level==k&&(l=!0,c[f[d].seq]=1,g(f[d].callback,e,f[d].combo,f[d].seq)):l||g(f[d].callback,e,f[d].combo);f="keypress"==e.type&&p;e.type!=v||u(a)||f||b(c);p=l&&"keydown"==e.type};d._bindMultiple=function(a,b,c){for(var d=0;d<a.length;++d)m(a[d],b,c)};t(a,"keypress",e);t(a,"keydown",e);t(a,"keyup",e)}var l={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",
20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},p={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},A={"~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},z={option:"alt",command:"meta","return":"enter",
escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},k;for(g=1;20>g;++g)l[111+g]="f"+g;for(g=0;9>=g;++g)l[g+96]=g;c.prototype.bind=function(a,b,c){a=a instanceof Array?a:[a];this._bindMultiple.call(this,a,b,c);return this};c.prototype.unbind=function(a,b){return this.bind.call(this,a,function(){},b)};c.prototype.trigger=function(a,b){if(this._directMap[a+":"+b])this._directMap[a+":"+b]({},a);return this};c.prototype.reset=function(){this._callbacks={};this._directMap=
{};return this};c.prototype.stopCallback=function(a,b){return-1<(" "+b.className+" ").indexOf(" mousetrap ")||B(b,this.target)?!1:"INPUT"==b.tagName||"SELECT"==b.tagName||"TEXTAREA"==b.tagName||b.isContentEditable};c.prototype.handleKey=function(){return this._handleKey.apply(this,arguments)};c.init=function(){var a=c(r),b;for(b in a)"_"!==b.charAt(0)&&(c[b]=function(b){return function(){return a[b].apply(a,arguments)}}(b))};c.init();C.Mousetrap=c;"undefined"!==typeof module&&module.exports&&(module.exports=
c);"function"===typeof define&&define.amd&&define(function(){return c})})(window,document);

Mousetrap.bind("enter", function () {
	$("#story-caption #endWeekButton a.macro-link").trigger("click");
});
Mousetrap.bind("space", function () {
	$("#story-caption #nextButton a.macro-link").trigger("click");
});
Mousetrap.bind("c", function () {
	$("#story-caption #manageArcology a.macro-link").trigger("click");
});
Mousetrap.bind("p", function () {
	$("#story-caption #managePenthouse a.macro-link").trigger("click");
});
Mousetrap.bind("left", function () {
	$("#prevSlave a.macro-link").trigger("click");
	$("#prevRule a").trigger("click");
});
Mousetrap.bind("q", function () {
	$("#prevSlave a.macro-link").trigger("click");
	$("#prevRule a").trigger("click");
});
Mousetrap.bind("shift+left", function () {
	$("#firstRule a").trigger("click");
});
Mousetrap.bind("shift+q", function () {
	$("#firstRule a").trigger("click");
});
Mousetrap.bind("right", function () {
	$("#nextSlave a.macro-link").trigger("click");
	$("#nextRule a").trigger("click");
});
Mousetrap.bind("shift+right", function () {
	$("#lastRule a").trigger("click");
});
Mousetrap.bind("e", function () {
	$("#nextSlave a.macro-link").trigger("click");
	$("#nextRule a").trigger("click");
});
Mousetrap.bind("shift+e", function () {
	$("#lastRule a").trigger("click");
});
Mousetrap.bind("f", function () {
	$("#walkpast a.macro-link").trigger("click");
});
Mousetrap.bind("h", function () {
	$("#manageHG a.macro-link").trigger("click");
});
Mousetrap.bind("s", function () {
	$("#buySlaves a.macro-link").trigger("click");
});
Mousetrap.bind("a", function () {
	$("#managePA a.macro-link").trigger("click");
});
Mousetrap.bind("b", function () {
	$("#manageBG a.macro-link").trigger("click");
});
Mousetrap.bind("u", function () {
	$("#manageRecruiter a.macro-link").trigger("click");
});
Mousetrap.bind("o", function () {
	$("#story-caption #optionsButton a.macro-link").trigger("click");
});
Mousetrap.bind("y", function () {
	$("#story-caption #policyButton a.macro-link").trigger("click");
});
Mousetrap.bind("f", function () {
	$("#story-caption #FSButton a.macro-link").trigger("click");
});
Mousetrap.bind("t", function () {
	$("#story-caption #PAOButton a.macro-link").trigger("click");
});
Mousetrap.bind("v", function () {
	$("#story-caption #URButton a.macro-link").trigger("click");
});
Mousetrap.bind("r", function () {
	$("#RAButton a.macro-link").trigger("click");
});
Mousetrap.bind("x", function () {
	$("#story-caption #managePerson a.macro-link").trigger("click");
});

/**
 * BoobGenerator namespace.
 */
if (typeof BoobGenerator == "undefined") {
	var BoobGenerator = {
		rollBreast: function (modif) {
			var volume = [0, 300, 500, 650, 800, 1000, 1200, 1400, 1600, 1800, 2050, 2300, 2600, 2900, 3250, 3600, 3950, 4300, 4700, 5100, 5500, 5900];
			var volume_dist = [90000, 470000, 720000, 840000, 908574, 947759, 970151, 982946, 990258, 994436, 996824, 998188, 998968, 999414, 999669, 999814, 999897, 999945, 999972, 999987, 999995, 1000000];
			var randomRoll = Math.floor(Math.random() * 1000000) + 1
			var actualSize = 0
			while (randomRoll > volume_dist[actualSize]) {
				actualSize = actualSize + 1
			}
			var minorSizeAdjustment = 0
			if (Math.random()<.5) {
				minorSizeAdjustment = (Math.floor(Math.random() * 2) + 1) * 50
			}
			var volResult = volume[actualSize] + minorSizeAdjustment + modif
			if (volResult < 0) {volResult = 0}
			return volResult
		}
	};
	// Raise namespace scope to Global.
	window.BoobGenerator = BoobGenerator;
};

/**
 * Slave checker namespace.
 */
if (typeof SlaveStatsChecker == "undefined") {
	var SlaveStatsChecker = {
		checkForLisp: function (slave) {
				/* Begin mod section: toggle whether slaves lisp. */
				if (SugarCube.State && SugarCube.State.variables.disableLisping == 1) {
					return false;
				}
				/* End mod section: toggle whether slaves lisp. */
				return ((slave.lips > 70) || (slave.lipsPiercing + slave.tonguePiercing > 2))
			}
	};
	// Raise namespace scope to Global.
	window.SlaveStatsChecker = SlaveStatsChecker;
};

window.removeFromArray = function(arr, val) {
	for (var i = 0; i < arr.length; i++) {
		if (val == arr[i])
			return arr.splice(i,1);
	}
	return null;
};

window.filterInPlace = function(arr, callback, thisArg) {
	var j = 0;

	arr.forEach(function(e, i) {
		if (callback.call(thisArg, e, i, arr))
			arr[j++] = e;
	});

	arr.length = j;
	return arr;
};

if (typeof FertilityAge == "undefined") {
	var FertilityAge = {
		setAge: function (age) {
			age = Number(age)
				if (age != age) {
					return 13;
				} else {
				return age
			}
		}
	};
	// Raise namespace scope to Global.
	window.FertilityAge = FertilityAge;
};

window.canGetPregnant = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg == -1) { /* contraceptives check */
		return false;
	} else if (isFertile(slave) == false) { /* check other fertility factors */
		return false;
	} else if ((slave.ovaries == 1) && (canDoVaginal(slave) == true)) {
		return true;
	} else if ((slave.mpreg == 1) && (canDoAnal(slave) == true)) { /* pregmod */
		return true;
	} else {
		return false;
	}
};

/* pregmod: are slave2's sperm compatible with slave1's eggs? */
window.canBreed = function(slave1, slave2) {
	if (!slave1 || !slave2) {
		return null;
	} else if (slave1.eggType == slave2.ballType) {
		return true;
	} else {
		return false;
	}
};

/* assuming slave1 is fertile, could slave2 impregnate slave1? slave2 must have dick and balls with compatible sperm; both slaves must not be in chastity; slave2 need not achieve erection */
window.canImpreg = function(slave1, slave2) {
	if (!slave1 || !slave2) {
		return null;
	} else if (slave2.dick < 1) {
		return false;
	} else if (slave2.balls < 1) {
		return false;
	} else if (slave2.dickAccessory == "chastity") {
		return false;
	} else if (slave2.dickAccessory == "combined chastity") {
		return false;
	} else if (slave2.pubertyXY == 0) { /* pregmod start */
		return false;
	} else if (slave2.vasectomy == 1) {
		return false;
	} else if (canBreed(slave1, slave2) == false) {
		return false;                   /* pregmod end */
	} else if (canGetPregnant(slave1) == false) { /* includes chastity checks */
		return false;
	} else {
		return true;
	}
};

/* contraceptives (.preg == -1) do not negate this function */
window.isFertile = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 0) { /* currently pregnant */
		return false;
	} else if (slave.preg < -1) { /* sterile */
		return false;
	} else if (slave.pubertyXX == 0) { /* pregmod start */
		return false;
	} else if (slave.ovaryAge >= 47) {
		return false;
	} else if (slave.inflation != 0) {
		return false;
	} else if (slave.bellyImplant != -1) {
		return false;
	} else if (slave.mpreg == 1) {
		return true;                   /* pregmod end */
	} else if (slave.ovaries == 1) {
		return true;
	} else {
		return false;
	}
};

//hyperpreg size 2
window.hyperBellyTwo = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 30 && slave.pregType >= 20) {
		return true;
	} else if (slave.bellyImplant >= 32000) {
		return true;
	} else {
		return false;
	}
};

window.hyperPregBellyTwo = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 30 && slave.pregType >= 20) {
		return true;
	} else {
		return false;
	}
};

//hyperpreg size 1
window.hyperBellyOne = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 20 && slave.pregType >= 20) {
		return true;
	} else if (slave.preg > 30 && slave.pregType >= 10) {
		return true;
	} else if (slave.bellyImplant >= 16000) {
		return true;
	} else {
		return false;
	}
};

window.hyperPregBellyOne = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 20 && slave.pregType >= 20) {
		return true;
	} else if (slave.preg > 30 && slave.pregType >= 10) {
		return true;
	} else {
		return false;
	}
};

//full term belly
window.hugeBelly = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 0 && slave.pregType >= 20) {
		return true;
	} else if (slave.preg > 10 && slave.pregType >= 10) {
		return true;
	} else if (slave.preg > 30) {
		return true;
	} else if (slave.inflation >= 3) {
		return true;
	} else if (slave.bellyImplant >= 8000) {
		return true;
	} else {
		return false;
	}
};

window.hugeBellyPreg = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 0 && slave.pregType >= 20) {
		return true;
	} else if (slave.preg > 10 && slave.pregType >= 10) {
		return true;
	} else if (slave.preg > 30) {
		return true;
	} else {
		return false;
	}
};

//is the slave's belly big enough to get in the way
window.bigBellyPreg = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 0 && slave.pregType >= 20) {
		return true;
	} else if (slave.preg > 10 && slave.pregType >= 10) {
		return true;
	} else if (slave.preg > 20) {
		return true;
	} else {
		return false;
	}
};

//is the slave's belly big enough to be noticiable.
window.visibleBellyPreg = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.preg > 0 && slave.pregType >= 20) {
		return true;
	} else if (slave.preg > 5 && slave.pregType >= 10) {
		return true;
	} else if (slave.preg > 10) {
		return true;
	} else {
		return false;
	}
};

window.bigBelly = function(slave) {
	if (!slave) {
		return null;
	} else if (bigBellyPreg(slave) == true) {
		return true;
	} else if (slave.inflation > 2) {
		return true;
	} else if (slave.bellyImplant >= 4000) {
		return true;
	} else {
		return false;
	}
};

window.visibleBelly = function(slave) {
	if (!slave) {
		return null;
	} else if (visibleBellyPreg(slave) == true) {
		return true;
	} else if (slave.inflation > 0) {
		return true;
	} else if (slave.bellyImplant >= 2000) {
		return true;
	} else {
		return false;
	}
};

window.canAchieveErection = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.dick < 7 && slave.dick > 0 && (slave.balls > 0 ? slave.hormones <= 0 : slave.hormones < 0)) {
		return true;
	} else {
		return false;
	}
};

window.canPenetrate = function(slave) {
	if (!slave) {
		return null;
	} else if (canAchieveErection(slave) == false) {
		return false;
	} else if (slave.dickAccessory == "chastity") {
		return false;
	} else if (slave.dickAccessory == "combined chastity") {
		return false;
	} else if (slave.dick > 7) {
		return false;
	}
	return true;
};

window.canSee = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.eyes > -2) {
		return true;
	} else {
		return false;
	}
};

window.canWalk = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.amp == 1)  {
		return false;
	} else if (tooFatSlave(slave)) {
		return false;
	} else if (tooBigBreasts(slave)) {
		return false;
	} else if (tooBigDick(slave)) {
		return false;
	} else if (tooBigBalls(slave)) {
		return false;
	} else if (tooBigButt(slave)) {
		return false;
	} else if (tooBigBelly(slave)) {
		return false;
	} else if (slave.heels == 0) {
		return true;
	} else if (slave.shoes == "heels") {
		return true;
	} else if (slave.shoes == "extreme heels") {
		return true;
	} else if (slave.shoes == "boots") {
		return true;
	} else {
		return false;
	}
};

window.canTalk = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.accent > 2)  {
		return false;
	} else if (slave.voice == 0) {
		return false;
	} else if (slave.lips > 95) {
		return false;
	} else if (slave.collar == "dildo gag") {
		return false;
	} else if (slave.collar == "massive dildo gag") {
		return false;
	} else if (slave.collar == "ball gag") {
		return false;
	} else if (slave.collar == "bit gag") {
		return false;
	} else {
		return true;
	}
};

window.canDoAnal = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.vaginalAccessory == "anal chastity") {
		return false;
	} else if (slave.dickAccessory == "anal chastity") {
		return false;
	} else if (slave.vaginalAccessory == "combined chastity") {
		return false;
	} else if (slave.dickAccessory == "combined chastity") {
		return false;
	}
	return true;
};

window.canDoVaginal = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.vagina < 0) {
		return false;
	} else if (slave.vaginalAccessory == "chastity belt") {
		return false;
	} else if (slave.vaginalAccessory == "combined chastity") {
		return false;
	}
	return true;
};

window.tooFatSlave = function(slave){
	if (!slave) {
		return null;
	} else if (slave.weight > 190+(slave.muscles/5) && slave.physicalAge >= 18) {
		return true;
	} else if (slave.weight > 130+(slave.muscles/20) && slave.physicalAge <= 3) {
		return true;
	} else if (slave.weight > 160+(slave.muscles/15) && slave.physicalAge <= 12) {
		return true;
	} else if (slave.weight > 185+(slave.muscles/10) && slave.physicalAge < 18) {
		return true;
	} else {
		return false;
	}
};

window.tooBigBreasts = function(slave){
	if (!slave) {
		return null;
	} else if (slave.boobs > 30000+(slave.muscles*100) && slave.physicalAge >= 18) {
		return true;
	} else if (slave.boobs > 5000+(slave.muscles*10) && slave.physicalAge <= 3) {
		return true;
	} else if (slave.boobs > 10000+(slave.muscles*20) && slave.physicalAge <= 12) {
		return true;
	} else if (slave.boobs > 20000+(slave.muscles*50) && slave.physicalAge < 18) {
		return true;
	} else {
		return false;
	}
};

window.tooBigBelly = function(slave){
	if (!slave) {
		return null;
	} else if (slave.belly >= 450000+(slave.muscles*2000) && slave.physicalAge >= 18) {
		return true;
	} else if (slave.belly >= 350000+(slave.muscles*1000) && slave.physicalAge >= 13) {
		return true;
	} else if (slave.belly >= 150000+(slave.muscles*500) && slave.physicalAge <= 3) {
		return true;
	} else if (slave.belly >= 250000+(slave.muscles*800) && slave.physicalAge <= 12) {
		return true;
	} else if (slave.bellyImplant > 31000+(slave.muscles*100) && slave.physicalAge >= 18) {
		return true;
	} else if (slave.bellyImplant > 31000+(slave.muscles*80) && slave.physicalAge >= 13) {
		return true;
	} else if (slave.bellyImplant > 12000+(slave.muscles*20) && slave.physicalAge <= 3) {
		return true;
	} else if (slave.bellyImplant > 16000+(slave.muscles*50) && slave.physicalAge <= 12) {
		return true;
	} else {
		return false;
	}
};

window.tooBigBalls = function(slave){
	if (!slave) {
		return null;
	} else if (slave.balls >= 30+(slave.muscles*.3) && slave.physicalAge <= 3) {
		return true;
	} else if (slave.balls >= 60+(slave.muscles*.5) && slave.physicalAge <= 12) {
		return true;
	} else if (slave.balls >= 90+(slave.muscles*.7)) {
		return true;
	} else {
		return false;
	}
};

window.tooBigDick = function(slave){
	if (!slave) {
		return null;
	} else if (slave.dick >= 15+(slave.muscles*.1) && slave.physicalAge <= 3 && slave.dick !== 0) {
		return true;
	} else if (slave.dick >= 30+(slave.muscles*.3) && slave.physicalAge <= 12) {
		return true;
	} else if (slave.dick >= 68+(slave.muscles*.4)) {
		return true;
	} else {
		return false;
	}
};

window.tooBigButt = function(slave){
	if (!slave) {
		return null;
	} else if (slave.butt > 10 && slave.physicalAge <= 3) {
		return true;
	} else if (slave.butt > 14 && slave.physicalAge <= 12) {
		return true;
	} else {
		return false;
	}
};

window.relationTargetWord = function(slave) {
	if (!slave) {
		return null;
	} else if (slave.relation == "daughter") {
		return "mother";
	} else if (slave.relation == "mother") {
		return "daughter";
	}
	return slave.relation;
};

window.ruleApplied = function(slave, ID) {
	if (!slave || !slave.currentRules)
		return null;
	return slave.currentRules.includes(ID);
};

window.expandFacilityAssignments = function(facilityAssignments) {
	var assignmentPairs = {
		"serve in the club": "be the DJ",
		"rest in the spa": "be the Attendant",
		"work in the brothel": "be the Madam",
		"work in the dairy": "be the Milkmaid",
		"work as a servant": "be the Stewardess",
		"get treatment in the clinic": "be the Nurse",
		"live with your Head Girl": "be your Head Girl",
		"serve in the master suite": "be your Concubine",
		"learn in the schoolroom": "be the Schoolteacher",
		"be confined in the cellblock": "be the Wardeness",
	};

	if (!facilityAssignments || !facilityAssignments.length)
		return [];
	var fullList = facilityAssignments.map(function(a) {
		if (a in assignmentPairs)
			return [a, assignmentPairs[a]];
		return a;
	});
	return fullList.flatten();
};

window.ruleSlaveSelected = function(slave, rule) {
	if (!slave || !rule || !rule.selectedSlaves)
		return false;
	return rule.selectedSlaves.includes(slave.ID);
};

window.ruleSlaveExcluded = function(slave, rule) {
	if (!slave || !rule || !rule.excludedSlaves)
		return false;
	return rule.excludedSlaves.includes(slave.ID);
};

window.ruleAssignmentSelected = function(slave, rule) {
	if (!slave || !rule || (!rule.assignment && !rule.facility))
		return false;
	var assignment = rule.assignment.concat(expandFacilityAssignments(rule.facility));
	return assignment.includes(slave.assignment);
}

window.ruleAssignmentExcluded = function(slave, rule) {
	if (!slave || !rule || (!rule.excludeAssignment && !rule.excludeFacility))
		return false;
	var excludeAssignment = rule.excludeAssignment.concat(expandFacilityAssignments(rule.excludeFacility));
	return excludeAssignment.includes(slave.assignment);
}

window.hasSurgeryRule = function(slave, rules) {
	if (!slave || !rules || !slave.currentRules)
		return false;

	for (var d = rules.length-1; d >= 0; d--) {
		if (ruleApplied(slave, rules[d].ID)) {
			if (rules[d].autoSurgery > 0) {
				return true;
			}
		}
	}
	return false;
};

window.hasRuleFor = function(slave, rules, what) {
	if (!slave || !rules || !slave.currentRules)
		return false;

	for (var d = rules.length-1; d >= 0; d--) {
		if (ruleApplied(slave, rules[d].ID)) {
			if (rules[d][what] !== "no default setting") {
				return true;
			}
		}
	}
	return false;
};

window.hasHColorRule = function(slave, rules) {
	return hasRuleFor(slave, rules, "hColor");
}

window.hasHStyleRule = function(slave, rules) {
	return hasRuleFor(slave, rules, "hStyle");
};

window.hasEyeColorRule = function(slave, rules) {
	return hasRuleFor(slave, rules, "eyeColor");
};

window.lastPregRule = function(slave, rules) {
	if (!slave || !rules)
		return null;
	if (!slave.currentRules)
		return false;

	for (var d = rules.length-1; d >= 0; d--) {
		if (ruleApplied(slave, rules[d].ID)) {
			if (rules[d].preg == -1) {
				return true;
			}
		}
	}

	return null;
};

window.lastSurgeryRuleFor = function(slave, rules, what) {
	if (!slave || !rules || !slave.currentRules)
		return null;

	for (var d = rules.length-1; d >= 0; d--) {
		if (!rules[d].surgery)
			return null;

		if (ruleApplied(slave, rules[d].ID)) {
			if (rules[d].surgery[what] != "no default setting") {
				return rules[d];
			}
		}
	}

	return null;
};

window.lastLactationSurgeryRule = function(slave, rules) {
	return lastSurgeryRuleFor(slave, rules, "lactation");
}

window.lastProstateSurgeryRule = function(slave, rules) {
	return lastSurgeryRuleFor(slave, rules, "prostate");
}

window.lastLipSurgeryRule = function(slave, rules) {
	return lastSurgeryRuleFor(slave, rules, "lips");
};

window.lastBoobSurgeryRule = function(slave, rules) {
	return lastSurgeryRuleFor(slave, rules, "boobs");
};

window.lastButtSurgeryRule = function(slave, rules) {
	return lastSurgeryRuleFor(slave, rules, "butt");
};

window.milkAmount = function(slave) {
	var milk;
	var calcs;
	if (!slave) {
		return null;
	} else {
		calcs = slave.boobs-slave.boobsImplant
		if (calcs > 40000) {
			milk = (158+((calcs-10000)/600))
		} else if (calcs > 25000) {
			milk = (128+((calcs-10000)/500))
		} else if (calcs > 10000) {
			milk = (78+((calcs-10000)/300))
		} else if (calcs > 5000) {
			milk = (53+((calcs-5000)/200))
		} else if (calcs > 2000) {
			milk = (29+((calcs-2000)/125))
		} else if (calcs > 800) {
			milk = (16+((calcs-800)/80))
		} else {
			milk = (8+((calcs-400)/50))
		}
		if (slave.lactation == 2) {
			milk *= 1.2
		}
		milk += (milk*((slave.devotion-50)/200))
		if (slave.boobsImplant > 200) {
			milk *= 0.9
		}
		calcs = slave.hormones
		if (slave.balls != 0 && calcs > -2) {
			calcs -= 1
		} else if (slave.ovaries != 1 && calcs < 2) {
			calcs += 1
		}
		milk *= (1+(calcs*0.1))
		milk *= (1+(slave.preg/100))
		milk *= (1+(slave.health/50))
		milk *= (1+(slave.weight/500))
		milk *= (1+(slave.lactationAdaptation/500))
		milk = Math.trunc(milk)
		milk = Math.clamp(milk,1,1000000000000000000)
		return milk
	}
};

window.cumAmount = function(slave) {
	var cum = 0;
	var calcs = 0;
	if (!slave) {
		return null;
	} else {
		if (slave.drugs == "testicle enhancement") {
			cum = ((slave.balls*3.5)+1)
		} else if (slave.drugs == "hyper testicle enhancement") {
			cum = ((slave.balls*5)+1)
		} else {
			cum = ((slave.balls*2.5)+1)
		}
		if (slave.diet == "cum production") {
			cum *= 1.2
		}
		calcs = slave.hormones
		cum *= (1-(calcs*0.1))
		if (slave.scrotum == 0) {
			cum *= 0.8
		}
		if (slave.prostate == 0) {
			cum *= 0.2 // being generous here
		} else if (slave.prostate == 2) {
			cum *= 1.2
		} else if (slave.prostate == 3) {
			cum *= 1.5
		}
		if (slave.devotion > 50) {
			cum += (cum*(slave.devotion/100))
		} else if (slave.devotion < -50) {
			cum += (cum*(slave.devotion/100))
		}
		if (slave.health > 50) {
			cum += (cum*(slave.health/50))
		} else if (slave.health < -50) {
			cum += (cum*(slave.health/50))
		}
		cum = Math.trunc(cum)
		cum = Math.clamp(cum,1,1000000000000000000)
		return cum
	}
};

window.mergeRules = function(rules) {
    var combinedRule = {};

    for (var i = 0; i < rules.length; i++) {
        for (var prop in rules[i]) {
            // we don't manage setAssignment here, we do it in <<DefaultRules>>
            if (prop === "setAssignment")
                continue;

            // A rule overrides any preceding ones if,
            //   * there are no preceding ones,
            //   * or it sets autoBrand,
            //   * or it does not set autoBrand and is not "no default setting"
            var applies = (
                combinedRule[prop] === undefined
                || (prop === "autoBrand" && rules[i][prop])
                || (prop !== "autoBrand" && rules[i][prop] !== "no default setting")
            );

            if (applies)
                combinedRule[prop] = rules[i][prop];
        }
    }

    return combinedRule;
}

window.isVegetable = function(slave) {
	slave = slave || State.variables.activeSlave;
	if(!slave) { return false; }
	return (slave.fetish === 'mindbroken');
};

window.repGainSacrifice = function(slave, arcology) {
	slave = slave || State.variables.activeSlave;
	arcology = arcology || State.variables.arcologies[0];
	if(!slave || !arcology || arcology.FSAztecRevivalist === "unset" || arcology.FSAztecRevivalist <= 0) {
		return 0;
	}
	return Math.ceil(
		(Math.min(100, Math.pow(1.0926, State.variables.week - slave.weekAcquired)) + slave.prestige * 30)
			* arcology.FSAztecRevivalist / 100 / ((State.variables.slavesSacrificedThisWeek || 0) + 1));
};

window.ngUpdateGenePool = function(genePool) {
  var transferredSlaveIds = (SugarCube.State.variables.slaves || [])
    .filter(function(s) { return s.ID >= 1200000; })
    .map(function(s) { return s.ID - 1200000; });
  return (genePool || [])
    .filter(function(s) { return transferredSlaveIds.indexOf(s.ID) >= 0; })
    .map(function(s) {
      var result = jQuery.extend(true, {}, s);
      result.ID += 1200000;
      return result;
    });
}

window.toJson = function(obj) {
    var jsontext = JSON.stringify(obj);
    jsontext = jsontext.replace(/^{/,"");
    jsontext = jsontext.replace(/}$/,"");
    return jsontext;
};

window.nippleColor = function(slave) {
	slave = slave || State.variables.activeSlave;
	if(slave.skin === 'tanned' || slave.skin === 'fair') {
		if(slave.preg > 10 || (slave.birthsTotal > 0 && slave.lactation > 0)) {
			return 'dark brown';
		} else {
			return 'pink';
		}
	} else if((slave.skin === 'pale' || slave.race === 'white')) {
		if(slave.preg > 10 || (slave.birthsTotal > 0 && slave.lactation > 0)) {
			return 'brown';
		} else {
			return 'pink';
		}
	} else if((slave.skin === 'brown' || slave.race === 'black')) {
		if(slave.preg > 10 || (slave.birthsTotal > 0 && slave.lactation > 0)) {
			return 'black';
		} else {
			return 'dark brown';
		}
	} else {
		if(slave.preg > 10 || (slave.birthsTotal > 0 && slave.lactation > 0)) {
			return 'dark brown';
		} else {
			return 'brown';
		}
	}
}

window.jsAlert = function(obj)
{
	alert(obj);
}

window.jsConsoleInfo = function(obj)
{
	console.info(obj);
}


code:
:: textinput [script]

Macro.add("textinput", {
    // Signifies that the macro is a container macro.
    tags: null,

    handler: function() {
        if (this.args.length < 2) {
            var errors = [];
            if (this.args.length < 1) { errors.push("variable name"); }
            if (this.args.length < 2) { errors.push("default value"); }
            return this.error("no " + errors.join(" or ") + " specified");
        }

        // Ensure that the variable name argument is a string.
        if (typeof this.args[0] !== "string") {
            return this.error("variable name argument is not a string");
        }

        var varName = this.args[0].trim();

        // Try to ensure that we receive the variable's name (incl. sigil), not its value.
        if (varName[0] !== "$" && varName[0] !== "_") {
            return this.error("variable name '" + varName + "' is missing its sigil ($ or _)");
        }

        var that = this;
        var defaultValue = this.args[1];
        var el = document.createElement("textarea");

        // Setup and append the textarea element to the output buffer.
        jQuery(el)
            .attr({
                rows: 4,
                // cols: 68, // instead of setting "cols" we set the `min-width` in CSS
                tabindex: 0 // for accessiblity
            })
            .addClass("macro-textarea")  // "hijack" the .macro-textarea class
            .on("input", function() {
                Wikifier.setValue(varName, this.value);
                if (that.payload[0].contents !== "")
                    Wikifier.wikifyEval(that.payload[0].contents.trim());
            })
            .appendTo(this.output);

        // Set the story variable and textarea element to the default value.
        Wikifier.setValue(varName, defaultValue);

        // Ideally, we should be setting `.defaultValue` here, but IE doesn't support it,
        // so we have to use `.textContent`, which is equivalent.
        el.textContent = defaultValue;
    }
});

license: mit


code:
:: textboxJS [script]

/* Nicked off greyelf, works for replace textboxes */
window.setReplaceTextboxMaxLength = function (storyVarName, maxLength) {
	var textboxId = '#textbox-' + Util.slugify(storyVarName);
	$(textboxId)
			.attr('maxlength', maxLength)
			.css({
				'min-width' : 'initial',
				width       : maxLength + 'em',
				padding		: '3px 2px'
			});
};

/* Nicked off TheMadExile, works for non-replace textboxes */
window.setTextboxMaxLength = function (storyVarName, maxLength) {
	var textboxId = '#textbox-' + Util.slugify(storyVarName);
	postdisplay[textboxId + '-maxlength'] = function (taskName) {
		delete postdisplay[taskName];
		$(textboxId)
			.attr('maxlength', maxLength)
			.css({
				'min-width' : 'initial',
				width       : maxLength + 'em',
				padding		: '3px 2px'
			});
	};
};


code:
:: UtilJS [script]

/*
 * Height.mean(nationality, race, genes, age) - returns the mean height for the given combination and age in years (>=2)
 * Height.mean(nationality, race, genes) - returns the mean adult height for the given combination
 * Height.mean(slave) - returns the mean (expected) height for the given slave
 *
 * Height.random(nationality, race, genes, age) - returns a random height for the given combination,
 *     with Gaussian distribution (mean = 1, standard deviation = 0.05) around the mean height
 * Height.random(nationality, race, genes) - returns a random height for the given combination of an adult, as above
 * Height.random(slave[, options]) - returns a random height for the given slave, as above.
 *                                   The additional options object can modify how the values are generated
 *                                   in the same way setting them as global configuration would, but only for this
 *                                   specific generation.
 *
 *                                   Example: Only generate above-average heights based on $activeSlave:
 *                                   Height.random($activeSlave, {limitMult: [0, 5]})
 *
 * Height.forAge(height, age, genes) - returns the height adapted to the age and genes
 * Height.forAge(height, slave) - returns the height adapted to the slave's age and genes
 *
 * Height.config(configuration) - configures the random height generator globally and returns the current configuration
 *   The options and their default values are:
 *   limitMult: [-3, 3] - Limit to the values the underlying (normal) random generator returns.
 *                        In normal use, the values are almost never reached; only 0.27% of values are
 *                        outside this range and need to be regenerated. With higher skew (see below),
 *                        this might change.
 *   spread: 0.05 - The random values generated are multiplied by this and added to 1 to generate
 *                  the final height multiplier. The default value together with the default limitMult
 *                  means that the generated height will always fall within (1 - 0.05 * 3) = 85% and
 *                  (1 + 0.05 * 3) = 115% of the mean height.
 *                  Minimum value: 0.001; maximum value: 0.5
 *   skew: 0 - How much the height distribution skews to the right (positive) or left (negative) side
 *             of the height.
 *             Minimum value: -1000, maximum value: 1000
 *   limitHeight: [0, 999] - Limit the resulting height range. Warning: A small height limit range
 *                           paired with a high spread value results in the generator having to
 *                           do lots of work generating and re-generating random heights until
 *                           one "fits".
 */
window.Height = (function(){
	'use strict';

	// Global configuration (for different game modes/options/types)
	var minMult = -3.0;
	var maxMult = 3.0;
	var skew = 0.0;
	var spread = 0.05;
	var minHeight = 0;
	var maxHeight = 999;

	// Configuration method for the above values
	const _config = function(conf) {
		if(_.isUndefined(conf)) {
			return {limitMult: [minMult, maxMult], limitHeight: [minHeight, maxHeight], skew: skew, spread: spread};
		}
		if(_.isFinite(conf.skew)) { skew = Math.clamp(conf.skew, -1000, 1000); }
		if(_.isFinite(conf.spread)) { spread = Math.clamp(conf.spread, 0.001, 0.5); }
		if(_.isArray(conf.limitMult) && conf.limitMult.length === 2 && conf.limitMult[0] !== conf.limitMult[1]
			&& _.isFinite(conf.limitMult[0]) && _.isFinite(conf.limitMult[1])) {
			minMult = Math.min(conf.limitMult[0], conf.limitMult[1]);
			maxMult = Math.max(conf.limitMult[0], conf.limitMult[1]);
		}
		if(_.isArray(conf.limitHeight) && conf.limitHeight.length === 2 && conf.limitHeight[0] !== conf.limitHeight[1]
			&& _.isFinite(conf.limitHeight[0]) && _.isFinite(conf.limitHeight[1])) {
			minHeight = Math.min(conf.limitHeight[0], conf.limitHeight[1]);
			maxHeight = Math.max(conf.limitHeight[0], conf.limitHeight[1]);
		}
		return {limitMult: [minMult, maxMult], limitHeight: [minHeight, maxHeight], skew: skew, spread: spread};
	}

	const xxMeanHeight = {
		"American.white": 165, "American.black": 163.6, "American.latina": 158.9, "American.asian": 158.4, "American": 161.8,
		"Afghan": undefined, "Algerian": 162, "Argentinian": 159.6, "Armenian": undefined, "Australian": 161.8, "Austrian": 166,
		"Bangladeshi": undefined, "Belarusian": 166.8, "Belgian": 168.1, "Bolivian": 142.2, "Brazilian": 158.8,
		"British": 161.9, "Burmese": undefined, "Canadian": 162.3, "Chilean": 157.2, "Chinese": 155.8, "Colombian": 158.7,
		"Congolese": 157.7, "Cuban": 156, "Czech": 167.22, "Danish": 168.7, "Dominican": 156.4, "Dutch": 169, "Egyptian": 158.9,
		"Emirati": 158.9, "Estonian": 165.5, "Ethiopian": undefined, "Filipina": undefined, "Finnish": 165.3, "French": 162.5,
		"German": 162.8, "Ghanan": 158.5, "Greek": 165, "Guatemalan": undefined, "Haitian": undefined, "Hungarian": 164,
		"Icelandic": 168, "Indian": 151.9, "Indonesian": 147, "Iranian": 157.2, "Iraqi": 155.8, "Irish": 163, "Israeli": 166,
		"Italian": 162.5, "Jamaican": 160.8, "Japanese": 158, "Jordanian": undefined, "Kazakh": 159.8, "Kenyan": undefined,
		"Korean": 156.15, "Lebanese": 165, "Libyan": 160.5, "Lithuanian": 167.5, "Malaysian": 154.7, "Malian": 160.4,
		"Mexican": 154, "Moroccan": 158.5, "Nepalese": 150.8, "Nigerian": 163.8, "Norwegian": 157.8, "Omani": undefined,
		"Pakistani": 151.9, "Peruvian": 151, "Polish": 165.1, "Portuguese": 165.1, "Puerto Rican": 158.9, "Romanian": 157,
		"Russian": 164.1, "Saudi": 156.3, "Scottish": 163, "Serbian": 166.8, "Slovak": 165.6, "South African": 159,
		"Spanish": 162.6, "Sudanese": undefined, "Swedish": 166.8, "Swiss": 162.5, "Tanzanian": undefined, "Thai": 159,
		"Tunisian": 160, "Turkish": 161.9, "Ugandan": undefined, "Ukrainian": 164.8, "Uzbek": 159.9, "Venezuelan": 159,
		"Vietnamese": 155.2, "Yemeni": undefined, "a New Zealander": 164, "Zimbabwean": undefined,
		"": 162.5 // default
	};
	const xyMeanHeight = {
		"American.white": 178.2, "American.black": 177.4, "American.latina": 172.5, "American.asian": 172.5, "American": 176.4,
		"Afghan": undefined, "Algerian": 172.2, "Argentinian": 174.46, "Armenian": undefined, "Australian": 175.6,
		"Austrian": 179, "Bangladeshi": undefined, "Belarusian": 176.9, "Belgian": 178.7, "Bolivian": 160, "Brazilian": 170.7,
		"British": 175.3, "Burmese": undefined, "Canadian": 175.1, "Chilean": 169.6, "Chinese": 167.1, "Colombian": 170.6,
		"Congolese": 158.9, "Cuban": 168, "Czech": 180.31, "Danish": 180.4, "Dominican": 168.4, "Dutch": 181, "Egyptian": 170.3,
		"Emirati": 170.3, "Estonian": 179.1, "Ethiopian": undefined, "Filipina": undefined, "Finnish": 178.9, "French": 175.6,
		"German": 175.4, "Ghanan": 169.5, "Greek": 177, "Guatemalan": undefined, "Haitian": undefined, "Hungarian": 176,
		"Icelandic": 181, "Indian": 164.7, "Indonesian": 158, "Iranian": 170.3, "Iraqi": 165.4, "Irish": 177, "Israeli": 177,
		"Italian": 176.5, "Jamaican": 171.8, "Japanese": 172, "Jordanian": undefined, "Kazakh": 169, "Kenyan": undefined,
		"Korean": 168.15, "Lebanese": 176, "Libyan": 171.3, "Lithuanian": 177.2, "Malaysian": 166.3, "Malian": 171.3,
		"Mexican": 167, "Moroccan": 172.7, "Nepalese": 163, "Nigerian": 163.8, "Norwegian": 179.63, "Omani": undefined,
		"Pakistani": 164.7, "Peruvian": 164, "Polish": 178.7, "Portuguese": 173.9, "Puerto Rican": 172.5, "Romanian": 172,
		"Russian": 177.2, "Saudi": 168.9, "Scottish": 177.6, "Serbian": 182, "Slovak": 179.4, "South African": 168,
		"Spanish": 173.1, "Sudanese": undefined, "Swedish": 181.5, "Swiss": 178.2, "Tanzanian": undefined, "Thai": 170.3,
		"Tunisian": 172.3, "Turkish": 173.6, "Ugandan": undefined, "Ukrainian": 176.5, "Uzbek": 175.4, "Venezuelan": 169,
		"Vietnamese": 165.7, "Yemeni": undefined, "a New Zealander": 177, "Zimbabwean": undefined,
		".white": 177.6, "": 172.5 // defaults
	};

	// Helper method - table lookup for nationality/race combinations
	const nationalityMeanHeight = function(table, nationality, race, def) {
		return table[nationality + "." + race] || table[nationality] || table["." + race] || table[""] || def;
	};

	// Helper method - generate two independent Gaussian numbers using Box-Muller transform
	const gaussianPair = function() {
		let r = Math.sqrt(-2.0 * Math.log(1 - Math.random()));
		let sigma = 2.0 * Math.PI * (1 - Math.random());
		return [r * Math.cos(sigma), r * Math.sin(sigma)];
	};

	// Helper method: Generate a skewed normal random variable with the skew s
	// Reference: http://azzalini.stat.unipd.it/SN/faq-r.html
	const skewedGaussian = function(s) {
		let randoms = gaussianPair();
		if(s === 0) {
			// Don't bother, return an unskewed normal distribution
			return randoms[0];
		}
		let delta = s / Math.sqrt(1 + s * s);
		let result = delta * randoms[0] + Math.sqrt(1 - delta * delta) * randoms[1];
		return randoms[0] >= 0 ? result : -result;
	};

	// Height multiplier generator; skewed gaussian according to global parameters
	const multGenerator = function() {
		let result = skewedGaussian(skew);
		while(result < minMult || result > maxMult) {
			result = skewedGaussian(skew);
		}
		return result;
	};

	// Helper method: Generate a height based on the mean one and limited according to config.
	const heightGenerator = function(mean) {
		let result = mean * (1 + multGenerator() * spread);
		while(result < minHeight || result > maxHeight) {
			result = mean * (1 + multGenerator() * spread);
		}
		return result;
	};

	// Helper method - apply age and genes to the adult height
	const applyAge = function(height, age, genes) {
		if(!_.isFinite(age) || age < 2 || age >= 20) {
			return height;
		}
		let minHeight = 0, midHeight = 0, midAge = 15;
		switch(genes) {
			case 'XX': // female
			case 'XXX': // Triple X syndrome female
				minHeight = 85; midHeight = height * 157 / 164; midAge = 13;
				break;
			case 'XY': // male
			case 'XXY': // Kinefelter syndrome male
			case 'XYY': // XYY syndrome male
				minHeight = 86; midHeight = height * 170 / 178; midAge = 15;
				break;
			case 'X0': case 'X': // Turner syndrome female
				minHeight = 85 * 0.93; midHeight = height * 157 / 164; midAge = 13;
				break;
			default:
				minHeight = 85.5, midHeight = height * 327 / 342, midAge = 14;
				break;
		}
		if(age > midAge) {
			// end of puberty to 20
			return interpolate(midAge, midHeight, 20, height, age);
		} else {
			// 2 to end of puberty
			return interpolate(2, minHeight, midAge, midHeight, age);
		}
	};

	const _meanHeight = function(nationality, race, genes, age) {
		if(_.isObject(nationality)) {
			// We got called with a single slave as the argument
			return _meanHeight(nationality.nationality, nationality.race, nationality.genes, nationality.physicalAge + nationality.birthWeek / 52.0);
		}
		let result = 0;
		switch(genes) {
			case 'XX': // female
				result = nationalityMeanHeight(xxMeanHeight, nationality, race);
				break;
			case 'XY': // male
				result = nationalityMeanHeight(xyMeanHeight, nationality, race);
				break;
			// special cases. Extra SHOX genes on X and Y chromosomes make for larger people
			case 'X0': case 'X': // Turner syndrome female
				result = nationalityMeanHeight(xxMeanHeight, nationality, race) * 0.93;
				break;
			case 'XXX': // Triple X syndrome female
				result = nationalityMeanHeight(xxMeanHeight, nationality, race) * 1.03;
				break;
			case 'XXY': // Kinefelter syndrome male
				result = nationalityMeanHeight(xyMeanHeight, nationality, race) * 1.03;
				break;
			case 'XYY': // XYY syndrome male
				result = nationalityMeanHeight(xyMeanHeight, nationality, race) * 1.04;
				break;
			case 'Y': case 'Y0': case 'YY': case 'YYY':
				console.log("Height.mean(): non-viable genes " + genes);
				break;
			default:
				console.log("Height.mean(): unknown genes " + genes + ", returning mean between XX and XY");
				result = nationalityMeanHeight(xxMeanHeight, nationality, race) * 0.5
					+ nationalityMeanHeight(xyMeanHeight, nationality, race) * 0.5;
				break;
		}
		return applyAge(result, age, genes);
	};

	const _randomHeight = function(nationality, race, genes, age) {
		const mean = _meanHeight(nationality, race, genes, age);
		// If we got called with a slave object and options, temporarily modify
		// our configuration.
		if(_.isObject(nationality) && _.isObject(race)) {
			const currentConfig = _config();
			_config(race);
			const result = heightGenerator(mean);
			_config(currentConfig);
			return result;
		}
		return heightGenerator(mean);
	};

	const _forAge = function(height, age, genes) {
		if(_.isObject(age)) {
			// We got called with a slave as a second argument
			return applyAge(height, age.physicalAge + age.birthWeek / 52.0, age.genes);
		} else {
			return applyAge(height, age, genes);
		}
	};

	return {
		mean: _meanHeight,
		random: _randomHeight,
		forAge: _forAge,
		config: _config,
	};
})();

if(!Array.prototype.findIndex) {
	Array.prototype.findIndex = function(predicate) {
		if (this == null) {
			throw new TypeError('Array.prototype.find called on null or undefined');
		}
		if (typeof predicate !== 'function') {
			throw new TypeError('predicate must be a function');
		}
		var list = Object(this);
		var length = list.length >>> 0;
		var thisArg = arguments[1];
		var value;

		for (var i = 0; i < length; i++) {
			value = list[i];
			if (predicate.call(thisArg, value, i, list)) {
				return i;
			}
		}
		return -1;
	};
};

/*
A categorizer is used to "slice" a value range into distinct categories in an efficient manner.

If the values are objects their property named 'value' will be set to whatever
the value used for the choice was. This is important for getters, where it can be accessed
via this.value.

--- Example ---
Original SugarCube code
<<if _Slave.muscles > 95>>
	Musc++
<<elseif _Slave.muscles > 30>>
	Musc+
<<elseif _Slave.muscles > 5>>
	Toned
<<elseif _Slave.muscles > -6>>
<<elseif _Slave.muscles > -31>>
	@@.red;weak@@
<<elseif _Slave.muscles > -96>>
	@@.red;weak+@@
<<else>>
	@@.red;weak++@@
<</if>>

As a categorizer
<<if ndef $cats>><<set $cats = {}>><</if>>
<<if ndef $cats.muscleCat>>
	<!-- This only gets set once, skipping much of the code evaluation, and can be set outside of the code in an "init" passage for further optimization -->
	<<set $cats.muscleCat = new Categorizer([96, 'Musc++'], [31, 'Musc+'], [6, 'Toned'], [-5, ''], [-30, '@@.red;weak@@'], [-95, '@@.red;weak+@@'], [-Infinity, '@@.red;weak++@@'])>>
<</if>>
<<print $cats.muscleCat.cat(_Slave.muscles)>>
*/
window.Categorizer = function() {
	this.cats = Array.prototype.slice.call(arguments)
		.filter(function(e, i, a) {
			return e instanceof Array && e.length == 2 && typeof e[0] === 'number' && !isNaN(e[0])
				&& a.findIndex(function(val) { return e[0] === val[0]; }) === i; /* uniqueness test */ })
		.sort(function(a, b) { return b[0] - a[0]; /* reverse sort */ });
};
window.Categorizer.prototype.cat = function(val, def) {
	var result = def;
	if(typeof val === 'number' && !isNaN(val)) {
		var foundCat = this.cats.find(function(e) { return val >= e[0]; });
		if(foundCat) {
			result = foundCat[1];
		}
	}
	// Record the value for the result's getter, if it is an object
	// and doesn't have the property yet
	if(result === Object(result)) {
		result['value'] = val;
	}
	return result;
};

/*
Make everything waiting for this execute. Usage:

let doSomething = function() {
	... your initialization code goes here ...
};
if(typeof Categorizer === 'function') {
	doSomething();
} else {
	jQuery(document).one('categorizer.ready', doSomething);
}
*/
jQuery(document).trigger('categorizer.ready');


code:
:: Abort [nobr]

<<set $nextButton = "Back", $nextLink = "Slave Interact">>
<<ClearSummaryCache $activeSlave>>

The remote surgery makes aborting a pregnancy quick and efficient. $activeSlave.slaveName is
<<if $activeSlave.fetish == "pregnancy">>
	@@.red;fundamentally broken.@@ Her entire concept of self and sexuality was wrapped up in the life growing within her, and now it is gone.
	<<set  $activeSlave.fetish to "mindbroken">>
<<elseif $activeSlave.devotion < -50>>
	@@.mediumorchid;filled with violent, consuming hatred@@. Even though she knew her baby was destined for a slave orphanage, it seems she cared for it and views you as its killer. She is @@.gold;terrified of your power@@ over her body.
	<<set  $activeSlave.trust -= 10>>
	<<set  $activeSlave.devotion -= 25>>
<<elseif $activeSlave.devotion < -20>>
	@@.mediumorchid;afflicted by desperate, inconsolable sobbing@@. Even though she knew her baby was destined for a slave orphanage, it seems she cared for it. She is @@.gold;terrified of your power@@ over her body.
	<<set  $activeSlave.trust -= 10>>
	<<set  $activeSlave.devotion -= 10>>
<<elseif $activeSlave.devotion <= 20>>
	@@.mediumorchid;consumed by muted weeping and enduring sorrow@@. Even though she knew her baby was destined for a slave orphanage, it seems she cared for it. She is @@.gold;terrified of your power@@ over her body.
	<<set  $activeSlave.trust -= 10>>
	<<set  $activeSlave.devotion -= 5>>
<<elseif $activeSlave.devotion <= 50>>
	dully obedient. She has been broken to slave life so thoroughly that even this is neither surprising nor affecting. She is @@.gold;terrified of your power@@ over her body.
	<<set  $activeSlave.trust -= 10>>
<<else>>
	@@.hotpink;pleased by this stark development@@, since she is so attentive to your will. She also expects she'll be able to fuck better now.
	<<set  $activeSlave.devotion += 4>>
<</if>>

<<if lastPregRule($activeSlave,$defaultRules)>><<set $activeSlave.preg = -1>><<else>><<set $activeSlave.preg = 0>><</if>>

<<if $activeSlave.reservedChildren > 0>>
	<<set $reservedChildren -= $activeSlave.reservedChildren>>
<</if>>
<<set $activeSlave.pregType = 0>>
<<set $activeSlave.pregSource = 0>>
<<set $activeSlave.pregKnown = 0>>
<<SetBellySize $activeSlave>>


code:
:: Acquisition [nobr]

<<unset $slaveWithoutBonuses, $startingGirlCopied, $startingGirlRelation>>

<<set $fixedNationality = 0>>

<<if $saveImported == 1>><<set _valueOwed = 5000>><<else>><<set _valueOwed = 50000>><</if>>
<<if $freshPC == 1 || $saveImported == 0>>
	<<if $PC.vagina == 1>>
		<<set $PC.births = 0>>
		<<if $PC.career == "servant">>
			<<if $PC.actualAge >= 50 >>
				<<set $PC.births = 9>>
				<<set $PC.birthMaster = 9>>
			<<elseif $PC.actualAge >= 35>>
				<<set $PC.births = 6>>
				<<set $PC.birthMaster = 6>>
			<<else>>
				<<set $PC.births = 3>>
				<<set $PC.birthMaster = 3>>
			<</if>>
			<<for $i = 0; $i < $slaves.length; $i++>>
				<<if $slaves[$i].origin == "She was another of your late master's servants. She spent nine months in your womb, courtesy of your master." || $slaves[$i].origin == "Your late master took pleasure in using his servants in creative ways. He inseminated you with your own sperm, and nine months later, your daughter was born.">>
				<<set $PC.births += 1>>
				<<set $PC.birthMaster += 1>>
				<</if>>
			<</for>>
		<<elseif $PC.career == "escort">>
			<<for $i = 0; $i < $slaves.length; $i++>>
				<<if $slaves[$i].origin == "She was the result of unprotected sex with a client. He paid you quite well to enjoy your body as you grew heavy with his child." || $slaves[$i].origin == "A client paid you a large sum of credits to prove you could literally fuck yourself. She is the result of that lucrative night.">>
				<<set $PC.births += 1>>
				<<set $PC.birthClient += 1>>
				<</if>>
			<</for>>
		<<else>>
			<<for $i = 0; $i < $slaves.length; $i++>>
				<<if $slaves[$i].mother == -1>>
				<<set $PC.births += 1>>
				<<set $PC.birthOther += 1>>
				<</if>>
			<</for>>
		<</if>>
		<<if $PC.preg > 0>>
			<<if $PC.career == "servant">>
				<<set $PC.pregSource = -3>>
			<<elseif $PC.career == "escort">>
				<<set $PC.pregSource = -2>>
			<</if>>
			<<set $PC.pregKnown = 1>>
			<<set $PC.belly = getPregBellySize($PC)>>
		<</if>>
	<</if>>
<<else>> /*testtest*/
	<<set $PC.sisters = 0>>
	<<set $PC.daughters = 0>>
<</if>> /*closes ng*/
<<if $familyTesting == 1>>
	<<set _pcMomFound = 0, _pcDadFound = 0>>
	<<for _i = 0; _i < $slaves.length; _i++>>
		<<if $PC.mother > 0 && $PC.mother == $slaves[_i].ID>>
			<<set _pcMomFound = 1>>
		<</if>>
		<<if $PC.father > 0 && $PC.father == $slaves[_i].ID>>
			<<set _pcDadFound = 1>>
		<</if>>
		<<if $slaves[_i].mother == $PC.ID || $slaves[_i].father == $PC.ID>>
			<<set $PC.daughters += 1>>
		<</if>>
		<<if areSisters($slaves[_i], $PC) > 0>>
			<<set $PC.sisters += 1>>
		<</if>>
	<</for>>
	<<if _pcMomFound == 0 && $PC.mother > 0>>
		<<set _lostMom = $PC.mother>>
		<<set $PC.mother = $missingParentId>>
		<<for _i = 0; _i < $slaves.length; _i++>>
			<<if $slaves[_i].mother == _lostMom>>
				<<set $slaves[_i].mother = $missingParentId>>
			<</if>>
		<</for>>
		<<set $missingParentId-->>
	<</if>>
	<<if _pcDadFound == 0 && $PC.father > 0>>
		<<set _lostDad = $PC.father>>
		<<set $PC.father = $missingParentId>>
		<<for _i = 0; _i < $slaves.length; _i++>>
			<<if $slaves[_i].father == _lostDad>>
				<<set $slaves[_i].father = $missingParentId>>
			<</if>>
		<</for>>
		<<set $missingParentId-->>
	<</if>>
	<<for _i = 0; _i < $slaves.length; _i++>>
		<<set _slaveMomFound = 0, _slaveDadFound = 0>>
		<<for _j = 0; _j < $slaves.length; _j++>>
			<<if $slaves[_i].mother > 0 && $slaves[_i].mother == $slaves[_j].ID>>
				<<set _slaveMomFound = 1>>
			<</if>>
			<<if $slaves[_i].father > 0 && $slaves[_i].father == $slaves[_j].ID>>
				<<set _slaveDadFound = 1>>
			<</if>>
		<</for>>
		<<if _slaveMomFound == 0 && $slaves[_i].mother > 0>>
			<<set _lostMom = $slaves[_i].mother>>
			<<set $slaves[_i].mother = $missingParentID>>
			<<for _j = 0; _j < $slaves.length; _j++>>
				<<if $slaves[_j].mother == _lostMom>>
					<<set $slaves[_j].mother = $missingParentID>>
				<</if>>
			<</for>>
			<<set $missingParentID-->>
		<</if>>
		<<if _slaveDadFound == 0 && $slaves[_i].father > 0>>
			<<set _lostDad = $slaves[_i].father>>
			<<set $slaves[_i].father = $missingParentID>>
			<<for _j = 0; _j < $slaves.length; _j++>>
				<<if $slaves[_j].father == _lostDad>>
					<<set $slaves[_j].father = $missingParentID>>
				<</if>>
			<</for>>
			<<set $missingParentID-->>
		<</if>>
	<</for>>
<</if>>
<<set $PC.ovaryAge = $PC.physicalAge>>

You've done it.

You arrive at your new arcology, $arcologies[0].name, and head straight to the penthouse to enter the access codes that will tell the $arcologies[0].name systems to recognize you as their owner. The penthouse office is ready to receive the codes, and they authenticate. A voice activates in your earpiece.

//Congratulations. I am a personal assistant program, and it is my pleasure to assist you,
<<switch $PC.nationality>>
<<case "Chinese" "Japanese" "Korean" "Cambodian" "Vietnamese" "Hungarian" "Mongolian">>
	<<if $PC.surname>>$PC.surname <</if>>$PC.name,
<<default>>
	$PC.name<<if $PC.surname>> $PC.surname<</if>>,
<</switch>>
the new owner of  $arcologies[0].name. I will offer useful information whenever possible in italics. Your new arcology has some unusual equipment. The previous owner kept a small stable of sex slaves. The penthouse therefore has a body modification studio for tattooing, bleaching and piercing, and an auto salon for more prosaic things like hair care. It also has a remote surgery, a small surgical theater that can be operated remotely by a qualified surgeon if you can pay the fee. Finally, it has a slave nutrition system connected to the arcology's hydroponics bays. This system produces a tasty protein-rich drink that provides the physically active female body all its necessary nutrients while leaving the lower digestive tract extremely clean. It even causes a mild increase in sex drive.

The previous owner seems to have left in something of a hurry.
<<if $cheatMode == 1>>
	Since you've elected to take over an arcology with special advantages, you've acquired a very special group of slaves.
<<elseif $saveImported == 1>>
	Since it took some time for you to ensure that your existing stable of slaves were safely moved to $arcologies[0].name, the previous owner had the time to get most of their things away.
<<elseif ($targetArcology.type != "New") && ($targetArcology.type != "Multiculturalist")>>
	<<switch $targetArcology.type>>
	<<case "Supremacist">>
		They kept a personal stable of fearful $arcologies[0].FSSupremacistRace sex slaves, but their sexual training is incomplete. Several of them are still here.
	<<case "Subjugationist">>
		They made it a special goal to enslave and whore out as many $arcologies[0].FSSubjugationistRace people as possible. Several of them are still here.
	<<case "GenderRadicalist">>
		They were in the process of building a stable of pretty young shemale whores. Several of them are still here. They're are all very attracted to men, and skilled at pleasing them.
	<<case "GenderFundamentalist">>
		They kept a personal stable of slaves for breeding purposes. Several of them are still here. They've been kept pregnant, and work as servants when they aren't being bred.
	<<case "Paternalist">>
		Their slaves were all very well treated. Several of them are still here. They were allowed to work as maids, and weren't even forced to have sex.
	<<case "Degradationist">>
		Their personal slaves were all Fuckdolls, slaves who have been permanently encased in advanced latex suits and converted into living sex toys. Several of them are still here.
	<<case "AssetExpansionist">>
		They kept a collection of bejeweled boobs for company, but they focused on breast expansion to the exclusion the slaves' emotional training. Several of them are still here.
	<<case "SlimnessEnthusiast">>
		They kept a harem of slim, pretty girls, and treated them very well. Several of them are still here. They should be very trusting of a new owner.
	<<case "TransformationFetishist">>
		They were just putting the finishing touches on a planned brothel's worth of surgically enhanced whores. Several of them are still here. They are already used to prostitution.
	<<case "BodyPurist">>
		Their slaves were trained for sexual use, but their health, fitness, and natural appearance were the main priorities. Several of them are still here.
	<<case "MaturityPreferentialist">>
		They preferred to keep their MILFs as scantily clad servants. Several of them are still here. They aren't all happy to be sex objects, but they're used to it.
	<<case "YouthPreferentialist">>
		They treated their young slaves very well. Several of them are still here. Virgins have been carefully preserved, but have learned to use their mouths through experience.
	<<case "Pastoralist">>
		Their herd of cow girls was progressing nicely, though more progress had been made on milk production than on training. Several of them are still here.
	<<case "PhysicalIdealist">>
		Their slaves worked as prostitutes, but mostly to fund a program of muscle building for all of them, which was nearing completion. Several of them are still here.
	<<case "ChattelReligionist">>
		They were recruiting a stable of slave whores by targeting people with religious complexes that made them particularly vulnerable to recruitment. Several of them are still here.
	<<case "RomanRevivalist">>
		The only one of their slaves left is the bodyguard. She should be very willing to transfer her loyalty to you, as her new owner.
	<<case "AztecRevivalist">>
		They maintained a combination of disobedient slaves, deemed incorrigible and blood priestesses. Since they offer themselves as slaves willingly, one has remained loyal to the owner of the arcology.
	<<case "EgyptianRevivalist">>
		They kept a harem of beautiful slave girls, who have been well-treated and well-trained. They should be very willing to serve you in turn.
	<<case "EdoRevivalist">>
		They put considerable effort into creating modern slave geisha, elegant Japanese slaves who were assigned to serve the public. Several of them are still here.
	<<case "ArabianRevivalist">>
		They trained slaves personally, and never kept slaves for very long. The slaves they left are all partway through being trained.
	<<case "ChineseRevivalist">>
		The only one of their slaves left is the Head Girl. She should be willing to transfer her loyalty to you, as her proper superior.
	<<case "Eugenics">>
		The only one of their slaves left is an absolute beauty of a girl. She is too smart for her own good and will likely not trust you.
	<<case "Repopulationist">>
		They kept a personal stable of slaves for breeding purposes. Several of them are still here. They've been kept heavily pregnant, and are used to being used whilst so.
	<<case "HedonisticDecadence">>
		Their slaves were heavily pampered; free to lie about, fuck, and eat as much as they wanted. Several of them are still here, too lazy and spoiled to leave. They eagerly paw at you upon your arrival, begging for their bellies to be filled with food and for a good, hard fucking.
	<<default>>
		ERROR: bad arcology type
	<</switch>>
<<else>>
	They could not get all of their personal effects away. Since they <<if $targetArcology.type == "Multiculturalist">>tried to sample different kinds of sexual slavery<<else>>did not have the time in control of the arcology to develop a specific stable of sex slaves<</if>>, their slaves were quite varied.
<</if>>

<<set $heroSlaves = $heroSlaves.shuffle()>>
<<set _valueGiven = 0>>
<<if $cheatMode == 1>>
	<<include [[Cheatmode Database]]>>
<<elseif $saveImported == 1>>
<<elseif ($targetArcology.type != "New") && ($targetArcology.type != "Multiculturalist")>>
	<<for $j = 0; $j < 5; $j++>>
	<<if _valueOwed - _valueGiven <= 5000>><<break>><</if>>
	<<switch $targetArcology.type>>
	<<case "Supremacist">>
		<<set $arcologies[0].FSSupremacistLawME = 1>><<include "Generate New Slave">><<set $arcologies[0].FSSupremacistLawME = 0>>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-25,-45), $activeSlave.health = random(0,15)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.entertainSkill = random(15,35)>>
		<<set $activeSlave.clothes = "uncomfortable straps", $activeSlave.collar = "uncomfortable leather", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "please you">>
	<<case "Subjugationist">>
		<<set $fixedRace = $activeArcology.FSSubjugationistRace>><<include "Generate New Slave">><<set $fixedRace = 0>>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-25,-45), $activeSlave.health = random(0,15)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.whoreSkill = random(15,35)>>
		<<set $activeSlave.clothes = "uncomfortable straps", $activeSlave.collar = "uncomfortable leather", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "whore">>
	<<case "GenderRadicalist">>
		<<set $activeSlaveOneTimeMaxAge = 25>>
		<<include "Generate XY Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(15,-15), $activeSlave.health = 100>>
		<<set $activeSlave.face = random(0,55)>>
		<<set $activeSlave.boobs += 100*random(2,4)>>
		<<set $activeSlave.butt += random(1,2)>>
		<<set $activeSlave.attrXY = random(70,90), $activeSlave.attrXX = 0>>
		<<set $activeSlave.oralSkill = random(35,65), $activeSlave.analSkill = random(35,65), $activeSlave.whoreSkill = random(35,65)>>
		<<SoftenSexualFlaw $activeSlave>>
		<<set $activeSlave.clothes = "uncomfortable straps", $activeSlave.collar = "stylish leather", $activeSlave.shoes = "heels">>
		<<set $activeSlave.assignment = "whore">>
	<<case "GenderFundamentalist">>
		<<set $activeSlaveOneTimeMinAge = $fertilityAge>>
		<<set $activeSlaveOneTimeMaxAge = 25>>
		<<include "Generate XX Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-25,-45), $activeSlave.health = random(55,65)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.preg = random(1,40), $activeSlave.lactation = 1>>
		<<SetBellySize $activeSlave>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.clothes = "a nice maid outfit", $activeSlave.collar = "tight steel", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "be a servant">>
	<<case "Paternalist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(55,65), $activeSlave.health = random(55,65)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.intelligence = random(1,3), $activeSlave.intelligenceImplant = 1>>
		<<set $activeSlave.entertainSkill = random(15,35)>>
		<<set $activeSlave.clothes = "conservative clothing", $activeSlave.collar = "none", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "be a servant">>
	<<case "Degradationist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = 25, $activeSlave.trust = -25, $activeSlave.health = random(0,15)>>
		<<set $activeSlave.fuckdoll = 100>>
		<<set $activeSlave.career = "a Fuckdoll">>
		<<set $activeSlave.fetish = "mindbroken">>
		<<set $activeSlave.boobs += 100*random(10,20)>>
		<<set $activeSlave.butt += random(2,3)>>
		<<set $activeSlave.lips = random(2,4)>>
		<<set $activeSlave.weight = random(-15,15)>>
		<<set $activeSlave.oralSkill = 0, $activeSlave.analSkill = 0, $activeSlave.vaginalSkill = 0, $activeSlave.entertainSkill = 0, $activeSlave.whoreSkill = 0>>
		<<set $activeSlave.behavioralFlaw = "none", $activeSlave.sexualFlaw = "none">>
		<<set $activeSlave.clothes = "a Fuckdoll suit">>
		<<set $activeSlave.assignment = "please you">>
	<<case "AssetExpansionist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-15,15), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.chem = 50>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.boobs += 100*random(10,20)>>
		<<set $activeSlave.butt += random(2,3)>>
		<<set $activeSlave.lips += random(0,1)>>
		<<if $activeSlave.balls > 0>><<set $activeSlave.balls++>><</if>>
		<<if $activeSlave.dick > 0>><<set $activeSlave.dick++>><</if>>
		<<set $activeSlave.weight = random(15,90)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = 0, $activeSlave.anus = 0>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.entertainSkill = random(15,35)>>
		<<set $activeSlave.clothes = "slutty jewelry", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "heels">>
		<<set $activeSlave.assignment = "please you">>
	<<case "SlimnessEnthusiast">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(55,65), $activeSlave.health = random(55,65)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.boobs = 100*random(1,4)>>
		<<set $activeSlave.butt = random(1,2)>>
		<<set $activeSlave.weight = random(-25,-15)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = 0, $activeSlave.anus = 0>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.entertainSkill = random(15,35)>>
		<<set $activeSlave.clothes = "a leotard", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "please you">>
	<<case "TransformationFetishist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-15,15), $activeSlave.health = random(-15,0)>>
		<<set $activeSlave.faceImplant = random(40,70)>>
		<<set $activeSlave.face = Math.trunc($activeSlave.face+$activeSlave.faceImplant/2,-100,100)>>
		<<set $activeSlave.boobsImplant = 200*random(4,8)>>
		<<set $activeSlave.boobs += $activeSlave.boobsImplant>>
		<<set $activeSlave.buttImplant = random(2,4)>>
		<<set $activeSlave.butt += $activeSlave.buttImplant>>
		<<set $activeSlave.lipsImplant = random(1,2)>>
		<<set $activeSlave.lips = Math.trunc($activeSlave.lipsImplant+2,-3,3)>>
		<<set $activeSlave.weight = random(-25,-15)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.clothes = "a string bikini", $activeSlave.collar = "shock punishment", $activeSlave.shoes = "extreme heels">>
		<<set $activeSlave.assignment = "whore">>
	<<case "BodyPurist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(55,65), $activeSlave.trust = random(25,45), $activeSlave.health = 100>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.weight = random(-5,5)>>
		<<set $activeSlave.muscles = random(10,25)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.clothes = "a nice maid outfit", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "heels">>
		<<set $activeSlave.assignment = "be a servant">>
	<<case "MaturityPreferentialist">>
		<<set $activeSlaveOneTimeMinAge = 36>>
		<<set $activeSlaveOneTimeMaxAge = 39>>
		<<set $one_time_age_overrides_pedo_mode = 1>>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(55,65), $activeSlave.trust = random(-15,15), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.boobs += 100*random(1,4)>>
		<<set $activeSlave.butt += random(1,2)>>
		<<set $activeSlave.weight = random(-5,90)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<SoftenBehavioralFlaw $activeSlave>>
		<<set $activeSlave.clothes = "a slutty maid outfit", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "heels">>
		<<set $activeSlave.assignment = "be a servant">>
	<<case "YouthPreferentialist">>
		<<set $activeSlaveOneTimeMaxAge = 19>>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(55,65), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.boobs = 100*random(1,4)>>
		<<set $activeSlave.butt = random(1,3)>>
		<<set $activeSlave.weight = random(-25,25)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = 0, $activeSlave.anus = 0>>
		<<if $activeSlave.vagina > -1>><<set $activeSlave.vaginalSkill = 0, $activeSlave.vagina = 0>><</if>>
		<<set $activeSlave.entertainSkill = random(15,35)>>
		<<set $activeSlave.clothes = "a schoolgirl outfit", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "heels">>
		<<set $activeSlave.assignment = "be a servant">>
	<<case "Pastoralist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-25,-45), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.boobs += 100*random(10,20)>>
		<<if $activeSlave.balls > 0>><<set $activeSlave.balls++>><</if>>
		<<set $activeSlave.lactation = 2>>
		<<set $activeSlave.clothes = "Western clothing", $activeSlave.collar = "leather with cowbell", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "get milked">>
	<<case "PhysicalIdealist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(25,45), $activeSlave.health = 100>>
		<<set $activeSlave.muscles = random(50,100)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.whoreSkill = random(15,35)>>
		<<set $activeSlave.clothes = "body oil", $activeSlave.collar = "none", $activeSlave.shoes = "none">>
		<<set $activeSlave.assignment = "whore">>
	<<case "ChattelReligionist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(55,65), $activeSlave.trust = random(55,65), $activeSlave.health = random(0,15)>>
		<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
		<<set $activeSlave.whoreSkill = random(10,20)>>
		<<set $activeSlave.behavioralFlaw = "none", $activeSlave.behavioralQuirk = "sinful">>
		<<set $activeSlave.clothes = "a chattel habit", $activeSlave.collar = "heavy gold", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "whore">>
	<<case "RomanRevivalist">>
		<<set $activeSlaveOneTimeMaxAge = 19>>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = 100, $activeSlave.trust = random(55,65), $activeSlave.health = 100>>
		<<set $activeSlave.face = random(0,55)>>
		<<set $activeSlave.muscles = random(25,50)>>
		<<set $activeSlave.combatSkill = 1>>
		<<set $activeSlave.behavioralFlaw = "none", $activeSlave.behavioralQuirk = "fitness">>
		<<set $activeSlave.behavioralFlaw = "none">>
		<<set $activeSlave.clothes = "a toga", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "guard you", $Bodyguard = $activeSlave>>
	<<case "AztecRevivalist">>
		<<set $fixedRace = "latina">><<include "Generate New Slave">><<set $fixedRace = 0>>
		<<set $activeSlave.nationality = "Mexican">>
		<<NationalityToName $activeSlave>>
		<<set $activeSlave.accent = 0>>
		<<set $activeSlave.devotion = 75, $activeSlave.trust = 75, $activeSlave.health = random(-20,20)>>
		<<set $activeSlave.muscles = random(50,75)>>
		<<set $activeSlave.combatSkill = 1>>
		<<set $activeSlave.behavioralFlaw = "malicious", $activeSlave.behavioralQuirk = "none">>
		<<set $activeSlave.clothes = "a huipil", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "none">>
		<<set $activeSlave.assignment = "be your Head Girl", $HeadGirl = $activeSlave>>
	<<case "EgyptianRevivalist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(25,45), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.entertainSkill = random(15,35)>>
		<<SoftenSexualFlaw $activeSlave>>
		<<set $activeSlave.clothes = "slutty jewelry", $activeSlave.collar = "ancient Egyptian", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "please you">>
	<<case "EdoRevivalist">>
		<<set $fixedRace = "asian">><<include "Generate New Slave">><<set $fixedRace = 0>>
		<<set $activeSlave.nationality = "Japanese">>
		<<NationalityToName $activeSlave>>
		<<set $activeSlave.accent = 0>>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(25,45), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.intelligence = random(1,3), $activeSlave.intelligenceImplant = 1>>
		<<set $activeSlave.entertainSkill = 100>>
		<<set $activeSlave.clothes = "a kimono", $activeSlave.collar = "satin choker", $activeSlave.shoes = "heels">>
		<<set $activeSlave.assignment = "serve the public">>
	<<case "ArabianRevivalist">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-15,15), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.intelligence = random(0,2), $activeSlave.intelligenceImplant = 0>>
		<<set $activeSlave.clothes = "harem gauze", $activeSlave.collar = "uncomfortable leather", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "take classes">>
	<<case "ChineseRevivalist">>
		<<set $activeSlaveOneTimeMinAge = 36>>
		<<set $activeSlaveOneTimeMaxAge = 38>>
		<<set $one_time_age_overrides_pedo_mode = 1>>
		<<set $fixedRace = "asian">><<include "Generate New Slave">><<set $fixedRace = 0>>
		<<set $activeSlave.nationality = "Chinese">>
		<<NationalityToName $activeSlave>>
		<<NationalityToAccent $activeSlave>>
		<<set $activeSlave.devotion = random(55,65), $activeSlave.trust = random(25,45), $activeSlave.health = random(25,45)>>
		<<set $activeSlave.face = random(0,55)>>
		<<set $activeSlave.accent = 0>>
		<<set $activeSlave.intelligence = 3, $activeSlave.intelligenceImplant = 1>>
		<<set $activeSlave.oralSkill = 100, $activeSlave.analSkill = 100>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = 100>>
		<</if>>
		<<set $activeSlave.entertainSkill = 100, $activeSlave.whoreSkill = 100>>
		<<SoftenBehavioralFlaw $activeSlave>>
		<<SoftenSexualFlaw $activeSlave>>
		<<set $activeSlave.clothes = "a slutty qipao", $activeSlave.collar = "pretty jewelry", $activeSlave.shoes = "heels">>
		<<set $activeSlave.assignment = "be your Head Girl", $HeadGirl = $activeSlave>>
	<<case "Eugenics">>
		<<include "Generate New Slave">>
		<<set $activeSlave.devotion = -100, $activeSlave.trust = -100, $activeSlave.health = random(80,90)>>
		<<set $activeSlave.intelligence = 3>>
		<<set $activeSlave.intelligenceImplant = 1>>
		<<set $activeSlave.face = 100>>
		<<set $activeSlave.faceShape = "sensual">>
		<<set $activeSlave.oralSkill = random(35,75), $activeSlave.analSkill = random(35,75)>>
		<<if $activeSlave.vagina > -1>>
			<<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>>
			<<set $activeSlave.vaginalSkill = random(35,75)>>
		<</if>>
		<<set $activeSlave.entertainSkill = random(15,35)>>
		<<set $activeSlave.whoreSkill = 0>>
		<<SoftenSexualFlaw $activeSlave>>
		<<set $activeSlave.clothes = "a ball gown", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "rest">>
	<<case "Repopulationist">>
		<<set $activeSlaveOneTimeMinAge = $fertilityAge+3>>
		<<set $activeSlaveOneTimeMaxAge = 25>>
		<<set $one_time_age_overrides_pedo_mode = 1>>
		<<include "Generate XX Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-25,-45), $activeSlave.health = random(55,65)>>
		<<set $activeSlave.face = random(15,100)>>
		<<set $activeSlave.preg = random(10,40), $activeSlave.pregType = random(3,8), $activeSlave.lactation = 1>>
		<<SetBellySize $activeSlave>>
		<<set $activeSlave.birthsTotal = 5>>
		<<set $activeSlave.bellySag = 20, $activeSlave.bellySagPreg = 20>>
		<<if $activeSlave.vagina > -1>>
			<<set $activeSlave.vagina = 4>>
			<<set $activeSlave.vaginalSkill = random(15,35)>>
		<</if>>
		<<set $activeSlave.clothes = "a nice maid outfit", $activeSlave.shoes = "flats">>
		<<set $activeSlave.assignment = "please you">>
	<<case "HedonisticDecadence">>
		<<set $activeSlaveOneTimeMaxAge = 25>>
		<<include "Generate XX Slave">>
		<<set $activeSlave.devotion = random(25,45), $activeSlave.trust = random(-25,-45), $activeSlave.health = random(-20,20)>>
		<<set $activeSlave.face = random(15,40)>>
		<<set $activeSlave.boobs += 100*random(3,6)>>
		<<set $activeSlave.butt += random(2,5)>>
		<<set $activeSlave.weight = random(100,200)>>
		<<set $activeSlave.oralSkill = random(15,35), $activeSlave.analSkill = random(15,35), $activeSlave.anus = 2>>
		<<if $activeSlave.vagina > -1>><<set $activeSlave.vaginalSkill = random(15,35), $activeSlave.vagina = 3>><</if>>
		<<set $activeSlave.entertainSkill = 0>>
		<<set $activeSlave.energy = random(60,80)>>
		<<set $activeSlave.behavioralFlaw = "gluttonous">>
		<<set $activeSlave.clothes = "attractive lingerie", $activeSlave.shoes = "flats">>
		<<set $activeSlave.diet = "fattening">>
		<<set $activeSlave.livingRules = "luxurious">>
		<<set $activeSlave.assignment = "rest">>
	<<default>>
		ERROR: bad arcology type
	<</switch>>
	<<set $activeSlave.origin = "You acquired her along with the arcology.", $activeSlave.career = "a slave">>
	<<slaveCost $activeSlave>>
	<<if $targetArcology.type == "Eugenics">>
		<<set _valueGiven += $slaveCost*4>>
	<<else>>
	<<set _valueGiven += $slaveCost>>
	<</if>>
	<<AddSlave $activeSlave>>
	<</for>>
<<else>>
	<<for $j = 0; $j < $heroSlaves.length; $j++>>
	<<if _valueOwed - _valueGiven <= 5000>>
		<<break>>
	<</if>>
	<<set $activeSlave = getHeroSlave($heroSlaves[$j], $baseHeroSlave)>>
	<<set $dump = $heroSlaves.pluck($j,$j)>>
	<<slaveCost $activeSlave>>
	<<if _valueGiven + $slaveCost < _valueOwed*2>>
		<<NationalityToAccent $activeSlave>>
		<<set $activeSlave.oldDevotion = $activeSlave.devotion>>
		<<set $activeSlave.oldTrust = $activeSlave.trust>>
		<<set _valueGiven += $slaveCost>>
		<<AddSlave $activeSlave>>
		<<if $activeSlave.fetish == "mindbroken">>
			$activeSlave.slaveName is, sadly, not mentally competent, and is wandering through the penthouse at the moment.
		<<elseif $activeSlave.amp == 1>>
			$activeSlave.slaveName is a quadruple amputee and is quite helpless, so you can attend to her at your leisure.
		<<elseif $activeSlave.devotion < -50>>
			$activeSlave.slaveName is quite rebellious and was attempting to escape, so I have locked her in the slave quarters.
		<<elseif $activeSlave.devotion < -20>>
			$activeSlave.slaveName resists my orders and was considering escape, so I have locked her in the slave quarters.
		<<elseif $activeSlave.devotion <= 20>>
			$activeSlave.slaveName is reasonably obedient, and is waiting for you in the dormitory, I believe in the hope of making a good impression.
		<<elseif $activeSlave.energy > 95>>
			$activeSlave.slaveName is a remarkable sexual addict, and I believe she will be very happy to meet you.
		<<elseif $activeSlave.fetish == "pregnancy" && $activeSlave.preg > 10>>
			$activeSlave.slaveName is currently in the dormitory masturbating over her growing pregnancy.
		<<elseif bigBelly($activeSlave)>>
			$activeSlave.slaveName is currently in the dormitory massaging her greatly distended belly.
		<<elseif $activeSlave.fetish == "buttslut">>
			$activeSlave.slaveName is currently in the dormitory masturbating anally, and I believe she will be happy to meet you.
		<<elseif $activeSlave.fetish == "cumslut">>
			$activeSlave.slaveName is currently in the dormitory exhibiting oral fixation, and I believe she will be happy to meet you.
		<<elseif $activeSlave.fetish == "boobs">>
			$activeSlave.slaveName is currently in the dormitory playing with her nipples, and I believe she will be happy to meet you.
		<<elseif $activeSlave.fetish == "pregnancy">>
			$activeSlave.slaveName is currently in the dormitory examining herself to try to discern her fertility, and I believe she will be happy to meet you.
		<<elseif $activeSlave.fetish == "humiliation">>
			$activeSlave.slaveName is currently in the entryway flashing passersby, and I believe she will be happy to meet you.
		<<elseif $activeSlave.fetish == "submissive">>
			$activeSlave.slaveName is currently in the dormitory, experimenting with self-bondage using the sheets; I believe she will be happy to meet you.
		<<elseif $activeSlave.fetish == "dom">>
			$activeSlave.slaveName is currently in the exercise area keeping fit; she likes to take an active role sexually and is using this down time to work out.
		<<elseif $activeSlave.fetish == "sadist">>
			$activeSlave.slaveName is currently outside your office; she enjoys being superior to other slaves and I believe she means to ingratiate herself to you.
		<<elseif $activeSlave.fetish == "masochist">>
			$activeSlave.slaveName is a sexual masochist; she is currently in the bathroom, experimenting with auto-flagellation with a wet towel.
		<<else>>
			$activeSlave.slaveName is currently outside your office, and I believe she is attempting to maintain sexual arousal to make a good first impression on you.
		<</if>>
	<</if>>
	<</for>>
<</if>>
<<if _valueOwed-_valueGiven > 0>>
	There are some valuables present, worth ¤<<print _valueOwed-_valueGiven>>.
	<<set $cash += _valueOwed-_valueGiven>>
<</if>>
//

/* RELATIONSHIP MUTUALITY CHECK, OLDMENTAL */

<<set $averageTrust = 0>>
<<set $averageDevotion = 0>>
<<set _slavesContributing = 0>>
<<for $i = 0; $i < $slaves.length; $i++>>
	<<if $slaves[$i].relation != 0>>
	<<set $seed = 0>>
	<<for $j = 0; $j < $slaves.length; $j++>>
		<<if $slaves[$i].relationTarget == $slaves[$j].ID>>
		<<if $slaves[$j].relationTarget == $slaves[$i].ID>>
		<<set $seed = 1>>
		<<break>>
		<</if>>
		<</if>>
	<</for>>
	<<if $seed == 0>>
		<<set $slaves[$i].relation = 0>>
		<<set $slaves[$i].relationTarget = 0>>
		<<goto "Acquisition">>
	<</if>>
	<</if>>
	<<set $slaves[$i].oldDevotion = $slaves[$i].devotion>>
	<<set $slaves[$i].oldTrust = $slaves[$i].trust>>
	/* AVERAGE VALUES UPDATE */
	<<if $slaves[$i].assignmentVisible == 1>>
		<<set $averageTrust += $slaves[$i].trust, $averageDevotion += $slaves[$i].devotion, _slavesContributing += 1>>
	<<else>>
		<<if $slaves[$i].assignment != "be confined in the cellblock">>
		<<if $slaves[$i].assignment != "be confined in the arcade">>
		<<if ($slaves[$i].assignment != "work in the dairy") || ($dairyRestraintsSetting < 2)>>
			<<set $averageTrust += $slaves[$i].trust*0.5, $averageDevotion += $slaves[$i].devotion*0.5, _slavesContributing += 0.5>>
		<</if>>
		<</if>>
		<</if>>
	<</if>>
<</for>>
<<if $familyTesting == 1>>
	<<set $slaves.forEach(function(s) { s.sisters = 0; s.daughters = 0; })>>
	<<set $PC.daughters = 0, $PC.sisters = 0>>
	<<for _fp = 0; _fp < $slaves.length; _fp++>>
		<<if ($slaves[_fp].mother == -1 || $slaves[_fp].father == -1)>>
			<<set $PC.daughters++>>
		<</if>>
		<<if areSisters($slaves[_fp], $PC) > 0>>
			<<set $PC.sisters++>>
		<</if>>
		<<for _fpt = 0; _fpt < $slaves.length; _fpt++>>
			<<if ($slaves[_fpt].mother == $slaves[_fp].ID) || ($slaves[_fpt].father == $slaves[_fp].ID)>>
				<<set $slaves[_fp].daughters++>>
			<</if>>
			<<if areSisters($slaves[_fpt], $slaves[_fp]) > 0>>
				<<set $slaves[_fp].sisters++>>
			<</if>>
		<</for>>
	<</for>>
<</if>>
<<set $averageTrust = $averageTrust/_slavesContributing>>
<<set $averageDevotion = $averageDevotion/_slavesContributing>>
<<set $enduringTrust = $averageTrust>>
<<set $enduringDevotion = $averageDevotion>>

<<link "Continue">>
	<<set $ui = "main">>
	<<if $terrain == "urban">>
		<<set $minimumSlaveCost = 2000>>
		<<set $slaveCostFactor = 0.85>>
	<<elseif $terrain == "marine">>
		<<set $minimumSlaveCost = 2500>>
		<<set $slaveCostFactor = 1>>
	<<else>>
		<<set $minimumSlaveCost = 3000>>
		<<set $slaveCostFactor = 1.15>>
	<</if>>
	<>
	<<goto "Main">>
<</link>>


code:
:: Agent Company [nobr]

<<set $nextButton = "Continue", $nextLink = "AS Dump", $returnTo = "Neighbor Interact", _SL = $slaves.length, _ID = $activeSlave.ID>>

<<assignJob $activeSlave "live with your agent">>

<<if $activeSlave.reservedChildren > 0>>
	<<set $reservedChildren -= $activeSlave.reservedChildren>>
	<<set $activeSlave.reservedChildren = 0>>
<</if>>

<<if $activeSlave.rivalry > 0>>
	<<for _i = 0; _i < _SL; _i++>>
		<<if _ID == $slaves[_i].rivalryTarget>>
			<<set $slaves[_i].rivalry = 0, $slaves[_i].rivalryTarget = 0>>
			<<break>>
		<</if>>
	<</for>>
	<<set $activeSlave.rivalry = 0, $activeSlave.rivalryTarget = 0>>
<</if>>

<<for _i = 0; _i < $arcologies.length; _i++>>
	<<if $subSlave.ID == $arcologies[_i].leaderID>>
		<<set $activeArcology = $arcologies[_i]>>
	<</if>>
<</for>>

Working in $activeArcology.name's penthouse office, $subSlave.slaveName gets a video call from you. Naturally, her personal assistant program has been instructed to give these the highest priority, and your face appears in front of her immediately. She greets you properly, and asks you what she can do to serve you. You tell her you're planning to send one of your slaves over to her arcology to assist her. Exchanges of this kind are neither unusual nor particularly interesting, so a slight look of perplexity clouds $subSlave.slaveName's face as she wonders why this merits a personal call. Normally, <<if $HeadGirl != 0>>$HeadGirl.slaveName<<else>>$assistantName<</if>> would handle it with her directly.

Her question is answered when you bring $activeSlave.slaveName in close, putting her in $subSlave.slaveName's view. $subSlave.slaveName's $subSlave.eyeColor eyes fly open with pleased surprise, but before she can speak, $activeSlave.slaveName goes first.
<<if canTalk($activeSlave) == false>>
  Unable to speak herself, she simply makes a heart shape with her hands in view of the video call, and blows her <<if $activeSlave.relationship == 4>>lover<<else>>wife<</if>> a kiss.
<<else>>
  <<Enunciate $activeSlave>>
  "Hi <<if $activeSlave.relationship == 4>>lover<<else>><<s>>weetheart<</if>>," she <<say>>s in a syrupy tone. "Mi<<ss>> me?"
<</if>>

$subSlave.slaveName smiles back at her, glowing with pleasure, and responds with exaggerated arousal.

<<Enunciate $subSlave>>

<<switch $subSlave.fetish>>
<<case "submissive">>
	"Looking forward to <<s>>leeping in your arm<<s>>, babe," the submissive
<<case "cumslut">>
	"Can't wait to ki<<ss>> you, babe," the orally fixated
<<case "humiliation">>
	"Can't wait to take you right in the middle of the pla<<z>>a here," the exhibitionist
<<case "buttslut">>
	"I can't wait to fuck you in your hot little a<<ss>>," the anally fixated
<<case "boobs">>
	"Looking forward to feeling your brea<<s>>t<<s>> again," the boob-loving
<<case "pregnancy">>
	"Can't wait to share all the pregnant girl<<s>> here with you," the impregnation fetishist
<<case "dom">>
	"Looking forward to <<s>>hoving you fa<<c>>edown, bitch," the dominant
<<case "sadist">>
	"Looking forward to making you bite the pillow again, bitch," the sadistic
<<case "masochist">>
	"Can't wait to feel you hurt me again, babe," the masochistic
<<default>>
	"Babe, I can't wait to give you a hug and tell you about $activeArcology.name," the loving
<</switch>>
leader of an entire arcology <<say>>s.


code:
:: Agent Retrieve [silently]

<<set _SL = $slaves.length, _ID = $activeArcology.leaderID, _LL = $leaders.length>>

<<for _i = 0; _i < _SL; _i++>>
	<<if $slaves[_i].ID == _ID>>
		<<if $slaves[_i].relationshipTarget > 0>>
			<<for _j = 0; _j < _SL; _j++>>
				<<if $slaves[_j].ID == $slaves[_i].relationshipTarget && $slaves[_j].assignment == "live with your agent">>
					<<if $slaves[$j].preg > 40>>
						<<set $slaves[$j].birthsTotal += $slaves[$j].pregType, $slaves[$j].preg = 0, $slaves[$j].pregSource = 0, $slaves[$j].pregType = 0>>
						<<set $slaves[$j].pregKnown = 0>>
						<<SetBellySize $slaves[$j]>>
					<</if>>
					<<removeJob $slaves[_j] "live with your agent">>
					<<break>>
				<</if>>
			<</for>>
			<<if $slaves[$i].preg > 40>>
				<<set $slaves[$i].birthsTotal += $slaves[$i].pregType, $slaves[$i].preg = 0, $slaves[$i].pregSource = 0, $slaves[$i].pregType = 0>>
				<<set $slaves[$i].pregKnown = 0>>
				<<SetBellySize $slaves[$i]>>
			<</if>>
		<</if>>
		<<removeJob $slaves[_i] "be your agent">>
		<<break>>
	<</if>>
<</for>>

<<set $activeArcology.leaderID = 0, $activeArcology.government = "your trustees">>

<<for _i = 0;_i < _LL;_i++>>
	<<if _ID == $leaders[_i].ID>>
		<<set _dump = $leaders.deleteAt(_i)>>
		<<break>>
	<</if>>
<</for>>

<<goto "Neighbor Interact">>


code:
:: Agent Select [nobr]

<<set $nextButton = "Back", $nextLink = "Neighbor Interact", $showEncyclopedia = 1, $encyclopedia = "Agents">>
''Appoint an Agent from your devoted slaves:''
<<include "Slave Summary">>


code:
:: Agent Workaround [nobr]

<<set $nextButton = "Continue", $nextLink = "Neighbor Interact", _SL = $slaves.length, _ID = $slaves[$i].ID>>

<<assignJob $slaves[$i] "be your agent">>

<<if $slaves[$i].reservedChildren > 0>>
	<<set $reservedChildren -= $slaves[$i].reservedChildren>>
	<<set $slaves[$i].reservedChildren = 0>>
<</if>>

<<if $slaves[$i].rivalry > 0>>
	<<for _i = 0; _i < _SL; _i++>>
		<<if _ID == $slaves[_i].rivalryTarget>>
			<<set $slaves[_i].rivalry = 0, $slaves[_i].rivalryTarget = 0>>
			<<break>>
		<</if>>
	<</for>>
	<<set $slaves[$i].rivalry = 0, $slaves[$i].rivalryTarget = 0>>
<</if>>

<<if $slaves[$i].relationship > 0 && $slaves[$i].relationship < 4>>
	<<for _i = 0;_i < _SL;_i++>>
		<<if _ID == $slaves[_i].relationshipTarget>>
			<<set $slaves[_i].relationship = 0, $slaves[_i].relationshipTarget = 0>>
			<<break>>
		<</if>>
	<</for>>
	<<set $slaves[$i].relationship = 0, $slaves[$i].relationshipTarget = 0>>
<</if>>

<<set $leaders.push($slaves[$i]), $activeArcology.leaderID = _ID, $activeArcology.government = "your agent">>

<<SlaveTitle $slaves[$i]>>

You order $slaves[$i].slaveName to come into your office for orders. The devoted $desc has no prior warning that this is anything unusual, and from the <<if $slaves[$i].energy > 95>>horny glint<<else>>glow of sexual availability<</if>> in her $slaves[$i].eyeColor eyes as she <<if canWalk($slaves[$i])>>enters<<else>>is helped in<</if>>, she <<if $slaves[$i].energy > 95>>seems to be hoping<<else>>wouldn't mind hearing<</if>> that you've called her in for a quick fuck. In fact, the matter at hand is about as far as it could possibly be from that, on the spectrum of interactions between <<if $PC.title != 0>>master<<else>>mistress<</if>> and slave.

You offer her, without preamble, agency on your behalf in $activeArcology.name. As a woman of intelligence, she knows the basics of such an arrangement, but she's stunned into silence by the offer, so you outline it briefly. Having a slave lead an arcology would be too much, even for the most open minded of Free Cities societies. So, she would be freed, albeit subject to a set of private, restrictive contracts that would allow you to recall her if you wish, and require her to follow your directions, if you give her any. But other than that, she would be the effective leader of an entire arcology. It's an unusual arrangement, but one that's becoming more common as multiple arcologies come under united control.

She's intelligent and confident of her place within society as a valued slave, and knows that with your resources behind her, this is likely something she's capable of succeeding at. Nevertheless, her feelings are obviously mixed. It will be a challenge,
<<switch $slaves[$i].fetish>>
<<case "submissive">>
	especially for a sexual submissive like her.
<<case "cumslut">>
	and she'll have to find dominant ways to sate her oral appetites.
<<case "humiliation">>
	especially for a humiliation addict like her.
<<case "buttslut">>
	though she'll probably be able to live her anal life vicariously by buttfucking others.
<<case "boobs">>
	but she'll have a practically infinite procession of breasts to judge and fondle.
<<case "pregnancy">>
	but the potential for impregnation of hundreds of slaves excites her.
<<case "dom">>
	but the prospect of having more slaves at her whim than even she could possibly use is incredibly exciting to her.
<<case "sadist">>
	but the prospect of having more slaves at her whim than even she could possibly break is incredibly exciting to her.
<<case "masochist">>
	especially for a masochist like her.
<<default>>
	though one she's willing to take on.
<</switch>>
It will mean that she'll see much less of you, something such a devoted slave may struggle with. Oppressed by the confusion and strength of her feelings, she begins to cry.

"Thank you, <<Master $slaves[i]>>," she gasps out. "I'll do my be<<s>>t."


code:
:: AS Dump

<<if (ndef $activeSlave) || ($activeSlave == 0)>>

	@@.red;ERROR:@@  AS Dump, activeSlave invalid, returnTo is '$returnTo', previous passage was '<<print previous()>>'. Please report this.

	<<link "Continue">><<goto $returnTo>><</link>> | [[Go Back|previous()]]

<<else>>

	<<silently>>

	<<set _SL = $slaves.length, _ID = $activeSlave.ID>>

	<<if $i >= 0 && $i < _SL && $slaves[$i].ID == _ID>> /* shortcut if $i is already pointing to this slave */
		<<set $slaves[$i] = $activeSlave>>
	<<else>>
		<<set $i = $slaves.findIndex(function(s) { return s.ID == _ID; })>> /* find $i if exists */
		<<if $i == -1>> /* not found, so new slave */
			<<AddSlave $activeSlave>>
		<<else>>
			<<set $slaves[$i] = $activeSlave>>
		<</if>>
	<</if>>

	<<switch _ID>>
		<<case $HeadGirl.ID>><<set $HeadGirl = $activeSlave>>
		<<case $Recruiter.ID>><<set $Recruiter = $activeSlave>>
		<<case $Bodyguard.ID>><<set $Bodyguard = $activeSlave>>
		<<case $Madam.ID>><<set $Madam = $activeSlave>>
		<<case $DJ.ID>><<set $DJ = $activeSlave>>
		<<case $Milkmaid.ID>><<set $Milkmaid = $activeSlave>>
		<<case $Schoolteacher.ID>><<set $Schoolteacher = $activeSlave>>
		<<case $Attendant.ID>><<set $Attendant = $activeSlave>>
		<<case $Nurse.ID>><<set $Nurse = $activeSlave>>
		<<case $Stewardess.ID>><<set $Stewardess = $activeSlave>>
		<<case $Wardeness.ID>><<set $Wardeness = $activeSlave>>
		<<case $Concubine.ID>><<set $Concubine = $activeSlave>>
		<<case $Collectrix.ID>><<set $Collectrix = $activeSlave>>
	<</switch>>

	<<ClearSummaryCache $activeSlave>>

	<</silently>>

	<<goto $returnTo>>

<</if>>


code:
:: custom Slaves Database

<<set _i = 1000000>>