public static void Modified_WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, DestroyMode mode, Thing thing) { if (!(thing.TryGetComp <CompMountable>() is CompMountable comp && comp.Active)) { GenSpawn.WipeExistingThings(thingPos, thingRot, thingDef, map, mode); } }
public virtual bool TryReplaceWithSolidThing(Pawn workerPawn, out Thing createdThing, out bool jobEnded) { jobEnded = false; if (GenConstruct.FirstBlockingThing(this, workerPawn) != null) { workerPawn.jobs.EndCurrentJob(JobCondition.Incompletable); jobEnded = true; createdThing = null; return(false); } createdThing = MakeSolidThing(); Map map = base.Map; GenSpawn.WipeExistingThings(base.Position, base.Rotation, createdThing.def, map, DestroyMode.Deconstruct); if (!base.Destroyed) { Destroy(); } if (createdThing.def.CanHaveFaction) { createdThing.SetFactionDirect(workerPawn.Faction); } GenSpawn.Spawn(createdThing, base.Position, map, base.Rotation); return(true); }
public virtual bool TryReplaceWithSolidThing(Pawn workerPawn, out Thing createdThing, out bool jobEnded) { jobEnded = false; bool result; if (GenConstruct.FirstBlockingThing(this, workerPawn) != null) { workerPawn.jobs.EndCurrentJob(JobCondition.Incompletable, true); jobEnded = true; createdThing = null; result = false; } else { createdThing = this.MakeSolidThing(); Map map = base.Map; CellRect cellRect = this.OccupiedRect(); GenSpawn.WipeExistingThings(base.Position, base.Rotation, createdThing.def, map, DestroyMode.Deconstruct); if (!base.Destroyed) { this.Destroy(DestroyMode.Vanish); } createdThing.SetFactionDirect(workerPawn.Faction); GenSpawn.Spawn(createdThing, base.Position, map, base.Rotation, WipeMode.Vanish, false); Blueprint.tmpCrashedShipParts.Clear(); CellRect.CellRectIterator iterator = cellRect.ExpandedBy(3).GetIterator(); while (!iterator.Done()) { if (iterator.Current.InBounds(map)) { List <Thing> thingList = iterator.Current.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { CompSpawnerMechanoidsOnDamaged compSpawnerMechanoidsOnDamaged = thingList[i].TryGetComp <CompSpawnerMechanoidsOnDamaged>(); if (compSpawnerMechanoidsOnDamaged != null) { Blueprint.tmpCrashedShipParts.Add(compSpawnerMechanoidsOnDamaged); } } } iterator.MoveNext(); } Blueprint.tmpCrashedShipParts.RemoveDuplicates <CompSpawnerMechanoidsOnDamaged>(); for (int j = 0; j < Blueprint.tmpCrashedShipParts.Count; j++) { Blueprint.tmpCrashedShipParts[j].Notify_BlueprintReplacedWithSolidThingNearby(workerPawn); } Blueprint.tmpCrashedShipParts.Clear(); result = true; } return(result); }
public static bool Prefix(Designator_Build __instance, ref IntVec3 c) { ThingDef stuffDef = (ThingDef)(typeof(Designator_Build).GetField("stuffDef", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(__instance)); if (stuffDef != null) { if (stuffDef.comps != null) { CompProperties_ReplaceThing compProperties_RepleceThing = stuffDef.comps.Where(x => x is CompProperties_ReplaceThing comp && comp.CompareThing == __instance.PlacingDef).FirstOrDefault() as CompProperties_ReplaceThing; if (compProperties_RepleceThing != null) { Rot4 placingRot = (Rot4)(typeof(Designator_Build).GetField("placingRot", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(__instance)); if (DebugSettings.godMode || __instance.PlacingDef.GetStatValueAbstract(StatDefOf.WorkToBuild, stuffDef) == 0f) { if (__instance.PlacingDef is TerrainDef) { __instance.Map.terrainGrid.SetTerrain(c, (TerrainDef)__instance.PlacingDef); } else { Thing thing = ThingMaker.MakeThing(compProperties_RepleceThing.ReplaceThing, stuffDef); thing.SetFactionDirect(Faction.OfPlayer); GenSpawn.Spawn(thing, c, __instance.Map, placingRot); } } else { BuildableDef buildableDef = compProperties_RepleceThing.ReplaceThing; if (buildableDef.blueprintDef == null) { buildableDef.blueprintDef = ThingDefGenerator_BuildingsCustom.NewBlueprintDef_Thing(compProperties_RepleceThing.ReplaceThing, isInstallBlueprint: false); } if (buildableDef.frameDef == null) { buildableDef.frameDef = ThingDefGenerator_BuildingsCustom.NewFrameDef_Thing(compProperties_RepleceThing.ReplaceThing); } GenSpawn.WipeExistingThings(c, placingRot, buildableDef, __instance.Map, DestroyMode.Deconstruct); GenConstruct.PlaceBlueprintForBuild(buildableDef, c, __instance.Map, placingRot, Faction.OfPlayer, stuffDef); } return(false); } } } return(true); }
public static Thing SpawnModded(Thing newThing, IntVec3 loc, Rot4 rot) { if (!loc.InBounds()) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing, " out of bounds at ", loc, "." })); return(null); } GenSpawn.WipeExistingThings(loc, rot, newThing.def, false); if (newThing.def.randomizeRotationOnSpawn) { newThing.Rotation = Rot4.Random; } else { newThing.Rotation = rot; } newThing.SetPositionDirect(IntVec3.Invalid); newThing.Position = loc; newThing.SpawnSetup(); if (newThing.stackCount == 0) { Log.Error("Spawned thing with 0 stackCount: " + newThing); newThing.Destroy(DestroyMode.Vanish); return(null); } if (newThing.def.GetType() != typeof(Thingdef_AlienRace)) { return(newThing); } else { AlienPawn alienpawn2 = newThing as AlienPawn; alienpawn2.SpawnSetupAlien(alienpawn2); if (alienpawn2.TryGetComp <CompImmuneToAge>() != null) { alienpawn2.health.hediffSet.Clear(); PawnTechHediffsGenerator.GeneratePartsAndImplantsFor(alienpawn2); } Log.Message(alienpawn2.kindDef.race.ToString()); return(alienpawn2); } }
public override void DesignateSingleCell(IntVec3 c) { GenSpawn.WipeExistingThings(c, placingRot, PlacingDef.installBlueprintDef, base.Map, DestroyMode.Deconstruct); MinifiedThing minifiedThing = MiniToInstallOrBuildingToReinstall as MinifiedThing; if (minifiedThing != null) { GenConstruct.PlaceBlueprintForInstall(minifiedThing, c, base.Map, placingRot, Faction.OfPlayer); } else { GenConstruct.PlaceBlueprintForReinstall((Building)MiniToInstallOrBuildingToReinstall, c, base.Map, placingRot, Faction.OfPlayer); } MoteMaker.ThrowMetaPuffs(GenAdj.OccupiedRect(c, placingRot, PlacingDef.Size), base.Map); Find.DesignatorManager.Deselect(); }
public override void DesignateSingleCell(IntVec3 c) { if (TutorSystem.TutorialMode && !TutorSystem.AllowAction(new EventPack(base.TutorTagDesignate, c))) { return; } if (DebugSettings.godMode || entDef.GetStatValueAbstract(StatDefOf.WorkToBuild, stuffDef) == 0f) { if (entDef is TerrainDef) { base.Map.terrainGrid.SetTerrain(c, (TerrainDef)entDef); } else { Thing thing = ThingMaker.MakeThing((ThingDef)entDef, stuffDef); thing.SetFactionDirect(Faction.OfPlayer); GenSpawn.Spawn(thing, c, base.Map, placingRot); } } else { GenSpawn.WipeExistingThings(c, placingRot, entDef.blueprintDef, base.Map, DestroyMode.Deconstruct); GenConstruct.PlaceBlueprintForBuild(entDef, c, base.Map, placingRot, Faction.OfPlayer, stuffDef); } MoteMaker.ThrowMetaPuffs(GenAdj.OccupiedRect(c, placingRot, entDef.Size), base.Map); ThingDef thingDef = entDef as ThingDef; if (thingDef != null && thingDef.IsOrbitalTradeBeacon) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.BuildOrbitalTradeBeacon, KnowledgeAmount.Total); } if (TutorSystem.TutorialMode) { TutorSystem.Notify_Event(new EventPack(base.TutorTagDesignate, c)); } if (entDef.PlaceWorkers != null) { for (int i = 0; i < entDef.PlaceWorkers.Count; i++) { entDef.PlaceWorkers[i].PostPlace(base.Map, entDef, c, placingRot); } } }
public static Thing Spawn(Thing thing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false) { if (thing.Spawned) { Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " but it's already spawned."); return(thing); } if (map == null) { Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " in a null map.", false); return(null); } if (!loc.InBounds(map)) { Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " out of bounds at " + loc + ".", false); return(null); } var occupiedRect = GenAdj.OccupiedRect(loc, rot, thing.def.Size); if (!occupiedRect.InBounds(map)) { Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " out of bounds at " + loc + " (out of bounds because size is " + thing.def.Size + ").", false); return(null); } if (thing.def.randomizeRotationOnSpawn) { rot = Rot4.Random; } switch (wipeMode) { case WipeMode.Vanish: GenSpawn.WipeExistingThings(loc, rot, thing.def, map, DestroyMode.Vanish); break; case WipeMode.FullRefund: GenSpawn.WipeAndRefundExistingThings(loc, rot, thing.def, map); break; } if (thing.holdingOwner != null) { thing.holdingOwner.Remove(thing); } thing.Position = loc; thing.Rotation = rot; thing.SpawnSetup(map, respawningAfterLoad); if ( thing.Spawned && thing.stackCount == 0 ) { Log.Error("Spawned thing with 0 stackCount: " + thing, false); thing.Destroy(DestroyMode.Vanish); return(null); } if (thing.def.passability == Traversability.Impassable) { foreach (var cell in occupiedRect) { foreach (var existingThing in cell.GetThingList(map).ToList <Thing>()) { if (existingThing != thing) { (existingThing as Pawn)?.pather.TryRecoverFromUnwalkablePosition(false); } } } } return(thing); }
public static Thing SpawnModded(Thing newThing, IntVec3 loc, Map map, Rot4 rot) { bool flag = map == null; Thing result; if (flag) { Log.Error("Tried to spawn " + newThing + " in a null map."); result = null; } else { bool flag2 = !loc.InBounds(map); if (flag2) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing, " out of bounds at ", loc, "." })); result = null; } else { bool spawned = newThing.Spawned; if (spawned) { Log.Error("Tried to spawn " + newThing + " but it's already spawned."); result = newThing; } else { GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); bool randomizeRotationOnSpawn = newThing.def.randomizeRotationOnSpawn; if (randomizeRotationOnSpawn) { newThing.Rotation = Rot4.Random; } else { newThing.Rotation = rot; } newThing.Position = loc; ThingUtility.UpdateRegionListers(IntVec3.Invalid, loc, map, newThing); map.thingGrid.Register(newThing); newThing.SpawnSetup(map); bool spawned2 = newThing.Spawned; if (spawned2) { bool flag3 = newThing.stackCount == 0; if (flag3) { Log.Error("Spawned thing with 0 stackCount: " + newThing); newThing.Destroy(DestroyMode.Vanish); result = null; return(result); } } else { ThingUtility.UpdateRegionListers(loc, IntVec3.Invalid, map, newThing); map.thingGrid.Deregister(newThing, true); } bool flag4 = newThing.def.GetType() != typeof(Thingdef_AlienRace); if (flag4) { result = newThing; } else { AlienPawn alienPawn = newThing as AlienPawn; alienPawn.SpawnSetupAlien(); result = alienPawn; } } } } return(result); }
public static bool Spawn(ref Thing __result, 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); __result = (Thing)null; return(false); } if (!loc.InBounds(map)) { Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " out of bounds at " + (object)loc + ".", false); __result = (Thing)null; return(false); } if (null != newThing) { if (null != newThing.def) { 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 <Thing>() + " out of bounds at " + (object)loc + " (out of bounds because size is " + (object)newThing.def.Size + ").", false); __result = (Thing)null; return(false); } if (newThing.Spawned) { Log.Error("Tried to spawn " + (object)newThing + " but it's already spawned.", false); __result = newThing; return(false); } switch (wipeMode) { case WipeMode.Vanish: GenSpawn.WipeExistingThings(loc, rot, (BuildableDef)newThing.def, map, DestroyMode.Vanish); break; case WipeMode.FullRefund: GenSpawn.WipeAndRefundExistingThings(loc, rot, (BuildableDef)newThing.def, map); break; case WipeMode.VanishOrMoveAside: GenSpawn.CheckMoveItemsAside(loc, rot, newThing.def, map); GenSpawn.WipeExistingThings(loc, rot, (BuildableDef)newThing.def, map, DestroyMode.Vanish); break; } if (newThing.def.category == ThingCategory.Item) { foreach (IntVec3 intVec3 in occupiedRect) { foreach (Thing thing in intVec3.GetThingList(map).ToList <Thing>()) { if (thing != newThing && thing.def.category == ThingCategory.Item) { thing.DeSpawn(DestroyMode.Vanish); if (!GenPlace.TryPlaceThing(thing, intVec3, map, ThingPlaceMode.Near, (Action <Thing, int>)null, (Predicate <IntVec3>)(x => !occupiedRect.Contains(x)), new Rot4())) { thing.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: " + (object)newThing, false); newThing.Destroy(DestroyMode.Vanish); __result = (Thing)null; return(false); } if (newThing.def.passability == Traversability.Impassable) { foreach (IntVec3 c in occupiedRect) { foreach (Thing thing in c.GetThingList(map).ToList <Thing>()) { if (thing != newThing && thing is Pawn pawn) { pawn.pather.TryRecoverFromUnwalkablePosition(false); } } } } } } __result = newThing; return(false); }