public static IEnumerable <PawnGenOption> ChoosePawnGenOptionsByPoints(float pointsTotal, List <PawnGenOption> options, PawnGroupMakerParms groupParms)
        {
            if (groupParms.seed != null)
            {
                Rand.PushState(groupParms.seed.Value);
            }
            float num = PawnGroupMakerUtility.MaxPawnCost(groupParms.faction, pointsTotal, groupParms.raidStrategy, groupParms.groupKind);
            List <PawnGenOption> list  = new List <PawnGenOption>();
            List <PawnGenOption> list2 = new List <PawnGenOption>();
            float num2        = pointsTotal;
            bool  flag        = false;
            float highestCost = -1f;

            for (;;)
            {
                list.Clear();
                for (int i = 0; i < options.Count; i++)
                {
                    PawnGenOption pawnGenOption = options[i];
                    if (pawnGenOption.Cost <= num2)
                    {
                        if (pawnGenOption.Cost <= num)
                        {
                            if (!groupParms.generateFightersOnly || pawnGenOption.kind.isFighter)
                            {
                                if (groupParms.raidStrategy == null || groupParms.raidStrategy.Worker.CanUsePawnGenOption(pawnGenOption, list2))
                                {
                                    if (!groupParms.dontUseSingleUseRocketLaunchers || pawnGenOption.kind.weaponTags == null || !pawnGenOption.kind.weaponTags.Contains("GunHeavy"))
                                    {
                                        if (!flag || !pawnGenOption.kind.factionLeader)
                                        {
                                            if (pawnGenOption.Cost > highestCost)
                                            {
                                                highestCost = pawnGenOption.Cost;
                                            }
                                            list.Add(pawnGenOption);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (list.Count == 0)
                {
                    break;
                }
                Func <PawnGenOption, float> weightSelector = delegate(PawnGenOption gr)
                {
                    float selectionWeight = gr.selectionWeight;
                    return(selectionWeight * PawnGroupMakerUtility.PawnWeightFactorByMostExpensivePawnCostFractionCurve.Evaluate(gr.Cost / highestCost));
                };
                PawnGenOption pawnGenOption2 = list.RandomElementByWeight(weightSelector);
                list2.Add(pawnGenOption2);
                num2 -= pawnGenOption2.Cost;
                if (pawnGenOption2.kind.factionLeader)
                {
                    flag = true;
                }
            }
            if (list2.Count == 1 && num2 > pointsTotal / 2f)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Used only ",
                    pointsTotal - num2,
                    " / ",
                    pointsTotal,
                    " points generating for ",
                    groupParms.faction
                }), false);
            }
            if (groupParms.seed != null)
            {
                Rand.PopState();
            }
            return(list2);
        }
        private static void <PawnGroupsMade> m__3(Faction fac)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Concat(new object[]
            {
                "FACTION: ",
                fac.Name,
                " (",
                fac.def.defName,
                ") min=",
                fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)
            }));
            Action <float> action = delegate(float points)
            {
                if (points < fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat))
                {
                    return;
                }
                PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();
                pawnGroupMakerParms.groupKind = PawnGroupKindDefOf.Combat;
                pawnGroupMakerParms.tile      = Find.CurrentMap.Tile;
                pawnGroupMakerParms.points    = points;
                pawnGroupMakerParms.faction   = fac;
                sb.AppendLine(string.Concat(new object[]
                {
                    "Group with ",
                    pawnGroupMakerParms.points,
                    " points (max option cost: ",
                    PawnGroupMakerUtility.MaxPawnCost(fac, points, RaidStrategyDefOf.ImmediateAttack, PawnGroupKindDefOf.Combat),
                    ")"
                }));
                float num2 = 0f;
                foreach (Pawn pawn in from pa in PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms, false)
                         orderby pa.kindDef.combatPower
                         select pa)
                {
                    string text;
                    if (pawn.equipment.Primary != null)
                    {
                        text = pawn.equipment.Primary.Label;
                    }
                    else
                    {
                        text = "no-equipment";
                    }
                    Apparel apparel = pawn.apparel.FirstApparelOnBodyPartGroup(BodyPartGroupDefOf.Torso);
                    string  text2;
                    if (apparel != null)
                    {
                        text2 = apparel.LabelCap;
                    }
                    else
                    {
                        text2 = "shirtless";
                    }
                    sb.AppendLine(string.Concat(new string[]
                    {
                        "  ",
                        pawn.kindDef.combatPower.ToString("F0").PadRight(6),
                        pawn.kindDef.defName,
                        ", ",
                        text,
                        ", ",
                        text2
                    }));
                    num2 += pawn.kindDef.combatPower;
                }
                sb.AppendLine("         totalCost " + num2);
                sb.AppendLine();
            };

            foreach (float num in Dialog_DebugActionsMenu.PointsOptions(false))
            {
                float obj = num;
                action(obj);
            }
            Log.Message(sb.ToString(), false);
        }
示例#3
0
 public static void PawnGroupsMade()
 {
     Dialog_DebugOptionListLister.ShowSimpleDebugMenu <Faction>(from fac in Find.FactionManager.AllFactions
                                                                where !fac.def.pawnGroupMakers.NullOrEmpty <PawnGroupMaker>()
                                                                select fac, (Faction fac) => fac.Name + " (" + fac.def.defName + ")", delegate(Faction fac)
     {
         StringBuilder sb = new StringBuilder();
         sb.AppendLine(string.Concat(new object[]
         {
             "FACTION: ",
             fac.Name,
             " (",
             fac.def.defName,
             ") min=",
             fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat)
         }));
         Action <float> action = delegate(float points)
         {
             if (points < fac.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat))
             {
                 return;
             }
             PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();
             pawnGroupMakerParms.groupKind           = PawnGroupKindDefOf.Combat;
             pawnGroupMakerParms.tile    = Find.CurrentMap.Tile;
             pawnGroupMakerParms.points  = points;
             pawnGroupMakerParms.faction = fac;
             sb.AppendLine(string.Concat(new object[]
             {
                 "Group with ",
                 pawnGroupMakerParms.points,
                 " points (max option cost: ",
                 PawnGroupMakerUtility.MaxPawnCost(fac, points, RaidStrategyDefOf.ImmediateAttack, PawnGroupKindDefOf.Combat),
                 ")"
             }));
             float num = 0f;
             foreach (Pawn current in PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms, false).OrderBy((Pawn pa) => pa.kindDef.combatPower))
             {
                 string text;
                 if (current.equipment.Primary != null)
                 {
                     text = current.equipment.Primary.Label;
                 }
                 else
                 {
                     text = "no-equipment";
                 }
                 Apparel apparel = current.apparel.FirstApparelOnBodyPartGroup(BodyPartGroupDefOf.Torso);
                 string text2;
                 if (apparel != null)
                 {
                     text2 = apparel.LabelCap;
                 }
                 else
                 {
                     text2 = "shirtless";
                 }
                 sb.AppendLine(string.Concat(new string[]
                 {
                     "  ",
                     current.kindDef.combatPower.ToString("F0").PadRight(6),
                     current.kindDef.defName,
                     ", ",
                     text,
                     ", ",
                     text2
                 }));
                 num += current.kindDef.combatPower;
             }
             sb.AppendLine("         totalCost " + num);
             sb.AppendLine();
         };
         foreach (float obj in Dialog_DebugActionsMenu.PointsOptions(false))
         {
             action(obj);
         }
         Log.Message(sb.ToString(), false);
     });
 }