public static GenesRecord GenerateGenesRecord(GeneticInformation mother, GeneticInformation father)
        {
            var result = new GenesRecord();

            EnsureAllGenesExist(result, mother, father);
            return(result);
        }
        public override void ExposeData()
        {
            GeneticInformation.ExposeData();

            if (Scribe.EnterNode("settings"))
            {
                Settings.ExposeData();
                Scribe.ExitNode();
            }
        }
        public override void PostExposeData()
        {
            base.PostExposeData();

            if (Scribe.EnterNode("animalGenetics"))
            {
                Scribe_References.Look(ref GeneticInformation, "geneticInformation");

                GenesRecord legacyGenesRecord = null;
                Scribe_Collections.Look(ref legacyGenesRecord, "geneRecords");
                if (legacyGenesRecord != null)
                {
                    LegacyGenesRecords[this] = legacyGenesRecord;
                }

                if (Scribe.mode == LoadSaveMode.PostLoadInit)
                {
                    if (GeneticInformation == null)
                    {
                        if (LegacyGenesRecords.ContainsKey(this))
                        {
                            Log.Message("Migrating Legacy Genetic Information for " + parent.ToString());
                            GeneticInformation = new GeneticInformation(LegacyGenesRecords[this]);
                            LegacyGenesRecords.Remove(this);
                        }
                        else
                        {
                            Log.Message("Generating Genetic Information for " + parent.ToString());
                            GeneticInformation = new GeneticInformation(null);
                        }
                        GeneticCalculator.EnsureAllGenesExist(GeneticInformation.GeneRecords, null, null);
                    }
                    else
                    {
                        GeneticCalculator.EnsureAllGenesExist(GeneticInformation.GeneRecords, GeneticInformation.Mother, GeneticInformation.Father);
                    }
                }

                Scribe.ExitNode();
            }
        }
        public static void EnsureAllGenesExist(GenesRecord records, GeneticInformation mother, GeneticInformation father)
        {
            var affectedStats = Constants.affectedStats;

            foreach (var stat in affectedStats)
            {
                if (records.ContainsKey(stat))
                {
                    continue;
                }

                var motherStat = mother?.GeneRecords?[stat];
                var fatherStat = father?.GeneRecords?[stat];

                float motherValue = motherStat?.Value ??
                                    Mathf.Max(Rand.Gaussian(Settings.Core.mean, Settings.Core.stdDev), 0.1f);
                float fatherValue = fatherStat?.Value ??
                                    Mathf.Max(Rand.Gaussian(Settings.Core.mean, Settings.Core.stdDev), 0.1f);

                float highValue = Math.Max(motherValue, fatherValue);
                float lowValue  = Math.Min(motherValue, fatherValue);

                var record = new GeneRecord();

                var parentValue = Rand.Chance(Settings.Core.bestGeneChance) ? highValue : lowValue;
                var delta       = Rand.Gaussian(Settings.Core.mutationMean, Settings.Core.mutationStdDev);

                if (parentValue == motherValue)
                {
                    record.Parent = motherStat != null ? GeneRecord.Source.Mother : GeneRecord.Source.None;
                }
                else
                {
                    record.Parent = fatherStat != null ? GeneRecord.Source.Father : GeneRecord.Source.None;
                }

                record.Value = parentValue + delta;

                records[stat] = record;
            }
        }
 public StatGroup(GeneticInformation geneticInformation)
 {
     Data = new Dictionary <StatDef, GeneRecord>(geneticInformation.GeneRecords);
 }
 public override void Initialize(CompProperties props)
 {
     base.Initialize(props);
     GeneticInformation = ParentReferences.ThisGeneticInformation ?? new GeneticInformation();
 }