Add sneak and sneak_glitch to set_physics_override()
authorPilzAdam <pilzadam@minetest.net>
Tue, 3 Dec 2013 17:51:15 +0000 (18:51 +0100)
committerPilzAdam <pilzadam@minetest.net>
Tue, 3 Dec 2013 22:20:00 +0000 (23:20 +0100)
doc/lua_api.txt
src/content_cao.cpp
src/content_sao.cpp
src/content_sao.h
src/genericobject.cpp
src/genericobject.h
src/localplayer.cpp
src/player.cpp
src/player.h
src/script/lua_api/l_object.cpp
src/script/lua_api/l_object.h

index f3240dd40d0ca60d9a6a698ec87e47abc53465c8..410998cc61fc2074e4dc9817ab7100e9fe956d2b 100644 (file)
@@ -1706,10 +1706,11 @@ Player-only: (no-op for other objects)
     {jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}
 - get_player_control_bits(): returns integer with bit packed player pressed keys
     bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
-- set_physics_override(speed, jump, gravity)
+- set_physics_override(speed, jump, gravity, sneak, sneak_glitch)
     modifies per-player walking speed, jump height, and gravity.
     Values default to 1 and act as offsets to the physics settings 
     in minetest.conf. nil will keep the current setting.
+    sneak and sneak_glitch are booleans, default is true
 - hud_add(hud definition): add a HUD element described by HUD def, returns ID number on success
 - hud_remove(id): remove the HUD element of the specified id
 - hud_change(id, stat, value): change a value of a previously added HUD element
index e97e3a1beae912712c507fde32cda4bc38089fb9..ec8cde35be1215cb56a75214e01703cba15e98d4 100644 (file)
@@ -1693,12 +1693,18 @@ public:
                        float override_speed = readF1000(is);
                        float override_jump = readF1000(is);
                        float override_gravity = readF1000(is);
+                       // these are sent inverted so we get true when the server sends nothing
+                       bool sneak = !readU8(is);
+                       bool sneak_glitch = !readU8(is);
+                       
                        if(m_is_local_player)
                        {
                                LocalPlayer *player = m_env->getLocalPlayer();
                                player->physics_override_speed = override_speed;
                                player->physics_override_jump = override_jump;
                                player->physics_override_gravity = override_gravity;
+                               player->physics_override_sneak = sneak;
+                               player->physics_override_sneak_glitch = sneak_glitch;
                        }
                }
                else if(cmd == GENERIC_CMD_SET_ANIMATION)
index 85ab8d307abe4bb4e36682eea48f92ffe6a6c8bc..52b741365cfa18c16606d3d3a4cdb85b4b3389d7 100644 (file)
@@ -969,6 +969,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
        m_physics_override_speed(1),
        m_physics_override_jump(1),
        m_physics_override_gravity(1),
+       m_physics_override_sneak(true),
+       m_physics_override_sneak_glitch(true),
        m_physics_override_sent(false)
 {
        assert(m_player);
@@ -1060,7 +1062,9 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
                        os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
                }
                os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
-               os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed, m_physics_override_jump, m_physics_override_gravity)); // 5
+               os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
+                               m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
+                               m_physics_override_sneak_glitch)); // 5
        }
        else
        {
@@ -1187,7 +1191,9 @@ void PlayerSAO::step(float dtime, bool send_recommended)
 
        if(m_physics_override_sent == false){
                m_physics_override_sent = true;
-               std::string str = gob_cmd_update_physics_override(m_physics_override_speed, m_physics_override_jump, m_physics_override_gravity);
+               std::string str = gob_cmd_update_physics_override(m_physics_override_speed,
+                               m_physics_override_jump, m_physics_override_gravity,
+                               m_physics_override_sneak, m_physics_override_sneak_glitch);
                // create message and add to list
                ActiveObjectMessage aom(getId(), true, str);
                m_messages_out.push_back(aom);
index 6b97cb1488ddd6ad92688af7d9cd3a672ea0c490..1be620f299b3845749b2a9a01ac7d685b16eb086 100644 (file)
@@ -330,6 +330,8 @@ public:
        float m_physics_override_speed;
        float m_physics_override_jump;
        float m_physics_override_gravity;
+       bool m_physics_override_sneak;
+       bool m_physics_override_sneak_glitch;
        bool m_physics_override_sent;
 };
 
index e2fbde8387095bfa9e402f49dae83bdedf730275..9a1b9d8d0dc657b109220b3d2a2d5877cce5277d 100644 (file)
@@ -117,7 +117,8 @@ std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups)
        return os.str();
 }
 
-std::string gob_cmd_update_physics_override(float physics_override_speed, float physics_override_jump, float physics_override_gravity)
+std::string gob_cmd_update_physics_override(float physics_override_speed, float physics_override_jump,
+               float physics_override_gravity, bool sneak, bool sneak_glitch)
 {
        std::ostringstream os(std::ios::binary);
        // command 
@@ -126,6 +127,9 @@ std::string gob_cmd_update_physics_override(float physics_override_speed, float
        writeF1000(os, physics_override_speed);
        writeF1000(os, physics_override_jump);
        writeF1000(os, physics_override_gravity);
+       // these are sent inverted so we get true when the server sends nothing
+       writeU8(os, !sneak);
+       writeU8(os, !sneak_glitch);
        return os.str();
 }
 
index 276865ab972250df9844311550eaf395df0b2751..29e5e29cb67481fc30846d6649bda20581eeb83d 100644 (file)
@@ -63,7 +63,8 @@ std::string gob_cmd_punched(s16 damage, s16 result_hp);
 #include "itemgroup.h"
 std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups);
 
