示例#1
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 DoWindowContents(Rect inRect)
        {
            Text.Font = GameFont.Medium;
            Rect rect = new Rect(0f, 0f, InitialSize.x, 50f);

            Widgets.Label(rect, "Medical Defaults");
            Text.Font = GameFont.Small;

            Rect content = new Rect(0, 50, inRect.width, inRect.height - 70);

            Listing_Standard listing_Standard = new Listing_Standard(content);
            float            stdHeight        = MedicalCareUtility.CareSetterHeight;

            float hgap = 40;

            float hposA = 10;
            float hposB = 160;
            float hposC = hposB + MedicalCareUtility.CareSetterWidth + hgap;

            float hwidthA = 120;
            float hwidthB = MedicalCareUtility.CareSetterWidth;
            float hwidthC = MedicalCareUtility.CareSetterWidth;

            try
            {
                Config config = UtilityWorldObjectManager.GetUtilityWorldObject <Config>();

                MedicalCareUtility_Detour.HorribleHackWithinDefaultDialog = true;

                listing_Standard.Gap(20);

                {
                    Rect title = listing_Standard.GetRect(stdHeight);
                    Widgets.Label(new Rect(hposB + 30, title.y, hwidthB, stdHeight), "Human");
                    Widgets.Label(new Rect(hposC + 30, title.y, hwidthC, stdHeight), "Animal");
                }

                {
                    Rect title = listing_Standard.GetRect(stdHeight);
                    Widgets.Label(new Rect(hposA, title.y, hwidthA, stdHeight), "Colonist");
                    MedicalCareUtility.MedicalCareSetter(new Rect(hposB, title.y, hwidthB, stdHeight), ref config.care_PlayerHuman);
                    MedicalCareUtility.MedicalCareSetter(new Rect(hposC, title.y, hwidthC, stdHeight), ref config.care_PlayerAnimal);
                }

                {
                    Rect title = listing_Standard.GetRect(stdHeight);
                    Widgets.Label(new Rect(hposA, title.y, hwidthA, stdHeight), "Colonist Prisoner");
                    MedicalCareUtility.MedicalCareSetter(new Rect(hposB, title.y, hwidthB, stdHeight), ref config.care_PrisonerHuman);
                }

                {
                    Rect title = listing_Standard.GetRect(stdHeight);
                    Widgets.Label(new Rect(hposA, title.y, hwidthA, stdHeight), "Ally");
                    MedicalCareUtility.MedicalCareSetter(new Rect(hposB, title.y, hwidthB, stdHeight), ref config.care_AllyHuman);
                    MedicalCareUtility.MedicalCareSetter(new Rect(hposC, title.y, hwidthC, stdHeight), ref config.care_AllyAnimal);
                }

                {
                    Rect title = listing_Standard.GetRect(stdHeight);
                    Widgets.Label(new Rect(hposA, title.y, hwidthA, stdHeight), "Enemy");
                    MedicalCareUtility.MedicalCareSetter(new Rect(hposB, title.y, hwidthB, stdHeight), ref config.care_EnemyHuman);
                    MedicalCareUtility.MedicalCareSetter(new Rect(hposC, title.y, hwidthC, stdHeight), ref config.care_EnemyAnimal);
                }

                listing_Standard.Gap(50);

                if (listing_Standard.ButtonText("Reset all pawns to these values"))
                {
                    foreach (Pawn p in PawnsFinder.AllMapsAndWorld_Alive)
                    {
                        Pawn_PlayerSettings_Detour.ResetPPSMedicalCare(p.playerSettings, p);
                    }
                }
            }
            finally
            {
                MedicalCareUtility_Detour.HorribleHackWithinDefaultDialog = false;
            }

            listing_Standard.End();
        }