public static bool CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null, ThingDef stuffDef = null) { TerrainAffordanceDef terrainAffordanceNeed = entDef.GetTerrainAffordanceNeed(stuffDef); if (terrainAffordanceNeed != null) { CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size); cellRect.ClipInsideMap(map); foreach (IntVec3 item in cellRect) { if (!map.terrainGrid.TerrainAt(item).affordances.Contains(terrainAffordanceNeed)) { return(false); } List <Thing> thingList = item.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i] != thingToIgnore) { TerrainDef terrainDef = thingList[i].def.entityDefToBuild as TerrainDef; if (terrainDef != null && !terrainDef.affordances.Contains(terrainAffordanceNeed)) { return(false); } } } } } return(true); }
public static bool NeedsBridge(BuildableDef def, IntVec3 pos, Map map, ThingDef stuff) { TerrainAffordanceDef needed = def.GetTerrainAffordanceNeed(stuff); return(pos.InBounds(map) && !pos.SupportsStructureType(map, needed) && pos.SupportsStructureType(map, TerrainDefOf.Bridge.terrainAffordanceNeeded) && TerrainDefOf.Bridge.affordances.Contains(needed)); }
public static TerrainDef GetNeededBridge(BuildableDef def, IntVec3 pos, Map map, ThingDef stuff) { if (!pos.InBounds(map)) { return(null); } TerrainAffordanceDef needed = def.GetTerrainAffordanceNeed(stuff); return(BridgelikeTerrain.FindBridgeFor(map.terrainGrid.TerrainAt(pos), needed, map)); }
//public static Blueprint_Build PlaceBlueprintForBuild(BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff) public static void Prefix(BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff) { if (faction != Faction.OfPlayer || sourceDef == TerrainDefOf.Bridge) { return; } TerrainAffordanceDef affNeeded = sourceDef.GetTerrainAffordanceNeed(stuff); foreach (IntVec3 pos in GenAdj.CellsOccupiedBy(center, rotation, sourceDef.Size)) { EnsureBridge.PlaceBridgeIfNeeded(sourceDef, pos, map, rotation, faction, stuff); } }
// Token: 0x060000DE RID: 222 RVA: 0x00006F5C File Offset: 0x0000515C public static bool CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null, ThingDef stuffDef = null) { bool flag = entDef is TerrainDef && !c.GetTerrain(map).changeable; bool result; if (flag) { result = false; } else { TerrainAffordanceDef terrainAffordanceNeed = entDef.GetTerrainAffordanceNeed(stuffDef); bool flag2 = terrainAffordanceNeed != null; if (flag2) { CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size); cellRect.ClipInsideMap(map); foreach (IntVec3 c2 in cellRect) { bool flag3 = !map.terrainGrid.TerrainAt(c2).affordances.Contains(terrainAffordanceNeed); if (flag3) { return(false); } List <Thing> thingList = c2.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { bool flag4 = thingList[i] != thingToIgnore; if (flag4) { TerrainDef terrainDef = thingList[i].def.entityDefToBuild as TerrainDef; bool flag5 = terrainDef != null && !terrainDef.affordances.Contains(terrainAffordanceNeed); if (flag5) { return(false); } } } } result = true; } else { result = true; } } return(result); }
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?... }
//public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null) public static void Postfix(ref AcceptanceReport __result, BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode, Thing thingToIgnore) { if (__result.Reason != "IdenticalThingExists".Translate() && __result.Reason != "IdenticalBlueprintExists".Translate()) { return; } if (!(entDef is ThingDef)) { return; } if (!entDef.MadeFromStuff) { return; } ThingDef newStuff = DesignatorContext.stuffDef; //It would not be so easy to transpile this part //it doesn't simply change __result to true when a replace frame can be placed, //it also checks if the replace frame is already there and overrides that with false bool makeItTrue = false; foreach (Thing thing in center.GetThingList(map)) { if (thing == thingToIgnore) { continue; } if (thing.Position == center && (thing.Rotation == rot || PlacingRotationDoesntMatter(entDef)) && GenConstruct.BuiltDefOf(thing.def) == entDef) { //Same thing or Building the same thing ThingDef oldStuff = thing is Blueprint bp?bp.EntityToBuildStuff() : thing.Stuff; if (thing is ReplaceFrame rf && oldStuff == newStuff) { //Identical things already exists return; } if (newStuff != oldStuff) { if (GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thing, newStuff)) { makeItTrue = true; } else { __result = "TerrainCannotSupport_TerrainAffordanceFromStuff".Translate(entDef, entDef.GetTerrainAffordanceNeed(newStuff), newStuff).CapitalizeFirst(); } } } else if ((thing is Blueprint || thing is Frame) && thing.def.entityDefToBuild is ThingDef) { //Upgrade blueprint/frame exists __result = "TD.ReplacementAlreadyInProgess".Translate(); return; } } if (makeItTrue) //Only if We found a replaceable, identical thing, and no other blueprints/frames for other defs { __result = true; } }
public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null, Thing thing = null, ThingDef stuffDef = null) { CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size); if (stuffDef == null && thing != null) { stuffDef = thing.Stuff; } foreach (IntVec3 item in cellRect) { if (!item.InBounds(map)) { return(new AcceptanceReport("OutOfBounds".Translate())); } if (item.InNoBuildEdgeArea(map) && !godMode) { return("TooCloseToMapEdge".Translate()); } } if (center.Fogged(map)) { return("CannotPlaceInUndiscovered".Translate()); } List <Thing> thingList = center.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing2 = thingList[i]; if (thing2 == thingToIgnore || !(thing2.Position == center) || !(thing2.Rotation == rot)) { continue; } if (thing2.def == entDef) { return(new AcceptanceReport("IdenticalThingExists".Translate())); } if (thing2.def.entityDefToBuild == entDef) { if (thing2 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 || list[j].def == thingDef) { return(new AcceptanceReport("InteractionSpotBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst())); } BuildableDef entityDefToBuild = list[j].def.entityDefToBuild; if (entityDefToBuild != null && (entityDefToBuild.passability == Traversability.Impassable || entityDefToBuild == thingDef)) { return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst())); } } } } foreach (IntVec3 item2 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size)) { if (item2.InBounds(map)) { thingList = item2.GetThingList(map); for (int k = 0; k < thingList.Count; k++) { Thing thing3 = thingList[k]; if (thing3 != thingToIgnore) { ThingDef thingDef2 = null; Blueprint blueprint = thing3 as Blueprint; if (blueprint != null) { ThingDef thingDef3 = blueprint.def.entityDefToBuild as ThingDef; if (thingDef3 == null) { continue; } thingDef2 = thingDef3; } else { thingDef2 = thing3.def; } if (thingDef2.hasInteractionCell && (entDef.passability == Traversability.Impassable || entDef == thingDef2) && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef2, thing3.Position, thing3.Rotation, thing3.Map))) { return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(entDef.label, thingDef2.label).CapitalizeFirst())); } } } } } 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("SpaceBeingSmoothed".Translate())); } } if (!CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore, stuffDef)) { if (entDef.GetTerrainAffordanceNeed(stuffDef) != null) { if (entDef.useStuffTerrainAffordance && stuffDef != null) { return(new AcceptanceReport("TerrainCannotSupport_TerrainAffordanceFromStuff".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef), stuffDef).CapitalizeFirst())); } return(new AcceptanceReport("TerrainCannotSupport_TerrainAffordance".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef)).CapitalizeFirst())); } return(new AcceptanceReport("TerrainCannotSupport".Translate(entDef).CapitalizeFirst())); } if (ModsConfig.RoyaltyActive) { List <Thing> list2 = map.listerThings.ThingsOfDef(ThingDefOf.MonumentMarker); for (int l = 0; l < list2.Count; l++) { MonumentMarker monumentMarker = (MonumentMarker)list2[l]; if (!monumentMarker.complete && !monumentMarker.AllowsPlacingBlueprint(entDef, center, rot, stuffDef)) { return(new AcceptanceReport("BlueprintWouldCollideWithMonument".Translate())); } } } if (!godMode) { foreach (IntVec3 item3 in cellRect) { thingList = item3.GetThingList(map); for (int m = 0; m < thingList.Count; m++) { Thing thing4 = thingList[m]; if (thing4 != thingToIgnore && !CanPlaceBlueprintOver(entDef, thing4.def)) { return(new AcceptanceReport("SpaceAlreadyOccupied".Translate())); } } } } if (entDef.PlaceWorkers != null) { for (int n = 0; n < entDef.PlaceWorkers.Count; n++) { AcceptanceReport result = entDef.PlaceWorkers[n].AllowsPlacing(entDef, center, rot, map, thingToIgnore, thing); if (!result.Accepted) { return(result); } } } return(AcceptanceReport.WasAccepted); }
// Token: 0x060000E2 RID: 226 RVA: 0x000071D4 File Offset: 0x000053D4 public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null, Thing thing = null, ThingDef stuffDef = null) { CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size); bool flag = stuffDef == null && thing != null; if (flag) { stuffDef = thing.Stuff; } foreach (IntVec3 c in cellRect) { bool flag2 = !c.InBounds(map); if (flag2) { return(new AcceptanceReport("OutOfBounds".Translate())); } bool flag3 = c.InNoBuildEdgeArea(map) && !godMode; if (flag3) { return("TooCloseToMapEdge".Translate()); } } bool flag4 = center.Fogged(map); AcceptanceReport result; if (flag4) { result = "CannotPlaceInUndiscovered".Translate(); } else { List <Thing> thingList = center.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing2 = thingList[i]; bool flag5 = thing2 != thingToIgnore && thing2.Position == center && thing2.Rotation == rot; if (flag5) { bool flag6 = thing2.def == entDef; if (flag6) { return(new AcceptanceReport("IdenticalThingExists".Translate())); } bool flag7 = thing2.def.entityDefToBuild == entDef; if (flag7) { bool flag8 = thing2 is Blueprint; if (flag8) { return(new AcceptanceReport("IdenticalBlueprintExists".Translate())); } return(new AcceptanceReport("IdenticalThingExists".Translate())); } } } ThingDef thingDef = entDef as ThingDef; bool flag9 = thingDef != null && thingDef.hasInteractionCell; if (flag9) { IntVec3 c2 = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map); bool flag10 = !c2.InBounds(map); if (flag10) { return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate())); } List <Thing> list = map.thingGrid.ThingsListAtFast(c2); for (int j = 0; j < list.Count; j++) { bool flag11 = list[j] != thingToIgnore; if (flag11) { bool flag12 = list[j].def.passability == Traversability.Impassable || list[j].def == thingDef; if (flag12) { return(new AcceptanceReport("InteractionSpotBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst())); } BuildableDef entityDefToBuild = list[j].def.entityDefToBuild; bool flag13 = entityDefToBuild != null && (entityDefToBuild.passability == Traversability.Impassable || entityDefToBuild == thingDef); if (flag13) { return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst())); } } } } foreach (IntVec3 c3 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size)) { bool flag14 = c3.InBounds(map); if (flag14) { thingList = c3.GetThingList(map); for (int k = 0; k < thingList.Count; k++) { Thing thing3 = thingList[k]; bool flag15 = thing3 != thingToIgnore; if (flag15) { Blueprint blueprint = thing3 as Blueprint; bool flag16 = blueprint != null; ThingDef thingDef3; if (flag16) { ThingDef thingDef2 = blueprint.def.entityDefToBuild as ThingDef; bool flag17 = thingDef2 == null; if (flag17) { goto IL_48F; } thingDef3 = thingDef2; } else { thingDef3 = thing3.def; } bool flag18 = thingDef3.hasInteractionCell && (entDef.passability == Traversability.Impassable || entDef == thingDef3) && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing3.Position, thing3.Rotation, thing3.Map)); if (flag18) { return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(entDef.label, thingDef3.label).CapitalizeFirst())); } } IL_48F :; } } } TerrainDef terrainDef = entDef as TerrainDef; bool flag19 = terrainDef != null; if (flag19) { bool flag20 = map.terrainGrid.TerrainAt(center) == terrainDef; if (flag20) { return(new AcceptanceReport("TerrainIsAlready".Translate(terrainDef.label))); } bool flag21 = map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null; if (flag21) { return(new AcceptanceReport("SpaceBeingSmoothed".Translate())); } } bool flag22 = WPGenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore, stuffDef); if (flag22) { bool flag23 = !godMode; if (flag23) { foreach (IntVec3 c4 in cellRect) { thingList = c4.GetThingList(map); for (int l = 0; l < thingList.Count; l++) { Thing thing4 = thingList[l]; bool flag24 = thing4 != thingToIgnore && !WPGenConstruct.CanPlaceBlueprintOver(entDef, thing4.def); if (flag24) { return(new AcceptanceReport("SpaceAlreadyOccupied".Translate())); } } } } bool flag25 = entDef.PlaceWorkers != null; if (flag25) { for (int m = 0; m < entDef.PlaceWorkers.Count; m++) { AcceptanceReport result2 = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore, thing); bool flag26 = !result2.Accepted; if (flag26) { return(result2); } } } result = AcceptanceReport.WasAccepted; } else { bool flag27 = entDef.GetTerrainAffordanceNeed(stuffDef) == null; if (flag27) { result = new AcceptanceReport("TerrainCannotSupport".Translate(entDef).CapitalizeFirst()); } else { bool flag28 = entDef.useStuffTerrainAffordance && stuffDef != null; if (flag28) { result = new AcceptanceReport("TerrainCannotSupport_TerrainAffordanceFromStuff".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef), stuffDef).CapitalizeFirst()); } else { result = new AcceptanceReport("TerrainCannotSupport_TerrainAffordance".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef)).CapitalizeFirst()); } } } } return(result); }