From 96109e7607bdb58c1bd24440daac3436fff03bc9 Mon Sep 17 00:00:00 2001 From: lutepickle <28810-lutepickle@users.noreply.gitgud.io> Date: Wed, 5 Oct 2022 08:53:24 -0700 Subject: [PATCH] Refactor breast CalculateLastBirth --- .../HediffComps/HediffComp_Breast.cs | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 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 9f651ff..e7eaf60 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 @@ -210,25 +210,16 @@ namespace RJW_Menstruation protected long CalculateLastBirth() { long youngestAge = (long)(BabyHalfAge * GenDate.TicksPerYear) * -2; // So a newborn isn't considered a new mother, either - if ((Pawn.relations?.ChildrenCount ?? 0) > 0) - { - foreach (Pawn child in Pawn.relations.Children) - { - bool isFetus = false; - if (Pawn.health.hediffSet.GetHediffs().Any(preg => preg.babies.Contains(child))) - { - isFetus = true; - break; - } - - if ( - Pawn.ageTracker.BirthAbsTicks - child.ageTracker.BirthAbsTicks > ageOfLastBirth && - !isFetus && - child.GetMother() == Pawn // Don't do Dad's boobs - ) - youngestAge = Pawn.ageTracker.BirthAbsTicks - child.ageTracker.BirthAbsTicks; - } - } + + if ((Pawn.relations == null)) return youngestAge; + + bool hasChild = Pawn.relations.Children. + Where(child => !Pawn.health.hediffSet.GetHediffs().Any(preg => preg.babies.Contains(child))). // no fetuses + Where(child => child.GetMother() == Pawn). // not Dad + TryMinBy(child => child.ageTracker.AgeBiologicalTicks, out Pawn youngest); + + if (hasChild) youngestAge = Pawn.ageTracker.AgeBiologicalTicks - youngest.ageTracker.AgeBiologicalTicks; + return youngestAge; }