diff options
author | paramat <paramat@users.noreply.github.com> | 2017-11-18 20:37:00 +0000 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-11-19 00:25:39 +0000 |
commit | 4b553ece09908dfdee59e9841fdc9420350eda9f (patch) | |
tree | 9e40dbc3725fd8e19eb163ed2198641cbd384817 /src | |
parent | c655984849d69e83f0221ff9fbf6ce3782be873f (diff) | |
download | minetest-4b553ece09908dfdee59e9841fdc9420350eda9f.tar.gz minetest-4b553ece09908dfdee59e9841fdc9420350eda9f.tar.bz2 minetest-4b553ece09908dfdee59e9841fdc9420350eda9f.zip |
Stratum ore: Add option for a constant thickness stratum
Add a 'stratum thickness' integer parameter, as an alternative
to providing a 2nd noise parameter for thickness variation.
Diffstat (limited to 'src')
-rw-r--r-- | src/mapgen/mg_ore.cpp | 19 | ||||
-rw-r--r-- | src/mapgen/mg_ore.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 10 |
3 files changed, 22 insertions, 9 deletions
diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp index 979135ed4..297472420 100644 --- a/src/mapgen/mg_ore.cpp +++ b/src/mapgen/mg_ore.cpp @@ -434,13 +434,20 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, MapNode n_ore(c_ore, 0, ore_param2); if (flags & OREFLAG_USE_NOISE) { - if (!(noise && noise_stratum_thickness)) { + 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); + } + + if (flags & OREFLAG_USE_NOISE2) { + 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->perlinMap2D(nmin.X, nmin.Z); } @@ -458,11 +465,13 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, 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]; - float nhalfthick = noise_stratum_thickness->result[index] / 2.0f; - y0 = MYMAX(nmin.Y, nmid - nhalfthick); + y0 = MYMAX(nmin.Y, ceil(nmid - nhalfthick)); y1 = MYMIN(nmax.Y, nmid + nhalfthick); - } else { + } else { // Simple horizontal stratum y0 = nmin.Y; y1 = nmax.Y; } diff --git a/src/mapgen/mg_ore.h b/src/mapgen/mg_ore.h index e715f348b..2bbc8c578 100644 --- a/src/mapgen/mg_ore.h +++ b/src/mapgen/mg_ore.h @@ -35,6 +35,7 @@ class MMVManip; #define OREFLAG_PUFF_CLIFFS 0x02 #define OREFLAG_PUFF_ADDITIVE 0x04 #define OREFLAG_USE_NOISE 0x08 +#define OREFLAG_USE_NOISE2 0x10 enum OreType { ORE_SCATTER, @@ -139,6 +140,7 @@ public: NoiseParams np_stratum_thickness; Noise *noise_stratum_thickness = nullptr; + u16 stratum_thickness; OreStratum() = default; virtual ~OreStratum(); diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 01f9d1c41..e39370323 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -1116,7 +1116,7 @@ int ModApiMapgen::l_register_ore(lua_State *L) ore->flags |= OREFLAG_USE_NOISE; } else if (ore->NEEDS_NOISE) { errorstream << "register_ore: specified ore type requires valid " - "noise parameters" << std::endl; + "'noise_params' parameter" << std::endl; delete ore; return 0; } @@ -1161,11 +1161,13 @@ int ModApiMapgen::l_register_ore(lua_State *L) OreStratum *orestratum = (OreStratum *)ore; lua_getfield(L, index, "np_stratum_thickness"); - // If thickness noise missing unset 'use noise' flag - if (!read_noiseparams(L, -1, &orestratum->np_stratum_thickness)) - ore->flags &= ~OREFLAG_USE_NOISE; + if (read_noiseparams(L, -1, &orestratum->np_stratum_thickness)) + ore->flags |= OREFLAG_USE_NOISE2; lua_pop(L, 1); + orestratum->stratum_thickness = getintfield_default(L, index, + "stratum_thickness", 8); + break; } default: |