Ejemplo n.º 1
0
 public ChunkBase2(Vec2i position, float height, ChunkBiome biome)
 {
     Pos             = position;
     Height          = height;
     Biome           = biome;
     ResourceAmounts = new Dictionary <ChunkResource, float>();
 }
Ejemplo n.º 2
0
    public async Task <Chunk> GenerateChunkAsync(int cx, int cz, World world, Chunk chunk = null)
    {
        if (chunk is null)
        {
            chunk = new Chunk(cx, cz);
        }
        // Sanity check
        if (chunk.isGenerated)
        {
            return(chunk);
        }

        // Build terrain map for this chunk
        var terrainHeightmap = new double[16, 16];
        var rockHeightmap    = new double[16, 16];
        var bedrockHeightmap = new double[16, 16];

        for (int bx = 0; bx < 16; bx++)
        {
            for (int bz = 0; bz < 16; bz++)
            {
                int worldX = bx + (cx << 4);
                int worldZ = bz + (cz << 4);
                terrainHeightmap[bx, bz] = terrainGen.GetValue(worldX, worldZ);
                //chunk.Heightmaps[ChunkData.HeightmapType.MotionBlocking].Set(bx, bz, (int)terrainHeightmap[bx, bz]);
                //chunk.Heightmaps[ChunkData.HeightmapType.OceanFloor].Set(bx, bz, (int)terrainHeightmap[bx, bz]);
                rockHeightmap[bx, bz]    = terrainGen.GetValue(worldX, worldZ) - 5;
                bedrockHeightmap[bx, bz] = -30; // noiseGen.Bedrock(worldX, worldZ) + 1;

                // Determine Biome
                if (bx % 4 == 0 && bz % 4 == 0) // Biomes are in 4x4x4 blocks. Do a 2D array for now and just copy it vertically.
                {
                    var b = ChunkBiome.GetBiome(worldX, worldZ, terrainGen);
                    for (int y = -64; y < 320; y += 4)
                    {
                        chunk.SetBiome(bx, y, bz, b);
                    }
                }
            }
        }

        ChunkBuilder.FillChunk(chunk, terrainHeightmap, bedrockHeightmap);
        ChunkBuilder.CarveCaves(terrainGen, chunk, terrainHeightmap, bedrockHeightmap);
        await OverworldDecorator.DecorateAsync(chunk, terrainHeightmap, terrainGen, world);


        for (int bx = 0; bx < 16; bx++)
        {
            for (int bz = 0; bz < 16; bz++)
            {
                chunk.Heightmaps[ChunkData.HeightmapType.MotionBlocking].Set(bx, bz, (int)terrainHeightmap[bx, bz]);
            }
        }

        chunk.isGenerated = true;
        return(chunk);
    }
Ejemplo n.º 3
0
 public static void Decorate(Chunk chunk, double[,] terrainHeightMap, OverworldNoise noise)
 {
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var        b         = ChunkBiome.GetBiome((chunk.X << 4) + x, (chunk.Z << 4) + z, noise);
             IDecorator decorator = DecoratorFactory.GetDecorator(b);
             var        blockPos  = new Vector(x, (int)terrainHeightMap[x, z], z);
             decorator.Decorate(chunk, blockPos, noise);
         }
     }
 }
Ejemplo n.º 4
0
        public static void Decorate(Chunk chunk, double[,] terrainHeightMap, OverworldTerrain ot, World world)
        {
            var noise = new TerrainNoise(ot.settings);

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    var        b         = ChunkBiome.GetBiome((chunk.X << 4) + x, (chunk.Z << 4) + z, ot);
                    var        blockPos  = new Vector(x, (int)terrainHeightMap[x, z], z);
                    IDecorator decorator = DecoratorFactory.GetDecorator(b, chunk, blockPos, noise);
                    decorator.Decorate();
                    GenerateTrees(world, blockPos + (chunk.X << 4, 0, chunk.Z << 4), decorator.Features, noise);
                }
            }
        }
Ejemplo n.º 5
0
    public static Tile GetFromBiome(ChunkBiome b)
    {
        switch (b)
        {
        case ChunkBiome.dessert:
            return(Tile.SAND);

        case ChunkBiome.forrest:
            return(Tile.GRASS);

        case ChunkBiome.grassland:
            return(Tile.GRASS);

        case ChunkBiome.ocean:
            return(Tile.WATER);
        }
        return(Tile.TEST_MAGENTA);
    }
Ejemplo n.º 6
0
    public static float GetMovementCost(this ChunkBiome b)
    {
        switch (b)
        {
        case ChunkBiome.ocean:
            return(Mathf.Infinity);

        case ChunkBiome.mountain:
            return(4000);

        case ChunkBiome.grassland:
            return(2000);

        case ChunkBiome.dessert:
            return(3000);

        case ChunkBiome.forrest:
            return(3000);
        }
        return(500);
    }
Ejemplo n.º 7
0
    public static Color GetColor(this ChunkBiome b)
    {
        switch (b)
        {
        case ChunkBiome.ocean:
            return(Color.blue);

        case ChunkBiome.mountain:
            return(Color.grey);

        case ChunkBiome.grassland:
            return(Color.green);

        case ChunkBiome.dessert:
            return(Color.yellow);

        case ChunkBiome.forrest:
            return(new Color(0, 100 / 255f, 0));
        }
        return(Color.magenta);
    }
Ejemplo n.º 8
0
    private void CalculateEnclosedBiomes()
    {
        for (int x = 0; x < GridSize; x++)
        {
            for (int z = 0; z < GridSize; z++)
            {
                if (GridPoints[x, z] != null)
                {
                    Vec2i cPos = GridPoints[x, z].ChunkPos;
                    List <ChunkBiome>[] enc = new List <ChunkBiome> [16];
                    for (int i = 1; i < 16; i++)
                    {
                        enc[i] = new List <ChunkBiome>();
                        //Add all previous
                        if (i != 1)
                        {
                            enc[i].AddRange(enc[i - 1]);
                        }
                        for (int j = i - 1; j < i; j++)
                        {
                            Vec2i      c1 = cPos + new Vec2i(i - 1, j);
                            ChunkBiome b1 = GameGen.TerGen.ChunkBases[c1.x, c1.z].Biome;
                            Vec2i      c2 = cPos + new Vec2i(j, i - 1);
                            ChunkBiome b2 = GameGen.TerGen.ChunkBases[c2.x, c2.z].Biome;

                            if (!enc[i].Contains(b1))
                            {
                                enc[i].Add(b1);
                            }
                            if (!enc[i].Contains(b2))
                            {
                                enc[i].Add(b2);
                            }
                        }
                    }
                    GridPoints[x, z].EnclosedBiomes = enc;
                }
            }
        }
    }
Ejemplo n.º 9
0
        public override Chunk GenerateChunk(int cx, int cz)
        {
            var chunk = new Chunk(cx, cz);

            // Build terrain map for this chunk
            var terrainHeightmap = new double[16, 16];
            var rockHeightmap    = new double[16, 16];
            var bedrockHeightmap = new double[16, 16];

            for (int bx = 0; bx < 16; bx++)
            {
                for (int bz = 0; bz < 16; bz++)
                {
                    int worldX = bx + (cx << 4);
                    int worldZ = bz + (cz << 4);
                    terrainHeightmap[bx, bz] = noiseGen.Terrain(worldX, worldZ);
                    rockHeightmap[bx, bz]    = noiseGen.Underground(worldX, worldZ) + terrainHeightmap[bx, bz] - 5;
                    bedrockHeightmap[bx, bz] = noiseGen.Bedrock(worldX, worldZ) + 1;

                    // Determine Biome

                    if (bx % 4 == 0 && bz % 4 == 0) // Biomes are in 4x4x4 blocks. Do a 2D array for now and just copy it vertically.
                    {
                        var b = ChunkBiome.GetBiome(worldX, worldZ, noiseGen);
                        for (int y = 0; y < 256; y += 4)
                        {
                            chunk.BiomeContainer.SetBiome(bx, y, bz, b);
                        }
                    }
                }
            }

            ChunkBuilder.FillChunk(chunk, terrainHeightmap, rockHeightmap, bedrockHeightmap);
            OverworldDecorator.Decorate(chunk, terrainHeightmap, noiseGen);
            GenerateCoal(chunk, rockHeightmap);
            ChunkBuilder.CarveCaves(noiseGen, chunk, rockHeightmap, bedrockHeightmap);
            return(chunk);
        }
