private bool HostileDefeated()
        {
            MapParent map = (MapParent)parent;

            if (map.HasMap && !GenHostility.AnyHostileActiveThreatTo(map.Map, Faction.OfPlayer))
            {
                active = false;
                List <Pawn> prisoner  = map.Map.mapPawns.AllPawns.Where(x => !x.Dead && !x.Downed && (x.IsPrisoner || x.kindDef == PawnKindDefOf.Slave)).ToList();
                int         pawnSaved = prisoner.Count(x => !x.Dead);
                if (pawnSaved == 0)
                {
                    Find.LetterStack.ReceiveLetter("LetterLabelSettlementRescueFail".Translate(), TranslatorFormattedStringExtensions.Translate("SettlementRescueFail", parent.Faction, TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(Global.DayInTicks),
                                                                                                                                                ally.leader, ally.def.pawnsPlural), LetterDefOf.NegativeEvent, parent, null, null);
                    return(true);
                }
                else
                {
                    prisoner[0].Faction.TryAffectGoodwillWith(Faction.OfPlayer, 10 * pawnSaved);
                }

                foreach (Pawn p in prisoner)
                {
                    if (Rand.Chance(UnWillingChance))
                    {
                        pawnStaying++;
                        p.mindState.WillJoinColonyIfRescued = false;
                    }
                }
                if (pawnStaying >= 3)
                {
                    resurrectSet = true;
                }
                DropPodUtility.DropThingsNear(DropCellFinder.TradeDropSpot(Find.AnyPlayerHomeMap), Find.AnyPlayerHomeMap, new Gift_RewardGeneratorBasedTMagic().Generate(500, new List <Thing>()), 110, false, true, true);
                string text = TranslatorFormattedStringExtensions.Translate("SettlementRescueWin", parent.Faction, TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(Global.DayInTicks), ally.leader, ally.def.leaderTitle) + GenLabel.ThingsLabel(new Gift_RewardGeneratorBasedTMagic().Generate(500, new List <Thing>()), string.Empty);
                Find.LetterStack.ReceiveLetter("LetterLabelSettlementRescue".Translate(), text, LetterDefOf.PositiveEvent, parent, null, null);
                return(true);
            }
            return(false);
        }
        public bool Execute(Caravan caravan)
        {
            Map map = GetOrGenerateMapUtility.GetOrGenerateMap(caravan.Tile, DefDatabase <WorldObjectDef> .GetNamed("WanderingCaravanEncounter"));

            if (!WanderingCaravansUtility.AllWanderingCaravansSpawnableInMap(map).TryRandomElement(out PawnKindDef wanderingCaravanDef))
            {
                return(false);
            }
            MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 caravanSpot, out IntVec3 wanderingCaravansSpot);
            IEnumerable <Pawn> wanderingCaravans = this.GenerateWanderingCaravans(wanderingCaravanDef);
            Pawn    infoPawn = wanderingCaravans.First();
            DiaNode diaNode  = new DiaNode($"WanderingCaravan.WanderingCaravan_Spotted".Translate(infoPawn.LabelCap, caravan.LabelCap))
            {
                options =
                {
                    new DiaOption("WanderingCaravan.WanderingCaravan_Accept")
                    {
                        action = delegate
                        {
                            string plural = wanderingCaravans.Count() > 1 ? "ies" : "y";
                            CaravanEnterMapUtility.Enter(caravan, map, pawn => CellFinder.RandomSpawnCellForPawnNear(caravanSpot, map));
                            Messages.Message($"WanderingCaravan.WanderingCaravan_Accepted".Translate(TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(60000), infoPawn.LabelCap, plural), infoPawn, MessageTypeDefOf.PositiveEvent);
                            ((WorldObject)map.ParentHolder).GetComponent <TimedForcedExit>().StartForceExitAndRemoveMapCountdown();
                        },
                        resolveTree = true
                    }, new DiaOption("WanderingCaravan.WanderingCaravan_Reject".Translate())
                    {
                        resolveTree = true
                    }
                }
            };

            Find.WindowStack.Add(new Dialog_NodeTree(diaNode, true, false, $"WanderingCaravan.WanderingCaravan_Title".Translate(infoPawn.LabelCap)));
            this.SpawnPawns(wanderingCaravans, map, wanderingCaravansSpot);
            return(true);
        }