aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mapgen.cpp64
-rw-r--r--src/mapgen.h12
-rw-r--r--src/mapgen_v6.cpp2
-rw-r--r--src/mapgen_v7.cpp2
-rw-r--r--src/scriptapi.cpp1
5 files changed, 33 insertions, 48 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index 22488bc4c..0646a8826 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -94,7 +94,7 @@ void Ore::resolveNodeNames(INodeDefManager *ndef) {
}
-void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
+void Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
int in_range = 0;
in_range |= (nmin.Y <= height_max && nmax.Y >= height_min);
@@ -105,9 +105,6 @@ void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
resolveNodeNames(mg->ndef);
- MapNode n_ore(ore);
- ManualMapVoxelManipulator *vm = mg->vm;
- PseudoRandom pr(blockseed);
int ymin, ymax;
if (in_range & ORE_RANGE_MIRROR) {
@@ -120,6 +117,17 @@ void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
if (clust_size >= ymax - ymin + 1)
return;
+ nmin.Y = ymin;
+ nmax.Y = ymax;
+ generate(mg->vm, mg->seed, blockseed, nmin, nmax);
+}
+
+
+void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
+ u32 blockseed, v3s16 nmin, v3s16 nmax) {
+ PseudoRandom pr(blockseed);
+ MapNode n_ore(ore, 0, ore_param2);
+
int volume = (nmax.X - nmin.X + 1) *
(nmax.Y - nmin.Y + 1) *
(nmax.Z - nmin.Z + 1);
@@ -129,10 +137,10 @@ void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
for (int i = 0; i != nclusters; i++) {
int x0 = pr.range(nmin.X, nmax.X - csize + 1);
- int y0 = pr.range(ymin, ymax - csize + 1);
+ int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
- if (np && (NoisePerlin3D(np, x0, y0, z0, mg->seed) < nthresh))
+ if (np && (NoisePerlin3D(np, x0, y0, z0, seed) < nthresh))
continue;
for (int z1 = 0; z1 != csize; z1++)
@@ -149,53 +157,25 @@ void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
}
-void OreSheet::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
- int in_range = 0;
-
- in_range |= (nmin.Y <= height_max && nmax.Y >= height_min);
- if (flags & OREFLAG_ABSHEIGHT)
- in_range |= (nmin.Y >= -height_max && nmax.Y <= -height_min) << 1;
- if (!in_range)
- return;
-
- resolveNodeNames(mg->ndef);
-
- MapNode n_ore(ore);
- ManualMapVoxelManipulator *vm = mg->vm;
+void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
+ u32 blockseed, v3s16 nmin, v3s16 nmax) {
PseudoRandom pr(blockseed + 4234);
- int ymin, ymax;
-
- if (in_range & ORE_RANGE_MIRROR) {
- ymin = MYMAX(nmin.Y, -height_max);
- ymax = MYMIN(nmax.Y, -height_min);
- } else {
- ymin = MYMAX(nmin.Y, height_min);
- ymax = MYMIN(nmax.Y, height_max);
- }
-
- if (clust_size >= ymax - ymin + 1)
- return;
-
- int x0 = nmin.X;
- int z0 = nmin.Z;
-
- int x1 = nmax.X;
- int z1 = nmax.Z;
+ MapNode n_ore(ore, 0, ore_param2);
int max_height = clust_size;
- int y_start = pr.range(ymin, ymax - max_height);
+ int y_start = pr.range(nmin.Y, nmax.Y - max_height);
if (!noise) {
int sx = nmax.X - nmin.X + 1;
int sz = nmax.Z - nmin.Z + 1;
noise = new Noise(np, 0, sx, sz);
}
- noise->seed = mg->seed + y_start;
- noise->perlinMap2D(x0, z0);
+ noise->seed = seed + y_start;
+ noise->perlinMap2D(nmin.X, nmin.Z);
int index = 0;
- for (int z = z0; z != z1; z++)
- for (int x = x0; x != x1; x++) {
+ for (int z = nmin.Z; z <= nmax.Z; z++)
+ for (int x = nmin.X; x <= nmax.X; x++) {
float noiseval = noise->result[index++];
if (noiseval < nthresh)
continue;
diff --git a/src/mapgen.h b/src/mapgen.h
index e708f23b1..17136a137 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -120,7 +120,6 @@ class Ore {
public:
std::string ore_name;
std::string wherein_name;
-
content_t ore;
content_t wherein; // the node to be replaced
u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
@@ -128,6 +127,7 @@ public:
s16 clust_size; // how large (in nodes) a chunk of ore is
s16 height_min;
s16 height_max;
+ u8 ore_param2; // to set node-specific attributes
u32 flags; // attributes for this ore
float nthresh; // threshhold for noise at which an ore is placed
NoiseParams *np; // noise for distribution of clusters (NULL for uniform scattering)
@@ -141,15 +141,19 @@ public:
}
void resolveNodeNames(INodeDefManager *ndef);
- virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
+ void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+ virtual void generate(ManualMapVoxelManipulator *vm, int seed,
+ u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
};
class OreScatter : public Ore {
- void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+ virtual void generate(ManualMapVoxelManipulator *vm, int seed,
+ u32 blockseed, v3s16 nmin, v3s16 nmax);
};
class OreSheet : public Ore {
- void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+ virtual void generate(ManualMapVoxelManipulator *vm, int seed,
+ u32 blockseed, v3s16 nmin, v3s16 nmax);
};
Ore *createOre(OreType type);
diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp
index 4a037bb85..2e44d7b4a 100644
--- a/src/mapgen_v6.cpp
+++ b/src/mapgen_v6.cpp
@@ -467,7 +467,7 @@ void MapgenV6::makeChunk(BlockMakeData *data) {
// Generate the registered ores
for (unsigned int i = 0; i != emerge->ores.size(); i++) {
Ore *ore = emerge->ores[i];
- ore->generate(this, blockseed + i, node_min, node_max);
+ ore->placeOre(this, blockseed + i, node_min, node_max);
}
// Calculate lighting
diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp
index 6aecfe310..8aad37f73 100644
--- a/src/mapgen_v7.cpp
+++ b/src/mapgen_v7.cpp
@@ -180,7 +180,7 @@ void MapgenV7::makeChunk(BlockMakeData *data) {
for (size_t i = 0; i != emerge->ores.size(); i++) {
Ore *ore = emerge->ores[i];
- ore->generate(this, blockseed + i, node_min, node_max);
+ ore->placeOre(this, blockseed + i, node_min, node_max);
}
//printf("makeChunk: %dms\n", t.stop());
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 0227c6a19..8d472e6b8 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -670,6 +670,7 @@ static int l_register_ore(lua_State *L)
}
ore->ore_name = getstringfield_default(L, index, "ore", "");
+ ore->ore_param2 = (u8)getintfield_default(L, index, "ore_param2", 0);
ore->wherein_name = getstringfield_default(L, index, "wherein", "");
ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);