mirror of
https://gitgud.io/lutepickle/rjw_menstruation.git
synced 2024-08-14 22:46:52 +00:00
Cache the ovulation and implantation chances to spare the UI
This commit is contained in:
parent
152a745af2
commit
82a34f8ea8
2 changed files with 59 additions and 42 deletions
Binary file not shown.
|
@ -123,6 +123,8 @@ namespace RJW_Menstruation
|
|||
protected string customwombtex = null;
|
||||
protected string customvagtex = null;
|
||||
protected bool estrusflag = false;
|
||||
protected float ovulationChanceCache = -1.0f; // Dirtied every simulation
|
||||
protected float implantationChanceCache = -1.0f;
|
||||
protected int opcache = -1;
|
||||
protected float antisperm = 0.0f;
|
||||
protected float? originvagsize = null;
|
||||
|
@ -294,58 +296,71 @@ namespace RJW_Menstruation
|
|||
// I hate doing this, but it's the least bad option
|
||||
public bool calculatingOvulationChance = false;
|
||||
|
||||
protected float CalcuatedOvulationChance()
|
||||
{
|
||||
float ovulationChance = 1.0f;
|
||||
if (EggHealth <= 0.0f) return 0.0f;
|
||||
if (EggHealth < 1.0f / 3.0f) ovulationChance = 0.8f;
|
||||
if (ModsConfig.BiotechActive && xxx.is_human(Pawn))
|
||||
{
|
||||
if (Pawn.SterileGenes()) return 0.0f;
|
||||
// Replicate how rjw.PawnCapacityWorker_Fertility.CalculateCapacityLevel does it, but without the age factor
|
||||
if (!Pawn.RaceHasFertility()) return 0.0f;
|
||||
if (AndroidsCompatibility.IsAndroid(Pawn) && parent.def != Genital_Helper.archotech_vagina) return 0.0f;
|
||||
foreach (var part in StatDefOf.Fertility.parts)
|
||||
{
|
||||
if(part is StatPart_FertilityByGenderAge fertilityByAge)
|
||||
{
|
||||
float factor = 1.0f;
|
||||
fertilityByAge.TransformValue(StatRequest.For(Pawn), ref factor);
|
||||
if (factor <= 0.0f) return 0.0f; // Too young or too old
|
||||
}
|
||||
else part.TransformValue(StatRequest.For(Pawn), ref ovulationChance);
|
||||
}
|
||||
if (Pawn.HasQuirk(QuirkUtility.Quirks.Breeder)) ovulationChance *= 10.0f;
|
||||
try
|
||||
{
|
||||
calculatingOvulationChance = true;
|
||||
ovulationChance *= PawnCapacityUtility.CalculateCapacityLevel(Pawn.health.hediffSet, xxx.reproduction);
|
||||
}
|
||||
finally { calculatingOvulationChance = false; }
|
||||
}
|
||||
return ovulationChance;
|
||||
}
|
||||
|
||||
protected float CalcuatedImplantChance()
|
||||
{
|
||||
float factor = 1.0f;
|
||||
if (ModsConfig.BiotechActive && xxx.is_human(Pawn))
|
||||
{
|
||||
// Implant factor will be based solely on pawn age, plus any rollover from ovulation chance
|
||||
StatPart_FertilityByGenderAge fertilityStatPart = StatDefOf.Fertility.GetStatPart<StatPart_FertilityByGenderAge>();
|
||||
fertilityStatPart?.TransformValue(StatRequest.For(Pawn), ref factor);
|
||||
float ovulationOverflow = OvulationChance;
|
||||
if (ovulationOverflow > 1.0f) factor *= ovulationOverflow;
|
||||
return Props.baseImplantationChanceFactor * FertilityModifier * factor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Pawn.health.capacities.GetLevel(xxx.reproduction) * Props.baseImplantationChanceFactor * FertilityModifier * factor;
|
||||
}
|
||||
}
|
||||
|
||||
public float OvulationChance
|
||||
{
|
||||
get
|
||||
{
|
||||
float ovulationChance = 1.0f;
|
||||
if (EggHealth <= 0.0f) return 0.0f;
|
||||
if (EggHealth < 1.0f / 3.0f) ovulationChance = 0.8f;
|
||||
if (ModsConfig.BiotechActive && xxx.is_human(Pawn))
|
||||
{
|
||||
if (Pawn.SterileGenes()) return 0.0f;
|
||||
// Replicate how rjw.PawnCapacityWorker_Fertility.CalculateCapacityLevel does it, but without the age factor
|
||||
if (!Pawn.RaceHasFertility()) return 0.0f;
|
||||
if (AndroidsCompatibility.IsAndroid(Pawn) && parent.def != Genital_Helper.archotech_vagina) return 0.0f;
|
||||
foreach (var part in StatDefOf.Fertility.parts)
|
||||
{
|
||||
if(part is StatPart_FertilityByGenderAge fertilityByAge)
|
||||
{
|
||||
float factor = 1.0f;
|
||||
fertilityByAge.TransformValue(StatRequest.For(Pawn), ref factor);
|
||||
if (factor <= 0.0f) return 0.0f; // Too young or too old
|
||||
}
|
||||
else part.TransformValue(StatRequest.For(Pawn), ref ovulationChance);
|
||||
}
|
||||
if (Pawn.HasQuirk(QuirkUtility.Quirks.Breeder)) ovulationChance *= 10.0f;
|
||||
try
|
||||
{
|
||||
calculatingOvulationChance = true;
|
||||
ovulationChance *= PawnCapacityUtility.CalculateCapacityLevel(Pawn.health.hediffSet, xxx.reproduction);
|
||||
}
|
||||
finally { calculatingOvulationChance = false; }
|
||||
}
|
||||
return ovulationChance;
|
||||
if (ovulationChanceCache < 0.0f) ovulationChanceCache = CalcuatedOvulationChance();
|
||||
return ovulationChanceCache;
|
||||
}
|
||||
}
|
||||
|
||||
public float ImplantChance
|
||||
{
|
||||
get
|
||||
{
|
||||
float factor = 1.0f;
|
||||
if (ModsConfig.BiotechActive && xxx.is_human(Pawn))
|
||||
{
|
||||
// Implant factor will be based solely on pawn age, plus any rollover from ovulation chance
|
||||
StatPart_FertilityByGenderAge fertilityStatPart = StatDefOf.Fertility.GetStatPart<StatPart_FertilityByGenderAge>();
|
||||
fertilityStatPart?.TransformValue(StatRequest.For(Pawn), ref factor);
|
||||
float ovulationOverflow = OvulationChance;
|
||||
if (ovulationOverflow > 1.0f) factor *= ovulationOverflow;
|
||||
return Props.baseImplantationChanceFactor * FertilityModifier * factor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Pawn.health.capacities.GetLevel(xxx.reproduction) * Props.baseImplantationChanceFactor * FertilityModifier * factor;
|
||||
}
|
||||
if (implantationChanceCache < 0.0f) implantationChanceCache = CalcuatedImplantChance();
|
||||
return implantationChanceCache;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1260,6 +1275,8 @@ namespace RJW_Menstruation
|
|||
|
||||
protected virtual void BeforeSimulator()
|
||||
{
|
||||
ovulationChanceCache = -1.0f;
|
||||
implantationChanceCache = -1.0f;
|
||||
CumOut();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue