Пример #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);
        }
Пример #2
0
        private static float DrawSingleParentData(Rect rect, float curY, Pawn pawn)
        {
            Text.Anchor = TextAnchor.MiddleCenter;

            Rect rectParent = new Rect(rect.x + rect.width * 0.6f, curY, rect.width * 0.2f, 20f);

            Widgets.Label(rectParent, "AG.Parent".Translate());
            TooltipHandler.TipRegion(rectParent, "AG.ParentTooltop".Translate());

            curY += 20f;

            var stats = Constants.affectedStats.Where((StatDef stat) => stat != AnimalGenetics.GatherYield || Genes.Gatherable(pawn));

            foreach (var stat in stats)
            {
                var statRecord = pawn.AnimalGenetics().GeneRecords[stat];
                if (statRecord.Parent != GeneRecord.Source.None)
                {
                    string extra = Genes.GetGenderSymbol(statRecord.Parent);
                    Utility.GUI.DrawGeneValueLabel(new Rect(rect.x + rect.width * 0.6f, curY, rect.width * 0.2f, 20f), (float)statRecord.ParentValue, false, extra);
                }

                curY += 20f;
            }

            return(stats.Count() * 20f);
        }
Пример #3
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);
        }
Пример #4
0
 private static float GetGene(Pawn pawn, StatDef gene)
 {
     if (gene == AnimalGenetics.GatherYield && !Genes.Gatherable(pawn))
     {
         return(0.0f);
     }
     return(Genes.GetGene(pawn, gene));
 }
Пример #5
0
        protected override void FillTab()
        {
            Rect rect = new Rect(0f, 0f, this.size.x, this.size.y).ContractedBy(20f);
            Pawn pawn = base.SelPawn;

            string str = (pawn.gender == Gender.None ? "PawnSummary" : "PawnSummaryWithGender").Translate(pawn.Named("PAWN"));

            Text.Font = GameFont.Small;
            Widgets.Label(new Rect(15f, 15f, rect.width * 0.9f, 30f), "AG.GeneticsOf".Translate() + ":  " + pawn.Label);
            Text.Font = GameFont.Tiny;
            Widgets.Label(new Rect(15f, 35f, rect.width * 0.9f, 30f), str);
            Text.Font = GameFont.Small;

            float headerY = 55f;
            float curY    = headerY;

            Text.Anchor = TextAnchor.MiddleCenter;

            Rect rectValue = new Rect(rect.x + rect.width * 0.4f, curY, rect.width * 0.2f, 20f);

            Widgets.Label(rectValue, "AG.Value".Translate());
            TooltipHandler.TipRegion(rectValue, "AG.ValueTooltop".Translate());

            curY += 20;

            var stats = Constants.affectedStats.Where((StatDef stat) => stat != AnimalGenetics.GatherYield || Genes.Gatherable(pawn));

            foreach (var stat in stats)
            {
                Rect rect2 = new Rect(rect.x, curY, rect.width, 20f);
                TooltipHandler.TipRegion(rect2, Genes.GetTooltip(stat));
                if (Mouse.IsOver(rect2))
                {
                    GUI.color = new Color(0.5f, 0.5f, 0.5f, 1f);
                    GUI.DrawTexture(rect2, TexUI.HighlightTex);
                    GUI.color = Color.white;
                }

                Text.Anchor = TextAnchor.MiddleLeft;

                Widgets.Label(new Rect(20f, curY, (rect.x + rect.width * 0.4f) - 20f, 20f), Constants.GetLabel(stat));

                Utility.GUI.DrawGeneValueLabel(new Rect(rect.x + rect.width * 0.4f, curY, rect.width * 0.2f, 20f), pawn.AnimalGenetics().GeneRecords[stat].Value);

                curY += 20;
            }

            if (Settings.UI.showBothParentsInPawnTab)
            {
                curY += DrawBothParentData(rect, headerY, pawn);
            }
            else
            {
                curY += DrawSingleParentData(rect, headerY, pawn);
            }

            Text.Anchor = TextAnchor.UpperLeft;
        }
Пример #6
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;
            }
        }
Пример #7
0
 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)));
 }
