static defaultOnSuccessfulImpregnation(father, mother, pregSlot, thisPtr, qtyEdit = null) {
if (thisPtr.debugTrace) Log(LogCategory.Player, LogDetail.Log, "defaultOnSuccessfulImpregnation handler called");
// Setup the pregnancy data for the Mother
const pData = mother.pregnancyData[pregSlot];
if (thisPtr.handlesType == null) {
Log(LogCategory.Creature, LogDetail.Warning, `BasePregnancyHandler for type ${this._handlesType} doesn't exist.`);
}
pData.pregnancyType = thisPtr.handlesType;
if (thisPtr.debugTrace) Log(LogCategory.Player, LogDetail.Log, "Knocking up " + mother.short + " with pregnancy type " + pData.pregnancyType);
pData.pregnancyIncubationMulti = (mother.pregnancyIncubationBonusMother() + father.pregnancyIncubationBonusFather()) / 2.0;
if (thisPtr.debugTrace) Log(LogCategory.Player, LogDetail.Log, "Calculated incubation acceleration multi as " + pData.pregnancyIncubationMulti);
pData.pregnancyIncubation = thisPtr.basePregnancyIncubationTime;
if (thisPtr.debugTrace) Log(LogCategory.Player, LogDetail.Log, "Total incubation time as " + pData.pregnancyIncubation);
// Define limits
const quantityMin = thisPtr.pregnancyQuantityMinimum;
let quantityMax = thisPtr.pregnancyQuantityMaximum;
// Limit bonuses
let qtyMultOverride = 1;
if (mother.perkv2("Broodmother") > 1) qtyMultOverride *= mother.perkv2("Broodmother");
if (qtyMultOverride > 1) quantityMax = Math.max(quantityMax, Math.round(quantityMax * qtyMultOverride));
// Calculate the *number* of "children", if applicable
let quantity = rand(quantityMax + 1);
if (quantity < quantityMin) quantity = quantityMin;
// qtyEdit is Array used to the children calculations
// 0: Applies extra multiplier to quantityMax (after fertility calculation).
// 1: Minimum fertility threshold before adding extra children.
// 2: Increment to count through fertility loop.
if (qtyEdit != null && qtyEdit.length > 2) {
const limit = Math.min(qtyEdit[1], 100);
const inc = Math.max(qtyEdit[2], 0.1);
let cnt = 0;
// Always start with the minimum amount of children.
quantity = quantityMin;
// Unnaturally fertile mothers may get multiple children.
for (let i = mother.fertility(); i >= limit; i -= inc) {
quantity += rand((quantityMax - quantityMin) + 1);
// To prevent overloop crashes.
cnt++;
if (cnt >= 100) break;
}
}
if (qtyEdit != null && qtyEdit.length > 0 && qtyEdit[0] > 1) quantityMax = Math.round(quantityMax * qtyEdit[0]);
// Quantity bonuses
const fatherBonus = Math.round((father.cumQ() * 2) / thisPtr.definedAverageLoadSize);
const motherBonus = Math.round((quantity * mother.pregnancyMultiplier()) - quantity);
quantity += fatherBonus + motherBonus;
if (quantity < quantityMin) quantity = quantityMin;
if (quantity > quantityMax) quantity = quantityMax;
pData.pregnancyQuantity = quantity;
}