]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapgen_v6.cpp
clientmap, clientmedia: code modernization
[dragonfireclient.git] / src / mapgen_v6.cpp
index fe2b0b36f282c36e7ce6e77c3abe60a1e8bac262..cbc4a19c3fb17d19497ec6ee4973f2330c65dbd6 100644 (file)
@@ -58,14 +58,14 @@ FlagDesc flagdesc_mapgen_v6[] = {
 MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params, EmergeManager *emerge)
        : Mapgen(mapgenid, params, emerge)
 {
-       this->m_emerge = emerge;
-       this->ystride = csize.X; //////fix this
+       m_emerge = emerge;
+       ystride = csize.X; //////fix this
 
-       this->heightmap = new s16[csize.X * csize.Z];
+       heightmap = new s16[csize.X * csize.Z];
 
-       this->spflags     = params->spflags;
-       this->freq_desert = params->freq_desert;
-       this->freq_beach  = params->freq_beach;
+       spflags     = params->spflags;
+       freq_desert = params->freq_desert;
+       freq_beach  = params->freq_beach;
 
        np_cave        = &params->np_cave;
        np_humidity    = &params->np_humidity;
@@ -147,12 +147,6 @@ MapgenV6::~MapgenV6()
 
 MapgenV6Params::MapgenV6Params()
 {
-       spflags = MGV6_JUNGLES | MGV6_SNOWBIOMES | MGV6_TREES |
-               MGV6_BIOMEBLEND | MGV6_MUDFLOW;
-
-       freq_desert = 0.45;
-       freq_beach  = 0.15;
-
        np_terrain_base   = NoiseParams(-4,   20.0, v3f(250.0, 250.0, 250.0), 82341,  5, 0.6,  2.0);
        np_terrain_higher = NoiseParams(20,   16.0, v3f(500.0, 500.0, 500.0), 85039,  5, 0.6,  2.0);
        np_steepness      = NoiseParams(0.85, 0.5,  v3f(125.0, 125.0, 125.0), -932,   5, 0.7,  2.0);
@@ -212,7 +206,7 @@ void MapgenV6Params::writeParams(Settings *settings) const
 // Returns Y one under area minimum if not found
 s16 MapgenV6::find_stone_level(v2s16 p2d)
 {
-       v3s16 em = vm->m_area.getExtent();
+       const v3s16 &em = vm->m_area.getExtent();
        s16 y_nodes_max = vm->m_area.MaxEdge.Y;
        s16 y_nodes_min = vm->m_area.MinEdge.Y;
        u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
@@ -625,10 +619,12 @@ void MapgenV6::makeChunk(BlockMakeData *data)
 
        // Generate the registered decorations
        if (flags & MG_DECORATIONS)
-               m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+               m_emerge->decomgr->placeAllDecos(this, blockseed,
+                       node_min, node_max, water_level - 1);
 
        // Generate the registered ores
-       m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+       m_emerge->oremgr->placeAllOres(this, blockseed,
+               node_min, node_max, water_level - 1);
 
        // Calculate lighting
        if (flags & MG_LIGHT)
@@ -685,7 +681,7 @@ int MapgenV6::generateGround()
                BiomeV6Type bt = getBiome(v2s16(x, z));
 
                // Fill ground with stone
-               v3s16 em = vm->m_area.getExtent();
+               const v3s16 &em = vm->m_area.getExtent();
                u32 i = vm->m_area.index(x, node_min.Y, z);
                for (s16 y = node_min.Y; y <= node_max.Y; y++) {
                        if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
@@ -754,7 +750,7 @@ void MapgenV6::addMud()
 
                // Add mud on ground
                s16 mudcount = 0;
-               v3s16 em = vm->m_area.getExtent();
+               const v3s16 &em = vm->m_area.getExtent();
                s16 y_start = surface_y + 1;
                u32 i = vm->m_area.index(x, y_start, z);
                for (s16 y = y_start; y <= node_max.Y; y++) {
@@ -788,7 +784,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
                        // Node position in 2d
                        v2s16 p2d = v2s16(node_min.X, node_min.Z) + v2s16(x, z);
 
-                       v3s16 em = vm->m_area.getExtent();
+                       const v3s16 &em = vm->m_area.getExtent();
                        u32 i = vm->m_area.index(p2d.X, node_max.Y, p2d.Y);
                        s16 y = node_max.Y;
 
@@ -884,26 +880,11 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
                                        } while (ndef->get(*n2).walkable == false);
                                        // Loop one up so that we're in air
                                        vm->m_area.add_y(em, i2, 1);
-                                       n2 = &vm->m_data[i2];
 
-                                       bool old_is_water = (n->getContent() == c_water_source);
-                                       // Move mud to new place
-                                       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);
-                                                       // Upper (n3) is not walkable or is NULL. If it is
-                                                       // not NULL and not air and not water it is a
-                                                       // decoration that needs removing, to avoid
-                                                       // unsupported decorations.
-                                                       if (n3 && n3->getContent() != CONTENT_AIR &&
-                                                                       n3->getContent() != c_water_source)
-                                                               *n3 = MapNode(CONTENT_AIR);
-                                               }
-                                       }
+                                       // Move mud to new place. Outside mapchunk remove
+                                       // any decorations above removed or placed mud.
+                                       if (!dropped_to_unknown)
+                                               moveMud(i, i2, i3, p2d, em);
 
                                        // Done
                                        break;
@@ -915,6 +896,45 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
 }
 
 
+void MapgenV6::moveMud(u32 remove_index, u32 place_index,
+       u32 above_remove_index, v2s16 pos, v3s16 em)
+{
+       MapNode n_air(CONTENT_AIR);
+       // Copy mud from old place to new place
+       vm->m_data[place_index] = vm->m_data[remove_index];
+       // Set old place to be air
+       vm->m_data[remove_index] = n_air;
+       // Outside the mapchunk decorations may need to be removed if above removed
+       // mud or if half-buried in placed mud. Placed mud is to the side of pos so
+       // use 'pos.X >= node_max.X' etc.
+       if (pos.X >= node_max.X || pos.X <= node_min.X ||
+                       pos.Y >= node_max.Z || pos.Y <= node_min.Z) {
+               // 'above remove' node is above removed mud. If it is not air, water or
+               // 'ignore' it is a decoration that needs removing. Also search upwards
+               // to remove a possible stacked decoration.
+               // Check for 'ignore' because stacked decorations can penetrate into
+               // 'ignore' nodes above the mapchunk.
+               while (vm->m_area.contains(above_remove_index) &&
+                               vm->m_data[above_remove_index].getContent() != CONTENT_AIR &&
+                               vm->m_data[above_remove_index].getContent() != c_water_source &&
+                               vm->m_data[above_remove_index].getContent() != CONTENT_IGNORE) {
+                       vm->m_data[above_remove_index] = n_air;
+                       vm->m_area.add_y(em, above_remove_index, 1);
+               }
+               // Mud placed may have partially-buried a stacked decoration, search
+               // above and remove.
+               vm->m_area.add_y(em, place_index, 1);
+               while (vm->m_area.contains(place_index) &&
+                               vm->m_data[place_index].getContent() != CONTENT_AIR &&
+                               vm->m_data[place_index].getContent() != c_water_source &&
+                               vm->m_data[place_index].getContent() != CONTENT_IGNORE) {
+                       vm->m_data[place_index] = n_air;
+                       vm->m_area.add_y(em, place_index, 1);
+               }
+       }
+}
+
+
 void MapgenV6::placeTreesAndJungleGrass()
 {
        //TimeTaker t("placeTrees");
@@ -927,7 +947,7 @@ void MapgenV6::placeTreesAndJungleGrass()
        if (c_junglegrass == CONTENT_IGNORE)
                c_junglegrass = CONTENT_AIR;
        MapNode n_junglegrass(c_junglegrass);
-       v3s16 em = vm->m_area.getExtent();
+       const v3s16 &em = vm->m_area.getExtent();
 
        // Divide area into parts
        s16 div = 8;
@@ -1002,14 +1022,13 @@ void MapgenV6::placeTreesAndJungleGrass()
                                continue;
 
                        v3s16 p(x, y, z);
-                       // Trees grow only on mud and grass and snowblock
+                       // Trees grow only on mud and grass
                        {
                                u32 i = vm->m_area.index(p);
                                content_t c = vm->m_data[i].getContent();
                                if (c != c_dirt &&
                                                c != c_dirt_with_grass &&
-                                               c != c_dirt_with_snow &&
-                                               c != c_snowblock)
+                                               c != c_dirt_with_snow)
                                        continue;
                        }
                        p.Y++;
@@ -1036,7 +1055,7 @@ void MapgenV6::growGrass() // Add surface nodes
        MapNode n_dirt_with_snow(c_dirt_with_snow);
        MapNode n_snowblock(c_snowblock);
        MapNode n_snow(c_snow);
-       v3s16 em = vm->m_area.getExtent();
+       const v3s16 &em = vm->m_area.getExtent();
 
        u32 index = 0;
        for (s16 z = full_node_min.Z; z <= full_node_max.Z; z++)
@@ -1064,15 +1083,15 @@ void MapgenV6::growGrass() // Add surface nodes
                content_t c = vm->m_data[i].getContent();
                if (surface_y >= water_level - 20) {
                        if (bt == BT_TAIGA && c == c_dirt) {
-                               vm->m_data[i] = n_snowblock;
-                               vm->m_area.add_y(em, i, -1);
                                vm->m_data[i] = n_dirt_with_snow;
                        } else if (bt == BT_TUNDRA) {
                                if (c == c_dirt) {
+                                       vm->m_data[i] = n_snowblock;
+                                       vm->m_area.add_y(em, i, -1);
                                        vm->m_data[i] = n_dirt_with_snow;
                                } else if (c == c_stone && surface_y < node_max.Y) {
                                        vm->m_area.add_y(em, i, 1);
-                                       vm->m_data[i] = n_snow;
+                                       vm->m_data[i] = n_snowblock;
                                }
                        } else if (c == c_dirt) {
                                vm->m_data[i] = n_dirt_with_grass;