Exemple #1
0
        /// <summary>
        /// Creates some flowers all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="cz"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        public static void MakeFlowers(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd)
        {
            for (int i = 0; i < 5; i++)
            {
                int x = cx + rnd.Next(chunksize);
                int y = cy + rnd.Next(chunksize);
                int z = cz + rnd.Next(chunksize);
                if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
                {
                    continue;
                }
                int xx; int yy; int zz;
                int tile  = rnd.NextDouble() < 0.75 ? WorldGeneratorTools.TileIdYellowFlower : WorldGeneratorTools.TileIdRedFlower;
                int count = rnd.Next(50, 80);
                for (int j = 0; j < count; j++)
                {
                    xx = x + rnd.Next(-6, 6);
                    yy = y + rnd.Next(-6, 6);
                    zz = z + rnd.Next(-2, 2);
                    if (!MapUtil.IsValidPos(map, xx, yy, zz) || map.GetBlock(xx, yy, zz) != WorldGeneratorTools.TileIdGrass)
                    {
                        continue;
                    }

                    // set the block
                    SetBlock(map, x, y, z, tile);
                }
            }
        }
Exemple #2
0
        private void Flood(Vector3 v)
        {
            if (!MapUtil.IsValidPos(map, (int)v.X, (int)v.Y, (int)v.Z))
            {
                return;
            }
            if (flooded.ContainsKey(v))
            {
                return;
            }
            int level = GetWaterLevel((byte)map.GetBlock((int)v.X, (int)v.Y, (int)v.Z));

            flooded.Add(v, v);

            foreach (Vector3 vv in BlocksAround(v))
            {
                if (!MapUtil.IsValidPos(map, (int)vv.X, (int)vv.Y, (int)vv.Z))
                {
                    continue;
                }
                var type = map.GetBlock((int)vv.X, (int)vv.Y, (int)vv.Z);
                if (!MapUtil.IsValidPos(map, (int)vv.X, (int)vv.Y, (int)vv.Z - 1))
                {
                    continue;
                }
                int under = map.GetBlock((int)v.X, (int)v.Y, (int)v.Z - 1);
                int nextlevel;
                //is ground under, then can flow to sides
                if (under != 0 && !IsWater(under))
                {
                    nextlevel = level - 1;
                    if (nextlevel < 0)
                    {
                        continue;
                    }
                }
                //is no ground under, then can only flow down.
                else
                {
                    if (vv.Z == v.Z)
                    {
                        continue;
                    }
                    nextlevel = waterLevelsCount - 1;
                }
                if (GetWaterLevel(type) > nextlevel)
                {
                    //already higher water level
                    continue;
                }
                if (type == SpecialBlockId.Empty && (!IsSpongeNear((int)vv.X, (int)vv.Y, (int)vv.Z)))
                {
                    tosetwater.Add(new ToSet()
                    {
                        pos = vv, level = nextlevel
                    });
                    toflood[vv] = vv;
                }
            }
        }
        bool IsTileEmptyForPhysics(int x, int y, int z)
        {
            if (z >= d_Map.MapSizeZ)
            {
                return(true);
            }
            bool ENABLE_FREEMOVE = false;

            if (x < 0 || y < 0 || z < 0)// || z >= mapsizez)
            {
                return(ENABLE_FREEMOVE);
            }
            if (x >= d_Map.MapSizeX || y >= d_Map.MapSizeY)// || z >= mapsizez)
            {
                return(ENABLE_FREEMOVE);
            }
            //this test is so the player does not walk on water.
            if (d_Data.IsFluid[d_Map.GetBlock(x, y, z)] &&
                !d_Data.IsFluid[d_Map.GetBlock(x, y, z + 1)])
            {
                return(true);
            }
            return(d_Map.GetBlock(x, y, z) == 0 ||
                   (d_Map.GetBlock(x, y, z) == d_Data.BlockIdSingleStairs && d_Map.GetBlock(x, y, z + 2) == 0 && d_Map.GetBlock(x, y, z + 1) == 0) || // also check if the block above the stair is empty
                   (d_Data.IsFluid[d_Map.GetBlock(x, y, z)] && (!swimmingtop)) ||
                   d_Data.IsEmptyForPhysics[d_Map.GetBlock(x, y, z)]);
        }
