From d98a102d44bb41c9e254f1800ccf4cf764c27bcd Mon Sep 17 00:00:00 2001 From: lutepickle <28810-lutepickle@users.noreply.gitgud.io> Date: Wed, 17 Aug 2022 06:37:30 -0700 Subject: [PATCH] Catch pawns that are pregnant but not with BasePregnancy (e.g. vanilla animal pregnancy) --- .../RJW_Menstruation/HediffComps/HediffComp_Breast.cs | 2 ++ .../RJW_Menstruation/RJW_Menstruation/Patch/RJW_Patch.cs | 5 +++-- 1.3/source/RJW_Menstruation/RJW_Menstruation/Utility.cs | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/1.3/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Breast.cs b/1.3/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Breast.cs index a275479..49e3905 100644 --- a/1.3/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Breast.cs +++ b/1.3/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_Breast.cs @@ -306,6 +306,8 @@ namespace RJW_Menstruation else newNippleProgress = 0f; + if (newNippleProgress < 0) newNippleProgress = 0; + if (newNippleProgress == nippleProgress) return; // Nothing to change else if (newNippleProgress > nippleProgress) { diff --git a/1.3/source/RJW_Menstruation/RJW_Menstruation/Patch/RJW_Patch.cs b/1.3/source/RJW_Menstruation/RJW_Menstruation/Patch/RJW_Patch.cs index f4445f9..8d69458 100644 --- a/1.3/source/RJW_Menstruation/RJW_Menstruation/Patch/RJW_Patch.cs +++ b/1.3/source/RJW_Menstruation/RJW_Menstruation/Patch/RJW_Patch.cs @@ -57,8 +57,9 @@ namespace RJW_Menstruation if (__state == null || __state.Pregnancy != null) return; // It was pregnant, but not anymore. This probably means the pregnancy was destroyed by e.g. a mech implant Pawn pawn = props.partner; - Hediff_BasePregnancy newestPregnancy = pawn.health.hediffSet.GetHediffs().MaxBy(hediff => hediff.loadID); - if (newestPregnancy == null) return; + IEnumerable pregnancies = pawn.health.hediffSet.GetHediffs(); + if (!pregnancies.Any()) return; + Hediff_BasePregnancy newestPregnancy = pregnancies.MaxBy(hediff => hediff.loadID); if (pawn.GetMenstruationComps().Any(comp => comp.Pregnancy == newestPregnancy)) return; // One of the wombs did get it else __state.Pregnancy = newestPregnancy; diff --git a/1.3/source/RJW_Menstruation/RJW_Menstruation/Utility.cs b/1.3/source/RJW_Menstruation/RJW_Menstruation/Utility.cs index 5e4ab93..1d74483 100644 --- a/1.3/source/RJW_Menstruation/RJW_Menstruation/Utility.cs +++ b/1.3/source/RJW_Menstruation/RJW_Menstruation/Utility.cs @@ -138,7 +138,9 @@ namespace RJW_Menstruation public static float GetFarthestPregnancyProgress(this Pawn pawn) { - return pawn.health.hediffSet.GetHediffs().MaxBy(hediff => hediff.GestationProgress)?.GestationProgress ?? -1; + IEnumerable pregnancies = pawn.health.hediffSet.GetHediffs(); + if (!pregnancies.Any()) return -1; + else return pregnancies.MaxBy(hediff => hediff.GestationProgress)?.GestationProgress ?? -1; } public static float GetPregnancyProgress(this HediffComp_Menstruation comp)