Ore: Add biomes parameter

master
kwolekr 2015-04-20 20:25:33 -04:00
parent a443a13a9d
commit 46a2c1f167
4 changed files with 69 additions and 23 deletions

View File

@ -3195,6 +3195,10 @@ Definition tables
-- ^ Multiplier of the randomness contribution to the noise value at any -- ^ Multiplier of the randomness contribution to the noise value at any
-- given point to decide if ore should be placed. Set to 0 for solid veins. -- given point to decide if ore should be placed. Set to 0 for solid veins.
-- ^ This parameter is only valid for ore_type == "vein". -- ^ This parameter is only valid for ore_type == "vein".
biomes = {"desert", "rainforest"}
-- ^ List of biomes in which this decoration occurs. Occurs in all biomes if this is omitted,
-- ^ and ignored if the Mapgen being used does not support biomes.
-- ^ Can be a list of (or a single) biome names, IDs, or definitions.
} }
### Decoration definition (`register_decoration`) ### Decoration definition (`register_decoration`)

View File

@ -112,7 +112,7 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
nmin.Y = actual_ymin; nmin.Y = actual_ymin;
nmax.Y = actual_ymax; nmax.Y = actual_ymax;
generate(mg->vm, mg->seed, blockseed, nmin, nmax); generate(mg->vm, mg->seed, blockseed, nmin, nmax, mg->biomemap);
return 1; return 1;
} }
@ -122,17 +122,18 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax) v3s16 nmin, v3s16 nmax, u8 *biomemap)
{ {
PseudoRandom pr(blockseed); PseudoRandom pr(blockseed);
MapNode n_ore(c_ore, 0, ore_param2); 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.Y - nmin.Y + 1) *
(nmax.Z - nmin.Z + 1); (nmax.Z - nmin.Z + 1);
int csize = clust_size; u32 csize = clust_size;
int orechance = (csize * csize * csize) / clust_num_ores; u32 orechance = (csize * csize * csize) / clust_num_ores;
int nclusters = volume / clust_scarcity; u32 nclusters = volume / clust_scarcity;
for (int i = 0; i != nclusters; i++) { for (int i = 0; i != nclusters; i++) {
int x0 = pr.range(nmin.X, nmax.X - csize + 1); int x0 = pr.range(nmin.X, nmax.X - csize + 1);
@ -143,9 +144,16 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
(NoisePerlin3D(&np, x0, y0, z0, mapseed) < nthresh)) (NoisePerlin3D(&np, x0, y0, z0, mapseed) < nthresh))
continue; continue;
for (int z1 = 0; z1 != csize; z1++) if (biomemap && !biomes.empty()) {
for (int y1 = 0; y1 != csize; y1++) u32 index = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
for (int x1 = 0; x1 != csize; x1++) { 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, orechance) != 1) if (pr.range(1, orechance) != 1)
continue; continue;
@ -163,7 +171,7 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
void OreSheet::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); PseudoRandom pr(blockseed + 4234);
MapNode n_ore(c_ore, 0, ore_param2); MapNode n_ore(c_ore, 0, ore_param2);
@ -181,11 +189,17 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
size_t index = 0; size_t index = 0;
for (int z = nmin.Z; z <= nmax.Z; z++) for (int z = nmin.Z; z <= nmax.Z; z++)
for (int x = nmin.X; x <= nmax.X; x++) { for (int x = nmin.X; x <= nmax.X; x++, index++) {
float noiseval = noise->result[index++]; float noiseval = noise->result[index];
if (noiseval < nthresh) if (noiseval < nthresh)
continue; continue;
if (biomemap && !biomes.empty()) {
std::set<u8>::iterator it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
int height = max_height * (1. / pr.range(1, 3)); int height = max_height * (1. / pr.range(1, 3));
int y0 = y_start + np.scale * noiseval; //pr.range(1, 3) - 1; int y0 = y_start + np.scale * noiseval; //pr.range(1, 3) - 1;
int y1 = y0 + height; int y1 = y0 + height;
@ -205,25 +219,33 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax) v3s16 nmin, v3s16 nmax, u8 *biomemap)
{ {
PseudoRandom pr(blockseed + 2404); PseudoRandom pr(blockseed + 2404);
MapNode n_ore(c_ore, 0, ore_param2); 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.Y - nmin.Y + 1) *
(nmax.Z - nmin.Z + 1); (nmax.Z - nmin.Z + 1);
int csize = clust_size; u32 csize = clust_size;
int nblobs = volume / clust_scarcity; u32 nblobs = volume / clust_scarcity;
if (!noise) if (!noise)
noise = new Noise(&np, mapseed, csize, csize, csize); 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 x0 = pr.range(nmin.X, nmax.X - csize + 1);
int y0 = pr.range(nmin.Y, nmax.Y - csize + 1); int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
int z0 = pr.range(nmin.Z, nmax.Z - 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; bool noise_generated = false;
noise->seed = blockseed + i; noise->seed = blockseed + i;
@ -274,11 +296,13 @@ OreVein::~OreVein()
void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax) v3s16 nmin, v3s16 nmax, u8 *biomemap)
{ {
PseudoRandom pr(blockseed + 520); PseudoRandom pr(blockseed + 520);
MapNode n_ore(c_ore, 0, ore_param2); MapNode n_ore(c_ore, 0, ore_param2);
u32 sizex = (nmax.X - nmin.X + 1);
if (!noise) { if (!noise) {
int sx = nmax.X - nmin.X + 1; int sx = nmax.X - nmin.X + 1;
int sy = nmax.Y - nmin.Y + 1; int sy = nmax.Y - nmin.Y + 1;
@ -298,6 +322,13 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
if (!CONTAINS(c_wherein, vm->m_data[i].getContent())) if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
continue; 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 // Same lazy generation optimization as in OreBlob
if (!noise_generated) { if (!noise_generated) {
noise_generated = true; noise_generated = true;

View File

@ -63,6 +63,7 @@ public:
float nthresh; // threshhold for noise at which an ore is placed float nthresh; // threshhold for noise at which an ore is placed
NoiseParams np; // noise for distribution of clusters (NULL for uniform scattering) NoiseParams np; // noise for distribution of clusters (NULL for uniform scattering)
Noise *noise; Noise *noise;
std::set<u8> biomes;
Ore(); Ore();
virtual ~Ore(); virtual ~Ore();
@ -71,7 +72,7 @@ public:
size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax) = 0; v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0;
}; };
class OreScatter : public Ore { class OreScatter : public Ore {
@ -79,7 +80,7 @@ public:
static const bool NEEDS_NOISE = false; static const bool NEEDS_NOISE = false;
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax); v3s16 nmin, v3s16 nmax, u8 *biomemap);
}; };
class OreSheet : public Ore { class OreSheet : public Ore {
@ -87,7 +88,7 @@ public:
static const bool NEEDS_NOISE = true; static const bool NEEDS_NOISE = true;
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax); v3s16 nmin, v3s16 nmax, u8 *biomemap);
}; };
class OreBlob : public Ore { class OreBlob : public Ore {
@ -95,7 +96,7 @@ public:
static const bool NEEDS_NOISE = true; static const bool NEEDS_NOISE = true;
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax); v3s16 nmin, v3s16 nmax, u8 *biomemap);
}; };
class OreVein : public Ore { class OreVein : public Ore {
@ -109,7 +110,7 @@ public:
virtual ~OreVein(); virtual ~OreVein();
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax); v3s16 nmin, v3s16 nmax, u8 *biomemap);
}; };
class OreManager : public ObjDefManager { class OreManager : public ObjDefManager {

View File

@ -847,6 +847,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
luaL_checktype(L, index, LUA_TTABLE); luaL_checktype(L, index, LUA_TTABLE);
INodeDefManager *ndef = getServer(L)->getNodeDefManager(); INodeDefManager *ndef = getServer(L)->getNodeDefManager();
BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr; OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr;
enum OreType oretype = (OreType)getenumfield(L, index, enum OreType oretype = (OreType)getenumfield(L, index,
@ -866,6 +867,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->noise = NULL; ore->noise = NULL;
ore->flags = 0; ore->flags = 0;
//// Get y_min/y_max
warn_if_field_exists(L, index, "height_min", warn_if_field_exists(L, index, "height_min",
"Deprecated: new name is \"y_min\"."); "Deprecated: new name is \"y_min\".");
warn_if_field_exists(L, index, "height_max", warn_if_field_exists(L, index, "height_max",
@ -888,8 +890,16 @@ int ModApiMapgen::l_register_ore(lua_State *L)
return 0; return 0;
} }
//// Get flags
getflagsfield(L, index, "flags", flagdesc_ore, &ore->flags, NULL); getflagsfield(L, index, "flags", flagdesc_ore, &ore->flags, NULL);
//// Get biomes associated with this decoration (if any)
lua_getfield(L, index, "biomes");
if (get_biome_list(L, -1, bmgr, &ore->biomes))
errorstream << "register_ore: couldn't get all biomes " << std::endl;
lua_pop(L, 1);
//// Get noise parameters if needed
lua_getfield(L, index, "noise_params"); lua_getfield(L, index, "noise_params");
if (read_noiseparams(L, -1, &ore->np)) { if (read_noiseparams(L, -1, &ore->np)) {
ore->flags |= OREFLAG_USE_NOISE; ore->flags |= OREFLAG_USE_NOISE;