Exemple #4
0
        public List <int> GetOnTable(List <Vector3i> table)
        {
            List <int> ontable = new List <int>();

            foreach (var v in table)
            {
                int t = d_Map.GetBlock(v.x, v.y, v.z + 1);
                ontable.Add(t);
            }
            return(ontable);
        }
Exemple #5
0
        public static void MakeSmallTrees(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd, int count)
        {
            int chooseTreeType;

            for (int i = 0; i < count; i++)
            {
                int x = cx + rnd.Next(chunksize);
                int y = cy + rnd.Next(chunksize);
                int z = cz + rnd.Next(chunksize);
                if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
                {
                    continue;
                }
                chooseTreeType = rnd.Next(0, 3);
                switch (chooseTreeType)
                {
                case 0: MakeTreeType1(map, x, y, z, rnd); break;

                case 1: MakeTreeType2(map, x, y, z, rnd); break;

                case 2: MakeTreeType3(map, x, y, z, rnd); break;
                }
                ;
            }
        }
Exemple #6
0
 private void Flood(Vector3 v)
 {
     if (!MapUtil.IsValidPos(map, (int)v.X, (int)v.Y, (int)v.Z))
     {
         return;
     }
     if (flooded.ContainsKey(v))
     {
         return;
     }
     flooded.Add(v, v);
     foreach (Vector3 vv in BlocksAround(v))
     {
         if (!MapUtil.IsValidPos(map, (int)vv.X, (int)vv.Y, (int)vv.Z))
         {
             continue;
         }
         var type = map.GetBlock((int)vv.X, (int)vv.Y, (int)vv.Z);
         if (type == 0 && (!IsSpongeNear((int)vv.X, (int)vv.Y, (int)vv.Z)))
         {
             tosetwater.Add(vv);
             toflood[vv] = vv;
         }
     }
 }
Exemple #7
0
        /// <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);
                            }
                        }
                    }
                }
            }
        }
Exemple #8
0
        public void StartParticleEffect(Vector3 v)
        {
            if (particleEffects.Count >= maxparticleeffects)
            {
                return;
            }
            ParticleEffect p = new ParticleEffect();

            p.center = v + new Vector3(0.5f, 0.5f, 0.5f);
            p.start  = DateTime.Now;
            if (!MapUtil.IsValidPos(d_Map, (int)v.X, (int)v.Z, (int)v.Y))
            {
                return;
            }
            int tiletype = d_Map.GetBlock((int)v.X, (int)v.Z, (int)v.Y);

            if (!d_Data.IsValid[tiletype])
            {
                return;
            }
            p.textureid = d_Data.TextureId[tiletype, (int)TileSide.Top];
            p.light     = (float)d_Shadows.MaybeGetLight((int)v.X, (int)v.Z, (int)v.Y) / d_Shadows.maxlight;
            for (int i = 0; i < particlecount; i++)
            {
                Particle pp = new Particle();
                pp.position  = p.center;
                pp.direction = new Vector3((float)rnd.NextDouble() - 0.5f,
                                           (float)rnd.NextDouble() - 0.5f, (float)rnd.NextDouble() - 0.5f);
                pp.direction.Normalize();
                p.particles.Add(pp);
            }
            particleEffects.Add(p);
        }
Exemple #9
0
 /// <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);
     }
 }
Exemple #10
0
 void BlockChangeFlood(IMapStorage map, int x, int y, int z)
 {
     //water here
     if (MapUtil.IsValidPos(map, x, y, z) &&
         IsWater(map.GetBlock(x, y, z)))
     {
         Flood(new Vector3(x, y, z));
     }
     //water around
     foreach (var vv in BlocksAroundAll(new Vector3(x, y, z)))
     {
         if (MapUtil.IsValidPos(map, (int)vv.X, (int)vv.Y, (int)vv.Z) &&
             IsWater(map.GetBlock((int)vv.X, (int)vv.Y, (int)vv.Z)))
         {
             Flood(vv);
         }
     }
 }