Пример #8
0
        public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
        {
            float gene = Genes.GetGene(pawn, statDef);

            GUI.color   = Utilities.TextColor(gene);
            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(rect, (gene * 100).ToString("F0") + "%");
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }
        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;
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
0
        protected override void FillTab()
        {
            Rect rect = new Rect(0f, 0f, this.size.x, this.size.y).ContractedBy(17f);

            rect.yMin += 10f;
            Pawn   pawn = base.SelPawn;
            string str;

            if (pawn.gender != Gender.None)
            {
                str = "PawnSummaryWithGender".Translate(pawn.Named("PAWN"));
            }
            else
            {
                str = "PawnSummary".Translate(pawn.Named("PAWN"));
            }
            Text.Font = GameFont.Small;
            Widgets.Label(new Rect(15f, 15f, rect.width * 0.9f, 30f), "AG.GeneticsOf".Translate() + ":  " + pawn.Label);
            Text.Font = GameFont.Tiny;
            Widgets.Label(new Rect(15f, 35f, rect.width * 0.9f, 30f), str);

            float curY          = 55f;
            var   affectedStats = Constants.affectedStats;

            Text.Anchor = TextAnchor.MiddleCenter;
            Rect rectValue = new Rect(rect.width * 0.6f, curY, rect.width * 0.2f, 20f);

            Widgets.Label(rectValue, "AG.Value".Translate());
            TooltipHandler.TipRegion(rectValue, "AG.ValueTooltop".Translate());
            Rect rectParent = new Rect(rect.width * 0.8f, curY, rect.width * 0.2f, 20f);

            Widgets.Label(rectParent, "AG.Parent".Translate());
            TooltipHandler.TipRegion(rectParent, "AG.ParentTooltop".Translate());
            curY += 21;
            foreach (var stat in affectedStats)
            {
                if (stat != AnimalGenetics.GatherYield || Genes.Gatherable(pawn))
                {
                    curY += DrawRow(rect, curY, Constants.GetLabel(stat), Genes.GetGene(pawn, stat), Genes.GetInheritString(pawn, stat), Genes.GetInheritValue(pawn, stat), Genes.GetTooltip(stat));
                }
            }
        }
Пример #15
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);
        }
Пример #16
0
 public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true)
 {
     return(Genes.GetGene(req.Thing as Pawn, ((StatDefWrapper)this.stat).Underlying));
 }
Пример #17
0
 public override bool ShouldShowFor(StatRequest req)
 {
     return(Genes.EffectsThing(req.Thing));
 }
Пример #18
0
        private static float DrawBothParentData(Rect rect, float curY, Pawn pawn)
        {
            Text.Anchor = TextAnchor.MiddleCenter;

            Rect rectMother = new Rect(rect.x + rect.width * 0.6f, curY, rect.width * 0.2f, 20f);

            Widgets.Label(rectMother, "AnimalGenetics.Mother".Translate());

            Rect rectFather = new Rect(rect.x + rect.width * 0.8f, curY, rect.width * 0.2f, 20f);

            Widgets.Label(rectFather, "AnimalGenetics.Father".Translate());

            curY += 20;

            var data = pawn.AnimalGenetics();

            var statsGroup = data.GeneRecords;

            var stats = Constants.affectedStats.Where((StatDef stat) => stat != AnimalGenetics.GatherYield || Genes.Gatherable(pawn));

            foreach (var stat in stats)
            {
                var statRecord = statsGroup[stat];

                if (statRecord.MotherValue != null)
                {
                    Utility.GUI.DrawGeneValueLabel(new Rect(rect.x + rect.width * 0.6f, curY, rect.width * 0.2f, 20f), (float)statRecord.MotherValue, statRecord.Parent != GeneRecord.Source.Mother);
                }

                if (statRecord.FatherValue != null)
                {
                    Utility.GUI.DrawGeneValueLabel(new Rect(rect.x + rect.width * 0.8f, curY, rect.width * 0.2f, 20f), (float)statRecord.FatherValue, statRecord.Parent != GeneRecord.Source.Father);
                }

                curY += 20f;
            }

            return(stats.Count() * 20f);
        }
Пример #19
0
 public override int Compare(Pawn a, Pawn b)
 {
     return(Genes.GetGene(a, statDef).CompareTo(Genes.GetGene(b, statDef)));
 }