Refactor the climacteric stage functions into the normal stage functions

This commit is contained in:
lutepickle 2022-07-07 10:50:49 -07:00
parent 9cc8897103
commit 4737641673
2 changed files with 69 additions and 144 deletions

View File

@ -36,9 +36,14 @@ namespace RJW_Menstruation
}
}
protected override void FollicularAction()
protected override void FollicularAction(bool climacteric)
{
if (!IsBreedingSeason())
if (climacteric && !Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (!IsBreedingSeason())
{
GoNextStage(Stage.Anestrus);
return;
@ -46,33 +51,9 @@ namespace RJW_Menstruation
if (curStageHrs >= currentIntervalhours)
{
estrusflag = false;
GoNextStage(Stage.Luteal);
GoNextStage(climacteric ? Stage.ClimactericLuteal : Stage.Luteal);
}
else
{
curStageHrs += Configurations.CycleAcceleration;
if (!estrusflag && curStageHrs > currentIntervalhours - Props.estrusDaysBeforeOvulation * 24)
{
estrusflag = true;
SetEstrus(Props.eggLifespanDays + Props.estrusDaysBeforeOvulation);
}
StayCurrentStage();
}
}
protected override void ClimactericFollicularAction()
{
if (!Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (curStageHrs >= currentIntervalhours)
{
estrusflag = false;
GoNextStage(Stage.ClimactericLuteal);
}
else if (ovarypower < OvaryPowerThreshold / 3 && Rand.Range(0.0f, 1.0f) < 0.2f) // Might randomly skip to luteal early)
else if (climacteric && ovarypower < OvaryPowerThreshold / 3 && Rand.Range(0.0f, 1.0f) < 0.2f) // Might randomly skip to luteal early)
{
estrusflag = false;
GoNextStage(Stage.ClimactericLuteal);

View File

@ -528,10 +528,8 @@ namespace RJW_Menstruation
Scribe_Collections.Look(ref eggs, saveDestroyedThings: true, label: "eggs", lookMode: LookMode.Deep, ctorArgs: new object[0]);
Scribe_Values.Look(ref curStage, "curStage", curStage, true);
Scribe_Values.Look(ref curStageHrs, "curStageHrs", curStageHrs, true);
//Scribe_Values.Look(ref follicularIntervalhours, "follicularIntervalhours", follicularIntervalhours, true);
//Scribe_Values.Look(ref lutealIntervalhours, "lutealIntervalhours", lutealIntervalhours, true);
//Scribe_Values.Look(ref bleedingIntervalhours, "bleedingIntervalhours", bleedingIntervalhours, true);
//Scribe_Values.Look(ref recoveryIntervalhours, "recoveryIntervalhours", recoveryIntervalhours, true);
Scribe_Values.Look(ref cycleSpeed, "cycleSpeed", cycleSpeed, true);
Scribe_Values.Look(ref cycleVariability, "cycleVariability", cycleVariability, true);
Scribe_Values.Look(ref currentIntervalhours, "currentIntervalhours", currentIntervalhours, true);
Scribe_Values.Look(ref crampPain, "crampPain", crampPain, true);
Scribe_Values.Look(ref ovarypower, "ovarypower", ovarypower, true);
@ -1300,9 +1298,14 @@ namespace RJW_Menstruation
parent.pawn.health.AddHediff(hediff, Genital_Helper.get_genitalsBPR(parent.pawn));
}
protected virtual void FollicularAction()
protected virtual void FollicularAction(bool climacteric)
{
if (!IsBreedingSeason())
if(climacteric && !Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (!IsBreedingSeason())
{
GoNextStage(Stage.Anestrus);
return;
@ -1311,6 +1314,10 @@ namespace RJW_Menstruation
{
GoNextStage(Stage.Ovulatory);
}
else if(climacteric && ovarypower < OvaryPowerThreshold / 3 && Rand.Range(0.0f, 1.0f) < 0.2f) //skips ovulatory
{
GoNextStage(Stage.ClimactericLuteal);
}
else
{
curStageHrs += Configurations.CycleAcceleration;
@ -1373,9 +1380,14 @@ namespace RJW_Menstruation
}
}
protected virtual void LutealAction()
protected virtual void LutealAction(bool climacteric)
{
if (!eggs.NullOrEmpty())
if (climacteric && !Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (!eggs.NullOrEmpty())
{
FertilizationCheck();
EggDecay();
@ -1403,7 +1415,11 @@ namespace RJW_Menstruation
eggs.Clear();
if (Props.bleedingIntervalDays == 0)
{
GoNextStage(Stage.Follicular);
GoNextStage(climacteric ? Stage.ClimactericFollicular : Stage.Follicular);
}
else if (climacteric && (ovarypower < OvaryPowerThreshold / 4 || (ovarypower < OvaryPowerThreshold / 3 && Rand.Range(0.0f, 1.0f) < 0.3f))) //skips bleeding
{
GoNextStage(Stage.ClimactericFollicular);
}
else
{
@ -1411,24 +1427,29 @@ namespace RJW_Menstruation
{
AddCrampPain();
}
GoNextStage(Stage.Bleeding);
GoNextStage(climacteric ? Stage.ClimactericBleeding : Stage.Bleeding);
}
}
}
protected virtual void BleedingAction()
protected virtual void BleedingAction(bool climacteric)
{
if (curStageHrs >= currentIntervalhours)
if (climacteric && !Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (curStageHrs >= currentIntervalhours)
{
Hediff hediff = parent.pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.Hediff_MenstrualCramp);
if (hediff != null) parent.pawn.health.RemoveHediff(hediff);
int totalFollicularHours = PeriodRandomizer(Stage.Follicular); // The total amount of time for both bleeding and follicular
int totalFollicularHours = PeriodRandomizer(climacteric ? Stage.ClimactericFollicular : Stage.Follicular, climacteric ? 6f : 1f); // 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
GoNextStage(Stage.Ovulatory);
else
{
currentIntervalhours = totalFollicularHours - currentIntervalhours;
GoNextStage(Stage.Follicular, false);
GoNextStage(climacteric ? Stage.ClimactericFollicular : Stage.Follicular, false);
}
}
else
@ -1504,101 +1525,6 @@ namespace RJW_Menstruation
}
}
protected virtual void ClimactericFollicularAction()
{
if (!Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (curStageHrs >= currentIntervalhours)
{
GoNextStage(Stage.Ovulatory);
}
else if (ovarypower < OvaryPowerThreshold / 3 && Rand.Range(0.0f, 1.0f) < 0.2f) //skips ovulatory
{
GoNextStage(Stage.ClimactericLuteal);
}
else
{
curStageHrs += Configurations.CycleAcceleration;
StayCurrentStage();
}
}
protected virtual void ClimactericLutealAction()
{
if (!Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (!eggs.NullOrEmpty())
{
FertilizationCheck();
EggDecay();
if (Implant()) GoNextStage(Stage.Pregnant);
else
{
curStageHrs += Configurations.CycleAcceleration;
StayCurrentStage();
}
}
else if (curStageHrs <= currentIntervalhours)
{
curStageHrs += Configurations.CycleAcceleration;
StayCurrentStage();
}
else
{
eggs.Clear();
if (Props.bleedingIntervalDays == 0)
{
GoNextStage(Stage.ClimactericFollicular);
}
else if (ovarypower < OvaryPowerThreshold / 4 || (ovarypower < OvaryPowerThreshold / 3 && Rand.Range(0.0f, 1.0f) < 0.3f)) //skips bleeding
{
GoNextStage(Stage.ClimactericFollicular);
}
else
{
if (crampPain >= 0.05f)
{
AddCrampPain();
}
GoNextStage(Stage.ClimactericBleeding);
}
}
}
protected virtual void ClimactericBleedingAction()
{
if (!Configurations.EnableMenopause)
{
RemoveClimactericEffect();
StayCurrentStage();
}
else if (curStageHrs >= currentIntervalhours)
{
Hediff hediff = parent.pawn.health.hediffSet.GetFirstHediffOfDef(VariousDefOf.Hediff_MenstrualCramp);
if (hediff != null) parent.pawn.health.RemoveHediff(hediff);
int totalFollicularHours = PeriodRandomizer(Stage.Follicular);
if (totalFollicularHours <= currentIntervalhours)
GoNextStage(Stage.Ovulatory);
else
{
currentIntervalhours = totalFollicularHours - currentIntervalhours;
GoNextStage(Stage.Follicular, false);
}
}
else
{
if (curStageHrs < currentIntervalhours / 4) for (int i = 0; i < Configurations.CycleAcceleration; i++) BleedOut();
curStageHrs += Configurations.CycleAcceleration;
StayCurrentStage();
}
}
protected virtual void AnestrusAction()
{
if (IsBreedingSeason())
@ -1674,16 +1600,25 @@ namespace RJW_Menstruation
switch (targetstage)
{
case Stage.Follicular:
action = FollicularAction;
action = delegate
{
FollicularAction(false);
};
break;
case Stage.Ovulatory:
action = OvulatoryAction;
break;
case Stage.Luteal:
action = LutealAction;
action = delegate
{
LutealAction(false);
};
break;
case Stage.Bleeding:
action = BleedingAction;
action = delegate
{
BleedingAction(false);
};
break;
case Stage.Pregnant:
action = PregnantAction;
@ -1701,13 +1636,22 @@ namespace RJW_Menstruation
action = YoungAction;
break;
case Stage.ClimactericFollicular:
action = ClimactericFollicularAction;
action = delegate
{
FollicularAction(true);
};
break;
case Stage.ClimactericLuteal:
action = ClimactericLutealAction;
action = delegate
{
LutealAction(true);
};
break;
case Stage.ClimactericBleeding:
action = ClimactericBleedingAction;
action = delegate
{
BleedingAction(true);
};
break;
case Stage.Anestrus:
action = AnestrusAction;
@ -1810,7 +1754,7 @@ namespace RJW_Menstruation
return (int)(Props.bleedingIntervalDays * 24 * (cycleSpeed * 0.5f) * (1 + Rand.Range(-cycleVariability, cycleVariability) * 0.5f * variabilityFactor));
case Stage.Recover:
return (int)(Props.recoveryIntervalDays * 24 * Rand.Range(-0.05f, 0.05f));
default: // Can happen on init, shouldn't happen during a cycle
default: // Often unused
return 1;
}
}