Exemple #11
0
        public RailSlope GetRailSlope(int x, int y, int z)
        {
            int tiletype            = d_MapStorage.GetBlock(x, y, z);
            RailDirectionFlags rail = d_Data.Rail[tiletype];
            int blocknear;

            if (x < d_MapStorage.MapSizeX - 1)
            {
                blocknear = d_MapStorage.GetBlock(x + 1, y, z);
                if (rail == RailDirectionFlags.Horizontal &&
                    blocknear != 0 && d_Data.Rail[blocknear] == RailDirectionFlags.None)
                {
                    return(RailSlope.TwoRightRaised);
                }
            }
            if (x > 0)
            {
                blocknear = d_MapStorage.GetBlock(x - 1, y, z);
                if (rail == RailDirectionFlags.Horizontal &&
                    blocknear != 0 && d_Data.Rail[blocknear] == RailDirectionFlags.None)
                {
                    return(RailSlope.TwoLeftRaised);
                }
            }
            if (y > 0)
            {
                blocknear = d_MapStorage.GetBlock(x, y - 1, z);
                if (rail == RailDirectionFlags.Vertical &&
                    blocknear != 0 && d_Data.Rail[blocknear] == RailDirectionFlags.None)
                {
                    return(RailSlope.TwoUpRaised);
                }
            }
            if (y < d_MapStorage.MapSizeY - 1)
            {
                blocknear = d_MapStorage.GetBlock(x, y + 1, z);
                if (rail == RailDirectionFlags.Vertical &&
                    blocknear != 0 && d_Data.Rail[blocknear] == RailDirectionFlags.None)
                {
                    return(RailSlope.TwoDownRaised);
                }
            }
            return(RailSlope.Flat);
        }
Exemple #12
0
 public static int SearchColumn(IMapStorage map, int x, int y, int id, int startH)
 {
     for (int h = startH; h > 0; h--)
     {
         if (map.GetBlock(x, y, h) == (byte)id)
         {
             return(h);
         }
     }
     return(-1); // -1 means 'not found'
 }
Exemple #13
0
 public static int blockheight(IMapStorage map, int tileidempty, int x, int y)
 {
     for (int z = map.MapSizeZ - 1; z >= 0; z--)
     {
         if (map.GetBlock(x, y, z) != tileidempty)
         {
             return(z + 1);
         }
     }
     return(map.MapSizeZ / 2);
 }
Exemple #14
0
        public void BlockChange(IMapStorage map, int x, int y, int z)
        {
            this.flooded = new Dictionary <Vector3, Vector3>();
            this.map     = map;
            //sponge just built.
            if (MapUtil.IsValidPos(map, x, y, z) && map.GetBlock(x, y, z) == data.BlockIdSponge)
            {
                for (int xx = x - spongerange; xx <= x + spongerange; xx++)
                {
                    for (int yy = y - spongerange; yy <= y + spongerange; yy++)
                    {
                        for (int zz = z - spongerange; zz <= z + spongerange; zz++)
                        {
                            if (MapUtil.IsValidPos(map, xx, yy, zz) && IsWater(map.GetBlock(xx, yy, zz)))
                            {
                                tosetempty.Add(new Vector3(xx, yy, zz));
                            }
                        }
                    }
                }
            }
            //maybe sponge destroyed. todo faster test.
            for (int xx = x - spongerange; xx <= x + spongerange; xx++)
            {
                for (int yy = y - spongerange; yy <= y + spongerange; yy++)
                {
                    for (int zz = z - spongerange; zz <= z + spongerange; zz++)
                    {
                        if (MapUtil.IsValidPos(map, xx, yy, zz) && map.GetBlock(xx, yy, zz) == SpecialBlockId.Empty)
                        {
                            BlockChangeFlood(map, xx, yy, zz);
                        }
                    }
                }
            }
            BlockChangeFlood(map, x, y, z);
            var v = new Vector3(x, y, z);

            tosetwater.Sort((a, b) => (v - a.pos).Length.CompareTo((v - b.pos).Length));
        }
