Пример #1
0
        public void DeinitAndRemoveMap(Map map)
        {
            if (map == null)
            {
                Log.Error("Tried to remove null map.", false);
                return;
            }
            if (!this.maps.Contains(map))
            {
                Log.Error("Tried to remove map " + map + " but it's not here.", false);
                return;
            }
            Map currentMap = this.CurrentMap;

            MapDeiniter.Deinit(map);
            this.maps.Remove(map);
            if (currentMap != null)
            {
                sbyte b = (sbyte)this.maps.IndexOf(currentMap);
                if ((int)b < 0)
                {
                    if (this.maps.Any <Map>())
                    {
                        this.CurrentMap = this.maps[0];
                    }
                    else
                    {
                        this.CurrentMap = null;
                    }
                    Find.World.renderer.wantedMode = WorldRenderMode.Planet;
                }
                else
                {
                    this.currentMapIndex = b;
                }
            }
            if (Current.ProgramState == ProgramState.Playing)
            {
                Find.ColonistBar.MarkColonistsDirty();
            }
            MapComponentUtility.MapRemoved(map);
            if (map.Parent != null)
            {
                map.Parent.Notify_MyMapRemoved(map);
            }
        }
Пример #2
0
        private static void PassPawnsToWorld(Map map)
        {
            bool        flag = map.ParentFaction != null && map.ParentFaction.HostileTo(Faction.OfPlayer);
            List <Pawn> list = map.mapPawns.AllPawns.ToList <Pawn>();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    Pawn pawn = list[i];
                    if (pawn.Spawned)
                    {
                        pawn.DeSpawn();
                    }
                    if (pawn.IsColonist && flag)
                    {
                        map.ParentFaction.kidnapped.KidnapPawn(pawn, null);
                    }
                    else
                    {
                        if (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer)
                        {
                            PawnBanishUtility.Banish(pawn, map.Tile);
                        }
                        MapDeiniter.CleanUpAndPassToWorld(pawn);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Could not despawn and pass to world ",
                        list[i],
                        ": ",
                        ex
                    }));
                }
            }
        }
Пример #3
0
 public static void Deinit(Map map)
 {
     try
     {
         MapDeiniter.DoQueuedPowerTasks(map);
     }
     catch (Exception arg)
     {
         Log.Error("Error while deiniting map: could not execute power related tasks: " + arg, false);
     }
     try
     {
         MapDeiniter.PassPawnsToWorld(map);
     }
     catch (Exception arg2)
     {
         Log.Error("Error while deiniting map: could not pass pawns to world: " + 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);
     }
 }
Пример #4
0
        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.Kidnap(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(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);
            }
        }
Пример #5
0
 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.LetterStack.Notify_MapRemoved(map);
     }
     catch (Exception arg9)
     {
         Log.Error("Error while deiniting map: could not remove things from thing listers: " + arg9, false);
     }
 }