]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapgen.cpp
Add a setting to enable always flying fast
[minetest.git] / src / mapgen.cpp
index 1d1d663c097306e39ca046295db0e397af3056e3..ae0c551cb5d6d84cdb311034e229fdf209cd69f5 100644 (file)
@@ -3,16 +3,16 @@ Minetest-c55
 Copyright (C) 2010-2011 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 General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+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 General Public License for more details.
+GNU Lesser General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
+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.
 */
@@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "voxelalgorithms.h"
 #include "profiler.h"
 #include "main.h" // For g_profiler
+#include "treegen.h"
 
 namespace mapgen
 {
@@ -120,173 +121,7 @@ static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d,
 }
 #endif
 
-void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
-               bool is_apple_tree, INodeDefManager *ndef)
-{
-       MapNode treenode(ndef->getId("mapgen_tree"));
-       MapNode leavesnode(ndef->getId("mapgen_leaves"));
-       MapNode applenode(ndef->getId("mapgen_apple"));
-       
-       s16 trunk_h = myrand_range(4, 5);
-       v3s16 p1 = p0;
-       for(s16 ii=0; ii<trunk_h; ii++)
-       {
-               if(vmanip.m_area.contains(p1))
-                       vmanip.m_data[vmanip.m_area.index(p1)] = treenode;
-               p1.Y++;
-       }
-
-       // p1 is now the last piece of the trunk
-       p1.Y -= 1;
-
-       VoxelArea leaves_a(v3s16(-2,-1,-2), v3s16(2,2,2));
-       //SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
-       Buffer<u8> leaves_d(leaves_a.getVolume());
-       for(s32 i=0; i<leaves_a.getVolume(); i++)
-               leaves_d[i] = 0;
-
-       // Force leaves at near the end of the trunk
-       {
-               s16 d = 1;
-               for(s16 z=-d; z<=d; z++)
-               for(s16 y=-d; y<=d; y++)
-               for(s16 x=-d; x<=d; x++)
-               {
-                       leaves_d[leaves_a.index(v3s16(x,y,z))] = 1;
-               }
-       }
-
-       // Add leaves randomly
-       for(u32 iii=0; iii<7; iii++)
-       {
-               s16 d = 1;
-
-               v3s16 p(
-                       myrand_range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d),
-                       myrand_range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d),
-                       myrand_range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d)
-               );
-
-               for(s16 z=0; z<=d; z++)
-               for(s16 y=0; y<=d; y++)
-               for(s16 x=0; x<=d; x++)
-               {
-                       leaves_d[leaves_a.index(p+v3s16(x,y,z))] = 1;
-               }
-       }
-
-       // Blit leaves to vmanip
-       for(s16 z=leaves_a.MinEdge.Z; z<=leaves_a.MaxEdge.Z; z++)
-       for(s16 y=leaves_a.MinEdge.Y; y<=leaves_a.MaxEdge.Y; y++)
-       for(s16 x=leaves_a.MinEdge.X; x<=leaves_a.MaxEdge.X; x++)
-       {
-               v3s16 p(x,y,z);
-               p += p1;
-               if(vmanip.m_area.contains(p) == false)
-                       continue;
-               u32 vi = vmanip.m_area.index(p);
-               if(vmanip.m_data[vi].getContent() != CONTENT_AIR
-                               && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
-                       continue;
-               u32 i = leaves_a.index(x,y,z);
-               if(leaves_d[i] == 1) {
-                       bool is_apple = myrand_range(0,99) < 10;
-                       if(is_apple_tree && is_apple) {
-                               vmanip.m_data[vi] = applenode;
-                       } else {
-                               vmanip.m_data[vi] = leavesnode;
-                       }
-               }
-       }
-}
-
 #if 0
