Esempio n. 1
0
        private void GenerateOuterLayer(int x, int y, int z, int firstBlockHeight, BIOME_TYPE type, IChunk c)
        {
            double heightPercentage = (firstBlockHeight - y) / 128.0;

            switch (type)
            {
            case BIOME_TYPE.PLAINS:
            case BIOME_TYPE.MOUNTAINS:
                // Beach
                if (y >= 60 && y <= 66)
                {
                    c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS);
                    c.SetSectionType(x, y, z, BlockData.Blocks.Sand);
                    break;
                }

                c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS);
                if (heightPercentage == 0.0 && y > 66)
                {
                    // Grass on top
                    c.SetSectionType(x, y, z, BlockData.Blocks.Grass);
                }
                else if (heightPercentage > 0.2)
                {
                    // Stone
                    c.SetSectionType(x, y, z, BlockData.Blocks.Stone);
                }
                else
                {
                    // Dirt
                    c.SetSectionType(x, y, z, BlockData.Blocks.Dirt);
                }

                GenerateRiver(c, x, y, z, heightPercentage, type);
                break;

            case BIOME_TYPE.SNOW:
                c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.SNOW);
                if (heightPercentage == 0.0 && y > 65)
                {
                    // Snow on top
                    c.SetSectionType(x, y, z, BlockData.Blocks.Snow);
                    // Grass under the snow
                    c.SetSectionType(x, y - 1, z, BlockData.Blocks.Grass);
                }

                else if (heightPercentage > 0.2)
                {
                    // Stone
                    c.SetSectionType(x, y, z, BlockData.Blocks.Stone);
                }
                else
                {
                    // Dirt
                    c.SetSectionType(x, y, z, BlockData.Blocks.Dirt);
                }


                GenerateRiver(c, x, y, z, heightPercentage, type);
                break;

            case BIOME_TYPE.DESERT:
                c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.DESERT);

                /*if (heightPercentage > 0.6 && y < 75)
                 * {
                 *  // Stone
                 *  data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Stone;
                 * }
                 * else*/
                if (y < 80)
                {
                    c.SetSectionType(x, y, z, BlockData.Blocks.Sand);
                }

                break;
            }
        }
Esempio n. 2
0
        private void GenerateOuterLayer(int x, int y, int z, int firstBlockHeight, BIOME_TYPE type, IChunk c)
        {
            double heightPercentage = (firstBlockHeight - y) / 128.0;

            switch (type)
            {
                case BIOME_TYPE.PLAINS:
                case BIOME_TYPE.MOUNTAINS:
                // Beach
                if (y >= 60 && y <= 66)
                {
                    c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS);
                    c.SetType(x, y, z, BlockData.Blocks.Sand, false);
                    break;
                }

                c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS);
                if (heightPercentage == 0.0 && y > 66)
                {
                    // Grass on top
                    c.SetType(x, y, z, BlockData.Blocks.Grass, false);
                }
                else if (heightPercentage > 0.2)
                {
                    // Stone
                    c.SetType(x, y, z, BlockData.Blocks.Stone, false);
                }
                else
                {
                    // Dirt
                    c.SetType(x, y, z, BlockData.Blocks.Dirt, false);
                }

                GenerateRiver(c, x, y, z, heightPercentage, type);
                break;

                case BIOME_TYPE.SNOW:
                c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.SNOW);
                if (heightPercentage == 0.0 && y > 65)
                {
                    // Snow on top
                    c.SetType(x, y, z, BlockData.Blocks.Snow, false);
                    // Grass under the snow
                    c.SetType(x, y - 1, z, BlockData.Blocks.Grass, false);
                }

                else if (heightPercentage > 0.2)
                    // Stone
                    c.SetType(x, y, z, BlockData.Blocks.Stone, false);
                else
                    // Dirt
                    c.SetType(x, y, z, BlockData.Blocks.Dirt, false);
                

                GenerateRiver(c, x, y, z, heightPercentage, type);
                break;

                case BIOME_TYPE.DESERT:
                c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.DESERT);
                /*if (heightPercentage > 0.6 && y < 75)
                {
                    // Stone
                    data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Stone;
                }
                else*/
                if (y < 80)
                    c.SetType(x, y, z, BlockData.Blocks.Sand, false);              

                break;

            }
        }
