Make the breast adjustment go off of the mother's biological age

This commit is contained in:
lutepickle 2022-03-13 08:26:53 -07:00
parent e0b8f30e76
commit 89d6353e16
2 changed files with 60 additions and 54 deletions

Binary file not shown.

View file

@ -52,8 +52,8 @@ namespace RJW_Menstruation
protected float nippleSizePermanent = -1f; protected float nippleSizePermanent = -1f;
protected float nippleSizeCurrent = -1f; protected float nippleSizeCurrent = -1f;
protected float nippleSize = -1f; protected float nippleSize = -1f;
protected long ageOfLastBirth = 0;
protected float breastSizeIncreased = 0f; protected float breastSizeIncreased = 0f;
protected long lastBabyBorn = -1;
protected float originalpha = -1f; protected float originalpha = -1f;
protected float originareola = -1f; protected float originareola = -1f;
protected float originnipple = -1f; protected float originnipple = -1f;
@ -66,7 +66,7 @@ namespace RJW_Menstruation
{ {
get get
{ {
float res = (parent?.pawn?.RaceProps?.lifeStageAges?.ElementAtOrDefault(1).minAge ?? 0.0f) / 2; float res = parent.pawn.RaceProps.lifeStageAges.ElementAtOrDefault(1).minAge / 2;
if (res == 0.0f) if (res == 0.0f)
{ {
if (Configurations.Debug) Log.Warning($"Could not find end age of baby lifestage for {parent.pawn}'s race"); if (Configurations.Debug) Log.Warning($"Could not find end age of baby lifestage for {parent.pawn}'s race");
@ -163,6 +163,7 @@ namespace RJW_Menstruation
Scribe_Values.Look(ref nippleSizePermanent, "nippleSizePermanent", DEFAULTNIPPLE, true); Scribe_Values.Look(ref nippleSizePermanent, "nippleSizePermanent", DEFAULTNIPPLE, true);
Scribe_Values.Look(ref nippleSizeCurrent, "nippleSizeCurrent", DEFAULTNIPPLE, true); Scribe_Values.Look(ref nippleSizeCurrent, "nippleSizeCurrent", DEFAULTNIPPLE, true);
Scribe_Values.Look(ref nippleSize, "nippleSize", DEFAULTNIPPLE, true); Scribe_Values.Look(ref nippleSize, "nippleSize", DEFAULTNIPPLE, true);
Scribe_Values.Look(ref ageOfLastBirth, "ageOfLastBirth", ageOfLastBirth, true);
Scribe_Values.Look(ref breastSizeIncreased, "breastSizeIncreased", breastSizeIncreased, true); Scribe_Values.Look(ref breastSizeIncreased, "breastSizeIncreased", breastSizeIncreased, true);
Scribe_Values.Look(ref originalpha, "originalpha", originalpha, true); Scribe_Values.Look(ref originalpha, "originalpha", originalpha, true);
Scribe_Values.Look(ref originareola, "originareola", originareola, true); Scribe_Values.Look(ref originareola, "originareola", originareola, true);
@ -176,6 +177,7 @@ namespace RJW_Menstruation
public override void CompPostPostAdd(DamageInfo? dinfo) public override void CompPostPostAdd(DamageInfo? dinfo)
{ {
if (!loaded) Initialize(); if (!loaded) Initialize();
if (ageOfLastBirth > parent.pawn.ageTracker.AgeChronologicalTicks) ageOfLastBirth = CalculateLastBirth(); // catch transplant issues
} }
public override void CompPostPostRemoved() public override void CompPostPostRemoved()
@ -193,32 +195,39 @@ namespace RJW_Menstruation
} }
} }
protected long CalculateLastBirth()
{
long youngestAge = (long)(BabyHalfAge * GenDate.TicksPerYear) * -2; // So a newborn isn't considered a new mother, either
if ((parent.pawn.relations?.ChildrenCount ?? 0) > 0)
{
foreach (Pawn child in parent.pawn.relations.Children)
{
bool isFetus;
if (PregnancyHelper.GetPregnancy(parent.pawn) is Hediff_BasePregnancy preg)
{
isFetus = preg.babies.Contains(child);
}
else isFetus = false;
if (
parent.pawn.ageTracker.BirthAbsTicks - child.ageTracker.BirthAbsTicks > ageOfLastBirth &&
!isFetus &&
child.GetMother() == parent.pawn // Don't do Dad's boobs
)
youngestAge = parent.pawn.ageTracker.BirthAbsTicks - child.ageTracker.BirthAbsTicks;
}
}
return youngestAge;
}
public void Initialize() public void Initialize()
{ {
Props = (CompProperties_Breast)props; Props = (CompProperties_Breast)props;
action = Transition; action = Transition;
if (lastBabyBorn < 0) if (ageOfLastBirth == 0)
{ {
if ((parent?.pawn?.relations?.ChildrenCount ?? 0) > 0) ageOfLastBirth = CalculateLastBirth();
{
foreach (Pawn child in parent.pawn.relations.Children)
{
bool isFetus;
if (PregnancyHelper.GetPregnancy(parent.pawn) is Hediff_BasePregnancy preg)
{
isFetus = preg.babies.Contains(child);
}
else isFetus = false;
if (
child.ageTracker.BirthAbsTicks > lastBabyBorn &&
!isFetus &&
child.GetMother() == parent.pawn // Don't do Dad's boobs
)
lastBabyBorn = child.ageTracker.BirthAbsTicks;
}
}
else lastBabyBorn = 0;
} }
if (alphaPermanent < 0f) if (alphaPermanent < 0f)
@ -257,43 +266,40 @@ namespace RJW_Menstruation
UpdateColor(); UpdateColor();
HugsLibController.Instance.TickDelayScheduler.ScheduleCallback(action, TICKINTERVAL, parent.pawn); HugsLibController.Instance.TickDelayScheduler.ScheduleCallback(action, TICKINTERVAL, parent.pawn);
if (!(parent?.pawn?.health?.Dead ?? true)) // Scenario A: the youngest child is less than halfway into babyhood: Full size
if (ageOfLastBirth + BabyHalfAge * GenDate.TicksPerYear > parent.pawn.ageTracker.AgeBiologicalTicks)
{ {
// Scenario A: the youngest child is less than halfway into babyhood: Full size if (Configurations.Debug) Log.Message($"Latest child of {parent.pawn} is young: breasts to full size");
if (lastBabyBorn + BabyHalfAge * GenDate.TicksPerYear > GenTicks.TicksAbs) if (breastSizeIncreased < MAX_BREAST_INCREMENT)
{ {
if (Configurations.Debug) Log.Message($"Latest child of {parent.pawn} is young: breasts to full size"); parent.Severity += (MAX_BREAST_INCREMENT - breastSizeIncreased);
if (breastSizeIncreased < MAX_BREAST_INCREMENT) breastSizeIncreased = MAX_BREAST_INCREMENT;
{
parent.Severity += (MAX_BREAST_INCREMENT - breastSizeIncreased);
breastSizeIncreased = MAX_BREAST_INCREMENT;
}
} }
// Scenario B: Pregnant, grow in the second half of first trimester }
else if (parent.pawn.IsPregnant()) // Scenario B: Pregnant, grow in the second half of first trimester
else if (parent.pawn.IsPregnant())
{
float pregnancySize = Mathf.InverseLerp(1f / 6f, 1f / 3f, parent.pawn.GetPregnancyProgress()) * MAX_BREAST_INCREMENT;
if (breastSizeIncreased > pregnancySize)
{ {
float pregnancySize = Mathf.InverseLerp(1f / 6f, 1f / 3f, parent.pawn.GetPregnancyProgress()) * MAX_BREAST_INCREMENT; if (Configurations.Debug) Log.Message($"{parent.pawn}'s breasts are too large for pregnancy ({breastSizeIncreased} > {pregnancySize}), shrinking");
if (breastSizeIncreased > pregnancySize) // Breasts still large from the last kid
{
if (Configurations.Debug) Log.Message($"{parent.pawn}'s breasts are too large for pregnancy ({breastSizeIncreased} > {pregnancySize}), shrinking");
// Breasts still large from the last kid
ShrinkBreasts();
}
else if (breastSizeIncreased < MAX_BREAST_INCREMENT)
{
// Time to grow
float growAmount = pregnancySize - breastSizeIncreased;
if (Configurations.Debug) Log.Message($"{parent.pawn} is pregnant, so growing breasts by {growAmount}");
breastSizeIncreased += growAmount;
parent.Severity += growAmount;
}
}
// Scenario C: Not (or very early) pregnant and youngest child nonexistent or more than halfway into babyhood, time to shrink
else if (breastSizeIncreased > 0)
{
if (Configurations.Debug) Log.Message($"{parent.pawn}'s breasts are too large and she is not pregnant, shrinking");
ShrinkBreasts(); ShrinkBreasts();
} }
else if (breastSizeIncreased < MAX_BREAST_INCREMENT)
{
// Time to grow
float growAmount = pregnancySize - breastSizeIncreased;
if (Configurations.Debug) Log.Message($"{parent.pawn} is pregnant, so growing breasts by {growAmount}");
breastSizeIncreased += growAmount;
parent.Severity += growAmount;
}
}
// Scenario C: Not (or very early) pregnant and youngest child nonexistent or more than halfway into babyhood, time to shrink
else if (breastSizeIncreased > 0)
{
if (Configurations.Debug) Log.Message($"{parent.pawn}'s breasts are too large and she is not pregnant, shrinking");
ShrinkBreasts();
} }
} }
@ -324,7 +330,7 @@ namespace RJW_Menstruation
areolaSize = areolaSizePermanent; areolaSize = areolaSizePermanent;
nippleSize = nippleSizePermanent; nippleSize = nippleSizePermanent;
pregnant = false; pregnant = false;
lastBabyBorn = GenTicks.TicksAbs; ageOfLastBirth = parent.pawn.ageTracker.AgeBiologicalTicks;
} }