Ejemplo n.º 1
0
        public static Pawn GeneratePawn(PawnGenerationRequest request)
        {
            Pawn result;

            try
            {
                Pawn pawn = PawnGenerator.GenerateOrRedressPawnInternal(request);
                if (pawn != null && !request.AllowDead && pawn.health.hediffSet.hediffs.Any <Hediff>())
                {
                    bool dead   = pawn.Dead;
                    bool downed = pawn.Downed;
                    pawn.health.hediffSet.DirtyCache();
                    pawn.health.CheckForStateChange(null, null);
                    if (pawn.Dead)
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "Pawn was generated dead but the pawn generation request specified the pawn must be alive. This shouldn't ever happen even if we ran out of tries because null pawn should have been returned instead in this case. Resetting health...\npawn.Dead=",
                            pawn.Dead,
                            " pawn.Downed=",
                            pawn.Downed,
                            " deadBefore=",
                            dead,
                            " downedBefore=",
                            downed,
                            "\nrequest=",
                            request
                        }), false);
                        pawn.health.Reset();
                    }
                }
                if (pawn.Faction == Faction.OfPlayerSilentFail)
                {
                    Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedColonist);
                }
                result = pawn;
            }
            catch (Exception arg)
            {
                Log.Error("Error while generating pawn. Rethrowing. Exception: " + arg, false);
                throw;
            }
            finally
            {
            }
            return(result);
        }