diff --git a/1.4/Assemblies/RJW_Menstruation.dll b/1.4/Assemblies/RJW_Menstruation.dll index 14f7597..ce5f760 100644 Binary files a/1.4/Assemblies/RJW_Menstruation.dll and b/1.4/Assemblies/RJW_Menstruation.dll differ diff --git a/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Menstruation.cs b/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Menstruation.cs index cea0d19..2745e80 100644 --- a/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Menstruation.cs +++ b/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Menstruation.cs @@ -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(); + 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(); - 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(); }