예제 #1
0
        private static void SpawnPawnQuality()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef item in DefDatabase <PawnKindDef> .AllDefs.Where(x => x.GetModExtension <DefExtension_Hybrid>() != null || x.race.tradeTags?.Contains("AnimalGeneticMechanoid") == true).OrderBy((PawnKindDef kd) => kd.defName))
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Tool, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    Pawn newPawn    = PawnGenerator.GeneratePawn(localKindDef, faction);
                    GenSpawn.Spawn(newPawn, UI.MouseCell(), Find.CurrentMap);
                    CompHybrid compHybrid = newPawn.TryGetComp <CompHybrid>();
                    if (compHybrid != null)
                    {
                        compHybrid.quality = QualityUtility.GenerateQualityRandomEqualChance();
                    }
                    if (faction != null && faction != Faction.OfPlayer)
                    {
                        Lord lord = null;
                        if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                        {
                            lord = ((Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null)).GetLord();
                        }
                        if (lord == null)
                        {
                            LordJob_DefendPoint lordJob = new LordJob_DefendPoint(newPawn.Position);
                            lord = LordMaker.MakeNewLord(faction, lordJob, Find.CurrentMap);
                        }
                        lord.AddPawn(newPawn);
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
예제 #2
0
        private static void TestForceKillx100()
        {
            int  num = 0;
            Pawn pawn;

            while (true)
            {
                if (num < 100)
                {
                    PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                    pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                    GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                    HealthUtility.DamageUntilDead(pawn);
                    if (!pawn.Dead)
                    {
                        break;
                    }
                    num++;
                    continue;
                }
                return;
            }
            Log.Error("Pawn died not die: " + pawn + " at " + pawn.Position);
        }
예제 #3
0
        public override void CompTick()
        {
            base.CompTick();
            Pawn pawn = this.parent as Pawn;

            if ((pawn.Map != null) && (pawn.needs.food.CurLevelPercentage < pawn.needs.food.PercentageThreshHungry) && (pawn.Awake() && AlphaAnimalsEvents_Settings.flagFrostmites))
            {
                if (stopdiggingcounter <= 0)
                {
                    PawnKindDef wildman = PawnKindDef.Named("WildMan");
                    Faction     faction = FactionUtility.DefaultFactionFrom(wildman.defaultFactionType);
                    Pawn        newPawn = PawnGenerator.GeneratePawn(wildman, faction);

                    Thing newcorpse = GenSpawn.Spawn(newPawn, pawn.Position, pawn.Map, WipeMode.Vanish);
                    newcorpse.Kill(null, null);
                    newcorpse.SetForbidden(true, false);
                    if (this.effecter == null)
                    {
                        this.effecter = EffecterDefOf.Mine.Spawn();
                    }
                    this.effecter.Trigger(pawn, newcorpse);


                    stopdiggingcounter = 40000;
                }
                stopdiggingcounter--;
            }
        }
예제 #4
0
        public static Pawn GetTestPawn(int shootSkill = 10)
        {
            PawnKindDef kindDef = DefDatabase <PawnKindDef> .GetNamed("StrangerInBlack");

            Faction faction = FactionUtility.DefaultFactionFrom(kindDef.defaultFactionType);

            TraitDef shootingAccuracy = DefDatabase <TraitDef> .GetNamed("ShootingAccuracy");

            Pawn pawn = PawnGenerator.GeneratePawn(kindDef, faction);

            while (pawn.story.traits.HasTrait(shootingAccuracy))
            {
                pawn = PawnGenerator.GeneratePawn(kindDef, faction);
            }

            pawn.health.Reset();

            var shooting = (from skill in pawn.skills.skills
                            where skill.def.defName.Equals("Shooting")
                            select skill).First();

            shooting.Level = 0;
            shooting.EnsureMinLevelWithMargin(shootSkill);

            return(pawn);
        }
예제 #5
0
        private static void SpawnPawn()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef item in DefDatabase <PawnKindDef> .AllDefs.OrderBy((PawnKindDef kd) => kd.defName))
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Tool, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    Pawn newPawn    = PawnGenerator.GeneratePawn(localKindDef, faction);
                    GenSpawn.Spawn(newPawn, UI.MouseCell(), Find.CurrentMap);
                    if (faction != null && faction != Faction.OfPlayer)
                    {
                        Lord lord = null;
                        if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                        {
                            lord = ((Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null)).GetLord();
                        }
                        if (lord == null)
                        {
                            LordJob_DefendPoint lordJob = new LordJob_DefendPoint(newPawn.Position);
                            lord = LordMaker.MakeNewLord(faction, lordJob, Find.CurrentMap);
                        }
                        lord.AddPawn(newPawn);
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
예제 #6
0
 private static void AddGuest(bool prisoner)
 {
     foreach (Building_Bed item in Find.CurrentMap.listerBuildings.AllBuildingsColonistOfClass <Building_Bed>())
     {
         if (item.ForPrisoners != prisoner || (item.OwnersForReading.Any() && (!prisoner || !item.AnyUnownedSleepingSlot)))
         {
             continue;
         }
         PawnKindDef pawnKindDef = (prisoner ? DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef pk) => pk.defaultFactionType != null && !pk.defaultFactionType.isPlayer && pk.RaceProps.Humanlike).RandomElement() : PawnKindDefOf.SpaceRefugee);
         Faction     faction     = FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType);
         Pawn        pawn        = PawnGenerator.GeneratePawn(pawnKindDef, faction);
         GenSpawn.Spawn(pawn, item.Position, Find.CurrentMap);
         foreach (ThingWithComps item2 in pawn.equipment.AllEquipmentListForReading.ToList())
         {
             if (pawn.equipment.TryDropEquipment(item2, out var resultingEq, pawn.Position))
             {
                 resultingEq.Destroy();
             }
         }
         pawn.inventory.innerContainer.Clear();
         pawn.ownership.ClaimBedIfNonMedical(item);
         pawn.guest.SetGuestStatus(Faction.OfPlayer, prisoner);
         break;
     }
 }
예제 #7
0
        public static Pawn GenerateRandom()
        {
            PawnKindDef pawnKindDef = DefDatabase <PawnKindDef> .AllDefsListForReading.RandomElementByWeight((PawnKindDef pawnkind) => (float)((!pawnkind.RaceProps.Humanlike) ? 1 : 5));

            Faction faction = FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType);

            return(PawnGenerator.GeneratePawn(pawnKindDef, faction));
        }
 public void EnsureNonNullFaction()
 {
     if (this.KindDef.RaceProps.Humanlike && this.Faction == null)
     {
         this.Faction = FactionUtility.DefaultFactionFrom(this.KindDef.defaultFactionType);
         Log.Error("Tried to generate pawn of Humanlike race " + this.KindDef + " with null faction. Setting to " + this.Faction);
     }
 }
        public static void DamageTest()
        {
            ThingDef    thingDef = ThingDef.Named("Bullet_BoltActionRifle");
            PawnKindDef slave    = PawnKindDefOf.Slave;
            Faction     faction  = FactionUtility.DefaultFactionFrom(slave.defaultFactionType);
            DamageInfo  dinfo    = new DamageInfo(thingDef.projectile.damageDef, thingDef.projectile.GetDamageAmount(null), thingDef.projectile.GetArmorPenetration(null));

            dinfo.SetIgnoreInstantKillProtection(ignore: true);
            int num  = 0;
            int num2 = 0;
            DefMap <BodyPartDef, int> defMap = new DefMap <BodyPartDef, int>();

            for (int i = 0; i < 500; i++)
            {
                Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(slave, faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true));
                List <BodyPartDef> list = (from hd in pawn.health.hediffSet.GetMissingPartsCommonAncestors()
                                           select hd.Part.def).ToList();
                for (int j = 0; j < 2; j++)
                {
                    pawn.TakeDamage(dinfo);
                    if (pawn.Dead)
                    {
                        num++;
                        break;
                    }
                }
                List <BodyPartDef> list2 = (from hd in pawn.health.hediffSet.GetMissingPartsCommonAncestors()
                                            select hd.Part.def).ToList();
                if (list2.Count > list.Count)
                {
                    num2++;
                    foreach (BodyPartDef item in list2)
                    {
                        defMap[item]++;
                    }
                    foreach (BodyPartDef item2 in list)
                    {
                        defMap[item2]--;
                    }
                }
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Damage test");
            stringBuilder.AppendLine("Hit " + 500 + " " + slave.label + "s with " + 2 + "x " + thingDef.label + " (" + thingDef.projectile.GetDamageAmount(null) + " damage) each. Results:");
            stringBuilder.AppendLine("Killed: " + num + " / " + 500 + " (" + ((float)num / 500f).ToStringPercent() + ")");
            stringBuilder.AppendLine("Part losers: " + num2 + " / " + 500 + " (" + ((float)num2 / 500f).ToStringPercent() + ")");
            stringBuilder.AppendLine("Parts lost:");
            foreach (BodyPartDef allDef in DefDatabase <BodyPartDef> .AllDefs)
            {
                if (defMap[allDef] > 0)
                {
                    stringBuilder.AppendLine("   " + allDef.label + ": " + defMap[allDef]);
                }
            }
            Log.Message(stringBuilder.ToString());
        }
