Implement exponential fertilization chance

This commit is contained in:
lutepickle 2022-07-07 12:23:45 -07:00
parent 8a048ea7e5
commit a90d6bf343
2 changed files with 5 additions and 5 deletions

View file

@ -1078,7 +1078,7 @@ namespace RJW_Menstruation
foreach (Cum cum in eligibleCum) foreach (Cum cum in eligibleCum)
totalFertPower += cum.FertVolume; totalFertPower += cum.FertVolume;
if (Rand.Range(0.0f, 1.0f) > totalFertPower * Configurations.FertilizeChance * Props.basefertilizationChanceFactor) if (Rand.Range(0.0f, 1.0f) > 1.0f - Mathf.Pow(1.0f - Configurations.FertilizeChance, totalFertPower * Props.basefertilizationChanceFactor))
return null; return null;
parent.pawn.records.AddTo(VariousDefOf.AmountofFertilizedEggs, 1); parent.pawn.records.AddTo(VariousDefOf.AmountofFertilizedEggs, 1);
@ -1438,7 +1438,7 @@ namespace RJW_Menstruation
{ {
Hediff hediff = parent.pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.Hediff_MenstrualCramp); Hediff hediff = parent.pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.Hediff_MenstrualCramp);
if (hediff != null) parent.pawn.health.RemoveHediff(hediff); if (hediff != null) parent.pawn.health.RemoveHediff(hediff);
int totalFollicularHours = PeriodRandomizer(climacteric ? Stage.ClimactericFollicular : Stage.Follicular, climacteric ? 6f : 1f); // The total amount of time for both bleeding and follicular int totalFollicularHours = PeriodRandomizer(climacteric ? Stage.ClimactericFollicular : Stage.Follicular, climacteric ? 6.0f : 1.0f); // The total amount of time for both bleeding and follicular
if (totalFollicularHours <= currentIntervalHours) // We've bled for so long that we completely missed the follicular phase if (totalFollicularHours <= currentIntervalHours) // We've bled for so long that we completely missed the follicular phase
GoNextStage(Stage.Ovulatory); GoNextStage(Stage.Ovulatory);
else else
@ -1687,7 +1687,7 @@ namespace RJW_Menstruation
protected void GoNextStage(Stage nextstage, bool calculateHours = true) protected void GoNextStage(Stage nextstage, bool calculateHours = true)
{ {
curStageHrs = 0; curStageHrs = 0;
float variabilityFactor = nextstage == Stage.ClimactericFollicular || nextstage == Stage.ClimactericLuteal || nextstage == Stage.ClimactericBleeding ? 6f : 1f; float variabilityFactor = nextstage == Stage.ClimactericFollicular || nextstage == Stage.ClimactericLuteal || nextstage == Stage.ClimactericBleeding ? 6.0f : 1.0f;
if (calculateHours) currentIntervalHours = PeriodRandomizer(nextstage, variabilityFactor); if (calculateHours) currentIntervalHours = PeriodRandomizer(nextstage, variabilityFactor);
curStage = nextstage; curStage = nextstage;
HugsLibController.Instance.TickDelayScheduler.ScheduleCallback(PeriodSimulator(nextstage), GetNextUpdate(), parent.pawn, false); HugsLibController.Instance.TickDelayScheduler.ScheduleCallback(PeriodSimulator(nextstage), GetNextUpdate(), parent.pawn, false);
@ -1733,7 +1733,7 @@ namespace RJW_Menstruation
return intervalhours + (int)(intervalhours * Rand.Range(-deviation, deviation)); return intervalhours + (int)(intervalhours * Rand.Range(-deviation, deviation));
} }
protected int PeriodRandomizer(Stage stage, float variabilityFactor = 1f) protected int PeriodRandomizer(Stage stage, float variabilityFactor = 1.0f)
{ {
// Most cycle lengthening or shortening occurs in the follicular phase, so weight towards that // Most cycle lengthening or shortening occurs in the follicular phase, so weight towards that
switch (stage) switch (stage)

View file

@ -66,7 +66,7 @@ namespace RJW_Menstruation
public static float GetFertilityChance(this HediffComp_Menstruation comp) public static float GetFertilityChance(this HediffComp_Menstruation comp)
{ {
return comp.TotalFertCum * Configurations.FertilizeChance * comp.Props.basefertilizationChanceFactor; return 1.0f - Mathf.Pow(1.0f - Configurations.FertilizeChance, comp.TotalFertCum * comp.Props.basefertilizationChanceFactor);
} }
public static HediffComp_Menstruation.Stage GetCurStage(this Pawn pawn) public static HediffComp_Menstruation.Stage GetCurStage(this Pawn pawn)