void AddBeaches([NotNull] Map map) { if (map == null) { throw new ArgumentNullException("map"); } int beachExtentSqr = (args.BeachExtent + 1) * (args.BeachExtent + 1); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Length; y++) { for (int z = args.WaterLevel; z <= args.WaterLevel + args.BeachHeight; z++) { if (map.GetBlock(x, y, z) != bGroundSurface) { continue; } bool found = false; for (int dx = -args.BeachExtent; !found && dx <= args.BeachExtent; dx++) { for (int dy = -args.BeachExtent; !found && dy <= args.BeachExtent; dy++) { for (int dz = -args.BeachHeight; dz <= 0; dz++) { if (dx * dx + dy * dy + dz * dz > beachExtentSqr) { continue; } int xx = x + dx; int yy = y + dy; int zz = z + dz; if (xx < 0 || xx >= map.Width || yy < 0 || yy >= map.Length || zz < 0 || zz >= map.Height) { continue; } Block block = map.GetBlock(xx, yy, zz); if (block == bWater || block == bWaterSurface) { found = true; break; } } } } if (found) { map.SetBlock(x, y, z, bSeaFloor); if (z > 0 && map.GetBlock(x, y, z - 1) == bGround) { map.SetBlock(x, y, z - 1, bSeaFloor); } } } } } }
static void SealLiquids(Map map, byte sealantType) { for (int x = 1; x < map.Width - 1; x++) { for (int z = 1; z < map.Height; z++) { for (int y = 1; y < map.Length - 1; y++) { int index = map.Index(x, y, z); if ((map.Blocks[index] == 10 || map.Blocks[index] == 11 || map.Blocks[index] == 8 || map.Blocks[index] == 9) && (map.GetBlock(x - 1, y, z) == Block.Air || map.GetBlock(x + 1, y, z) == Block.Air || map.GetBlock(x, y - 1, z) == Block.Air || map.GetBlock(x, y + 1, z) == Block.Air || map.GetBlock(x, y, z - 1) == Block.Air)) { map.Blocks[index] = sealantType; } } } } }
private static void SetUpMines() { for (short i = 0; i <= _map.Width; ++i) { for (short j = 0; j <= _map.Length; ++j) { if (_map.GetBlock(i, j, _ground) != Block.Red && _map.GetBlock(i, j, _ground) != Block.Green && _map.GetBlock(i, j, _ground) != Block.Water) { _map.SetBlock(i, j, _ground, Block.Dirt); _map.SetBlock(i, j, _ground - 1, Block.Dirt); if (_rand.Next(1, 100) > 96) { Vector3I vec = new Vector3I(i, j, _ground); Mines.TryAdd(vec.ToString(), vec); //_map.SetBlock(vec, Block.Red);// } } } } }
public static bool CanPlacePortal(short x, short y, short z, Map map) { int count = 0; // ReSharper disable once InconsistentNaming for (short Z = z; Z < z + 2; Z++) { Block check = map.GetBlock(x, y, Z); if (check != Block.Air && check != Block.Water && check != Block.Lava) { count++; } } return(count == 2); }
public static bool CanPlacePortal(int x, int y, int z, Map map) { int Count = 0; for (int Z = z; Z < z + 2; Z++) { Block check = map.GetBlock(x, y, Z); if (check != Block.Air && check != Block.Water && check != Block.Lava) { Count++; } } if (Count == 2) { return(true); } else { return(false); } }
void GenerateTrees([NotNull] Map map) { if (map == null) { throw new ArgumentNullException("map"); } int minHeight = args.TreeHeightMin; int maxHeight = args.TreeHeightMax; int minTrunkPadding = args.TreeSpacingMin; int maxTrunkPadding = args.TreeSpacingMax; const int topLayers = 2; const double odds = 0.618; Random rn = new Random(); map.CalculateShadows(); for (int x = 0; x < map.Width; x += rn.Next(minTrunkPadding, maxTrunkPadding + 1)) { for (int y = 0; y < map.Length; y += rn.Next(minTrunkPadding, maxTrunkPadding + 1)) { int nx = x + rn.Next(-(minTrunkPadding / 2), (maxTrunkPadding / 2) + 1); int ny = y + rn.Next(-(minTrunkPadding / 2), (maxTrunkPadding / 2) + 1); if (nx < 0 || nx >= map.Width || ny < 0 || ny >= map.Length) { continue; } int nz = map.Shadows[nx, ny]; if ((map.GetBlock(nx, ny, nz) == bGroundSurface) && slopemap[nx, ny] < .5) { // Pick a random height for the tree between Min and Max, // discarding this tree if it would breach the top of the map int nh; if ((nh = rn.Next(minHeight, maxHeight + 1)) + nz + nh / 2 > map.Height) { continue; } // Generate the trunk of the tree for (int z = 1; z <= nh; z++) { map.SetBlock(nx, ny, nz + z, Block.Log); } for (int i = -1; i < nh / 2; i++) { // Should we draw thin (2x2) or thicker (4x4) foliage int radius = (i >= (nh / 2) - topLayers) ? 1 : 2; // Draw the foliage for (int xoff = -radius; xoff < radius + 1; xoff++) { for (int yoff = -radius; yoff < radius + 1; yoff++) { // Drop random leaves from the edges if (rn.NextDouble() > odds && Math.Abs(xoff) == Math.Abs(yoff) && Math.Abs(xoff) == radius) { continue; } // By default only replace an existing block if its air if (map.GetBlock(nx + xoff, ny + yoff, nz + nh + i) == Block.Air) { map.SetBlock(nx + xoff, ny + yoff, nz + nh + i, Block.Leaves); } } } } } } } }