示例#1
0
        public void Generate(Pawn mother = null, Pawn father = null)
        {
            if (!(parent is Pawn pawn))
            {
                return;
            }

            if (!Genes.EffectsThing(parent))
            {
                return;
            }

            _geneRecords = new Dictionary <StatDef, GeneRecord>();

            if (mother == null)
            {
                mother = pawn.GetMother();
            }

            if (father == null)
            {
                father = pawn.GetFather();
            }

            var motherStats = mother?.AnimalGenetics().GeneRecords;
            var fatherStats = father?.AnimalGenetics().GeneRecords;

            var affectedStats = Constants.affectedStats;

            foreach (var stat in affectedStats)
            {
                float motherValue = motherStats != null ? motherStats[stat].Value : Mathf.Max(Verse.Rand.Gaussian(Settings.Core.mean, Settings.Core.stdDev), 0.1f);
                float fatherValue = fatherStats != null ? fatherStats[stat].Value : Mathf.Max(Verse.Rand.Gaussian(Settings.Core.mean, Settings.Core.stdDev), 0.1f);

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

                float?ToNullableFloat(bool nullify, float value) => nullify ? null : (float?)value;

                var record = new GeneRecord(ToNullableFloat(mother == null, motherValue), ToNullableFloat(father == null, fatherValue));
                record.ParentValue = Verse.Rand.Chance(Settings.Core.bestGeneChance) ? highValue : lowValue;

                if (record.ParentValue == motherValue)
                {
                    record.Parent = motherStats != null ? GeneRecord.Source.Mother : GeneRecord.Source.None;
                }
                else
                {
                    record.Parent = fatherStats != null ? GeneRecord.Source.Father : GeneRecord.Source.None;
                }

                record.Value = record.ParentValue + Verse.Rand.Gaussian(Settings.Core.mutationMean, Settings.Core.mutationStdDev);
                record.Value = Mathf.Max(record.Value, 0.1f);

                _geneRecords[stat] = record;
            }
        }
示例#2
0
        public static String GetInheritString(GeneRecord statRecord)
        {
            GeneRecord.Source parentType = statRecord.Parent;
            if (parentType == GeneRecord.Source.None)
            {
                return("");
            }

            string gender = parentType == GeneRecord.Source.Mother ? "♀" : "♂";

            return((statRecord.ParentValue * 100).ToString("F0") + "% " + gender);
        }
        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;
            }
        }