-static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0,
-               INodeDefManager *ndef)
-{
-       MapNode treenode(ndef->getId("mapgen_jungletree"));
-       MapNode leavesnode(ndef->getId("mapgen_leaves"));
-
-       for(s16 x=-1; x<=1; x++)
-       for(s16 z=-1; z<=1; z++)
-       {
-               if(myrand_range(0, 2) == 0)
-                       continue;
-               v3s16 p1 = p0 + v3s16(x,0,z);
-               v3s16 p2 = p0 + v3s16(x,-1,z);
-               if(vmanip.m_area.contains(p2)
-                               && vmanip.m_data[vmanip.m_area.index(p2)] == CONTENT_AIR)
-                       vmanip.m_data[vmanip.m_area.index(p2)] = treenode;
-               else if(vmanip.m_area.contains(p1))
-                       vmanip.m_data[vmanip.m_area.index(p1)] = treenode;
-       }
-
-       s16 trunk_h = myrand_range(8, 12);
-       v3s16 p1 = p0;
-       for(s16 ii=0; ii<trunk_h; ii++)
-       {
-               if(vmanip.m_area.contains(p1))
-                       vmanip.m_data[vmanip.m_area.index(p1)] = treenode;
-               p1.Y++;
-       }
-
-       // p1 is now the last piece of the trunk
-       p1.Y -= 1;
-
-       VoxelArea leaves_a(v3s16(-3,-2,-3), v3s16(3,2,3));
-       //SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
-       Buffer<u8> leaves_d(leaves_a.getVolume());
-       for(s32 i=0; i<leaves_a.getVolume(); i++)
-               leaves_d[i] = 0;
-
-       // Force leaves at near the end of the trunk
-       {
-               s16 d = 1;
-               for(s16 z=-d; z<=d; z++)
-               for(s16 y=-d; y<=d; y++)
-               for(s16 x=-d; x<=d; x++)
-               {
-                       leaves_d[leaves_a.index(v3s16(x,y,z))] = 1;
-               }
-       }
-
-       // Add leaves randomly
-       for(u32 iii=0; iii<30; iii++)
-       {
-               s16 d = 1;
-
-               v3s16 p(
-                       myrand_range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d),
-                       myrand_range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d),
-                       myrand_range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d)
-               );
-
-               for(s16 z=0; z<=d; z++)
-               for(s16 y=0; y<=d; y++)
-               for(s16 x=0; x<=d; x++)
-               {
-                       leaves_d[leaves_a.index(p+v3s16(x,y,z))] = 1;
-               }
-       }
-
-       // Blit leaves to vmanip
-       for(s16 z=leaves_a.MinEdge.Z; z<=leaves_a.MaxEdge.Z; z++)
-       for(s16 y=leaves_a.MinEdge.Y; y<=leaves_a.MaxEdge.Y; y++)
-       for(s16 x=leaves_a.MinEdge.X; x<=leaves_a.MaxEdge.X; x++)
-       {
-               v3s16 p(x,y,z);
-               p += p1;
-               if(vmanip.m_area.contains(p) == false)
-                       continue;
-               u32 vi = vmanip.m_area.index(p);
-               if(vmanip.m_data[vi].getContent() != CONTENT_AIR
-                               && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
-                       continue;
-               u32 i = leaves_a.index(x,y,z);
-               if(leaves_d[i] == 1)
-                       vmanip.m_data[vi] = leavesnode;
-       }
-}
 
 static void make_papyrus(VoxelManipulator &vmanip, v3s16 p0,
                INodeDefManager *ndef)
@@ -1228,7 +1063,7 @@ double base_rock_level_2d(u64 seed, v2s16 p)
                        0.5+(float)p.X/125., 0.5+(float)p.Y/125.,
                        seed-932, 5, 0.7);
        b = rangelim(b, 0.0, 1000.0);
-       b = pow(b, 7);
+       b = b*b*b*b*b*b*b;
        b *= 5;
        b = rangelim(b, 0.5, 1000.0);
        // Values 1.5...100 give quite horrible looking slopes
@@ -1297,7 +1132,9 @@ BiomeType get_biome(u64 seed, v2s16 p2d)
        double d = noise2d_perlin(
                        0.6+(float)p2d.X/250, 0.2+(float)p2d.Y/250,
                        seed+9130, 3, 0.50);
-       if(d > 0.2)
+       if(d > 0.45) 
+               return BT_DESERT;
+       if(d > 0.35 && (noise2d( p2d.X, p2d.Y, int(seed) ) + 1.0) > ( 0.45 - d ) * 20.0  ) 
                return BT_DESERT;
        return BT_NORMAL;
 };
@@ -1510,10 +1347,11 @@ void make_block(BlockMakeData *data)
                        0.5+(double)node_min.X/250, 0.5+(double)node_min.Y/250,
                        data->seed+34329, 3, 0.50);
        cave_amount = MYMAX(0.0, cave_amount);
-       u32 caves_count = cave_amount * volume_nodes / 20000;
+       u32 caves_count = cave_amount * volume_nodes / 50000;
        u32 bruises_count = 1;
        PseudoRandom ps(blockseed+21343);
-       if(ps.range(1, 4) == 1)
+       PseudoRandom ps2(blockseed+1032);
+       if(ps.range(1, 6) == 1)
                bruises_count = ps.range(0, ps.range(0, 2));
        if(get_biome(data->seed, v2s16(node_min.X, node_min.Y)) == BT_DESERT){
                caves_count /= 3;
@@ -1523,7 +1361,7 @@ void make_block(BlockMakeData *data)
        {
                bool large_cave = (jj >= caves_count);
                s16 min_tunnel_diameter = 2;
-               s16 max_tunnel_diameter = ps.range(2,5);
+               s16 max_tunnel_diameter = ps.range(2,6);
                int dswitchint = ps.range(1,14);
                u16 tunnel_routepoints = 0;
                int part_max_length_rs = 0;
@@ -1629,12 +1467,15 @@ void make_block(BlockMakeData *data)
                                );
                                main_direction *= (float)ps.range(0, 10)/10;
                        }
-
+                       
                        // Randomize size
                        s16 min_d = min_tunnel_diameter;
                        s16 max_d = max_tunnel_diameter;
                        s16 rs = ps.range(min_d, max_d);
                        
