#include "mg_ore.h"
#include "mapgen.h"
#include "noise.h"
-#include "util/numeric.h"
#include "map.h"
#include "log.h"
+#include <algorithm>
+
FlagDesc flagdesc_ore[] = {
{"absheight", OREFLAG_ABSHEIGHT},
void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax, u8 *biomemap)
{
- PseudoRandom pr(blockseed);
+ PcgRandom pr(blockseed);
MapNode n_ore(c_ore, 0, ore_param2);
u32 sizex = (nmax.X - nmin.X + 1);
if (biomemap && !biomes.empty()) {
u32 index = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
- std::set<u8>::iterator it = biomes.find(biomemap[index]);
+ UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax, u8 *biomemap)
{
- PseudoRandom pr(blockseed + 4234);
+ PcgRandom pr(blockseed + 4234);
MapNode n_ore(c_ore, 0, ore_param2);
u16 max_height = column_height_max;
- int y_start = pr.range(nmin.Y + max_height, nmax.Y - max_height);
+ int y_start_min = nmin.Y + max_height;
+ int y_start_max = nmax.Y - max_height;
+
+ int y_start = y_start_min < y_start_max ?
+ pr.range(y_start_min, y_start_max) :
+ (y_start_min + y_start_max) / 2;
if (!noise) {
int sx = nmax.X - nmin.X + 1;
continue;
if (biomemap && !biomes.empty()) {
- std::set<u8>::iterator it = biomes.find(biomemap[index]);
+ UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
u16 height = pr.range(column_height_min, column_height_max);
int ymidpoint = y_start + noiseval;
- int y0 = ymidpoint - height * (1 - column_midpoint_factor);
- int y1 = y0 + height;
+ int y0 = MYMAX(nmin.Y, ymidpoint - height * (1 - column_midpoint_factor));
+ int y1 = MYMIN(nmax.Y, y0 + height - 1);
- for (int y = y0; y < y1; y++) {
+ for (int y = y0; y <= y1; y++) {
u32 i = vm->m_area.index(x, y, z);
if (!vm->m_area.contains(i))
continue;
void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax, u8 *biomemap)
{
- PseudoRandom pr(blockseed + 4234);
+ PcgRandom pr(blockseed + 4234);
MapNode n_ore(c_ore, 0, ore_param2);
int y_start = pr.range(nmin.Y, nmax.Y);
continue;
if (biomemap && !biomes.empty()) {
- std::set<u8>::iterator it = biomes.find(biomemap[index]);
+ UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[index]);
if (it == biomes.end())
continue;
}
void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax, u8 *biomemap)
{
- PseudoRandom pr(blockseed + 2404);
+ PcgRandom pr(blockseed + 2404);
MapNode n_ore(c_ore, 0, ore_param2);
u32 sizex = (nmax.X - nmin.X + 1);
if (biomemap && !biomes.empty()) {
u32 bmapidx = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
- std::set<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+ UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[bmapidx]);
if (it == biomes.end())
continue;
}
float noiseval = noise->result[index];
- float xdist = x1 - csize / 2;
- float ydist = y1 - csize / 2;
- float zdist = z1 - csize / 2;
+ float xdist = (s32)x1 - (s32)csize / 2;
+ float ydist = (s32)y1 - (s32)csize / 2;
+ float zdist = (s32)z1 - (s32)csize / 2;
noiseval -= (sqrt(xdist * xdist + ydist * ydist + zdist * zdist) / csize);
void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax, u8 *biomemap)
{
- PseudoRandom pr(blockseed + 520);
+ PcgRandom pr(blockseed + 520);
MapNode n_ore(c_ore, 0, ore_param2);
u32 sizex = (nmax.X - nmin.X + 1);
if (biomemap && !biomes.empty()) {
u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
- std::set<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+ UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[bmapidx]);
if (it == biomes.end())
continue;
}