예제 #10
0
        private static Pawn CreateXenoPawn(string pawnKindDefName)
        {
            var faction = FactionUtility.DefaultFactionFrom(FactionDef.Named("THU_Xenomorph"));

            var pawnKindDef = PawnKindDef.Named(pawnKindDefName);

            var request = new PawnGenerationRequest(pawnKindDef, newborn: true, faction: faction);

            return(PawnGenerator.GeneratePawn(request));
        }
예제 #11
0
        private static void PawnKindApparelCheck()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef item in from kd in DefDatabase <PawnKindDef> .AllDefs
                     where kd.race == ThingDefOf.Human
                     orderby kd.defName
                     select kd)
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Action, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    bool flag       = false;
                    for (int k = 0; k < 100; k++)
                    {
                        Pawn pawn2 = PawnGenerator.GeneratePawn(localKindDef, faction);
                        if (pawn2.royalty != null)
                        {
                            RoyalTitle mostSeniorTitle2 = pawn2.royalty.MostSeniorTitle;
                            if (mostSeniorTitle2 != null && !mostSeniorTitle2.def.requiredApparel.NullOrEmpty())
                            {
                                for (int l = 0; l < mostSeniorTitle2.def.requiredApparel.Count; l++)
                                {
                                    if (!mostSeniorTitle2.def.requiredApparel[l].IsMet(pawn2))
                                    {
                                        Log.Error(string.Concat(localKindDef, " (", mostSeniorTitle2.def.label, ")  does not have its title requirements met. index=", l, logApparel(pawn2)));
                                        flag = true;
                                    }
                                }
                            }
                        }
                        List <Apparel> wornApparel2 = pawn2.apparel.WornApparel;
                        for (int m = 0; m < wornApparel2.Count; m++)
                        {
                            string text = apparelOkayToWear(pawn2, wornApparel2[m]);
                            if (text != "OK")
                            {
                                Log.Error(text + " - " + wornApparel2[m].Label + logApparel(pawn2));
                                flag = true;
                            }
                        }
                        Find.WorldPawns.PassToWorld(pawn2, PawnDiscardDecideMode.Discard);
                    }
                    if (!flag)
                    {
                        Log.Message("No errors for " + localKindDef.defName);
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
예제 #12
0
 public void EnsureNonNullFaction()
 {
     if (this.KindDef.RaceProps.Humanlike && this.Faction == null)
     {
         this.Faction = FactionUtility.DefaultFactionFrom(this.KindDef.defaultFactionType);
         Log.Error(string.Concat(new object[]
         {
             "Tried to generate pawn of Humanlike race ",
             this.KindDef,
             " with null faction. Setting to ",
             this.Faction
         }));
     }
 }
예제 #13
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            if (Faction == null)
            {
                SetFactionDirect(FactionUtility.DefaultFactionFrom(FactionDef.Named("Horrors")));
            }

            if (Faction != null && Faction.IsPlayer)
            {
                contentsKnown = true;
            }
        }
