Bugfix: don't highlight air nodes.
[oweals/minetest.git] / src / mapgen.cpp
index be65694aa27a28f6473e7b55507b8ed4e5d2fb33..1a31a8bcb0d728f35c74266a12aaf6490bbf1476 100644 (file)
@@ -35,18 +35,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "treegen.h"
 #include "mapgen_v6.h"
 #include "mapgen_v7.h"
+#include "serialization.h"
 #include "util/serialize.h"
 #include "filesys.h"
 
+
 FlagDesc flagdesc_mapgen[] = {
-       {"trees",          MG_TREES},
-       {"caves",          MG_CAVES},
-       {"dungeons",       MG_DUNGEONS},
-       {"v6_jungles",     MGV6_JUNGLES},
-       {"v6_biome_blend", MGV6_BIOME_BLEND},
-       {"flat",           MG_FLAT},
-       {"nolight",        MG_NOLIGHT},
-       {NULL,             0}
+       {"trees",    MG_TREES},
+       {"caves",    MG_CAVES},
+       {"dungeons", MG_DUNGEONS},
+       {"flat",     MG_FLAT},
+       {"light",    MG_LIGHT},
+       {NULL,       0}
 };
 
 FlagDesc flagdesc_ore[] = {
@@ -63,6 +63,16 @@ FlagDesc flagdesc_deco_schematic[] = {
        {NULL,             0}
 };
 
+FlagDesc flagdesc_gennotify[] = {
+       {"dungeon",          1 << GENNOTIFY_DUNGEON},
+       {"temple",           1 << GENNOTIFY_TEMPLE},
+       {"cave_begin",       1 << GENNOTIFY_CAVE_BEGIN},
+       {"cave_end",         1 << GENNOTIFY_CAVE_END},
+       {"large_cave_begin", 1 << GENNOTIFY_LARGECAVE_BEGIN},
+       {"large_cave_end",   1 << GENNOTIFY_LARGECAVE_END},
+       {NULL,               0}
+};
+
 ///////////////////////////////////////////////////////////////////////////////
 
 
@@ -150,7 +160,7 @@ void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
                int x0 = pr.range(nmin.X, nmax.X - csize + 1);
                int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
                int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
+
                if (np && (NoisePerlin3D(np, x0, y0, z0, seed) < nthresh))
                        continue;
 
@@ -240,7 +250,7 @@ Decoration::~Decoration() {
 
 void Decoration::resolveNodeNames(INodeDefManager *ndef) {
        this->ndef = ndef;
-       
+
        if (c_place_on == CONTENT_IGNORE)
                c_place_on = ndef->getId(place_on_name);
 }
@@ -256,7 +266,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
                        "sidelen; setting sidelen to " << carea_size << std::endl;
                sidelen = carea_size;
        }
-       
+
        s16 divlen = carea_size / sidelen;
        int area = sidelen * sidelen;
 
@@ -286,11 +296,11 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
                        s16 z = ps.range(p2d_min.Y, p2d_max.Y);
 
                        int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X);
-                       
-                       s16 y = mg->heightmap ? 
+
+                       s16 y = mg->heightmap ?
                                        mg->heightmap[mapindex] :
                                        mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
-                                       
+
                        if (y < nmin.Y || y > nmax.Y)
                                continue;
 
