Example #1
0
        private bool CoverIce(IChunk chunk, IBiomeRepository biomes, Coordinates3D location)
        {
            const int maxDistance = 4;
            var       adjacent    = new[]
            {
                location + new Coordinates3D(-maxDistance, 0, 0),
                location + new Coordinates3D(maxDistance, 0, 0),
                location + new Coordinates3D(0, 0, maxDistance),
                location + new Coordinates3D(0, 0, -maxDistance)
            };

            for (var i = 0; i < adjacent.Length; i++)
            {
                var check = adjacent[i];
                if (check.X < 0 || check.X >= Chunk.Width || check.Z < 0 || check.Z >= Chunk.Depth || check.Y < 0 ||
                    check.Y >= Chunk.Height)
                {
                    return(false);
                }
                var biome = biomes.GetBiome(chunk.Biomes[check.X * Chunk.Width + check.Z]);
                if (chunk.GetBlockID(check).Equals(biome.SurfaceBlock) ||
                    chunk.GetBlockID(check).Equals(biome.FillerBlock))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     var noise = new Perlin();
     noise.Seed = world.Seed;
     var chanceNoise = new ClampNoise(noise);
     chanceNoise.MaxValue = 2;
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
             var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
             var height = chunk.HeightMap[x * Chunk.Width + z];
             if (biome.Plants.Contains(PlantSpecies.Cactus) && chanceNoise.Value2D(blockX, blockZ) > 1.7)
             {
                 var blockLocation = new Coordinates3D(x, height, z);
                 var cactiPosition = blockLocation + Coordinates3D.Up;
                 if (chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockID))
                 {
                     var HeightChance = chanceNoise.Value2D(blockX, blockZ);
                     var CactusHeight = (HeightChance < 1.4) ? 2 : 3;
                     Decoration.GenerateColumn(chunk, cactiPosition, CactusHeight, CactusBlock.BlockID);
                 }
             }
         }
     }
 }
Example #3
0
 public byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location)
 {
     double temp = Math.Abs(TempNoise.Value2D(location.X, location.Z));
     double rainfall = Math.Abs(RainNoise.Value2D(location.X, location.Z));
     byte ID = biomes.GetBiome(temp, rainfall).ID;
     return ID;
 }
Example #4
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            var noise = new Perlin();

            noise.Seed = world.Seed;
            var chanceNoise = new ClampNoise(noise);

            chanceNoise.MaxValue = 2;
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    var height = chunk.HeightMap[x * Chunk.Width + z];
                    if (biome.Plants.Contains(PlantSpecies.Cactus) && chanceNoise.Value2D(blockX, blockZ) > 1.7)
                    {
                        var blockLocation = new Coordinates3D(x, height, z);
                        var cactiPosition = blockLocation + Coordinates3D.Up;
                        if (chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockID))
                        {
                            var HeightChance = chanceNoise.Value2D(blockX, blockZ);
                            var CactusHeight = (HeightChance < 1.4) ? 2 : 3;
                            Decoration.GenerateColumn(chunk, cactiPosition, CactusHeight, CactusBlock.BlockID);
                        }
                    }
                }
            }
        }
Example #5
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            for (int attempts = 0; attempts < 8; attempts++)
            {
                var noise = new Perlin();
                noise.Seed = world.Seed - (chunk.Coordinates.X + chunk.Coordinates.Z);
                var offsetNoise = new ClampNoise(noise);
                offsetNoise.MaxValue = 3;
                var x = 0;
                var z = 0;
                var offset = 0.0;
                offset += offsetNoise.Value2D(x, z);
                int finalX = (int)Math.Floor(x + offset);
                int finalZ = (int)Math.Floor(z + offset);
                var y = (int)(10 + offset);

                var blockX = MathHelper.ChunkToBlockX(finalX, chunk.Coordinates.X);
                var blockZ = MathHelper.ChunkToBlockZ(finalZ, chunk.Coordinates.Z);
                var spawnValue = offsetNoise.Value2D(blockX, blockZ);
                if (spawnValue > 1.95 && spawnValue < 2.09)
                {
                    var generated = new Dungeon().GenerateAt(world, chunk, new Coordinates3D(blockX, y, blockZ));
                    if (generated)
                        break;
                }
            }
        }
Example #6
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            for (int attempts = 0; attempts < 8; attempts++)
            {
                var noise       = new Perlin(world.Seed - (chunk.Coordinates.X + chunk.Coordinates.Z));
                var offsetNoise = new ClampNoise(noise);
                offsetNoise.MaxValue = 3;
                var x      = 0;
                var z      = 0;
                var offset = 0.0;
                offset += offsetNoise.Value2D(x, z);
                int finalX = (int)Math.Floor(x + offset);
                int finalZ = (int)Math.Floor(z + offset);
                var y      = (int)(10 + offset);

                var blockX     = MathHelper.ChunkToBlockX(finalX, chunk.Coordinates.X);
                var blockZ     = MathHelper.ChunkToBlockZ(finalZ, chunk.Coordinates.Z);
                var spawnValue = offsetNoise.Value2D(blockX, blockZ);
                if (spawnValue > 1.95 && spawnValue < 2.09)
                {
                    var generated = new Dungeon().GenerateAt(world, chunk, new Coordinates3D(blockX, y, blockZ));
                    if (generated)
                    {
                        break;
                    }
                }
            }
        }
Example #7
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            var noise       = new Perlin(world.Seed);
            var chanceNoise = new ClampNoise(noise);

            chanceNoise.MaxValue = 2;
            for (var x = 0; x < 16; x++)
            {
                for (var z = 0; z < 16; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    var height = chunk.HeightMap[x * Chunk.Width + z];
                    if (noise.Value2D(blockX, blockZ) > 0)
                    {
                        var blockLocation = new Coordinates3D(x, height, z);
                        var plantPosition = blockLocation + Coordinates3D.Up;
                        if (chunk.GetBlockID(blockLocation) == biome.SurfaceBlock && plantPosition.Y < Chunk.Height)
                        {
                            var chance = chanceNoise.Value2D(blockX, blockZ);
                            if (chance < 1)
                            {
                                var bushNoise  = chanceNoise.Value2D(blockX * 0.7, blockZ * 0.7);
                                var grassNoise = chanceNoise.Value2D(blockX * 0.3, blockZ * 0.3);
                                if (biome.Plants.Contains(PlantSpecies.Deadbush) && bushNoise > 1 &&
                                    chunk.GetBlockID(blockLocation) == SandBlock.BlockId)
                                {
                                    GenerateDeadBush(chunk, plantPosition);
                                    continue;
                                }

                                if (biome.Plants.Contains(PlantSpecies.TallGrass) && grassNoise > 0.3 && grassNoise < 0.95)
                                {
                                    var meta = grassNoise > 0.3 && grassNoise < 0.45 &&
                                               biome.Plants.Contains(PlantSpecies.Fern)
                                                                        ? (byte)0x2
                                                                        : (byte)0x1;
                                    GenerateTallGrass(chunk, plantPosition, meta);
                                }
                            }
                            else
                            {
                                var flowerTypeNoise = chanceNoise.Value2D(blockX * 1.2, blockZ * 1.2);
                                if (biome.Plants.Contains(PlantSpecies.Rose) && flowerTypeNoise > 0.8 &&
                                    flowerTypeNoise < 1.5)
                                {
                                    GenerateRose(chunk, plantPosition);
                                }
                                else if (biome.Plants.Contains(PlantSpecies.Dandelion) && flowerTypeNoise <= 0.8)
                                {
                                    GenerateDandelion(chunk, plantPosition);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        public byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location, bool spawn)
        {
            var temp     = Math.Abs(TempNoise.Value2D(location.X, location.Z));
            var rainfall = Math.Abs(RainNoise.Value2D(location.X, location.Z));
            var Id       = biomes.GetBiome(temp, rainfall, spawn).Id;

            return(Id);
        }
Example #9
0
        public byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location)
        {
            double temp     = Math.Abs(TempNoise.Value2D(location.X, location.Z));
            double rainfall = Math.Abs(RainNoise.Value2D(location.X, location.Z));
            byte   ID       = biomes.GetBiome(temp, rainfall).ID;

            return(ID);
        }
Example #10
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     var noise = new Perlin();
     noise.Seed = world.Seed;
     var chanceNoise = new ClampNoise(noise);
     chanceNoise.MaxValue = 2;
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
             var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
             var height = chunk.HeightMap[x * Chunk.Width + z];
             if (noise.Value2D(blockX, blockZ) > 0)
             {
                 var blockLocation = new Coordinates3D(x, height, z);
                 var plantPosition = blockLocation + Coordinates3D.Up;
                 if (chunk.GetBlockID(blockLocation) == biome.SurfaceBlock && plantPosition.Y < Chunk.Height)
                 {
                     var chance = chanceNoise.Value2D(blockX, blockZ);
                     if (chance < 1)
                     {
                         var bushNoise = chanceNoise.Value2D(blockX * 0.7, blockZ * 0.7);
                         var grassNoise = chanceNoise.Value2D(blockX * 0.3, blockZ * 0.3);
                         if (biome.Plants.Contains(PlantSpecies.Deadbush) && bushNoise > 1 && chunk.GetBlockID(blockLocation) == SandBlock.BlockID)
                         {
                             GenerateDeadBush(chunk, plantPosition);
                             continue;
                         }
                         
                         if (biome.Plants.Contains(PlantSpecies.TallGrass) && grassNoise > 0.3 && grassNoise < 0.95)
                         {
                             byte meta = (grassNoise > 0.3 && grassNoise < 0.45 && biome.Plants.Contains(PlantSpecies.Fern)) ? (byte)0x2 : (byte)0x1;
                             GenerateTallGrass(chunk, plantPosition, meta);
                             continue;
                         }
                     }
                     else
                     {
                         var flowerTypeNoise = chanceNoise.Value2D(blockX * 1.2, blockZ * 1.2);
                         if (biome.Plants.Contains(PlantSpecies.Rose) && flowerTypeNoise > 0.8 && flowerTypeNoise < 1.5)
                         {
                             GenerateRose(chunk, plantPosition);
                         }
                         else if (biome.Plants.Contains(PlantSpecies.Dandelion) && flowerTypeNoise <= 0.8)
                         {
                             GenerateDandelion(chunk, plantPosition);
                         }
                     }
                 }
             }
         }
     }
 }
Example #11
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            for (var x = 0; x < Chunk.Width; x++)
            {
                for (var z = 0; z < Chunk.Depth; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var height = chunk.HeightMap[x * Chunk.Width + z];
                    for (var y = height; y <= WaterLevel; y++)
                    {
                        var blockLocation = new Coordinates3D(x, y, z);
                        int blockId       = chunk.GetBlockID(blockLocation);
                        if (blockId.Equals(AirBlock.BlockId))
                        {
                            chunk.SetBlockID(blockLocation, biome.WaterBlock);
                            var below = blockLocation + Coordinates3D.Down;
                            if (!chunk.GetBlockID(below).Equals(AirBlock.BlockId) &&
                                !chunk.GetBlockID(below).Equals(biome.WaterBlock))
                            {
                                if (!biome.WaterBlock.Equals(LavaBlock.BlockId) &&
                                    !biome.WaterBlock.Equals(StationaryLavaBlock.BlockId))
                                {
                                    var random = new Random(world.Seed);
                                    if (random.Next(100) < 40)
                                    {
                                        chunk.SetBlockID(below, ClayBlock.BlockId);
                                    }
                                    else
                                    {
                                        chunk.SetBlockID(below, SandBlock.BlockId);
                                    }
                                }
                            }
                        }
                    }

                    for (var y = 4; y < height / 8; y++)
                    {
                        var blockLocation = new Coordinates3D(x, y, z);
                        int blockId       = chunk.GetBlockID(blockLocation);
                        if (blockId.Equals(AirBlock.BlockId))
                        {
                            chunk.SetBlockID(blockLocation, LavaBlock.BlockId);
                        }
                    }
                }
            }
        }
Example #12
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     for (var x = 0; x < 16; x++)
     {
         for (var z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             if (biome.Temperature < 0.15)
             {
                 var height = chunk.HeightMap[x * Chunk.Width + z];
                 for (var y = height; y < Chunk.Height; y++)
                 {
                     var location = new Coordinates3D(x, y, z);
                     if (chunk.GetBlockID(location).Equals(StationaryWaterBlock.BlockId) ||
                         chunk.GetBlockID(location).Equals(WaterBlock.BlockId))
                     {
                         chunk.SetBlockID(location, IceBlock.BlockId);
                     }
                     else
                     {
                         var    below     = chunk.GetBlockID(location);
                         byte[] whitelist =
                         {
                             DirtBlock.BlockId,
                             GrassBlock.BlockId,
                             IceBlock.BlockId,
                             LeavesBlock.BlockId
                         };
                         if (y == height && whitelist.Any(w => w == below))
                         {
                             if (chunk.GetBlockID(location).Equals(IceBlock.BlockId) &&
                                 CoverIce(chunk, biomes, location))
                             {
                                 chunk.SetBlockID(location + Coordinates3D.Up, SnowfallBlock.BlockId);
                             }
                             else if (!chunk.GetBlockID(location).Equals(SnowfallBlock.BlockId) &&
                                      !chunk.GetBlockID(location).Equals(AirBlock.BlockId))
                             {
                                 chunk.SetBlockID(location + Coordinates3D.Up, SnowfallBlock.BlockId);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #13
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     for (int x = 0; x < Chunk.Width; x++)
     {
         for (int z = 0; z < Chunk.Depth; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             var height = chunk.HeightMap[x * Chunk.Width + z];
             for (int y = height; y <= WaterLevel; y++)
             {
                 var blockLocation = new Coordinates3D(x, y, z);
                 int blockId = chunk.GetBlockID(blockLocation);
                 if (blockId.Equals(AirBlock.BlockID))
                 {
                     chunk.SetBlockID(blockLocation, biome.WaterBlock);
                     var below = blockLocation + Coordinates3D.Down;
                     if (!chunk.GetBlockID(below).Equals(AirBlock.BlockID) && !chunk.GetBlockID(below).Equals(biome.WaterBlock))
                     {
                         if (!biome.WaterBlock.Equals(LavaBlock.BlockID) && !biome.WaterBlock.Equals(StationaryLavaBlock.BlockID))
                         {
                             var random = new Random(world.Seed);
                             if (random.Next(100) < 40)
                             {
                                 chunk.SetBlockID(below, ClayBlock.BlockID);
                             }
                             else
                             {
                                 chunk.SetBlockID(below, SandBlock.BlockID);
                             }
                         }
                     }
                 }
             }
             for (int y = 4; y < height / 8; y++)
             {
                 var blockLocation = new Coordinates3D(x, y, z);
                 int blockId = chunk.GetBlockID(blockLocation);
                 if (blockId.Equals(AirBlock.BlockID))
                 {
                     chunk.SetBlockID(blockLocation, LavaBlock.BlockID);
                 }
             }
         }
     }
 }
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            var noise       = new Perlin(world.Seed);
            var chanceNoise = new ClampNoise(noise);

            chanceNoise.MaxValue = 1;
            for (var x = 0; x < 16; x++)
            {
                for (var z = 0; z < 16; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var height = chunk.HeightMap[x * Chunk.Width + z];
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    if (biome.Plants.Contains(PlantSpecies.SugarCane))
                    {
                        if (noise.Value2D(blockX, blockZ) > 0.65)
                        {
                            var blockLocation     = new Coordinates3D(x, height, z);
                            var sugarCaneLocation = blockLocation + Coordinates3D.Up;
                            var neighborsWater    = Decoration.NeighboursBlock(chunk, blockLocation, WaterBlock.BlockId) ||
                                                    Decoration.NeighboursBlock(chunk, blockLocation,
                                                                               StationaryWaterBlock.BlockId);
                            if (chunk.GetBlockID(blockLocation).Equals(GrassBlock.BlockId) && neighborsWater ||
                                chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockId) && neighborsWater)
                            {
                                var random       = new Random(world.Seed);
                                var heightChance = random.NextDouble();
                                var caneHeight   = 3;
                                if (heightChance < 0.05)
                                {
                                    caneHeight = 4;
                                }
                                else if (heightChance > 0.1 && height < 0.25)
                                {
                                    caneHeight = 2;
                                }
                                Decoration.GenerateColumn(chunk, sugarCaneLocation, caneHeight, SugarcaneBlock.BlockId);
                            }
                        }
                    }
                }
            }
        }
Example #15
0
 bool CoverIce(IChunk chunk, IBiomeRepository biomes, Coordinates3D location)
 {
     const int maxDistance = 4;
     var adjacent = new[] {
         location + new Coordinates3D(-maxDistance, 0, 0),
         location + new Coordinates3D(maxDistance, 0, 0),
         location + new Coordinates3D(0, 0, maxDistance),
         location + new Coordinates3D(0, 0, -maxDistance),
     };
     for (int i = 0; i < adjacent.Length; i++)
     {
         var check = adjacent[i];
         if (check.X < 0 || check.X >= Chunk.Width || check.Z < 0 || check.Z >= Chunk.Depth || check.Y < 0 || check.Y >= Chunk.Height)
             return false;
         var biome = biomes.GetBiome(chunk.Biomes[check.X * Chunk.Width + check.Z]);
         if (chunk.GetBlockID(check).Equals(biome.SurfaceBlock) || chunk.GetBlockID(check).Equals(biome.FillerBlock))
             return true;
     }
     return false;
 }
Example #16
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             if (biome.Temperature < 0.15)
             {
                 var height = chunk.HeightMap[x * Chunk.Width + z];
                 for (int y = height; y < Chunk.Height; y++)
                 {
                     var location = new Coordinates3D(x, y, z);
                     if (chunk.GetBlockID(location).Equals(StationaryWaterBlock.BlockID) || chunk.GetBlockID(location).Equals(WaterBlock.BlockID))
                         chunk.SetBlockID(location, IceBlock.BlockID);
                     else
                     {
                         var below = chunk.GetBlockID(location);
                         byte[] whitelist =
                         {
                             DirtBlock.BlockID,
                             GrassBlock.BlockID,
                             IceBlock.BlockID,
                             LeavesBlock.BlockID
                         };
                         if (y == height && whitelist.Any(w => w == below))
                         {
                             if (chunk.GetBlockID(location).Equals(IceBlock.BlockID) && CoverIce(chunk, biomes, location))
                                 chunk.SetBlockID((location + Coordinates3D.Up), SnowfallBlock.BlockID);
                             else if (!chunk.GetBlockID(location).Equals(SnowfallBlock.BlockID) && !chunk.GetBlockID(location).Equals(AirBlock.BlockID))
                                 chunk.SetBlockID((location + Coordinates3D.Up), SnowfallBlock.BlockID);
                         }
                     }
                 }
             }
         }
     }
 }
Example #17
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     var noise = new Perlin();
     noise.Seed = world.Seed;
     var chanceNoise = new ClampNoise(noise);
     chanceNoise.MaxValue = 1;
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             var height = chunk.HeightMap[x * Chunk.Width + z];
             var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
             var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
             if (biome.Plants.Contains(PlantSpecies.SugarCane))
             {
                 if (noise.Value2D(blockX, blockZ) > 0.65)
                 {
                     var blockLocation = new Coordinates3D(x, height, z);
                     var sugarCaneLocation = blockLocation + Coordinates3D.Up;
                     var neighborsWater = Decoration.NeighboursBlock(chunk, blockLocation, WaterBlock.BlockID) || Decoration.NeighboursBlock(chunk, blockLocation, StationaryWaterBlock.BlockID);
                     if (chunk.GetBlockID(blockLocation).Equals(GrassBlock.BlockID) && neighborsWater || chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockID) && neighborsWater)
                     {
                         var random = new Random(world.Seed);
                         double heightChance = random.NextDouble();
                         int caneHeight = 3;
                         if (heightChance < 0.05)
                             caneHeight = 4;
                         else if (heightChance > 0.1 && height < 0.25)
                             caneHeight = 2;
                         Decoration.GenerateColumn(chunk, sugarCaneLocation, caneHeight, SugarcaneBlock.BlockID);
                     }
                 }
             }
         }
     }
 }
Example #18
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            //Test Seed: 291887241
            var perlin = new Perlin();
            perlin.Lacunarity = 1;
            perlin.Amplitude = 7;
            perlin.Frequency = 0.015;
            perlin.Seed = world.Seed;
            var chanceNoise = new ClampNoise(perlin);
            var noise = new ScaledNoise(perlin);
            var random = new Random(world.Seed);
            var lowWeightOffset = new int[2] { 2, 3 };
            var highWeightOffset = new int[2] { 2, 2 };
            foreach (var data in Ores)
            {
                var midpoint = (data.MaxY + data.MinY) / 2;
                var weightOffsets = (data.MaxY > 30) ? highWeightOffset : lowWeightOffset;
                const int weightPasses = 4;
                for (int i = 0; i < data.Veins; i++)
                {
                    double weight = 0;
                    for (int j = 0; j < weightPasses; j++)
                    {
                        weight += random.NextDouble();
                    }
                    weight /= data.Rarity;
                    weight = weightOffsets[0] - Math.Abs(weight - weightOffsets[1]);
                    double x = random.Next(0, Chunk.Width);
                    double z = random.Next(0, Chunk.Depth);
                    double y = weight * midpoint;

                    double randomOffsetX = (float)random.NextDouble() - 1;
                    double randomOffsetY = (float)random.NextDouble() - 1;
                    double randomOffsetZ = (float)random.NextDouble() - 1;

                    int abundance = random.Next(0, data.Abundance);
                    for (int k = 0; k < abundance; k++)
                    {
                        x += randomOffsetX;
                        y += randomOffsetY;
                        z += randomOffsetZ;
                        if (x >= 0 && z >= 0 && y >= data.MinY && x < Chunk.Width && y < data.MaxY && z < Chunk.Depth)
                        {
                            var biome = biomes.GetBiome(chunk.Biomes[(int)(x * Chunk.Width + z)]);
                            if (biome.Ores.Contains(data.Type) && chunk.GetBlockID(new Coordinates3D((int)x, (int)y, (int)z)).Equals(StoneBlock.BlockID))
                                chunk.SetBlockID(new Coordinates3D((int)x, (int)y, (int)z), data.ID);
                        }
                        var blockX = MathHelper.ChunkToBlockX((int)(x), chunk.Coordinates.X);
                        var blockZ = MathHelper.ChunkToBlockZ((int)(z), chunk.Coordinates.Z);

                        double offsetX = 0;
                        double offsetY = 0;
                        double offsetZ = 0;
                        int offset = random.Next(0, 3);
                        double offset2 = random.NextDouble();

                        if (offset.Equals(0) && offset2 < 0.4)
                            offsetX += 1;
                        else if (offset.Equals(1) && offset2 >= 0.4 && offset2 < 0.65)
                            offsetY += 1;
                        else
                            offsetZ += 1;

                        var newX = (int)(x + offsetX);
                        var newY = (int)(y + offsetY);
                        var newZ = (int)(z + offsetZ);
                        if (newX >= 0 && newZ >= 0 && newY >= data.MinY && newX < Chunk.Width && newY < data.MaxY && newZ < Chunk.Depth)
                        {
                            IBiomeProvider Biome = biomes.GetBiome(chunk.Biomes[newX * Chunk.Width + newZ]);
                            var coordinates = new Coordinates3D((int)newX, (int)newY, (int)newZ);
                            if (Biome.Ores.Contains(data.Type) && chunk.GetBlockID(coordinates).Equals(StoneBlock.BlockID))
                            {
                                chunk.SetBlockID(coordinates, data.ID);
                            }
                        }
                    }
                }
            }
        }
Example #19
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            Noise = new Perlin();
            Noise.Seed = world.Seed;
            ChanceNoise = new ClampNoise(Noise);
            ChanceNoise.MaxValue = 2;
            Coordinates2D? lastTree = null;
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    var height = chunk.HeightMap[x * Chunk.Width + z];

                    if (lastTree != null && lastTree.Value.DistanceTo(new Coordinates2D(x, z)) < biome.TreeDensity)
                        continue;

                    if (Noise.Value2D(blockX, blockZ) > 0.3)
                    {
                        var location = new Coordinates3D(x, height, z);
                        var id = chunk.GetBlockID(location);
                        var provider = world.BlockRepository.GetBlockProvider(id);
                        if (id == DirtBlock.BlockID || id == GrassBlock.BlockID || id == SnowfallBlock.BlockID
                            || (id != StationaryWaterBlock.BlockID && id != WaterBlock.BlockID
                                && id != LavaBlock.BlockID && id != StationaryLavaBlock.BlockID
                                && provider.BoundingBox == null))
                        {
                            if (provider.BoundingBox == null)
                                location.Y--;
                            var oakNoise = ChanceNoise.Value2D(blockX * 0.6, blockZ * 0.6);
                            var birchNoise = ChanceNoise.Value2D(blockX * 0.2, blockZ * 0.2);
                            var spruceNoise = ChanceNoise.Value2D(blockX * 0.35, blockZ * 0.35);

                            var baseCoordinates = location + Coordinates3D.Up;
                            if (biome.Trees.Contains(TreeSpecies.Oak) && oakNoise > 1.01 && oakNoise < 1.25)
                            {
                                var oak = new OakTree().GenerateAt(world, chunk, baseCoordinates);
                                if (oak)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Birch) && birchNoise > 0.3 && birchNoise < 0.95)
                            {
                                var birch = new BirchTree().GenerateAt(world, chunk, baseCoordinates);
                                if (birch)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Spruce) && spruceNoise < 0.75)
                            {
                                var random = new Random(world.Seed);
                                var type = random.Next(1, 2);
                                var generated = false;
                                if (type.Equals(1))
                                    generated = new PineTree().GenerateAt(world, chunk, baseCoordinates);
                                else
                                    generated = new ConiferTree().GenerateAt(world, chunk, baseCoordinates);

                                if (generated)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #20
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            Noise                = new Perlin(world.Seed);
            ChanceNoise          = new ClampNoise(Noise);
            ChanceNoise.MaxValue = 2;
            Coordinates2D?lastTree = null;

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    var height = chunk.HeightMap[x * Chunk.Width + z];

                    if (lastTree != null && lastTree.Value.DistanceTo(new Coordinates2D(x, z)) < biome.TreeDensity)
                    {
                        continue;
                    }

                    if (Noise.Value2D(blockX, blockZ) > 0.3)
                    {
                        var location = new Coordinates3D(x, height, z);
                        var id       = chunk.GetBlockID(location);
                        var provider = world.BlockRepository.GetBlockProvider(id);
                        if (id == DirtBlock.BlockID || id == GrassBlock.BlockID || id == SnowfallBlock.BlockID ||
                            (id != StationaryWaterBlock.BlockID && id != WaterBlock.BlockID &&
                             id != LavaBlock.BlockID && id != StationaryLavaBlock.BlockID &&
                             provider.BoundingBox == null))
                        {
                            if (provider.BoundingBox == null)
                            {
                                location.Y--;
                            }
                            var oakNoise    = ChanceNoise.Value2D(blockX * 0.6, blockZ * 0.6);
                            var birchNoise  = ChanceNoise.Value2D(blockX * 0.2, blockZ * 0.2);
                            var spruceNoise = ChanceNoise.Value2D(blockX * 0.35, blockZ * 0.35);

                            var baseCoordinates = location + Coordinates3D.Up;
                            if (biome.Trees.Contains(TreeSpecies.Oak) && oakNoise > 1.01 && oakNoise < 1.25)
                            {
                                var oak = new OakTree().GenerateAt(world, chunk, baseCoordinates);
                                if (oak)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Birch) && birchNoise > 0.3 && birchNoise < 0.95)
                            {
                                var birch = new BirchTree().GenerateAt(world, chunk, baseCoordinates);
                                if (birch)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Spruce) && spruceNoise < 0.75)
                            {
                                var random    = new Random(world.Seed);
                                var type      = random.Next(1, 2);
                                var generated = false;
                                if (type.Equals(1))
                                {
                                    generated = new PineTree().GenerateAt(world, chunk, baseCoordinates);
                                }
                                else
                                {
                                    generated = new ConiferTree().GenerateAt(world, chunk, baseCoordinates);
                                }

                                if (generated)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #21
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            var perlin = new Perlin(world.Seed);

            perlin.Lacunarity = 1;
            perlin.Amplitude  = 7;
            perlin.Frequency  = 0.015;
            var chanceNoise     = new ClampNoise(perlin);
            var noise           = new ScaledNoise(perlin);
            var random          = new Random(world.Seed);
            var lowWeightOffset = new int[2] {
                2, 3
            };
            var highWeightOffset = new int[2] {
                2, 2
            };

            foreach (var data in Ores)
            {
                var       midpoint      = (data.MaxY + data.MinY) / 2;
                var       weightOffsets = data.MaxY > 30 ? highWeightOffset : lowWeightOffset;
                const int weightPasses  = 4;
                for (var i = 0; i < data.Veins; i++)
                {
                    double weight = 0;
                    for (var j = 0; j < weightPasses; j++)
                    {
                        weight += random.NextDouble();
                    }
                    weight /= data.Rarity;
                    weight  = weightOffsets[0] - Math.Abs(weight - weightOffsets[1]);
                    double x = random.Next(0, Chunk.Width);
                    double z = random.Next(0, Chunk.Depth);
                    var    y = weight * midpoint;

                    double randomOffsetX = (float)random.NextDouble() - 1;
                    double randomOffsetY = (float)random.NextDouble() - 1;
                    double randomOffsetZ = (float)random.NextDouble() - 1;

                    var abundance = random.Next(0, data.Abundance);
                    for (var k = 0; k < abundance; k++)
                    {
                        x += randomOffsetX;
                        y += randomOffsetY;
                        z += randomOffsetZ;
                        if (x >= 0 && z >= 0 && y >= data.MinY && x < Chunk.Width && y < data.MaxY && z < Chunk.Depth)
                        {
                            var biome = biomes.GetBiome(chunk.Biomes[(int)(x * Chunk.Width + z)]);
                            if (biome.Ores.Contains(data.Type) && chunk
                                .GetBlockID(new Coordinates3D((int)x, (int)y, (int)z))
                                .Equals(StoneBlock.BlockId))
                            {
                                chunk.SetBlockID(new Coordinates3D((int)x, (int)y, (int)z), data.Id);
                            }
                        }

                        var blockX = MathHelper.ChunkToBlockX((int)x, chunk.Coordinates.X);
                        var blockZ = MathHelper.ChunkToBlockZ((int)z, chunk.Coordinates.Z);

                        double offsetX = 0;
                        double offsetY = 0;
                        double offsetZ = 0;
                        var    offset  = random.Next(0, 3);
                        var    offset2 = random.NextDouble();

                        if (offset.Equals(0) && offset2 < 0.4)
                        {
                            offsetX += 1;
                        }
                        else if (offset.Equals(1) && offset2 >= 0.4 && offset2 < 0.65)
                        {
                            offsetY += 1;
                        }
                        else
                        {
                            offsetZ += 1;
                        }

                        var newX = (int)(x + offsetX);
                        var newY = (int)(y + offsetY);
                        var newZ = (int)(z + offsetZ);
                        if (newX >= 0 && newZ >= 0 && newY >= data.MinY && newX < Chunk.Width && newY < data.MaxY &&
                            newZ < Chunk.Depth)
                        {
                            var Biome       = biomes.GetBiome(chunk.Biomes[newX * Chunk.Width + newZ]);
                            var coordinates = new Coordinates3D(newX, newY, newZ);
                            if (Biome.Ores.Contains(data.Type) &&
                                chunk.GetBlockID(coordinates).Equals(StoneBlock.BlockId))
                            {
                                chunk.SetBlockID(coordinates, data.Id);
                            }
                        }
                    }
                }
            }
        }