private void CheckAutoRebuild(Map map) { if (this.autoRearm && this.CanSetAutoRearm && map != null && GenConstruct.CanPlaceBlueprintAt(this.def, base.Position, base.Rotation, map, false, null, null, base.Stuff).Accepted) { //GenConstruct.PlaceBlueprintForBuild(this.def, base.Position, map, base.Rotation, Faction.OfPlayer, base.Stuff); GenConstruct.PlaceBlueprintForBuild_NewTemp(this.def, base.Position, map, base.Rotation, Faction.OfPlayer, base.Stuff); } }
public static void DoReplace(Thing thing, ThingDef stuffDef) { var pos = thing.Position; var rot = thing.Rotation; var map = thing.Map; //In case you're replacing with a stuff that needs a higher affordance that bridges can handle. PlaceBridges.EnsureBridge.PlaceBridgeIfNeeded(thing.def, pos, map, rot, Faction.OfPlayer, stuffDef); //CanReplaceStuffFor has verified this is different stuff //so the task here is: place new replacements, kill old replacement //Too finicky to change stuff of current replacement - canceling jobs and such. if (thing is Blueprint_Build oldBP) { oldBP.Destroy(DestroyMode.Cancel); //Destroy before Place beacause GenSpawn.Spawn will wipe it GenConstruct.PlaceBlueprintForBuild_NewTemp(oldBP.def.entityDefToBuild, pos, map, rot, Faction.OfPlayer, stuffDef); } else if (thing is ReplaceFrame oldRF) { if (DebugSettings.godMode) { ReplaceFrame.FinalizeReplace(thing, stuffDef); } if (oldRF.oldStuff != stuffDef) { //replacement frame should keep deconstruction work mount ReplaceFrame newFrame = GenReplace.PlaceReplaceFrame(oldRF.oldThing, stuffDef); newFrame.workDone = Mathf.Min(oldRF.workDone, oldRF.WorkToDeconstruct); } //else, if same stuff as old stuff, we just chose replace with original stuff, so we're already done - just destroy the frame. //upgrade frames/blueprints oldRF.Destroy(DestroyMode.Cancel); } else if (thing is Frame oldFrame) { oldFrame.Destroy(DestroyMode.Cancel); GenConstruct.PlaceBlueprintForBuild_NewTemp(oldFrame.def.entityDefToBuild, pos, map, rot, Faction.OfPlayer, stuffDef); } else if (DebugSettings.godMode) { ReplaceFrame.FinalizeReplace(thing, stuffDef); } else { //Oh of course the standard case is, just place a replace frame! I almost forgot about that. GenReplace.PlaceReplaceFrame(thing, stuffDef); } FleckMaker.ThrowMetaPuffs(GenAdj.OccupiedRect(pos, rot, thing.def.size), map); }
//A lot like CheckAutoRebuildOnDestroyed public static void CheckAutoRebuildOnLaunch(Thing thing, Map map, BuildableDef buildingDef) { if (!Mod.settings.autoRebuildTransportPod) { return; } if (Find.PlaySettings.autoRebuild && thing.Faction == Faction.OfPlayer && buildingDef.blueprintDef != null && buildingDef.IsResearchFinished && map.areaManager.Home[thing.Position] && GenConstruct.CanPlaceBlueprintAt(buildingDef, thing.Position, thing.Rotation, map, false, null).Accepted) { GenConstruct.PlaceBlueprintForBuild_NewTemp(buildingDef, thing.Position, map, thing.Rotation, Faction.OfPlayer, thing.Stuff); } }
public static void PlaceBridgeIfNeeded(BuildableDef sourceDef, IntVec3 pos, Map map, Rot4 rotation, Faction faction, ThingDef stuff) { TerrainDef bridgeDef = PlaceBridges.GetNeededBridge(sourceDef, pos, map, stuff); if (bridgeDef == null) { return; } if (pos.GetThingList(map).Any(t => t.def.entityDefToBuild == bridgeDef)) { return; //Already building! } Log.Message($"Replace Stuff placing {bridgeDef} for {sourceDef}({sourceDef.GetTerrainAffordanceNeed(stuff)}) on {map.terrainGrid.TerrainAt(pos)}"); GenConstruct.PlaceBlueprintForBuild_NewTemp(bridgeDef, pos, map, rotation, faction, null); //Are there bridge precepts/styles?... }