diff --git a/1.4/source/RJW_Menstruation/RJW_Menstruation/Configurations.cs b/1.4/source/RJW_Menstruation/RJW_Menstruation/Configurations.cs index c496fb6..80aceeb 100644 --- a/1.4/source/RJW_Menstruation/RJW_Menstruation/Configurations.cs +++ b/1.4/source/RJW_Menstruation/RJW_Menstruation/Configurations.cs @@ -437,8 +437,8 @@ namespace RJW_Menstruation Configurations.PregnancySource = Configurations.PregnancyType.MultiplePregnancy; if (ModsConfig.BiotechActive && listmain.RadioButton(Translations.Option_PregnancyFromBiotech_Label, Configurations.PregnancySource == Configurations.PregnancyType.Biotech)) Configurations.PregnancySource = Configurations.PregnancyType.Biotech; - // TODO: Also for modified Biotech pregnancy - if (Configurations.PregnancySource == Configurations.PregnancyType.MultiplePregnancy) + if (Configurations.PregnancySource == Configurations.PregnancyType.MultiplePregnancy || + (Configurations.PregnancySource == Configurations.PregnancyType.Biotech && Configurations.EnableBiotechTwins)) { float sectionheight = 75f; if (Configurations.EnableEnzygoticTwins) sectionheight += 100; diff --git a/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs b/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs index f0d8ef2..53171f8 100644 --- a/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs +++ b/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs @@ -181,4 +181,88 @@ namespace RJW_Menstruation } } } + + [HarmonyPatch(typeof(Hediff_LaborPushing), nameof(Hediff_LaborPushing.PreRemoved))] + public static class Hediff_LaborPushing_PreRemoved_Patch + { + private static Thing ApplyBirthLoop(OutcomeChance outcome, float quality, Precept_Ritual ritual, List genes, Pawn geneticMother, Thing birtherThing, Pawn father, Pawn doctor, LordJob_Ritual lordJobRitual, RitualRoleAssignments assignments) + { + if (birtherThing is Pawn mother) + { + HediffComp_PregeneratedBabies comp = mother.health.hediffSet.GetFirstHediff().TryGetComp(); + if (comp?.HasBaby ?? false) + { + OutcomeChance thisOutcome = outcome; + Precept_Ritual precept_Ritual = (Precept_Ritual)comp.Pawn.Ideo.GetPrecept(PreceptDefOf.ChildBirth); + float birthQuality = PregnancyUtility.GetBirthQualityFor(mother); + + do + { + PregnancyUtility.ApplyBirthOutcome(thisOutcome, quality, ritual, genes, geneticMother, birtherThing, father, doctor, lordJobRitual, assignments); + // No more babies if mom dies halfway through. Unrealistic maybe, but saves a lot of headache in ApplyBirthOutcome + if (mother.health.Dead) break; + thisOutcome = ((RitualOutcomeEffectWorker_ChildBirth)precept_Ritual.outcomeEffect).GetOutcome(birthQuality, null); + } while (comp.HasBaby); + + // PreRemoved doesn't use the return value + return null; + } + } + + return PregnancyUtility.ApplyBirthOutcome(outcome, quality, ritual, genes, geneticMother, birtherThing, father, doctor, lordJobRitual, assignments); + } + + private static readonly MethodInfo ApplyBirthOutcome = typeof(PregnancyUtility).GetMethod(nameof(PregnancyUtility.ApplyBirthOutcome), + new Type[] {typeof(OutcomeChance), typeof(float), typeof(Precept_Ritual), typeof(List), typeof(Pawn), typeof(Thing), typeof(Pawn), typeof(Pawn), typeof(LordJob_Ritual), typeof(RitualRoleAssignments)}); + public static IEnumerable Transpiler(IEnumerable instructions) + { + if (ApplyBirthOutcome == null || ApplyBirthOutcome.ReturnType != typeof(Thing)) throw new InvalidOperationException("ApplyBirthOutcome not found"); + foreach (CodeInstruction instruction in instructions) + { + if (instruction.Calls(ApplyBirthOutcome)) + yield return CodeInstruction.Call(typeof(Hediff_LaborPushing_PreRemoved_Patch), nameof(Hediff_LaborPushing_PreRemoved_Patch.ApplyBirthLoop)); + else yield return instruction; + } + } + } + + // Much the same as the other one + [HarmonyPatch(typeof(RitualOutcomeEffectWorker_ChildBirth), nameof (RitualOutcomeEffectWorker_ChildBirth.Apply))] + public static class Ritual_ChildBirth_Apply_Patch + { + private static Thing ApplyBirthLoop(OutcomeChance outcome, float quality, Precept_Ritual ritual, List genes, Pawn geneticMother, Thing birtherThing, Pawn father, Pawn doctor, LordJob_Ritual lordJobRitual, RitualRoleAssignments assignments) + { + if (birtherThing is Pawn mother) + { + HediffComp_PregeneratedBabies comp = mother.health.hediffSet.GetFirstHediff().TryGetComp(); + if (comp?.HasBaby ?? false) + { + // Don't reroll the outcome every time, I think + // This is all one ritual, so every baby has the same ritual outcome + // I don't think this will add the ritual memory every time? + // Though even if it does, that's probably okay. More babies more memories after all + do + { + PregnancyUtility.ApplyBirthOutcome(outcome, quality, ritual, genes, geneticMother, birtherThing, father, doctor, lordJobRitual, assignments); + if (mother.health.Dead) break; + } while (comp.HasBaby); + + return null; + } + } + return PregnancyUtility.ApplyBirthOutcome(outcome, quality, ritual, genes, geneticMother, birtherThing, father, doctor, lordJobRitual, assignments); + } + private static readonly MethodInfo ApplyBirthOutcome = typeof(PregnancyUtility).GetMethod(nameof(PregnancyUtility.ApplyBirthOutcome), + new Type[] { typeof(OutcomeChance), typeof(float), typeof(Precept_Ritual), typeof(List), typeof(Pawn), typeof(Thing), typeof(Pawn), typeof(Pawn), typeof(LordJob_Ritual), typeof(RitualRoleAssignments) }); + public static IEnumerable Transpiler(IEnumerable instructions) + { + if (ApplyBirthOutcome == null || ApplyBirthOutcome.ReturnType != typeof(Thing)) throw new InvalidOperationException("ApplyBirthOutcome not found"); + foreach (var instruction in instructions) + { + if (instruction.Calls(ApplyBirthOutcome)) + yield return CodeInstruction.Call(typeof(Ritual_ChildBirth_Apply_Patch), nameof(Ritual_ChildBirth_Apply_Patch.ApplyBirthLoop)); + else yield return instruction; + } + } + } }