Ore: Add Blob ore type

master
kwolekr 2014-12-28 03:11:00 -05:00
parent 8c98f497d9
commit 900fa26965
4 changed files with 84 additions and 19 deletions

View File

@ -562,9 +562,9 @@ All default ores are of the uniformly-distributed scatter type.
The height of the blob is randomly scattered, with a maximum height of clust_size.
clust_scarcity and clust_num_ores are ignored.
This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
- claylike - NOT YET IMPLEMENTED
Places ore if there are no more than clust_scarcity number of specified nodes within a Von Neumann
neighborhood of clust_size radius.
- blob
Creates a roundish blob of ore according to 3d perlin noise described by noise_params. The maximum
size of the blob is clust_size, and clust_scarcity has the same meaning as with scatter type.
Ore attributes

View File

@ -178,12 +178,12 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
if (!noise) {
int sx = nmax.X - nmin.X + 1;
int sz = nmax.Z - nmin.Z + 1;
noise = new Noise(&np, seed, sx, sz);
noise = new Noise(&np, 0, sx, sz);
}
noise->seed = seed + y_start;
noise->perlinMap2D(nmin.X, nmin.Z);
int index = 0;
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++];
@ -204,3 +204,60 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
}
}
}
///////////////////////////////////////////////////////////////////////////////
void OreBlob::generate(ManualMapVoxelManipulator *vm, int seed, u32 blockseed,
v3s16 nmin, v3s16 nmax)
{
PseudoRandom pr(blockseed + 2404);
MapNode n_ore(c_ore, 0, ore_param2);
int 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;
if (!noise)
noise = new Noise(&np, seed, csize, csize, csize);
for (int 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);
bool noise_generated = false;
noise->seed = blockseed + i;
size_t index = 0;
for (int z1 = 0; z1 != csize; z1++)
for (int y1 = 0; y1 != csize; y1++)
for (int x1 = 0; x1 != csize; x1++, index++) {
u32 i = vm->m_area.index(x0 + x1, y0 + y1, z0 + z1);
if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
continue;
// Lazily generate noise only if there's a chance of ore being placed
// This simple optimization makes calls 6x faster on average
if (!noise_generated) {
noise_generated = true;
noise->perlinMap3D(x0, y0, z0);
}
float noiseval = noise->result[index];
float xdist = x1 - csize / 2;
float ydist = y1 - csize / 2;
float zdist = z1 - csize / 2;
noiseval -= (sqrt(xdist * xdist + ydist * ydist + zdist * zdist) / csize);
if (noiseval < nthresh)
continue;
vm->m_data[i] = n_ore;
}
}
}

View File

@ -47,9 +47,9 @@ class ManualMapVoxelManipulator;
enum OreType {
ORE_SCATTER,
ORE_SHEET,
ORE_CLAYLIKE
ORE_TYPE_SCATTER,
ORE_TYPE_SHEET,
ORE_TYPE_BLOB,
};
extern FlagDesc flagdesc_ore[];
@ -78,7 +78,7 @@ public:
size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
};
class OreScatter : public Ore {
@ -86,7 +86,7 @@ public:
static const bool NEEDS_NOISE = false;
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax);
u32 blockseed, v3s16 nmin, v3s16 nmax);
};
class OreSheet : public Ore {
@ -94,7 +94,15 @@ public:
static const bool NEEDS_NOISE = true;
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax);
u32 blockseed, v3s16 nmin, v3s16 nmax);
};
class OreBlob : public Ore {
public:
static const bool NEEDS_NOISE = true;
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax);
};
class OreManager : public GenElementManager {
@ -108,12 +116,12 @@ public:
Ore *create(int type)
{
switch (type) {
case ORE_SCATTER:
case ORE_TYPE_SCATTER:
return new OreScatter;
case ORE_SHEET:
case ORE_TYPE_SHEET:
return new OreSheet;
//case ORE_CLAYLIKE: //TODO: implement this!
// return new OreClaylike;
case ORE_TYPE_BLOB:
return new OreBlob;
default:
return NULL;
}

View File

@ -68,9 +68,9 @@ struct EnumString ModApiMapgen::es_MapgenObject[] =
struct EnumString ModApiMapgen::es_OreType[] =
{
{ORE_SCATTER, "scatter"},
{ORE_SHEET, "sheet"},
{ORE_CLAYLIKE, "claylike"},
{ORE_TYPE_SCATTER, "scatter"},
{ORE_TYPE_SHEET, "sheet"},
{ORE_TYPE_BLOB, "blob"},
{0, NULL},
};
@ -642,7 +642,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr;
enum OreType oretype = (OreType)getenumfield(L, index,
"ore_type", es_OreType, ORE_SCATTER);
"ore_type", es_OreType, ORE_TYPE_SCATTER);
Ore *ore = oremgr->create(oretype);
if (!ore) {
errorstream << "register_ore: ore_type " << oretype << " not implemented";