Esempio n. 3
0
        private void GenerateTerrain(IChunk c, int x, int z)
        {
            double[, ,] density = new double[17, 129, 17];

            // Build the density map with lower resolution, 4*4*16 instead of 16*16*128
            for (int bx = 0; bx <= 16; bx += 4)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz <= 16; bz += 4)
                {
                    BIOME_TYPE type   = CalcBiomeType(x, z);
                    int        worldZ = bz + (z * 16);
                    for (int by = 0; by <= 128; by += 8)
                    {
                        density[bx, by, bz] = CalcDensity(worldX, by, worldZ, type);
                    }
                }
            }

            triLerpDensityMap(density);

            for (int bx = 0; bx < 16; bx++)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz < 16; bz++)
                {
                    int worldZ           = bz + (z * 16);
                    int firstBlockHeight = -1;

                    BIOME_TYPE type = CalcBiomeType(worldX, worldZ);
                    for (int by = 127; by >= 0; --by)
                    {
                        //int index = bx << 11 | bz << 7 | by;
                        if (by == 0) // First bedrock Layer
                        {
                            c.SetSectionType(bx, by, bz, BlockData.Blocks.Bedrock);
                        }

                        else if (by > 0 && by < 5 && _FastRandom.randomDouble() > 0.3) // Randomly put blocks of the remaining 4 layers of bedrock
                        {
                            c.SetSectionType(bx, by, bz, BlockData.Blocks.Bedrock);
                        }

                        else if (by <= 55)
                        {
                            c.SetSectionType(bx, by, bz, BlockData.Blocks.Stone);
                        }
                        else
                        {
                            if (by > 55 && by < 64)
                            {
                                c.SetSectionType(bx, by, bz, BlockData.Blocks.Still_Water);
                                if (by == 63 && type == BIOME_TYPE.SNOW)
                                {
                                    c.SetBiomeColumn(bx, bz, (byte)BIOME_TYPE.SNOW);
                                    c.SetSectionType(bx, by, bz, BlockData.Blocks.Ice);
                                }
                            }

                            double dens = density[bx, by, bz];

                            if (dens >= 0.009 && dens <= 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                {
                                    firstBlockHeight = by;
                                }

                                GenerateOuterLayer(bx, by, bz, firstBlockHeight, type, c);
                            }
                            else if (dens > 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                {
                                    firstBlockHeight = by;
                                }

                                if (CalcCaveDensity(worldX, by, worldZ) > -0.6)
                                {
                                    GenerateInnerLayer(bx, by, bz, type, c);
                                }
                            }
                            else
                            {
                                firstBlockHeight = -1;
                            }
                        }

                        if (c.GetSectionType(bx, by, bz) == (byte)BlockData.Blocks.Stone)
                        {
                            GenerateResource(bx, by, bz, c);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void GenerateTerrain(IChunk c, int x, int z)
        {           
            double[, ,] density = new double[17, 129, 17];

            // Build the density map with lower resolution, 4*4*16 instead of 16*16*128
            for (int bx = 0; bx <= 16; bx += 4)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz <= 16; bz += 4)
                {
                    BIOME_TYPE type = CalcBiomeType(x, z);
                    int worldZ = bz + (z * 16);
                    for (int by = 0; by <= 128; by += 8)
                    {
                        density[bx, by, bz] = CalcDensity(worldX, by, worldZ, type);
                    }
                }
            }

            triLerpDensityMap(density);

            for (int bx = 0; bx < 16; bx++)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz < 16; bz++)
                {
                    int worldZ = bz + (z * 16);
                    int firstBlockHeight = -1;

                    BIOME_TYPE type = CalcBiomeType(worldX, worldZ);
                    for (int by = 127; by >= 0; --by)
                    {
                        //int index = bx << 11 | bz << 7 | by;
                        if (by == 0) // First bedrock Layer
                            c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false);

                        else if (by > 0 && by < 5 && _FastRandom.randomDouble() > 0.3) // Randomly put blocks of the remaining 4 layers of bedrock
                            c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false);

                        else if (by <= 55)
                            c.SetType(bx, by, bz, BlockData.Blocks.Stone, false);
                        else
                        {
                            if (by > 55 && by < 64)
                            {
                                c.SetType(bx, by, bz, BlockData.Blocks.Still_Water, false);
                                if (by == 63 && type == BIOME_TYPE.SNOW)
                                {
                                    c.SetBiomeColumn(bx, bz, (byte)BIOME_TYPE.SNOW);
                                    c.SetType(bx, by, bz, BlockData.Blocks.Ice, false);
                                }
                            }

                            double dens = density[bx, by, bz];

                            if (dens >= 0.009 && dens <= 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                    firstBlockHeight = by;

                                GenerateOuterLayer(bx, by, bz, firstBlockHeight, type, c);
                            }
                            else if (dens > 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                    firstBlockHeight = by;

                                if (CalcCaveDensity(worldX, by, worldZ) > -0.6)
                                    GenerateInnerLayer(bx, by, bz, type, c);
                            }
                            else
                                firstBlockHeight = -1;
                        }

                        if (c.GetType(bx, by, bz) == BlockData.Blocks.Stone)
                            GenerateResource(bx, by, bz, c);
                    }
                }
            }
        }