HAR transpiles ApplyBirthOutcome to produce multiple children per littersize, but the pregenerated babies already handle that. So patch HAR to only produce one if our system is running

This commit is contained in:
lutepickle 2023-01-10 12:41:02 -08:00
parent b9bfad10bb
commit 2cb26ea016
3 changed files with 21 additions and 1 deletions

Binary file not shown.

View file

@ -283,4 +283,18 @@ namespace RJW_Menstruation
}
}
}
// HAR patches ApplyBirthOutcome to produce multiple babies based on the mother's littersize. But the pregenerated babies system already makes multiple babies
// So make it always consider the mother to have one baby
public static class HAR_LitterSize_Undo
{
public static void Postfix(ref int __result, Pawn mother)
{
if (Configurations.PregnancySource != Configurations.PregnancyType.Biotech || !Configurations.EnableBiotechTwins) return;
// 'mother' is the genetic mother, but unless she's in labor at the same time the birtherthing is spitting out, this will work as intended
if (mother?.health.hediffSet.GetFirstHediff<Hediff_LaborPushing>()?.TryGetComp<HediffComp_PregeneratedBabies>()?.HasBaby ?? false)
__result = 0;
return;
}
}
}

View file

@ -1,4 +1,5 @@
using HarmonyLib;
using AlienRace;
using HarmonyLib;
using rjw;
using rjw.Modules.Interactions.Internals.Implementation;
using rjw.Modules.Interactions.Rules.PartKindUsageRules;
@ -16,6 +17,11 @@ namespace RJW_Menstruation
{
Harmony har = new Harmony("RJW_Menstruation");
har.PatchAll(Assembly.GetExecutingAssembly());
if (ModsConfig.IsActive("erdelf.HumanoidAlienRaces")) // Don't use the cached in Configurations, it isn't initialized yet
{
har.Patch(typeof(AlienRace.HarmonyPatches).GetMethod(nameof(AlienRace.HarmonyPatches.BirthOutcomeMultiplier)),
postfix: new HarmonyMethod(typeof(HAR_LitterSize_Undo).GetMethod(nameof(HAR_LitterSize_Undo.Postfix))));
}
InjectIntoRjwInteractionServices();
}