Noise: Prevent unittest crash caused by division by zero
[oweals/minetest.git] / src / mapgen_valleys.h
index 6b3eb9cfe87aa478610bf808e97d3b56269d469c..573f598a58fe34a86ab2c94ae76bf491fe41547d 100644 (file)
@@ -1,8 +1,7 @@
 /*
 Minetest Valleys C
-Copyright (C) 2010-2015 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-Copyright (C) 2010-2015 paramat, Matt Gregory
-Copyright (C) 2016 Duane Robertson <duane@duanerobertson.com>
+Copyright (C) 2016-2017 Duane Robertson <duane@duanerobertson.com>
+Copyright (C) 2016-2017 paramat
 
 Based on Valleys Mapgen by Gael de Sailly
  (https://forum.minetest.net/viewtopic.php?f=9&t=11430)
@@ -39,27 +38,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define MYCUBE(x) (x) * (x) * (x)
 
 class BiomeManager;
+class BiomeGenOriginal;
 
 // Global profiler
 //class Profiler;
 //extern Profiler *mapgen_profiler;
 
 
-struct MapgenValleysParams : public MapgenSpecificParams {
-       u32 spflags;
-
-       s16 large_cave_depth;
-       s16 massive_cave_depth;
-       u16 altitude_chill;
-       u16 lava_features;
-       u16 river_depth;
-       u16 river_size;
-       u16 water_features;
-
-       NoiseParams np_biome_heat;
-       NoiseParams np_biome_heat_blend;
-       NoiseParams np_biome_humidity;
-       NoiseParams np_biome_humidity_blend;
+struct MapgenValleysParams : public MapgenParams {
+       u32 spflags = MGVALLEYS_HUMID_RIVERS | MGVALLEYS_ALT_CHILL;
+       s16 large_cave_depth = -33;
+       s16 massive_cave_depth = -256; // highest altitude of massive caves
+       u16 altitude_chill = 90; // The altitude at which temperature drops by 20C.
+       u16 lava_features = 0; // How often water will occur in caves.
+       u16 river_depth = 4; // How deep to carve river channels.
+       u16 river_size = 5; // How wide to make rivers.
+       u16 water_features = 0; // How often water will occur in caves.
+       float cave_width = 0.09f;
        NoiseParams np_cave1;
        NoiseParams np_cave2;
        NoiseParams np_filler_depth;
@@ -89,76 +84,44 @@ struct TerrainNoise {
        float inter_valley_fill;
 };
 
-class MapgenValleys : public Mapgen {
+class MapgenValleys : public MapgenBasic {
 public:
 
-       MapgenValleys(int mapgenid, MapgenParams *params, EmergeManager *emerge);
+       MapgenValleys(int mapgenid, MapgenValleysParams *params, EmergeManager *emerge);
        ~MapgenValleys();
 
+       virtual MapgenType getType() const { return MAPGEN_VALLEYS; }
+
        virtual void makeChunk(BlockMakeData *data);
        int getSpawnLevelAtPoint(v2s16 p);
 
        s16 large_cave_depth;
 
 private:
-       EmergeManager *m_emerge;
-       BiomeManager *bmgr;
-
-       int ystride;
-       int zstride;
+       BiomeGenOriginal *m_bgen;
 
-       float map_gen_limit;
-
-       u32 spflags;
        bool humid_rivers;
        bool use_altitude_chill;
-
-       v3s16 node_min;
-       v3s16 node_max;
-       v3s16 full_node_min;
-       v3s16 full_node_max;
-
-       Noise *noise_filler_depth;
-
-       Noise *noise_cave1;
-       Noise *noise_cave2;
-       Noise *noise_heat;
-       Noise *noise_heat_blend;
-       Noise *noise_humidity;
-       Noise *noise_humidity_blend;
-       Noise *noise_inter_valley_fill;
-       Noise *noise_inter_valley_slope;
-       Noise *noise_rivers;
-       Noise *noise_massive_caves;
-       Noise *noise_terrain_height;
-       Noise *noise_valley_depth;
-       Noise *noise_valley_profile;
+       float humidity_adjust;
+       s16 cave_water_max_height;
+       s16 lava_max_height;
 
        float altitude_chill;
-       s16 cave_water_max_height;
-       float humidity_adjust;
        s16 lava_features_lim;
-       s16 lava_max_height;
        s16 massive_cave_depth;
        float river_depth_bed;
        float river_size_factor;
        float *tcave_cache;
        s16 water_features_lim;
-
-       content_t c_cobble;
-       content_t c_desert_stone;
-       content_t c_dirt;
-       content_t c_ice;
-       content_t c_lava_source;
-       content_t c_mossycobble;
-       content_t c_river_water_source;
-       content_t c_sand;
-       content_t c_sandstone;
-       content_t c_sandstonebrick;
-       content_t c_stair_cobble;
-       content_t c_stair_sandstonebrick;
-       content_t c_stone;
-       content_t c_water_source;
+       Noise *noise_inter_valley_fill;
+       Noise *noise_inter_valley_slope;
+       Noise *noise_rivers;
+       Noise *noise_cave1;
+       Noise *noise_cave2;
+       Noise *noise_massive_caves;
+       Noise *noise_terrain_height;
+       Noise *noise_valley_depth;
+       Noise *noise_valley_profile;
 
        float terrainLevelAtPoint(s16 x, s16 z);
 
@@ -168,24 +131,7 @@ private:
        float terrainLevelFromNoise(TerrainNoise *tn);
        float adjustedTerrainLevelFromNoise(TerrainNoise *tn);
 
-       float humidityByTerrain(float humidity_base, float mount, float rivers, float valley);
-
-       MgStoneType generateBiomes(float *heat_map, float *humidity_map);
-       void dustTopNodes();
-
-       void generateCaves(s16 max_stone_y);
-};
-
-struct MapgenFactoryValleys : public MapgenFactory {
-       Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge)
-       {
-               return new MapgenValleys(mgid, params, emerge);
-       };
-
-       MapgenSpecificParams *createMapgenParams()
-       {
-               return new MapgenValleysParams();
-       };
+       virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
 };
 
 #endif