:: pregJS [script]

/* Major props to the anons who worked together to forge the Super Pregnancy Project. Let your legacy go unforgotten.*/
window.getPregBellySize = function(s) {
	var gestastionWeek = s.preg;
	var fetuses = s.pregType;
	var phi = 1.618;

	if(gestastionWeek <= 32) {
		var targetLen = ((0.00006396 * Math.pow(gestastionWeek, 4)) - (0.005501 * Math.pow(gestastionWeek, 3)) + (0.161 * Math.pow(gestastionWeek, 2)) - (0.76 * gestastionWeek) + 0.208);
	} else if(gestastionWeek <= 106) {
		var targetLen = ((-0.0000004675 * Math.pow(gestastionWeek, 4)) + (0.0001905 * Math.pow(gestastionWeek, 3)) - (0.029 * Math.pow(gestastionWeek, 2)) + (2.132 * gestastionWeek) - 16.575);
	} else {
		var targetLen = ((-0.00003266 * Math.pow(gestastionWeek,2)) + (0.076 * gestastionWeek) + 43.843);
	}

	var bellySize = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((targetLen / 2), 3)) * fetuses);
	return bellySize;
};

window.bellyAdjective = function(slave) {
	slave = slave || State.variables.activeSlave;
	if(slave.belly >= 1500) {
		if(slave.belly >= 1000000) {
			if(slave.preg > 10) {
				return 'unfathomably distended, brimming with life';
			} else {
				return 'unfathomable';
			}
		} else if(slave.belly >= 750000) {
			if(slave.preg > 10) {
				return 'monolithic bulging';
			} else {
				return 'monolithic';
			}
		} else if(slave.belly >= 600000) {
			if(slave.preg > 10) {
				return 'titanic bulging';
			} else {
				return 'titanic';
			}
		} else if(slave.belly >= 450000) {
			if(slave.preg > 10) {
				return 'gigantic bulgy';
			} else {
				return 'gigantic';
			}
		} else if(slave.belly >= 300000) {
			return 'massive';
		} else if(slave.belly >= 100000) {
			return 'giant';
		} else if(slave.belly >= 15000) {
			return 'huge';
		} else if(slave.belly >= 10000) {
			return 'big';
		} else {
			return 'swollen';
		}
	} else {
		return '';
	}
}

