Add sneak and sneak_glitch to set_physics_override()

This commit is contained in:
PilzAdam 2013-12-03 18:51:15 +01:00
parent d9de9f23d9
commit 15be2659ea
11 changed files with 53 additions and 13 deletions

@ -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

@ -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)

@ -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);

@ -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;
};

@ -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();
}

@ -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);

@ -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);
}

@ -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 |

@ -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;

@ -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;
}

@ -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)