Exemple #15
0
 public void BlockChange(IMapStorage map, int x, int y, int z)
 {
     this.flooded = new Dictionary<Vector3, Vector3>();
     this.map = map;
     //sponge just built.
     if (MapUtil.IsValidPos(map, x, y, z) && map.GetBlock(x, y, z) == data.BlockIdSponge)
     {
         for (int xx = x - spongerange; xx <= x + spongerange; xx++)
         {
             for (int yy = y - spongerange; yy <= y + spongerange; yy++)
             {
                 for (int zz = z - spongerange; zz <= z + spongerange; zz++)
                 {
                     if (MapUtil.IsValidPos(map, xx, yy, zz) && data.IsWater[map.GetBlock(xx, yy, zz)])
                     {
                         tosetempty.Add(new Vector3(xx, yy, zz));
                     }
                 }
             }
         }
     }
     //maybe sponge destroyed. todo faster test.
     for (int xx = x - spongerange; xx <= x + spongerange; xx++)
     {
         for (int yy = y - spongerange; yy <= y + spongerange; yy++)
         {
             for (int zz = z - spongerange; zz <= z + spongerange; zz++)
             {
                 if (MapUtil.IsValidPos(map, xx, yy, zz) && map.GetBlock(xx, yy, zz) == 0)
                 {
                     BlockChangeFlood(map, xx, yy, zz);
                 }
             }
         }
     }
     BlockChangeFlood(map, x, y, z);
     var v = new Vector3(x, y, z);
     tosetwater.Sort((a, b) => (v - a).Length.CompareTo((v - b).Length));
 }
Exemple #16
0
        public static int DistanceToBlock(IMapStorage map, Vector3f coord, Vector3f vec, int blockType, bool invert)
        {
            coord += .5f;
            int iterations = 0;

            while (MapUtil.IsValidPos(map, (int)coord.x, (int)coord.y, (int)coord.h))
            {
                byte blockAtPos = (byte)map.GetBlock((int)coord.x, (int)coord.y, (int)coord.h);
                if ((blockAtPos == (byte)blockType && !invert) ||
                    (blockAtPos != (byte)blockType && invert))
                {
                    break;
                }
                else
                {
                    coord += vec;
                    iterations++;
                }
            }
            return(iterations);
        }
 byte[] SaveXml(IMapStorage map)
 {
     StringBuilder b = new StringBuilder();
     b.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
     b.AppendLine("<ManicDiggerSave>");
     b.AppendLine(XmlTool.X("FormatVersion", "1"));
     b.AppendLine("<MapSize>");
     b.AppendLine(XmlTool.X("X", "" + map.MapSizeX));
     b.AppendLine(XmlTool.X("Y", "" + map.MapSizeY));
     b.AppendLine(XmlTool.X("Z", "" + map.MapSizeZ));
     b.AppendLine("</MapSize>");
     MemoryStream mapdata = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(mapdata);
     for (int z = 0; z < map.MapSizeZ; z++)
     {
         for (int y = 0; y < map.MapSizeY; y++)
         {
             for (int x = 0; x < map.MapSizeX; x++)
             {
                 bw.Write((byte)map.GetBlock(x, y, z));
             }
         }
     }
     b.AppendLine(XmlTool.X("MapData", Convert.ToBase64String(mapdata.ToArray())));
     //b.AppendLine(X("DefaultSpawn", ));
     b.AppendLine("</ManicDiggerSave>");
     /*
     <ManicDiggerSave>
       <SaveFormat>1</SaveFormat>
       <MapSize>
     <X>256</X>
     <Y>256</Y>
     <Z>64</Z>
       </MapSize>
       <MapData>BASE64</MapData>
       <Players>
     <Player>
       <Id>0</Id>
       <SpawnPoint>
         <X>5</X>
         <Y>5</Y>
         <Z>40</Z>
       </SpawnPoint>
     </Player>
       </Players>
     </ManicDiggerSave>
     */
     return Encoding.UTF8.GetBytes(b.ToString());
 }
 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 PopulateChunk(IMapStorage map, int x, int y, int z, int chunksize)
    {
        x *= chunksize;
            y *= chunksize;
            z *= chunksize;
            //if (rnd.NextDouble() >= 0.6)
            {
                //return;
            }

            //find cave start
            double curx = x;
            double cury = y;
            double curz = z;
            for (int i = 0; i < 10; i++)
            {
                curx = x + rnd.Next(chunksize);
                cury = y + rnd.Next(chunksize);
                curz = z + rnd.Next(chunksize);
                if (map.GetBlock((int)curx, (int)cury, (int)curz) == TileIdStone)
                {
                    goto ok;
                }
            }
            return;
        ok:
            int blocktype = TileIdEmpty;
            int length = 200;
            if (rnd.NextDouble() < 0.5)
            {
                int oretype = rnd.Next(3);
                if (oretype == 0) { length = goldorelength; }
                if (oretype == 1) { length = ironorelength; }
                if (oretype == 2) { length = coalorelength; }
                length = rnd.Next(length);
                blocktype = TileIdGoldOre + oretype;
            }
            //map.SetBlock(x, y, z, TileIdLava);
            int dirx = rnd.NextDouble() < 0.5 ? -1 : 1;
            int dirz = rnd.NextDouble() < 0.5 ? -1 : 1;
            double curspeedx = rnd.NextDouble() * dirx;
            double curspeedy = rnd.NextDouble();
            double curspeedz = rnd.NextDouble() * 0.5 * dirz;
            for (int i = 0; i < length; i++)
            {
                if (rnd.NextDouble() < 0.05)
                {
                    curspeedx = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.05)
                {
                    curspeedy = rnd.NextDouble();
                }
                if (rnd.NextDouble() < 0.02)
                {
                    curspeedz = rnd.NextDouble() * 0.5 * dirz;
                }
                curx += curspeedx;
                cury += curspeedy;
                curz += curspeedz;
                if (!MapUtil.IsValidPos(map, (int)curx, (int)cury, (int)curz))
                {
                    continue;
                }
                for (int ii = 0; ii < 3; ii++)
                {
                    int sizex = rnd.Next(3, 5);
                    int sizey = rnd.Next(3, 5);
                    int sizez = rnd.Next(3, 5);
                    int dx = rnd.Next(-sizex / 1, sizex / 1);
                    int dy = rnd.Next(-sizey / 1, sizey / 1);
                    int dz = rnd.Next(-sizez / 2, sizez / 2);
                    int[] allowin = blocktype == TileIdEmpty
                        ? new int[] { TileIdStone, TileIdDirt, TileIdGrass, TileIdGoldOre, TileIdIronOre, TileIdCoalOre }
                        : new int[] { TileIdStone };
                    double density = blocktype == TileIdEmpty ? 1 : rnd.NextDouble() * 0.4;
                    MakeCuboid(map, (int)curx - sizex / 2 + dx, (int)cury - sizey / 2 + dy, (int)curz - sizez / 2 + dz, sizex, sizey, sizez, blocktype, allowin, density);
                }
            }
    }
