Cache the ovulation and implantation chances to spare the UI
This commit is contained in:
parent
152a745af2
commit
82a34f8ea8
Binary file not shown.
|
@ -123,6 +123,8 @@ namespace RJW_Menstruation
|
||||||
protected string customwombtex = null;
|
protected string customwombtex = null;
|
||||||
protected string customvagtex = null;
|
protected string customvagtex = null;
|
||||||
protected bool estrusflag = false;
|
protected bool estrusflag = false;
|
||||||
|
protected float ovulationChanceCache = -1.0f; // Dirtied every simulation
|
||||||
|
protected float implantationChanceCache = -1.0f;
|
||||||
protected int opcache = -1;
|
protected int opcache = -1;
|
||||||
protected float antisperm = 0.0f;
|
protected float antisperm = 0.0f;
|
||||||
protected float? originvagsize = null;
|
protected float? originvagsize = null;
|
||||||
|
@ -294,58 +296,71 @@ namespace RJW_Menstruation
|
||||||
// I hate doing this, but it's the least bad option
|
// I hate doing this, but it's the least bad option
|
||||||
public bool calculatingOvulationChance = false;
|
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
|
public float OvulationChance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
float ovulationChance = 1.0f;
|
if (ovulationChanceCache < 0.0f) ovulationChanceCache = CalcuatedOvulationChance();
|
||||||
if (EggHealth <= 0.0f) return 0.0f;
|
return ovulationChanceCache;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float ImplantChance
|
public float ImplantChance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
float factor = 1.0f;
|
if (implantationChanceCache < 0.0f) implantationChanceCache = CalcuatedImplantChance();
|
||||||
if (ModsConfig.BiotechActive && xxx.is_human(Pawn))
|
return implantationChanceCache;
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,6 +1275,8 @@ namespace RJW_Menstruation
|
||||||
|
|
||||||
protected virtual void BeforeSimulator()
|
protected virtual void BeforeSimulator()
|
||||||
{
|
{
|
||||||
|
ovulationChanceCache = -1.0f;
|
||||||
|
implantationChanceCache = -1.0f;
|
||||||
CumOut();
|
CumOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue