]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapgen.cpp
Node placement client-side prediction
[dragonfireclient.git] / src / mapgen.cpp
index 0b8832ece089bfb356e133153b124488f23b4afc..a487e8f6dd04bd4d5da39ca82c3b2c75a755524a 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.
 */
@@ -102,10 +102,13 @@ static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d,
        u32 i = vmanip.m_area.index(v3s16(p2d.X, y_nodes_max, p2d.Y));
        s16 y;
        content_t c_stone = ndef->getId("mapgen_stone");
+       content_t c_desert_stone = ndef->getId("mapgen_desert_stone");
        for(y=y_nodes_max; y>=y_nodes_min; y--)
        {
                MapNode &n = vmanip.m_data[i];
-               if(n.getContent() == c_stone)
+               content_t c = n.getContent();
+               if(c != CONTENT_IGNORE && (
+                               c == c_stone || c == c_desert_stone))
                        break;
 
                vmanip.m_area.add_y(em, i, -1);
@@ -1276,12 +1279,29 @@ bool get_have_beach(u64 seed, v2s16 p2d)
 {
        // Determine whether to have sand here
        double sandnoise = noise2d_perlin(
-                       0.5+(float)p2d.X/500, 0.5+(float)p2d.Y/500,
+                       0.2+(float)p2d.X/250, 0.7+(float)p2d.Y/250,
                        seed+59420, 3, 0.50);
 
        return (sandnoise > 0.15);
 }
 
+enum BiomeType
+{
+       BT_NORMAL,
+       BT_DESERT
+};
+
+BiomeType get_biome(u64 seed, v2s16 p2d)
+{
+       // Just do something very simple as for now
+       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)
+               return BT_DESERT;
+       return BT_NORMAL;
+};
+
 u32 get_blockseed(u64 seed, v3s16 p)
 {
        s32 x=p.X, y=p.Y, z=p.Z;
@@ -1359,6 +1379,12 @@ void make_block(BlockMakeData *data)
 #define CONTENT_VARIABLE(ndef, name)\
        content_t c_##name = ndef->getId("mapgen_" #name);\
        MapNode n_##name(c_##name);
+// Default to something else if was CONTENT_IGNORE
+#define CONTENT_VARIABLE_FALLBACK(name, dname)\
+       if(c_##name == CONTENT_IGNORE){\
+               c_##name = c_##dname;\
+               n_##name = n_##dname;\
+       }
 
        CONTENT_VARIABLE(ndef, stone);
        CONTENT_VARIABLE(ndef, air);
@@ -1375,6 +1401,10 @@ void make_block(BlockMakeData *data)
        CONTENT_VARIABLE(ndef, stone_with_coal);
        CONTENT_VARIABLE(ndef, stone_with_iron);
        CONTENT_VARIABLE(ndef, mese);
+       CONTENT_VARIABLE(ndef, desert_sand);
+       CONTENT_VARIABLE_FALLBACK(desert_sand, sand);
+       CONTENT_VARIABLE(ndef, desert_stone);
+       CONTENT_VARIABLE_FALLBACK(desert_stone, stone);
 
        // Maximum height of the stone surface and obstacles.
        // This is used to guide the cave generation
@@ -1422,6 +1452,7 @@ void make_block(BlockMakeData *data)
                if(surface_y > stone_surface_max_y)
                        stone_surface_max_y = surface_y;
 
+               BiomeType bt = get_biome(data->seed, p2d);
                /*
                        Fill ground with stone
                */
@@ -1431,15 +1462,18 @@ void make_block(BlockMakeData *data)
                        u32 i = vmanip.m_area.index(v3s16(p2d.X, node_min.Y, p2d.Y));
                        for(s16 y=node_min.Y; y<=node_max.Y; y++)
                        {
-                               if(y <= surface_y){
-                                       if(vmanip.m_data[i].getContent() == CONTENT_IGNORE)
-                                               vmanip.m_data[i] = MapNode(c_stone);
-                               } else if(y <= WATER_LEVEL){
-                                       vmanip.m_data[i] = MapNode(c_water_source);
-                               } else {
-                                       vmanip.m_data[i] = MapNode(c_air);
+                               if(vmanip.m_data[i].getContent() == CONTENT_IGNORE){
+                                       if(y <= surface_y){
+                                               if(y > WATER_LEVEL && bt == BT_DESERT)
+                                                       vmanip.m_data[i] = n_desert_stone;
+                                               else
+                                                       vmanip.m_data[i] = n_stone;
+                                       } else if(y <= WATER_LEVEL){
+                                               vmanip.m_data[i] = MapNode(c_water_source);
+                                       } else {
+                                               vmanip.m_data[i] = MapNode(c_air);
+                                       }
                                }
-
                                vmanip.m_area.add_y(em, i, 1);
                        }
                }
@@ -1476,16 +1510,21 @@ 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;
+               bruises_count /= 3;
+       }
        for(u32 jj=0; jj<caves_count+bruises_count; jj++)
        {
                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;
@@ -1591,12 +1630,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)
                        {
@@ -1665,8 +1707,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);
@@ -1752,10 +1798,8 @@ void make_block(BlockMakeData *data)
                // Node position in 2d
                v2s16 p2d = v2s16(x,z);
                
-               MapNode addnode(c_dirt);
-
                // Randomize mud amount
-               s16 mud_add_amount = get_mud_add_amount(data->seed, p2d) / 2.0;
+               s16 mud_add_amount = get_mud_add_amount(data->seed, p2d) / 2.0 + 0.5;
 
                // Find ground level
                s16 surface_y = find_stone_level(vmanip, p2d, ndef);
@@ -1763,13 +1807,27 @@ 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(get_have_beach(data->seed, p2d) &&
+               } else if(bt == BT_NORMAL && get_have_beach(data->seed, p2d) &&
                                surface_y + mud_add_amount <= WATER_LEVEL+2){
                        addnode = MapNode(c_sand);
                }
+               
+               if(bt == BT_DESERT){
+                       if(surface_y > 20){
+                               mud_add_amount = MYMAX(0, mud_add_amount - (surface_y - 20)/5);
+                       }
+               }
 
                /*
                        If topmost node is grass, change it to mud.
@@ -1812,6 +1870,7 @@ void make_block(BlockMakeData *data)
        /*
                Add blobs of dirt and gravel underground
        */
+       if(get_biome(data->seed, v2s16(node_min.X, node_min.Y)) == BT_NORMAL)
        {
        PseudoRandom pr(blockseed+983);
        for(int i=0; i<volume_nodes/10/10/10; i++)
@@ -2453,19 +2512,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