Exemple #20
0
 void BlockChangeFlood(IMapStorage map, int x, int y, int z)
 {
     //water here
     if (MapUtil.IsValidPos(map, x, y, z)
         && data.IsWater[map.GetBlock(x, y, z)])
     {
         Flood(new Vector3(x, y, z));
         return;
     }
     //water around
     foreach (var vv in BlocksAround(new Vector3(x, y, z)))
     {
         if (MapUtil.IsValidPos(map, (int)vv.X, (int)vv.Y, (int)vv.Z) &&
             data.IsWater[map.GetBlock((int)vv.X, (int)vv.Y, (int)vv.Z)])
         {
             Flood(vv);
             return;
         }
     }
 }
Exemple #21
0
 public static int SearchColumn(IMapStorage map, int x, int y, int id, int startH)
 {
     for (int h = startH; h > 0; h--)
     {
         if (map.GetBlock(x, y, h) == (byte)id)
         {
             return h;
         }
     }
     return -1; // -1 means 'not found'
 }
Exemple #22
0
 public static int DistanceToBlock(IMapStorage map, Vector3f coord, Vector3f vec, int blockType, bool invert)
 {
     coord += .5f;
     int iterations = 0;
     while (MapUtil.IsValidPos(map, (int)coord.x, (int)coord.y, (int)coord.h))
     {
         byte blockAtPos = (byte)map.GetBlock((int)coord.x, (int)coord.y, (int)coord.h);
         if ((blockAtPos == (byte)blockType && !invert) ||
             (blockAtPos != (byte)blockType && invert))
         {
             break;
         }
         else
         {
             coord += vec;
             iterations++;
         }
     }
     return iterations;
 }
Exemple #23
0
 /// <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);
     }
 }
