#include "mg_ore.h"
#include "mapgen.h"
+#include "noise.h"
#include "util/numeric.h"
#include "map.h"
#include "log.h"
+const char *OreManager::ELEMENT_TITLE = "ore";
FlagDesc flagdesc_ore[] = {
{"absheight", OREFLAG_ABSHEIGHT},
{NULL, 0}
};
+
///////////////////////////////////////////////////////////////////////////////
-Ore *createOre(OreType type)
+OreManager::OreManager(IGameDef *gamedef) :
+ GenElementManager(gamedef)
+{
+}
+
+
+size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)
{
- switch (type) {
- case ORE_SCATTER:
- return new OreScatter;
- case ORE_SHEET:
- return new OreSheet;
- //case ORE_CLAYLIKE: //TODO: implement this!
- // return new OreClaylike;
- default:
- return NULL;
+ size_t nplaced = 0;
+
+ for (size_t i = 0; i != m_elements.size(); i++) {
+ Ore *ore = (Ore *)m_elements[i];
+ if (!ore)
+ continue;
+
+ nplaced += ore->placeOre(mg, seed, nmin, nmax);
+ seed++;
}
+
+ return nplaced;
+}
+
+
+void OreManager::clear()
+{
+ for (size_t i = 0; i < m_elements.size(); i++) {
+ Ore *ore = (Ore *)m_elements[i];
+ delete ore;
+ }
+ m_elements.clear();
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+Ore::Ore()
+{
+ flags = 0;
+ noise = NULL;
}
Ore::~Ore()
{
- delete np;
delete noise;
}
-void Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
+void Ore::resolveNodeNames(NodeResolveInfo *nri)
+{
+ m_ndef->getIdFromResolveInfo(nri, "", CONTENT_AIR, c_ore);
+ m_ndef->getIdsFromResolveInfo(nri, c_wherein);
+}
+
+
+size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
{
int in_range = 0;
if (flags & OREFLAG_ABSHEIGHT)
in_range |= (nmin.Y >= -height_max && nmax.Y <= -height_min) << 1;
if (!in_range)
- return;
+ return 0;
int ymin, ymax;
if (in_range & ORE_RANGE_MIRROR) {
ymax = MYMIN(nmax.Y, height_max);
}
if (clust_size >= ymax - ymin + 1)
- return;
+ return 0;
nmin.Y = ymin;
nmax.Y = ymax;
generate(mg->vm, mg->seed, blockseed, nmin, nmax);
+
+ return 1;
}
+///////////////////////////////////////////////////////////////////////////////
+
+
void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax)
{
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, seed) < nthresh))
+ if ((flags & OREFLAG_USE_NOISE) &&
+ (NoisePerlin3D(&np, x0, y0, z0, seed) < nthresh))
continue;
for (int z1 = 0; z1 != csize; z1++)
}
+///////////////////////////////////////////////////////////////////////////////
+
+
void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax)
{
if (!noise) {
int sx = nmax.X - nmin.X + 1;
int sz = nmax.Z - nmin.Z + 1;
- noise = new Noise(np, 0, sx, sz);
+ noise = new Noise(&np, seed, sx, sz);
}
noise->seed = seed + y_start;
noise->perlinMap2D(nmin.X, nmin.Z);
continue;
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;
for (int y = y0; y != y1; y++) {
u32 i = vm->m_area.index(x, y, z);
}
}
}
-