X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmg_ore.cpp;h=4f4c9c7113e10596dc550b0b5e95d5af1839ebc9;hb=9eb163ab4f72fad234d47e9446f5608d1c5c02dc;hp=f959ca9e65b9fa760282baf392e620da9a26d5ab;hpb=1237206d4bdf840ae89018d14a0510035d54d0d3;p=oweals%2Fminetest.git diff --git a/src/mg_ore.cpp b/src/mg_ore.cpp index f959ca9e6..4f4c9c711 100644 --- a/src/mg_ore.cpp +++ b/src/mg_ore.cpp @@ -23,11 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "noise.h" #include "map.h" #include "log.h" +#include "util/numeric.h" #include FlagDesc flagdesc_ore[] = { - {"absheight", OREFLAG_ABSHEIGHT}, + {"absheight", OREFLAG_ABSHEIGHT}, // Non-functional {"puff_cliffs", OREFLAG_PUFF_CLIFFS}, {"puff_additive_composition", OREFLAG_PUFF_ADDITIVE}, {NULL, 0} @@ -62,8 +63,8 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nma void OreManager::clear() { - for (size_t i = 0; i < m_objects.size(); i++) { - Ore *ore = (Ore *)m_objects[i]; + for (ObjDef *object : m_objects) { + Ore *ore = (Ore *) object; delete ore; } m_objects.clear(); @@ -72,6 +73,7 @@ void OreManager::clear() /////////////////////////////////////////////////////////////////////////////// + Ore::~Ore() { delete noise; @@ -87,22 +89,11 @@ void Ore::resolveNodeNames() size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { - int in_range = 0; - - in_range |= (nmin.Y <= y_max && nmax.Y >= y_min); - if (flags & OREFLAG_ABSHEIGHT) - in_range |= (nmin.Y >= -y_max && nmax.Y <= -y_min) << 1; - if (!in_range) + if (nmin.Y > y_max || nmax.Y < y_min) return 0; - int actual_ymin, actual_ymax; - if (in_range & ORE_RANGE_MIRROR) { - actual_ymin = MYMAX(nmin.Y, -y_max); - actual_ymax = MYMIN(nmax.Y, -y_min); - } else { - actual_ymin = MYMAX(nmin.Y, y_min); - actual_ymax = MYMIN(nmax.Y, y_max); - } + int actual_ymin = MYMAX(nmin.Y, y_min); + int actual_ymax = MYMIN(nmax.Y, y_max); if (clust_size >= actual_ymax - actual_ymin + 1) return 0; @@ -221,11 +212,6 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, /////////////////////////////////////////////////////////////////////////////// -OrePuff::OrePuff() : - Ore() -{ -} - OrePuff::~OrePuff() { @@ -372,11 +358,6 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, /////////////////////////////////////////////////////////////////////////////// -OreVein::OreVein() : - Ore() -{ -} - OreVein::~OreVein() { @@ -435,3 +416,58 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, vm->m_data[i] = n_ore; } } + + +/////////////////////////////////////////////////////////////////////////////// + + +OreStratum::~OreStratum() +{ + delete noise_stratum_thickness; +} + + +void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, + v3s16 nmin, v3s16 nmax, u8 *biomemap) +{ + PcgRandom pr(blockseed + 4234); + MapNode n_ore(c_ore, 0, ore_param2); + + if (!noise) { + int sx = nmax.X - nmin.X + 1; + int sz = nmax.Z - nmin.Z + 1; + noise = new Noise(&np, 0, sx, sz); + noise_stratum_thickness = new Noise(&np_stratum_thickness, 0, sx, sz); + } + noise->perlinMap2D(nmin.X, nmin.Z); + noise_stratum_thickness->perlinMap2D(nmin.X, nmin.Z); + + 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()) { + std::unordered_set::const_iterator it = biomes.find(biomemap[index]); + if (it == biomes.end()) + continue; + } + + float nmid = noise->result[index]; + float nhalfthick = noise_stratum_thickness->result[index] / 2.0f; + int y0 = MYMAX(nmin.Y, nmid - nhalfthick); + int y1 = MYMIN(nmax.Y, nmid + nhalfthick); + + 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; + + vm->m_data[i] = n_ore; + } + } +}