Only fly through walls in noclip mode wich requires the noclip privilege
authorPilzAdam <adam-k@outlook.com>
Sun, 9 Dec 2012 12:34:16 +0000 (13:34 +0100)
committerPilzAdam <adam-k@outlook.com>
Tue, 11 Dec 2012 15:44:13 +0000 (16:44 +0100)
builtin/privileges.lua
src/defaultsettings.cpp
src/game.cpp
src/guiKeyChangeMenu.cpp
src/localplayer.cpp

index 9ec09d7f6a8c0698dc1c601bd05ed0f81024d808..8dd06b24f9ea99a5519638f8d3d57e9d5a01e803 100644 (file)
@@ -44,5 +44,9 @@ minetest.register_privilege("fast", {
        description = "Can walk fast using the fast_move mode",
        give_to_singleplayer = false,
 })
+minetest.register_privilege("noclip", {
+       description = "Can fly through walls",
+       give_to_singleplayer = false,
+})
 minetest.register_privilege("rollback", "Can use the rollback functionality")
 
index c43e0e03c5020863504dc46c7d54f6eee5dccd3b..d824d292387542a50975819f13babc54a469b2ce 100644 (file)
@@ -43,6 +43,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
        settings->setDefault("keymap_freemove", "KEY_KEY_K");
        settings->setDefault("keymap_fastmove", "KEY_KEY_J");
+       settings->setDefault("keymap_noclip", "KEY_KEY_H");
        settings->setDefault("keymap_screenshot", "KEY_F12");
        settings->setDefault("keymap_toggle_hud", "KEY_F1");
        settings->setDefault("keymap_toggle_chat", "KEY_F2");
@@ -95,6 +96,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("shader_path", "");
        settings->setDefault("video_driver", "opengl");
        settings->setDefault("free_move", "false");
+       settings->setDefault("noclip", "false");
        settings->setDefault("continuous_forward", "false");
        settings->setDefault("fast_move", "false");
        settings->setDefault("invert_mouse", "false");
index 9cd4609223baac42e840ca347c4094259200984c..dbb71369fbaf1da3ab9d397af74fa30c6cde8d47 100644 (file)
@@ -1665,6 +1665,23 @@ void the_game(
                                        statustext += L" (note: no 'fast' privilege)";
                        }
                }
+               else if(input->wasKeyDown(getKeySetting("keymap_noclip")))
+               {
+                       if(g_settings->getBool("noclip"))
+                       {
+                               g_settings->set("noclip","false");
+                               statustext = L"noclip disabled";
+                               statustext_time = 0;
+                       }
+                       else
+                       {
+                               g_settings->set("noclip","true");
+                               statustext = L"noclip enabled";
+                               statustext_time = 0;
+                               if(!client.checkPrivilege("noclip"))
+                                       statustext += L" (note: no 'noclip' privilege)";
+                       }
+               }
                else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
                {
                        irr::video::IImage* const image = driver->createScreenShot(); 
index 405a81e0b8350cb32a15f3d44b6362060f34080f..8f7c7245c1dc0fc437b54b965f527d2a0ba9bac9 100644 (file)
@@ -46,6 +46,7 @@ enum
        GUI_ID_KEY_FLY_BUTTON,
        GUI_ID_KEY_FAST_BUTTON,
        GUI_ID_KEY_JUMP_BUTTON,
+       GUI_ID_KEY_NOCLIP_BUTTON,
        GUI_ID_KEY_CHAT_BUTTON,
        GUI_ID_KEY_CMD_BUTTON,
        GUI_ID_KEY_CONSOLE_BUTTON,
@@ -362,6 +363,7 @@ void GUIKeyChangeMenu::init_keys()
        this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, "Console", "keymap_console");
        this->add_key(GUI_ID_KEY_FLY_BUTTON, "Toggle fly", "keymap_freemove");
        this->add_key(GUI_ID_KEY_FAST_BUTTON, "Toggle fast", "keymap_fastmove");
+       this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, "Toggle noclip", "keymap_noclip");
        this->add_key(GUI_ID_KEY_RANGE_BUTTON, "Range select", "keymap_rangeselect");
        this->add_key(GUI_ID_KEY_DUMP_BUTTON, "Print stacks", "keymap_print_debug_stacks");
 }
index 14d1ac60ecb605fbe59e3f24e2e9acfa3c9c6527..96ddb4bb20434f2c40cf8e8e200c3abb22d0acd7 100644 (file)
@@ -73,9 +73,11 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                return;
        }
 
-       // Skip collision detection if a special movement mode is used
+       // Skip collision detection if noclip mode is used
        bool fly_allowed = m_gamedef->checkLocalPrivilege("fly");
-       bool free_move = fly_allowed && g_settings->getBool("free_move");
+       bool noclip = m_gamedef->checkLocalPrivilege("noclip") &&
+               g_settings->getBool("noclip");
+       bool free_move = noclip && fly_allowed && g_settings->getBool("free_move");
        if(free_move)
        {
         position += m_speed * dtime;
@@ -300,7 +302,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                Report collisions
        */
        bool bouncy_jump = false;
-       if(collision_info)
+       // Dont report if flying
+       if(collision_info && !g_settings->getBool("free_move"))
        {
                for(size_t i=0; i<result.collisions.size(); i++){
                        const CollisionInfo &info = result.collisions[i];