Ore: Add biomes parameter

This commit is contained in:
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
-- given point to decide if ore should be placed. Set to 0 for solid veins.
-- ^ 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`)

View File

@ -112,7 +112,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;
}
@ -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,
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 orechance = (csize * csize * csize) / clust_num_ores;
u32 nclusters = volume / clust_scarcity;
for (int i = 0; i != nclusters; i++) {
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))
continue;
for (int z1 = 0; z1 != csize; z1++)
for (int y1 = 0; y1 != csize; y1++)
for (int x1 = 0; x1 != csize; x1++) {
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, orechance) != 1)
continue;
@ -163,7 +171,7 @@ 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);
@ -181,11 +189,17 @@ 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;
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 y0 = y_start + np.scale * noiseval; //pr.range(1, 3) - 1;
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,
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;
@ -274,11 +296,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;
@ -298,6 +322,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;

View File

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

View File

@ -847,6 +847,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
luaL_checktype(L, index, LUA_TTABLE);
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr;
enum OreType oretype = (OreType)getenumfield(L, index,
@ -866,6 +867,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->noise = NULL;
ore->flags = 0;
//// Get y_min/y_max
warn_if_field_exists(L, index, "height_min",
"Deprecated: new name is \"y_min\".");
warn_if_field_exists(L, index, "height_max",
@ -888,8 +890,16 @@ int ModApiMapgen::l_register_ore(lua_State *L)
return 0;
}
//// Get flags
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");
if (read_noiseparams(L, -1, &ore->np)) {
ore->flags |= OREFLAG_USE_NOISE;