/*
Minetest
-Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2015-2017 paramat
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
#include "mg_ore.h"
#include "mapgen.h"
#include "noise.h"
-#include "util/numeric.h"
#include "map.h"
#include "log.h"
+#include "util/numeric.h"
+#include <algorithm>
+
FlagDesc flagdesc_ore[] = {
- {"absheight", OREFLAG_ABSHEIGHT},
+ {"absheight", OREFLAG_ABSHEIGHT}, // Non-functional
{"puff_cliffs", OREFLAG_PUFF_CLIFFS},
{"puff_additive_composition", OREFLAG_PUFF_ADDITIVE},
{NULL, 0}
void OreManager::clear()
{
- for (size_t i = 0; i < m_objects.size(); i++) {
- Ore *ore = (Ore *)m_objects[i];
+ for (ObjDef *object : m_objects) {
+ Ore *ore = (Ore *) object;
delete ore;
}
m_objects.clear();
///////////////////////////////////////////////////////////////////////////////
-Ore::Ore()
-{
- flags = 0;
- noise = NULL;
-}
-
-
Ore::~Ore()
{
delete noise;
size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
{
- int in_range = 0;
-
- in_range |= (nmin.Y <= y_max && nmax.Y >= y_min);
- if (flags & OREFLAG_ABSHEIGHT)
- in_range |= (nmin.Y >= -y_max && nmax.Y <= -y_min) << 1;
- if (!in_range)
+ if (nmin.Y > y_max || nmax.Y < y_min)
return 0;
- int actual_ymin, actual_ymax;
- if (in_range & ORE_RANGE_MIRROR) {
- actual_ymin = MYMAX(nmin.Y, -y_max);
- actual_ymax = MYMIN(nmax.Y, -y_min);
- } else {
- actual_ymin = MYMAX(nmin.Y, y_min);
- actual_ymax = MYMIN(nmax.Y, y_max);
- }
+ int actual_ymin = MYMAX(nmin.Y, y_min);
+ int actual_ymax = MYMIN(nmax.Y, y_max);
if (clust_size >= actual_ymax - actual_ymin + 1)
return 0;
if (biomemap && !biomes.empty()) {
u32 index = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
- std::set<u8>::iterator it = biomes.find(biomemap[index]);
+ std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
continue;
if (biomemap && !biomes.empty()) {
- std::set<u8>::iterator it = biomes.find(biomemap[index]);
+ std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
///////////////////////////////////////////////////////////////////////////////
-OrePuff::OrePuff() :
- Ore()
-{
- noise_puff_top = NULL;
- noise_puff_bottom = NULL;
-}
-
OrePuff::~OrePuff()
{
continue;
if (biomemap && !biomes.empty()) {
- std::set<u8>::iterator it = biomes.find(biomemap[index]);
+ std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
if (biomemap && !biomes.empty()) {
u32 bmapidx = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
- std::set<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+ std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[bmapidx]);
if (it == biomes.end())
continue;
}
///////////////////////////////////////////////////////////////////////////////
-OreVein::OreVein() :
- Ore()
-{
- noise2 = NULL;
-}
-
OreVein::~OreVein()
{
if (biomemap && !biomes.empty()) {
u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
- std::set<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+ std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[bmapidx]);
if (it == biomes.end())
continue;
}
vm->m_data[i] = n_ore;
}
}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+OreStratum::~OreStratum()
+{
+ delete noise_stratum_thickness;
+}
+
+
+void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, u8 *biomemap)
+{
+ PcgRandom pr(blockseed + 4234);
+ MapNode n_ore(c_ore, 0, ore_param2);
+
+ if (!noise) {
+ int sx = nmax.X - nmin.X + 1;
+ int sz = nmax.Z - nmin.Z + 1;
+ noise = new Noise(&np, 0, sx, sz);
+ noise_stratum_thickness = new Noise(&np_stratum_thickness, 0, sx, sz);
+ }
+ noise->perlinMap2D(nmin.X, nmin.Z);
+ noise_stratum_thickness->perlinMap2D(nmin.X, nmin.Z);
+
+ size_t index = 0;
+
+ for (int z = nmin.Z; z <= nmax.Z; z++)
+ for (int x = nmin.X; x <= nmax.X; x++, index++) {
+ if (biomemap && !biomes.empty()) {
+ std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
+ if (it == biomes.end())
+ continue;
+ }
+
+ float nmid = noise->result[index];
+ float nhalfthick = noise_stratum_thickness->result[index] / 2.0f;
+ int y0 = MYMAX(nmin.Y, nmid - nhalfthick);
+ int y1 = MYMIN(nmax.Y, nmid + nhalfthick);
+
+ for (int y = y0; y <= y1; y++) {
+ if (pr.range(1, clust_scarcity) != 1)
+ continue;
+
+ u32 i = vm->m_area.index(x, y, z);
+ if (!vm->m_area.contains(i))
+ continue;
+ if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
+ continue;
+
+ vm->m_data[i] = n_ore;
+ }
+ }
+}