From: PilzAdam Date: Tue, 3 Dec 2013 17:51:15 +0000 (+0100) Subject: Add sneak and sneak_glitch to set_physics_override() X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=15be2659eae6da2c3807713eb6e068d8aa436423;p=zefram%2Fminetest%2Fminetest_engine.git Add sneak and sneak_glitch to set_physics_override() --- diff --git a/doc/lua_api.txt b/doc/lua_api.txt index f3240dd4..410998cc 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -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 diff --git a/src/content_cao.cpp b/src/content_cao.cpp index e97e3a1b..ec8cde35 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -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) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 85ab8d30..52b74136 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -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<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); } diff --git a/src/player.cpp b/src/player.cpp index 584c00dd..3481260c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -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 | diff --git a/src/player.h b/src/player.h index 12ea0dba..a1050d4c 100644 --- a/src/player.h +++ b/src/player.h @@ -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; diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index cbcaa40e..5e1517e4 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -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; } diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index 4b4f5eff..c8c67f2c 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -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)