예제 #14
0
        private static void CallDeepstrikeOf()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef localKindDef2 in from f in DefDatabase <PawnKindDef> .AllDefs
                     //  where f.RoyalTitlesAwardableInSeniorityOrderForReading.Count > 0
                     orderby f.defName
                     select f)
            {
                PawnKindDef localKindDef = localKindDef2;

                /*
                 * if (!localKindDef.HasModExtension<DeepStrikeExtension>())
                 * {
                 *  continue;
                 * }
                 */
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Tool, delegate()
                {
                    List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                    IntVec3 cell = UI.MouseCell();
                    for (int i = 0; i < 6; i++)
                    {
                        DeepStrikeType strikeType = (DeepStrikeType)i;
                        list2.Add(new FloatMenuOption(DeepStrikeUtility.DeepstrikeArrivalmode(strikeType) + " - ", delegate()
                        {
                            Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                            Pawn newPawn    = PawnGenerator.GeneratePawn(localKindDef, faction);
                            DeepStrikeUtility.DropThingsNear(cell, Find.CurrentMap, Gen.YieldSingle <Thing>(newPawn), 110, false, false, true, strikeType);
                            if (faction != null && faction != Faction.OfPlayer)
                            {
                                Lord lord = null;
                                if (Find.CurrentMap.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                                {
                                    lord = ((Pawn)GenClosest.ClosestThing_Global(cell, Find.CurrentMap.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null, null)).GetLord();
                                }
                                if (lord == null)
                                {
                                    LordJob_DefendPoint lordJob = new LordJob_DefendPoint(cell, null, false, true);
                                    lord = LordMaker.MakeNewLord(faction, lordJob, Find.CurrentMap, null);
                                }
                                lord.AddPawn(newPawn);
                            }
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(list2));
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
예제 #15
0
        public static Pawn RandomPawnForCombat()
        {
            PawnKindDef pawnKindDef = DefDatabase <PawnKindDef> .AllDefsListForReading.RandomElementByWeight(delegate(PawnKindDef pawnkind)
            {
                if (pawnkind.RaceProps.Humanlike)
                {
                    return(8f);
                }
                return(pawnkind.RaceProps.IsMechanoid ? 8f : 1f);
            });

            Faction faction = FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType);

            return(PawnGenerator.GeneratePawn(pawnKindDef, faction));
        }
예제 #16
0
        public Faction GetFaction()
        {
            if (!SpawnerProps.usePlayerFaction)
            {
                if (SpawnerProps.forcedFaction == null)
                {
                    return(parent.Faction);
                }
                else
                {
                    return(FactionUtility.DefaultFactionFrom(SpawnerProps.forcedFaction));
                }
            }

            return(Faction.OfPlayer);
        }
        private static void TestForceKillx100()
        {
            for (int i = 0; i < 100; i++)
            {
                PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                Pawn pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                HealthUtility.DamageUntilDead(pawn);
                if (!pawn.Dead)
                {
                    Log.Error(string.Concat("Pawn died not die: ", pawn, " at ", pawn.Position));
                    break;
                }
            }
        }
예제 #18
0
        private static void SpawnPawn(int skill, AorB ab, HediffDef hediffs, bool AffectsEye, SkillDef skilldef)
        {
            Faction faction = FactionUtility.DefaultFactionFrom(ft: ab.fac);

            var pawngen = new PawnGenerationRequest(
                kind: ab.pkd,
                faction: faction,
                context: PawnGenerationContext.NonPlayer,
                mustBeCapableOfViolence: true,
                forceGenerateNewPawn: true,
                worldPawnFactionDoesntMatter: true
                );

            Pawn newPawn = PawnGenerator.GeneratePawn(request: pawngen);

            newPawn.skills.GetSkill(skillDef: skilldef).Level = skill;

            newPawn.story.traits.allTraits.RemoveAll(match: trt => ab.undesired.Contains(item: trt.def.defName));

            if (hediffs != null)
            {
                if (AffectsEye)
                {
                    foreach (BodyPartRecord bpr in newPawn.RaceProps.body.GetPartsWithTag(tag: Defs_Rimworld.EyeTag))
                    {
                        newPawn.health.AddHediff(def: hediffs, part: bpr, dinfo: null, result: null);
                    }
                }
                else
                {
                    newPawn.health.AddHediff(def: hediffs);
                }
            }

            GenSpawn.Spawn(newThing: newPawn, loc: UI.MouseCell(), map: Find.CurrentMap, wipeMode: WipeMode.Vanish);

            if (faction != null && faction != Faction.OfPlayer)
            {
                Lord lord = null;

                var lordJob = new LordJob_DefendPoint(point: newPawn.Position);
                lord = LordMaker.MakeNewLord(faction: faction, lordJob: lordJob, map: Find.CurrentMap, startingPawns: null);


                lord.AddPawn(p: newPawn);
            }
        }
예제 #19
0
        public bool SpawnRandomWildAnimalAt(Map map, IntVec3 loc)
        {
            PawnKindDef pawnKindDef = (from a in biome1.AllWildAnimals
                                       where map.mapTemperature.SeasonAcceptableFor(a.race)
                                       select a).RandomElementByWeight((PawnKindDef def) => biome1.CommonalityOfAnimal(def) / def.wildGroupSize.Average);

            if (pawnKindDef == null)
            {
                Log.Error("No spawnable animals right now.");
                return(false);
            }
            int randomInRange = pawnKindDef.wildGroupSize.RandomInRange;
            int radius        = Mathf.CeilToInt(Mathf.Sqrt((float)pawnKindDef.wildGroupSize.max));

            for (int i = 0; i < randomInRange; i++)
            {
                IntVec3 loc2    = CellFinder.RandomClosewalkCellNear(loc, map, radius, null);
                Faction faction = FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType);

                //Pawn newThing = PawnGenerator.GeneratePawn(pawnKindDef, faction);

                Pawn newPawn = PawnGenerator.GeneratePawn(pawnKindDef, faction);
                GenSpawn.Spawn(newPawn, loc2, map);
                if (faction != null && faction != Faction.OfPlayer)
                {
                    Lord lord = null;

                    LordJob_DefendPoint lordJob = new LordJob_DefendPoint(newPawn.Position);
                    lord = LordMaker.MakeNewLord(faction, lordJob, newPawn.Map, null);

                    /* if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                     * {
                     *   Pawn p2 = (Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null, null);
                     *   lord = p2.GetLord();
                     * }
                     * if (lord == null)
                     * {
                     *
                     * }*/
                    lord.AddPawn(newPawn);
                }


                //GenSpawn.Spawn(newThing, loc2, map);
            }
            return(true);
        }
예제 #20
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 item2 in orderedEnumerable)
            {
                PawnKindDef kind = item2;
                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();
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Sampled " + 300 + "x " + kind.defName + ":");
                    for (int l = 0; l < 21; l++)
                    {
                        int num3 = dictionary[l];
                        stringBuilder.AppendLine("  " + (l * 5).ToString() + "    " + num3 + " (" + ((float)num3 / 300f).ToStringPercent() + ")");
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
예제 #21
0
        private static void TestSurgeryFailRidiculousx100()
        {
            for (int i = 0; i < 100; i++)
            {
                PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                Pawn pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                pawn.health.forceIncap = true;
                HealthUtility.GiveInjuriesOperationFailureRidiculous(pawn);
                pawn.health.forceIncap = false;
                if (pawn.Dead)
                {
                    Log.Error("Pawn died: " + pawn + " at " + pawn.Position);
                }
            }
        }
        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 item2 in orderedEnumerable)
            {
                PawnKindDef     kind = item2;
                Faction         fac  = FactionUtility.DefaultFactionFrom(kind.defaultFactionType);
                FloatMenuOption item = new FloatMenuOption(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.CombinedDisabledWorkTags;
                        foreach (WorkTags value in Enum.GetValues(typeof(WorkTags)))
                        {
                            if (!dictionary.ContainsKey(value))
                            {
                                dictionary.Add(value, 0);
                            }
                            if ((combinedDisabledWorkTags & value) != 0)
                            {
                                dictionary[value]++;
                            }
                        }
                        pawn.Destroy();
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Sampled " + 1000 + "x " + kind.defName + ":");
                    stringBuilder.AppendLine("Worktags disabled");
                    foreach (WorkTags value2 in Enum.GetValues(typeof(WorkTags)))
                    {
                        int num = dictionary[value2];
                        stringBuilder.AppendLine("  " + value2.ToString() + "    " + num + " (" + ((float)num / 1000f).ToStringPercent() + ")");
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
예제 #23
0
        public static Pawn GenerateNewTenant()
        {
            bool generation = true;
            Pawn newTenant  = null;

            while (generation)
            {
                string      race   = SettingsHelper.LatestVersion.AvailableRaces.RandomElement();
                PawnKindDef random = DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => x.race.defName == race).RandomElement();

                if (random == null)
                {
                    return(null);
                }
                Faction faction = FactionUtility.DefaultFactionFrom(random.defaultFactionType);
                newTenant = PawnGenerator.GeneratePawn(random, faction);
                if (newTenant != null && !newTenant.Dead && !newTenant.IsDessicated() && !newTenant.AnimalOrWildMan())
                {
                    {
                        if (SettingsHelper.LatestVersion.SimpleClothing)
                        {
                            FloatRange range = newTenant.kindDef.apparelMoney;
                            newTenant.kindDef.apparelMoney = new FloatRange(SettingsHelper.LatestVersion.SimpleClothingMin, SettingsHelper.LatestVersion.SimpleClothingMax);
                            PawnApparelGenerator.GenerateStartingApparelFor(newTenant, new PawnGenerationRequest(random));
                            newTenant.kindDef.apparelMoney = range;
                        }
                        RemoveExpensiveItems(newTenant);
                        newTenant.GetTenantComponent().IsTenant      = true;
                        newTenant.GetTenantComponent().HiddenFaction = faction;
                        newTenant.SetFaction(Faction.OfAncients);
                        if (SettingsHelper.LatestVersion.Weapons)
                        {
                            List <Thing> ammo = newTenant.inventory.innerContainer.Where(x => x.def.defName.Contains("Ammunition")).ToList();
                            foreach (Thing thing in ammo)
                            {
                                newTenant.inventory.innerContainer.Remove(thing);
                            }
                        }
                        newTenant.DestroyOrPassToWorld();
                        generation = false;
                    }
                }
            }
            return(newTenant);
        }
예제 #24
0
        public Faction ResolveFaction(SpawnThings spawnables)
        {
            FactionDef factionDefToAssign = FactionDefOf.PlayerColony;

            if (spawnables.factionDef != null)
            {
                factionDefToAssign = spawnables.factionDef;
            }
            if (spawnables.kindDef != null)
            {
                if (spawnables.kindDef.defaultFactionType != null)
                {
                    factionDefToAssign = spawnables.kindDef.defaultFactionType;
                }
            }

            return(FactionUtility.DefaultFactionFrom(factionDefToAssign));
        }
예제 #25
0
        private static void TestSurgeryFailCatastrophicx100()
        {
            for (int i = 0; i < 100; i++)
            {
                PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                Pawn pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                GenSpawn.Spawn(pawn, CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(Find.CurrentMap), Find.CurrentMap), Find.CurrentMap);
                pawn.health.forceIncap = true;
                BodyPartRecord part = pawn.health.hediffSet.GetNotMissingParts().RandomElement();
                HealthUtility.GiveInjuriesOperationFailureCatastrophic(pawn, part);
                pawn.health.forceIncap = false;
                if (pawn.Dead)
                {
                    Log.Error("Pawn died: " + pawn + " at " + pawn.Position);
                }
            }
        }
예제 #26
0
        private static List <Pawn> NVPawnSetSpawner
        (
            Map map, SkillDef skill, GlowTeam team, int count, IntVec3 spot,
            AorB side
        )
        {
            var     list    = new List <Pawn>();
            Faction faction = FactionUtility.DefaultFactionFrom(ft: side.fac);

            for (var i = 0; i < count; i++)
            {
                var pawngen = new PawnGenerationRequest(
                    kind: side.pkd,
                    faction: faction,
                    context: PawnGenerationContext.NonPlayer,
                    mustBeCapableOfViolence: true,
                    forceGenerateNewPawn: true,
                    worldPawnFactionDoesntMatter: true
                    );

                Pawn newPawn = PawnGenerator.GeneratePawn(request: pawngen);
                newPawn.skills.GetSkill(skillDef: skill).Level = team.Skill;

                newPawn.story.traits.allTraits.RemoveAll(match: trt => side.undesired.Contains(item: trt.def.defName));

                if (team.GlowHediff != null)
                {
                    newPawn.health.AddHediff(
                        def: team.GlowHediff,
                        part: newPawn.RaceProps.body.GetPartsWithTag(tag: BodyPartTagDefOf.ConsciousnessSource).First()
                        );
                }

                IntVec3 loc = CellFinder.RandomClosewalkCellNear(root: spot, map: map, radius: 12, extraValidator: null);
                GenSpawn.Spawn(newThing: newPawn, loc: loc, map: map, rot: Rot4.Random, wipeMode: WipeMode.Vanish, respawningAfterLoad: false);
                list.Add(item: newPawn);
            }

            LordMaker.MakeNewLord(faction: faction, lordJob: new LordJob_DefendPoint(point: map.Center), map: map, startingPawns: list);

            return(list);
        }
예제 #27
0
        public static Faction ResolveFaction(Pawn caster, SpawnThings spawnables, Faction spawnAbleFaction, bool hostile = false)
        {
            FactionDef val = FactionDefOf.PlayerColony;
            Faction    obj = null;

            if (spawnAbleFaction != null && !hostile)
            {
                return(spawnAbleFaction);
            }

            obj = ((caster != null) ? caster.Faction : null);
            Faction val2 = obj;

            if (hostile)
            {
                if (obj != null && !val2.IsPlayer)
                {
                    return(val2);
                }
                if (spawnables.factionDef != null)
                {
                    val = spawnables.factionDef;
                }
                if (spawnables.kindDef != null && spawnables.kindDef.defaultFactionType != null)
                {
                    val = spawnables.kindDef.defaultFactionType;
                }
                if (val != null)
                {
                    return(FactionUtility.DefaultFactionFrom(val));
                }
                else
                {
                    return(Find.FactionManager.RandomEnemyFaction(true, true, true));
                }
            }
            if (caster != null && caster.Faction != null)
            {
                return(caster.Faction);
            }
            return(Find.FactionManager.AllFactionsVisible.RandomElement());
        }
예제 #28
0
        public static Faction ResolveFaction(Pawn caster, SpawnThings spawnables)
        {
            FactionDef val = FactionDefOf.PlayerColony;
            Faction    obj = null;

            obj = ((caster != null) ? caster.Faction : null);
            Faction val2 = obj;

            if (obj != null && !val2.IsPlayer)
            {
                return(val2);
            }
            if (spawnables.factionDef != null)
            {
                val = spawnables.factionDef;
            }
            if (spawnables.kindDef != null && spawnables.kindDef.defaultFactionType != null)
            {
                val = spawnables.kindDef.defaultFactionType;
            }
            return(FactionUtility.DefaultFactionFrom(val));
        }
        public Faction ResolveFaction(SpawnThings spawnables)
        {
            var factionDefToAssign = FactionDefOf.PlayerColony;

            if (this?.Caster?.Faction is Faction f && f.IsPlayer == false)
            {
                return(f);
            }
            if (spawnables.factionDef != null)
            {
                factionDefToAssign = spawnables.factionDef;
            }
            if (spawnables.kindDef != null)
            {
                if (spawnables.kindDef.defaultFactionType != null)
                {
                    factionDefToAssign = spawnables.kindDef.defaultFactionType;
                }
            }

            return(FactionUtility.DefaultFactionFrom(factionDefToAssign));
        }
예제 #30
0
        private static void TestGeneratePawnx1000()
        {
            float[] array = new float[10]
            {
                10f,
                20f,
                50f,
                100f,
                200f,
                500f,
                1000f,
                2000f,
                5000f,
                1E+20f
            };
            int[] array2 = new int[array.Length];
            for (int i = 0; i < 1000; i++)
            {
                PawnKindDef random = DefDatabase <PawnKindDef> .GetRandom();

                PerfLogger.Reset();
                Pawn  pawn = PawnGenerator.GeneratePawn(random, FactionUtility.DefaultFactionFrom(random.defaultFactionType));
                float ms   = PerfLogger.Duration() * 1000f;
                array2[array.FirstIndexOf((float time) => ms <= time)]++;
                if (pawn.Dead)
                {
                    Log.Error("Pawn is dead");
                }
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Pawn creation time histogram:");
            for (int j = 0; j < array2.Length; j++)
            {
                stringBuilder.AppendLine($"<{array[j]}ms: {array2[j]}");
            }
            Log.Message(stringBuilder.ToString());
        }