Allow multiple 'wherein' nodes in oredef
authorPilzAdam <pilzadam@minetest.net>
Thu, 1 Aug 2013 22:29:27 +0000 (00:29 +0200)
committerPilzAdam <pilzadam@minetest.net>
Thu, 1 Aug 2013 22:55:16 +0000 (00:55 +0200)
src/mapgen.cpp
src/mapgen.h
src/script/lua_api/luaapi.cpp

index d285129fb880089aaf441f77c3929db9c3e81434..f446d05b7d41ea8ecc02ec07773de17922090ee3 100644 (file)
@@ -91,18 +91,17 @@ void Ore::resolveNodeNames(INodeDefManager *ndef) {
                if (ore == CONTENT_IGNORE) {
                        errorstream << "Ore::resolveNodeNames: ore node '"
                                << ore_name << "' not defined";
-                       ore     = CONTENT_AIR;
-                       wherein = CONTENT_AIR;
+                       ore = CONTENT_AIR;
+                       wherein.push_back(CONTENT_AIR);
+                       return;
                }
        }
 
-       if (wherein == CONTENT_IGNORE) {
-               wherein = ndef->getId(wherein_name);
-               if (wherein == CONTENT_IGNORE) {
-                       errorstream << "Ore::resolveNodeNames: wherein node '"
-                               << wherein_name << "' not defined";
-                       ore     = CONTENT_AIR;
-                       wherein = CONTENT_AIR;
+       for (size_t i=0; i != wherein_names.size(); i++) {
+               std::string name = wherein_names[i];
+               content_t c = ndef->getId(name);
+               if (c != CONTENT_IGNORE) {
+                       wherein.push_back(c);
                }
        }
 }
@@ -161,8 +160,9 @@ void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
                                continue;
 
                        u32 i = vm->m_area.index(x0 + x1, y0 + y1, z0 + z1);
-                       if (vm->m_data[i].getContent() == wherein)
-                               vm->m_data[i] = n_ore;
+                       for (size_t ii = 0; ii < wherein.size(); ii++)
+                               if (vm->m_data[i].getContent() == wherein[ii])
+                                       vm->m_data[i] = n_ore;
                }
        }
 }
@@ -199,8 +199,9 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
                        if (!vm->m_area.contains(i))
                                continue;
 
-                       if (vm->m_data[i].getContent() == wherein)
-                               vm->m_data[i] = n_ore;
+                       for (size_t ii = 0; ii < wherein.size(); ii++)
+                               if (vm->m_data[i].getContent() == wherein[ii])
+                                       vm->m_data[i] = n_ore;
                }
        }
 }
index b167978d7e5f045fcbff40084bbff5bf3e036122..8aff332882928b44920b6b805430d3b390467f63 100644 (file)
@@ -149,9 +149,9 @@ enum OreType {
 class Ore {
 public:
        std::string ore_name;
-       std::string wherein_name;
+       std::vector<std::string> wherein_names;
        content_t ore;
-       content_t wherein;  // the node to be replaced
+       std::vector<content_t> wherein;  // the node to be replaced
        u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
        s16 clust_num_ores; // how many ore nodes are in a chunk
        s16 clust_size;     // how large (in nodes) a chunk of ore is
@@ -165,7 +165,6 @@ public:
        
        Ore() {
                ore     = CONTENT_IGNORE;
-               wherein = CONTENT_IGNORE;
                np      = NULL;
                noise   = NULL;
        }
index 020d1cf324aecab6f3f02897f0f5960fe9506d03..0d4c7da7bb9b871f2c202b242355815b40f7f9c7 100644 (file)
@@ -672,7 +672,6 @@ int ModApiBasic::l_register_ore(lua_State *L)
 
        ore->ore_name       = getstringfield_default(L, index, "ore", "");
        ore->ore_param2     = (u8)getintfield_default(L, index, "ore_param2", 0);
-       ore->wherein_name   = getstringfield_default(L, index, "wherein", "");
        ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
        ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);
        ore->clust_size     = getintfield_default(L, index, "clust_size", 0);
@@ -681,6 +680,21 @@ int ModApiBasic::l_register_ore(lua_State *L)
        ore->flags          = getflagsfield(L, index, "flags", flagdesc_ore);
        ore->nthresh        = getfloatfield_default(L, index, "noise_threshhold", 0.);
 
+       lua_getfield(L, index, "wherein");
+       if (lua_istable(L, -1)) {
+               int  i = lua_gettop(L);
+               lua_pushnil(L);
+               while(lua_next(L, i) != 0) {
+                       ore->wherein_names.push_back(lua_tostring(L, -1));
+                       lua_pop(L, 1);
+               }
+       } else if (lua_isstring(L, -1)) {
+               ore->wherein_names.push_back(lua_tostring(L, -1));
+       } else {
+               ore->wherein_names.push_back("");
+       }
+       lua_pop(L, 1);
+
        lua_getfield(L, index, "noise_params");
        ore->np = read_noiseparams(L, -1);
        lua_pop(L, 1);