@@ -308,7 +318,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
 
                        if (mg->biomemap) {
                                std::set<u8>::iterator iter;
-                               
+
                                if (biomes.size()) {
                                        iter = biomes.find(mg->biomemap[mapindex]);
                                        if (iter == biomes.end())
@@ -326,7 +336,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
 void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
        PseudoRandom pr(blockseed + 53);
        std::vector<CutoffData> handled_cutoffs;
-       
+
        // Copy over the cutoffs we're interested in so we don't needlessly hold a lock
        {
                JMutexAutoLock cutofflock(cutoff_mutex);
@@ -340,37 +350,37 @@ void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
                                continue;
                        if (p.Y + height < nmin.Y || p.Y > nmax.Y)
                                continue;
-                       
+
                        handled_cutoffs.push_back(cutoff);
                }
        }
-       
+
        // Generate the cutoffs
        for (size_t i = 0; i != handled_cutoffs.size(); i++) {
                v3s16 p    = handled_cutoffs[i].p;
                s16 height = handled_cutoffs[i].height;
-               
+
                if (p.Y + height > nmax.Y) {
                        //printf("Decoration at (%d %d %d) cut off again!\n", p.X, p.Y, p.Z);
                        cuttoffs.push_back(v3s16(p.X, p.Y, p.Z));
                }
-               
+
                generate(mg, &pr, nmax.Y, nmin.Y - p.Y, v3s16(p.X, nmin.Y, p.Z));
        }
-       
+
        // Remove cutoffs that were handled from the cutoff list
        {
                JMutexAutoLock cutofflock(cutoff_mutex);
                for (std::list<CutoffData>::iterator i = cutoffs.begin();
                        i != cutoffs.end(); ++i) {
-                       
+
                        for (size_t j = 0; j != handled_cutoffs.size(); j++) {
                                CutoffData coff = *i;
                                if (coff.p == handled_cutoffs[j].p)
                                        i = cutoffs.erase(i);
                        }
                }
-       }       
+       }
 }
 #endif
 
@@ -380,8 +390,8 @@ void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 
 void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
        Decoration::resolveNodeNames(ndef);
