]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mg_ore.cpp
Ore: Add puff ore type
[dragonfireclient.git] / src / mg_ore.cpp
index c62f05860edb72078c98bfcb2e88630d75b2df9c..28be816f50c18c53ab8a5535c5f51ff49a79515d 100644 (file)
@@ -24,11 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "log.h"
 
-const char *OreManager::ELEMENT_TITLE = "ore";
-
 FlagDesc flagdesc_ore[] = {
-       {"absheight", OREFLAG_ABSHEIGHT},
-       {NULL,        0}
+       {"absheight",                 OREFLAG_ABSHEIGHT},
+       {"puff_cliffs",               OREFLAG_PUFF_CLIFFS},
+       {"puff_additive_composition", OREFLAG_PUFF_ADDITIVE},
+       {NULL,                        0}
 };
 
 
@@ -36,7 +36,7 @@ FlagDesc flagdesc_ore[] = {
 
 
 OreManager::OreManager(IGameDef *gamedef) :
-       GenElementManager(gamedef)
+       ObjDefManager(gamedef, OBJDEF_ORE)
 {
 }
 
@@ -45,8 +45,8 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nma
 {
        size_t nplaced = 0;
 
-       for (size_t i = 0; i != m_elements.size(); i++) {
-               Ore *ore = (Ore *)m_elements[i];
+       for (size_t i = 0; i != m_objects.size(); i++) {
+               Ore *ore = (Ore *)m_objects[i];
                if (!ore)
                        continue;
 
@@ -60,11 +60,11 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nma
 
 void OreManager::clear()
 {
-       for (size_t i = 0; i < m_elements.size(); i++) {
-               Ore *ore = (Ore *)m_elements[i];
+       for (size_t i = 0; i < m_objects.size(); i++) {
+               Ore *ore = (Ore *)m_objects[i];
                delete ore;
        }
-       m_elements.clear();
+       m_objects.clear();
 }
 
 
@@ -84,10 +84,10 @@ Ore::~Ore()
 }
 
 
-void Ore::resolveNodeNames(NodeResolveInfo *nri)
+void Ore::resolveNodeNames()
 {
-       m_ndef->getIdFromResolveInfo(nri, "", CONTENT_AIR, c_ore);
-       m_ndef->getIdsFromResolveInfo(nri, c_wherein);
+       getIdFromNrBacklog(&c_ore, "", CONTENT_AIR);
+       getIdsFromNrBacklog(&c_wherein);
 }
 
 
@@ -114,7 +114,7 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 
        nmin.Y = actual_ymin;
        nmax.Y = actual_ymax;
-       generate(mg->vm, mg->seed, blockseed, nmin, nmax);
+       generate(mg->vm, mg->seed, blockseed, nmin, nmax, mg->biomemap);
 
        return 1;
 }
@@ -124,19 +124,20 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 
 
 void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
-       v3s16 nmin, v3s16 nmax)
+       v3s16 nmin, v3s16 nmax, u8 *biomemap)
 {
        PseudoRandom pr(blockseed);
        MapNode n_ore(c_ore, 0, ore_param2);
 
-       int volume = (nmax.X - nmin.X + 1) *
+       u32 sizex  = (nmax.X - nmin.X + 1);
+       u32 volume = (nmax.X - nmin.X + 1) *
                                 (nmax.Y - nmin.Y + 1) *
                                 (nmax.Z - nmin.Z + 1);
-       int csize     = clust_size;
-       int orechance = (csize * csize * csize) / clust_num_ores;
-       int nclusters = volume / clust_scarcity;
+       u32 csize     = clust_size;
+       u32 cvolume    = csize * csize * csize;
+       u32 nclusters = volume / clust_scarcity;
 
-       for (int i = 0; i != nclusters; i++) {
+       for (u32 i = 0; i != nclusters; i++) {
                int x0 = pr.range(nmin.X, nmax.X - csize + 1);
                int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
                int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
@@ -145,10 +146,17 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
                        (NoisePerlin3D(&np, x0, y0, z0, mapseed) < nthresh))
                        continue;
 
-               for (int z1 = 0; z1 != csize; z1++)
-               for (int y1 = 0; y1 != csize; y1++)
-               for (int x1 = 0; x1 != csize; x1++) {
-                       if (pr.range(1, orechance) != 1)
+               if (biomemap && !biomes.empty()) {
+                       u32 index = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
+                       std::set<u8>::iterator it = biomes.find(biomemap[index]);
+                       if (it == biomes.end())
+                               continue;
+               }
+
+               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);
@@ -165,13 +173,13 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
 
 void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
-       v3s16 nmin, v3s16 nmax)
+       v3s16 nmin, v3s16 nmax, u8 *biomemap)
 {
        PseudoRandom pr(blockseed + 4234);
        MapNode n_ore(c_ore, 0, ore_param2);
 
-       int max_height = clust_size;
-       int y_start = pr.range(nmin.Y, nmax.Y - max_height);
+       u16 max_height = column_height_max;
+       int y_start = pr.range(nmin.Y + max_height, nmax.Y - max_height);
 
        if (!noise) {
                int sx = nmax.X - nmin.X + 1;
@@ -183,15 +191,23 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
        size_t index = 0;
        for (int z = nmin.Z; z <= nmax.Z; z++)
-       for (int x = nmin.X; x <= nmax.X; x++) {
-               float noiseval = noise->result[index++];
+       for (int x = nmin.X; x <= nmax.X; x++, index++) {
+               float noiseval = noise->result[index];
                if (noiseval < nthresh)
                        continue;
 
-               int height = max_height * (1. / pr.range(1, 3));
-               int y0 = y_start + np.scale * noiseval; //pr.range(1, 3) - 1;
+               if (biomemap && !biomes.empty()) {
+                       std::set<u8>::iterator 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 = ymidpoint - height * (1 - column_midpoint_factor);
                int y1 = y0 + height;
-               for (int y = y0; y != y1; y++) {
+
+               for (int y = y0; y < y1; y++) {
                        u32 i = vm->m_area.index(x, y, z);
                        if (!vm->m_area.contains(i))
                                continue;
@@ -206,33 +222,129 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
 ///////////////////////////////////////////////////////////////////////////////
 
+OrePuff::OrePuff() :
+       Ore()
+{
+       noise_puff_top    = NULL;
+       noise_puff_bottom = NULL;
+}
+
+
+OrePuff::~OrePuff()
+{
+       delete noise_puff_top;
+       delete noise_puff_bottom;
+}
+
+
+void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, u8 *biomemap)
+{
+       PseudoRandom pr(blockseed + 4234);
+       MapNode n_ore(c_ore, 0, ore_param2);
+
+       int y_start = pr.range(nmin.Y, nmax.Y);
+
+       if (!noise) {
+               int sx = nmax.X - nmin.X + 1;
+               int sz = nmax.Z - nmin.Z + 1;
+               noise = new Noise(&np, 0, sx, sz);
+               noise_puff_top = new Noise(&np_puff_top, 0, sx, sz);
+               noise_puff_bottom = new Noise(&np_puff_bottom, 0, sx, sz);
+       }
+
+       noise->seed = mapseed + y_start;
+       noise->perlinMap2D(nmin.X, nmin.Z);
+       bool noise_generated = false;
+
+       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;
+
+               if (biomemap && !biomes.empty()) {
+                       std::set<u8>::iterator 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);
+               }
+
+               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;
+                       }
+               }
+
+               int ymid = y_start;
+               int y0 = ymid - nbottom;
+               int y1 = ymid + ntop;
+
+               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;
+
+                       vm->m_data[i] = n_ore;
+               }
+       }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
 void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
-       v3s16 nmin, v3s16 nmax)
+       v3s16 nmin, v3s16 nmax, u8 *biomemap)
 {
        PseudoRandom pr(blockseed + 2404);
        MapNode n_ore(c_ore, 0, ore_param2);
 
-       int volume = (nmax.X - nmin.X + 1) *
+       u32 sizex  = (nmax.X - nmin.X + 1);
+       u32 volume = (nmax.X - nmin.X + 1) *
                                 (nmax.Y - nmin.Y + 1) *
                                 (nmax.Z - nmin.Z + 1);
-       int csize  = clust_size;
-       int nblobs = volume / clust_scarcity;
+       u32 csize  = clust_size;
+       u32 nblobs = volume / clust_scarcity;
 
        if (!noise)
                noise = new Noise(&np, mapseed, csize, csize, csize);
 
-       for (int i = 0; i != nblobs; i++) {
+       for (u32 i = 0; i != nblobs; i++) {
                int x0 = pr.range(nmin.X, nmax.X - csize + 1);
                int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
                int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
 
+               if (biomemap && !biomes.empty()) {
+                       u32 bmapidx = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
+                       std::set<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+                       if (it == biomes.end())
+                               continue;
+               }
+
                bool noise_generated = false;
                noise->seed = blockseed + i;
 
                size_t index = 0;
-               for (int z1 = 0; z1 != csize; z1++)
-               for (int y1 = 0; y1 != csize; y1++)
-               for (int x1 = 0; x1 != csize; x1++, index++) {
+               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;
@@ -263,7 +375,8 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
 ///////////////////////////////////////////////////////////////////////////////
 
-OreVein::OreVein()
+OreVein::OreVein() :
+       Ore()
 {
        noise2 = NULL;
 }
@@ -276,11 +389,13 @@ OreVein::~OreVein()
 
 
 void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
-       v3s16 nmin, v3s16 nmax)
+       v3s16 nmin, v3s16 nmax, u8 *biomemap)
 {
        PseudoRandom pr(blockseed + 520);
        MapNode n_ore(c_ore, 0, ore_param2);
 
+       u32 sizex = (nmax.X - nmin.X + 1);
+
        if (!noise) {
                int sx = nmax.X - nmin.X + 1;
                int sy = nmax.Y - nmin.Y + 1;
@@ -300,6 +415,13 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
                if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
                        continue;
 
+               if (biomemap && !biomes.empty()) {
+                       u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
+                       std::set<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+                       if (it == biomes.end())
+                               continue;
+               }
+
                // Same lazy generation optimization as in OreBlob
                if (!noise_generated) {
                        noise_generated = true;
@@ -308,7 +430,7 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
                }
 
                // randval ranges from -1..1
-               float randval   = (float)pr.next() / (PSEUDORANDOM_MAX / 2) - 1.f;
+               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)