/// <summary> /// Create a circular area to a given map /// </summary> /// <param name="map">The map where the area should be placed on</param> /// <param name="rowIndex">Tile row index</param> /// <param name="columnIndex">Tile column index</param> /// <param name="rowCount">Number of rows per grid</param> /// <param name="columnCount">Number of columns per grid</param> /// <param name="radius">Radius of the circle</param> /// <param name="tileSize">Size of a tile in pixel</param> /// <param name="metersPerTile">Size of a tile in meter</param> /// <param name="tileIdValue">Tile id value for the circular area</param> /// <param name="tileFlag">Tile flag</param> /// <param name="allowEdgeManipulation">Allows areas to overlap tiles from other maps</param> /// <returns>Returns the number of changed tiles</returns> private int CreateCircleArea(Tile[] map, int rowIndex, int columnIndex, int rowCount, int columnCount, int radius, int tileSize, float metersPerTile, ushort tileIdValue, byte tileFlag, bool allowEdgeManipulation) { int modified = 0; int minRadiusTile = (int)Math.Ceiling(radius / metersPerTile); int minRadiusPx = minRadiusTile * tileSize; int x = columnIndex * tileSize; int y = rowIndex * tileSize; for (int r = rowIndex - minRadiusTile; r < rowIndex + minRadiusTile; r++) { for (int c = columnIndex - minRadiusTile; c < columnIndex + minRadiusTile; c++) { int realRow = r; int realColumn = c; if (TileMathHelper.IsOutOfRange(r, c, rowCount, columnCount)) { if (allowEdgeManipulation) { realRow = TileMathHelper.FixTileIndex(r, rowCount); realColumn = TileMathHelper.FixTileIndex(c, columnCount); } else { continue; } } int distance = TileMathHelper.GetDistance(x, y, c * tileSize, r * tileSize); if (distance <= minRadiusPx) { int id = TileMathHelper.ToIndex(realRow, realColumn, columnCount); if (map[id].Id == 0) { map[id] = new Tile(tileIdValue, tileFlag); modified++; } } } } return(modified); }
/// <summary> /// Create a circular area to a given map /// </summary> /// <param name="mapIndex">Index of the map</param> /// <param name="maps">Current grids</param> /// <param name="edgeOverrides">Current edge override maps</param> /// <param name="rowIndex">Tile row index</param> /// <param name="columnIndex">Tile column index</param> /// <param name="rowCount">Number of rows per grid</param> /// <param name="columnCount">Number of columns per grid</param> /// <param name="radius">Radius of the circle</param> /// <param name="tileSize">Size of a tile in pixel</param> /// <param name="metersPerTile">Size of a tile in meter</param> /// <param name="tileIdValue">Tile id value for the circular area</param> /// <param name="tileFlags">Tile flags</param> /// <param name="allowEdgeOverflow">Allows areas to overlap tiles from other maps</param> /// <param name="useEdgeNoise">Adds edge noise to the generated area</param> /// <returns>Returns the number of changed tiles</returns> private int CreateCircleArea(int mapIndex, Tile[][] maps, Tile[][] edgeOverrides, int rowIndex, int columnIndex, int rowCount, int columnCount, int radius, int tileSize, float metersPerTile, ushort tileIdValue, byte tileFlags, bool allowEdgeOverflow, bool useEdgeNoise) { int modified = 0; int minRadiusTile = (int)Math.Ceiling(radius / metersPerTile); int minRadiusPx = minRadiusTile * tileSize; int x = columnIndex * tileSize; int y = rowIndex * tileSize; for (int r = rowIndex - minRadiusTile; r < rowIndex + minRadiusTile; r++) { for (int c = columnIndex - minRadiusTile; c < columnIndex + minRadiusTile; c++) { int currentMapIndex = mapIndex; int realRow = r; int realColumn = c; if (TileMathHelper.IsOutOfRange(r, c, rowCount, columnCount)) { if (allowEdgeOverflow) { currentMapIndex = TileMathHelper.GetMapIndex(r, c, rowCount, columnCount, currentMapIndex); if (currentMapIndex >= 0) { realRow = TileMathHelper.FixTileIndex(r, rowCount); realColumn = TileMathHelper.FixTileIndex(c, columnCount); } else { continue; } } else { continue; } } int distance = TileMathHelper.GetDistance(x, y, c * tileSize, r * tileSize); if (distance <= minRadiusPx) { int id = TileMathHelper.ToIndex(realRow, realColumn, columnCount); if (mapIndex == currentMapIndex) { if (maps[currentMapIndex][id].Id == 0) { maps[currentMapIndex][id] = new Tile(tileIdValue, tileFlags); modified++; } } else { if (edgeOverrides[currentMapIndex][id].Id == 0) { edgeOverrides[currentMapIndex][id] = new Tile(tileIdValue, tileFlags); } } } } } return(modified); }