-       
-       if (c_deco == CONTENT_IGNORE) {
+
+       if (c_deco == CONTENT_IGNORE && !decolist_names.size()) {
                c_deco = ndef->getId(deco_name);
                if (c_deco == CONTENT_IGNORE) {
                        errorstream << "DecoSimple::resolveNodeNames: decoration node '"
@@ -393,16 +403,16 @@ void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
                c_spawnby = ndef->getId(spawnby_name);
                if (c_spawnby == CONTENT_IGNORE) {
                        errorstream << "DecoSimple::resolveNodeNames: spawnby node '"
-                               << deco_name << "' not defined" << std::endl;
+                               << spawnby_name << "' not defined" << std::endl;
                        nspawnby = -1;
                        c_spawnby = CONTENT_AIR;
                }
        }
-       
+
        if (c_decolist.size())
                return;
-       
-       for (size_t i = 0; i != decolist_names.size(); i++) {           
+
+       for (size_t i = 0; i != decolist_names.size(); i++) {
                content_t c = ndef->getId(decolist_names[i]);
                if (c == CONTENT_IGNORE) {
                        errorstream << "DecoSimple::resolveNodeNames: decolist node '"
@@ -421,7 +431,7 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
        if (vm->m_data[vi].getContent() != c_place_on &&
                c_place_on != CONTENT_IGNORE)
                return;
-               
+
        if (nspawnby != -1) {
                int nneighs = 0;
                v3s16 dirs[8] = { // a Moore neighborhood
@@ -434,18 +444,18 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
                        v3s16(-1, 0, -1),
                        v3s16( 1, 0, -1)
                };
-               
+
                for (int i = 0; i != 8; i++) {
                        u32 index = vm->m_area.index(p + dirs[i]);
                        if (vm->m_area.contains(index) &&
                                vm->m_data[index].getContent() == c_spawnby)
                                nneighs++;
                }
-               
+
                if (nneighs < nspawnby)
                        return;
        }
-       
+
        size_t ndecos = c_decolist.size();
        content_t c_place = ndecos ? c_decolist[pr->range(0, ndecos - 1)] : c_deco;
 
@@ -453,15 +463,15 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
                pr->range(deco_height, deco_height_max) : deco_height;
 
        height = MYMIN(height, max_y - p.Y);
-       
+
        v3s16 em = vm->m_area.getExtent();
        for (int i = 0; i < height; i++) {
                vm->m_area.add_y(em, vi, 1);
-               
+
                content_t c = vm->m_data[vi].getContent();
                if (c != CONTENT_AIR && c != CONTENT_IGNORE)
                        break;
-               
+
                vm->m_data[vi] = MapNode(c_place);
        }
 }
@@ -481,52 +491,54 @@ std::string DecoSimple::getName() {
 
 
 DecoSchematic::DecoSchematic() {
-       node_names = NULL;
-       schematic  = NULL;
-       flags      = 0;
-       size       = v3s16(0, 0, 0);
+       node_names  = NULL;
+       schematic   = NULL;
+       slice_probs = NULL;
+       flags       = 0;
+       size        = v3s16(0, 0, 0);
 }
 
 
 DecoSchematic::~DecoSchematic() {
        delete node_names;
        delete []schematic;
+       delete []slice_probs;
 }
 
 
 void DecoSchematic::resolveNodeNames(INodeDefManager *ndef) {
        Decoration::resolveNodeNames(ndef);
-       
+
        if (filename.empty())
                return;
-       
+
        if (!node_names) {
                errorstream << "DecoSchematic::resolveNodeNames: node name list was "
                        "not created" << std::endl;
                return;
        }
-       
+
        for (size_t i = 0; i != node_names->size(); i++) {
                std::string name = node_names->at(i);
-               
+
                std::map<std::string, std::string>::iterator it;
                it = replacements.find(name);
                if (it != replacements.end())
                        name = it->second;
-               
+
                content_t c = ndef->getId(name);
                if (c == CONTENT_IGNORE) {
                        errorstream << "DecoSchematic::resolveNodeNames: node '"
                                << name << "' not defined" << std::endl;
                        c = CONTENT_AIR;
                }
-               
+
                c_nodes.push_back(c);
        }
-               
+
        for (int i = 0; i != size.X * size.Y * size.Z; i++)
                schematic[i].setContent(c_nodes[schematic[i].getContent()]);
-       
+
        delete node_names;
        node_names = NULL;
 }
@@ -541,15 +553,15 @@ void DecoSchematic::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
                p.Y -= (size.Y + 1) / 2;
        if (flags & DECO_PLACE_CENTER_Z)
                p.Z -= (size.Z + 1) / 2;
-               
+
        u32 vi = vm->m_area.index(p);
        if (vm->m_data[vi].getContent() != c_place_on &&
                c_place_on != CONTENT_IGNORE)
                return;
-       
+
        Rotation rot = (rotation == ROTATE_RAND) ?
                (Rotation)pr->range(ROTATE_0, ROTATE_270) : rotation;
-       
+
        blitToVManip(p, vm, rot, false);
 }
 
@@ -598,48 +610,55 @@ void DecoSchematic::blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
                        i_step_x = xstride;
                        i_step_z = zstride;
        }
-       
-       for (s16 z = 0; z != sz; z++)
+
+       s16 y_map = p.Y;
        for (s16 y = 0; y != sy; y++) {
-               u32 i = z * i_step_z + y * ystride + i_start;
-               for (s16 x = 0; x != sx; x++, i += i_step_x) {
-                       u32 vi = vm->m_area.index(p.X + x, p.Y + y, p.Z + z);
-                       if (!vm->m_area.contains(vi))
-                               continue;
-                       
-                       if (schematic[i].getContent() == CONTENT_IGNORE)
-                               continue;
-                               
-                       if (schematic[i].param1 == MTSCHEM_PROB_NEVER)
-                               continue;
+               if (slice_probs[y] != MTSCHEM_PROB_ALWAYS &&
+                       myrand_range(1, 255) > slice_probs[y])
+                       continue;
+
+               for (s16 z = 0; z != sz; z++) {
+                       u32 i = z * i_step_z + y * ystride + i_start;
+                       for (s16 x = 0; x != sx; x++, i += i_step_x) {
+                               u32 vi = vm->m_area.index(p.X + x, y_map, p.Z + z);
+                               if (!vm->m_area.contains(vi))
+                                       continue;
+
+                               if (schematic[i].getContent() == CONTENT_IGNORE)
+                                       continue;
+
+                               if (schematic[i].param1 == MTSCHEM_PROB_NEVER)
+                                       continue;
+
+                               if (!force_placement) {
+                                       content_t c = vm->m_data[vi].getContent();
+                                       if (c != CONTENT_AIR && c != CONTENT_IGNORE)
+                                               continue;
+                               }
 
-                       if (!force_placement) {
-                               content_t c = vm->m_data[vi].getContent();
-                               if (c != CONTENT_AIR && c != CONTENT_IGNORE)
+                               if (schematic[i].param1 != MTSCHEM_PROB_ALWAYS &&
+                                       myrand_range(1, 255) > schematic[i].param1)
                                        continue;
+
+                               vm->m_data[vi] = schematic[i];
+                               vm->m_data[vi].param1 = 0;
+
+                               if (rot)
+                                       vm->m_data[vi].rotateAlongYAxis(ndef, rot);
                        }
-                       
-                       if (schematic[i].param1 != MTSCHEM_PROB_ALWAYS &&
-                               myrand_range(1, 255) > schematic[i].param1)
-                               continue;
-                       
-                       vm->m_data[vi] = schematic[i];
-                       vm->m_data[vi].param1 = 0;
-                       
-                       if (rot)
-                               vm->m_data[vi].rotateAlongYAxis(ndef, rot);
                }
+               y_map++;
        }
 }
 
 
-void DecoSchematic::placeStructure(Map *map, v3s16 p) {
+void DecoSchematic::placeStructure(Map *map, v3s16 p, bool force_placement) {
        assert(schematic != NULL);
        ManualMapVoxelManipulator *vm = new ManualMapVoxelManipulator(map);
 
        Rotation rot = (rotation == ROTATE_RAND) ?
                (Rotation)myrand_range(ROTATE_0, ROTATE_270) : rotation;
-       
+
        v3s16 s = (rot == ROTATE_90 || rot == ROTATE_270) ?
                                v3s16(size.Z, size.Y, size.X) : size;
 
@@ -649,17 +668,17 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
                p.Y -= (s.Y + 1) / 2;
        if (flags & DECO_PLACE_CENTER_Z)
                p.Z -= (s.Z + 1) / 2;
-               
+
        v3s16 bp1 = getNodeBlockPos(p);
        v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1));
        vm->initialEmerge(bp1, bp2);
-       
-       blitToVManip(p, vm, rot, true);
-       
+
+       blitToVManip(p, vm, rot, force_placement);
+
        std::map<v3s16, MapBlock *> lighting_modified_blocks;
        std::map<v3s16, MapBlock *> modified_blocks;
        vm->blitBackAll(&modified_blocks);
-       
+
        // TODO: Optimize this by using Mapgen::calcLighting() instead
        lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
        map->updateLighting(lighting_modified_blocks, modified_blocks);
@@ -670,7 +689,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
                it = modified_blocks.begin();
                it != modified_blocks.end(); ++it)
                event.modified_blocks.insert(it->first);
-               
+
        map->dispatchEvent(&event);
 }
 
@@ -678,7 +697,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
 bool DecoSchematic::loadSchematicFile() {
        content_t cignore = CONTENT_IGNORE;
        bool have_cignore = false;
-       
+
        std::ifstream is(filename.c_str(), std::ios_base::binary);
 
        u32 signature = readU32(is);
@@ -687,19 +706,30 @@ bool DecoSchematic::loadSchematicFile() {
                        "file" << std::endl;
                return false;
        }
-       
+
        u16 version = readU16(is);
-       if (version > 2) {
+       if (version > MTSCHEM_FILE_VER_HIGHEST_READ) {
                errorstream << "loadSchematicFile: unsupported schematic "
                        "file version" << std::endl;
                return false;
        }
 
        size = readV3S16(is);
+
+       delete []slice_probs;
+       slice_probs = new u8[size.Y];
+       if (version >= 3) {
+               for (int y = 0; y != size.Y; y++)
+                       slice_probs[y] = readU8(is);
+       } else {
+               for (int y = 0; y != size.Y; y++)
+                       slice_probs[y] = MTSCHEM_PROB_ALWAYS;
+       }
+
        int nodecount = size.X * size.Y * size.Z;
-       
+
        u16 nidmapcount = readU16(is);
-       
+
        node_names = new std::vector<std::string>;
        for (int i = 0; i != nidmapcount; i++) {
                std::string name = deSerializeString(is);
@@ -711,11 +741,11 @@ bool DecoSchematic::loadSchematicFile() {
                node_names->push_back(name);
        }
 
-       delete schematic;
+       delete []schematic;
        schematic = new MapNode[nodecount];
        MapNode::deSerializeBulk(is, SER_FMT_VER_HIGHEST_READ, schematic,
                                nodecount, 2, 2, true);
-       
+
        if (version == 1) { // fix up the probability values
                for (int i = 0; i != nodecount; i++) {
                        if (schematic[i].param1 == 0)
@@ -724,7 +754,7 @@ bool DecoSchematic::loadSchematicFile() {
                                schematic[i].param1 = MTSCHEM_PROB_NEVER;
                }
        }
-       
+
        return true;
 }
 
@@ -734,10 +764,12 @@ bool DecoSchematic::loadSchematicFile() {
 
        All values are stored in big-endian byte order.
        [u32] signature: 'MTSM'
-       [u16] version: 2
+       [u16] version: 3
        [u16] size X
        [u16] size Y
        [u16] size Z
+       For each Y:
+               [u8] slice probability value
        [Name-ID table] Name ID Mapping Table
                [u16] name-id count
                For each name-id mapping:
@@ -751,27 +783,31 @@ bool DecoSchematic::loadSchematicFile() {
        For each node in schematic:
                [u8] param2
        }
-       
+
        Version changes:
        1 - Initial version
        2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
+       3 - Added y-slice probabilities; this allows for variable height structures
 */
 void DecoSchematic::saveSchematicFile(INodeDefManager *ndef) {
        std::ostringstream ss(std::ios_base::binary);
 
-       writeU32(ss, MTSCHEM_FILE_SIGNATURE); // signature
-       writeU16(ss, 2);      // version
-       writeV3S16(ss, size); // schematic size
-       
+       writeU32(ss, MTSCHEM_FILE_SIGNATURE);         // signature
+       writeU16(ss, MTSCHEM_FILE_VER_HIGHEST_WRITE); // version
+       writeV3S16(ss, size);                         // schematic size
+
+       for (int y = 0; y != size.Y; y++)             // Y slice probabilities
+               writeU8(ss, slice_probs[y]);
+
        std::vector<content_t> usednodes;
        int nodecount = size.X * size.Y * size.Z;
        build_nnlist_and_update_ids(schematic, nodecount, &usednodes);
-       
+
        u16 numids = usednodes.size();
        writeU16(ss, numids); // name count
        for (int i = 0; i != numids; i++)
                ss << serializeString(ndef->get(usednodes[i]).name); // node names
-               
+
        // compressed bulk node data
        MapNode::serializeBulk(ss, SER_FMT_VER_HIGHEST_WRITE, schematic,
                                nodecount, 2, 2, true);
@@ -784,7 +820,7 @@ void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
                                                std::vector<content_t> *usednodes) {
        std::map<content_t, content_t> nodeidmap;
        content_t numids = 0;
-       
+
        for (u32 i = 0; i != nodecount; i++) {
                content_t id;
                content_t c = nodes[i].getContent();
@@ -810,10 +846,15 @@ bool DecoSchematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) {
        v3s16 bp1 = getNodeBlockPos(p1);
        v3s16 bp2 = getNodeBlockPos(p2);
        vm->initialEmerge(bp1, bp2);
-       
+
        size = p2 - p1 + 1;
+
+       slice_probs = new u8[size.Y];
+       for (s16 y = 0; y != size.Y; y++)
+               slice_probs[y] = MTSCHEM_PROB_ALWAYS;
+
        schematic = new MapNode[size.X * size.Y * size.Z];
-       
+
        u32 i = 0;
        for (s16 z = p1.Z; z <= p2.Z; z++)
        for (s16 y = p1.Y; y <= p2.Y; y++) {
@@ -829,20 +870,27 @@ bool DecoSchematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) {
 }
 
 
-void DecoSchematic::applyProbabilities(std::vector<std::pair<v3s16, u8> > *plist,
-                                                                       v3s16 p0) {
+void DecoSchematic::applyProbabilities(v3s16 p0,
+       std::vector<std::pair<v3s16, u8> > *plist,
+       std::vector<std::pair<s16, u8> > *splist) {
+
        for (size_t i = 0; i != plist->size(); i++) {
                v3s16 p = (*plist)[i].first - p0;
                int index = p.Z * (size.Y * size.X) + p.Y * size.X + p.X;
                if (index < size.Z * size.Y * size.X) {
                        u8 prob = (*plist)[i].second;
                        schematic[index].param1 = prob;
-                       
+
                        // trim unnecessary node names from schematic
                        if (prob == MTSCHEM_PROB_NEVER)
                                schematic[index].setContent(CONTENT_AIR);
                }
        }
+
+       for (size_t i = 0; i != splist->size(); i++) {
+               s16 y = (*splist)[i].first - p0.Y;
+               slice_probs[y] = (*splist)[i].second;
+       }
 }
 
 
@@ -858,6 +906,15 @@ Mapgen::Mapgen() {
        ndef        = NULL;
        heightmap   = NULL;
        biomemap    = NULL;
+
+       for (unsigned int i = 0; i != NUM_GEN_NOTIFY; i++)
+               gen_notifications[i] = new std::vector<v3s16>;
+}
+
+
+Mapgen::~Mapgen() {
+       for (unsigned int i = 0; i != NUM_GEN_NOTIFY; i++)
+               delete gen_notifications[i];
 }
 
 
@@ -868,7 +925,7 @@ s16 Mapgen::findGroundLevelFull(v2s16 p2d) {
        s16 y_nodes_min = vm->m_area.MinEdge.Y;
        u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
        s16 y;
-       
+
        for (y = y_nodes_max; y >= y_nodes_min; y--) {
                MapNode &n = vm->m_data[i];
                if (ndef->get(n).walkable)
@@ -884,7 +941,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) {
        v3s16 em = vm->m_area.getExtent();
        u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
        s16 y;
-       
+
        for (y = ymax; y >= ymin; y--) {
                MapNode &n = vm->m_data[i];
                if (ndef->get(n).walkable)
@@ -899,7 +956,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) {
 void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
        if (!heightmap)
                return;
-       
+
        //TimeTaker t("Mapgen::updateHeightmap", NULL, PRECISION_MICRO);
        int index = 0;
        for (s16 z = nmin.Z; z <= nmax.Z; z++) {
@@ -911,7 +968,7 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
                                continue;
                        if (y == nmin.Y - 1 && heightmap[index] < nmin.Y)
                                continue;
-                               
+
                        heightmap[index] = y;
                }
        }
@@ -920,10 +977,8 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
 
 
 void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax) {
-       bool isliquid, wasliquid, rare;
+       bool isliquid, wasliquid;
        v3s16 em  = vm->m_area.getExtent();
-       rare = g_settings->getBool("liquid_finite");
-       int rarecnt = 0;
 
        for (s16 z = nmin.Z; z <= nmax.Z; z++) {
                for (s16 x = nmin.X; x <= nmax.X; x++) {
@@ -933,8 +988,8 @@ void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nm
                        for (s16 y = nmax.Y; y >= nmin.Y; y--) {
                                isliquid = ndef->get(vm->m_data[i]).isLiquid();
 
-                               // there was a change between liquid and nonliquid, add to queue. no need to add every with liquid_finite
-                               if (isliquid != wasliquid && (!rare || !(rarecnt++ % 36)))
+                               // there was a change between liquid and nonliquid, add to queue.
+                               if (isliquid != wasliquid)
                                        trans_liquid->push_back(v3s16(x, y, z));
 
                                wasliquid = isliquid;
@@ -1002,7 +1057,7 @@ void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax) {
                                continue;
                        }
                        vm->m_area.add_y(em, i, -1);
+
                        for (int y = a.MaxEdge.Y; y >= a.MinEdge.Y; y--) {
                                MapNode &n = vm->m_data[i];
                                if (!ndef->get(n).sunlight_propagates)
@@ -1065,71 +1120,3 @@ void Mapgen::calcLightingOld(v3s16 nmin, v3s16 nmax) {
                vm->spreadLight(bank, light_sources, ndef);
        }
 }
-//////////////////////// Mapgen V6 parameter read/write
-bool MapgenV6Params::readParams(Settings *settings) {
-       freq_desert = settings->getFloat("mgv6_freq_desert");
-       freq_beach  = settings->getFloat("mgv6_freq_beach");
-
-       bool success = 
-               settings->getNoiseParams("mgv6_np_terrain_base",   np_terrain_base)   &&
-               settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher) &&
-               settings->getNoiseParams("mgv6_np_steepness",      np_steepness)      &&
-               settings->getNoiseParams("mgv6_np_height_select",  np_height_select)  &&
-               settings->getNoiseParams("mgv6_np_mud",            np_mud)            &&
-               settings->getNoiseParams("mgv6_np_beach",          np_beach)          &&
-               settings->getNoiseParams("mgv6_np_biome",          np_biome)          &&
-               settings->getNoiseParams("mgv6_np_cave",           np_cave)           &&
-               settings->getNoiseParams("mgv6_np_humidity",       np_humidity)       &&
-               settings->getNoiseParams("mgv6_np_trees",          np_trees)          &&
-               settings->getNoiseParams("mgv6_np_apple_trees",    np_apple_trees);
-       return success;
-}
-void MapgenV6Params::writeParams(Settings *settings) {
-       settings->setFloat("mgv6_freq_desert", freq_desert);
-       settings->setFloat("mgv6_freq_beach",  freq_beach);
-       settings->setNoiseParams("mgv6_np_terrain_base",   np_terrain_base);
-       settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
-       settings->setNoiseParams("mgv6_np_steepness",      np_steepness);
-       settings->setNoiseParams("mgv6_np_height_select",  np_height_select);
-       settings->setNoiseParams("mgv6_np_mud",            np_mud);
-       settings->setNoiseParams("mgv6_np_beach",          np_beach);
-       settings->setNoiseParams("mgv6_np_biome",          np_biome);
-       settings->setNoiseParams("mgv6_np_cave",           np_cave);
-       settings->setNoiseParams("mgv6_np_humidity",       np_humidity);
-       settings->setNoiseParams("mgv6_np_trees",          np_trees);
-       settings->setNoiseParams("mgv6_np_apple_trees",    np_apple_trees);
-}
-
-
-bool MapgenV7Params::readParams(Settings *settings) {
-       bool success = 
-               settings->getNoiseParams("mgv7_np_terrain_base",    np_terrain_base)    &&
-               settings->getNoiseParams("mgv7_np_terrain_alt",     np_terrain_alt)     &&
-               settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist) &&
-               settings->getNoiseParams("mgv7_np_height_select",   np_height_select)   &&
-               settings->getNoiseParams("mgv7_np_filler_depth",    np_filler_depth)    &&
-               settings->getNoiseParams("mgv7_np_mount_height",    np_mount_height)    &&
-               settings->getNoiseParams("mgv7_np_ridge_uwater",    np_ridge_uwater)    &&
-               settings->getNoiseParams("mgv7_np_mountain",        np_mountain)        &&
-               settings->getNoiseParams("mgv7_np_ridge",           np_ridge);
-       return success;
-}
-
-
-void MapgenV7Params::writeParams(Settings *settings) {
-       settings->setNoiseParams("mgv7_np_terrain_base",    np_terrain_base);
-       settings->setNoiseParams("mgv7_np_terrain_alt",     np_terrain_alt);
-       settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
-       settings->setNoiseParams("mgv7_np_height_select",   np_height_select);
-       settings->setNoiseParams("mgv7_np_filler_depth",    np_filler_depth);
-       settings->setNoiseParams("mgv7_np_mount_height",    np_mount_height);
-       settings->setNoiseParams("mgv7_np_ridge_uwater",    np_ridge_uwater);
-       settings->setNoiseParams("mgv7_np_mountain",        np_mountain);
-       settings->setNoiseParams("mgv7_np_ridge",           np_ridge);
-}