예제 #1
0
    public static void GenerateChunk(Chunk chunk)
    {
        int gx = (int)chunk.Position.x * 16;
        int gz = (int)chunk.Position.y * 16;

        for (int x = 0; x < Chunk.CHUNK_SIZE; x++)
        {
            for (int z = 0; z < Chunk.CHUNK_SIZE; z++)
            {
                BIOME_TYPE biome = GetBiome(gx + x, gz + z);
                switch (biome)
                {
                case BIOME_TYPE.Plains:
                    PlainBiome.Generate(ref chunk, x, z);
                    break;

                case BIOME_TYPE.Desert:
                    DesertBiome.Generate(ref chunk, x, z);
                    break;

                case BIOME_TYPE.Sea:
                    SeaBiome.Generate(ref chunk, x, z);
                    break;

                case BIOME_TYPE.Forest:
                    ForestBiome.Generate(ref chunk, x, z);
                    break;
                }
            }
        }
    }
예제 #2
0
        private double CalcDensity(double x, double y, double z, BIOME_TYPE type)
        {
            double height = CalcBaseTerrain(x, z);
            double density = CalcMountainDensity(x, y, z);
            double divHeight = (y - 55) * 1.5;

            if (y > 100)
                divHeight *= 2.0;

            if (type == BIOME_TYPE.DESERT)
            {
                divHeight *= 2.5;
            }
            else if (type == BIOME_TYPE.PLAINS)
            {
                divHeight *= 1.6;
            }
            else if (type == BIOME_TYPE.MOUNTAINS)
            {
                divHeight *= 1.1;
            }
            else if (type == BIOME_TYPE.SNOW)
            {
                divHeight *= 1.2;
            }

            return (height + density) / divHeight;
        }
예제 #3
0
        private double CalcDensity(double x, double y, double z, BIOME_TYPE type)
        {
            double height    = CalcBaseTerrain(x, z);
            double density   = CalcMountainDensity(x, y, z);
            double divHeight = (y - 55) * 1.5;

            if (y > 100)
            {
                divHeight *= 2.0;
            }

            if (type == BIOME_TYPE.DESERT)
            {
                divHeight *= 2.5;
            }
            else if (type == BIOME_TYPE.PLAINS)
            {
                divHeight *= 1.6;
            }
            else if (type == BIOME_TYPE.MOUNTAINS)
            {
                divHeight *= 1.1;
            }
            else if (type == BIOME_TYPE.SNOW)
            {
                divHeight *= 1.2;
            }

            return((height + density) / divHeight);
        }
예제 #4
0
    private BiomeParameters GetBiomeParameters(BIOME_TYPE biomeType)
    {
        foreach (BiomeParameters biomeParameter in biomeParameters)
        {
            if (biomeParameter.type == biomeType)
            {
                return(biomeParameter);
            }
        }

        Debug.LogError("Trying to use incorrect biome type.");
        return(new BiomeParameters());
    }
예제 #5
0
        protected void GenerateRiver(Chunk c, int x, int y, int z, double heightPercentage, BIOME_TYPE type, byte[] data)
        {
            // Rivers under water? Nope.
            if (y <= 63)
                return;

            double lakeIntens = CalcLakeIntensity(x + c.Coords.ChunkX * 16, z + c.Coords.ChunkZ * 16);
            short currentIndex = (short)(x << 11 | z << 7 | y);

            if (lakeIntens < 0.2 )
            {
                if (heightPercentage < 0.001)
                    data[currentIndex] = (byte)BlockData.Blocks.Air;
                else if (heightPercentage < 0.02)
                {
                    if (type == BIOME_TYPE.SNOW)
                    {
                        // To be sure that there's no snow above us
                        data[x << 11 | z << 7 | y + 1] = (byte)BlockData.Blocks.Air;
                        data[currentIndex] = (byte)BlockData.Blocks.Ice;
                    }
                    else
                    {
                        data[currentIndex] = (byte)BlockData.Blocks.Still_Water;
                    }
                }
            }
        }
예제 #6
0
 private void GenerateInnerLayer(int x, int y, int z, BIOME_TYPE type, IChunk c)
 {
     c.SetSectionType(x, y, z, BlockData.Blocks.Stone);
 }
