Example #1
0
        public override string ExplanationPart(StatRequest req)
        {
            if (!Genes.EffectsThing(req.Thing))
            {
                return(null);
            }

            Pawn pawn = req.Thing as Pawn;

            if (!Settings.Core.omniscientMode && pawn.Faction != Faction.OfPlayer)
            {
                return(null);
            }

            var statRecord = pawn.AnimalGenetics().GeneRecords[_StatDef];

            if (statRecord == null)
            {
                return(null);
            }

            string postfix = "";

            if (statRecord.Parent != GeneRecord.Source.None)
            {
                string icon = statRecord.Parent == GeneRecord.Source.Mother ? "♀" : "♂";
                postfix = " (x" + GenText.ToStringPercent(statRecord.ParentValue) + icon + ")";
            }

            return("AG.Genetics".Translate() + ": x" + GenText.ToStringPercent(statRecord.Value) + postfix);
        }
Example #2
0
        public override string ExplanationPart(StatRequest req)
        {
            if (!Genes.EffectsThing(req.Thing))
            {
                return(null);
            }

            Pawn pawn = req.Thing as Pawn;

            if (!Controller.Settings.omniscientMode && pawn.Faction != Faction.OfPlayer)
            {
                return(null);
            }

            var statRecord = Find.World.GetComponent <AnimalGenetics>().GetFactor(pawn, _StatDef);

            if (statRecord == null)
            {
                return(null);
            }

            string postfix = "";

            if (statRecord.Parent != StatRecord.Source.None)
            {
                string icon = statRecord.Parent == StatRecord.Source.Mother ? "♀" : "♂";
                postfix = " (x" + GenText.ToStringPercent(statRecord.ParentValue) + icon + ")";
            }

            return("AG.Genetics".Translate() + ": x" + GenText.ToStringPercent(statRecord.Value) + postfix);
        }
Example #3
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;
            }
        }
 public static IEnumerable <StatDef> GetGenes(this Pawn pawn)
 {
     if (!Genes.EffectsThing(pawn))
     {
         return(new List <StatDef>());
     }
     return(Constants.affectedStats.Where((StatDef stat) =>
                                          stat != AG.GatherYield || Genes.Gatherable(pawn)));
 }
        public override void TransformValue(StatRequest req, ref float val)
        {
            var pawn = req.Thing as Pawn;

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

            var genes = pawn.GetGenes();

            var factor = genes.Select(g => pawn.GetGene(g)).Aggregate(1.0f, (lhs, rhs) => lhs * rhs);

            val *= factor;
        }
Example #6
0
        public StatGroup GenerateStatsGroup(Pawn pawn)
        {
            StatGroup toReturn = new StatGroup();

            if (!Genes.EffectsThing(pawn))
            {
                return(toReturn);
            }

            var mother = pawn.GetMother();
            var father = pawn.GetFather();

            var motherStats = mother == null ? null : GetData(mother);
            var fatherStats = father == null ? null : GetData(father);

            var affectedStats = Constants.affectedStats;

            foreach (var stat in affectedStats)
            {
                var record = new StatRecord();

                float motherValue = motherStats != null?motherStats.GetFactor(stat).Value : Utilities.SampleGaussian(Controller.Settings.mean, Controller.Settings.stdDev, 0.1f);

                float fatherValue = fatherStats != null?fatherStats.GetFactor(stat).Value : Utilities.SampleGaussian(Controller.Settings.mean, Controller.Settings.stdDev, 0.1f);

                bool fromMother = Utilities.SampleInt() % 2 == 0;

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

                record.Value = record.ParentValue + Utilities.SampleGaussian(Controller.Settings.mutationMean, Controller.Settings.mutationStdDev);
                record.Value = Mathf.Max(record.Value, 0.1f);

                toReturn.Data[stat] = record;
            }

            return(toReturn);
        }
Example #7
0
        float?GetFactor(StatRequest req)
        {
            if (!req.HasThing)
            {
                return(null);
            }

            if (!Genes.EffectsThing(req.Thing))
            {
                return(null);
            }

            Pawn pawn = req.Thing as Pawn;

            var statRecord = pawn.AnimalGenetics().GeneRecords[_StatDef];

            return(statRecord == null ? 1.0f : statRecord.Value);
        }
Example #8
0
        float?GetFactor(StatRequest req)
        {
            if (!req.HasThing)
            {
                return(null);
            }

            if (!Genes.EffectsThing(req.Thing))
            {
                return(null);
            }

            Pawn pawn = req.Thing as Pawn;

            var statRecord = Find.World.GetComponent <AnimalGenetics>().GetFactor(pawn, _StatDef);

            return(statRecord == null ? 1.0f : statRecord.Value);
        }
Example #9
0
        public override string ExplanationPart(StatRequest req)
        {
            if (!Genes.EffectsThing(req.Thing))
            {
                return(null);
            }

            if (!(req.Thing is Pawn pawn))
            {
                return("");
            }

            if (!Settings.Core.omniscientMode && pawn.Faction != Faction.OfPlayer)
            {
                return(null);
            }

            var statRecord = pawn.GetGeneRecord(_StatDef);

            if (statRecord == null)
            {
                return(null);
            }

            string postfix = "";

            if (statRecord.Parent != GeneRecord.Source.None)
            {
                string icon = statRecord.Parent == GeneRecord.Source.Mother ? "♀" : "♂";

                var parentGeneticInformation = statRecord.Parent == GeneRecord.Source.Mother
                    ? pawn.AnimalGenetics()?.Mother
                    : pawn.AnimalGenetics()?.Father;

                // Shouldn't really occur...
                if (parentGeneticInformation != null)
                {
                    var parentValue = parentGeneticInformation.GeneRecords[_StatDef].Value;
                    postfix = " (x" + parentValue.ToStringPercent() + icon + ")";
                }
            }

            return("AG.Genetics".Translate() + ": x" + statRecord.Value.ToStringPercent() + postfix);
        }
Example #10
0
        float?GetFactor(StatRequest req)
        {
            if (!req.HasThing)
            {
                return(null);
            }

            if (!Genes.EffectsThing(req.Thing))
            {
                return(null);
            }

            Pawn pawn = req.Thing as Pawn;

            if (pawn == null)
            {
                Log.Error(req.Thing.ToStringSafe() + " is not a Pawn");
            }

            var statRecord = pawn.GetGeneRecord(_StatDef);

            return(statRecord == null ? 1.0f : statRecord.Value);
        }
Example #11
0
 public override bool ShouldShowFor(StatRequest req)
 {
     return(Genes.EffectsThing(req.Thing));
 }