static void Postfix(ref bool __result, BuildableDef newEntDef, BuildableDef oldEntDef) { ThingDef newDef = newEntDef as ThingDef; ThingDef oldDef = oldEntDef as ThingDef; if (newDef == null || oldDef == null) { return; } if (!newDef.IsBlueprint && oldDef.IsBlueprint && !GenConstruct.CanPlaceBlueprintOver(GenConstruct.BuiltDefOf(oldDef), newDef)) { __result = true; } }
private Job GetDeconstructingJob(Pawn meeseeks, SavedTargetInfo jobTarget, Map map) { BuildableDef buildableDef = jobTarget.BuildableDef; if (buildableDef == null) { return(null); } CellRect cellRect = GenAdj.OccupiedRect(jobTarget.Cell, jobTarget.blueprintRotation, buildableDef.Size); foreach (IntVec3 cell in cellRect) { foreach (Thing thing in cell.GetThingList(map)) { if (!GenConstruct.CanPlaceBlueprintOver(buildableDef, thing.def)) { return(JobMaker.MakeJob(JobDefOf.Deconstruct, thing)); } } } return(null); }
public bool BuildingDesignatorControl() { if (Find.CurrentMap == null || Find.DesignatorManager == null) { return(true); } var Dem = Find.DesignatorManager.SelectedDesignator; if (Dem != null && Dem is Designator_Build) { if (Event.current.type == EventType.MouseDown && Event.current.button == 2) { //Better than UI.mousecell MiddleClickCell = Find.CameraDriver.MapPosition; } //Middle click to select designator if (Event.current.type == EventType.MouseUp && Event.current.button == 2 && MiddleClickCell == Find.CameraDriver.MapPosition) { Thing targetThing = null; IntVec3 UICell = UI.MouseCell(); Map map = Find.CurrentMap; if (map == null) { return(false); } if (!UICell.InBounds(map)) { return(false); } //Search for blueprints if (targetThing == null) { targetThing = UICell.GetFirstThing <Blueprint>(map); } //Search for frames if (targetThing == null) { targetThing = UICell.GetFirstThing <Frame>(map); } //Search for Buildings if (targetThing == null) { targetThing = UICell.GetFirstBuilding(map); } //Can't find things if (targetThing == null) { //SoundDefOf.ClickReject.PlayOneShotOnCamera(); Event.current.Use(); return(false); } //Find designator Designator_Build Desig = null; Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def); if (Desig == null && (targetThing is Blueprint || targetThing is Frame)) { Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def.entityDefToBuild); } if ((targetThing.def.BuildableByPlayer || targetThing.def.entityDefToBuild?.BuildableByPlayer == true) && Desig != null) { //Set stuff if (targetThing.Stuff != null) { Desig.SetStuffDef(targetThing.Stuff); } if ((targetThing as Blueprint_Build)?.stuffToUse != null) { Desig.SetStuffDef((targetThing as Blueprint_Build).stuffToUse); } if ((targetThing as Blueprint_Install)?.Stuff != null) { Desig.SetStuffDef((targetThing as Blueprint_Install).Stuff); } if ((targetThing as Frame)?.Stuff != null) { Desig.SetStuffDef((targetThing as Frame).Stuff); } Find.DesignatorManager.Select(Desig); SoundDefOf.Click.PlayOneShotOnCamera(); } else { //SoundDefOf.ClickReject.PlayOneShotOnCamera(); } Event.current.Use(); return(false); } //Cancel drag //First, absorb Right click event, handle it manually if (Event.current.type == EventType.MouseDown && Event.current.button == 1) { Event.current.Use(); } if (IsCancelDragging) { GenUI.DrawMouseAttachment(CancelIcon, string.Empty, 0); } if (Input.GetMouseButton(1)) { if (IsCancelDragging) { //RenderCancelHighlights(); } else { //Start cancel dragging IsCancelDragging = true; DragStart = UI.MouseCell(); SoundDefOf.Click.PlayOneShotOnCamera(null); } } //Right click up else if (Event.current.type == EventType.MouseUp && Event.current.button == 1) { IsCancelDragging = false; selectedThings.Clear(); Event.current.Use(); if (selectedThings.Any()) { selectedThings.Do(delegate(Thing t) { t.Destroy(DestroyMode.Cancel); }); SoundDefOf.Designate_Cancel.PlayOneShotOnCamera(); } else { SoundDefOf.CancelMode.PlayOneShotOnCamera(null); Find.DesignatorManager.Deselect(); return(false); } } //While cancel dragging, left click to abort if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && IsCancelDragging) { selectedThings.Clear(); IsCancelDragging = false; SoundDefOf.CancelMode.PlayOneShotOnCamera(null); Find.DesignatorManager.Deselect(); Event.current.Use(); return(false); } //Drag to place blueprints var BuildDesignator = (Designator_Build)Dem; if (BuildDesignator.DraggableDimensions != 0) { return(true); } if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { PreviousCell = IntVec3.Invalid; ClickedFlag = true; Event.current.Use(); } if (Event.current.type == EventType.MouseUp && Event.current.button == 0) { PreviousCell = IntVec3.Invalid; ClickedFlag = false; Event.current.Use(); } if (Input.GetMouseButton(0) && !Mouse.IsInputBlockedNow && PreviousCell != UI.MouseCell() && ClickedFlag) { var acceptanceReport = BuildDesignator.CanDesignateCell(UI.MouseCell()); if (DebugSettings.godMode && acceptanceReport.Accepted) //Handle god mode { Traverse t = Traverse.Create(BuildDesignator); BuildableDef entDef = t.Field("entDef").GetValue <BuildableDef>(); Rot4 rot = t.Field("placingRot").GetValue <Rot4>(); CellRect cellRect = GenAdj.OccupiedRect(UI.MouseCell(), rot, entDef.Size); foreach (IntVec3 c in cellRect) { var thinglist = c.GetThingList(Find.CurrentMap); for (int i = 0; i < thinglist.Count; i++) { var thing3 = thinglist[i]; if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def)) { acceptanceReport = new AcceptanceReport("SpaceAlreadyOccupied_DevFail"); } } } } if (acceptanceReport.Accepted) { BuildDesignator.DesignateSingleCell(UI.MouseCell()); BuildDesignator.Finalize(true); } else { //If this is first cell clicked if (PreviousCell == IntVec3.Invalid) { Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.SilentInput, false); BuildDesignator.Finalize(false); } } PreviousCell = UI.MouseCell(); //Event.current.Use(); } return(false); } else //This is not Building designator { IsCancelDragging = false; return(true); } }
public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null) { CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; if (!current.InBounds(map)) { return(new AcceptanceReport("OutOfBounds".Translate())); } if (current.InNoBuildEdgeArea(map) && !DebugSettings.godMode && entDef != ThingDefOf.DeepDrill) { return("TooCloseToMapEdge".Translate()); } iterator.MoveNext(); } if (center.Fogged(map)) { return("CannotPlaceInUndiscovered".Translate()); } List <Thing> thingList = center.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing != thingToIgnore) { if (thing.Position == center && thing.Rotation == rot) { if (thing.def == entDef) { return(new AcceptanceReport("IdenticalThingExists".Translate())); } if (thing.def.entityDefToBuild == entDef) { if (thing is Blueprint) { return(new AcceptanceReport("IdenticalBlueprintExists".Translate())); } return(new AcceptanceReport("IdenticalThingExists".Translate())); } } } } ThingDef thingDef = entDef as ThingDef; if (thingDef != null && thingDef.hasInteractionCell) { IntVec3 c = Thing.InteractionCellWhenAt(thingDef, center, rot, map); if (!c.InBounds(map)) { return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate())); } List <Thing> list = map.thingGrid.ThingsListAtFast(c); for (int j = 0; j < list.Count; j++) { if (list[j] != thingToIgnore) { if (list[j].def.passability == Traversability.Impassable) { return(new AcceptanceReport("InteractionSpotBlocked".Translate(list[j].LabelNoCount).CapitalizeFirst())); } Blueprint blueprint = list[j] as Blueprint; if (blueprint != null && blueprint.def.entityDefToBuild.passability == Traversability.Impassable) { return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(blueprint.LabelNoCount).CapitalizeFirst())); } } } } if (entDef.passability != Traversability.Standable) { foreach (IntVec3 current2 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size)) { if (current2.InBounds(map)) { thingList = current2.GetThingList(map); for (int k = 0; k < thingList.Count; k++) { Thing thing2 = thingList[k]; if (thing2 != thingToIgnore) { Blueprint blueprint2 = thing2 as Blueprint; ThingDef thingDef3; if (blueprint2 != null) { ThingDef thingDef2 = blueprint2.def.entityDefToBuild as ThingDef; if (thingDef2 == null) { goto IL_37E; } thingDef3 = thingDef2; } else { thingDef3 = thing2.def; } if (thingDef3.hasInteractionCell && cellRect.Contains(Thing.InteractionCellWhenAt(thingDef3, thing2.Position, thing2.Rotation, thing2.Map))) { return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(entDef.label, thingDef3.label).CapitalizeFirst())); } } IL_37E :; } } } } TerrainDef terrainDef = entDef as TerrainDef; if (terrainDef != null) { if (map.terrainGrid.TerrainAt(center) == terrainDef) { return(new AcceptanceReport("TerrainIsAlready".Translate(terrainDef.label))); } if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null) { return(new AcceptanceReport("BeingSmoothed".Translate())); } } if (!GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore)) { return(new AcceptanceReport("TerrainCannotSupport".Translate())); } if (!godMode) { CellRect.CellRectIterator iterator2 = cellRect.GetIterator(); while (!iterator2.Done()) { thingList = iterator2.Current.GetThingList(map); for (int l = 0; l < thingList.Count; l++) { Thing thing3 = thingList[l]; if (thing3 != thingToIgnore) { if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def)) { return(new AcceptanceReport("SpaceAlreadyOccupied".Translate())); } } } iterator2.MoveNext(); } } if (entDef.PlaceWorkers != null) { for (int m = 0; m < entDef.PlaceWorkers.Count; m++) { AcceptanceReport result = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, thingToIgnore); if (!result.Accepted) { return(result); } } } return(AcceptanceReport.WasAccepted); }
public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, ThingDef stuff, bool godMode = false, Thing thingToIgnore = null) { CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { IntVec3 current = iterator.Current; if (!current.InBounds(map)) { return(new AcceptanceReport("OutOfBounds".Translate())); } if (current.InNoBuildEdgeArea(map) && !DebugSettings.godMode) { return("TooCloseToMapEdge".Translate()); } iterator.MoveNext(); } if (center.Fogged(map)) { return("CannotPlaceInUndiscovered".Translate()); } List <Thing> thingList = center.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing != thingToIgnore) { if (thing.Position == center && thing.Rotation == rot) { if (thing.def == entDef) { //Start my code, this code allows blueprint to be placed, so canPlaceOverWall can do it's thing. if (((walls.Contains(thing.def.defName) && walls.Contains(entDef.defName)) || (doors.Contains(thing.def.defName) && doors.Contains(entDef.defName))) && thing.Stuff != stuff) { return(AcceptanceReport.WasAccepted); } //End my code return(new AcceptanceReport("IdenticalThingExists".Translate())); } if (thing.def.entityDefToBuild == entDef) { if (thing is Blueprint) { return(new AcceptanceReport("IdenticalBlueprintExists".Translate())); } return(new AcceptanceReport("IdenticalThingExists".Translate())); } } } } ThingDef thingDef = entDef as ThingDef; if (thingDef != null && thingDef.hasInteractionCell) { IntVec3 c = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map); if (!c.InBounds(map)) { return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate())); } List <Thing> list = map.thingGrid.ThingsListAtFast(c); for (int j = 0; j < list.Count; j++) { if (list[j] != thingToIgnore) { if (list[j].def.passability == Traversability.Impassable) { return(new AcceptanceReport("InteractionSpotBlocked".Translate(new object[] { list[j].LabelNoCount }).CapitalizeFirst())); } Blueprint blueprint = list[j] as Blueprint; if (blueprint != null && blueprint.def.entityDefToBuild.passability == Traversability.Impassable) { return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(new object[] { blueprint.LabelNoCount }).CapitalizeFirst())); } } } } if (entDef.passability != Traversability.Standable) { foreach (IntVec3 current2 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size)) { if (current2.InBounds(map)) { thingList = current2.GetThingList(map); for (int k = 0; k < thingList.Count; k++) { Thing thing2 = thingList[k]; if (thing2 != thingToIgnore) { Blueprint blueprint2 = thing2 as Blueprint; ThingDef thingDef3; if (blueprint2 != null) { ThingDef thingDef2 = blueprint2.def.entityDefToBuild as ThingDef; if (thingDef2 == null) { goto IL_37E; } thingDef3 = thingDef2; } else { thingDef3 = thing2.def; } if (thingDef3.hasInteractionCell && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing2.Position, thing2.Rotation, thing2.Map))) { return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(new object[] { entDef.label, thingDef3.label }).CapitalizeFirst())); } } IL_37E :; } } } } TerrainDef terrainDef = entDef as TerrainDef; if (terrainDef != null) { if (map.terrainGrid.TerrainAt(center) == terrainDef) { return(new AcceptanceReport("TerrainIsAlready".Translate(new object[] { terrainDef.label }))); } if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null) { return(new AcceptanceReport("BeingSmoothed".Translate())); } } if (!GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore)) { return(new AcceptanceReport("TerrainCannotSupport".Translate())); } if (!godMode) { CellRect.CellRectIterator iterator2 = cellRect.GetIterator(); while (!iterator2.Done()) { thingList = iterator2.Current.GetThingList(map); for (int l = 0; l < thingList.Count; l++) { Thing thing3 = thingList[l]; if (thing3 != thingToIgnore) { if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def)) { //Start my code, entDef is new, thing3 is old //Allows for doors to replace each other only if different stuff or door <--> autodoor if (thing3?.def?.defName != null) { if ((doors.Contains(entDef.defName) && doors.Contains(thing3.def.defName)) && //New and old are both doors (thing3.Stuff != stuff || !entDef.defName.Equals(thing3.def.defName))) //Not the same stuff or not same thing { return(AcceptanceReport.WasAccepted); } //Allow placing over mineable if (thing3 is Mineable && (doors.Contains(entDef.defName) || walls.Contains(entDef.defName))) { return(AcceptanceReport.WasAccepted); } //Allow walls and doors to be placed over walls if ((walls.Contains(entDef.defName) || doors.Contains(entDef.defName)) && walls.Contains(thing3.def.defName)) { return(AcceptanceReport.WasAccepted); } //Allow replacing invisible power lines from PowerSwitch by Haplo if (conduits.Contains(entDef.defName) && conduits.Contains(thing3.def.defName)) { return(AcceptanceReport.WasAccepted); } } //End my code return(new AcceptanceReport("SpaceAlreadyOccupied".Translate())); } } } iterator2.MoveNext(); } } if (entDef.PlaceWorkers != null) { for (int m = 0; m < entDef.PlaceWorkers.Count; m++) { AcceptanceReport result = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore); if (!result.Accepted) { return(result); } } } return(AcceptanceReport.WasAccepted); }