private static void SpawnWorldPawn()
        {
            List <DebugMenuOption> list   = new List <DebugMenuOption>();
            PawnKindDef            kLocal = default(PawnKindDef);
            Action <Pawn>          act    = delegate(Pawn p)
            {
                List <DebugMenuOption> list2 = new List <DebugMenuOption>();
                foreach (PawnKindDef item in DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef x) => x.race == p.def))
                {
                    kLocal = item;
                    list2.Add(new DebugMenuOption(kLocal.defName, DebugMenuOptionMode.Tool, delegate
                    {
                        PawnGenerationRequest request = new PawnGenerationRequest(kLocal, p.Faction);
                        PawnGenerator.RedressPawn(p, request);
                        GenSpawn.Spawn(p, UI.MouseCell(), Find.CurrentMap);
                        DebugTools.curTool = null;
                    }));
                }
                Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2));
            };

            foreach (Pawn item2 in Find.WorldPawns.AllPawnsAlive)
            {
                Pawn pLocal = item2;
                list.Add(new DebugMenuOption(item2.LabelShort, DebugMenuOptionMode.Action, delegate
                {
                    act(pLocal);
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Example #2
0
        private static Pawn GeneratePawnInternal(PawnGenerationRequest request)
        {
            request.EnsureNonNullFaction();
            Pawn pawn = null;

            if (!request.Newborn && !request.ForceGenerateNewPawn)
            {
                if (request.ForceRedressWorldPawnIfFormerColonist)
                {
                    IEnumerable <Pawn> validCandidatesToRedress = PawnGenerator.GetValidCandidatesToRedress(request);
                    if (validCandidatesToRedress.Where(new Func <Pawn, bool>(PawnUtility.EverBeenColonistOrTameAnimal)).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn))
                    {
                        PawnGenerator.RedressPawn(pawn, request);
                        Find.WorldPawns.RemovePawn(pawn);
                    }
                }
                if (pawn == null && request.Inhabitant && request.Tile != -1)
                {
                    Settlement settlement = Find.WorldObjects.WorldObjectAt <Settlement>(request.Tile);
                    if (settlement != null && settlement.previouslyGeneratedInhabitants.Any <Pawn>())
                    {
                        IEnumerable <Pawn> validCandidatesToRedress2 = PawnGenerator.GetValidCandidatesToRedress(request);
                        if ((from x in validCandidatesToRedress2
                             where settlement.previouslyGeneratedInhabitants.Contains(x)
                             select x).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn))
                        {
                            PawnGenerator.RedressPawn(pawn, request);
                            Find.WorldPawns.RemovePawn(pawn);
                        }
                    }
                }
                if (pawn == null && Rand.Chance(PawnGenerator.ChanceToRedressAnyWorldPawn(request)))
                {
                    IEnumerable <Pawn> validCandidatesToRedress3 = PawnGenerator.GetValidCandidatesToRedress(request);
                    if (validCandidatesToRedress3.TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn))
                    {
                        PawnGenerator.RedressPawn(pawn, request);
                        Find.WorldPawns.RemovePawn(pawn);
                    }
                }
            }
            if (pawn == null)
            {
                pawn = PawnGenerator.GenerateNewNakedPawn(ref request);
                if (pawn == null)
                {
                    return(null);
                }
                if (!request.Newborn)
                {
                    PawnGenerator.GenerateGearFor(pawn, request);
                }
                if (request.Inhabitant && request.Tile != -1)
                {
                    Settlement settlement2 = Find.WorldObjects.WorldObjectAt <Settlement>(request.Tile);
                    if (settlement2 != null)
                    {
                        settlement2.previouslyGeneratedInhabitants.Add(pawn);
                    }
                }
            }
            if (Find.Scenario != null)
            {
                Find.Scenario.Notify_PawnGenerated(pawn, request.Context);
            }
            return(pawn);
        }