Erase unborn babies upon miscarriage.

This commit is contained in:
lutepickle 2024-05-26 08:22:12 -07:00
parent 1c62cb2293
commit 4febc97c73
2 changed files with 20 additions and 0 deletions

View file

@ -161,6 +161,13 @@ namespace RJW_Menstruation
}
}
}
public void Miscarried()
{
if (babies == null) return;
foreach (Pawn baby in babies)
baby.Destroy(DestroyMode.Vanish);
}
}
[HarmonyPatch(typeof(PregnancyUtility), nameof(PregnancyUtility.ApplyBirthOutcome_NewTemp))]
@ -333,4 +340,14 @@ namespace RJW_Menstruation
return;
}
}
[HarmonyPatch(typeof(Hediff_Pregnant), nameof(Hediff_Pregnant.Miscarry))]
public static class Miscarry_Patch
{
public static void Postfix(Hediff_Pregnant __instance)
{
HediffComp_PregeneratedBabies comp = __instance.TryGetComp<HediffComp_PregeneratedBabies>();
if (comp != null) comp.Miscarried();
}
}
}

View file

@ -38,6 +38,9 @@ namespace RJW_Menstruation
public override void Miscarry()
{
this.GetMenstruationCompFromPregnancy().Pregnancy = null;
if (babies != null)
foreach (var baby in babies)
baby.Destroy(DestroyMode.Vanish);
base.Miscarry();
}