Exemplo n.º 1
0
        public static void PawnGroupGenSampled()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (Faction current in Find.FactionManager.AllFactions)
            {
                if (current.def.pawnGroupMakers != null)
                {
                    if (current.def.pawnGroupMakers.Any((PawnGroupMaker x) => x.kindDef == PawnGroupKindDefOf.Combat))
                    {
                        Faction localFac = current;
                        list.Add(new DebugMenuOption(localFac.Name + " (" + localFac.def.defName + ")", DebugMenuOptionMode.Action, delegate
                        {
                            List <DebugMenuOption> list2 = new List <DebugMenuOption>();
                            foreach (float localP2 in Dialog_DebugActionsMenu.PointsOptions(true))
                            {
                                float localP      = localP2;
                                float maxPawnCost = PawnGroupMakerUtility.MaxPawnCost(localFac, localP, null, PawnGroupKindDefOf.Combat);
                                string defName    = (from op in localFac.def.pawnGroupMakers.SelectMany((PawnGroupMaker gm) => gm.options)
                                                     where op.Cost <= maxPawnCost
                                                     select op).MaxBy((PawnGenOption op) => op.Cost).kind.defName;
                                string label = string.Concat(new string[]
                                {
                                    localP.ToString(),
                                    ", max ",
                                    maxPawnCost.ToString("F0"),
                                    " ",
                                    defName
                                });
                                list2.Add(new DebugMenuOption(label, DebugMenuOptionMode.Action, delegate
                                {
                                    Dictionary <ThingDef, int>[] weaponsCount = new Dictionary <ThingDef, int> [20];
                                    string[] pawnKinds = new string[20];
                                    for (int i = 0; i < 20; i++)
                                    {
                                        weaponsCount[i]   = new Dictionary <ThingDef, int>();
                                        List <Pawn> list3 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
                                        {
                                            groupKind = PawnGroupKindDefOf.Combat,
                                            tile      = Find.CurrentMap.Tile,
                                            points    = localP,
                                            faction   = localFac
                                        }, false).ToList <Pawn>();
                                        pawnKinds[i] = PawnUtility.PawnKindsToCommaList(list3, true);
                                        foreach (Pawn current2 in list3)
                                        {
                                            if (current2.equipment.Primary != null)
                                            {
                                                if (!weaponsCount[i].ContainsKey(current2.equipment.Primary.def))
                                                {
                                                    weaponsCount[i].Add(current2.equipment.Primary.def, 0);
                                                }
                                                Dictionary <ThingDef, int> dictionary;
                                                ThingDef def;
                                                (dictionary = weaponsCount[i])[def = current2.equipment.Primary.def] = dictionary[def] + 1;
                                            }
                                            current2.Destroy(DestroyMode.Vanish);
                                        }
                                    }
                                    int totalPawns = weaponsCount.Sum((Dictionary <ThingDef, int> x) => x.Sum((KeyValuePair <ThingDef, int> y) => y.Value));
                                    List <TableDataGetter <int> > list4 = new List <TableDataGetter <int> >();
                                    list4.Add(new TableDataGetter <int>(string.Empty, (int x) => (x != 20) ? (x + 1).ToString() : "avg"));
                                    list4.Add(new TableDataGetter <int>("pawns", delegate(int x)
                                    {
                                        string arg_64_0 = " ";
                                        string arg_64_1;
                                        if (x == 20)
                                        {
                                            arg_64_1 = ((float)totalPawns / 20f).ToString("0.#");
                                        }
                                        else
                                        {
                                            arg_64_1 = weaponsCount[x].Sum((KeyValuePair <ThingDef, int> y) => y.Value).ToString();
                                        }
                                        return(arg_64_0 + arg_64_1);
                                    }));
                                    list4.Add(new TableDataGetter <int>("kinds", (int x) => (x != 20) ? pawnKinds[x] : string.Empty));
                                    list4.AddRange(from x in DefDatabase <ThingDef> .AllDefs
                                                   where x.IsWeapon && !x.weaponTags.NullOrEmpty <string>() && weaponsCount.Any((Dictionary <ThingDef, int> wc) => wc.ContainsKey(x))
                                                   orderby x.IsMeleeWeapon descending, x.techLevel, x.BaseMarketValue
                                                   select new TableDataGetter <int>(x.label.Shorten(), delegate(int y)
                                    {
                                        if (y == 20)
                                        {
                                            return(" " + ((float)weaponsCount.Sum((Dictionary <ThingDef, int> z) => (!z.ContainsKey(x)) ? 0 : z[x]) / 20f).ToString("0.#"));
                                        }
                                        string arg_104_0;
                                        if (weaponsCount[y].ContainsKey(x))
                                        {
                                            object[] expr_66 = new object[5];
                                            expr_66[0]       = " ";
                                            expr_66[1]       = weaponsCount[y][x];
                                            expr_66[2]       = " (";
                                            expr_66[3]       = ((float)weaponsCount[y][x] / (float)weaponsCount[y].Sum((KeyValuePair <ThingDef, int> z) => z.Value)).ToStringPercent("F0");
                                            expr_66[4]       = ")";
                                            arg_104_0        = string.Concat(expr_66);
                                        }
                                        else
                                        {
                                            arg_104_0 = string.Empty;
                                        }
                                        return(arg_104_0);
                                    }));
                                    DebugTables.MakeTablesDialog <int>(Enumerable.Range(0, 21), list4.ToArray());
                                }));
                            }
                            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2));
                        }));
                    }
                }
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Exemplo n.º 2
0
        public static void PawnGroupGenSampled()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (Faction allFaction in Find.FactionManager.AllFactions)
            {
                if (allFaction.def.pawnGroupMakers != null && allFaction.def.pawnGroupMakers.Any((PawnGroupMaker x) => x.kindDef == PawnGroupKindDefOf.Combat))
                {
                    Faction localFac = allFaction;
                    float   localP;
                    float   maxPawnCost;
                    list.Add(new DebugMenuOption(localFac.Name + " (" + localFac.def.defName + ")", DebugMenuOptionMode.Action, delegate
                    {
                        List <DebugMenuOption> list2 = new List <DebugMenuOption>();
                        foreach (float item in Dialog_DebugActionsMenu.PointsOptions(extended: true))
                        {
                            float num      = item;
                            localP         = num;
                            maxPawnCost    = PawnGroupMakerUtility.MaxPawnCost(localFac, localP, null, PawnGroupKindDefOf.Combat);
                            string defName = (from op in localFac.def.pawnGroupMakers.SelectMany((PawnGroupMaker gm) => gm.options)
                                              where op.Cost <= maxPawnCost
                                              select op).MaxBy((PawnGenOption op) => op.Cost).kind.defName;
                            string label = localP.ToString() + ", max " + maxPawnCost.ToString("F0") + " " + defName;
                            list2.Add(new DebugMenuOption(label, DebugMenuOptionMode.Action, delegate
                            {
                                Dictionary <ThingDef, int>[] weaponsCount = new Dictionary <ThingDef, int> [20];
                                string[] pawnKinds = new string[20];
                                for (int i = 0; i < 20; i++)
                                {
                                    weaponsCount[i]   = new Dictionary <ThingDef, int>();
                                    List <Pawn> list3 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
                                    {
                                        groupKind = PawnGroupKindDefOf.Combat,
                                        tile      = Find.CurrentMap.Tile,
                                        points    = localP,
                                        faction   = localFac
                                    }, warnOnZeroResults: false).ToList();
                                    pawnKinds[i] = PawnUtility.PawnKindsToCommaList(list3, useAnd: true);
                                    foreach (Pawn item2 in list3)
                                    {
                                        if (item2.equipment.Primary != null)
                                        {
                                            if (!weaponsCount[i].ContainsKey(item2.equipment.Primary.def))
                                            {
                                                weaponsCount[i].Add(item2.equipment.Primary.def, 0);
                                            }
                                            Dictionary <ThingDef, int> dictionary;
                                            ThingDef def;
                                            (dictionary = weaponsCount[i])[def = item2.equipment.Primary.def] = dictionary[def] + 1;
                                        }
                                        item2.Destroy();
                                    }
                                }
                                int totalPawns = weaponsCount.Sum((Dictionary <ThingDef, int> x) => x.Sum((KeyValuePair <ThingDef, int> y) => y.Value));
                                List <TableDataGetter <int> > list4 = new List <TableDataGetter <int> >();
                                list4.Add(new TableDataGetter <int>(string.Empty, (int x) => (x != 20) ? (x + 1).ToString() : "avg"));
                                list4.Add(new TableDataGetter <int>("pawns", (int x) => " " + ((x != 20) ? weaponsCount[x].Sum((KeyValuePair <ThingDef, int> y) => y.Value).ToString() : ((float)totalPawns / 20f).ToString("0.#"))));
                                list4.Add(new TableDataGetter <int>("kinds", (int x) => (x != 20) ? pawnKinds[x] : string.Empty));
                                list4.AddRange(from x in DefDatabase <ThingDef> .AllDefs
                                               where x.IsWeapon && !x.weaponTags.NullOrEmpty() && weaponsCount.Any((Dictionary <ThingDef, int> wc) => wc.ContainsKey(x))
                                               orderby x.IsMeleeWeapon descending, x.techLevel, x.BaseMarketValue
                                               select new TableDataGetter <int>(x.label.Shorten(), delegate(int y)
                                {
                                    if (y == 20)
                                    {
                                        return(" " + ((float)weaponsCount.Sum((Dictionary <ThingDef, int> z) => z.ContainsKey(x) ? z[x] : 0) / 20f).ToString("0.#"));
                                    }
                                    return((!weaponsCount[y].ContainsKey(x)) ? string.Empty : (" " + weaponsCount[y][x] + " (" + ((float)weaponsCount[y][x] / (float)weaponsCount[y].Sum((KeyValuePair <ThingDef, int> z) => z.Value)).ToStringPercent("F0") + ")"));
                                }));
                                DebugTables.MakeTablesDialog(Enumerable.Range(0, 21), list4.ToArray());
                            }));
                        }
                        Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2));
                    }));
                }
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }