Пример #1
0
        public static NameTriple FromString(string rawName)
        {
            if (rawName.Trim().Length == 0)
            {
                Log.Error("Tried to parse PawnName from empty or whitespace string.");
                return(NameTriple.Invalid);
            }
            NameTriple nameTriple = new NameTriple();
            int        num        = -1;
            int        num2       = -1;

            for (int i = 0; i < rawName.Length - 1; i++)
            {
                if (rawName[i] == ' ' && rawName[i + 1] == '\'' && num == -1)
                {
                    num = i;
                }
                if (rawName[i] == '\'' && rawName[i + 1] == ' ')
                {
                    num2 = i;
                }
            }
            if (num == -1 || num2 == -1)
            {
                if (!rawName.Contains(' '))
                {
                    nameTriple.nickInt = rawName.Trim();
                }
                else
                {
                    string[] array = rawName.Split(new char[]
                    {
                        ' '
                    });
                    if (array.Length == 1)
                    {
                        nameTriple.nickInt = array[0].Trim();
                    }
                    else if (array.Length == 2)
                    {
                        nameTriple.firstInt = array[0].Trim();
                        nameTriple.lastInt  = array[1].Trim();
                    }
                    else
                    {
                        nameTriple.firstInt = array[0].Trim();
                        nameTriple.lastInt  = string.Empty;
                        for (int j = 1; j < array.Length; j++)
                        {
                            NameTriple expr_137 = nameTriple;
                            expr_137.lastInt += array[j];
                            if (j < array.Length - 1)
                            {
                                NameTriple expr_15A = nameTriple;
                                expr_15A.lastInt += " ";
                            }
                        }
                    }
                }
            }
            else
            {
                nameTriple.firstInt = rawName.Substring(0, num).Trim();
                nameTriple.nickInt  = rawName.Substring(num + 2, num2 - num - 2).Trim();
                nameTriple.lastInt  = ((num2 >= rawName.Length - 2) ? string.Empty : rawName.Substring(num2 + 2).Trim());
            }
            return(nameTriple);
        }
        public void FloodFill(int rootTile, Predicate <int> passCheck, Func <int, int, bool> processor, int maxTilesToProcess = int.MaxValue, IEnumerable <int> extraRootTiles = null)
        {
            if (working)
            {
                Log.Error("Nested FloodFill calls are not allowed. This will cause bugs.");
            }
            working = true;
            ClearVisited();
            if (rootTile != -1 && extraRootTiles == null && !passCheck(rootTile))
            {
                working = false;
                return;
            }
            int tilesCount = Find.WorldGrid.TilesCount;
            int num        = tilesCount;

            if (traversalDistance.Count != tilesCount)
            {
                traversalDistance.Clear();
                for (int i = 0; i < tilesCount; i++)
                {
                    traversalDistance.Add(-1);
                }
            }
            WorldGrid  worldGrid = Find.WorldGrid;
            List <int> tileIDToNeighbors_offsets = worldGrid.tileIDToNeighbors_offsets;
            List <int> tileIDToNeighbors_values  = worldGrid.tileIDToNeighbors_values;
            int        num2 = 0;

            openSet.Clear();
            if (rootTile != -1)
            {
                visited.Add(rootTile);
                traversalDistance[rootTile] = 0;
                openSet.Enqueue(rootTile);
            }
            if (extraRootTiles != null)
            {
                visited.AddRange(extraRootTiles);
                IList <int> list = extraRootTiles as IList <int>;
                if (list != null)
                {
                    for (int j = 0; j < list.Count; j++)
                    {
                        int num3 = list[j];
                        traversalDistance[num3] = 0;
                        openSet.Enqueue(num3);
                    }
                }
                else
                {
                    foreach (int extraRootTile in extraRootTiles)
                    {
                        traversalDistance[extraRootTile] = 0;
                        openSet.Enqueue(extraRootTile);
                    }
                }
            }
            while (openSet.Count > 0)
            {
                int num4 = openSet.Dequeue();
                int num5 = traversalDistance[num4];
                if (processor(num4, num5))
                {
                    break;
                }
                num2++;
                if (num2 == maxTilesToProcess)
                {
                    break;
                }
                int num6 = ((num4 + 1 < tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_offsets[num4 + 1] : tileIDToNeighbors_values.Count);
                for (int k = tileIDToNeighbors_offsets[num4]; k < num6; k++)
                {
                    int num7 = tileIDToNeighbors_values[k];
                    if (traversalDistance[num7] == -1 && passCheck(num7))
                    {
                        visited.Add(num7);
                        openSet.Enqueue(num7);
                        traversalDistance[num7] = num5 + 1;
                    }
                }
                if (openSet.Count > num)
                {
                    Log.Error("Overflow on world flood fill (>" + num + " cells). Make sure we're not flooding over the same area after we check it.");
                    working = false;
                    return;
                }
            }
            working = false;
        }
 private static void GenerateRandomAge(Pawn pawn, PawnGenerationRequest request)
 {
     if (request.FixedBiologicalAge.HasValue && request.FixedChronologicalAge.HasValue)
     {
         float?fixedBiologicalAge    = request.FixedBiologicalAge;
         bool  hasValue              = fixedBiologicalAge.HasValue;
         float?fixedChronologicalAge = request.FixedChronologicalAge;
         if ((hasValue & fixedChronologicalAge.HasValue) && fixedBiologicalAge.GetValueOrDefault() > fixedChronologicalAge.GetValueOrDefault())
         {
             Log.Warning("Tried to generate age for pawn " + pawn + ", but pawn generation request demands biological age (" + request.FixedBiologicalAge + ") to be greater than chronological age (" + request.FixedChronologicalAge + ").");
         }
     }
     if (request.Newborn)
     {
         pawn.ageTracker.AgeBiologicalTicks = 0L;
     }
     else if (request.FixedBiologicalAge.HasValue)
     {
         pawn.ageTracker.AgeBiologicalTicks = (long)(request.FixedBiologicalAge.Value * 3600000.0);
     }
     else
     {
         float num  = 0f;
         int   num2 = 0;
         while (true)
         {
             num = ((pawn.RaceProps.ageGenerationCurve == null) ? ((!pawn.RaceProps.IsMechanoid) ? (Rand.ByCurve(PawnGenerator.DefaultAgeGenerationCurve, 200) * pawn.RaceProps.lifeExpectancy) : ((float)Rand.Range(0, 2500))) : ((float)Mathf.RoundToInt(Rand.ByCurve(pawn.RaceProps.ageGenerationCurve, 200))));
             num2++;
             if (num2 > 300)
             {
                 Log.Error("Tried 300 times to generate age for " + pawn);
                 break;
             }
             if (!(num > (float)pawn.kindDef.maxGenerationAge) && !(num < (float)pawn.kindDef.minGenerationAge))
             {
                 break;
             }
         }
         pawn.ageTracker.AgeBiologicalTicks = (long)(num * 3600000.0) + Rand.Range(0, 3600000);
     }
     if (request.Newborn)
     {
         pawn.ageTracker.AgeChronologicalTicks = 0L;
     }
     else if (request.FixedChronologicalAge.HasValue)
     {
         pawn.ageTracker.AgeChronologicalTicks = (long)(request.FixedChronologicalAge.Value * 3600000.0);
     }
     else
     {
         int num3;
         if (request.CertainlyBeenInCryptosleep || Rand.Value < pawn.kindDef.backstoryCryptosleepCommonality)
         {
             float value = Rand.Value;
             if (value < 0.699999988079071)
             {
                 num3 = Rand.Range(0, 100);
             }
             else if (value < 0.949999988079071)
             {
                 num3 = Rand.Range(100, 1000);
             }
             else
             {
                 int max = GenDate.Year(GenTicks.TicksAbs, 0f) - 2026 - pawn.ageTracker.AgeBiologicalYears;
                 num3 = Rand.Range(1000, max);
             }
         }
         else
         {
             num3 = 0;
         }
         int  ticksAbs = GenTicks.TicksAbs;
         long num4     = ticksAbs - pawn.ageTracker.AgeBiologicalTicks;
         num4 -= (long)num3 * 3600000L;
         pawn.ageTracker.BirthAbsTicks = num4;
     }
     if (pawn.ageTracker.AgeBiologicalTicks > pawn.ageTracker.AgeChronologicalTicks)
     {
         pawn.ageTracker.AgeChronologicalTicks = pawn.ageTracker.AgeBiologicalTicks;
     }
 }
        private static void GenerateTraits(Pawn pawn, PawnGenerationRequest request)
        {
            if (pawn.story != null)
            {
                if (pawn.story.childhood.forcedTraits != null)
                {
                    List <TraitEntry> forcedTraits = pawn.story.childhood.forcedTraits;
                    for (int i = 0; i < forcedTraits.Count; i++)
                    {
                        TraitEntry traitEntry = forcedTraits[i];
                        if (traitEntry.def == null)
                        {
                            Log.Error("Null forced trait def on " + pawn.story.childhood);
                        }
                        else if (!pawn.story.traits.HasTrait(traitEntry.def))
                        {
                            pawn.story.traits.GainTrait(new Trait(traitEntry.def, traitEntry.degree, false));
                        }
                    }
                }
                if (pawn.story.adulthood != null && pawn.story.adulthood.forcedTraits != null)
                {
                    List <TraitEntry> forcedTraits2 = pawn.story.adulthood.forcedTraits;
                    for (int j = 0; j < forcedTraits2.Count; j++)
                    {
                        TraitEntry traitEntry2 = forcedTraits2[j];
                        if (traitEntry2.def == null)
                        {
                            Log.Error("Null forced trait def on " + pawn.story.adulthood);
                        }
                        else if (!pawn.story.traits.HasTrait(traitEntry2.def))
                        {
                            pawn.story.traits.GainTrait(new Trait(traitEntry2.def, traitEntry2.degree, false));
                        }
                    }
                }
                int num = Rand.RangeInclusive(2, 3);
                if (request.AllowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn)))
                {
                    Trait trait = new Trait(TraitDefOf.Gay, PawnGenerator.RandomTraitDegree(TraitDefOf.Gay), false);
                    pawn.story.traits.GainTrait(trait);
                }
                while (pawn.story.traits.allTraits.Count < num)
                {
                    TraitDef newTraitDef = DefDatabase <TraitDef> .AllDefsListForReading.RandomElementByWeight((TraitDef tr) => tr.GetGenderSpecificCommonality(pawn));

                    Trait trait2;
                    if (!pawn.story.traits.HasTrait(newTraitDef) && (newTraitDef != TraitDefOf.Gay || (request.AllowGay && !LovePartnerRelationUtility.HasAnyLovePartnerOfTheOppositeGender(pawn) && !LovePartnerRelationUtility.HasAnyExLovePartnerOfTheOppositeGender(pawn))) && (request.Faction == null || Faction.OfPlayerSilentFail == null || !request.Faction.HostileTo(Faction.OfPlayer) || newTraitDef.allowOnHostileSpawn) && !pawn.story.traits.allTraits.Any((Trait tr) => newTraitDef.ConflictsWith(tr)) && (newTraitDef.conflictingTraits == null || !newTraitDef.conflictingTraits.Any((TraitDef tr) => pawn.story.traits.HasTrait(tr))) && (newTraitDef.requiredWorkTypes == null || !pawn.story.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes)) && !pawn.story.WorkTagIsDisabled(newTraitDef.requiredWorkTags))
                    {
                        int degree = PawnGenerator.RandomTraitDegree(newTraitDef);
                        if (!pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && (pawn.story.adulthood == null || !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree)))
                        {
                            trait2 = new Trait(newTraitDef, degree, false);
                            if (pawn.mindState != null && pawn.mindState.mentalBreaker != null)
                            {
                                float breakThresholdExtreme = pawn.mindState.mentalBreaker.BreakThresholdExtreme;
                                breakThresholdExtreme += trait2.OffsetOfStat(StatDefOf.MentalBreakThreshold);
                                breakThresholdExtreme *= trait2.MultiplierOfStat(StatDefOf.MentalBreakThreshold);
                                if (!(breakThresholdExtreme > 0.40000000596046448))
                                {
                                    goto IL_04be;
                                }
                                continue;
                            }
                            goto IL_04be;
                        }
                    }
                    continue;
IL_04be:
                    pawn.story.traits.GainTrait(trait2);
                }
            }
        }
Пример #5
0
        public void FloodFill(IntVec3 root, Predicate <IntVec3> passCheck, Func <IntVec3, int, bool> processor, int maxCellsToProcess = 2147483647, bool rememberParents = false, IEnumerable <IntVec3> extraRoots = null)
        {
            if (this.working)
            {
                Log.Error("Nested FloodFill calls are not allowed. This will cause bugs.", false);
            }
            this.working = true;
            this.ClearVisited();
            if (rememberParents && this.parentGrid == null)
            {
                this.parentGrid = new CellGrid(this.map);
            }
            if (root.IsValid && extraRoots == null && !passCheck(root))
            {
                if (rememberParents)
                {
                    this.parentGrid[root] = IntVec3.Invalid;
                }
                this.working = false;
                return;
            }
            int area = this.map.Area;

            IntVec3[]   cardinalDirectionsAround = GenAdj.CardinalDirectionsAround;
            int         num         = cardinalDirectionsAround.Length;
            CellIndices cellIndices = this.map.cellIndices;
            int         num2        = 0;

            this.openSet.Clear();
            if (root.IsValid)
            {
                int num3 = cellIndices.CellToIndex(root);
                this.visited.Add(num3);
                this.traversalDistance[num3] = 0;
                this.openSet.Enqueue(root);
            }
            if (extraRoots != null)
            {
                IList <IntVec3> list = extraRoots as IList <IntVec3>;
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        int num4 = cellIndices.CellToIndex(list[i]);
                        this.visited.Add(num4);
                        this.traversalDistance[num4] = 0;
                        this.openSet.Enqueue(list[i]);
                    }
                }
                else
                {
                    foreach (IntVec3 current in extraRoots)
                    {
                        int num5 = cellIndices.CellToIndex(current);
                        this.visited.Add(num5);
                        this.traversalDistance[num5] = 0;
                        this.openSet.Enqueue(current);
                    }
                }
            }
            if (rememberParents)
            {
                for (int j = 0; j < this.visited.Count; j++)
                {
                    IntVec3 intVec = cellIndices.IndexToCell(this.visited[j]);
                    this.parentGrid[this.visited[j]] = ((!passCheck(intVec)) ? IntVec3.Invalid : intVec);
                }
            }
            while (this.openSet.Count > 0)
            {
                IntVec3 intVec2 = this.openSet.Dequeue();
                int     num6    = this.traversalDistance[cellIndices.CellToIndex(intVec2)];
                if (processor(intVec2, num6))
                {
                    break;
                }
                num2++;
                if (num2 == maxCellsToProcess)
                {
                    break;
                }
                for (int k = 0; k < num; k++)
                {
                    IntVec3 intVec3 = intVec2 + cardinalDirectionsAround[k];
                    int     num7    = cellIndices.CellToIndex(intVec3);
                    if (intVec3.InBounds(this.map) && this.traversalDistance[num7] == -1 && passCheck(intVec3))
                    {
                        this.visited.Add(num7);
                        this.openSet.Enqueue(intVec3);
                        this.traversalDistance[num7] = num6 + 1;
                        if (rememberParents)
                        {
                            this.parentGrid[num7] = intVec2;
                        }
                    }
                }
                if (this.openSet.Count > area)
                {
                    Log.Error("Overflow on flood fill (>" + area + " cells). Make sure we're not flooding over the same area after we check it.", false);
                    this.working = false;
                    return;
                }
            }
            this.working = false;
        }
Пример #6
0
        private static void DoSaveTranslationReport()
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();

            stringBuilder.AppendLine("Translation report for " + activeLanguage);
            if (activeLanguage.defInjections.Any((DefInjectionPackage x) => x.usedOldRepSyntax))
            {
                stringBuilder.AppendLine();
                stringBuilder.AppendLine("Consider using <Something.Field.Example.Etc>translation</Something.Field.Example.Etc> def-injection syntax instead of <rep>.");
            }
            try
            {
                AppendGeneralLoadErrors(stringBuilder);
            }
            catch (Exception arg)
            {
                Log.Error("Error while generating translation report (general load errors): " + arg);
            }
            try
            {
                AppendDefInjectionsLoadErros(stringBuilder);
            }
            catch (Exception arg2)
            {
                Log.Error("Error while generating translation report (def-injections load errors): " + arg2);
            }
            try
            {
                AppendBackstoriesLoadErrors(stringBuilder);
            }
            catch (Exception arg3)
            {
                Log.Error("Error while generating translation report (backstories load errors): " + arg3);
            }
            try
            {
                AppendMissingKeyedTranslations(stringBuilder);
            }
            catch (Exception arg4)
            {
                Log.Error("Error while generating translation report (missing keyed translations): " + arg4);
            }
            List <string> list = new List <string>();

            try
            {
                AppendMissingDefInjections(stringBuilder, list);
            }
            catch (Exception arg5)
            {
                Log.Error("Error while generating translation report (missing def-injections): " + arg5);
            }
            try
            {
                AppendMissingBackstories(stringBuilder);
            }
            catch (Exception arg6)
            {
                Log.Error("Error while generating translation report (missing backstories): " + arg6);
            }
            try
            {
                AppendUnnecessaryDefInjections(stringBuilder, list);
            }
            catch (Exception arg7)
            {
                Log.Error("Error while generating translation report (unnecessary def-injections): " + arg7);
            }
            try
            {
                AppendRenamedDefInjections(stringBuilder);
            }
            catch (Exception arg8)
            {
                Log.Error("Error while generating translation report (renamed def-injections): " + arg8);
            }
            try
            {
                AppendArgumentCountMismatches(stringBuilder);
            }
            catch (Exception arg9)
            {
                Log.Error("Error while generating translation report (argument count mismatches): " + arg9);
            }
            try
            {
                AppendUnnecessaryKeyedTranslations(stringBuilder);
            }
            catch (Exception arg10)
            {
                Log.Error("Error while generating translation report (unnecessary keyed translations): " + arg10);
            }
            try
            {
                AppendKeyedTranslationsMatchingEnglish(stringBuilder);
            }
            catch (Exception arg11)
            {
                Log.Error("Error while generating translation report (keyed translations matching English): " + arg11);
            }
            try
            {
                AppendBackstoriesMatchingEnglish(stringBuilder);
            }
            catch (Exception arg12)
            {
                Log.Error("Error while generating translation report (backstories matching English): " + arg12);
            }
            try
            {
                AppendDefInjectionsSyntaxSuggestions(stringBuilder);
            }
            catch (Exception arg13)
            {
                Log.Error("Error while generating translation report (def-injections syntax suggestions): " + arg13);
            }
            try
            {
                AppendTKeySystemErrors(stringBuilder);
            }
            catch (Exception arg14)
            {
                Log.Error("Error while generating translation report (TKeySystem errors): " + arg14);
            }
            string text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            if (text.NullOrEmpty())
            {
                text = GenFilePaths.SaveDataFolderPath;
            }
            text = Path.Combine(text, "TranslationReport.txt");
            File.WriteAllText(text, stringBuilder.ToString());
            Messages.Message("MessageTranslationReportSaved".Translate(Path.GetFullPath(text)), MessageTypeDefOf.TaskCompletion, historical: false);
        }
Пример #7
0
 public static void Look <T>(ref T target, bool saveDestroyedThings, string label, params object[] ctorArgs)
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         Thing thing = target as Thing;
         if (thing != null && thing.Destroyed)
         {
             if (!saveDestroyedThings)
             {
                 Log.Warning(string.Concat(new object[]
                 {
                     "Deep-saving destroyed thing ",
                     thing,
                     " with saveDestroyedThings==false. label=",
                     label
                 }));
             }
             else if (thing.Discarded)
             {
                 Log.Warning(string.Concat(new object[]
                 {
                     "Deep-saving discarded thing ",
                     thing,
                     ". This mode means that the thing is no longer managed by anything in the code and should not be deep-saved anywhere. (even with saveDestroyedThings==true) , label=",
                     label
                 }));
             }
         }
         IExposable exposable = target as IExposable;
         if (target != null && exposable == null)
         {
             Log.Error(string.Concat(new object[]
             {
                 "Cannot use LookDeep to save non-IExposable non-null ",
                 label,
                 " of type ",
                 typeof(T)
             }));
             return;
         }
         if (target == null)
         {
             if (Scribe.EnterNode(label))
             {
                 try
                 {
                     Scribe.saver.WriteAttribute("IsNull", "True");
                 }
                 finally
                 {
                     Scribe.ExitNode();
                 }
             }
         }
         else if (Scribe.EnterNode(label))
         {
             try
             {
                 if (target.GetType() != typeof(T) || typeof(T).IsGenericTypeDefinition)
                 {
                     Scribe.saver.WriteAttribute("Class", GenTypes.GetTypeNameWithoutIgnoredNamespaces(target.GetType()));
                 }
                 exposable.ExposeData();
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Exception while saving ",
                     exposable.ToStringSafe <IExposable>(),
                     ": ",
                     ex
                 }));
             }
             finally
             {
                 Scribe.ExitNode();
             }
         }
         Scribe.saver.loadIDsErrorsChecker.RegisterDeepSaved(target, label);
     }
     else if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         try
         {
             target = ScribeExtractor.SaveableFromNode <T>(Scribe.loader.curXmlParent[label], ctorArgs);
         }
         catch (Exception ex2)
         {
             Log.Error(string.Concat(new object[]
             {
                 "Exception while loading ",
                 Scribe.loader.curXmlParent[label].ToStringSafe <XmlElement>(),
                 ": ",
                 ex2
             }));
             target = default(T);
         }
     }
 }
		public static void Deinit(Map map)
		{
			try
			{
				MapDeiniter.PassPawnsToWorld(map);
			}
			catch (Exception arg)
			{
				Log.Error("Error while deiniting map: could not pass pawns to world: " + arg, false);
			}
			try
			{
				MapDeiniter.NotifyFactions(map);
			}
			catch (Exception arg2)
			{
				Log.Error("Error while deiniting map: could not notify factions: " + arg2, false);
			}
			try
			{
				map.weatherManager.EndAllSustainers();
			}
			catch (Exception arg3)
			{
				Log.Error("Error while deiniting map: could not end all weather sustainers: " + arg3, false);
			}
			try
			{
				Find.SoundRoot.sustainerManager.EndAllInMap(map);
			}
			catch (Exception arg4)
			{
				Log.Error("Error while deiniting map: could not end all effect sustainers: " + arg4, false);
			}
			try
			{
				map.areaManager.Notify_MapRemoved();
			}
			catch (Exception arg5)
			{
				Log.Error("Error while deiniting map: could not remove areas: " + arg5, false);
			}
			try
			{
				Find.TickManager.RemoveAllFromMap(map);
			}
			catch (Exception arg6)
			{
				Log.Error("Error while deiniting map: could not remove things from the tick manager: " + arg6, false);
			}
			try
			{
				MapDeiniter.NotifyEverythingWhichUsesMapReference(map);
			}
			catch (Exception arg7)
			{
				Log.Error("Error while deiniting map: could not notify things/regions/rooms/etc: " + arg7, false);
			}
			try
			{
				map.listerThings.Clear();
				map.spawnedThings.Clear();
			}
			catch (Exception arg8)
			{
				Log.Error("Error while deiniting map: could not remove things from thing listers: " + arg8, false);
			}
			try
			{
				Find.Archive.Notify_MapRemoved(map);
			}
			catch (Exception arg9)
			{
				Log.Error("Error while deiniting map: could not remove look targets: " + arg9, false);
			}
			try
			{
				Find.Storyteller.incidentQueue.Notify_MapRemoved(map);
			}
			catch (Exception arg10)
			{
				Log.Error("Error while deiniting map: could not remove queued incidents: " + arg10, false);
			}
		}
		private static void PassPawnsToWorld(Map map)
		{
			List<Pawn> list = new List<Pawn>();
			List<Pawn> list2 = new List<Pawn>();
			bool flag = map.ParentFaction != null && map.ParentFaction.HostileTo(Faction.OfPlayer);
			List<Pawn> list3 = map.mapPawns.AllPawns.ToList<Pawn>();
			for (int i = 0; i < list3.Count; i++)
			{
				Find.Storyteller.Notify_PawnEvent(list3[i], AdaptationEvent.LostBecauseMapClosed, null);
				try
				{
					Pawn pawn = list3[i];
					if (pawn.Spawned)
					{
						pawn.DeSpawn(DestroyMode.Vanish);
					}
					if (pawn.IsColonist && flag)
					{
						list.Add(pawn);
						map.ParentFaction.kidnapped.KidnapPawn(pawn, null);
					}
					else
					{
						if (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer)
						{
							list2.Add(pawn);
							PawnBanishUtility.Banish(pawn, map.Tile);
						}
						MapDeiniter.CleanUpAndPassToWorld(pawn);
					}
				}
				catch (Exception ex)
				{
					Log.Error(string.Concat(new object[]
					{
						"Could not despawn and pass to world ",
						list3[i],
						": ",
						ex
					}), false);
				}
			}
			if (list.Any<Pawn>() || list2.Any<Pawn>())
			{
				StringBuilder stringBuilder = new StringBuilder();
				if (list.Any<Pawn>())
				{
					list.SortByDescending((Pawn x) => x.RaceProps.Humanlike);
					for (int j = 0; j < list.Count; j++)
					{
						stringBuilder.AppendLine(string.Concat(new string[]
						{
							"  - ",
							list[j].LabelCap,
							" (",
							"capturedBy".Translate(new object[]
							{
								map.ParentFaction.Name
							}),
							")"
						}));
					}
				}
				if (list2.Any<Pawn>())
				{
					list2.SortByDescending((Pawn x) => x.RaceProps.Humanlike);
					for (int k = 0; k < list2.Count; k++)
					{
						stringBuilder.AppendLine("  - " + list2[k].LabelCap);
					}
				}
				string label;
				string text;
				if (map.IsPlayerHome)
				{
					label = "LetterLabelPawnsLostBecauseMapClosed_Home".Translate();
					text = "LetterPawnsLostBecauseMapClosed_Home".Translate();
				}
				else
				{
					label = "LetterLabelPawnsLostBecauseMapClosed_Caravan".Translate();
					text = "LetterPawnsLostBecauseMapClosed_Caravan".Translate();
				}
				text = text + ":\n\n" + stringBuilder.ToString().TrimEndNewlines();
				Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NegativeEvent, new GlobalTargetInfo(map.Tile), null, null);
			}
		}