Ejemplo n.º 10
0
        public override Chunk GenerateChunk(int cx, int cz)
        {
            var chunk = new Chunk(cx, cz);

            // Build terrain map for this chunk
            var terrainHeightmap = new double[16, 16];
            var rockHeightmap    = new double[16, 16];
            var bedrockHeightmap = new double[16, 16];

            for (int bx = 0; bx < 16; bx++)
            {
                for (int bz = 0; bz < 16; bz++)
                {
                    int worldX = bx + (cx << 4);
                    int worldZ = bz + (cz << 4);
                    terrainHeightmap[bx, bz] = noiseGen.Terrain(worldX, worldZ);
                    chunk.Heightmaps[ChunkData.HeightmapType.WorldSurface].Set(bx, bz, (int)terrainHeightmap[bx, bz]);
                    chunk.Heightmaps[ChunkData.HeightmapType.OceanFloor].Set(bx, bz, noiseGen.OceanFloor(bx, bz));
                    rockHeightmap[bx, bz]    = noiseGen.Underground(worldX, worldZ) + terrainHeightmap[bx, bz] - 5;
                    bedrockHeightmap[bx, bz] = noiseGen.Bedrock(worldX, worldZ) + 1;

                    // Determine Biome
                    if (bx % 4 == 0 && bz % 4 == 0) // Biomes are in 4x4x4 blocks. Do a 2D array for now and just copy it vertically.
                    {
                        var b = ChunkBiome.GetBiome(worldX, worldZ, noiseGen);
                        for (int y = 0; y < 256; y += 4)
                        {
                            chunk.BiomeContainer.SetBiome(bx, y, bz, b);
                        }
                    }
                }
            }



            ChunkBuilder.FillChunk(chunk, terrainHeightmap, rockHeightmap, bedrockHeightmap);

            /*            for (int bx = 0; bx < 16; bx++)
             *          {
             *              for (int bz = 0; bz < 16; bz++)
             *              {
             *                  if (noiseGen.isRiver(bx + (cx * 16), bz + (cz * 16)))
             *                      chunk.SetBlock(bx, 106, bz, Registry.GetBlock(Materials.LightBlueStainedGlass));
             *
             *                  if (noiseGen.isMountain(bx + (cx * 16), bz + (cz * 16)))
             *                      chunk.SetBlock(bx, 105, bz, Registry.GetBlock(Materials.BlackStainedGlass));
             *
             *                  if (noiseGen.isHills(bx + (cx * 16), bz + (cz * 16)))
             *                      chunk.SetBlock(bx, 103, bz, Registry.GetBlock(Materials.GreenStainedGlass));
             *
             *                  if (noiseGen.isBadlands(bx + (cx * 16), bz + (cz * 16)))
             *                      chunk.SetBlock(bx, 104, bz, Registry.GetBlock(Materials.RedStainedGlass));
             *
             *                  if (noiseGen.isPlains(bx + (cx * 16), bz + (cz * 16)))
             *                      chunk.SetBlock(bx, 102, bz, Registry.GetBlock(Materials.WhiteStainedGlass));
             *
             *                  if (noiseGen.isOcean(bx + (cx * 16), bz + (cz * 16)))
             *                      chunk.SetBlock(bx, 101, bz, Registry.GetBlock(Materials.BlueStainedGlass));
             *
             *                  if (noiseGen.isDeepOcean(bx + (cx * 16), bz + (cz * 16)))
             *                      chunk.SetBlock(bx, 101, bz, Registry.GetBlock(Materials.BlueStainedGlass));
             *              }
             *          }*/

            OverworldDecorator.Decorate(chunk, terrainHeightmap, noiseGen);
            GenerateCoal(chunk, rockHeightmap);
            ChunkBuilder.CarveCaves(noiseGen, chunk, rockHeightmap, bedrockHeightmap);


            for (int bx = 0; bx < 16; bx++)
            {
                for (int bz = 0; bz < 16; bz++)
                {
                    chunk.Heightmaps[ChunkData.HeightmapType.MotionBlocking].Set(bx, bz, (int)terrainHeightmap[bx, bz]);
                }
            }
            return(chunk);
        }
Ejemplo n.º 11
0
    /// <summary>
    /// Generates the height map & biomes, + chunk resource details
    /// </summary>
    private void GenerateBaseTerrain()
    {
        //imulateWater();
        for (int x = 0; x < World.WorldSize; x++)
        {
            for (int z = 0; z < World.WorldSize; z++)
            {
                float height = GetChunkHeightAt(x, z);
                int   eqDist = Mathf.Abs(z - (World.WorldSize / 2));
                float temp   = Mathf.Exp(-eqDist / 100f) * 2f - height / 256f;
                float hum    = PerlinNoise(x, z, 2);

                ChunkBiome b = ChunkBiome.ocean;


                if (height > 100)
                {
                    b = ChunkBiome.mountain;
                }
                else if (height < WaterHeight)
                {
                    b = ChunkBiome.ocean;
                }
                else if ((temp > 0.4f && hum < 0.3f) || temp > 0.9f)
                {
                    b = ChunkBiome.dessert;
                }
                else if (temp > 0.4f & hum > 0.5f)
                {
                    b = ChunkBiome.forrest;
                }
                else
                {
                    b = ChunkBiome.grassland;
                }
                ChunkBases[x, z] = new ChunkBase2(new Vec2i(x, z), height, b);

                switch (b)
                {
                //Deserts and mountains are for mining
                case ChunkBiome.mountain:
                case ChunkBiome.dessert:
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.ironOre, PerlinNoise(x, z, 3));
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.silverOre, 0.4f * PerlinNoise(x, z, 4));
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.goldOre, 0.2f * PerlinNoise(x, z, 5));
                    break;

                case ChunkBiome.forrest:
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.wood, 1);
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.sheepFarm, PerlinNoise(x, z, 6));
                    break;

                case ChunkBiome.grassland:
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.sheepFarm, PerlinNoise(x, z, 7));
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.cattleFarm, PerlinNoise(x, z, 8));
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.wheatFarm, PerlinNoise(x, z, 9));
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.vegetableFarm, PerlinNoise(x, z, 10));
                    ChunkBases[x, z].SetResourceAmount(ChunkResource.silkFarm, PerlinNoise(x, z, 11));


                    break;
                }
            }
        }
    }
Ejemplo n.º 12
0
 public void SetBiome(ChunkBiome biome)
 {
     Biome = biome;
 }