From 511e5286dc0677b3fbccfbdd333412b3724d0c47 Mon Sep 17 00:00:00 2001 From: lutepickle <28810-lutepickle@users.noreply.gitgud.io> Date: Fri, 23 Sep 2022 06:51:04 -0700 Subject: [PATCH] Copy Animal Genetics properties for enzygotic siblings --- .../AnimalGeneticsCompatibility.cs | 25 ++++++++++++++----- .../Hediff_MultiplePregnancy.cs | 4 +-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/1.3/source/RJW_Menstruation/RJW_Menstruation/Compatibility/AnimalGeneticsCompatibility.cs b/1.3/source/RJW_Menstruation/RJW_Menstruation/Compatibility/AnimalGeneticsCompatibility.cs index 709e086..7cc1e5e 100644 --- a/1.3/source/RJW_Menstruation/RJW_Menstruation/Compatibility/AnimalGeneticsCompatibility.cs +++ b/1.3/source/RJW_Menstruation/RJW_Menstruation/Compatibility/AnimalGeneticsCompatibility.cs @@ -1,4 +1,6 @@ using AnimalGenetics; +using RimWorld; +using System.Collections.Generic; using Verse; namespace RJW_Menstruation @@ -10,12 +12,6 @@ namespace RJW_Menstruation GeneticInformation motherGeneticInformation = mother?.AnimalGenetics(); GeneticInformation fatherGeneticInformation = father?.AnimalGenetics(); - if (fatherGeneticInformation == null && motherGeneticInformation != null) - { - FatherGeneticInformation fatherGeneticInformationComp = pregnancy.TryGetComp(); - fatherGeneticInformation = fatherGeneticInformationComp?.GeneticInformation; - } - ParentReferences.Push(new ParentReferences.Record { Mother = motherGeneticInformation, Father = fatherGeneticInformation }); } @@ -23,5 +19,22 @@ namespace RJW_Menstruation { ParentReferences.Pop(); } + + public static void CopyGenes(Pawn baby, Pawn original) + { + Dictionary babyRecords = baby.AnimalGenetics()?.GeneRecords; + Dictionary originalRecords = original.AnimalGenetics()?.GeneRecords; + + if (babyRecords == null || originalRecords == null) return; + + foreach(KeyValuePair record in originalRecords) + { + GeneRecord originalRecord = record.Value; + if (!babyRecords.TryGetValue(record.Key, out GeneRecord babyRecord)) continue; // Shouldn't fail, but best to be safe + + babyRecord.Parent = originalRecord.Parent; + babyRecord.Value = originalRecord.Value; + } + } } } diff --git a/1.3/source/RJW_Menstruation/RJW_Menstruation/Hediff_MultiplePregnancy.cs b/1.3/source/RJW_Menstruation/RJW_Menstruation/Hediff_MultiplePregnancy.cs index 9985921..e395e6b 100644 --- a/1.3/source/RJW_Menstruation/RJW_Menstruation/Hediff_MultiplePregnancy.cs +++ b/1.3/source/RJW_Menstruation/RJW_Menstruation/Hediff_MultiplePregnancy.cs @@ -455,9 +455,9 @@ namespace RJW_Menstruation baby.story.SetMemberValue("headGraphicPath", firstheadpath); if (baby.IsHAR()) - { HARCompatibility.CopyHARProperties(baby, firstbaby); - } + if (Configurations.AnimalGeneticsActivated) + AnimalGeneticsCompatibility.CopyGenes(baby, firstbaby); } } babies.Add(baby);