Example #1
0
 public override void DeSpawn()
 {
     if (this.Destroyed)
     {
         Log.Error("Tried to despawn " + this.ToStringSafe() + " which is already destroyed.");
     }
     else if (!this.Spawned)
     {
         Log.Error("Tried to despawn " + this.ToStringSafe() + " which is not spawned.");
     }
     else
     {
         Map map = this.Map;
         RegionListersUpdater.DeregisterInRegions(this, map);
         map.spawnedThings.Remove(this);
         map.listerThings.Remove(this);
         map.thingGrid.Deregister(this, false);
         map.coverGrid.DeRegister(this);
         if (this.def.receivesSignals)
         {
             Find.SignalManager.DeregisterReceiver(this);
         }
         map.tooltipGiverList.Notify_ThingDespawned(this);
         if (this.def.graphicData != null && this.def.graphicData.Linked)
         {
             map.linkGrid.Notify_LinkerCreatedOrDestroyed(this);
             map.mapDrawer.MapMeshDirty(this.Position, MapMeshFlag.Things, true, false);
         }
         Find.Selector.Deselect(this);
         this.DirtyMapMesh(map);
         if (this.def.drawerType != DrawerType.MapMeshOnly)
         {
             map.dynamicDrawManager.DeRegisterDrawable(this);
         }
         Region validRegionAt_NoRebuild = map.regionGrid.GetValidRegionAt_NoRebuild(this.Position);
         Room   room = (validRegionAt_NoRebuild != null) ? validRegionAt_NoRebuild.Room : null;
         if (room != null)
         {
             room.Notify_ContainedThingSpawnedOrDespawned(this);
         }
         if (this.def.AffectsRegions)
         {
             map.regionDirtyer.Notify_ThingAffectingRegionsDespawned(this);
         }
         if (this.def.pathCost != 0 || this.def.passability == Traversability.Impassable)
         {
             map.pathGrid.RecalculatePerceivedPathCostUnderThing(this);
         }
         if (this.def.AffectsReachability)
         {
             map.reachability.ClearCache();
         }
         Find.TickManager.DeRegisterAllTickabilityFor(this);
         this.mapIndexOrState = -1;
         if (this.def.category == ThingCategory.Item)
         {
             map.listerHaulables.Notify_DeSpawned(this);
         }
         map.attackTargetsCache.Notify_ThingDespawned(this);
         StealAIDebugDrawer.Notify_ThingChanged(this);
         if (this is IThingHolder && Find.ColonistBar != null)
         {
             Find.ColonistBar.MarkColonistsDirty();
         }
         if (this.def.category == ThingCategory.Item)
         {
             SlotGroup slotGroup = this.Position.GetSlotGroup(map);
             if (slotGroup != null && slotGroup.parent != null)
             {
                 slotGroup.parent.Notify_LostThing(this);
             }
         }
     }
 }
Example #2
0
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            if (Destroyed)
            {
                Log.Error("Tried to despawn " + this.ToStringSafe() + " which is already destroyed.");
                return;
            }
            if (!Spawned)
            {
                Log.Error("Tried to despawn " + this.ToStringSafe() + " which is not spawned.");
                return;
            }
            Map map = Map;

            RegionListersUpdater.DeregisterInRegions(this, map);
            map.spawnedThings.Remove(this);
            map.listerThings.Remove(this);
            map.thingGrid.Deregister(this);
            map.coverGrid.DeRegister(this);
            if (def.receivesSignals)
            {
                Find.SignalManager.DeregisterReceiver(this);
            }
            map.tooltipGiverList.Notify_ThingDespawned(this);
            if (def.graphicData != null && def.graphicData.Linked)
            {
                map.linkGrid.Notify_LinkerCreatedOrDestroyed(this);
                map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Things, regenAdjacentCells: true, regenAdjacentSections: false);
            }
            if (Find.Selector.IsSelected(this))
            {
                Find.Selector.Deselect(this);
                Find.MainButtonsRoot.tabs.Notify_SelectedObjectDespawned();
            }
            DirtyMapMesh(map);
            if (def.drawerType != DrawerType.MapMeshOnly)
            {
                map.dynamicDrawManager.DeRegisterDrawable(this);
            }
            (map.regionGrid.GetValidRegionAt_NoRebuild(Position)?.Room)?.Notify_ContainedThingSpawnedOrDespawned(this);
            if (def.AffectsRegions)
            {
                map.regionDirtyer.Notify_ThingAffectingRegionsDespawned(this);
            }
            if (def.pathCost != 0 || def.passability == Traversability.Impassable)
            {
                map.pathGrid.RecalculatePerceivedPathCostUnderThing(this);
            }
            if (def.AffectsReachability)
            {
                map.reachability.ClearCache();
            }
            Find.TickManager.DeRegisterAllTickabilityFor(this);
            mapIndexOrState = -1;
            if (def.category == ThingCategory.Item)
            {
                map.listerHaulables.Notify_DeSpawned(this);
                map.listerMergeables.Notify_DeSpawned(this);
            }
            map.attackTargetsCache.Notify_ThingDespawned(this);
            map.physicalInteractionReservationManager.ReleaseAllForTarget(this);
            StealAIDebugDrawer.Notify_ThingChanged(this);
            IHaulDestination haulDestination = this as IHaulDestination;

            if (haulDestination != null)
            {
                map.haulDestinationManager.RemoveHaulDestination(haulDestination);
            }
            if (this is IThingHolder && Find.ColonistBar != null)
            {
                Find.ColonistBar.MarkColonistsDirty();
            }
            if (def.category == ThingCategory.Item)
            {
                SlotGroup slotGroup = Position.GetSlotGroup(map);
                if (slotGroup != null && slotGroup.parent != null)
                {
                    slotGroup.parent.Notify_LostThing(this);
                }
            }
            QuestUtility.SendQuestTargetSignals(questTags, "Despawned", this.Named("SUBJECT"));
        }