public override void Notify_PawnLost(Pawn p, PawnLostCondition condition)
 {
     ReachabilityUtility.ClearCache();
     if (!this.caravanSent)
     {
         CaravanFormingUtility.RemovePawnFromCaravan(p, this.lord);
     }
 }
 public void SetGuestStatus(Faction newHost, bool prisoner = false)
 {
     if (newHost != null)
     {
         this.Released = false;
     }
     if (newHost == this.HostFaction && prisoner == this.IsPrisoner)
     {
         return;
     }
     if (!prisoner && this.pawn.Faction.HostileTo(newHost))
     {
         Log.Error("Tried to make " + this.pawn + " a guest of " + newHost + " but their faction " + this.pawn.Faction + " is hostile to " + newHost);
     }
     else if (newHost != null && newHost == this.pawn.Faction && !prisoner)
     {
         Log.Error("Tried to make " + this.pawn + " a guest of their own faction " + this.pawn.Faction);
     }
     else
     {
         bool flag = prisoner && (!this.IsPrisoner || this.HostFaction != newHost);
         this.isPrisonerInt  = prisoner;
         this.hostFactionInt = newHost;
         this.pawn.ClearMind(false);
         if (flag)
         {
             this.pawn.DropAndForbidEverything(false);
             Lord lord = this.pawn.GetLord();
             if (lord != null)
             {
                 lord.Notify_PawnLost(this.pawn, PawnLostCondition.MadePrisoner);
             }
             if (this.pawn.Drafted)
             {
                 this.pawn.drafter.Drafted = false;
             }
         }
         PawnComponentsUtility.AddAndRemoveDynamicComponents(this.pawn, false);
         this.pawn.health.surgeryBills.Clear();
         if (this.pawn.ownership != null)
         {
             this.pawn.ownership.Notify_ChangedGuestStatus();
         }
         ReachabilityUtility.ClearCache();
         if (this.pawn.Spawned)
         {
             this.pawn.Map.mapPawns.UpdateRegistryForPawn(this.pawn);
             this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn);
         }
         AddictionUtility.CheckDrugAddictionTeachOpportunity(this.pawn);
         if (prisoner && this.pawn.playerSettings != null)
         {
             this.pawn.playerSettings.Notify_MadePrisoner();
         }
     }
 }
 public override void Notify_PawnAdded(Pawn p)
 {
     ReachabilityUtility.ClearCache();
 }
Example #4
0
        public static void SetFaction(this Pawn pawn, Faction newFaction, Pawn recruiter = null)
        {
            if (newFaction == pawn.Faction)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Used ChangePawnFactionTo to change ",
                    pawn,
                    " to same faction ",
                    newFaction
                }));
                return;
            }
            if (pawn.guest != null)
            {
                pawn.guest.SetGuestStatus(null, false);
            }
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.DeRegisterPawn(pawn);
                pawn.Map.pawnDestinationManager.RemovePawnFromSystem(pawn);
                pawn.Map.designationManager.RemoveAllDesignationsOn(pawn, false);
            }
            if (newFaction == Faction.OfPlayer || pawn.Faction == Faction.OfPlayer)
            {
                Find.ColonistBar.MarkColonistsDirty();
            }
            Lord lord = pawn.GetLord();

            if (lord != null)
            {
                lord.Notify_PawnLost(pawn, PawnLostCondition.ChangedFaction);
            }
            if (pawn.Faction != null && pawn.Faction.leader == pawn)
            {
                pawn.Faction.Notify_LeaderLost();
            }
            if (newFaction == Faction.OfPlayer && pawn.RaceProps.Humanlike)
            {
                pawn.kindDef = newFaction.def.basicMemberKind;
            }

            // Call base SetFaction directly - horrible mojo warning
            MethodInfo method = typeof(Thing).GetMethod("SetFaction", BindingFlags.Public | BindingFlags.Instance);
            IntPtr     fptr   = method.MethodHandle.GetFunctionPointer();

            ((Action <Faction, Pawn>)Activator.CreateInstance(typeof(Action <Faction, Pawn>), pawn, fptr))(newFaction, null);

            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
            if (pawn.Faction != null && pawn.Faction.IsPlayer)
            {
                if (pawn.workSettings != null)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                Find.Storyteller.intenderPopulation.Notify_PopulationGained();
            }
            if (pawn.Drafted)
            {
                pawn.drafter.Drafted = false;
            }
            ReachabilityUtility.ClearCache();
            pawn.health.surgeryBills.Clear();
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.RegisterPawn(pawn);
            }
            pawn.GenerateNecessaryName();
            if (pawn.playerSettings != null)
            {
                Pawn_PlayerSettings_Detour.ResetPPSMedicalCare(pawn.playerSettings, pawn);
            }
            pawn.ClearMind(true);
            if (!pawn.Dead && pawn.needs.mood != null)
            {
                pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
            }
            if (pawn.Spawned)
            {
                pawn.Map.attackTargetsCache.UpdateTarget(pawn);
            }
            Find.GameEnder.CheckGameOver();
            AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
            if (pawn.needs != null)
            {
                pawn.needs.AddOrRemoveNeedsAsAppropriate();
            }
            if (pawn.playerSettings != null)
            {
                pawn.playerSettings.Notify_FactionChanged();
            }
        }
 public override void Notify_PawnLost(Pawn p, PawnLostCondition condition)
 {
     ReachabilityUtility.ClearCache();
 }