private bool TrySpawnPillar(Faction faction, ThingDef wallStuff) { if (!roofsAboutToCollapse.Any()) { return(false); } Map map = BaseGen.globalSettings.map; IntVec3 bestCell = IntVec3.Invalid; float bestScore = 0f; FloodFiller floodFiller = map.floodFiller; IntVec3 invalid = IntVec3.Invalid; Predicate <IntVec3> passCheck = (IntVec3 x) => roofsAboutToCollapse.Contains(x); Action <IntVec3> processor = delegate(IntVec3 x) { float pillarSpawnScore = GetPillarSpawnScore(x); if (pillarSpawnScore > 0f && (!bestCell.IsValid || pillarSpawnScore >= bestScore)) { bestCell = x; bestScore = pillarSpawnScore; } }; List <IntVec3> extraRoots = edgeRoofs; floodFiller.FloodFill(invalid, passCheck, processor, 2147483647, rememberParents: false, extraRoots); if (bestCell.IsValid) { Thing thing = ThingMaker.MakeThing(ThingDefOf.Wall, wallStuff); thing.SetFaction(faction); GenSpawn.Spawn(thing, bestCell, map); return(true); } return(false); }
private bool TrySpawnPillar(Faction faction, ThingDef wallStuff) { if (!SymbolResolver_EnsureCanHoldRoof.roofsAboutToCollapse.Any <IntVec3>()) { return(false); } Map map = BaseGen.globalSettings.map; IntVec3 bestCell = IntVec3.Invalid; float bestScore = 0f; FloodFiller arg_8A_0 = map.floodFiller; IntVec3 invalid = IntVec3.Invalid; Predicate <IntVec3> passCheck = (IntVec3 x) => SymbolResolver_EnsureCanHoldRoof.roofsAboutToCollapse.Contains(x); Action <IntVec3> processor = delegate(IntVec3 x) { float pillarSpawnScore = this.GetPillarSpawnScore(x); if (pillarSpawnScore > 0f && (!bestCell.IsValid || pillarSpawnScore >= bestScore)) { bestCell = x; bestScore = pillarSpawnScore; } }; List <IntVec3> extraRoots = SymbolResolver_EnsureCanHoldRoof.edgeRoofs; arg_8A_0.FloodFill(invalid, passCheck, processor, 2147483647, false, extraRoots); if (bestCell.IsValid) { Thing thing = ThingMaker.MakeThing(ThingDefOf.Wall, wallStuff); thing.SetFaction(faction, null); GenSpawn.Spawn(thing, bestCell, map, WipeMode.Vanish); return(true); } return(false); }
public static Bitmap FillColor(Bitmap bmp, Point location, Color fillColor) { if (bmp == null || fillColor == null) { log.Error("Failed to fill color, image or color is null."); return(null); } try { FloodFiller filler = new FloodFiller(); filler.FillColor = fillColor; return(filler.FloodFill(bmp, location)); } catch (Exception ex) { log.ErrorFormat("Failed to fill color, image size {0}, location {1}, color {2}, error info {3}.", bmp.Size.ToString(), location.ToString(), fillColor.ToString(), ex.Message); return(null); } }
void GenerateCells(Map map, List <ZombieCostSpecs> specs, int[] costCells, FloodFiller filler) { var mapSizeX = map.Size.x; var pathGrid = map.pathGrid; var cardinals = GenAdj.CardinalDirections; foreach (var spec in specs) { var loc = spec.position; var costBase = spec.maxCosts; var radiusSquared = spec.radius * spec.radius; var floodedCells = new Dictionary <IntVec3, int>(); filler.FloodFill(loc, cell => (loc - cell).LengthHorizontalSquared <= radiusSquared && pathGrid.Walkable(cell) && (cell.GetEdifice(map) is Building_Door) == false, cell => { var f = 1f - (loc - cell).LengthHorizontalSquared / radiusSquared; var cost = (int)(costBase * f); var idx = cell.x + cell.z * mapSizeX; costCells[idx] = Math.Max(costCells[idx], cost); floodedCells[cell] = costCells[idx]; }); foreach (var cell in floodedCells.Keys) { for (var i = 0; i < 3; i++) { var pos = cell + cardinals[i]; if (floodedCells.ContainsKey(pos) == false && (loc - cell).LengthHorizontalSquared <= radiusSquared && pos.InBounds(map) && pos.GetEdifice(map) is Building_Door) { costCells[pos.x + pos.z * mapSizeX] = floodedCells[cell]; } } } } }
public static Bitmap MagicCutOut(Bitmap sourceImage, Color color, Point[] points) { byte toll = 40; FloodFiller filter = new FloodFiller { FillStyle = FloodFillStyle.Queue, Tolerance = { [0] = toll, [1] = toll, [2] = toll }, FillColor = color, Bmp = sourceImage }; points.ToList().ForEach(point => filter.FloodFill(filter.Bmp, point)); return(filter.Bmp); }
public bool RemoveIslands(bool refValue) { FloodFiller floodFiller = new FloodFiller(grid, refValue); List <FloodFiller.Pos> prevRegion = null; bool filled = false; for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { if (grid[row, col] == refValue && !floodFiller.IsFilled(row, col)) { var newRegion = floodFiller.FloodFill(row, col); if (prevRegion == null) { prevRegion = newRegion; continue; } var fillRegion = newRegion; if (prevRegion.Count < newRegion.Count) { fillRegion = prevRegion; prevRegion = newRegion; } foreach (var pos in fillRegion) { grid[pos.row, pos.col] = !refValue; filled = true; } } } } return(filled); }
private void ExpandSnow() { if (this.snowNoise == null) { this.snowNoise = new Perlin(0.054999999701976776, 2.0, 0.5, 5, Rand.Range(0, 651431), QualityMode.Medium); } if (this.snowRadius < 8f) { this.snowRadius += 1.3f; } else { if (this.snowRadius < 17f) { this.snowRadius += 0.7f; } else { if (this.snowRadius < 30f) { this.snowRadius += 0.4f; } else { this.snowRadius += 0.1f; } } } if (this.snowRadius > 55f) { this.snowRadius = 55f; } CellRect occupiedRect = this.OccupiedRect(); Building_CrashedShipPartCopy.reachableCells.Clear(); FloodFiller.FloodFill(base.Position, (IntVec3 x) => x.DistanceToSquared(this.Position) <= this.snowRadius * this.snowRadius && (occupiedRect.Contains(x) || !x.Filled()), delegate(IntVec3 x) { Building_CrashedShipPartCopy.reachableCells.Add(x); }); int num = GenRadial.NumCellsInRadius(this.snowRadius); for (int i = 0; i < num; i++) { IntVec3 intVec = base.Position + GenRadial.RadialPattern[i]; if (intVec.InBounds()) { if (Building_CrashedShipPartCopy.reachableCells.Contains(intVec)) { float num2 = this.snowNoise.GetValue(intVec); num2 += 1f; num2 *= 0.5f; if (num2 < 0.1f) { num2 = 0.1f; } if (Find.SnowGrid.GetDepth(intVec) <= num2) { float lengthHorizontal = (intVec - base.Position).LengthHorizontal; float num3 = 1f - lengthHorizontal / this.snowRadius; Find.SnowGrid.AddDepth(intVec, num3 * 0.12f * num2); } } } } }