public static void RegisterAllAt(IntVec3 c, Map map, HashSet <Thing> processedThings = null) { List <Thing> thingList = c.GetThingList(map); int count = thingList.Count; for (int i = 0; i < count; i++) { Thing thing = thingList[i]; if (processedThings == null || processedThings.Add(thing)) { RegionListersUpdater.RegisterInRegions(thing, map); } } }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { if (this.Destroyed) { Log.Error("Spawning destroyed thing " + this + " at " + this.Position + ". Correcting."); this.mapIndexOrState = -1; if (this.HitPoints <= 0 && this.def.useHitPoints) { this.HitPoints = 1; } } if (this.Spawned) { Log.Error("Tried to spawn already-spawned thing " + this + " at " + this.Position); } else { int num = Find.Maps.IndexOf(map); if (num < 0) { Log.Error("Tried to spawn thing " + this + ", but the map provided does not exist."); } else { if (this.stackCount > this.def.stackLimit) { Log.Error("Spawned " + this + " with stackCount " + this.stackCount + " but stackLimit is " + this.def.stackLimit + ". Truncating."); this.stackCount = this.def.stackLimit; } this.mapIndexOrState = (sbyte)num; RegionListersUpdater.RegisterInRegions(this, map); if (!map.spawnedThings.TryAdd(this, false)) { Log.Error("Couldn't add thing " + this + " to spawned things."); } map.listerThings.Add(this); map.thingGrid.Register(this); if (Find.TickManager != null) { Find.TickManager.RegisterAllTickabilityFor(this); } this.DirtyMapMesh(map); if (this.def.drawerType != DrawerType.MapMeshOnly) { map.dynamicDrawManager.RegisterDrawable(this); } map.tooltipGiverList.Notify_ThingSpawned(this); if (this.def.graphicData != null && this.def.graphicData.Linked) { map.linkGrid.Notify_LinkerCreatedOrDestroyed(this); map.mapDrawer.MapMeshDirty(this.Position, MapMeshFlag.Things, true, false); } if (!this.def.CanOverlapZones) { map.zoneManager.Notify_NoZoneOverlapThingSpawned(this); } if (this.def.AffectsRegions) { map.regionDirtyer.Notify_ThingAffectingRegionsSpawned(this); } if (this.def.pathCost != 0 || this.def.passability == Traversability.Impassable) { map.pathGrid.RecalculatePerceivedPathCostUnderThing(this); } if (this.def.AffectsReachability) { map.reachability.ClearCache(); } map.coverGrid.Register(this); if (this.def.category == ThingCategory.Item) { map.listerHaulables.Notify_Spawned(this); } map.attackTargetsCache.Notify_ThingSpawned(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); } 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_ReceivedThing(this); } } if (this.def.receivesSignals) { Find.SignalManager.RegisterReceiver(this); } } } }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { if (Destroyed) { Log.Error(string.Concat("Spawning destroyed thing ", this, " at ", Position, ". Correcting.")); mapIndexOrState = -1; if (HitPoints <= 0 && def.useHitPoints) { HitPoints = 1; } } if (Spawned) { Log.Error(string.Concat("Tried to spawn already-spawned thing ", this, " at ", Position)); return; } int num = Find.Maps.IndexOf(map); if (num < 0) { Log.Error(string.Concat("Tried to spawn thing ", this, ", but the map provided does not exist.")); return; } if (stackCount > def.stackLimit) { Log.Error(string.Concat("Spawned ", this, " with stackCount ", stackCount, " but stackLimit is ", def.stackLimit, ". Truncating.")); stackCount = def.stackLimit; } mapIndexOrState = (sbyte)num; RegionListersUpdater.RegisterInRegions(this, map); if (!map.spawnedThings.TryAdd(this, canMergeWithExistingStacks: false)) { Log.Error(string.Concat("Couldn't add thing ", this, " to spawned things.")); } map.listerThings.Add(this); map.thingGrid.Register(this); if (Find.TickManager != null) { Find.TickManager.RegisterAllTickabilityFor(this); } DirtyMapMesh(map); if (def.drawerType != DrawerType.MapMeshOnly) { map.dynamicDrawManager.RegisterDrawable(this); } map.tooltipGiverList.Notify_ThingSpawned(this); if (def.graphicData != null && def.graphicData.Linked) { map.linkGrid.Notify_LinkerCreatedOrDestroyed(this); map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Things, regenAdjacentCells: true, regenAdjacentSections: false); } if (!def.CanOverlapZones) { map.zoneManager.Notify_NoZoneOverlapThingSpawned(this); } if (def.AffectsRegions) { map.regionDirtyer.Notify_ThingAffectingRegionsSpawned(this); } if (def.pathCost != 0 || def.passability == Traversability.Impassable) { map.pathGrid.RecalculatePerceivedPathCostUnderThing(this); } if (def.AffectsReachability) { map.reachability.ClearCache(); } map.coverGrid.Register(this); if (def.category == ThingCategory.Item) { map.listerHaulables.Notify_Spawned(this); map.listerMergeables.Notify_Spawned(this); } map.attackTargetsCache.Notify_ThingSpawned(this); (map.regionGrid.GetValidRegionAt_NoRebuild(Position)?.Room)?.Notify_ContainedThingSpawnedOrDespawned(this); StealAIDebugDrawer.Notify_ThingChanged(this); IHaulDestination haulDestination = this as IHaulDestination; if (haulDestination != null) { map.haulDestinationManager.AddHaulDestination(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_ReceivedThing(this); } } if (def.receivesSignals) { Find.SignalManager.RegisterReceiver(this); } if (!respawningAfterLoad) { QuestUtility.SendQuestTargetSignals(questTags, "Spawned", this.Named("SUBJECT")); } }