Exemple #24
0
        /// <summary>
        /// Creates caves all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        /// <param name="enableCaves"></param>
        /// <param name="gravelLength"></param>
        /// <param name="goldOreLength"></param>
        /// <param name="ironOreLength"></param>
        /// <param name="coalOreLength"></param>
        /// <param name="dirtOreLength"></param>
        public static void MakeCaves(IMapStorage map, int x, int y, int z, int chunksize, Random rnd,
            bool enableCaves,
            int gravelLength,
            int goldOreLength,
            int ironOreLength,
            int coalOreLength,
            int dirtOreLength,
            int silverOreLength)
        {
            //if (rnd.NextDouble() >= 0.6)
            {
                //return;
            }

            //find cave start
            double curx = x;
            double cury = y;
            double curz = z;
            for (int i = 0; i < 2; i++)
            {
                curx = x + rnd.Next(chunksize);
                cury = y + rnd.Next(chunksize);
                curz = z + rnd.Next(chunksize);
                if (map.GetBlock((int)curx, (int)cury, (int)curz) == WorldGeneratorTools.TileIdStone)
                {
                    goto ok;
                }
            }
            return;
            ok:
            int blocktype = WorldGeneratorTools.TileIdEmpty;
            int length = 200;
            if (rnd.NextDouble() < 0.85)
            {
                int oretype = rnd.Next(6);
                if (oretype == 0) { length = gravelLength; }
                if (oretype == 1) { length = goldOreLength; }
                if (oretype == 2) { length = ironOreLength; }
                if (oretype == 3) { length = coalOreLength; }
                if (oretype == 4) { length = dirtOreLength; }
                if (oretype == 5) { length = silverOreLength; }

                length = rnd.Next(length);
                blocktype = oretype < 4 ? WorldGeneratorTools.TileIdGravel + oretype : (oretype > 4 ? WorldGeneratorTools.TileIdGravel + oretype + 115 : WorldGeneratorTools.TileIdDirt);
            }
            if (blocktype == WorldGeneratorTools.TileIdEmpty && (!enableCaves))
            {
                return;
            }
            //map.SetBlock(x, y, z, WorldGeneratorTools.TileIdLava);
            int dirx = rnd.NextDouble() < 0.5 ? -1 : 1;
            int dirz = rnd.NextDouble() < 0.5 ? -1 : 1;
            double curspeedx = rnd.NextDouble() * dirx;
            double curspeedy = rnd.NextDouble();
            double curspeedz = rnd.NextDouble() * 0.5 * dirz;
            for (int i = 0; i < length; i++)
            {
                if (rnd.NextDouble() < 0.06)
                {
                    curspeedx = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.06)
                {
                    curspeedy = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.02)
                {
                    curspeedz = rnd.NextDouble() * 0.5 * dirz;
                }
                curx += curspeedx;
                cury += curspeedy;
                curz += curspeedz;
                if (!MapUtil.IsValidPos(map, (int)curx, (int)cury, (int)curz))
                {
                    continue;
                }
                for (int ii = 0; ii < 3; ii++)
                {
                    int sizex = rnd.Next(3, 6);
                    int sizey = rnd.Next(3, 6);
                    int sizez = rnd.Next(2, 3);
                    int dx = rnd.Next(-sizex / 2, sizex / 2);
                    int dy = rnd.Next(-sizey / 2, sizey / 2);
                    int dz = rnd.Next(-sizez / 1, sizez / 1);

                    int[] allowin = new int[] { WorldGeneratorTools.TileIdStone };
                    double density = blocktype == WorldGeneratorTools.TileIdEmpty ? 1 : rnd.NextDouble() * 0.90;
                    if (blocktype == WorldGeneratorTools.TileIdEmpty)
                    {
                        allowin = new int[] {
                            WorldGeneratorTools.TileIdStone,
                            WorldGeneratorTools.TileIdDirt,
                            WorldGeneratorTools.TileIdGrass,
                            WorldGeneratorTools.TileIdGoldOre,
                            WorldGeneratorTools.TileIdIronOre,
                            WorldGeneratorTools.TileIdCoalOre,
                            WorldGeneratorTools.TileIdSilverOre
                        };
                    }
                    if (blocktype == WorldGeneratorTools.TileIdGravel)
                    {
                        density = 1;
                        allowin = new int[] {
                            WorldGeneratorTools.TileIdDirt,
                            WorldGeneratorTools.TileIdStone,
                            WorldGeneratorTools.TileIdSand,
                            WorldGeneratorTools.TileIdGoldOre,
                            WorldGeneratorTools.TileIdIronOre,
                            WorldGeneratorTools.TileIdCoalOre,
                            WorldGeneratorTools.TileIdSilverOre
                        };
                    }

                    MakeCuboid(map, (int)curx - sizex / 2 + dx, (int)cury - sizey / 2 + dy, (int)curz - sizez / 2 + dz, sizex, sizey, sizez, blocktype, allowin, density, rnd);
                }
            }
        }