+                       // Every second section is rough
+                       bool randomize_xz = (ps2.range(1,2) == 1);
+
                        v3s16 maxlen;
                        if(large_cave)
                        {
@@ -1703,8 +1544,12 @@ void make_block(BlockMakeData *data)
                                fp.Z += 0.1*ps.range(-10,10);
                                v3s16 cp(fp.X, fp.Y, fp.Z);
 
-                               s16 d0 = -rs/2 + ps.range(-1,1);
-                               s16 d1 = d0 + rs + ps.range(-1,1);
+                               s16 d0 = -rs/2;
+                               s16 d1 = d0 + rs;
+                               if(randomize_xz){
+                                       d0 += ps.range(-1,1);
+                                       d1 += ps.range(-1,1);
+                               }
                                for(s16 z0=d0; z0<=d1; z0++)
                                {
                                        s16 si = rs/2 - MYMAX(0, abs(z0)-rs/7-1);
@@ -1751,8 +1596,9 @@ void make_block(BlockMakeData *data)
                                                                        vmanip.m_data[i] = airnode;
                                                                }
                                                        } else {
-                                                               // Don't replace air or water or lava
-                                                               if(vmanip.m_data[i].getContent() == CONTENT_AIR ||
+                                                               // Don't replace air or water or lava or ignore
+                                                               if(vmanip.m_data[i].getContent() == CONTENT_IGNORE ||
+                                                               vmanip.m_data[i].getContent() == CONTENT_AIR ||
                                                                vmanip.m_data[i].getContent() == c_water_source ||
                                                                vmanip.m_data[i].getContent() == c_lava_source)
                                                                        continue;
@@ -1790,11 +1636,6 @@ void make_block(BlockMakeData *data)
                // Node position in 2d
                v2s16 p2d = v2s16(x,z);
                
-               MapNode addnode(c_dirt);
-               BiomeType bt = get_biome(data->seed, p2d);
-               if(bt == BT_DESERT)
-                       addnode = MapNode(c_desert_sand);
-
                // Randomize mud amount
                s16 mud_add_amount = get_mud_add_amount(data->seed, p2d) / 2.0 + 0.5;
 
@@ -1804,7 +1645,15 @@ void make_block(BlockMakeData *data)
                if(surface_y == vmanip.m_area.MinEdge.Y - 1)
                        continue;
 
-               if(mud_add_amount <= 0){
+               MapNode addnode(c_dirt);
+               BiomeType bt = get_biome(data->seed, p2d);
+
+               if(bt == BT_DESERT)
+                       addnode = MapNode(c_desert_sand);
+
+               if(bt == BT_DESERT && surface_y + mud_add_amount <= WATER_LEVEL+1){
+                       addnode = MapNode(c_sand);
+               } else if(mud_add_amount <= 0){
                        mud_add_amount = 1 - mud_add_amount;
                        addnode = MapNode(c_gravel);
                } else if(bt == BT_NORMAL && get_have_beach(data->seed, p2d) &&
@@ -2048,13 +1897,14 @@ void make_block(BlockMakeData *data)
                                
                                bool old_is_water = (n->getContent() == c_water_source);
                                // Move mud to new place
-                               if(!dropped_to_unknown)
+                               if(!dropped_to_unknown) {
                                        *n2 = *n;
-                               // Set old place to be air (or water)
-                               if(old_is_water)
-                                       *n = MapNode(c_water_source);
-                               else
-                                       *n = MapNode(CONTENT_AIR);
+                                       // Set old place to be air (or water)
+                                       if(old_is_water)
+                                               *n = MapNode(c_water_source);
+                                       else
+                                               *n = MapNode(CONTENT_AIR);
+                               }
 
                                // Done
                                break;
@@ -2223,7 +2073,7 @@ void make_block(BlockMakeData *data)
                                }
                                p.Y++;
                                // Make a tree
-                               make_tree(vmanip, p, false, ndef);
+                               treegen::make_tree(vmanip, p, false, ndef);
                        }
                }
        }
@@ -2501,19 +2351,7 @@ void make_block(BlockMakeData *data)
                                                {
                                                        if(have_sand)
                                                        {
-                                                               // Determine whether to have clay in the sand here
-                                                               double claynoise = noise2d_perlin(
-                                                                               0.5+(float)p2d.X/500, 0.5+(float)p2d.Y/500,
-                                                                               data->seed+4321, 6, 0.95) + 0.5;
-                               
-                                                               have_clay = (y <= WATER_LEVEL) && (y >= WATER_LEVEL-2) && (
-                                                                       ((claynoise > 0) && (claynoise < 0.04) && (current_depth == 0)) ||
-                                                                       ((claynoise > 0) && (claynoise < 0.12) && (current_depth == 1))
-                                                                       );
-                                                               if (have_clay)
-                                                                       vmanip.m_data[i] = MapNode(c_clay);
-                                                               else
-                                                                       vmanip.m_data[i] = MapNode(c_sand);
+                                                               vmanip.m_data[i] = MapNode(c_sand);
                                                        }
                                                        #if 1
                                                        else if(current_depth==0 && !water_detected