/// <summary> /// Creates a cuboid at the given location and using the given sizes. /// </summary> /// <param name="map"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <param name="sizex"></param> /// <param name="sizey"></param> /// <param name="sizez"></param> /// <param name="blocktype"></param> /// <param name="allowin"></param> /// <param name="chance"></param> /// <param name="rnd"></param> public static void MakeCuboid(IMapStorage map, int x, int y, int z, int sizex, int sizey, int sizez, int blocktype, int[] allowin, double chance, Random rnd) { for (int xx = 0; xx < sizex; xx++) { for (int yy = 0; yy < sizey; yy++) { for (int zz = 0; zz < sizez; zz++) { if (MapUtil.IsValidPos(map, x + xx, y + yy, z + zz)) { int t = map.GetBlock(x + xx, y + yy, z + zz); if (allowin == null) { goto ok; } foreach (int tt in allowin) { if (tt == t) { goto ok; } } continue; ok: if (rnd.NextDouble() < chance) { map.SetBlock(x + xx, y + yy, z + zz, blocktype); } } } } } }
/// <summary> /// Sets a block at the given position, but only if it is empty. /// </summary> /// <param name="map"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <param name="blocktype"></param> private static void SetBlockIfEmpty(IMapStorage map, int x, int y, int z, int blocktype) { if (MapUtil.IsValidPos(map, x, y, z) && map.GetBlock(x, y, z) == WorldGeneratorTools.TileIdEmpty) { map.SetBlock(x, y, z, blocktype); } }
/// <summary> /// Sets a block at the given position. /// </summary> /// <param name="map"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <param name="blocktype"></param> private static void SetBlock(IMapStorage map, int x, int y, int z, int blocktype) { if (MapUtil.IsValidPos(map, x, y, z)) { map.SetBlock(x, y, z, blocktype); } }
void MakeCuboid(IMapStorage map, int x, int y, int z, int sizex, int sizey, int sizez, int blocktype, int[] allowin, double chance) { for (int xx = 0; xx < sizex; xx++) { for (int yy = 0; yy < sizey; yy++) { for (int zz = 0; zz < sizez; zz++) { if (MapUtil.IsValidPos(map, x + xx, y + yy, z + zz)) { int t = map.GetBlock(x + xx, y + yy, z + zz); if (allowin == null) { goto ok; } foreach (int tt in allowin) { if (tt == t) { goto ok; } } continue; ok: if (rnd.NextDouble() < chance) { map.SetBlock(x + xx, y + yy, z + zz, blocktype); } } } } } }
public void LoadMapArray(IMapStorage map, Stream s) { BinaryReader br = new BinaryReader(s); map.UseMap(new byte[map.MapSizeX, map.MapSizeY, map.MapSizeZ]); for (int z = 0; z < map.MapSizeZ; z++) { for (int y = 0; y < map.MapSizeY; y++) { for (int x = 0; x < map.MapSizeX; x++) { map.SetBlock(x, y, z, br.ReadByte()); } } } //.gui.DrawMap(); Console.WriteLine("Game loaded successfully."); }
public void GenerateMap(IMapStorage map) { for (int x = 0; x < map.MapSizeX; x++) { for (int y = 0; y < map.MapSizeY; y++) { for (int z = 0; z < map.MapSizeZ; z++) { map.SetBlock(x, y, z, data.TileIdEmpty); } } } for (int x = 0; x < map.MapSizeX; x++) { for (int y = 0; y < map.MapSizeY; y++) { for (int z = 0; z < map.MapSizeZ / 2 - 1; z++) { map.SetBlock(x, y, z, data.TileIdDirt); } map.SetBlock(x, y, map.MapSizeZ / 2 - 1, data.TileIdGrass); } } for (int x = 0; x < 100; x++) { map.SetBlock(x, 1, 0, 1); } Random rnd = new Random(); for (int i = 0; i < map.MapSizeX * map.MapSizeY * map.MapSizeZ * 0.005f; i++) { int x = rnd.Next(map.MapSizeX); int y = rnd.Next(map.MapSizeY); int z = rnd.Next(map.MapSizeZ); if (map.GetBlock(x, y, z) == data.TileIdDirt) { map.SetBlock(x, y, z, data.GoldTileId); } } //debug map.SetBlock(10, 10, map.MapSizeZ / 2, data.GoldTileId); }