Exemple #25
0
 public static void MakeSmallTrees(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd, int count)
 {
     int chooseTreeType;
     for (int i = 0; i < count; i++)
     {
         int x = cx + rnd.Next(chunksize);
         int y = cy + rnd.Next(chunksize);
         int z = cz + rnd.Next(chunksize);
         if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
         {
             continue;
         }
         chooseTreeType = rnd.Next(0, 3);
         switch (chooseTreeType)
         {
             case 0: MakeTreeType1(map, x, y, z, rnd); break;
             case 1: MakeTreeType2(map, x, y, z, rnd); break;
             case 2: MakeTreeType3(map, x, y, z, rnd); break;
         };
     }
 }
 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);
 }
Exemple #27
0
 public static int blockheight(IMapStorage map, int tileidempty, int x, int y)
 {
     for (int z = map.MapSizeZ - 1; z >= 0; z--)
     {
         if (map.GetBlock(x, y, z) != tileidempty)
         {
             return z + 1;
         }
     }
     return map.MapSizeZ / 2;
 }
Exemple #28
0
        /// <summary>
        /// Creates some flowers all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="cz"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        public static void MakeFlowers(IMapStorage map, int cx, int cy, int cz, int chunksize, Random rnd)
        {
            for (int i = 0; i < 5; i++)
            {
                int x = cx + rnd.Next(chunksize);
                int y = cy + rnd.Next(chunksize);
                int z = cz + rnd.Next(chunksize);
                if (!MapUtil.IsValidPos(map, x, y, z) || map.GetBlock(x, y, z) != WorldGeneratorTools.TileIdGrass)
                {
                    continue;
                }
                int xx; int yy; int zz;
                int tile = rnd.NextDouble() < 0.75 ? WorldGeneratorTools.TileIdYellowFlower : WorldGeneratorTools.TileIdRedFlower;
                int count = rnd.Next(50, 80);
                for (int j = 0; j < count; j++)
                {
                    xx = x + rnd.Next(-6, 6);
                    yy = y + rnd.Next(-6, 6);
                    zz = z + rnd.Next(-2, 2);
                    if (!MapUtil.IsValidPos(map, xx, yy, zz) || map.GetBlock(xx, yy, zz) != WorldGeneratorTools.TileIdGrass)
                    {
                        continue;
                    }

                    // set the block
                    SetBlock(map, x, y, z, tile);
                }
            }
        }
