public static void CheckMoveItemsAside(IntVec3 thingPos, Rot4 thingRot, ThingDef thingDef, Map map) { if (thingDef.surfaceType == SurfaceType.None && thingDef.passability != 0) { CellRect occupiedRect = GenAdj.OccupiedRect(thingPos, thingRot, thingDef.Size); foreach (IntVec3 item in occupiedRect) { foreach (Thing item2 in item.GetThingList(map).ToList()) { if (item2.def.category == ThingCategory.Item) { item2.DeSpawn(); if (!GenPlace.TryPlaceThing(item2, item, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x))) { item2.Destroy(); } } } } } }
public static bool TryDropSpawn(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null) { bool result; if (map == null) { Log.Error("Dropped " + thing + " in a null map.", false); resultingThing = null; result = false; } else if (!dropCell.InBounds(map)) { Log.Error(string.Concat(new object[] { "Dropped ", thing, " out of bounds at ", dropCell }), false); resultingThing = null; result = false; } else if (thing.def.destroyOnDrop) { thing.Destroy(DestroyMode.Vanish); resultingThing = null; result = true; } else { if (thing.def.soundDrop != null) { thing.def.soundDrop.PlayOneShot(new TargetInfo(dropCell, map, false)); } result = GenPlace.TryPlaceThing(thing, dropCell, map, mode, out resultingThing, placedAction, nearPlaceValidator); } return(result); }
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); } }
protected override void ScatterAt(IntVec3 loc, Map map, int stackCount = 1) { if (!TryGetRandomValidRotation(loc, map, out Rot4 rot)) { Log.Warning("Could not find any valid rotation for " + thingDef); } else { if (clearSpaceSize > 0) { foreach (IntVec3 item in GridShapeMaker.IrregularLump(loc, map, clearSpaceSize)) { item.GetEdifice(map)?.Destroy(); } } Thing thing = ThingMaker.MakeThing(thingDef, stuff); if (thingDef.Minifiable) { thing = thing.MakeMinified(); } if (thing.def.category == ThingCategory.Item) { thing.stackCount = stackCount; thing.SetForbidden(value: true, warnOnFail: false); GenPlace.TryPlaceThing(thing, loc, map, ThingPlaceMode.Near, out Thing lastResultingThing); if (nearPlayerStart && lastResultingThing != null && lastResultingThing.def.category == ThingCategory.Item && TutorSystem.TutorialMode) { Find.TutorialState.AddStartingItem(lastResultingThing); } } else { GenSpawn.Spawn(thing, loc, map, rot); } } }
public static void DebugSpawn(ThingDef def, IntVec3 c, int stackCount = -1, bool direct = false) { if (stackCount <= 0) { stackCount = def.stackLimit; } ThingDef stuff = GenStuff.RandomStuffFor(def); Thing thing = ThingMaker.MakeThing(def, stuff); thing.TryGetComp <CompQuality>()?.SetQuality(QualityUtility.GenerateQualityRandomEqualChance(), ArtGenerationContext.Colony); if (thing.def.Minifiable) { thing = thing.MakeMinified(); } thing.stackCount = stackCount; if (direct) { GenPlace.TryPlaceThing(thing, c, Find.CurrentMap, ThingPlaceMode.Direct); } else { GenPlace.TryPlaceThing(thing, c, Find.CurrentMap, ThingPlaceMode.Near); } }
public static bool TryPlaceThing(Thing thing, IntVec3 center, Map map, ThingPlaceMode mode, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null) { Thing thing2; return(GenPlace.TryPlaceThing(thing, center, map, mode, out thing2, placedAction, nearPlaceValidator)); }
public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false) { if (map == null) { Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " in a null map.", false); return(null); } if (!loc.InBounds(map)) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing.ToStringSafe <Thing>(), " out of bounds at ", loc, "." }), false); return(null); } if (newThing.def.randomizeRotationOnSpawn) { rot = Rot4.Random; } CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size); if (!occupiedRect.InBounds(map)) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing.ToStringSafe <Thing>(), " out of bounds at ", loc, " (out of bounds because size is ", newThing.def.Size, ")." }), false); return(null); } if (newThing.Spawned) { Log.Error("Tried to spawn " + newThing + " but it's already spawned.", false); return(newThing); } if (wipeMode == WipeMode.Vanish) { GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); } else if (wipeMode == WipeMode.FullRefund) { GenSpawn.WipeAndRefundExistingThings(loc, rot, newThing.def, map); } if (newThing.def.category == ThingCategory.Item) { foreach (IntVec3 current in occupiedRect) { foreach (Thing current2 in current.GetThingList(map).ToList <Thing>()) { if (current2 != newThing) { if (current2.def.category == ThingCategory.Item) { current2.DeSpawn(DestroyMode.Vanish); if (!GenPlace.TryPlaceThing(current2, current, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x))) { current2.Destroy(DestroyMode.Vanish); } } } } } } newThing.Rotation = rot; newThing.Position = loc; if (newThing.holdingOwner != null) { newThing.holdingOwner.Remove(newThing); } newThing.SpawnSetup(map, respawningAfterLoad); if (newThing.Spawned && newThing.stackCount == 0) { Log.Error("Spawned thing with 0 stackCount: " + newThing, false); newThing.Destroy(DestroyMode.Vanish); return(null); } if (newThing.def.passability == Traversability.Impassable) { foreach (IntVec3 current3 in occupiedRect) { foreach (Thing current4 in current3.GetThingList(map).ToList <Thing>()) { if (current4 != newThing) { Pawn pawn = current4 as Pawn; if (pawn != null) { pawn.pather.TryRecoverFromUnwalkablePosition(false); } } } } } return(newThing); }
public static bool TryPlaceThing(Thing thing, IntVec3 center, Map map, ThingPlaceMode mode, Action <Thing, int> placedAction = null) { Thing thing2 = default(Thing); return(GenPlace.TryPlaceThing(thing, center, map, mode, out thing2, placedAction)); }
public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false) { if (map == null) { Log.Error("Tried to spawn " + newThing.ToStringSafe() + " in a null map."); return(null); } if (!loc.InBounds(map)) { Log.Error("Tried to spawn " + newThing.ToStringSafe() + " out of bounds at " + loc + "."); return(null); } if (newThing.def.randomizeRotationOnSpawn) { rot = Rot4.Random; } CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size); if (!occupiedRect.InBounds(map)) { Log.Error("Tried to spawn " + newThing.ToStringSafe() + " out of bounds at " + loc + " (out of bounds because size is " + newThing.def.Size + ")."); return(null); } if (newThing.Spawned) { Log.Error("Tried to spawn " + newThing + " but it's already spawned."); return(newThing); } switch (wipeMode) { case WipeMode.Vanish: WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); break; case WipeMode.FullRefund: WipeAndRefundExistingThings(loc, rot, newThing.def, map); break; } if (newThing.def.category == ThingCategory.Item) { foreach (IntVec3 item in occupiedRect) { foreach (Thing item2 in item.GetThingList(map).ToList()) { if (item2 != newThing && item2.def.category == ThingCategory.Item) { item2.DeSpawn(); if (!GenPlace.TryPlaceThing(item2, item, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x))) { item2.Destroy(); } } } } } newThing.Rotation = rot; newThing.Position = loc; if (newThing.holdingOwner != null) { newThing.holdingOwner.Remove(newThing); } newThing.SpawnSetup(map, respawningAfterLoad); if (newThing.Spawned && newThing.stackCount == 0) { Log.Error("Spawned thing with 0 stackCount: " + newThing); newThing.Destroy(); return(null); } if (newThing.def.passability == Traversability.Impassable) { foreach (IntVec3 item3 in occupiedRect) { foreach (Thing item4 in item3.GetThingList(map).ToList()) { if (item4 != newThing) { (item4 as Pawn)?.pather.TryRecoverFromUnwalkablePosition(error: false); } } } return(newThing); } return(newThing); }