예제 #7
0
        protected void GenerateRiver(IChunk c, int x, int y, int z, double heightPercentage, BIOME_TYPE type)
        {
            // Rivers under water? Nope.
            if (y <= 63)
            {
                return;
            }

            double lakeIntens   = CalcLakeIntensity(x + c.Coords.ChunkX * 16, z + c.Coords.ChunkZ * 16);
            short  currentIndex = (short)(x << 11 | z << 7 | y);

            if (lakeIntens < 0.2)
            {
                if (heightPercentage < 0.001)
                {
                    c.SetSectionType(x, y, z, BlockData.Blocks.Air);
                }
                else if (heightPercentage < 0.02)
                {
                    if (type == BIOME_TYPE.SNOW)
                    {
                        // To be sure that there's no snow above us
                        c.SetSectionType(x, y + 1, z, BlockData.Blocks.Air);
                        c.SetSectionType(x, y, z, BlockData.Blocks.Ice);
                    }
                    else
                    {
                        c.SetSectionType(x, y, z, BlockData.Blocks.Still_Water);
                    }
                }
            }
        }
예제 #8
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;
            }
        }
예제 #9
0
        private void GenerateFlora(IChunk c, int x, int z)
        {
            BIOME_TYPE biome = CalcBiomeType(x, z);

            for (int bx = 0; bx < 16; ++bx)
            {
                int worldX = bx + x * 16;
                for (int bz = 0; bz < 16; ++bz)
                {
                    int worldZ = bz + z * 16;
                    for (int by = 64; by < 128; ++by)
                    {
                        int worldY = by;
                        //int index = bx << 11 | bz << 7 | by + 1;

                        if (c.GetSectionType(bx, by, bz) == (byte)BlockData.Blocks.Grass && c.GetSectionType(bx, by + 1, bz) == (byte)BlockData.Blocks.Air)
                        {
                            double grassDens = CalcGrassDensity(worldX, worldZ);
                            if (grassDens > 0.0)
                            {
                                // Generate high grass.
                                double rand = _FastRandom.standNormalDistrDouble();
                                if (rand > -0.2 && rand < 0.2)
                                {
                                    c.SetSectionType(bx, by + 1, bz, BlockData.Blocks.TallGrass);
                                    c.SetData(bx, by + 1, bz, 1, false);
                                }


                                //Generate flowers.
                                if (_FastRandom.standNormalDistrDouble() < -2)
                                {
                                    if (_FastRandom.randomBoolean())
                                    {
                                        c.SetSectionType(bx, by + 1, bz, BlockData.Blocks.Rose);
                                    }
                                    else
                                    {
                                        c.SetSectionType(bx, by + 1, bz, BlockData.Blocks.Yellow_Flower);
                                    }
                                }
                            }

                            if (by < 110 && bx % 4 == 0 && bz % 4 == 0)
                            {
                                double forestDens = CalcForestDensity(worldX, worldZ);

                                if (forestDens > 0.005)
                                {
                                    int randX = bx + _FastRandom.randomInt() % 12 + 4;
                                    int randZ = bz + _FastRandom.randomInt() % 12 + 4;

                                    if (randX < 3)
                                    {
                                        randX = 3;
                                    }
                                    else if (randX > 12)
                                    {
                                        randX = 12;
                                    }

                                    if (randZ < 3)
                                    {
                                        randZ = 3;
                                    }
                                    else if (randZ > 15)
                                    {
                                        randZ = 12;
                                    }

                                    if (c.GetSectionType(randX, by, randZ) == (byte)BlockData.Blocks.Grass)
                                    {
                                        GenerateTree(c, randX, by, randZ);
                                    }

                                    else if (biome == BIOME_TYPE.DESERT && c.GetSectionType(randX, by, randZ) == (byte)BlockData.Blocks.Sand)
                                    {
                                        GenerateCactus(c, randX, by, randZ);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #10
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);
                        }
                    }
                }
            }
        }
예제 #11
0
 private void GenerateInnerLayer(int x, int y, int z, BIOME_TYPE type, Chunk c)
 {
     c.SetType(x, y, z, BlockType.Stone, false);
 }
예제 #12
0
        protected void GenerateRiver(IChunk c, int x, int y, int z, double heightPercentage, BIOME_TYPE type)
        {
            // Rivers under water? Nope.
            if (y <= 63)
                return;

            double lakeIntens = CalcLakeIntensity(x + c.Coords.ChunkX * 16, z + c.Coords.ChunkZ * 16);
            short currentIndex = (short)(x << 11 | z << 7 | y);

            if (lakeIntens < 0.2)
            {
                if (heightPercentage < 0.001)
                    c.SetType(x, y, z, BlockData.Blocks.Air, false);
                else if (heightPercentage < 0.02)
                {
                    if (type == BIOME_TYPE.SNOW)
                    {
                        // To be sure that there's no snow above us
                        c.SetType(x, y + 1, z, BlockData.Blocks.Air, false);
                        c.SetType(x, y, z, BlockData.Blocks.Ice, false);
                    }
                    else
                        c.SetType(x, y, z, BlockData.Blocks.Still_Water, false);
                    
                }
            }
        }
예제 #13
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;

            }
        }