/* calculates and returns expected ovum count during conception*/
window.setPregType = function(actor) {
	/* IMHO rework is posssible. Can be more interesting to play, if this code will take in account more body conditions - age, fat, food, hormone levels, etc. */

	var ovum = 1;
	var fertilityStack = 0;	// adds an increasing bonus roll for stacked fertility drugs

	if(actor.broodmother < 1) { // Broodmothers should be not processed here. Necessary now.
		if(typeof actor.readyOva == "number" && actor.readyOva != 0) {
			ovum = actor.readyOva; //just single override; for delayed impregnation cases 
		} else if(actor.ID == -1) {
			if(actor.birthMaster > 0) { // Predisposed to twins
				if(actor.fertDrugs == 1) {
					ovum += jsEither([1, 1, 2, 2, 2, 2, 3, 3]);
				} else {
					ovum += jsEither([0, 0, 0, 1, 1, 1, 1, 1, 1, 2]);
				}
				if(actor.forcedFertDrugs > 0) {
					ovum += jsEither([1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4]);
				}
			} else {
				if(actor.fertDrugs == 1) {
					ovum += jsEither([0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3]);
				} else {
					ovum += jsEither([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
				}
				if(actor.forcedFertDrugs > 0) {
					ovum += jsEither([0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4]);
				}
			}
		} else if(actor.pregType == 0) {
			ovum += jsEither([0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);	//base chance for twins
			if(actor.hormones == 2) {
				ovum += jsEither([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2]);
				fertilityStack++;
			}
			if(actor.hormoneBalance >= 200) {
				ovum += jsEither([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2]);
				fertilityStack++;
			}
			if(actor.diet == "fertility") {
				ovum += jsEither([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
				fertilityStack++;
			}
			if(State.variables.masterSuitePregnancyFertilitySupplements == 1 && ((actor.assignment == "serve in the master suite" || actor.assignment == "be your Concubine"))) {
				ovum += jsEither([0, 0, 0, 1, 1, 2, 2, 2, 3, 3]);
				fertilityStack++;
				fertilityStack++;
			}
			if(State.variables.reproductionFormula == 1 && (State.variables.week-actor.weekAcquired > 0)) {
				fertilityStack++;
			}
			if(actor.drugs == "super fertility drugs") {
				ovum += jsEither([1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5]);
				fertilityStack++;
				fertilityStack++;
				fertilityStack++;
				fertilityStack++;
				fertilityStack++;
			} else if(actor.drugs == "fertility drugs") {
				ovum += jsEither([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3]);
				fertilityStack++;
			}
			if(State.variables.seeHyperPreg == 1) {
				if(actor.drugs == "super fertility drugs") {
					ovum += jsRandom(0, fertilityStack*2);
				} else {
					ovum += jsRandom(0, fertilityStack);
				}
			} else {
				ovum += jsRandom(0, fertilityStack);
				if(ovum > 12) {
					ovum = jsRandom(6, 12);
				}
			}
		}
	}
	return ovum;
}

/*
 Penetrative ability, ability to become pregnant, and canBreed() must be checked outside of this. Designed to assume .eggType == "human".
 target is the slave to get pregnant. Also accepts the PC.
 chance is the % chance to conceive.
 hole control's the hole involved (0 - vagina, 1 - ass, 2 - both). .mpreg did this.
 fatherID is the ID of her sire or 0 if undefined.
 displayOverride is an override if defined - fatherID must be defined in this case.
*/
window.knockMeUp = function(target, chance, hole, fatherID, displayOverride) {
	const V = State.variables;
	let r = "";
	if (V.seePreg !== 0) {
		if (jsRandom(0,99) < (chance + (V.reproductionFormula*((target.pregSource <= 0) ? ((target.ID == -1) ? 0 : 10) : 20)))) {
			if (target.mpreg === hole) {

				target.preg = 1;
				target.pregSource = (!fatherID ? 0 : fatherID);

				if (target.ID !== -1) {
					target.pregWeek = 1;
				}

				target.pregType = setPregType(target);
				WombImpregnate(target, target.pregType, target.pregSource, 1);

				if (V.menstruation === 1) {}
				else if (!displayOverride) {
					target.pregKnown = 1;
					if (target.ID === -1) {
						/* r += "@@.lime;You have gotten pregnant.@@"; */
					} else if (target.fuckdoll === 0) {
						r += "@@.lime;She has become pregnant.@@";
					} else {
						r += "@@.lime;It has become pregnant.@@";
					}
				} else {
					target.pregKnown = 1;
				}

			} else if (hole === 2) {

				target.preg = 1;
				target.pregSource = (!fatherID ? 0 : fatherID);

				if (target.ID !== -1) {
					target.pregWeek = 1;
				}

				target.pregType = setPregType(target);
				WombImpregnate(target, target.pregType, target.pregSource, 1);

				if (V.menstruation === 1) {}
				else if (!displayOverride) {
					target.pregKnown = 1;
					if (target.ID === -1) {
						/* r += "@@.lime;You have gotten pregnant.@@"; */
					} else if (target.fuckdoll === 0) {
						r += "@@.lime;She has become pregnant.@@";
					} else {
						r += "@@.lime;It has become pregnant.@@";
					}
				} else {
					target.pregKnown = 1;
				}
			}
		}
	}
	return r;
}

window.getIncubatorReserved = function(slaves) {
	var count = 0;
	slaves.forEach(function(s){
		if (s.reservedChildren > 0)
			count += s.reservedChildren;
		});
	return count;
}

window.getNurseryReserved = function (slaves) {
	var count = 0;
	slaves.forEach(function (s) {
		if (s.reservedChildrenNursery > 0)
			count += s.reservedChildrenNursery;
		});
	return count;
}

/* not to be used until that last part is defined. It may become slave.boobWomb.volume or some shit */
window.getBaseBoobs = function(slave) {
	return slave.boobs-slave.boobsImplant-slave.boobsWombVolume;
}
