public override void SpawnSetup(Map map, bool respawningAfterLoad) { if (def.IsEdifice()) { map.edificeGrid.Register(this); if (def.Fillage == FillCategory.Full) { map.terrainGrid.Drawer.SetDirty(); } if (def.AffectsFertility) { map.fertilityGrid.Drawer.SetDirty(); } } base.SpawnSetup(map, respawningAfterLoad); base.Map.listerBuildings.Add(this); if (def.coversFloor) { base.Map.mapDrawer.MapMeshDirty(base.Position, MapMeshFlag.Terrain, regenAdjacentCells: true, regenAdjacentSections: false); } CellRect cellRect = this.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 intVec = new IntVec3(j, 0, i); base.Map.mapDrawer.MapMeshDirty(intVec, MapMeshFlag.Buildings); base.Map.glowGrid.MarkGlowGridDirty(intVec); if (!SnowGrid.CanCoexistWithSnow(def)) { base.Map.snowGrid.SetDepth(intVec, 0f); } } } if (base.Faction == Faction.OfPlayer && def.building != null && def.building.spawnedConceptLearnOpportunity != null) { LessonAutoActivator.TeachOpportunity(def.building.spawnedConceptLearnOpportunity, OpportunityType.GoodToKnow); } AutoHomeAreaMaker.Notify_BuildingSpawned(this); if (def.building != null && !def.building.soundAmbient.NullOrUndefined()) { LongEventHandler.ExecuteWhenFinished(delegate { SoundInfo info = SoundInfo.InMap(this); sustainerAmbient = def.building.soundAmbient.TrySpawnSustainer(info); }); } base.Map.listerBuildingsRepairable.Notify_BuildingSpawned(this); base.Map.listerArtificialBuildingsForMeditation.Notify_BuildingSpawned(this); base.Map.listerBuldingOfDefInProximity.Notify_BuildingSpawned(this); if (!this.CanBeSeenOver()) { base.Map.exitMapGrid.Notify_LOSBlockerSpawned(); } SmoothSurfaceDesignatorUtility.Notify_BuildingSpawned(this); map.avoidGrid.Notify_BuildingSpawned(this); }
public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) { Map map = base.Map; base.DeSpawn(mode); if (this.def.IsEdifice()) { map.edificeGrid.DeRegister(this); } if (mode != DestroyMode.WillReplace) { if (this.def.MakeFog) { map.fogGrid.Notify_FogBlockerRemoved(base.Position); } if (this.def.holdsRoof) { RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map); } if (this.def.IsSmoothable) { SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map); } } if (this.sustainerAmbient != null) { this.sustainerAmbient.End(); } CellRect cellRect = this.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 loc = new IntVec3(j, 0, i); MapMeshFlag mapMeshFlag = MapMeshFlag.Buildings; if (this.def.coversFloor) { mapMeshFlag |= MapMeshFlag.Terrain; } if (this.def.Fillage == FillCategory.Full) { mapMeshFlag |= MapMeshFlag.Roofs; mapMeshFlag |= MapMeshFlag.Snow; } map.mapDrawer.MapMeshDirty(loc, mapMeshFlag); map.glowGrid.MarkGlowGridDirty(loc); } } map.listerBuildings.Remove(this); map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this); if (this.def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && this.canChangeTerrainOnDestroyed) { CellRect.CellRectIterator iterator = this.OccupiedRect().GetIterator(); while (!iterator.Done()) { map.terrainGrid.SetTerrain(iterator.Current, this.def.building.leaveTerrain); iterator.MoveNext(); } } map.designationManager.Notify_BuildingDespawned(this); if (!this.CanBeSeenOver()) { map.exitMapGrid.Notify_LOSBlockerDespawned(); } if (this.def.building.hasFuelingPort) { IntVec3 fuelingPortCell = FuelingPortUtility.GetFuelingPortCell(base.Position, base.Rotation); CompLaunchable compLaunchable = FuelingPortUtility.LaunchableAt(fuelingPortCell, map); if (compLaunchable != null) { compLaunchable.Notify_FuelingPortSourceDeSpawned(); } } if (this.def.building.ai_combatDangerous) { AvoidGridMaker.Notify_CombatDangerousBuildingDespawned(this, map); } }
public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) { Map map = base.Map; base.DeSpawn(mode); if (def.IsEdifice()) { map.edificeGrid.DeRegister(this); if (def.Fillage == FillCategory.Full) { map.terrainGrid.Drawer.SetDirty(); } if (def.AffectsFertility) { map.fertilityGrid.Drawer.SetDirty(); } } if (mode != DestroyMode.WillReplace) { if (def.MakeFog) { map.fogGrid.Notify_FogBlockerRemoved(base.Position); } if (def.holdsRoof) { RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map); } if (def.IsSmoothable) { SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map); } } if (sustainerAmbient != null) { sustainerAmbient.End(); } CellRect cellRect = this.OccupiedRect(); for (int i = cellRect.minZ; i <= cellRect.maxZ; i++) { for (int j = cellRect.minX; j <= cellRect.maxX; j++) { IntVec3 loc = new IntVec3(j, 0, i); MapMeshFlag mapMeshFlag = MapMeshFlag.Buildings; if (def.coversFloor) { mapMeshFlag |= MapMeshFlag.Terrain; } if (def.Fillage == FillCategory.Full) { mapMeshFlag |= MapMeshFlag.Roofs; mapMeshFlag |= MapMeshFlag.Snow; } map.mapDrawer.MapMeshDirty(loc, mapMeshFlag); map.glowGrid.MarkGlowGridDirty(loc); } } map.listerBuildings.Remove(this); map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this); map.listerArtificialBuildingsForMeditation.Notify_BuildingDeSpawned(this); if (def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && canChangeTerrainOnDestroyed) { foreach (IntVec3 item in this.OccupiedRect()) { map.terrainGrid.SetTerrain(item, def.building.leaveTerrain); } } map.designationManager.Notify_BuildingDespawned(this); if (!this.CanBeSeenOver()) { map.exitMapGrid.Notify_LOSBlockerDespawned(); } if (def.building.hasFuelingPort) { FuelingPortUtility.LaunchableAt(FuelingPortUtility.GetFuelingPortCell(base.Position, base.Rotation), map)?.Notify_FuelingPortSourceDeSpawned(); } map.avoidGrid.Notify_BuildingDespawned(this); }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { //Before base.SpawnSetup() so when regions are rebuilt this building can be accessed via edificeGrid if (def.IsEdifice()) { map.edificeGrid.Register(this); } base.SpawnSetup(map, respawningAfterLoad); Map.listerBuildings.Add(this); //Remake terrain meshes with new underwall under me if (def.coversFloor) { Map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Terrain, true, false); } var occRect = this.OccupiedRect(); for (int z = occRect.minZ; z <= occRect.maxZ; z++) { for (int x = occRect.minX; x <= occRect.maxX; x++) { var c = new IntVec3(x, 0, z); Map.mapDrawer.MapMeshDirty(c, MapMeshFlag.Buildings); Map.glowGrid.MarkGlowGridDirty(c); if (!SnowGrid.CanCoexistWithSnow(def)) { Map.snowGrid.SetDepth(c, 0); } } } if (Faction == Faction.OfPlayer) { if (def.building != null && def.building.spawnedConceptLearnOpportunity != null) { LessonAutoActivator.TeachOpportunity(def.building.spawnedConceptLearnOpportunity, OpportunityType.GoodToKnow); } } AutoHomeAreaMaker.Notify_BuildingSpawned(this); if (def.building != null && !def.building.soundAmbient.NullOrUndefined()) { LongEventHandler.ExecuteWhenFinished(() => { SoundInfo info = SoundInfo.InMap(this, MaintenanceType.None); sustainerAmbient = SoundStarter.TrySpawnSustainer(def.building.soundAmbient, info); }); } Map.listerBuildingsRepairable.Notify_BuildingSpawned(this); if (!this.CanBeSeenOver()) { Map.exitMapGrid.Notify_LOSBlockerSpawned(); } SmoothSurfaceDesignatorUtility.Notify_BuildingSpawned(this); //Must go after adding to buildings list map.avoidGrid.Notify_BuildingSpawned(this); }
public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) { var map = Map; // before DeSpawn! base.DeSpawn(mode); if (def.IsEdifice()) { map.edificeGrid.DeRegister(this); } if (mode != DestroyMode.WillReplace) { if (def.MakeFog) { map.fogGrid.Notify_FogBlockerRemoved(Position); } if (def.holdsRoof) { RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map); } if (def.IsSmoothable) { SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map); } } if (sustainerAmbient != null) { sustainerAmbient.End(); } CellRect occRect = GenAdj.OccupiedRect(this); for (int z = occRect.minZ; z <= occRect.maxZ; z++) { for (int x = occRect.minX; x <= occRect.maxX; x++) { IntVec3 c = new IntVec3(x, 0, z); MapMeshFlag changeType = MapMeshFlag.Buildings; if (def.coversFloor) { changeType |= MapMeshFlag.Terrain; } if (def.Fillage == FillCategory.Full) { changeType |= MapMeshFlag.Roofs; changeType |= MapMeshFlag.Snow; } map.mapDrawer.MapMeshDirty(c, changeType); map.glowGrid.MarkGlowGridDirty(c); } } map.listerBuildings.Remove(this); map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this); if (def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && canChangeTerrainOnDestroyed) { for (var cri = GenAdj.OccupiedRect(this).GetIterator(); !cri.Done(); cri.MoveNext()) { map.terrainGrid.SetTerrain(cri.Current, def.building.leaveTerrain); } } //Mining, planning, etc map.designationManager.Notify_BuildingDespawned(this); if (!this.CanBeSeenOver()) { map.exitMapGrid.Notify_LOSBlockerDespawned(); } if (def.building.hasFuelingPort) { var fuelingPortCell = FuelingPortUtility.GetFuelingPortCell(Position, Rotation); var launchable = FuelingPortUtility.LaunchableAt(fuelingPortCell, map); if (launchable != null) { launchable.Notify_FuelingPortSourceDeSpawned(); } } //Must go after removing from buildings list map.avoidGrid.Notify_BuildingDespawned(this); }