]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapgen.cpp
Add a setting to enable always flying fast
[minetest.git] / src / mapgen.cpp
index a487e8f6dd04bd4d5da39ca82c3b2c75a755524a..ae0c551cb5d6d84cdb311034e229fdf209cd69f5 100644 (file)
@@ -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.35)
+       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;
 };
@@ -1759,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;
@@ -2059,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;
@@ -2234,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);
                        }
                }
        }