public void CheckContiguous() { if (cells.Count != 0) { if (extantGrid == null) { extantGrid = new BoolGrid(Map); } else { extantGrid.ClearAndResizeTo(Map); } if (foundGrid == null) { foundGrid = new BoolGrid(Map); } else { foundGrid.ClearAndResizeTo(Map); } for (int i = 0; i < cells.Count; i++) { extantGrid.Set(cells[i], value: true); } Predicate <IntVec3> passCheck = delegate(IntVec3 c) { if (!extantGrid[c]) { return(false); } if (foundGrid[c]) { return(false); } return(true); }; int numFound = 0; Action <IntVec3> processor = delegate(IntVec3 c) { foundGrid.Set(c, value: true); numFound++; }; Map.floodFiller.FloodFill(cells[0], passCheck, processor); if (numFound < cells.Count) { foreach (IntVec3 allCell in Map.AllCells) { if (extantGrid[allCell] && !foundGrid[allCell]) { RemoveCell(allCell); } } } } }
public static void DrawFieldEdges(List <IntVec3> cells, Color color) { Map currentMap = Find.CurrentMap; MaterialRequest req = default(MaterialRequest); req.shader = ShaderDatabase.Transparent; req.color = color; req.BaseTexPath = "UI/Overlays/TargetHighlight_Side"; Material material = MaterialPool.MatFrom(req); material.GetTexture("_MainTex").wrapMode = TextureWrapMode.Clamp; if (fieldGrid == null) { fieldGrid = new BoolGrid(currentMap); } else { fieldGrid.ClearAndResizeTo(currentMap); } IntVec3 size = currentMap.Size; int x = size.x; IntVec3 size2 = currentMap.Size; int z = size2.z; int count = cells.Count; for (int i = 0; i < count; i++) { if (cells[i].InBounds(currentMap)) { BoolGrid boolGrid = fieldGrid; IntVec3 intVec = cells[i]; int x2 = intVec.x; IntVec3 intVec2 = cells[i]; boolGrid[x2, intVec2.z] = true; } } for (int j = 0; j < count; j++) { IntVec3 c = cells[j]; if (c.InBounds(currentMap)) { rotNeeded[0] = (c.z < z - 1 && !fieldGrid[c.x, c.z + 1]); rotNeeded[1] = (c.x < x - 1 && !fieldGrid[c.x + 1, c.z]); rotNeeded[2] = (c.z > 0 && !fieldGrid[c.x, c.z - 1]); rotNeeded[3] = (c.x > 0 && !fieldGrid[c.x - 1, c.z]); for (int k = 0; k < 4; k++) { if (rotNeeded[k]) { Graphics.DrawMesh(MeshPool.plane10, c.ToVector3ShiftedWithAltitude(AltitudeLayer.MetaOverlays), new Rot4(k).AsQuat, material, 0); } } } } }
public static CellRect FindLargestRect(Map map, Predicate <IntVec3> predicate, int breakEarlyOn = -1) { if (visited == null) { visited = new BoolGrid(map); } visited.ClearAndResizeTo(map); Rand.PushState(map.uniqueID ^ 0x1CDAF373); CellRect largestRect = CellRect.Empty; for (int i = 0; i < 3; i++) { tmpProcessed.Clear(); foreach (IntVec3 item in map.cellsInRandomOrder.GetAll().InRandomOrder(randomOrderWorkingList)) { CellRect cellRect = FindLargestRectAt(item, map, tmpProcessed, predicate); if (cellRect.Area > largestRect.Area) { largestRect = cellRect; if (ShouldBreakEarly()) { break; } } } if (ShouldBreakEarly()) { break; } } Rand.PopState(); return(largestRect); bool ShouldBreakEarly() { if (breakEarlyOn >= 0 && largestRect.Width >= breakEarlyOn) { return(largestRect.Height >= breakEarlyOn); } return(false); } }