public static void ThingDestroy(Thing __instance, DestroyMode mode = DestroyMode.Vanish) { if (!Thing.allowDestroyNonDestroyable && !__instance.def.destroyable) { Log.Error("Tried to destroy non-destroyable thing " + __instance); return; } if (__instance.Destroyed) { Log.Error("Tried to destroy already-destroyed thing " + __instance); return; } bool spawned = __instance.Spawned; Map map = __instance.Map; if (__instance.Spawned) { __instance.DeSpawn(mode); } mapIndexOrState(__instance) = -2; if (__instance.def.DiscardOnDestroyed) { __instance.Discard(); } CompExplosive compExplosive = __instance.TryGetComp <CompExplosive>(); if (spawned) { List <Thing> list = (compExplosive != null) ? new List <Thing>() : null; GenLeaving.DoLeavingsFor(__instance, map, mode, list); compExplosive?.AddThingsIgnoredByExplosion(list); } if (__instance.holdingOwner != null) { __instance.holdingOwner.Notify_ContainedItemDestroyed(__instance); } RemoveAllReservationsAndDesignationsOnThis(__instance); if (!(__instance is Pawn)) { __instance.stackCount = 0; } if (mode != DestroyMode.QuestLogic) { QuestUtility.SendQuestTargetSignals(__instance.questTags, "Destroyed", __instance.Named("SUBJECT")); } if (mode == DestroyMode.KillFinalize) { QuestUtility.SendQuestTargetSignals(__instance.questTags, "Killed", __instance.Named("SUBJECT")); } }
public static bool Prefix(TerrainGrid __instance, IntVec3 c, bool doLeavings, Map ___map, ref TerrainDef[] ___underGrid) { try { var ZTracker = ZUtils.ZTracker; if (ZTracker.GetZIndexFor(___map) > 0) { int num = ___map.cellIndices.CellToIndex(c); if (doLeavings) { GenLeaving.DoLeavingsFor(__instance.topGrid[num], c, ___map); } if (___underGrid[num] != null) { __instance.topGrid[num] = ___underGrid[num]; ___underGrid[num] = null; Traverse.Create(__instance).Method("DoTerrainChangedEffects", new object[] { c }).GetValue(); } if (c.GetTerrain(___map) == TerrainDefOf.Sand) { __instance.SetTerrain(c, ZLevelsDefOf.ZL_OutsideTerrain); } Map lowerMap = ZTracker.GetLowerLevel(___map.Tile, ___map); bool firstTime = false; if (lowerMap == null) { return(false); //lowerMap = ZTracker.CreateLowerLevel(___map, c); firstTime = true; } var thingList = c.GetThingList(___map); if (thingList.Where(x => x is Blueprint || x is Frame).Count() == 0) { for (int i = thingList.Count - 1; i >= 0; i--) { if (!(thingList[i] is Mineable || thingList[i] is Blueprint || thingList[i] is Frame)) { //Log.Message(thingList[i] + " going down 1"); ZTracker.SimpleTeleportThing(thingList[i], c, lowerMap, firstTime, 10); } } } return(false); } } catch (Exception ex) { Log.Error("[Z-Levels] DestroyedTerrain patch produced an error. That should not happen and will break things. Send a Hugslib log to the Z-Levels developers. Error message: " + ex, true); } return(true); }
public static void SpawnBuildingAsPossible(Building building, Map map, bool respawningAfterLoad = false) { bool flag = false; foreach (IntVec3 item in building.OccupiedRect()) { List <Thing> thingList = item.GetThingList(map); int num = 0; while (num < thingList.Count) { if (!(thingList[num] is Pawn) || building.def.passability != Traversability.Impassable) { if ((thingList[num].def.category == ThingCategory.Building || thingList[num].def.category == ThingCategory.Item) && GenSpawn.SpawningWipes(building.def, thingList[num].def)) { flag = true; break; } num++; continue; } flag = true; break; } if (flag) { break; } } if (flag) { bool flag2 = false; if (building.def.Minifiable) { MinifiedThing minifiedThing = building.MakeMinified(); if (GenPlace.TryPlaceThing(minifiedThing, building.Position, map, ThingPlaceMode.Near, null)) { flag2 = true; } else { minifiedThing.GetDirectlyHeldThings().Clear(); minifiedThing.Destroy(DestroyMode.Vanish); } } if (!flag2) { GenLeaving.DoLeavingsFor(building, map, DestroyMode.Refund, building.OccupiedRect()); } } else { GenSpawn.Spawn(building, building.Position, map, building.Rotation, respawningAfterLoad); } }
public virtual void Destroy(DestroyMode mode = DestroyMode.Vanish) { if (!allowDestroyNonDestroyable && !def.destroyable) { Log.Error("Tried to destroy non-destroyable thing " + this); return; } if (Destroyed) { Log.Error("Tried to destroy already-destroyed thing " + this); return; } bool spawned = Spawned; Map map = Map; if (Spawned) { DeSpawn(mode); } mapIndexOrState = -2; if (def.DiscardOnDestroyed) { Discard(); } CompExplosive compExplosive = this.TryGetComp <CompExplosive>(); if (spawned) { List <Thing> list = ((compExplosive != null) ? new List <Thing>() : null); GenLeaving.DoLeavingsFor(this, map, mode, list); compExplosive?.AddThingsIgnoredByExplosion(list); } if (holdingOwner != null) { holdingOwner.Notify_ContainedItemDestroyed(this); } RemoveAllReservationsAndDesignationsOnThis(); if (!(this is Pawn)) { stackCount = 0; } if (mode != DestroyMode.QuestLogic) { QuestUtility.SendQuestTargetSignals(questTags, "Destroyed", this.Named("SUBJECT")); } if (mode == DestroyMode.KillFinalize) { QuestUtility.SendQuestTargetSignals(questTags, "Killed", this.Named("SUBJECT")); } }
public static void ChangeStuff(this Thing thing, ThingDef stuff) { thing.SetStuffDirect(stuff); thing.HitPoints = thing.MaxHitPoints; //Deconstruction/construction implicitly repairs if (thing is Frame frame) { GenLeaving.DoLeavingsFor(thing, thing.Map, DestroyMode.Cancel); frame.workDone = 0; } thing.Notify_ColorChanged(); thing.Map.reservationManager.ReleaseAllForTarget(thing); }
public void RemoveTopLayer(IntVec3 c, bool doLeavings = true) { int num = this.map.cellIndices.CellToIndex(c); if (doLeavings) { GenLeaving.DoLeavingsFor(this.topGrid[num], c, this.map); } if (this.underGrid[num] != null) { this.topGrid[num] = this.underGrid[num]; this.underGrid[num] = null; this.DoTerrainChangedEffects(c); } }
public void RemoveTopLayer(IntVec3 c, bool doLeavings = true) { int index = this.map.cellIndices.CellToIndex(c); if (doLeavings) { GenLeaving.DoLeavingsFor(this.topGrid[index], c, this.map); } if (this.underGrid[index] == null) { return; } this.topGrid[index] = this.underGrid[index]; this.underGrid[index] = (TerrainDef)null; this.DoTerrainChangedEffects(c); }
public new void FailConstruction(Pawn worker) { Log.Message($"Failed replace frame! work was {workDone}, Decon is {WorkToDeconstruct(def, oldStuff)}, total is {WorkToBuild}"); workDone = Mathf.Min(workDone, WorkToDeconstruct(def, oldStuff)); if (workDone < WorkToDeconstruct(def, oldStuff)) { return; //Deconstruction doesn't fail } GenLeaving.DoLeavingsFor(this, Map, DestroyMode.FailConstruction); MoteMaker.ThrowText(this.DrawPos, Map, "TextMote_ConstructionFail".Translate()); if (base.Faction == Faction.OfPlayer && this.WorkToReplace > 1400f) { Messages.Message("MessageConstructionFailed".Translate(this.LabelEntityToBuild, worker.LabelShort, worker.Named("WORKER")), new TargetInfo(base.Position, Map), MessageTypeDefOf.NegativeEvent); } }
public virtual void Destroy(DestroyMode mode = DestroyMode.Vanish) { if (!Thing.allowDestroyNonDestroyable && !this.def.destroyable) { Log.Error("Tried to destroy non-destroyable thing " + this); return; } if (this.Destroyed) { Log.Error("Tried to destroy already-destroyed thing " + this); return; } bool spawned = this.Spawned; Map map = this.Map; if (this.Spawned) { this.DeSpawn(); } this.mapIndexOrState = -2; if (this.def.DiscardOnDestroyed) { this.Discard(false); } CompExplosive compExplosive = this.TryGetComp <CompExplosive>(); bool flag = compExplosive != null && compExplosive.destroyedThroughDetonation; if (spawned && !flag) { GenLeaving.DoLeavingsFor(this, map, mode); } if (this.holdingOwner != null) { this.holdingOwner.Notify_ContainedItemDestroyed(this); } this.RemoveAllReservationsAndDesignationsOnThis(); if (!(this is Pawn)) { this.stackCount = 0; } }
public override void Destroy() { base.Destroy(); GenLeaving.DoLeavingsFor(this, destroyMode); if (def.MakeFog) { Find.FogGrid.Notify_FogBlockerDestroyed(Position); } if (def.holdsRoof) { RoofCollapseChecker.Notify_RoofHolderDestroyed(this); } if (def.leaveTerrain != null && Map.Initialized) { foreach (IntVec3 loc in GenAdj.SquaresOccupiedBy(this)) { Find.TerrainGrid.SetTerrain(loc, def.leaveTerrain); } } Find.ListerBuildings.Remove(this); if (TransmitsPower || def.ConnectToPower) { if (TransmitsPower) { PowerNetManager.Notify_TransmitterDespawned(this); } if (def.ConnectToPower) { PowerNetManager.Notify_ConnectorDespawned(this); } Find.MapDrawer.MapChanged(Position, MapChangeType.PowerGrid, true, false); } }
public virtual void Destroy(DestroyMode mode = DestroyMode.Vanish) { if (!allowDestroyNonDestroyable && !def.destroyable) { Log.Error("Tried to destroy non-destroyable thing " + this); } else if (Destroyed) { Log.Error("Tried to destroy already-destroyed thing " + this); } else { bool spawned = Spawned; Map map = Map; if (Spawned) { DeSpawn(mode); } mapIndexOrState = -2; if (def.DiscardOnDestroyed) { Discard(); } bool flag = this.TryGetComp <CompExplosive>()?.destroyedThroughDetonation ?? false; if (spawned && !flag) { GenLeaving.DoLeavingsFor(this, map, mode); } if (holdingOwner != null) { holdingOwner.Notify_ContainedItemDestroyed(this); } RemoveAllReservationsAndDesignationsOnThis(); if (!(this is Pawn)) { stackCount = 0; } } }
public static void Refund(Thing thing, Map map, CellRect avoidThisRect) { bool flag = false; if (thing.def.Minifiable) { MinifiedThing minifiedThing = thing.MakeMinified(); if (GenPlace.TryPlaceThing(minifiedThing, thing.Position, map, ThingPlaceMode.Near, null, (IntVec3 x) => !avoidThisRect.Contains(x))) { flag = true; } else { minifiedThing.GetDirectlyHeldThings().Clear(); minifiedThing.Destroy(DestroyMode.Vanish); } } if (!flag) { GenLeaving.DoLeavingsFor(thing, map, DestroyMode.Refund, thing.OccupiedRect(), (IntVec3 x) => !avoidThisRect.Contains(x)); thing.Destroy(DestroyMode.Vanish); } }
// Token: 0x060000F0 RID: 240 RVA: 0x00008874 File Offset: 0x00006A74 public static void Destroy_Prefix(Thing __instance, DestroyMode mode = DestroyMode.Vanish) { bool flag = !Thing.allowDestroyNonDestroyable && !__instance.def.destroyable; if (!flag) { bool destroyed = __instance.Destroyed; if (!destroyed) { bool spawned = __instance.Spawned; Map map = __instance.Map; bool spawned2 = __instance.Spawned; if (spawned2) { __instance.DeSpawn(mode); } sbyte value = Traverse.Create(typeof(Thing)).Field("mapIndexOrState").GetValue <sbyte>(); bool discardOnDestroyed = __instance.def.DiscardOnDestroyed; if (discardOnDestroyed) { __instance.Discard(false); } CompExplosive compExplosive = __instance.TryGetComp <CompExplosive>(); bool flag2 = compExplosive != null && compExplosive.destroyedThroughDetonation; bool flag3 = spawned && !flag2; if (flag3) { GenLeaving.DoLeavingsFor(__instance, map, mode, null); } bool flag4 = __instance.holdingOwner != null; if (flag4) { __instance.holdingOwner.Notify_ContainedItemDestroyed(__instance); } List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { bool flag5 = __instance.def.category == ThingCategory.Mote; if (flag5) { return; } bool flag6 = __instance.def.category != ThingCategory.Mote; if (flag6) { maps[i].reservationManager.ReleaseAllForTarget(__instance); maps[i].physicalInteractionReservationManager.ReleaseAllForTarget(__instance); IAttackTarget attackTarget = __instance as IAttackTarget; bool flag7 = attackTarget != null; if (flag7) { maps[i].attackTargetReservationManager.ReleaseAllForTarget(attackTarget); } maps[i].designationManager.RemoveAllDesignationsOn(__instance, false); } } bool flag8 = !(__instance is Pawn); if (flag8) { __instance.stackCount = 0; } } } }