Example #1
0
 public static Pawn GeneratePawn(PawnKindDef kindDef, Faction faction = null)
 {
     return(GeneratePawn(new PawnGenerationRequest(kindDef, faction)));
 }
Example #2
0
        public static void RecruitDifficultiesSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.Humanlike
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef current in orderedEnumerable)
            {
                PawnKindDef kind = current;
                Faction     fac  = FactionUtility.DefaultFactionFrom(kind.defaultFactionType);
                if (kind == PawnKindDefOf.WildMan)
                {
                    fac = null;
                }
                FloatMenuOption item = new FloatMenuOption(kind.defName + " (" + kind.baseRecruitDifficulty.ToStringPercent() + ")", delegate
                {
                    Dictionary <int, int> dictionary = new Dictionary <int, int>();
                    for (int i = 0; i < 21; i++)
                    {
                        dictionary.Add(i, 0);
                    }
                    for (int j = 0; j < 300; j++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        float num = pawn.RecruitDifficulty(Faction.OfPlayer);
                        int num2  = Mathf.RoundToInt(num * 20f);
                        Dictionary <int, int> dictionary2;
                        int key;
                        (dictionary2 = dictionary)[key = num2] = dictionary2[key] + 1;
                        pawn.Destroy(DestroyMode.Vanish);
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Concat(new object[]
                    {
                        "Sampled ",
                        300,
                        "x ",
                        kind.defName,
                        ":"
                    }));
                    for (int k = 0; k < 21; k++)
                    {
                        int num3 = dictionary[k];
                        stringBuilder.AppendLine(string.Concat(new object[]
                        {
                            "  ",
                            (k * 5).ToString(),
                            "    ",
                            num3,
                            " (",
                            ((float)num3 / 300f).ToStringPercent(),
                            ")"
                        }));
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines(), false);
                }, MenuOptionPriority.Default, null, null, 0f, null, null);
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Example #3
0
 public static void PerformBattleRoyale(IEnumerable <PawnKindDef> kindsEnumerable)
 {
     if (ArenaUtility.ValidateArenaCapability())
     {
         List <PawnKindDef> kinds = kindsEnumerable.ToList <PawnKindDef>();
         Dictionary <PawnKindDef, float> ratings = new Dictionary <PawnKindDef, float>();
         foreach (PawnKindDef pawnKindDef in kinds)
         {
             ratings[pawnKindDef] = EloUtility.CalculateRating(pawnKindDef.combatPower, 1500f, 60f);
         }
         int currentFights  = 0;
         int completeFights = 0;
         Current.Game.GetComponent <GameComponent_DebugTools>().AddPerFrameCallback(delegate
         {
             bool result2;
             if (currentFights >= 15)
             {
                 result2 = false;
             }
             else
             {
                 PawnKindDef lhsDef = kinds.RandomElement <PawnKindDef>();
                 PawnKindDef rhsDef = kinds.RandomElement <PawnKindDef>();
                 float num          = EloUtility.CalculateExpectation(ratings[lhsDef], ratings[rhsDef]);
                 float num2         = 1f - num;
                 float num3         = num;
                 float num4         = Mathf.Min(num2, num3);
                 num2      /= num4;
                 num3      /= num4;
                 float num5 = Mathf.Max(num2, num3);
                 if (num5 > 40f)
                 {
                     result2 = false;
                 }
                 else
                 {
                     float num6             = 40f / num5;
                     float num7             = (float)Math.Exp((double)Rand.Range(0f, (float)Math.Log((double)num6)));
                     num2                  *= num7;
                     num3                  *= num7;
                     List <PawnKindDef> lhs = Enumerable.Repeat <PawnKindDef>(lhsDef, GenMath.RoundRandom(num2)).ToList <PawnKindDef>();
                     List <PawnKindDef> rhs = Enumerable.Repeat <PawnKindDef>(rhsDef, GenMath.RoundRandom(num3)).ToList <PawnKindDef>();
                     currentFights++;
                     ArenaUtility.BeginArenaFight(lhs, rhs, delegate(ArenaUtility.ArenaResult result)
                     {
                         currentFights--;
                         completeFights++;
                         if (result.winner != ArenaUtility.ArenaResult.Winner.Other)
                         {
                             float value   = ratings[lhsDef];
                             float value2  = ratings[rhsDef];
                             float kfactor = 8f * Mathf.Pow(0.5f, Time.realtimeSinceStartup / 900f);
                             EloUtility.Update(ref value, ref value2, 0.5f, (float)((result.winner != ArenaUtility.ArenaResult.Winner.Lhs) ? 0 : 1), kfactor);
                             ratings[lhsDef] = value;
                             ratings[rhsDef] = value2;
                             Log.Message(string.Format("Scores after {0} trials:\n\n{1}", completeFights, (from v in ratings
                                                                                                           orderby v.Value
                                                                                                           select string.Format("  {0}: {1}->{2} (rating {2})", new object[]
                             {
                                 v.Key.label,
                                 v.Key.combatPower,
                                 EloUtility.CalculateLinearScore(v.Value, 1500f, 60f).ToString("F0"),
                                 v.Value.ToString("F0")
                             })).ToLineList("")), false);
                         }
                     });
                     result2 = false;
                 }
             }
             return(result2);
         });
     }
 }
Example #4
0
        public static void PawnKindGearSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.ToolUser
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef current in orderedEnumerable)
            {
                Faction         fac  = FactionUtility.DefaultFactionFrom(current.defaultFactionType);
                PawnKindDef     kind = current;
                FloatMenuOption item = new FloatMenuOption(string.Concat(new object[]
                {
                    kind.defName,
                    " (",
                    kind.combatPower,
                    ")"
                }), delegate
                {
                    DefMap <ThingDef, int> weapons  = new DefMap <ThingDef, int>();
                    DefMap <ThingDef, int> apparel  = new DefMap <ThingDef, int>();
                    DefMap <HediffDef, int> hediffs = new DefMap <HediffDef, int>();
                    for (int i = 0; i < 400; i++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        if (pawn.equipment.Primary != null)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def;
                            (defMap = weapons)[def = pawn.equipment.Primary.def] = defMap[def] + 1;
                        }
                        foreach (Hediff current2 in pawn.health.hediffSet.hediffs)
                        {
                            DefMap <HediffDef, int> hediffs2;
                            HediffDef def2;
                            (hediffs2 = hediffs)[def2 = current2.def] = hediffs2[def2] + 1;
                        }
                        foreach (Apparel current3 in pawn.apparel.WornApparel)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def3;
                            (defMap = apparel)[def3 = current3.def] = defMap[def3] + 1;
                        }
                        pawn.Destroy(DestroyMode.Vanish);
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Concat(new object[]
                    {
                        "Sampled ",
                        400,
                        "x ",
                        kind.defName,
                        ":"
                    }));
                    stringBuilder.AppendLine("Weapons");
                    foreach (ThingDef current4 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby weapons[t] descending
                             select t)
                    {
                        int num = weapons[current4];
                        if (num > 0)
                        {
                            stringBuilder.AppendLine("  " + current4.defName + "    " + ((float)num / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Apparel");
                    foreach (ThingDef current5 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby apparel[t] descending
                             select t)
                    {
                        int num2 = apparel[current5];
                        if (num2 > 0)
                        {
                            stringBuilder.AppendLine("  " + current5.defName + "    " + ((float)num2 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Tech hediffs");
                    foreach (HediffDef current6 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved != null
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num3 = hediffs[current6];
                        if (num3 > 0)
                        {
                            stringBuilder.AppendLine("  " + current6.defName + "    " + ((float)num3 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Addiction hediffs");
                    foreach (HediffDef current7 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num4 = hediffs[current7];
                        if (num4 > 0)
                        {
                            stringBuilder.AppendLine("  " + current7.defName + "    " + ((float)num4 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Other hediffs");
                    foreach (HediffDef current8 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved == null && !h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num5 = hediffs[current8];
                        if (num5 > 0)
                        {
                            stringBuilder.AppendLine("  " + current8.defName + "    " + ((float)num5 / 400f).ToStringPercent());
                        }
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines(), false);
                }, MenuOptionPriority.Default, null, null, 0f, null, null);
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Example #5
0
        public static void PawnWorkDisablesSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.Humanlike
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef current in orderedEnumerable)
            {
                PawnKindDef     kind = current;
                Faction         fac  = FactionUtility.DefaultFactionFrom(kind.defaultFactionType);
                FloatMenuOption item = new FloatMenuOption(string.Concat(new object[]
                {
                    kind.defName,
                    " (",
                    kind.combatPower,
                    ")"
                }), delegate
                {
                    Dictionary <WorkTags, int> dictionary = new Dictionary <WorkTags, int>();
                    for (int i = 0; i < 1000; i++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        WorkTags combinedDisabledWorkTags = pawn.story.CombinedDisabledWorkTags;
                        foreach (WorkTags workTags in Enum.GetValues(typeof(WorkTags)))
                        {
                            if (!dictionary.ContainsKey(workTags))
                            {
                                dictionary.Add(workTags, 0);
                            }
                            if ((combinedDisabledWorkTags & workTags) != WorkTags.None)
                            {
                                Dictionary <WorkTags, int> dictionary2;
                                WorkTags key;
                                (dictionary2 = dictionary)[key = workTags] = dictionary2[key] + 1;
                            }
                        }
                        pawn.Destroy(DestroyMode.Vanish);
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Concat(new object[]
                    {
                        "Sampled ",
                        1000,
                        "x ",
                        kind.defName,
                        ":"
                    }));
                    stringBuilder.AppendLine("Worktags disabled");
                    foreach (WorkTags key2 in Enum.GetValues(typeof(WorkTags)))
                    {
                        int num = dictionary[key2];
                        stringBuilder.AppendLine(string.Concat(new object[]
                        {
                            "  ",
                            key2.ToString(),
                            "    ",
                            num,
                            " (",
                            ((float)num / 1000f).ToStringPercent(),
                            ")"
                        }));
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines(), false);
                }, MenuOptionPriority.Default, null, null, 0f, null, null);
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Example #6
0
 internal float <> m__1(PawnKindDef ki)
 {
     return(this.b.CommonalityOfAnimal(ki));
 }
Example #7
0
 internal float <> m__2(PawnKindDef ki)
 {
     return(this.k.ecoSystemWeight * (this.b.CommonalityOfAnimal(ki) / this.totalCommonality));
 }
Example #8
0
 private static string <AnimalWildCountsOnMap> m__20(PawnKindDef k)
 {
     return(k.defName);
 }
Example #9
0
 private static string <BiomeAnimalsInternal> m__19(PawnKindDef d)
 {
     return(d.defName);
 }
Example #10
0
 private static bool <BiomeAnimalsInternal> m__18(PawnKindDef d)
 {
     return(d.race != null && d.RaceProps.Animal);
 }
Example #11
0
 private static string <BiomeAnimalsInternal> m__17(PawnKindDef k)
 {
     return(k.defName + string.Empty + ((!k.race.race.predator) ? string.Empty : " (P)"));
 }
Example #12
0
 private static string <BiomeAnimalsTypicalCounts> m__14(PawnKindDef k, BiomeDef b)
 {
     return(DebugOutputsEcology.ExpectedAnimalCount(k, b).ToStringEmptyZero("F2"));
 }