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); } }
private static Action DestroySafely(MinifiedThing __instance) { return(() => { try { Log.Message("Removing invalid minified thing of type " + __instance.InnerThing.def.LabelCap + "."); __instance.Destroy(); } catch (NullReferenceException) { // We're expecting one from the InstallBlueprintUtility - can't be avoided } }); }
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); } }