#include "constants.h"
#include "map.h"
#include "main.h"
+#include "util/numeric.h"
#include "log.h"
/////////////////// Mapgen Indev perlin noise (default values - not used, from config or defaultsettings)
MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params, EmergeManager *emerge)
: MapgenV6(mapgenid, params, emerge)
{
- noiseindev_terrain_base = new NoiseIndev(params->npindev_terrain_base, seed, csize.X, csize.Z);
- noiseindev_terrain_higher = new NoiseIndev(params->npindev_terrain_higher, seed, csize.X, csize.Z);
- noiseindev_steepness = new NoiseIndev(params->npindev_steepness, seed, csize.X, csize.Z);
-// noise_height_select = new Noise(params->np_height_select, seed, csize.X, csize.Y);
-// noise_trees = new Noise(params->np_trees, seed, csize.X, csize.Y);
- noiseindev_mud = new NoiseIndev(params->npindev_mud, seed, csize.X, csize.Z);
-// noise_beach = new Noise(params->np_beach, seed, csize.X, csize.Y);
- noiseindev_float_islands1 = new NoiseIndev(params->npindev_float_islands1, seed, csize.X, csize.Y, csize.Z);
- noiseindev_float_islands2 = new NoiseIndev(params->npindev_float_islands2, seed, csize.X, csize.Y, csize.Z);
- noiseindev_float_islands3 = new NoiseIndev(params->npindev_float_islands3, seed, csize.X, csize.Z);
- noiseindev_biome = new NoiseIndev(params->npindev_biome, seed, csize.X, csize.Z);
+ noiseindev_terrain_base = new NoiseIndev(¶ms->npindev_terrain_base, seed, csize.X, csize.Z);
+ noiseindev_terrain_higher = new NoiseIndev(¶ms->npindev_terrain_higher, seed, csize.X, csize.Z);
+ noiseindev_steepness = new NoiseIndev(¶ms->npindev_steepness, seed, csize.X, csize.Z);
+ noiseindev_mud = new NoiseIndev(¶ms->npindev_mud, seed, csize.X, csize.Z);
+ noiseindev_float_islands1 = new NoiseIndev(¶ms->npindev_float_islands1, seed, csize.X, csize.Y, csize.Z);
+ noiseindev_float_islands2 = new NoiseIndev(¶ms->npindev_float_islands2, seed, csize.X, csize.Y, csize.Z);
+ noiseindev_float_islands3 = new NoiseIndev(¶ms->npindev_float_islands3, seed, csize.X, csize.Z);
+ noiseindev_biome = new NoiseIndev(¶ms->npindev_biome, seed, csize.X, csize.Z);
}
MapgenIndev::~MapgenIndev() {
z + 0.5 * noiseindev_float_islands3->npindev->spread.Z * farscale(noiseindev_float_islands3->npindev->farspread, x, z));
noiseindev_float_islands3->transformNoiseMapFarScale(x, y, z);
- }
-
- if (!(flags & MG_FLAT)) {
noiseindev_mud->perlinMap2D(
x + 0.5 * noiseindev_mud->npindev->spread.X * farscale(noiseindev_mud->npindev->farspread, x, y, z),
z + 0.5 * noiseindev_mud->npindev->spread.Z * farscale(noiseindev_mud->npindev->farspread, x, y, z));
}
bool MapgenIndevParams::readParams(Settings *settings) {
- freq_desert = settings->getFloat("mgv6_freq_desert");
- freq_beach = settings->getFloat("mgv6_freq_beach");
-
- npindev_terrain_base = settings->getNoiseIndevParams("mgindev_np_terrain_base");
- npindev_terrain_higher = settings->getNoiseIndevParams("mgindev_np_terrain_higher");
- npindev_steepness = settings->getNoiseIndevParams("mgindev_np_steepness");
- np_height_select = settings->getNoiseParams("mgv6_np_height_select");
- np_trees = settings->getNoiseParams("mgv6_np_trees");
- npindev_mud = settings->getNoiseIndevParams("mgindev_np_mud");
- np_beach = settings->getNoiseParams("mgv6_np_beach");
- npindev_biome = settings->getNoiseIndevParams("mgindev_np_biome");
- np_cave = settings->getNoiseParams("mgv6_np_cave");
- npindev_float_islands1 = settings->getNoiseIndevParams("mgindev_np_float_islands1");
- npindev_float_islands2 = settings->getNoiseIndevParams("mgindev_np_float_islands2");
- npindev_float_islands3 = settings->getNoiseIndevParams("mgindev_np_float_islands3");
-
- bool success =
- npindev_terrain_base && npindev_terrain_higher && npindev_steepness &&
- np_height_select && np_trees && npindev_mud &&
- np_beach && np_biome && np_cave &&
- npindev_float_islands1 && npindev_float_islands2 && npindev_float_islands3;
- return success;
+ freq_desert = settings->getFloat("mgv6_freq_desert");
+ freq_beach = settings->getFloat("mgv6_freq_beach");
+
+ bool success =
+ settings->getNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base) &&
+ settings->getNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher) &&
+ settings->getNoiseIndevParams("mgindev_np_steepness", npindev_steepness) &&
+ settings->getNoiseParams("mgv6_np_height_select", np_height_select) &&
+ settings->getNoiseParams("mgv6_np_trees", np_trees) &&
+ settings->getNoiseIndevParams("mgindev_np_mud", npindev_mud) &&
+ settings->getNoiseParams("mgv6_np_beach", np_beach) &&
+ settings->getNoiseIndevParams("mgindev_np_biome", npindev_biome) &&
+ settings->getNoiseParams("mgv6_np_cave", np_cave) &&
+ settings->getNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1) &&
+ settings->getNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2) &&
+ settings->getNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
+ return success;
}
void MapgenIndevParams::writeParams(Settings *settings) {
- settings->setFloat("mgv6_freq_desert", freq_desert);
- settings->setFloat("mgv6_freq_beach", freq_beach);
-
- settings->setNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base);
- settings->setNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher);
- settings->setNoiseIndevParams("mgindev_np_steepness", npindev_steepness);
- settings->setNoiseParams("mgv6_np_height_select", np_height_select);
- settings->setNoiseParams("mgv6_np_trees", np_trees);
- settings->setNoiseIndevParams("mgindev_np_mud", npindev_mud);
- settings->setNoiseParams("mgv6_np_beach", np_beach);
- settings->setNoiseIndevParams("mgindev_np_biome", npindev_biome);
- settings->setNoiseParams("mgv6_np_cave", np_cave);
- settings->setNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1);
- settings->setNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2);
- settings->setNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
+ settings->setFloat("mgv6_freq_desert", freq_desert);
+ settings->setFloat("mgv6_freq_beach", freq_beach);
+
+ settings->setNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base);
+ settings->setNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher);
+ settings->setNoiseIndevParams("mgindev_np_steepness", npindev_steepness);
+ settings->setNoiseParams("mgv6_np_height_select", np_height_select);
+ settings->setNoiseParams("mgv6_np_trees", np_trees);
+ settings->setNoiseIndevParams("mgindev_np_mud", npindev_mud);
+ settings->setNoiseParams("mgv6_np_beach", np_beach);
+ settings->setNoiseIndevParams("mgindev_np_biome", npindev_biome);
+ settings->setNoiseParams("mgv6_np_cave", np_cave);
+ settings->setNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1);
+ settings->setNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2);
+ settings->setNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
}
return noiseindev_mud->result[index];
}
-void MapgenIndev::defineCave(Cave & cave, PseudoRandom ps, v3s16 node_min, bool large_cave) {
- cave.min_tunnel_diameter = 2;
- cave.max_tunnel_diameter = ps.range(2,6);
- cave.dswitchint = ps.range(1,14);
- cave.flooded = large_cave && ps.range(0,4);
- if(large_cave){
- cave.part_max_length_rs = ps.range(2,4);
- if (node_min.Y < -100 && !ps.range(0, farscale(0.2, node_min.X,node_min.Y,node_min.Z)*30)) { //huge
- cave.flooded = !ps.range(0, 3);
- cave.tunnel_routepoints = ps.range(5, 20);
- cave.min_tunnel_diameter = 30;
- cave.max_tunnel_diameter = ps.range(40, ps.range(80,120));
+void MapgenIndev::generateCaves(int max_stone_y) {
+ float cave_amount = NoisePerlin2D(np_cave, node_min.X, node_min.Y, seed);
+ int volume_nodes = (node_max.X - node_min.X + 1) *
+ (node_max.Y - node_min.Y + 1) * MAP_BLOCKSIZE;
+ cave_amount = MYMAX(0.0, cave_amount);
+ u32 caves_count = cave_amount * volume_nodes / 50000;
+ u32 bruises_count = 1;
+ PseudoRandom ps(blockseed + 21343);
+ PseudoRandom ps2(blockseed + 1032);
+
+ if (ps.range(1, 6) == 1)
+ bruises_count = ps.range(0, ps.range(0, 2));
+
+ if (getBiome(v2s16(node_min.X, node_min.Z)) == BT_DESERT) {
+ caves_count /= 3;
+ bruises_count /= 3;
+ }
+
+ for (u32 i = 0; i < caves_count + bruises_count; i++) {
+ bool large_cave = (i >= caves_count);
+ CaveIndev cave(this, &ps, &ps2, node_min, large_cave);
+
+ cave.makeCave(node_min, node_max, max_stone_y);
+ }
+}
+
+CaveIndev::CaveIndev(MapgenIndev *mg, PseudoRandom *ps, PseudoRandom *ps2,
+ v3s16 node_min, bool is_large_cave) {
+ this->vm = mg->vm;
+ this->water_level = mg->water_level;
+ this->large_cave = is_large_cave;
+ this->ps = ps;
+ this->ps2 = ps2;
+ this->c_water_source = mg->c_water_source;
+ this->c_lava_source = mg->c_lava_source;
+
+ min_tunnel_diameter = 2;
+ max_tunnel_diameter = ps->range(2,6);
+ dswitchint = ps->range(1,14);
+ flooded = large_cave && ps->range(0,4);
+ if (large_cave) {
+ part_max_length_rs = ps->range(2,4);
+ float scale = farscale(0.2, node_min.X, node_min.Y, node_min.Z);
+ if (node_min.Y < -100 && !ps->range(0, scale * 30)) { //huge
+ flooded = !ps->range(0, 3);
+ tunnel_routepoints = ps->range(5, 30);
+ min_tunnel_diameter = 30;
+ max_tunnel_diameter = ps->range(40, ps->range(80, 150));
} else {
- cave.tunnel_routepoints = ps.range(5, ps.range(15,30));
- cave.min_tunnel_diameter = 5;
- cave.max_tunnel_diameter = ps.range(7, ps.range(8,24));
+ tunnel_routepoints = ps->range(5, ps->range(15,30));
+ min_tunnel_diameter = 5;
+ max_tunnel_diameter = ps->range(7, ps->range(8,24));
}
} else {
- cave.part_max_length_rs = ps.range(2,9);
- cave.tunnel_routepoints = ps.range(10, ps.range(15,30));
+ part_max_length_rs = ps->range(2,9);
+ tunnel_routepoints = ps->range(10, ps->range(15,30));
}
- cave.large_cave_is_flat = (ps.range(0,1) == 0);
+ large_cave_is_flat = (ps->range(0,1) == 0);
}
/*
float xl = node_max.X - node_min.X;
float yl = node_max.Y - node_min.Y;
float zl = node_max.Z - node_min.Z;
+ u32 zstride = xl + 1;
float midy = node_min.Y + yl * 0.5;
- u32 index = 0, index2d = 0;
- for (int x1 = 0; x1 <= xl; ++x1)
- {
- for (int z1 = 0; z1 <= zl; ++z1, ++index2d)
- {
- float noise3 = noiseindev_float_islands3->result[index2d];
- float pmidy = midy + noise3 / 1.5 * AMPY;
- for (int y1 = 0; y1 <= yl; ++y1, ++index)
- {
- int y = y1 + node_min.Y;
- float noise1 = noiseindev_float_islands1->result[index];
- float offset = y > pmidy ? (y - pmidy) / TGRAD : (pmidy - y) / BGRAD;
- float noise1off = noise1 - offset - RAR;
- if (noise1off > 0 && noise1off < 0.7) {
- float noise2 = noiseindev_float_islands2->result[index];
- if (noise2 - noise1off > -0.7){
- v3s16 p = p0 + v3s16(x1, y1, z1);
- u32 i = vm->m_area.index(p);
- if (!vm->m_area.contains(i))
- continue;
- // Cancel if not air
- if (vm->m_data[i].getContent() != CONTENT_AIR)
- continue;
- vm->m_data[i] = n1;
- }
- }
+ u32 index = 0;
+ for (int z1 = 0; z1 <= zl; ++z1)
+ for (int y1 = 0; y1 <= yl; ++y1)
+ for (int x1 = 0; x1 <= xl; ++x1, ++index) {
+ int y = y1 + node_min.Y;
+ u32 index2d = z1 * zstride + x1;
+ float noise3 = noiseindev_float_islands3->result[index2d];
+ float pmidy = midy + noise3 / 1.5 * AMPY;
+ float noise1 = noiseindev_float_islands1->result[index];
+ float offset = y > pmidy ? (y - pmidy) / TGRAD : (pmidy - y) / BGRAD;
+ float noise1off = noise1 - offset - RAR;
+ if (noise1off > 0 && noise1off < 0.7) {
+ float noise2 = noiseindev_float_islands2->result[index];
+ if (noise2 - noise1off > -0.7) {
+ v3s16 p = p0 + v3s16(x1, y1, z1);
+ u32 i = vm->m_area.index(p);
+ if (!vm->m_area.contains(i))
+ continue;
+ // Cancel if not air
+ if (vm->m_data[i].getContent() != CONTENT_AIR)
+ continue;
+ vm->m_data[i] = n1;
}
}
}
}
-void MapgenIndev::generateSomething() {
+void MapgenIndev::generateExperimental() {
int float_islands = g_settings->getS16("mgindev_float_islands");
- if(float_islands) generateFloatIslands(float_islands);
+ if (float_islands)
+ generateFloatIslands(float_islands);
}