Exemple #29
0
        /// <summary>
        /// Creates caves all over the chunk.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="chunksize"></param>
        /// <param name="rnd"></param>
        /// <param name="enableCaves"></param>
        /// <param name="gravelLength"></param>
        /// <param name="goldOreLength"></param>
        /// <param name="ironOreLength"></param>
        /// <param name="coalOreLength"></param>
        /// <param name="dirtOreLength"></param>
        public static void MakeCaves(IMapStorage map, int x, int y, int z, int chunksize, Random rnd,
                                     bool enableCaves,
                                     int gravelLength,
                                     int goldOreLength,
                                     int ironOreLength,
                                     int coalOreLength,
                                     int dirtOreLength,
                                     int silverOreLength)
        {
            //if (rnd.NextDouble() >= 0.6)
            {
                //return;
            }

            //find cave start
            double curx = x;
            double cury = y;
            double curz = z;

            for (int i = 0; i < 2; i++)
            {
                curx = x + rnd.Next(chunksize);
                cury = y + rnd.Next(chunksize);
                curz = z + rnd.Next(chunksize);
                if (map.GetBlock((int)curx, (int)cury, (int)curz) == WorldGeneratorTools.TileIdStone)
                {
                    goto ok;
                }
            }
            return;

ok:
            int blocktype = WorldGeneratorTools.TileIdEmpty;
            int length = 200;

            if (rnd.NextDouble() < 0.85)
            {
                int oretype = rnd.Next(6);
                if (oretype == 0)
                {
                    length = gravelLength;
                }
                if (oretype == 1)
                {
                    length = goldOreLength;
                }
                if (oretype == 2)
                {
                    length = ironOreLength;
                }
                if (oretype == 3)
                {
                    length = coalOreLength;
                }
                if (oretype == 4)
                {
                    length = dirtOreLength;
                }
                if (oretype == 5)
                {
                    length = silverOreLength;
                }

                length    = rnd.Next(length);
                blocktype = oretype < 4 ? WorldGeneratorTools.TileIdGravel + oretype : (oretype > 4 ? WorldGeneratorTools.TileIdGravel + oretype + 115 : WorldGeneratorTools.TileIdDirt);
            }
            if (blocktype == WorldGeneratorTools.TileIdEmpty && (!enableCaves))
            {
                return;
            }
            //map.SetBlock(x, y, z, WorldGeneratorTools.TileIdLava);
            int    dirx      = rnd.NextDouble() < 0.5 ? -1 : 1;
            int    dirz      = rnd.NextDouble() < 0.5 ? -1 : 1;
            double curspeedx = rnd.NextDouble() * dirx;
            double curspeedy = rnd.NextDouble();
            double curspeedz = rnd.NextDouble() * 0.5 * dirz;

            for (int i = 0; i < length; i++)
            {
                if (rnd.NextDouble() < 0.06)
                {
                    curspeedx = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.06)
                {
                    curspeedy = rnd.NextDouble() * dirx;
                }
                if (rnd.NextDouble() < 0.02)
                {
                    curspeedz = rnd.NextDouble() * 0.5 * dirz;
                }
                curx += curspeedx;
                cury += curspeedy;
                curz += curspeedz;
                if (!MapUtil.IsValidPos(map, (int)curx, (int)cury, (int)curz))
                {
                    continue;
                }
                for (int ii = 0; ii < 3; ii++)
                {
                    int sizex = rnd.Next(3, 6);
                    int sizey = rnd.Next(3, 6);
                    int sizez = rnd.Next(2, 3);
                    int dx    = rnd.Next(-sizex / 2, sizex / 2);
                    int dy    = rnd.Next(-sizey / 2, sizey / 2);
                    int dz    = rnd.Next(-sizez / 1, sizez / 1);

                    int[]  allowin = new int[] { WorldGeneratorTools.TileIdStone };
                    double density = blocktype == WorldGeneratorTools.TileIdEmpty ? 1 : rnd.NextDouble() * 0.90;
                    if (blocktype == WorldGeneratorTools.TileIdEmpty)
                    {
                        allowin = new int[] {
                            WorldGeneratorTools.TileIdStone,
                            WorldGeneratorTools.TileIdDirt,
                            WorldGeneratorTools.TileIdGrass,
                            WorldGeneratorTools.TileIdGoldOre,
                            WorldGeneratorTools.TileIdIronOre,
                            WorldGeneratorTools.TileIdCoalOre,
                            WorldGeneratorTools.TileIdSilverOre
                        };
                    }
                    if (blocktype == WorldGeneratorTools.TileIdGravel)
                    {
                        density = 1;
                        allowin = new int[] {
                            WorldGeneratorTools.TileIdDirt,
                            WorldGeneratorTools.TileIdStone,
                            WorldGeneratorTools.TileIdSand,
                            WorldGeneratorTools.TileIdGoldOre,
                            WorldGeneratorTools.TileIdIronOre,
                            WorldGeneratorTools.TileIdCoalOre,
                            WorldGeneratorTools.TileIdSilverOre
                        };
                    }

                    MakeCuboid(map, (int)curx - sizex / 2 + dx, (int)cury - sizey / 2 + dy, (int)curz - sizez / 2 + dz, sizex, sizey, sizez, blocktype, allowin, density, rnd);
                }
            }
        }