Fix damage flash when damage disabled
[oweals/minetest.git] / src / dungeongen.cpp
index 2027b7f1381c0fac9aca3a45e8d7c1f31b7b5c85..7e292024da8c170014d9aa593ec09fe6ac6f6621 100644 (file)
@@ -26,14 +26,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "nodedef.h"
 #include "profiler.h"
-#include "settings.h" // For g_settings
-#include "main.h" // For g_profiler
+#include "settings.h"
 
 //#define DGEN_USE_TORCHES
 
-NoiseParams nparams_dungeon_rarity(0.0, 1.0, v3f(500.0, 500.0, 500.0), 0, 2, 0.8);
-NoiseParams nparams_dungeon_wetness(0.0, 1.0, v3f(40.0, 40.0, 40.0), 32474, 4, 1.1);
-NoiseParams nparams_dungeon_density(0.0, 1.0, v3f(2.5, 2.5, 2.5), 0, 2, 1.4);
+NoiseParams nparams_dungeon_rarity(0.0, 1.0, v3f(500.0, 500.0, 500.0), 0, 2, 0.8, 2.0);
+NoiseParams nparams_dungeon_wetness(0.0, 1.0, v3f(40.0, 40.0, 40.0), 32474, 4, 1.1, 2.0);
+NoiseParams nparams_dungeon_density(0.0, 1.0, v3f(2.5, 2.5, 2.5), 0, 2, 1.4, 2.0);
 
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -46,7 +45,7 @@ DungeonGen::DungeonGen(Mapgen *mapgen, DungeonParams *dparams) {
 #ifdef DGEN_USE_TORCHES
        c_torch  = ndef->getId("default:torch");
 #endif
-       
+
        if (dparams) {
                memcpy(&dp, dparams, sizeof(dp));
        } else {
@@ -70,10 +69,7 @@ DungeonGen::DungeonGen(Mapgen *mapgen, DungeonParams *dparams) {
 
 void DungeonGen::generate(u32 bseed, v3s16 nmin, v3s16 nmax) {
        //TimeTaker t("gen dungeons");
-       int approx_groundlevel = 10 + mg->water_level;
-
-       if ((nmin.Y + nmax.Y) / 2 >= approx_groundlevel ||
-               NoisePerlin3D(&dp.np_rarity, nmin.X, nmin.Y, nmin.Z, mg->seed) < 0.2)
+       if (NoisePerlin3D(&dp.np_rarity, nmin.X, nmin.Y, nmin.Z, mg->seed) < 0.2)
                return;
 
        this->blockseed = bseed;
@@ -82,20 +78,23 @@ void DungeonGen::generate(u32 bseed, v3s16 nmin, v3s16 nmax) {
        // Dungeon generator doesn't modify places which have this set
        vm->clearFlag(VMANIP_FLAG_DUNGEON_INSIDE | VMANIP_FLAG_DUNGEON_PRESERVE);
 
-       // Set all air and water to be untouchable to make dungeons open
-       // to caves and open air
+       bool no_float = !g_settings->getBool("enable_floating_dungeons");
+
+       // Set all air and water (and optionally ignore) to be untouchable
+       // to make dungeons open to caves and open air
        for (s16 z = nmin.Z; z <= nmax.Z; z++) {
                for (s16 y = nmin.Y; y <= nmax.Y; y++) {
                        u32 i = vm->m_area.index(nmin.X, y, z);
                        for (s16 x = nmin.X; x <= nmax.X; x++) {
                                content_t c = vm->m_data[i].getContent();
-                               if (c == CONTENT_AIR || c == dp.c_water)
+                               if (c == CONTENT_AIR || c == dp.c_water
+                                               || (no_float && c == CONTENT_IGNORE))
                                        vm->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE;
                                i++;
                        }
                }
        }
-       
+
        // Add it
        makeDungeon(v3s16(1,1,1) * MAP_BLOCKSIZE);
 
@@ -115,7 +114,7 @@ void DungeonGen::generate(u32 bseed, v3s16 nmin, v3s16 nmax) {
                        }
                }
        }
-       
+
        //printf("== gen dungeons: %dms\n", t.stop());
 }
 
@@ -144,7 +143,7 @@ void DungeonGen::makeDungeon(v3s16 start_padding)
                        random.range(0,areasize.X-roomsize.X-1-start_padding.X),
                        random.range(0,areasize.Y-roomsize.Y-1-start_padding.Y),
                        random.range(0,areasize.Z-roomsize.Z-1-start_padding.Z));
-                       
+
                /*
                        Check that we're not putting the room to an unknown place,
                        otherwise it might end up floating in the air
@@ -181,10 +180,7 @@ void DungeonGen::makeDungeon(v3s16 start_padding)
                makeRoom(roomsize, roomplace);
 
                v3s16 room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2);
-               if (mg->gennotify & (1 << dp.notifytype)) {
-                       std::vector <v3s16> *nvec = mg->gen_notifications[dp.notifytype];
-                       nvec->push_back(room_center);
-               }
+               mg->gennotify.addEvent(dp.notifytype, room_center);
 
 #ifdef DGEN_USE_TORCHES
                // Place torch at room center (for testing)
@@ -212,7 +208,7 @@ void DungeonGen::makeDungeon(v3s16 start_padding)
                // Create walker and find a place for a door
                v3s16 doorplace;
                v3s16 doordir;
-               
+
                m_pos = walker_start_place;
                if (!findPlaceForDoor(doorplace, doordir))
                        return;
@@ -253,7 +249,7 @@ void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace)
 {
        MapNode n_cobble(dp.c_cobble);
        MapNode n_air(CONTENT_AIR);
-       
+
        // Make +-X walls
        for (s16 z = 0; z < roomsize.Z; z++)
        for (s16 y = 0; y < roomsize.Y; y++)
@@ -393,10 +389,10 @@ void DungeonGen::makeCorridor(v3s16 doorplace,
        u32 partlength = random.range(1, 13);
        u32 partcount = 0;
        s16 make_stairs = 0;
-       
+
        if (random.next() % 2 == 0 && partlength >= 3)
                make_stairs = random.next() % 2 ? 1 : -1;
-       
+
        for (u32 i = 0; i < length; i++) {
                v3s16 p = p0 + dir;
                if (partcount != 0)
@@ -409,7 +405,7 @@ void DungeonGen::makeCorridor(v3s16 doorplace,
                                                VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_cobble), 0);
                                makeHole(p);
                                makeHole(p - dir);
-                               
+
                                // TODO: fix stairs code so it works 100% (quite difficult)
 
                                // exclude stairs from the bottom step
@@ -419,11 +415,11 @@ void DungeonGen::makeCorridor(v3s16 doorplace,
                                        ((make_stairs == -1) && i != length - 1))) {
                                        // rotate face 180 deg if making stairs backwards
                                        int facedir = dir_to_facedir(dir * make_stairs);
-                                       
+
                                        u32 vi = vm->m_area.index(p.X - dir.X, p.Y - 1, p.Z - dir.Z);
                                        if (vm->m_data[vi].getContent() == dp.c_cobble)
                                                vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir);
-                                       
+
                                        vi = vm->m_area.index(p.X, p.Y, p.Z);
                                        if (vm->m_data[vi].getContent() == dp.c_cobble)
                                                vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir);