Noise: Prevent unittest crash caused by division by zero
[oweals/minetest.git] / src / mapgen_v6.cpp
index 7bf2ea9dbfdeccd40c419216f3d1fdd72c4d23ea..cbc4a19c3fb17d19497ec6ee4973f2330c65dbd6 100644 (file)
@@ -58,14 +58,14 @@ FlagDesc flagdesc_mapgen_v6[] = {
 MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params, EmergeManager *emerge)
        : Mapgen(mapgenid, params, emerge)
 {
-       this->m_emerge = emerge;
-       this->ystride = csize.X; //////fix this
+       m_emerge = emerge;
+       ystride = csize.X; //////fix this
 
-       this->heightmap = new s16[csize.X * csize.Z];
+       heightmap = new s16[csize.X * csize.Z];
 
-       this->spflags     = params->spflags;
-       this->freq_desert = params->freq_desert;
-       this->freq_beach  = params->freq_beach;
+       spflags     = params->spflags;
+       freq_desert = params->freq_desert;
+       freq_beach  = params->freq_beach;
 
        np_cave        = &params->np_cave;
        np_humidity    = &params->np_humidity;
@@ -147,12 +147,6 @@ MapgenV6::~MapgenV6()
 
 MapgenV6Params::MapgenV6Params()
 {
-       spflags = MGV6_JUNGLES | MGV6_SNOWBIOMES | MGV6_TREES |
-               MGV6_BIOMEBLEND | MGV6_MUDFLOW;
-
-       freq_desert = 0.45;
-       freq_beach  = 0.15;
-
        np_terrain_base   = NoiseParams(-4,   20.0, v3f(250.0, 250.0, 250.0), 82341,  5, 0.6,  2.0);
        np_terrain_higher = NoiseParams(20,   16.0, v3f(500.0, 500.0, 500.0), 85039,  5, 0.6,  2.0);
        np_steepness      = NoiseParams(0.85, 0.5,  v3f(125.0, 125.0, 125.0), -932,   5, 0.7,  2.0);
@@ -212,7 +206,7 @@ void MapgenV6Params::writeParams(Settings *settings) const
 // Returns Y one under area minimum if not found
 s16 MapgenV6::find_stone_level(v2s16 p2d)
 {
-       v3s16 em = vm->m_area.getExtent();
+       const v3s16 &em = vm->m_area.getExtent();
        s16 y_nodes_max = vm->m_area.MaxEdge.Y;
        s16 y_nodes_min = vm->m_area.MinEdge.Y;
        u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
@@ -625,10 +619,12 @@ void MapgenV6::makeChunk(BlockMakeData *data)
 
        // Generate the registered decorations
        if (flags & MG_DECORATIONS)
-               m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+               m_emerge->decomgr->placeAllDecos(this, blockseed,
+                       node_min, node_max, water_level - 1);
 
        // Generate the registered ores
-       m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+       m_emerge->oremgr->placeAllOres(this, blockseed,
+               node_min, node_max, water_level - 1);
 
        // Calculate lighting
        if (flags & MG_LIGHT)
@@ -685,7 +681,7 @@ int MapgenV6::generateGround()
                BiomeV6Type bt = getBiome(v2s16(x, z));
 
                // Fill ground with stone
-               v3s16 em = vm->m_area.getExtent();
+               const v3s16 &em = vm->m_area.getExtent();
                u32 i = vm->m_area.index(x, node_min.Y, z);
                for (s16 y = node_min.Y; y <= node_max.Y; y++) {
                        if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
@@ -754,7 +750,7 @@ void MapgenV6::addMud()
 
                // Add mud on ground
                s16 mudcount = 0;
-               v3s16 em = vm->m_area.getExtent();
+               const v3s16 &em = vm->m_area.getExtent();
                s16 y_start = surface_y + 1;
                u32 i = vm->m_area.index(x, y_start, z);
                for (s16 y = y_start; y <= node_max.Y; y++) {
@@ -788,7 +784,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
                        // Node position in 2d
                        v2s16 p2d = v2s16(node_min.X, node_min.Z) + v2s16(x, z);
 
-                       v3s16 em = vm->m_area.getExtent();
+                       const v3s16 &em = vm->m_area.getExtent();
                        u32 i = vm->m_area.index(p2d.X, node_max.Y, p2d.Y);
                        s16 y = node_max.Y;
 
@@ -913,21 +909,25 @@ void MapgenV6::moveMud(u32 remove_index, u32 place_index,
        // use 'pos.X >= node_max.X' etc.
        if (pos.X >= node_max.X || pos.X <= node_min.X ||
                        pos.Y >= node_max.Z || pos.Y <= node_min.Z) {
-               // 'above remove' node is above removed mud. If it is not air and not
-               // water it is a decoration that needs removing. Also search upwards
-               // for a possible stacked decoration.
+               // 'above remove' node is above removed mud. If it is not air, water or
+               // 'ignore' it is a decoration that needs removing. Also search upwards
+               // to remove a possible stacked decoration.
+               // Check for 'ignore' because stacked decorations can penetrate into
+               // 'ignore' nodes above the mapchunk.
                while (vm->m_area.contains(above_remove_index) &&
                                vm->m_data[above_remove_index].getContent() != CONTENT_AIR &&
-                               vm->m_data[above_remove_index].getContent() != c_water_source) {
+                               vm->m_data[above_remove_index].getContent() != c_water_source &&
+                               vm->m_data[above_remove_index].getContent() != CONTENT_IGNORE) {
                        vm->m_data[above_remove_index] = n_air;
                        vm->m_area.add_y(em, above_remove_index, 1);
                }
-               // Mud placed may have half-buried a tall decoration, search above and
-               // remove.
+               // Mud placed may have partially-buried a stacked decoration, search
+               // above and remove.
                vm->m_area.add_y(em, place_index, 1);
                while (vm->m_area.contains(place_index) &&
                                vm->m_data[place_index].getContent() != CONTENT_AIR &&
-                               vm->m_data[place_index].getContent() != c_water_source) {
+                               vm->m_data[place_index].getContent() != c_water_source &&
+                               vm->m_data[place_index].getContent() != CONTENT_IGNORE) {
                        vm->m_data[place_index] = n_air;
                        vm->m_area.add_y(em, place_index, 1);
                }
@@ -947,7 +947,7 @@ void MapgenV6::placeTreesAndJungleGrass()
        if (c_junglegrass == CONTENT_IGNORE)
                c_junglegrass = CONTENT_AIR;
        MapNode n_junglegrass(c_junglegrass);
-       v3s16 em = vm->m_area.getExtent();
+       const v3s16 &em = vm->m_area.getExtent();
 
        // Divide area into parts
        s16 div = 8;
@@ -1055,7 +1055,7 @@ void MapgenV6::growGrass() // Add surface nodes
        MapNode n_dirt_with_snow(c_dirt_with_snow);
        MapNode n_snowblock(c_snowblock);
        MapNode n_snow(c_snow);
-       v3s16 em = vm->m_area.getExtent();
+       const v3s16 &em = vm->m_area.getExtent();
 
        u32 index = 0;
        for (s16 z = full_node_min.Z; z <= full_node_max.Z; z++)