Esempio n. 1
0
        public static GenesRecord GenerateGenesRecord(GeneticInformation mother, GeneticInformation father)
        {
            var result = new GenesRecord();

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

            if (Scribe.EnterNode("settings"))
            {
                Settings.ExposeData();
                Scribe.ExitNode();
            }
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
 public StatGroup(GeneticInformation geneticInformation)
 {
     Data = new Dictionary <StatDef, GeneRecord>(geneticInformation.GeneRecords);
 }
Esempio n. 6
0
 public override void Initialize(CompProperties props)
 {
     base.Initialize(props);
     GeneticInformation = ParentReferences.ThisGeneticInformation ?? new GeneticInformation();
 }