public override void DrawGhost(ThingDef def, IntVec3 loc, Rot4 rot, Color ghostCol) { GenDraw.DrawFieldEdges(CompPowerPlantWater.GroundCells(loc, rot).ToList <IntVec3>(), Color.white); Color color = (!this.WaterCellsPresent(loc, rot, Find.CurrentMap)) ? Designator_Place.CannotPlaceColor.ToOpaque() : Designator_Place.CanPlaceColor.ToOpaque(); GenDraw.DrawFieldEdges(CompPowerPlantWater.WaterCells(loc, rot).ToList <IntVec3>(), color); bool flag = false; CellRect cellRect = CompPowerPlantWater.WaterUseRect(loc, rot); PlaceWorker_WatermillGenerator.waterMills.AddRange(Find.CurrentMap.listerBuildings.AllBuildingsColonistOfDef(ThingDefOf.WatermillGenerator).Cast <Thing>()); PlaceWorker_WatermillGenerator.waterMills.AddRange(from t in Find.CurrentMap.listerThings.ThingsInGroup(ThingRequestGroup.Blueprint) where t.def.entityDefToBuild == ThingDefOf.WatermillGenerator select t); PlaceWorker_WatermillGenerator.waterMills.AddRange(from t in Find.CurrentMap.listerThings.ThingsInGroup(ThingRequestGroup.BuildingFrame) where t.def.entityDefToBuild == ThingDefOf.WatermillGenerator select t); foreach (Thing thing in PlaceWorker_WatermillGenerator.waterMills) { GenDraw.DrawFieldEdges(CompPowerPlantWater.WaterUseCells(thing.Position, thing.Rotation).ToList <IntVec3>(), new Color(0.2f, 0.2f, 1f)); if (cellRect.Overlaps(CompPowerPlantWater.WaterUseRect(thing.Position, thing.Rotation))) { flag = true; } } PlaceWorker_WatermillGenerator.waterMills.Clear(); Color color2 = (!flag) ? Designator_Place.CanPlaceColor.ToOpaque() : new Color(1f, 0.6f, 0f); if (!flag || Time.realtimeSinceStartup % 0.4f < 0.2f) { GenDraw.DrawFieldEdges(CompPowerPlantWater.WaterUseCells(loc, rot).ToList <IntVec3>(), color2); } }
public void WipeColliding(ThingDef def, IntVec3 pos, Rot4 rot) { if (!WouldCollide(def, pos, rot)) { return; } CellRect cellRect = GenAdj.OccupiedRect(pos, rot, def.size); if (def.terrainAffordanceNeeded != null) { foreach (IntVec3 item in cellRect) { TerrainDef terrainDef = TerrainAt(item); if (terrainDef != null && !terrainDef.affordances.Contains(def.terrainAffordanceNeeded)) { RemoveTerrain(item); } } } for (int num = cachedThings.Count - 1; num >= 0; num--) { if (cellRect.Overlaps(cachedThings[num].OccupiedRect) && !GenConstruct.CanPlaceBlueprintOver(def, cachedThings[num].def)) { Remove(cachedThings[num]); } } }
public bool WouldCollide(ThingDef def, IntVec3 pos, Rot4 rot) { CellRect cellRect = GenAdj.OccupiedRect(pos, rot, def.size); if (def.terrainAffordanceNeeded != null) { foreach (IntVec3 item in cellRect) { TerrainDef terrainDef = TerrainAt(item); if (terrainDef != null && !terrainDef.affordances.Contains(def.terrainAffordanceNeeded)) { return(true); } } } for (int i = 0; i < cachedThings.Count; i++) { if (!cellRect.Overlaps(cachedThings[i].OccupiedRect)) { continue; } if (def.race != null) { if (cachedThings[i].def.passability == Traversability.Impassable) { return(true); } } else if (!GenConstruct.CanPlaceBlueprintOver(def, cachedThings[i].def)) { return(true); } } return(false); }
public void Spawn(Map map, IntVec3 pos, Faction faction, SpawnPosType posType = SpawnPosType.Unchanged, SpawnMode spawnMode = SpawnMode.Normal, bool wipeIfCollides = false, bool clearEdificeWhereFloor = false, List <Thing> spawnedThings = null, bool dormant = false, bool buildRoofsInstantly = false, Func <SketchEntity, IntVec3, bool> canSpawnThing = null, Action <IntVec3, SketchEntity> onFailedToSpawnThing = null) { IntVec3 offset = GetOffset(pos, posType); if (clearEdificeWhereFloor) { for (int i = 0; i < cachedTerrain.Count; i++) { if (cachedTerrain[i].def.layerable) { (cachedTerrain[i].pos + offset).GetEdifice(map)?.Destroy(); } } } foreach (SketchEntity item in entities.OrderBy((SketchEntity x) => x.SpawnOrder)) { IntVec3 intVec = item.pos + offset; if ((canSpawnThing == null || canSpawnThing(item, intVec)) && !item.Spawn(intVec, map, faction, spawnMode, wipeIfCollides, spawnedThings, dormant)) { onFailedToSpawnThing?.Invoke(intVec, item); } } if (spawnedThings != null && spawnMode == SpawnMode.TransportPod && !wipeIfCollides) { bool flag = false; for (int j = 0; j < spawnedThings.Count; j++) { for (int k = j + 1; k < spawnedThings.Count; k++) { CellRect cellRect = GenAdj.OccupiedRect(spawnedThings[j].Position, spawnedThings[j].Rotation, spawnedThings[j].def.size); CellRect other = GenAdj.OccupiedRect(spawnedThings[k].Position, spawnedThings[k].Rotation, spawnedThings[k].def.size); if (cellRect.Overlaps(other) && (GenSpawn.SpawningWipes(spawnedThings[j].def, spawnedThings[k].def) || GenSpawn.SpawningWipes(spawnedThings[k].def, spawnedThings[j].def))) { flag = true; break; } } if (flag) { break; } } if (flag) { for (int l = 0; l < spawnedThings.Count; l++) { ActiveDropPodInfo activeDropPodInfo; if ((activeDropPodInfo = (spawnedThings[l].ParentHolder as ActiveDropPodInfo)) != null) { activeDropPodInfo.spawnWipeMode = null; } } } } if (buildRoofsInstantly && spawnMode == SpawnMode.Normal) { foreach (IntVec3 suggestedRoofCell in GetSuggestedRoofCells()) { IntVec3 c = suggestedRoofCell + offset; if (c.InBounds(map) && !c.Roofed(map)) { map.roofGrid.SetRoof(c, RoofDefOf.RoofConstructed); } } } }
protected override bool CanScatterAt(IntVec3 c, Map map) { if (!base.CanScatterAt(c, map)) { return(false); } CellRect rect = CellRect.CenteredOn(c, 10, 10).ClipInsideMap(map); if (MapGenerator.TryGetVar <List <CellRect> >("UsedRects", out var var) && var.Any((CellRect x) => rect.Overlaps(x))) { return(false); } foreach (IntVec3 cell in rect.Cells) { if (!GenConstruct.CanBuildOnTerrain(currentParams.sitePart.conditionCauser.def, cell, map, Rot4.North)) { return(false); } foreach (Thing thing in cell.GetThingList(map)) { if (thing.def.building != null) { return(false); } } } return(true); }
private static bool TryFindRandomPlaceFor(ThingDef thingDef, Sketch sketch, IntVec2 size, out IntVec3 pos, bool lowerLeftQuarterOnly, bool avoidCenter, bool requireLOSToEdge, bool avoidEdge, List <CellRect> edgeWallRects) { for (int i = 0; i < 200; i++) { CellRect cellRect = new CellRect(0, 0, size.x, size.z); if (lowerLeftQuarterOnly) { cellRect = new CellRect(cellRect.minX, cellRect.minZ, cellRect.Width / 2, cellRect.Height / 2); } IntVec3 randomCell = cellRect.RandomCell; if (avoidCenter) { CellRect cellRect2 = CellRect.CenteredOn(new CellRect(0, 0, size.x, size.z).CenterCell, size.x / 2, size.z / 2); for (int j = 0; j < 5; j++) { if (!cellRect2.Contains(randomCell)) { break; } randomCell = cellRect.RandomCell; } } if (avoidEdge) { CellRect cellRect3 = CellRect.CenteredOn(new CellRect(0, 0, size.x, size.z).CenterCell, Mathf.RoundToInt((float)size.x * 0.75f), Mathf.RoundToInt((float)size.z * 0.75f)); for (int k = 0; k < 5; k++) { if (cellRect3.Contains(randomCell)) { break; } randomCell = cellRect.RandomCell; } } if (requireLOSToEdge) { IntVec3 end = randomCell; end.x += size.x + 1; IntVec3 end2 = randomCell; end2.x -= size.x + 1; IntVec3 end3 = randomCell; end3.z -= size.z + 1; IntVec3 end4 = randomCell; end4.z += size.z + 1; if (!sketch.LineOfSight(randomCell, end) && !sketch.LineOfSight(randomCell, end2) && !sketch.LineOfSight(randomCell, end3) && !sketch.LineOfSight(randomCell, end4)) { continue; } } if (thingDef.building.minDistanceToSameTypeOfBuilding > 0) { bool flag = false; for (int l = 0; l < sketch.Things.Count; l++) { if (sketch.Things[l].def == thingDef && sketch.Things[l].pos.InHorDistOf(randomCell, thingDef.building.minDistanceToSameTypeOfBuilding)) { flag = true; break; } } if (flag) { continue; } } bool flag2 = false; CellRect cellRect4 = GenAdj.OccupiedRect(randomCell, Rot4.North, thingDef.Size); for (int m = 0; m < 4; m++) { if (cellRect4.Overlaps(edgeWallRects[m])) { flag2 = true; break; } } if (!flag2 && !sketch.WouldCollide(thingDef, randomCell, Rot4.North)) { pos = randomCell; return(true); } } pos = IntVec3.Invalid; return(false); }