Copy Animal Genetics properties for enzygotic siblings

This commit is contained in:
lutepickle 2022-09-23 06:51:04 -07:00
parent 9e8dcc0540
commit 511e5286dc
2 changed files with 21 additions and 8 deletions

View File

@ -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>();
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<StatDef, GeneRecord> babyRecords = baby.AnimalGenetics()?.GeneRecords;
Dictionary<StatDef, GeneRecord> originalRecords = original.AnimalGenetics()?.GeneRecords;
if (babyRecords == null || originalRecords == null) return;
foreach(KeyValuePair<StatDef, GeneRecord> 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;
}
}
}
}

View File

@ -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);