Simple decorations: Add 'param2_max' parameter for random param2
authorparamat <paramat@users.noreply.github.com>
Sun, 8 Oct 2017 20:08:52 +0000 (21:08 +0100)
committerparamat <mat.gregory@virginmedia.com>
Mon, 9 Oct 2017 17:27:17 +0000 (18:27 +0100)
If 'param2_max' is not used, parameter 'param2' works as before for
compatibility.
If 'param2_max' is used, 'param2' and 'param2_max' become the lower
and upper bounds of a per-decoration random param2.

doc/lua_api.txt
src/mg_decoration.cpp
src/mg_decoration.h
src/script/lua_api/l_mapgen.cpp

index 703e81436a3ba98fe5a978b35a57232e96decb71..63c4bea4817604a0be03bf664af4197fab8d12ae 100644 (file)
@@ -4842,6 +4842,10 @@ Definition tables
     --  ^ If absent, the parameter 'height' is used as a constant.
         param2 = 0,
     --  ^ Param2 value of placed decoration node.
+    --  ^ If param2_max is not 0, this is the lower bound of the randomly selected param2.
+        param2_max = 0,
+    --  ^ Upper bound of the randomly selected param2.
+    --  ^ If absent, the parameter 'param2' is used as a constant.
 
         ----- Schematic-type parameters
         schematic = "foobar.mts",
index 094694e44bffb2d4cf2a2afede7c9a3679e3985a..cb4705177b3adefd80ec9340b882d9d30f55c8cc 100644 (file)
@@ -227,6 +227,9 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
        s16 height = (deco_height_max > 0) ?
                pr->range(deco_height, deco_height_max) : deco_height;
 
+       u8 param2 = (deco_param2_max > 0) ?
+               pr->range(deco_param2, deco_param2_max) : deco_param2;
+
        bool force_placement = (flags & DECO_FORCE_PLACEMENT);
 
        const v3s16 &em = vm->m_area.getExtent();
@@ -239,7 +242,7 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
                                !force_placement)
                        break;
 
-               vm->m_data[vi] = MapNode(c_place, 0, deco_param2);
+               vm->m_data[vi] = MapNode(c_place, 0, param2);
        }
 
        return 1;
index 31f6871d90d7942e71650848e340bd5da7cafdc4..b63e62effc197fca7451ac0e3330176e0de4c54e 100644 (file)
@@ -84,6 +84,7 @@ public:
        s16 deco_height;
        s16 deco_height_max;
        u8 deco_param2;
+       u8 deco_param2_max;
 };
 
 
index b179ac40717818f7ccbbc198df1fdbf6c368e65c..f475a8f7f952be5506cdc7e79cf140a4c059024e 100644 (file)
@@ -981,6 +981,7 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
 {
        int index = 1;
        int param2;
+       int param2_max;
 
        deco->deco_height     = getintfield_default(L, index, "height", 1);
        deco->deco_height_max = getintfield_default(L, index, "height_max", 0);
@@ -993,6 +994,7 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
 
        size_t nnames = getstringlistfield(L, index, "decoration", &deco->m_nodenames);
        deco->m_nnlistsizes.push_back(nnames);
+
        if (nnames == 0) {
                errorstream << "register_decoration: no decoration nodes "
                        "defined" << std::endl;
@@ -1000,12 +1002,16 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
        }
 
        param2 = getintfield_default(L, index, "param2", 0);
-       if ((param2 < 0) || (param2 > 255)) {
-               errorstream << "register_decoration: param2 out of bounds (0-255)"
+       param2_max = getintfield_default(L, index, "param2_max", 0);
+
+       if (param2 < 0 || param2 > 255 || param2_max < 0 || param2_max > 255) {
+               errorstream << "register_decoration: param2 or param2_max out of bounds (0-255)"
                        << std::endl;
                return false;
        }
+
        deco->deco_param2 = (u8)param2;
+       deco->deco_param2_max = (u8)param2_max;
 
        return true;
 }