aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorproller <proller@github.com>2013-03-13 00:41:14 +0400
committerkwolekr <kwolekr@minetest.net>2013-03-16 21:48:32 -0400
commit165498cecfc11f3471d84855f4d019be9b353621 (patch)
treea907ea34711c3c56d29c691d985e7047413c018e
parente3badd7062d4bee62335cf100f3f91ef4c370aae (diff)
downloadminetest-165498cecfc11f3471d84855f4d019be9b353621.tar.gz
minetest-165498cecfc11f3471d84855f4d019be9b353621.tar.bz2
minetest-165498cecfc11f3471d84855f4d019be9b353621.zip
initial mapgen indev version with farscale feature and huge caves
-rw-r--r--minetest.conf.example8
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/defaultsettings.cpp6
-rw-r--r--src/emerge.cpp2
-rw-r--r--src/map.cpp1
-rw-r--r--src/mapgen_indev.cpp246
-rw-r--r--src/mapgen_indev.h135
-rw-r--r--src/mapgen_v6.cpp72
-rw-r--r--src/mapgen_v6.h21
-rw-r--r--src/noise.cpp1
-rw-r--r--src/noise.h2
-rw-r--r--src/settings.h2
12 files changed, 456 insertions, 41 deletions
diff --git a/minetest.conf.example b/minetest.conf.example
index 649717ee8..6a227487a 100644
--- a/minetest.conf.example
+++ b/minetest.conf.example
@@ -308,7 +308,7 @@
# Mapgen stuff
#
-# Name of map generator to be used. Currently only v6 is supported.
+# Name of map generator to be used. Currently v6 and indev are supported.
#mg_name = v6
# Water level of map.
#water_level = 1
@@ -337,3 +337,9 @@
#mgv7_np_bgroup = 0.5, 0.3125, (350, 350, 350), 5923, 2, 0.6
#mgv7_np_heat = 25, 50, (500, 500, 500), 35293, 1, 0
#mgv7_np_humidity = 50, 31.25, (750, 750, 750), 12094, 2, 0.6
+
+# Offset, scale, spread factor, seed offset, number of octaves, persistence, farscale
+#mgindev_np_terrain_base = -4, 20, (250.0, 250, 250), 82341, 5, 0.6, 10
+#mgindev_np_terrain_higher = 20, 16, (500, 500, 500), 85039, 5, 0.6, 10
+#mgindev_np_steepness = 0.85, 0.5, (125, 125, 125), -932, 5, 0.7, 10
+#mgindev_np_mud = 4, 2, (200, 200, 200), 91013, 3, 0.55, 1
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 60e2b1d88..0f8396c02 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -225,6 +225,7 @@ set(common_SRCS
emerge.cpp
mapgen.cpp
mapgen_v6.cpp
+ mapgen_indev.cpp
treegen.cpp
dungeongen.cpp
content_nodemeta.cpp
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index f7724fa11..b0ae271ce 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -235,5 +235,11 @@ void set_default_settings(Settings *settings)
settings->setDefault("mgv7_np_bgroup", "0.5, 0.3125, (350, 350, 350), 5923, 2, 0.6");
settings->setDefault("mgv7_np_heat", "25, 50, (500, 500, 500), 35293, 1, 0");
settings->setDefault("mgv7_np_humidity", "50, 31.25, (750, 750, 750), 12094, 2, 0.6");
+
+ settings->setDefault("mgindev_np_terrain_base", "-4, 20, (250.0, 250, 250), 82341, 5, 0.6, 10");
+ settings->setDefault("mgindev_np_terrain_higher", "20, 16, (500, 500, 500), 85039, 5, 0.6, 10");
+ settings->setDefault("mgindev_np_steepness", "0.85, 0.5, (125, 125, 125), -932, 5, 0.7, 10");
+ settings->setDefault("mgindev_np_mud", "4, 2, (200, 200, 200), 91013, 3, 0.55, 1");
+
}
diff --git a/src/emerge.cpp b/src/emerge.cpp
index 8a060d107..5311c1210 100644
--- a/src/emerge.cpp
+++ b/src/emerge.cpp
@@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "biome.h"
#include "emerge.h"
#include "mapgen_v6.h"
+#include "mapgen_indev.h"
/////////////////////////////// Emerge Manager ////////////////////////////////
@@ -46,6 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
EmergeManager::EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef) {
//register built-in mapgens
registerMapgen("v6", new MapgenFactoryV6());
+ registerMapgen("indev", new MapgenFactoryIndev());
this->biomedef = bdef ? bdef : new BiomeDefManager(gamedef);
this->params = NULL;
diff --git a/src/map.cpp b/src/map.cpp
index 6103b9017..3d36675a8 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "rollback_interface.h"
#include "emerge.h"
#include "mapgen_v6.h"
+#include "mapgen_indev.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
diff --git a/src/mapgen_indev.cpp b/src/mapgen_indev.cpp
new file mode 100644
index 000000000..e9ab36ae9
--- /dev/null
+++ b/src/mapgen_indev.cpp
@@ -0,0 +1,246 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+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
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "mapgen_indev.h"
+#include "constants.h"
+#include "log.h"
+
+/////////////////// Mapgen Indev perlin noise default values
+
+NoiseIndevParams nparams_indev_def_terrain_base
+ (-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6, 1);
+NoiseIndevParams nparams_indev_def_terrain_higher
+ (20.0, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6, 1);
+NoiseIndevParams nparams_indev_def_steepness
+ (0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7, 1);
+NoiseIndevParams nparams_indev_def_mud
+ (AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55, 1);
+
+///////////////////////////////////////////////////////////////////////////////
+
+void NoiseIndev::init(NoiseIndevParams *np, int seed, int sx, int sy, int sz) {
+ Noise::init((NoiseParams*)np, seed, sx, sy, sz);
+ this->npindev = np;
+}
+
+
+NoiseIndev::NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy) : Noise(np, seed, sx, sy) {
+ init(np, seed, sx, sy, 1);
+}
+
+
+NoiseIndev::NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy, int sz) : Noise(np, seed, sx, sy, sz) {
+ init(np, seed, sx, sy, sz);
+}
+
+
+float farscale(float scale, float x, float y, float z) {
+ return ( 1 + ( 1 - (MAP_GENERATION_LIMIT * 3 - (fabs(x) + fabs(y) + fabs(z)) ) / (MAP_GENERATION_LIMIT * 3) ) * (scale - 1) );
+}
+
+void NoiseIndev::transformNoiseMapFarScale(float xx, float yy, float zz) {
+ // more correct use distantion from 0,0,0 via pow, but + is faster
+ //float farscale = ( 1 + ( 1 - (MAP_GENERATION_LIMIT * 3 - (fabs(xx) + fabs(yy) + fabs(zz)) ) / (MAP_GENERATION_LIMIT * 3) ) * ((npindev)->farscale - 1) );
+ // dstream << "TNM rs=" << farscale << " from=" << (npindev)->farscale << " x=" << xx << " y=" << yy <<" z=" << zz << std::endl;
+ int i = 0;
+ for (int z = 0; z != sz; z++) {
+ for (int y = 0; y != sy; y++) {
+ for (int x = 0; x != sx; x++) {
+ //result[i] = result[i] * npindev->scale * farscale + npindev->offset;
+ result[i] = result[i] * npindev->scale * farscale(npindev->farscale,xx,yy,zz) + npindev->offset;
+ i++;
+ }
+ }
+ }
+}
+
+MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params) : MapgenV6(mapgenid, params) {
+ noiseindev_terrain_base = new NoiseIndev(params->npindev_terrain_base, seed, csize.X, csize.Y);
+ noiseindev_terrain_higher = new NoiseIndev(params->npindev_terrain_higher, seed, csize.X, csize.Y);
+ noiseindev_steepness = new NoiseIndev(params->npindev_steepness, seed, csize.X, csize.Y);
+// 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.Y);
+// noise_beach = new Noise(params->np_beach, seed, csize.X, csize.Y);
+// noise_biome = new Noise(params->np_biome, seed, csize.X, csize.Y);
+}
+
+MapgenIndev::~MapgenIndev() {
+ delete noiseindev_terrain_base;
+ delete noiseindev_terrain_higher;
+ delete noiseindev_steepness;
+ //delete noise_height_select;
+ //delete noise_trees;
+ delete noiseindev_mud;
+ //delete noise_beach;
+ //delete noise_biome;
+}
+
+
+void MapgenIndev::calculateNoise() {
+ int x = node_min.X;
+ int y = node_min.Y;
+ int z = node_min.Z;
+ // Need to adjust for the original implementation's +.5 offset...
+ if (!(flags & MG_FLAT)) {
+ noiseindev_terrain_base->perlinMap2D(
+ x + 0.5 * noiseindev_terrain_base->npindev->spread.X,
+ z + 0.5 * noiseindev_terrain_base->npindev->spread.Z);
+ noiseindev_terrain_base->transformNoiseMapFarScale(x, y, z);
+ //noise_terrain_base->transformNoiseMap();
+
+ noiseindev_terrain_higher->perlinMap2D(
+ x + 0.5 * noiseindev_terrain_higher->npindev->spread.X,
+ z + 0.5 * noiseindev_terrain_higher->npindev->spread.Z);
+ noiseindev_terrain_higher->transformNoiseMapFarScale(x, y, z);
+ //noise_terrain_higher->transformNoiseMap();
+
+ noiseindev_steepness->perlinMap2D(
+ x + 0.5 * noiseindev_steepness->npindev->spread.X,
+ z + 0.5 * noiseindev_steepness->npindev->spread.Z);
+ noiseindev_steepness->transformNoiseMapFarScale(x, y, z);
+
+ noise_height_select->perlinMap2D(
+ x + 0.5 * noise_height_select->np->spread.X,
+ z + 0.5 * noise_height_select->np->spread.Z);
+ }
+
+ if (!(flags & MG_FLAT)) {
+ noiseindev_mud->perlinMap2D(
+ x + 0.5 * noiseindev_mud->npindev->spread.X,
+ z + 0.5 * noiseindev_mud->npindev->spread.Z);
+ noiseindev_mud->transformNoiseMapFarScale(x, y, z);
+ }
+ noise_beach->perlinMap2D(
+ x + 0.2 * noise_beach->np->spread.X,
+ z + 0.7 * noise_beach->np->spread.Z);
+
+ noise_biome->perlinMap2D(
+ x + 0.6 * noise_biome->np->spread.X,
+ z + 0.2 * noise_biome->np->spread.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");
+ np_biome = settings->getNoiseParams("mgv6_np_biome");
+ np_cave = settings->getNoiseParams("mgv6_np_cave");
+
+ bool success =
+ npindev_terrain_base && npindev_terrain_higher && npindev_steepness &&
+ np_height_select && np_trees && npindev_mud &&
+ np_beach && np_biome && np_cave;
+ 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->setNoiseParams("mgv6_np_biome", np_biome);
+ settings->setNoiseParams("mgv6_np_cave", np_cave);
+}
+
+
+float MapgenIndev::baseTerrainLevelFromNoise(v2s16 p) {
+ if (flags & MG_FLAT)
+ return water_level;
+
+ float terrain_base = NoisePerlin2DPosOffset(noiseindev_terrain_base->npindev,
+ p.X, 0.5, p.Y, 0.5, seed);
+ float terrain_higher = NoisePerlin2DPosOffset(noiseindev_terrain_higher->npindev,
+ p.X, 0.5, p.Y, 0.5, seed);
+ float steepness = NoisePerlin2DPosOffset(noiseindev_steepness->npindev,
+ p.X, 0.5, p.Y, 0.5, seed);
+ float height_select = NoisePerlin2DNoTxfmPosOffset(noise_height_select->np,
+ p.X, 0.5, p.Y, 0.5, seed);
+
+ return baseTerrainLevel(terrain_base, terrain_higher,
+ steepness, height_select);
+}
+
+float MapgenIndev::baseTerrainLevelFromMap(int index) {
+ if (flags & MG_FLAT)
+ return water_level;
+
+ float terrain_base = noiseindev_terrain_base->result[index];
+ float terrain_higher = noiseindev_terrain_higher->result[index];
+ float steepness = noiseindev_steepness->result[index];
+ float height_select = noise_height_select->result[index];
+
+ return baseTerrainLevel(terrain_base, terrain_higher,
+ steepness, height_select);
+}
+
+float MapgenIndev::getMudAmount(int index)
+{
+ if (flags & MG_FLAT)
+ return AVERAGE_MUD_AMOUNT;
+
+ /*return ((float)AVERAGE_MUD_AMOUNT + 2.0 * noise2d_perlin(
+ 0.5+(float)p.X/200, 0.5+(float)p.Y/200,
+ seed+91013, 3, 0.55));*/
+
+ 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.tunnel_routepoints = 0;
+ //cave.part_max_length_rs = 0;
+ cave.flooded = large_cave && ps.range(0,4);
+ if(large_cave){
+ cave.part_max_length_rs = ps.range(2,4);
+//dstream<<"try:"<<farscale(0.2, node_min.X,node_min.Y,node_min.Z)*30<<std::endl;
+ if (node_min.Y < -500 && !ps.range(0, farscale(0.2, node_min.X,node_min.Y,node_min.Z)*30)) { //huge
+ cave.flooded = ps.range(0, 1);
+//dstream<<"HUGE:"<<cave.flooded<<std::endl;
+ cave.tunnel_routepoints = ps.range(5, 1522);
+ cave.min_tunnel_diameter = 30;
+ cave.max_tunnel_diameter = ps.range(30, ps.range(80,120));
+ } else {
+//dstream<<"large:"<<cave.flooded<<std::endl;
+ 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));
+ }
+ } else {
+ cave.part_max_length_rs = ps.range(2,9);
+ cave.tunnel_routepoints = ps.range(10, ps.range(15,30));
+ }
+ cave.large_cave_is_flat = (ps.range(0,1) == 0);
+};
diff --git a/src/mapgen_indev.h b/src/mapgen_indev.h
new file mode 100644
index 000000000..ef6193c12
--- /dev/null
+++ b/src/mapgen_indev.h
@@ -0,0 +1,135 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+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
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef MAPGENINDEV_HEADER
+#define MAPGENINDEV_HEADER
+
+#include "mapgen.h"
+#include "mapgen_v6.h"
+
+float farscale(float scale, float x, float y, float z);
+
+struct NoiseIndevParams : public NoiseParams {
+ float farscale;
+
+ NoiseIndevParams(){}
+ NoiseIndevParams(float offset_, float scale_, v3f spread_, int seed_, int octaves_, float persist_, float farscale_)
+ //:NoiseParams(offset_, scale_, spread_, seed_, octaves_, persist_)
+ {
+ //NoiseParams(float offset_, float scale_, v3f spread_, int seed_, int octaves_, float persist_) {
+ offset = offset_;
+ scale = scale_;
+ spread = spread_;
+ seed = seed_;
+ octaves = octaves_;
+ persist = persist_;
+ //}
+ farscale = farscale_;
+ }
+
+};
+
+#define getNoiseIndevParams(x) getStruct<NoiseIndevParams>((x), "f,f,v3,s32,s32,f,f")
+#define setNoiseIndevParams(x, y) setStruct((x), "f,f,v3,s32,s32,f,f", (y))
+
+class NoiseIndev : public Noise {
+ public:
+ NoiseIndevParams *npindev;
+
+ //NoiseIndev() {};
+ NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy);
+ NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy, int sz);
+ void init(NoiseIndevParams *np, int seed, int sx, int sy, int sz);
+ void transformNoiseMapFarScale(float xx = 0, float yy = 0, float zz = 0);
+};
+
+extern NoiseIndevParams nparams_indev_def_terrain_base;
+extern NoiseIndevParams nparams_indev_def_terrain_higher;
+extern NoiseIndevParams nparams_indev_def_steepness;
+//extern NoiseIndevParams nparams_indev_def_height_select;
+//extern NoiseIndevParams nparams_indev_def_trees;
+extern NoiseIndevParams nparams_indev_def_mud;
+//extern NoiseIndevParams nparams_indev_def_beach;
+//extern NoiseIndevParams nparams_indev_def_biome;
+//extern NoiseIndevParams nparams_indev_def_cave;
+
+
+struct MapgenIndevParams : public MapgenV6Params {
+ NoiseIndevParams *npindev_terrain_base;
+ NoiseIndevParams *npindev_terrain_higher;
+ NoiseIndevParams *npindev_steepness;
+ //NoiseParams *np_height_select;
+ //NoiseParams *np_trees;
+ NoiseIndevParams *npindev_mud;
+ //NoiseParams *np_beach;
+ //NoiseParams *np_biome;
+ //NoiseParams *np_cave;
+
+ MapgenIndevParams() {
+ //freq_desert = 0.45;
+ //freq_beach = 0.15;
+ npindev_terrain_base = &nparams_indev_def_terrain_base;
+ npindev_terrain_higher = &nparams_indev_def_terrain_higher;
+ npindev_steepness = &nparams_indev_def_steepness;
+ //np_height_select = &nparams_v6_def_height_select;
+ //np_trees = &nparams_v6_def_trees;
+ npindev_mud = &nparams_indev_def_mud;
+ //np_beach = &nparams_v6_def_beach;
+ //np_biome = &nparams_v6_def_biome;
+ //np_cave = &nparams_v6_def_cave;
+ }
+
+ bool readParams(Settings *settings);
+ void writeParams(Settings *settings);
+};
+
+class MapgenIndev : public MapgenV6 {
+ public:
+ NoiseIndev *noiseindev_terrain_base;
+ NoiseIndev *noiseindev_terrain_higher;
+ NoiseIndev *noiseindev_steepness;
+ //NoiseIndev *noise_height_select;
+ //NoiseIndev *noise_trees;
+ NoiseIndev *noiseindev_mud;
+ //NoiseIndev *noise_beach;
+ //NoiseIndev *noise_biome;
+ //NoiseIndevParams *np_cave;
+
+ MapgenIndev(int mapgenid, MapgenIndevParams *params);
+ ~MapgenIndev();
+ void calculateNoise();
+
+ float baseTerrainLevelFromNoise(v2s16 p);
+ float baseTerrainLevelFromMap(int index);
+ float getMudAmount(int index);
+ void defineCave(Cave & cave, PseudoRandom ps, v3s16 node_min, bool large_cave);
+};
+
+struct MapgenFactoryIndev : public MapgenFactoryV6 {
+ Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge) {
+ return new MapgenIndev(mgid, (MapgenIndevParams *)params);
+ };
+
+ MapgenParams *createMapgenParams() {
+ return new MapgenIndevParams();
+ };
+};
+
+
+#endif
diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp
index dca4e5353..91947df84 100644
--- a/src/mapgen_v6.cpp
+++ b/src/mapgen_v6.cpp
@@ -878,6 +878,24 @@ void MapgenV6::growGrass() {
}
}
+void MapgenV6::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.tunnel_routepoints = 0;
+ //cave.part_max_length_rs = 0;
+ cave.flooded = large_cave && ps.range(0,4);
+ if(large_cave){
+ cave.part_max_length_rs = ps.range(2,4);
+ 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));
+ } else {
+ cave.part_max_length_rs = ps.range(2,9);
+ cave.tunnel_routepoints = ps.range(10, ps.range(15,30));
+ }
+ cave.large_cave_is_flat = (ps.range(0,1) == 0);
+};
void MapgenV6::generateCaves(int max_stone_y) {
// 24ms @cs=8
@@ -911,21 +929,9 @@ void MapgenV6::generateCaves(int max_stone_y) {
break;*/
bool large_cave = (jj >= caves_count);
- s16 min_tunnel_diameter = 2;
- s16 max_tunnel_diameter = ps.range(2,6);
- int dswitchint = ps.range(1,14);
- u16 tunnel_routepoints = 0;
- int part_max_length_rs = 0;
- if(large_cave){
- part_max_length_rs = ps.range(2,4);
- tunnel_routepoints = ps.range(5, ps.range(15,30));
- min_tunnel_diameter = 5;
- max_tunnel_diameter = ps.range(7, ps.range(8,24));
- } else {
- part_max_length_rs = ps.range(2,9);
- tunnel_routepoints = ps.range(10, ps.range(15,30));
- }
- bool large_cave_is_flat = (ps.range(0,1) == 0);
+
+ Cave cave;
+ defineCave(cave, ps, node_min, large_cave);
v3f main_direction(0,0,0);
@@ -938,13 +944,13 @@ void MapgenV6::generateCaves(int max_stone_y) {
// Allow a bit more
//(this should be more than the maximum radius of the tunnel)
s16 insure = 10;
- s16 more = max_spread_amount - max_tunnel_diameter / 2 - insure;
+ s16 more = max_spread_amount - cave.max_tunnel_diameter / 2 - insure;
ar += v3s16(1,0,1) * more * 2;
of -= v3s16(1,0,1) * more;
s16 route_y_min = 0;
// Allow half a diameter + 7 over stone surface
- s16 route_y_max = -of.Y + max_stone_y + max_tunnel_diameter/2 + 7;
+ s16 route_y_max = -of.Y + max_stone_y + cave.max_tunnel_diameter/2 + 7;
// Limit maximum to area
route_y_max = rangelim(route_y_max, 0, ar.Y-1);
@@ -954,10 +960,10 @@ void MapgenV6::generateCaves(int max_stone_y) {
s16 min = 0;
if(node_min.Y < water_level && node_max.Y > water_level)
{
- min = water_level - max_tunnel_diameter/3 - of.Y;
- route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
+ min = water_level - cave.max_tunnel_diameter/3 - of.Y;
+ route_y_max = water_level + cave.max_tunnel_diameter/3 - of.Y;
}
- route_y_min = ps.range(min, min + max_tunnel_diameter);
+ route_y_min = ps.range(min, min + cave.max_tunnel_diameter);
route_y_min = rangelim(route_y_min, 0, route_y_max);
}
@@ -985,9 +991,9 @@ void MapgenV6::generateCaves(int max_stone_y) {
Generate some tunnel starting from orp
*/
- for(u16 j=0; j<tunnel_routepoints; j++)
+ for(u16 j=0; j<cave.tunnel_routepoints; j++)
{
- if(j%dswitchint==0 && large_cave == false)
+ if(j%cave.dswitchint==0 && large_cave == false)
{
main_direction = v3f(
((float)(ps.next()%20)-(float)10)/10,
@@ -998,8 +1004,8 @@ void MapgenV6::generateCaves(int max_stone_y) {
}
// Randomize size
- s16 min_d = min_tunnel_diameter;
- s16 max_d = max_tunnel_diameter;
+ s16 min_d = cave.min_tunnel_diameter;
+ s16 max_d = cave.max_tunnel_diameter;
s16 rs = ps.range(min_d, max_d);
// Every second section is rough
@@ -1009,17 +1015,17 @@ void MapgenV6::generateCaves(int max_stone_y) {
if(large_cave)
{
maxlen = v3s16(
- rs*part_max_length_rs,
- rs*part_max_length_rs/2,
- rs*part_max_length_rs
+ rs*cave.part_max_length_rs,
+ rs*cave.part_max_length_rs/2,
+ rs*cave.part_max_length_rs
);
}
else
{
maxlen = v3s16(
- rs*part_max_length_rs,
- ps.range(1, rs*part_max_length_rs),
- rs*part_max_length_rs
+ rs*cave.part_max_length_rs,
+ ps.range(1, rs*cave.part_max_length_rs),
+ rs*cave.part_max_length_rs
);
}
@@ -1091,7 +1097,7 @@ void MapgenV6::generateCaves(int max_stone_y) {
/*// Make better floors in small caves
if(y0 <= -rs/2 && rs<=7)
continue;*/
- if (large_cave_is_flat) {
+ if (cave.large_cave_is_flat) {
// Make large caves not so tall
if (rs > 7 && abs(y0) >= rs/3)
continue;
@@ -1109,13 +1115,13 @@ void MapgenV6::generateCaves(int max_stone_y) {
u32 i = vm->m_area.index(p);
if(large_cave) {
- if (full_node_min.Y < water_level &&
+ if (cave.flooded && full_node_min.Y < water_level &&
full_node_max.Y > water_level) {
if (p.Y <= water_level)
vm->m_data[i] = waternode;
else
vm->m_data[i] = airnode;
- } else if (full_node_max.Y < water_level) {
+ } else if (cave.flooded && full_node_max.Y < water_level) {
if (p.Y < startp.Y - 2)
vm->m_data[i] = lavanode;
else
diff --git a/src/mapgen_v6.h b/src/mapgen_v6.h
index 89d72300a..34de7c0ed 100644
--- a/src/mapgen_v6.h
+++ b/src/mapgen_v6.h
@@ -43,6 +43,16 @@ extern NoiseParams nparams_v6_def_humidity;
extern NoiseParams nparams_v6_def_trees;
extern NoiseParams nparams_v6_def_apple_trees;
+struct Cave {
+ s16 min_tunnel_diameter;
+ s16 max_tunnel_diameter;
+ int dswitchint;
+ u16 tunnel_routepoints;
+ int part_max_length_rs;
+ bool large_cave_is_flat;
+ bool flooded;
+};
+
struct MapgenV6Params : public MapgenParams {
float freq_desert;
float freq_beach;
@@ -126,9 +136,9 @@ public:
float baseTerrainLevel(float terrain_base, float terrain_higher,
float steepness, float height_select);
- float baseTerrainLevelFromNoise(v2s16 p);
- float baseTerrainLevelFromMap(v2s16 p);
- float baseTerrainLevelFromMap(int index);
+ virtual float baseTerrainLevelFromNoise(v2s16 p);
+ virtual float baseTerrainLevelFromMap(v2s16 p);
+ virtual float baseTerrainLevelFromMap(int index);
s16 find_ground_level(v2s16 p2d);
s16 find_stone_level(v2s16 p2d);
@@ -139,7 +149,7 @@ public:
float getTreeAmount(v2s16 p);
bool getHaveAppleTree(v2s16 p);
float getMudAmount(v2s16 p);
- float getMudAmount(int index);
+ virtual float getMudAmount(int index);
bool getHaveBeach(v2s16 p);
bool getHaveBeach(int index);
BiomeType getBiome(v2s16 p);
@@ -148,13 +158,14 @@ public:
u32 get_blockseed(u64 seed, v3s16 p);
- void calculateNoise();
+ virtual void calculateNoise();
int generateGround();
void addMud();
void flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos);
void addDirtGravelBlobs();
void growGrass();
void placeTrees();
+ virtual void defineCave(Cave & cave, PseudoRandom ps, v3s16 node_min, bool large_cave);
void generateCaves(int max_stone_y);
};
diff --git a/src/noise.cpp b/src/noise.cpp
index 49b5f7e58..ba7c30574 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -524,6 +524,7 @@ float *Noise::perlinMap2D(float x, float y) {
for (j = 0; j != sy; j++) {
for (i = 0; i != sx; i++) {
result[index] += g * buf[index];
+//dstream << "pm2d i="<<index<<" r="<< result[index]<<std::endl;
index++;
}
}
diff --git a/src/noise.h b/src/noise.h
index cec3b95b0..34b4d0b41 100644
--- a/src/noise.h
+++ b/src/noise.h
@@ -89,7 +89,7 @@ public:
Noise(NoiseParams *np, int seed, int sx, int sy, int sz);
~Noise();
- void init(NoiseParams *np, int seed, int sx, int sy, int sz);
+ virtual void init(NoiseParams *np, int seed, int sx, int sy, int sz);
void setSize(int sx, int sy);
void setSize(int sx, int sy, int sz);
void setSpreadFactor(v3f spread);
diff --git a/src/settings.h b/src/settings.h
index 0696b8190..1b7e3cb09 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -460,7 +460,7 @@ public:
n = m_defaults.find(name);
if(n == m_defaults.end())
{
- throw SettingNotFoundException("Setting not found");
+ throw SettingNotFoundException(("Setting [" + name + "] not found ").c_str());
}
}