rjw-genes/Source/Animal_Inheritance/Patches/Patch_RJW_PregnancyHelper_VanillaExpandedGenetics.cs

66 lines
3.1 KiB
C#
Raw Normal View History

2024-06-04 11:08:37 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RJW_BGS;
using HarmonyLib;
using rjw;
using static rjw.Hediff_BasePregnancy;
2024-06-04 15:16:36 +00:00
using RJW_Genes;
2024-06-04 11:08:37 +00:00
namespace RJW_BGS
{
[HarmonyPatch(typeof(PregnancyHelper))]
public class Patch_RJW_PregnancyHelper_VanillaExpandedGenetics
2024-06-04 11:08:37 +00:00
{
/// <summary>
/// This Patch changes the pregnancy logic to check for possible hybridization.
/// Iff the hybrdiization applies, this prefix skips the normal AddPregnancyHediff (by returning false).
///
/// Small Note: Below we use `Hediff_BasePregnancy.Create<Hediff_BestialPregnancy>(mother, father, DnaGivingParent.Mother);`
/// This completely creates the pregnancy, it does not need to be assigned to anything or added to some hediffs.
/// </summary>
2024-06-04 11:08:37 +00:00
[HarmonyPrefix]
[HarmonyPatch("AddPregnancyHediff")]
public static bool AddPregnancyHediffPrefix(Pawn mother, Pawn father)
{
if (!RJW_BGSSettings.rjw_bgs_VE_genetics) return true;
if (mother == null || father == null) return true;
bool humanMotherAndSupportedAnimal = mother.IsHuman() && Patch_RJW_BasePregnancy_VanillaExpandedGenetics.supportedInitialAnimalRaces.Contains(father.kindDef.race.defName);
bool humanMotherAndSupportedHybrid = mother.IsHuman() && Patch_RJW_BasePregnancy_VanillaExpandedGenetics.supportedHybridRaces.Contains(father.kindDef.race.defName);
bool humanFatherAndSupportedAnimal = father.IsHuman() && Patch_RJW_BasePregnancy_VanillaExpandedGenetics.supportedInitialAnimalRaces.Contains(mother.kindDef.race.defName);
bool humanFatherAndSupportedHybrid = father.IsHuman() && Patch_RJW_BasePregnancy_VanillaExpandedGenetics.supportedHybridRaces.Contains(mother.kindDef.race.defName);
2024-06-04 11:08:37 +00:00
2024-06-04 14:44:50 +00:00
if (!(humanMotherAndSupportedAnimal || humanMotherAndSupportedHybrid||humanFatherAndSupportedAnimal|| humanFatherAndSupportedHybrid)) return true;
if (humanMotherAndSupportedAnimal)
2024-06-04 11:08:37 +00:00
{
Hediff_BasePregnancy.Create<Hediff_BestialPregnancy>(mother, father, DnaGivingParent.Father);
return false;
}
2024-06-04 14:44:50 +00:00
else if (humanMotherAndSupportedHybrid)
2024-06-04 11:08:37 +00:00
{
2024-06-04 15:16:36 +00:00
if (RJW_Genes_Settings.rjw_genes_detailed_debug)
RJW_Genes.ModLog.Message("preg hediffdefof PregnantHuman " + RimWorld.HediffDefOf.PregnantHuman);
2024-06-04 11:08:37 +00:00
PregnancyHelper.StartVanillaPregnancy(mother, father);
return false;
}
2024-06-04 14:44:50 +00:00
else if (humanFatherAndSupportedAnimal)
2024-06-04 11:08:37 +00:00
{
Hediff_BasePregnancy.Create<Hediff_BestialPregnancy>(mother, father, DnaGivingParent.Mother);
return false;
}
2024-06-04 14:44:50 +00:00
else if (humanFatherAndSupportedHybrid)
2024-06-04 11:08:37 +00:00
{
Hediff_BasePregnancy.Create<Hediff_BestialPregnancy>(mother, father, DnaGivingParent.Father);
return false;
}
return true;
}
}
}