-std::string gob_cmd_update_physics_override(float physics_override_speed, float physics_override_jump, float physics_override_gravity);
+std::string gob_cmd_update_physics_override(float physics_override_speed,
+               float physics_override_jump, float physics_override_gravity, bool sneak, bool sneak_glitch);
 
 std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend);
 
index 48e6592c19e5252e557b935c75240da985a0c8ec..a6f04849ab42c27778f3904e3be42c6036ef25af 100644 (file)
@@ -165,7 +165,9 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
                If sneaking, keep in range from the last walked node and don't
                fall off from it
        */
-       if(control.sneak && m_sneak_node_exists && !(fly_allowed && g_settings->getBool("free_move")) && !in_liquid)
+       if(control.sneak && m_sneak_node_exists &&
+                       !(fly_allowed && g_settings->getBool("free_move")) && !in_liquid &&
+                       physics_override_sneak)
        {
                f32 maxd = 0.5*BS + sneak_max;
                v3f lwn_f = intToFloat(m_sneak_node, BS);
@@ -225,7 +227,7 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
                // node.
                m_need_to_get_new_sneak_node = true;
        }
-       if(m_need_to_get_new_sneak_node)
+       if(m_need_to_get_new_sneak_node && physics_override_sneak)
        {
                v3s16 pos_i_bottom = floatToInt(position - v3f(0,BS/2,0), BS);
                v2f player_p2df(position.X, position.Z);
@@ -264,6 +266,10 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
                                // And the node above it has to be nonwalkable
                                if(nodemgr->get(map->getNode(p+v3s16(0,1,0))).walkable == true)
                                        continue;
+                               if (!physics_override_sneak_glitch) {
+                                       if (nodemgr->get(map->getNode(p+v3s16(0,2,0))).walkable)
+                                               continue;
+                               }
                        }
                        catch(InvalidPositionException &e)
                        {
@@ -576,6 +582,6 @@ v3s16 LocalPlayer::getStandingNodePos()
 {
        if(m_sneak_node_exists)
                return m_sneak_node;
-       return floatToInt(getPosition(), BS);
+       return floatToInt(getPosition() - v3f(0, BS, 0), BS);
 }
 
index 584c00dd0855158a400ecc14bc5e0f3b72588281..3481260c032222753284bd97eefe11ef987444d2 100644 (file)
@@ -85,9 +85,11 @@ Player::Player(IGameDef *gamedef):
        movement_gravity                = 9.81 * BS;
 
        // Movement overrides are multipliers and must be 1 by default
-       physics_override_speed   = 1;
-       physics_override_jump    = 1;
-       physics_override_gravity = 1;
+       physics_override_speed        = 1;
+       physics_override_jump         = 1;
+       physics_override_gravity      = 1;
+       physics_override_sneak        = true;
+       physics_override_sneak_glitch = true;
 
        hud_flags = HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE |
                         HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
index 12ea0dba1c14e087a74e5fd3e98cee2f7c0cdfa9..a1050d4c7dae5fdc979b0f38d72f9af44902b453 100644 (file)
@@ -266,6 +266,8 @@ public:
        float physics_override_speed;
        float physics_override_jump;
        float physics_override_gravity;
+       bool physics_override_sneak;
+       bool physics_override_sneak_glitch;
 
        u16 hp;
 
index cbcaa40eb7cf173f3fe8b9d0560ef1122755cb55..5e1517e46cf38c622f92ce9ac000ca49d427b657 100644 (file)
@@ -349,7 +349,8 @@ int ObjectRef::l_set_armor_groups(lua_State *L)
        return 0;
 }
 
-// set_physics_override(self, physics_override_speed, physics_override_jump, physics_override_gravity)
+// set_physics_override(self, physics_override_speed, physics_override_jump,
+//                      physics_override_gravity, sneak, sneak_glitch)
 int ObjectRef::l_set_physics_override(lua_State *L)
 {
        ObjectRef *ref = checkobject(L, 1);
@@ -368,6 +369,14 @@ int ObjectRef::l_set_physics_override(lua_State *L)
                co->m_physics_override_gravity = lua_tonumber(L, 4);
                co->m_physics_override_sent = false;
        }
+       if (lua_isboolean(L, 5)) {
+               co->m_physics_override_sneak = lua_toboolean(L, 5);
+               co->m_physics_override_sent = false;
+       }
+       if (lua_isboolean(L, 6)) {
+               co->m_physics_override_sneak_glitch = lua_toboolean(L, 6);
+               co->m_physics_override_sent = false;
+       }
        return 0;
 }
 
index 4b4f5eff7e193745d771b53ca5510110758d334f..c8c67f2c52ae5c6d97e30675ba4af721c4761adf 100644 (file)
@@ -101,7 +101,8 @@ private:
        // set_armor_groups(self, groups)
        static int l_set_armor_groups(lua_State *L);
 
-       // set_physics_override(self, physics_override_speed, physics_override_jump, physics_override_gravity)
+       // set_physics_override(self, physics_override_speed, physics_override_jump,
+       //                      physics_override_gravity, sneak, sneak_glitch)
        static int l_set_physics_override(lua_State *L);
 
        // set_animation(self, frame_range, frame_speed, frame_blend)