Exemplo n.º 1
0
        public static void CreateCliffsLand(GraphicsDevice graphicsDevice)
        {
            int size = 512;

            Map = new MapData[size, size];

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    float height = ComputeHeight(x * 1.0f, y * 2.0f, size, size, 1.0f, false);
                    float level  = (int)(height / 0.15f) * 0.15f + 0.08f;


                    Map[x, y].Height      = level;
                    Map[x, y].Biome       = BiomeLibrary.GetBiome("DeciduousForest").Biome;
                    Map[x, y].Erosion     = 1.0f;
                    Map[x, y].Weathering  = 0;
                    Map[x, y].Faults      = 1.0f;
                    Map[x, y].Temperature = 0.6f;
                    Map[x, y].Rainfall    = 0.6f;
                }
            }

            Overworld.Name = "Cliffs_" + MathFunctions.Random.Next(9999);
        }
Exemplo n.º 2
0
        public static void CreateOceanLand(GraphicsDevice graphicsDevice, float seaLevel)
        {
            int size = 512;

            Map = new MapData[size, size];

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    Map[x, y].Biome       = BiomeLibrary.GetBiome("Grassland").Biome;
                    Map[x, y].Erosion     = 1.0f;
                    Map[x, y].Weathering  = 0;
                    Map[x, y].Faults      = 1.0f;
                    Map[x, y].Temperature = size;
                    Map[x, y].Rainfall    = size;
                    Map[x, y].Height      = 0.05f; //ComputeHeight(x, y, size0, size0, 5.0f, false);
                }
            }

            Overworld.Name = "ocean_" + MathFunctions.Random.Next(9999);
        }
Exemplo n.º 3
0
        public void GenerateCaves(VoxelChunk chunk, WorldManager world)
        {
            if (CaveLevels == null)
            {
                CaveLevels = new List <int>();
                var caveStep = 48 / world.GenerationSettings.NumCaveLayers;

                for (var i = 0; i < world.GenerationSettings.NumCaveLayers; ++i)
                {
                    CaveLevels.Add(4 + (caveStep * i));
                }
            }

            Vector3   origin    = chunk.Origin;
            BiomeData biome     = BiomeLibrary.GetBiome("Cave");
            var       hellBiome = BiomeLibrary.GetBiome("Hell");

            for (int x = 0; x < VoxelConstants.ChunkSizeX; x++)
            {
                for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++)
                {
                    var topVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle(
                                                                        chunk, new LocalVoxelCoordinate(x, VoxelConstants.ChunkSizeY - 1, z)));

                    for (int i = 0; i < CaveLevels.Count; i++)
                    {
                        int y = CaveLevels[i];
                        if (y <= 0 || y >= topVoxel.Coordinate.Y)
                        {
                            continue;
                        }

                        var frequency = i < CaveFrequencies.Count ? CaveFrequencies[i] : CaveFrequencies[CaveFrequencies.Count - 1];
                        var caveBiome = (y <= HellLevel) ? hellBiome : biome;

                        Vector3 vec       = new Vector3(x, y, z) + chunk.Origin;
                        double  caveNoise = CaveNoise.GetValue((x + origin.X) * CaveNoiseScale * frequency,
                                                               (y + origin.Y) * CaveNoiseScale * 3.0f, (z + origin.Z) * CaveNoiseScale * frequency);

                        double heightnoise = NoiseGenerator.Noise((x + origin.X) * NoiseScale * frequency,
                                                                  (y + origin.Y) * NoiseScale * 3.0f, (z + origin.Z) * NoiseScale * frequency);

                        int caveHeight = Math.Min(Math.Max((int)(heightnoise * 5), 1), 3);

                        if (!(caveNoise > CaveSize))
                        {
                            continue;
                        }

                        bool invalidCave = false;
                        for (int dy = 0; dy < caveHeight; dy++)
                        {
                            if (y - dy <= 0)
                            {
                                continue;
                            }

                            var voxel = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y - dy, z));

                            foreach (var coord in VoxelHelpers.EnumerateAllNeighbors(voxel.Coordinate))
                            {
                                VoxelHandle v = new VoxelHandle(Manager.ChunkData, coord);
                                if (!v.IsValid || (v.Sunlight))
                                {
                                    invalidCave = true;
                                    break;
                                }
                            }

                            if (!invalidCave)
                            {
                                voxel.RawSetType(VoxelLibrary.emptyType);
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (!invalidCave && caveNoise > CaveSize * 1.8f && y - caveHeight > 0 && y > LavaLevel)
                        {
                            GenerateCaveVegetation(chunk, x, y, z, caveHeight, caveBiome, vec, world, NoiseGenerator);
                        }
                    }
                }
            }

            /*
             * // Second pass sets the caves to empty as needed
             * for (int x = 0; x < VoxelConstants.ChunkSizeX; x++)
             * {
             *  for (int y = 0; y < VoxelConstants.ChunkSizeY; y++)
             *  {
             *      for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++)
             *      {
             *          VoxelHandle handle = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y, z));
             *          if (handle.Type == magicCube)
             *          {
             *              handle.RawSetType(VoxelLibrary.emptyType);
             *          }
             *      }
             *  }
             * }
             */
        }
Exemplo n.º 4
0
        public void GenerateCaves(VoxelChunk chunk, WorldManager world)
        {
            Vector3   origin = chunk.Origin;
            BiomeData biome  = BiomeLibrary.GetBiome("Cave");

            for (int x = 0; x < VoxelConstants.ChunkSizeX; x++)
            {
                for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++)
                {
                    var topVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle(
                                                                        chunk, new LocalVoxelCoordinate(x, VoxelConstants.ChunkSizeY - 1, z)));

                    for (int i = 0; i < CaveLevels.Count; i++)
                    {
                        int y = CaveLevels[i];
                        if (y <= 0 || y >= topVoxel.Coordinate.Y)
                        {
                            continue;
                        }
                        Vector3 vec       = new Vector3(x, y, z) + chunk.Origin;
                        double  caveNoise = CaveNoise.GetValue((x + origin.X) * CaveNoiseScale * CaveFrequencies[i],
                                                               (y + origin.Y) * CaveNoiseScale * 3.0f, (z + origin.Z) * CaveNoiseScale * CaveFrequencies[i]);

                        double heightnoise = NoiseGenerator.Noise((x + origin.X) * NoiseScale * CaveFrequencies[i],
                                                                  (y + origin.Y) * NoiseScale * 3.0f, (z + origin.Z) * NoiseScale * CaveFrequencies[i]);

                        int caveHeight = Math.Min(Math.Max((int)(heightnoise * 5), 1), 3);

                        if (!(caveNoise > CaveSize))
                        {
                            continue;
                        }

                        bool invalidCave = false;
                        for (int dy = 0; dy < caveHeight; dy++)
                        {
                            if (y - dy <= 0)
                            {
                                continue;
                            }

                            var voxel = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y - dy, z));

                            foreach (var coord in VoxelHelpers.EnumerateAllNeighbors(voxel.Coordinate))
                            {
                                VoxelHandle v = new VoxelHandle(Manager.ChunkData, coord);
                                if (v.IsValid && (v.LiquidLevel > 0 || v.Sunlight))
                                {
                                    invalidCave = true;
                                    break;
                                }
                            }

                            if (!invalidCave)
                            {
                                voxel.RawSetType(VoxelLibrary.emptyType);
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (!invalidCave && caveNoise > CaveSize * 1.8f && y - caveHeight > 0)
                        {
                            GenerateCaveVegetation(chunk, x, y, z, caveHeight, biome, vec, world, NoiseGenerator);
                            GenerateCaveFauna(chunk, world, biome, y - caveHeight, x, z);
                        }
                    }
                }
            }

            /*
             * // Second pass sets the caves to empty as needed
             * for (int x = 0; x < VoxelConstants.ChunkSizeX; x++)
             * {
             *  for (int y = 0; y < VoxelConstants.ChunkSizeY; y++)
             *  {
             *      for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++)
             *      {
             *          VoxelHandle handle = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y, z));
             *          if (handle.Type == magicCube)
             *          {
             *              handle.RawSetType(VoxelLibrary.emptyType);
             *          }
             *      }
             *  }
             * }
             */
        }