예제 #14
0
        protected void GenerateRiver(Chunk c, int x, int y, int z, double heightPercentage, BIOME_TYPE type, byte[] data)
        {
            // Rivers under water? Nope.
            if (y <= 63)
                return;

            double lakeIntens = CalcLakeIntensity(x + c.X * 16 , z + c.Z * 16);

            if (lakeIntens < 0.2 && heightPercentage < 0.015)
            {
                data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Air;
            }
            else if (lakeIntens < 0.2 && heightPercentage >= 0.015 && heightPercentage < 0.05)
            {
                if (type == BIOME_TYPE.SNOW)
                {
                    // To be sure that there's no snow above us
                    data[x << 11 | z << 7 | y + 1] = (byte)BlockData.Blocks.Air;
                    data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Ice;
                }
                else
                {
                    data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Still_Water;
                }
            }
        }
예제 #15
0
 private void GenerateInnerLayer(int x, int y, int z, BIOME_TYPE type, byte[] data)
 {
     data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Stone;
 }
예제 #16
0
        private void GenerateOuterLayer(int x, int y, int z, int firstBlockHeight, BIOME_TYPE type, Chunk c, byte[] data)
        {
            double heightPercentage = (firstBlockHeight - y) / 128.0;
            short currentIndex = (short)(x << 11 | z << 7 | y);

            switch (type)
            {
                case BIOME_TYPE.PLAINS:
                case BIOME_TYPE.MOUNTAINS:
                    // Beach
                    if (y >= 60 && y <= 66)
                    {
                        data[currentIndex] = (byte)BlockData.Blocks.Sand;
                        break;
                    }

                    if (heightPercentage == 0.0 && y > 66)
                    {
                        // Grass on top
                        data[currentIndex] = (byte)BlockData.Blocks.Grass;
                    }
                    else if (heightPercentage > 0.2)
                    {
                        // Stone
                        data[currentIndex] = (byte)BlockData.Blocks.Stone;
                    }
                    else
                    {
                        // Dirt
                        data[currentIndex] = (byte)BlockData.Blocks.Dirt;
                    }

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

                case BIOME_TYPE.SNOW:

                    if (heightPercentage == 0.0 && y > 65)
                    {
                        // Snow on top
                        data[currentIndex] = (byte)BlockData.Blocks.Snow;
                        // Grass under the snow
                        data[x << 11 | z << 7 | y - 1] = (byte)BlockData.Blocks.Grass;
                    }

                    else if (heightPercentage > 0.2)
                    {
                        // Stone
                        data[currentIndex] = (byte)BlockData.Blocks.Stone;
                    }
                    else if (data[x << 11 | z << 7 | (y + 1)] == (byte)BlockData.Blocks.Air)
                    {
                        // Grass under the snow
                        data[currentIndex] = (byte)BlockData.Blocks.Grass;
                        data[x << 11 | z << 7 | (y + 1)] = (byte)BlockData.Blocks.Snow;
                    }
                    else
                    {
                        // Dirt
                        data[currentIndex] = (byte)BlockData.Blocks.Dirt;
                    }

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

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

                    break;

            }
        }
예제 #17
0
        private void GenerateInnerLayer(int x, int y, int z, BIOME_TYPE type, IChunk c)
        {
            c.SetType(x, y, z, BlockData.Blocks.Stone, false);

        }