Refactor breast CalculateLastBirth

This commit is contained in:
lutepickle 2022-10-05 08:53:24 -07:00
parent 034bf4d75a
commit 96109e7607
1 changed files with 10 additions and 19 deletions

View File

@ -210,25 +210,16 @@ namespace RJW_Menstruation
protected long CalculateLastBirth() protected long CalculateLastBirth()
{ {
long youngestAge = (long)(BabyHalfAge * GenDate.TicksPerYear) * -2; // So a newborn isn't considered a new mother, either 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<Hediff_BasePregnancy>().Any(preg => preg.babies.Contains(child)))
{
isFetus = true;
break;
}
if ( if ((Pawn.relations == null)) return youngestAge;
Pawn.ageTracker.BirthAbsTicks - child.ageTracker.BirthAbsTicks > ageOfLastBirth &&
!isFetus && bool hasChild = Pawn.relations.Children.
child.GetMother() == Pawn // Don't do Dad's boobs Where(child => !Pawn.health.hediffSet.GetHediffs<Hediff_BasePregnancy>().Any(preg => preg.babies.Contains(child))). // no fetuses
) Where(child => child.GetMother() == Pawn). // not Dad
youngestAge = Pawn.ageTracker.BirthAbsTicks - child.ageTracker.BirthAbsTicks; TryMinBy(child => child.ageTracker.AgeBiologicalTicks, out Pawn youngest);
}
} if (hasChild) youngestAge = Pawn.ageTracker.AgeBiologicalTicks - youngest.ageTracker.AgeBiologicalTicks;
return youngestAge; return youngestAge;
} }