private static void CalculateExpectedListers(Map map) { Autotests_RegionListers.expectedListers.Clear(); List <Thing> allThings = map.listerThings.AllThings; for (int i = 0; i < allThings.Count; i++) { Thing thing = allThings[i]; if (ListerThings.EverListable(thing.def, ListerThingsUse.Region)) { RegionListersUpdater.GetTouchableRegions(thing, map, Autotests_RegionListers.tmpTouchableRegions, false); for (int j = 0; j < Autotests_RegionListers.tmpTouchableRegions.Count; j++) { Region key = Autotests_RegionListers.tmpTouchableRegions[j]; List <Thing> list = default(List <Thing>); if (!Autotests_RegionListers.expectedListers.TryGetValue(key, out list)) { list = new List <Thing>(); Autotests_RegionListers.expectedListers.Add(key, list); } list.Add(allThings[i]); } } } }
private static void CalculateExpectedListers(Map map) { expectedListers.Clear(); List <Thing> allThings = map.listerThings.AllThings; for (int i = 0; i < allThings.Count; i++) { Thing thing = allThings[i]; if (!ListerThings.EverListable(thing.def, ListerThingsUse.Region)) { continue; } RegionListersUpdater.GetTouchableRegions(thing, map, tmpTouchableRegions); for (int j = 0; j < tmpTouchableRegions.Count; j++) { Region key = tmpTouchableRegions[j]; if (!expectedListers.TryGetValue(key, out var value)) { value = new List <Thing>(); expectedListers.Add(key, value); } value.Add(allThings[i]); } } }
public static void GetTouchableRegions(Thing thing, Map map, List <Region> outRegions, bool allowAdjacentEvenIfCantTouch = false) { outRegions.Clear(); CellRect cellRect = thing.OccupiedRect(); CellRect cellRect2 = cellRect; if (RegionListersUpdater.CanRegisterInAdjacentRegions(thing)) { cellRect2 = cellRect2.ExpandedBy(1); } CellRect.CellRectIterator iterator = cellRect2.GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; if (current.InBounds(map)) { Region validRegionAt_NoRebuild = map.regionGrid.GetValidRegionAt_NoRebuild(current); if (validRegionAt_NoRebuild != null && validRegionAt_NoRebuild.type.Passable() && !outRegions.Contains(validRegionAt_NoRebuild)) { if (cellRect.Contains(current)) { outRegions.Add(validRegionAt_NoRebuild); } else if (allowAdjacentEvenIfCantTouch || ReachabilityImmediate.CanReachImmediate(current, thing, map, PathEndMode.Touch, null)) { outRegions.Add(validRegionAt_NoRebuild); } } } iterator.MoveNext(); } }
private void RegisterThingsInRegionListers() { CellRect cellRect = this.newReg.extentsClose; cellRect = cellRect.ExpandedBy(1); cellRect.ClipInsideMap(this.map); RegionMaker.tmpProcessedThings.Clear(); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; bool flag = false; for (int i = 0; i < 9; i++) { IntVec3 c = current + GenAdj.AdjacentCellsAndInside[i]; if (c.InBounds(this.map) && this.regionGrid.GetValidRegionAt(c) == this.newReg) { flag = true; break; } } if (flag) { RegionListersUpdater.RegisterAllAt(current, this.map, RegionMaker.tmpProcessedThings); } iterator.MoveNext(); } RegionMaker.tmpProcessedThings.Clear(); }
private void RegisterThingsInRegionListers() { CellRect extentsClose = newReg.extentsClose; extentsClose = extentsClose.ExpandedBy(1); extentsClose.ClipInsideMap(map); tmpProcessedThings.Clear(); foreach (IntVec3 item in extentsClose) { bool flag = false; for (int i = 0; i < 9; i++) { IntVec3 c = item + GenAdj.AdjacentCellsAndInside[i]; if (c.InBounds(map) && regionGrid.GetValidRegionAt(c) == newReg) { flag = true; break; } } if (flag) { RegionListersUpdater.RegisterAllAt(item, map, tmpProcessedThings); } } tmpProcessedThings.Clear(); }
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 static void RegisterInRegions(Thing thing, Map map) { ThingDef def = thing.def; if (ListerThings.EverListable(def, ListerThingsUse.Region)) { RegionListersUpdater.GetTouchableRegions(thing, map, RegionListersUpdater.tmpRegions, false); for (int i = 0; i < RegionListersUpdater.tmpRegions.Count; i++) { ListerThings listerThings = RegionListersUpdater.tmpRegions[i].ListerThings; if (!listerThings.Contains(thing)) { listerThings.Add(thing); } } } }
public static void DeregisterInRegions(Thing thing, Map map) { ThingDef def = thing.def; if (!ListerThings.EverListable(def, ListerThingsUse.Region)) { return; } RegionListersUpdater.GetTouchableRegions(thing, map, RegionListersUpdater.tmpRegions, true); for (int i = 0; i < RegionListersUpdater.tmpRegions.Count; i++) { ListerThings listerThings = RegionListersUpdater.tmpRegions[i].ListerThings; if (listerThings.Contains(thing)) { listerThings.Remove(thing); } } RegionListersUpdater.tmpRegions.Clear(); }
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); } } } }
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 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")); }
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")); } }