public override void DoWindowContents(Rect inRect)
        {
            Text.Font = GameFont.Small;
            bool flag = false;

            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
            {
                flag = true;
                Event.current.Use();
            }
            Listing_Standard listing_Standard = new Listing_Standard();

            listing_Standard.Begin(inRect);

            listing_Standard.Label("ChooseLeader".Translate());
            String label = (chosenPawn == null ? "NoneL" : chosenPawn.Name.ToStringShort);

            if (listing_Standard.ButtonText(label, null))
            {
                List <FloatMenuOption> list    = new List <FloatMenuOption>();
                List <Pawn>            tpawns2 = new List <Pawn>();

                list.Add(new FloatMenuOption("-" + "NoneL".Translate() + "-", delegate
                {
                    this.chosenPawn = null;
                }, MenuOptionPriority.Default, null, null, 0f, null, null));

                foreach (Pawn current in IncidentWorker_SetLeadership.getAllColonists())
                {
                    Hediff h1 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader1"));
                    Hediff h2 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader2"));
                    Hediff h3 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader3"));
                    Hediff h4 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader4"));
                    Hediff h5 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leaderExpired"));
                    //Hediff h6 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("ruler1"));
                    if (h1 == null && h2 == null && h3 == null && h4 == null && h5 == null && !current.WorkTagIsDisabled(WorkTags.Social))
                    {
                        tpawns2.Add(current);
                    }
                }

                foreach (Pawn p in tpawns2)
                {
                    list.Add(new FloatMenuOption(p.Name.ToStringShort, delegate
                    {
                        this.chosenPawn = p;
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                if (list.Count() == 1)
                {
                    TooltipHandler.TipRegion(inRect, "ChooseLeader_NoAbleColonists".Translate());
                }

                Find.WindowStack.Add(new FloatMenu(list));
            }


            if (listing_Standard.ButtonText("OK".Translate(), null))
            {
                if (this.chosenPawn != null)
                {
                    Pawn most = this.chosenPawn;
                    if (Utility.getGov().name == "Democracy".Translate() || Utility.getGov().name == "Dictatorship".Translate())
                    {
                        String targetLeader = "";
                        float  maxValue = new float[] { IncidentWorker_SetLeadership.getBotanistScore(most), IncidentWorker_SetLeadership.getWarriorScore(most), IncidentWorker_SetLeadership.getCarpenterScore(most), IncidentWorker_SetLeadership.getScientistScore(most) }.Max();
                        if (maxValue == IncidentWorker_SetLeadership.getBotanistScore(most))
                        {
                            targetLeader = "leader1";
                        }
                        if (maxValue == IncidentWorker_SetLeadership.getWarriorScore(most))
                        {
                            targetLeader = "leader2";
                        }
                        if (maxValue == IncidentWorker_SetLeadership.getCarpenterScore(most))
                        {
                            targetLeader = "leader3";
                        }
                        if (maxValue == IncidentWorker_SetLeadership.getScientistScore(most))
                        {
                            targetLeader = "leader4";
                        }
                        Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named(targetLeader), most, null);
                        IncidentWorker_SetLeadership.doElect(most, hediff, true);
                    }

                    /**
                     * else if(Utility.getGov().name == "Monarchy")
                     * {
                     *  Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("ruler1"), most, null);
                     *  IncidentWorker_SetLeadership.setRuler(most, hediff, true);
                     * }
                     **/
                }
                Find.WindowStack.TryRemove(this, true);
            }
            listing_Standard.End();
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnAggroMentalState(TargetIndex.A);
            if (base.job.def == JobDefOf.Rescue)
            {
                this.FailOnNotDowned(TargetIndex.A);
            }
            this.FailOn(delegate
            {
                if (this.job.def.makeTargetPrisoner)
                {
                    if (!this.DropBed.ForPrisoners)
                    {
                        return(true);
                    }
                }
                else if (this.DropBed.ForPrisoners != ((Pawn)((Thing)this.TargetA)).IsPrisoner)
                {
                    return(true);
                }
                return(false);
            });
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

            yield return(Toils_Reserve.Reserve(TargetIndex.B, this.DropBed.SleepingSlotsCount));

            yield return(Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A));

            this.globalFinishActions.Add(delegate
            {
                if (this.job.def.makeTargetPrisoner && this.Takee.ownership.OwnedBed == this.DropBed && this.Takee.Position != RestUtility.GetBedSleepingSlotPosFor(this.Takee, this.DropBed))
                {
                    this.Takee.ownership.UnclaimBed();
                }
            });                         //Pretty sure I just changed this code to say "If(!CanBeArrestedByMyself){... See !this.Takee.CanBeArrestedBy((Pawn)base.pawn)). Previously used to be !this.CanBeArrested() but this method no longer exists.
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A).FailOn(() => this.job.def == JobDefOf.Arrest && !this.Takee.CanBeArrestedBy((Pawn)base.pawn)).FailOn(() => !this.pawn.CanReach(this.DropBed, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)).FailOnSomeonePhysicallyInteracting(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    if (this.job.def.makeTargetPrisoner)
                    {
                        Pawn pawn = (Pawn)this.job.targetA.Thing;
                        Lord lord = pawn.GetLord();
                        if (lord != null)
                        {
                            lord.Notify_PawnAttemptArrested(pawn);
                        }


                        GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm);


                        if (Rand.Value < 0.1f)
                        {
                            Messages.Message("MessageRefusedArrest".Translate(new object[]
                                                                              { pawn.LabelShort }), pawn, MessageTypeDefOf.NegativeEvent);

                            pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Berserk, null, false, false, null);
                            IncidentWorker_Rebellion.removeLeadership(pawn);
                            pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("LeaderArrested"));
                            this.pawn.mindState.mentalStateHandler.CurState.RecoverFromState();
                            Find.LetterStack.ReceiveLetter("LeaderEndLetter".Translate(), "LeaderEndLetterDesc".Translate(new object[] { pawn.Name.ToStringFull }), LetterDefOf.NegativeEvent, pawn, null);
                            this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                        }
                    }
                }
            });

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, false, false));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch));

            yield return(new Toil
            {
                initAction = delegate
                {
                    if (this.job.def.makeTargetPrisoner)
                    {
                        this.pawn.mindState.mentalStateHandler.CurState.RecoverFromState();
                        IncidentWorker_Rebellion.removeLeadership(this.Takee);
                        this.Takee.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("LeaderArrested"));
                        Find.LetterStack.ReceiveLetter("LeaderEndLetterArrested".Translate(), "LeaderEndLetterDescArrested".Translate(new object[] { Takee.Name.ToStringFull }), LetterDefOf.NegativeEvent, this.pawn, null);
                        foreach (Pawn p in IncidentWorker_SetLeadership.getAllColonists())
                        {
                            if (p != this.Takee)
                            {
                                p.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("LeaderArrestedColonist"), null);
                            }
                        }

                        if (this.Takee.guest.Released)
                        {
                            this.Takee.guest.Released = false;
                            this.Takee.guest.interactionMode = PrisonerInteractionModeDefOf.NoInteraction;
                        }
                        if (!this.Takee.IsPrisonerOfColony)
                        {
                            if (this.Takee.Faction != null)
                            {
                                this.Takee.Faction.Notify_MemberCaptured(this.Takee, this.pawn.Faction);
                            }
                            this.Takee.guest.SetGuestStatus(Faction.OfPlayer, true);
                            if (this.Takee.guest.IsPrisoner)
                            {
                                TaleRecorder.RecordTale(TaleDefOf.Captured, new object[]
                                {
                                    this.pawn,
                                    this.Takee
                                });
                                this.pawn.records.Increment(RecordDefOf.PeopleCaptured);
                            }
                        }
                    }
                    else if (this.Takee.Faction != Faction.OfPlayer && this.Takee.HostFaction != Faction.OfPlayer && this.Takee.guest != null)
                    {
                        this.Takee.guest.SetGuestStatus(Faction.OfPlayer, false);
                    }
                    if (this.Takee.playerSettings == null)
                    {
                        this.Takee.playerSettings = new Pawn_PlayerSettings(this.Takee);
                    }
                }
            });

            yield return(Toils_Reserve.Release(TargetIndex.B));

            yield return(new Toil
            {
                initAction = delegate
                {
                    IntVec3 position = this.DropBed.Position;
                    Thing thing;
                    this.pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out thing, null);
                    if (!this.DropBed.Destroyed && (this.DropBed.OwnersForReading.Contains(this.Takee) || (this.DropBed.Medical && this.DropBed.AnyUnoccupiedSleepingSlot) || this.Takee.ownership == null))
                    {
                        this.Takee.jobs.Notify_TuckedIntoBed(this.DropBed);
                        if (this.Takee.RaceProps.Humanlike && this.job.def != JobDefOf.Arrest && !this.Takee.IsPrisonerOfColony)
                        {
                            this.Takee.relations.Notify_RescuedBy(this.pawn);
                        }
                    }
                    if (this.Takee.IsPrisonerOfColony)
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, this.Takee, OpportunityType.GoodToKnow);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }