]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapgen/mg_ore.cpp
Attempt to fix SEGFAULT in push_inventory
[dragonfireclient.git] / src / mapgen / mg_ore.cpp
index 5af8e31e4f6ee2d48c591bb9a3b9771ccb08e484..5814f433a81182b7214aeb15f6637f36b4d0b5a2 100644 (file)
@@ -27,16 +27,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <cmath>
 #include <algorithm>
 
-FlagDesc flagdesc_ore[] = {{"absheight", OREFLAG_ABSHEIGHT}, // Non-functional
-               {"puff_cliffs", OREFLAG_PUFF_CLIFFS},
-               {"puff_additive_composition", OREFLAG_PUFF_ADDITIVE}, {NULL, 0}};
+
+FlagDesc flagdesc_ore[] = {
+       {"absheight",                 OREFLAG_ABSHEIGHT}, // Non-functional
+       {"puff_cliffs",               OREFLAG_PUFF_CLIFFS},
+       {"puff_additive_composition", OREFLAG_PUFF_ADDITIVE},
+       {NULL,                        0}
+};
+
 
 ///////////////////////////////////////////////////////////////////////////////
 
-OreManager::OreManager(IGameDef *gamedef) : ObjDefManager(gamedef, OBJDEF_ORE)
+
+OreManager::OreManager(IGameDef *gamedef) :
+       ObjDefManager(gamedef, OBJDEF_ORE)
 {
 }
 
+
 size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 {
        size_t nplaced = 0;
@@ -53,15 +61,17 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nma
        return nplaced;
 }
 
+
 void OreManager::clear()
 {
        for (ObjDef *object : m_objects) {
-               Ore *ore = (Ore *)object;
+               Ore *ore = (Ore *) object;
                delete ore;
        }
        m_objects.clear();
 }
 
+
 OreManager *OreManager::clone() const
 {
        auto mgr = new OreManager();
@@ -69,19 +79,23 @@ OreManager *OreManager::clone() const
        return mgr;
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
+
 Ore::~Ore()
 {
        delete noise;
 }
 
+
 void Ore::resolveNodeNames()
 {
        getIdFromNrBacklog(&c_ore, "", CONTENT_AIR);
        getIdsFromNrBacklog(&c_wherein);
 }
 
+
 size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 {
        if (nmin.Y > y_max || nmax.Y < y_min)
@@ -99,6 +113,7 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
        return 1;
 }
 
+
 void Ore::cloneTo(Ore *def) const
 {
        ObjDef::cloneTo(def);
@@ -118,8 +133,10 @@ void Ore::cloneTo(Ore *def) const
        def->biomes = biomes;
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
+
 ObjDef *OreScatter::clone() const
 {
        auto def = new OreScatter();
@@ -127,17 +144,19 @@ ObjDef *OreScatter::clone() const
        return def;
 }
 
-void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin,
-               v3s16 nmax, biome_t *biomemap)
+
+void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, biome_t *biomemap)
 {
        PcgRandom pr(blockseed);
        MapNode n_ore(c_ore, 0, ore_param2);
 
-       u32 sizex = (nmax.X - nmin.X + 1);
-       u32 volume = (nmax.X - nmin.X + 1) * (nmax.Y - nmin.Y + 1) *
-                    (nmax.Z - nmin.Z + 1);
-       u32 csize = clust_size;
-       u32 cvolume = csize * csize * csize;
+       u32 sizex  = (nmax.X - nmin.X + 1);
+       u32 volume = (nmax.X - nmin.X + 1) *
+                                (nmax.Y - nmin.Y + 1) *
+                                (nmax.Z - nmin.Z + 1);
+       u32 csize     = clust_size;
+       u32 cvolume    = csize * csize * csize;
        u32 nclusters = volume / clust_scarcity;
 
        for (u32 i = 0; i != nclusters; i++) {
@@ -146,7 +165,7 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin,
                int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
 
                if ((flags & OREFLAG_USE_NOISE) &&
-                               (NoisePerlin3D(&np, x0, y0, z0, mapseed) < nthresh))
+                       (NoisePerlin3D(&np, x0, y0, z0, mapseed) < nthresh))
                        continue;
 
                if (biomemap && !biomes.empty()) {
@@ -157,24 +176,24 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin,
                }
 
                for (u32 z1 = 0; z1 != csize; z1++)
-                       for (u32 y1 = 0; y1 != csize; y1++)
-                               for (u32 x1 = 0; x1 != csize; x1++) {
-                                       if (pr.range(1, cvolume) > clust_num_ores)
-                                               continue;
-
-                                       u32 i = vm->m_area.index(
-                                                       x0 + x1, y0 + y1, z0 + z1);
-                                       if (!CONTAINS(c_wherein,
-                                                           vm->m_data[i].getContent()))
-                                               continue;
-
-                                       vm->m_data[i] = n_ore;
-                               }
+               for (u32 y1 = 0; y1 != csize; y1++)
+               for (u32 x1 = 0; x1 != csize; x1++) {
+                       if (pr.range(1, cvolume) > clust_num_ores)
+                               continue;
+
+                       u32 i = vm->m_area.index(x0 + x1, y0 + y1, z0 + z1);
+                       if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
+                               continue;
+
+                       vm->m_data[i] = n_ore;
+               }
        }
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
+
 ObjDef *OreSheet::clone() const
 {
        auto def = new OreSheet();
@@ -187,8 +206,9 @@ ObjDef *OreSheet::clone() const
        return def;
 }
 
-void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax,
-               biome_t *biomemap)
+
+void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, biome_t *biomemap)
 {
        PcgRandom pr(blockseed + 4234);
        MapNode n_ore(c_ore, 0, ore_param2);
@@ -197,8 +217,9 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3
        int y_start_min = nmin.Y + max_height;
        int y_start_max = nmax.Y - max_height;
 
-       int y_start = y_start_min < y_start_max ? pr.range(y_start_min, y_start_max)
-                                               : (y_start_min + y_start_max) / 2;
+       int y_start = y_start_min < y_start_max ?
+               pr.range(y_start_min, y_start_max) :
+               (y_start_min + y_start_max) / 2;
 
        if (!noise) {
                int sx = nmax.X - nmin.X + 1;
@@ -210,43 +231,45 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3
 
        size_t index = 0;
        for (int z = nmin.Z; z <= nmax.Z; z++)
-               for (int x = nmin.X; x <= nmax.X; x++, index++) {
-                       float noiseval = noise->result[index];
-                       if (noiseval < nthresh)
-                               continue;
+       for (int x = nmin.X; x <= nmax.X; x++, index++) {
+               float noiseval = noise->result[index];
+               if (noiseval < nthresh)
+                       continue;
 
-                       if (biomemap && !biomes.empty()) {
-                               auto it = biomes.find(biomemap[index]);
-                               if (it == biomes.end())
-                                       continue;
-                       }
+               if (biomemap && !biomes.empty()) {
+                       auto it = biomes.find(biomemap[index]);
+                       if (it == biomes.end())
+                               continue;
+               }
 
-                       u16 height = pr.range(column_height_min, column_height_max);
-                       int ymidpoint = y_start + noiseval;
-                       int y0 = MYMAX(nmin.Y,
-                                       ymidpoint - height * (1 - column_midpoint_factor));
-                       int y1 = MYMIN(nmax.Y, y0 + height - 1);
+               u16 height = pr.range(column_height_min, column_height_max);
+               int ymidpoint = y_start + noiseval;
+               int y0 = MYMAX(nmin.Y, ymidpoint - height * (1 - column_midpoint_factor));
+               int y1 = MYMIN(nmax.Y, y0 + height - 1);
 
-                       for (int y = y0; y <= y1; y++) {
-                               u32 i = vm->m_area.index(x, y, z);
-                               if (!vm->m_area.contains(i))
-                                       continue;
-                               if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
-                                       continue;
+               for (int y = y0; y <= y1; y++) {
+                       u32 i = vm->m_area.index(x, y, z);
+                       if (!vm->m_area.contains(i))
+                               continue;
+                       if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
+                               continue;
 
-                               vm->m_data[i] = n_ore;
-                       }
+                       vm->m_data[i] = n_ore;
                }
+       }
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
+
 OrePuff::~OrePuff()
 {
        delete noise_puff_top;
        delete noise_puff_bottom;
 }
 
+
 ObjDef *OrePuff::clone() const
 {
        auto def = new OrePuff();
@@ -260,8 +283,9 @@ ObjDef *OrePuff::clone() const
        return def;
 }
 
-void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax,
-               biome_t *biomemap)
+
+void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, biome_t *biomemap)
 {
        PcgRandom pr(blockseed + 4234);
        MapNode n_ore(c_ore, 0, ore_param2);
@@ -282,55 +306,57 @@ void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s
 
        size_t index = 0;
        for (int z = nmin.Z; z <= nmax.Z; z++)
-               for (int x = nmin.X; x <= nmax.X; x++, index++) {
-                       float noiseval = noise->result[index];
-                       if (noiseval < nthresh)
-                               continue;
+       for (int x = nmin.X; x <= nmax.X; x++, index++) {
+               float noiseval = noise->result[index];
+               if (noiseval < nthresh)
+                       continue;
 
-                       if (biomemap && !biomes.empty()) {
-                               auto it = biomes.find(biomemap[index]);
-                               if (it == biomes.end())
-                                       continue;
-                       }
+               if (biomemap && !biomes.empty()) {
+                       auto it = biomes.find(biomemap[index]);
+                       if (it == biomes.end())
+                               continue;
+               }
 
-                       if (!noise_generated) {
-                               noise_generated = true;
-                               noise_puff_top->perlinMap2D(nmin.X, nmin.Z);
-                               noise_puff_bottom->perlinMap2D(nmin.X, nmin.Z);
-                       }
+               if (!noise_generated) {
+                       noise_generated = true;
+                       noise_puff_top->perlinMap2D(nmin.X, nmin.Z);
+                       noise_puff_bottom->perlinMap2D(nmin.X, nmin.Z);
+               }
 
-                       float ntop = noise_puff_top->result[index];
-                       float nbottom = noise_puff_bottom->result[index];
+               float ntop    = noise_puff_top->result[index];
+               float nbottom = noise_puff_bottom->result[index];
 
-                       if (!(flags & OREFLAG_PUFF_CLIFFS)) {
-                               float ndiff = noiseval - nthresh;
-                               if (ndiff < 1.0f) {
-                                       ntop *= ndiff;
-                                       nbottom *= ndiff;
-                               }
+               if (!(flags & OREFLAG_PUFF_CLIFFS)) {
+                       float ndiff = noiseval - nthresh;
+                       if (ndiff < 1.0f) {
+                               ntop *= ndiff;
+                               nbottom *= ndiff;
                        }
+               }
 
-                       int ymid = y_start;
-                       int y0 = ymid - nbottom;
-                       int y1 = ymid + ntop;
+               int ymid = y_start;
+               int y0 = ymid - nbottom;
+               int y1 = ymid + ntop;
 
-                       if ((flags & OREFLAG_PUFF_ADDITIVE) && (y0 > y1))
-                               SWAP(int, y0, y1);
+               if ((flags & OREFLAG_PUFF_ADDITIVE) && (y0 > y1))
+                       SWAP(int, y0, y1);
 
-                       for (int y = y0; y <= y1; y++) {
-                               u32 i = vm->m_area.index(x, y, z);
-                               if (!vm->m_area.contains(i))
-                                       continue;
-                               if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
-                                       continue;
+               for (int y = y0; y <= y1; y++) {
+                       u32 i = vm->m_area.index(x, y, z);
+                       if (!vm->m_area.contains(i))
+                               continue;
+                       if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
+                               continue;
 
-                               vm->m_data[i] = n_ore;
-                       }
+                       vm->m_data[i] = n_ore;
                }
+       }
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
+
 ObjDef *OreBlob::clone() const
 {
        auto def = new OreBlob();
@@ -338,16 +364,18 @@ ObjDef *OreBlob::clone() const
        return def;
 }
 
-void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax,
-               biome_t *biomemap)
+
+void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, biome_t *biomemap)
 {
        PcgRandom pr(blockseed + 2404);
        MapNode n_ore(c_ore, 0, ore_param2);
 
-       u32 sizex = (nmax.X - nmin.X + 1);
-       u32 volume = (nmax.X - nmin.X + 1) * (nmax.Y - nmin.Y + 1) *
-                    (nmax.Z - nmin.Z + 1);
-       u32 csize = clust_size;
+       u32 sizex  = (nmax.X - nmin.X + 1);
+       u32 volume = (nmax.X - nmin.X + 1) *
+                                (nmax.Y - nmin.Y + 1) *
+                                (nmax.Z - nmin.Z + 1);
+       u32 csize  = clust_size;
        u32 nblobs = volume / clust_scarcity;
 
        if (!noise)
@@ -370,48 +398,45 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s
 
                size_t index = 0;
                for (u32 z1 = 0; z1 != csize; z1++)
-                       for (u32 y1 = 0; y1 != csize; y1++)
-                               for (u32 x1 = 0; x1 != csize; x1++, index++) {
-                                       u32 i = vm->m_area.index(
-                                                       x0 + x1, y0 + y1, z0 + z1);
-                                       if (!CONTAINS(c_wherein,
-                                                           vm->m_data[i].getContent()))
-                                               continue;
-
-                                       // Lazily generate noise only if there's a chance
-                                       // of ore being placed This simple optimization
-                                       // makes calls 6x faster on average
-                                       if (!noise_generated) {
-                                               noise_generated = true;
-                                               noise->perlinMap3D(x0, y0, z0);
-                                       }
-
-                                       float noiseval = noise->result[index];
-
-                                       float xdist = (s32)x1 - (s32)csize / 2;
-                                       float ydist = (s32)y1 - (s32)csize / 2;
-                                       float zdist = (s32)z1 - (s32)csize / 2;
-
-                                       noiseval -= std::sqrt(xdist * xdist +
-                                                                   ydist * ydist +
-                                                                   zdist * zdist) /
-                                                   csize;
-
-                                       if (noiseval < nthresh)
-                                               continue;
-
-                                       vm->m_data[i] = n_ore;
-                               }
+               for (u32 y1 = 0; y1 != csize; y1++)
+               for (u32 x1 = 0; x1 != csize; x1++, index++) {
+                       u32 i = vm->m_area.index(x0 + x1, y0 + y1, z0 + z1);
+                       if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
+                               continue;
+
+                       // Lazily generate noise only if there's a chance of ore being placed
+                       // This simple optimization makes calls 6x faster on average
+                       if (!noise_generated) {
+                               noise_generated = true;
+                               noise->perlinMap3D(x0, y0, z0);
+                       }
+
+                       float noiseval = noise->result[index];
+
+                       float xdist = (s32)x1 - (s32)csize / 2;
+                       float ydist = (s32)y1 - (s32)csize / 2;
+                       float zdist = (s32)z1 - (s32)csize / 2;
+
+                       noiseval -= std::sqrt(xdist * xdist + ydist * ydist + zdist * zdist) / csize;
+
+                       if (noiseval < nthresh)
+                               continue;
+
+                       vm->m_data[i] = n_ore;
+               }
        }
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
+
 OreVein::~OreVein()
 {
        delete noise2;
 }
 
+
 ObjDef *OreVein::clone() const
 {
        auto def = new OreVein();
@@ -424,8 +449,9 @@ ObjDef *OreVein::clone() const
        return def;
 }
 
-void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax,
-               biome_t *biomemap)
+
+void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, biome_t *biomemap)
 {
        PcgRandom pr(blockseed + 520);
        MapNode n_ore(c_ore, 0, ore_param2);
@@ -441,7 +467,7 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s
                delete noise;
                delete noise2;
                int sizez = nmax.Z - nmin.Z + 1;
-               noise = new Noise(&np, mapseed, sizex, sizey, sizez);
+               noise  = new Noise(&np, mapseed, sizex, sizey, sizez);
                noise2 = new Noise(&np, mapseed + 436, sizex, sizey, sizez);
                sizey_prev = sizey;
        }
@@ -449,48 +475,53 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s
        bool noise_generated = false;
        size_t index = 0;
        for (int z = nmin.Z; z <= nmax.Z; z++)
-               for (int y = nmin.Y; y <= nmax.Y; y++)
-                       for (int x = nmin.X; x <= nmax.X; x++, index++) {
-                               u32 i = vm->m_area.index(x, y, z);
-                               if (!vm->m_area.contains(i))
-                                       continue;
-                               if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
-                                       continue;
-
-                               if (biomemap && !biomes.empty()) {
-                                       u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
-                                       auto it = biomes.find(biomemap[bmapidx]);
-                                       if (it == biomes.end())
-                                               continue;
-                               }
-
-                               // Same lazy generation optimization as in OreBlob
-                               if (!noise_generated) {
-                                       noise_generated = true;
-                                       noise->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
-                                       noise2->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
-                               }
-
-                               // randval ranges from -1..1
-                               float randval = (float)pr.next() / (pr.RANDOM_RANGE / 2) -
-                                               1.f;
-                               float noiseval = contour(noise->result[index]);
-                               float noiseval2 = contour(noise2->result[index]);
-                               if (noiseval * noiseval2 + randval * random_factor <
-                                               nthresh)
-                                       continue;
-
-                               vm->m_data[i] = n_ore;
-                       }
+       for (int y = nmin.Y; y <= nmax.Y; y++)
+       for (int x = nmin.X; x <= nmax.X; x++, index++) {
+               u32 i = vm->m_area.index(x, y, z);
+               if (!vm->m_area.contains(i))
+                       continue;
+               if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
+                       continue;
+
+               if (biomemap && !biomes.empty()) {
+                       u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
+                       auto it = biomes.find(biomemap[bmapidx]);
+                       if (it == biomes.end())
+                               continue;
+               }
+
+               // Same lazy generation optimization as in OreBlob
+               if (!noise_generated) {
+                       noise_generated = true;
+                       noise->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
+                       noise2->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
+               }
+
+               // randval ranges from -1..1
+               /* 
+                       Note: can generate values slightly larger than 1 
+                       but this can't be changed as mapgen must be deterministic accross versions.
+               */
+               float randval   = (float)pr.next() / float(pr.RANDOM_RANGE / 2) - 1.f;
+               float noiseval  = contour(noise->result[index]);
+               float noiseval2 = contour(noise2->result[index]);
+               if (noiseval * noiseval2 + randval * random_factor < nthresh)
+                       continue;
+
+               vm->m_data[i] = n_ore;
+       }
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 
+
 OreStratum::~OreStratum()
 {
        delete noise_stratum_thickness;
 }
 
+
 ObjDef *OreStratum::clone() const
 {
        auto def = new OreStratum();
@@ -503,8 +534,9 @@ ObjDef *OreStratum::clone() const
        return def;
 }
 
-void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin,
-               v3s16 nmax, biome_t *biomemap)
+
+void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, biome_t *biomemap)
 {
        PcgRandom pr(blockseed + 4234);
        MapNode n_ore(c_ore, 0, ore_param2);
@@ -522,8 +554,7 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin,
                if (!noise_stratum_thickness) {
                        int sx = nmax.X - nmin.X + 1;
                        int sz = nmax.Z - nmin.Z + 1;
-                       noise_stratum_thickness =
-                                       new Noise(&np_stratum_thickness, 0, sx, sz);
+                       noise_stratum_thickness = new Noise(&np_stratum_thickness, 0, sx, sz);
                }
                noise_stratum_thickness->perlinMap2D(nmin.X, nmin.Z);
        }
@@ -531,41 +562,39 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin,
        size_t index = 0;
 
        for (int z = nmin.Z; z <= nmax.Z; z++)
-               for (int x = nmin.X; x <= nmax.X; x++, index++) {
-                       if (biomemap && !biomes.empty()) {
-                               auto it = biomes.find(biomemap[index]);
-                               if (it == biomes.end())
-                                       continue;
-                       }
+       for (int x = nmin.X; x <= nmax.X; x++, index++) {
+               if (biomemap && !biomes.empty()) {
+                       auto it = biomes.find(biomemap[index]);
+                       if (it == biomes.end())
+                               continue;
+               }
 
-                       int y0;
-                       int y1;
-
-                       if (flags & OREFLAG_USE_NOISE) {
-                               float nhalfthick =
-                                               ((flags & OREFLAG_USE_NOISE2) ? noise_stratum_thickness
-                                                                                               ->result[index]
-                                                                             : (float)stratum_thickness) /
-                                               2.0f;
-                               float nmid = noise->result[index];
-                               y0 = MYMAX(nmin.Y, std::ceil(nmid - nhalfthick));
-                               y1 = MYMIN(nmax.Y, nmid + nhalfthick);
-                       } else { // Simple horizontal stratum
-                               y0 = nmin.Y;
-                               y1 = nmax.Y;
-                       }
+               int y0;
+               int y1;
+
+               if (flags & OREFLAG_USE_NOISE) {
+                       float nhalfthick = ((flags & OREFLAG_USE_NOISE2) ?
+                               noise_stratum_thickness->result[index] : (float)stratum_thickness) /
+                               2.0f;
+                       float nmid = noise->result[index];
+                       y0 = MYMAX(nmin.Y, std::ceil(nmid - nhalfthick));
+                       y1 = MYMIN(nmax.Y, nmid + nhalfthick);
+               } else { // Simple horizontal stratum
+                       y0 = nmin.Y;
+                       y1 = nmax.Y;
+               }
 
-                       for (int y = y0; y <= y1; y++) {
-                               if (pr.range(1, clust_scarcity) != 1)
-                                       continue;
+               for (int y = y0; y <= y1; y++) {
+                       if (pr.range(1, clust_scarcity) != 1)
+                               continue;
 
-                               u32 i = vm->m_area.index(x, y, z);
-                               if (!vm->m_area.contains(i))
-                                       continue;
-                               if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
-                                       continue;
+                       u32 i = vm->m_area.index(x, y, z);
+                       if (!vm->m_area.contains(i))
+                               continue;
+                       if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
+                               continue;
 
-                               vm->m_data[i] = n_ore;
-                       }
+                       vm->m_data[i] = n_ore;
                }
+       }
 }