summaryrefslogtreecommitdiff
path: root/src/mapgen_v6.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-03-16 17:06:11 -0400
committerkwolekr <kwolekr@minetest.net>2013-03-16 17:06:11 -0400
commit6823ce99a7deabe410dd8b143b688cd364490cec (patch)
treeeee1243f8c1e10f240abcda7a0c25abe08483665 /src/mapgen_v6.cpp
parent1f1ad9fd23b07a1c1b5477ee0dbf2c4fdaabccef (diff)
downloadminetest-6823ce99a7deabe410dd8b143b688cd364490cec.tar.gz
minetest-6823ce99a7deabe410dd8b143b688cd364490cec.tar.bz2
minetest-6823ce99a7deabe410dd8b143b688cd364490cec.zip
Re-add jungles, apple trees
Diffstat (limited to 'src/mapgen_v6.cpp')
-rw-r--r--src/mapgen_v6.cpp81
1 files changed, 59 insertions, 22 deletions
diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp
index b60758310..dca4e5353 100644
--- a/src/mapgen_v6.cpp
+++ b/src/mapgen_v6.cpp
@@ -45,8 +45,6 @@ NoiseParams nparams_v6_def_steepness =
{0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
NoiseParams nparams_v6_def_height_select =
{0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
-NoiseParams nparams_v6_def_trees =
- {0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
NoiseParams nparams_v6_def_mud =
{AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
NoiseParams nparams_v6_def_beach =
@@ -55,6 +53,12 @@ NoiseParams nparams_v6_def_biome =
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
NoiseParams nparams_v6_def_cave =
{6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
+NoiseParams nparams_v6_def_humidity =
+ {0.5, 0.5, v3f(500.0, 500.0, 500.0), 72384, 4, 0.66};
+NoiseParams nparams_v6_def_trees =
+ {0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
+NoiseParams nparams_v6_def_apple_trees =
+ {0.0, 1.0, v3f(100.0, 100.0, 100.0), 342902, 3, 0.45};
///////////////////////////////////////////////////////////////////////////////
@@ -74,13 +78,15 @@ MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params) {
this->ystride = csize.X; //////fix this
- np_cave = params->np_cave;
+ np_cave = params->np_cave;
+ np_humidity = params->np_humidity;
+ np_trees = params->np_trees;
+ np_apple_trees = params->np_apple_trees;
noise_terrain_base = new Noise(params->np_terrain_base, seed, csize.X, csize.Y);
noise_terrain_higher = new Noise(params->np_terrain_higher, seed, csize.X, csize.Y);
noise_steepness = new Noise(params->np_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);
noise_mud = new Noise(params->np_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);
@@ -92,7 +98,6 @@ MapgenV6::~MapgenV6() {
delete noise_terrain_higher;
delete noise_steepness;
delete noise_height_select;
- delete noise_trees;
delete noise_mud;
delete noise_beach;
delete noise_biome;
@@ -234,12 +239,6 @@ int MapgenV6::getGroundLevelAtPoint(v2s16 p) {
//////////////////////// Noise functions
-float MapgenV6::getTreeAmount(v2s16 p) {
- int index = (p.Y - node_min.Z) * ystride + (p.X - node_min.X);
- return getTreeAmount(index);
-}
-
-
float MapgenV6::getMudAmount(v2s16 p) {
int index = (p.Y - node_min.Z) * ystride + (p.X - node_min.X);
return getMudAmount(index);
@@ -258,13 +257,30 @@ BiomeType MapgenV6::getBiome(v2s16 p) {
}
-float MapgenV6::getTreeAmount(int index)
+float MapgenV6::getHumidity(v2s16 p)
+{
+ /*double noise = noise2d_perlin(
+ 0.5+(float)p.X/500, 0.5+(float)p.Y/500,
+ seed+72384, 4, 0.66);
+ noise = (noise + 1.0)/2.0;*/
+
+ float noise = NoisePerlin2D(np_humidity, p.X, p.Y, seed);
+
+ if (noise < 0.0)
+ noise = 0.0;
+ if (noise > 1.0)
+ noise = 1.0;
+ return noise;
+}
+
+
+float MapgenV6::getTreeAmount(v2s16 p)
{
/*double noise = noise2d_perlin(
0.5+(float)p.X/125, 0.5+(float)p.Y/125,
seed+2, 4, 0.66);*/
- float noise = noise_trees->result[index];
+ float noise = NoisePerlin2D(np_trees, p.X, p.Y, seed);
float zeroval = -0.39;
if (noise < zeroval)
return 0;
@@ -273,6 +289,18 @@ float MapgenV6::getTreeAmount(int index)
}
+bool MapgenV6::getHaveAppleTree(v2s16 p)
+{
+ /*is_apple_tree = noise2d_perlin(
+ 0.5+(float)p.X/100, 0.5+(float)p.Z/100,
+ data->seed+342902, 3, 0.45) > 0.2;*/
+
+ float noise = NoisePerlin2D(np_apple_trees, p.X, p.Y, seed);
+
+ return noise > 0.2;
+}
+
+
float MapgenV6::getMudAmount(int index)
{
if (flags & MG_FLAT)
@@ -465,12 +493,6 @@ void MapgenV6::calculateNoise() {
x + 0.5 * noise_height_select->np->spread.X,
z + 0.5 * noise_height_select->np->spread.Z);
}
-
- if (flags & MG_TREES) {
- noise_trees->perlinMap2D(
- x + 0.5 * noise_trees->np->spread.X,
- z + 0.5 * noise_trees->np->spread.Z);
- }
if (!(flags & MG_FLAT)) {
noise_mud->perlinMap2D(
@@ -762,6 +784,8 @@ void MapgenV6::addDirtGravelBlobs() {
void MapgenV6::placeTrees() {
+ //TimeTaker t("placeTrees");
+
// Divide area into parts
s16 div = 8;
s16 sidelen = central_area_size.X / div;
@@ -784,8 +808,13 @@ void MapgenV6::placeTrees() {
node_min.X + sidelen + sidelen * x0 - 1,
node_min.Z + sidelen + sidelen * z0 - 1
);
- // Amount of trees
- u32 tree_count = area * getTreeAmount(p2d_center); /////////////optimize this!
+
+ // Amount of trees, jungle area
+ u32 tree_count = area * getTreeAmount(p2d_center);
+ bool is_jungle = (flags & MGV6_JUNGLES) && (getHumidity(p2d_center) > 0.75);
+ if (is_jungle)
+ tree_count *= 4;
+
// Put trees in random places on part of division
for (u32 i = 0; i < tree_count; i++) {
s16 x = myrand_range(p2d_min.X, p2d_max.X);
@@ -806,10 +835,18 @@ void MapgenV6::placeTrees() {
continue;
}
p.Y++;
+
// Make a tree
- treegen::make_tree(*vm, p, false, ndef, myrand());
+ if (is_jungle) {
+ treegen::make_jungletree(*vm, p, ndef, myrand());
+ } else {
+ bool is_apple_tree = (myrand_range(0, 3) == 0) &&
+ getHaveAppleTree(v2s16(x, z));
+ treegen::make_tree(*vm, p, is_apple_tree, ndef, myrand());
+ }
}
}
+ //printf("placeTrees: %dms\n", t.stop());
}