mirror of https://github.com/minetest/minetest.git
Slippery physics override setting
Allows mods to change a player's slip factor (e.g. wearing boots could reduce this) Note: Require assistance on implementing needed changed protocol version check in I_object!
This commit is contained in:
parent
fe1b5b4947
commit
b6b0b831ac
|
@ -1661,6 +1661,8 @@ void GenericCAO::processMessage(const std::string &data)
|
||||||
float override_speed = readF1000(is);
|
float override_speed = readF1000(is);
|
||||||
float override_jump = readF1000(is);
|
float override_jump = readF1000(is);
|
||||||
float override_gravity = readF1000(is);
|
float override_gravity = readF1000(is);
|
||||||
|
///TODO: detect protocol VERSION!
|
||||||
|
float override_slip = readF1000(is);
|
||||||
// these are sent inverted so we get true when the server sends nothing
|
// these are sent inverted so we get true when the server sends nothing
|
||||||
bool sneak = !readU8(is);
|
bool sneak = !readU8(is);
|
||||||
bool sneak_glitch = !readU8(is);
|
bool sneak_glitch = !readU8(is);
|
||||||
|
@ -1672,6 +1674,7 @@ void GenericCAO::processMessage(const std::string &data)
|
||||||
player->physics_override_speed = override_speed;
|
player->physics_override_speed = override_speed;
|
||||||
player->physics_override_jump = override_jump;
|
player->physics_override_jump = override_jump;
|
||||||
player->physics_override_gravity = override_gravity;
|
player->physics_override_gravity = override_gravity;
|
||||||
|
player->physics_override_slip = override_slip;
|
||||||
player->physics_override_sneak = sneak;
|
player->physics_override_sneak = sneak;
|
||||||
player->physics_override_sneak_glitch = sneak_glitch;
|
player->physics_override_sneak_glitch = sneak_glitch;
|
||||||
}
|
}
|
||||||
|
|
|
@ -773,6 +773,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
|
||||||
m_physics_override_speed(1),
|
m_physics_override_speed(1),
|
||||||
m_physics_override_jump(1),
|
m_physics_override_jump(1),
|
||||||
m_physics_override_gravity(1),
|
m_physics_override_gravity(1),
|
||||||
|
m_physics_override_slip(1),
|
||||||
m_physics_override_sneak(true),
|
m_physics_override_sneak(true),
|
||||||
m_physics_override_sneak_glitch(true),
|
m_physics_override_sneak_glitch(true),
|
||||||
m_physics_override_sent(false)
|
m_physics_override_sent(false)
|
||||||
|
@ -865,7 +866,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
|
||||||
}
|
}
|
||||||
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_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,
|
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_jump, m_physics_override_gravity, m_physics_override_slip, m_physics_override_sneak,
|
||||||
m_physics_override_sneak_glitch)); // 5
|
m_physics_override_sneak_glitch)); // 5
|
||||||
os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6 (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
|
os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6 (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
|
||||||
}
|
}
|
||||||
|
@ -989,7 +990,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
|
||||||
if(m_physics_override_sent == false){
|
if(m_physics_override_sent == false){
|
||||||
m_physics_override_sent = true;
|
m_physics_override_sent = true;
|
||||||
std::string str = gob_cmd_update_physics_override(m_physics_override_speed,
|
std::string str = gob_cmd_update_physics_override(m_physics_override_speed,
|
||||||
m_physics_override_jump, m_physics_override_gravity,
|
m_physics_override_jump, m_physics_override_gravity, m_physics_override_slip,
|
||||||
m_physics_override_sneak, m_physics_override_sneak_glitch);
|
m_physics_override_sneak, m_physics_override_sneak_glitch);
|
||||||
// create message and add to list
|
// create message and add to list
|
||||||
ActiveObjectMessage aom(getId(), true, str);
|
ActiveObjectMessage aom(getId(), true, str);
|
||||||
|
|
|
@ -336,6 +336,7 @@ public:
|
||||||
float m_physics_override_speed;
|
float m_physics_override_speed;
|
||||||
float m_physics_override_jump;
|
float m_physics_override_jump;
|
||||||
float m_physics_override_gravity;
|
float m_physics_override_gravity;
|
||||||
|
float m_physics_override_slip;
|
||||||
bool m_physics_override_sneak;
|
bool m_physics_override_sneak;
|
||||||
bool m_physics_override_sneak_glitch;
|
bool m_physics_override_sneak_glitch;
|
||||||
bool m_physics_override_sent;
|
bool m_physics_override_sent;
|
||||||
|
|
|
@ -118,7 +118,7 @@ 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,
|
std::string gob_cmd_update_physics_override(float physics_override_speed, float physics_override_jump,
|
||||||
float physics_override_gravity, bool sneak, bool sneak_glitch)
|
float physics_override_gravity, float physics_override_slip, bool sneak, bool sneak_glitch)
|
||||||
{
|
{
|
||||||
std::ostringstream os(std::ios::binary);
|
std::ostringstream os(std::ios::binary);
|
||||||
// command
|
// command
|
||||||
|
@ -127,6 +127,7 @@ std::string gob_cmd_update_physics_override(float physics_override_speed, float
|
||||||
writeF1000(os, physics_override_speed);
|
writeF1000(os, physics_override_speed);
|
||||||
writeF1000(os, physics_override_jump);
|
writeF1000(os, physics_override_jump);
|
||||||
writeF1000(os, physics_override_gravity);
|
writeF1000(os, physics_override_gravity);
|
||||||
|
writeF1000(os, physics_override_slip);
|
||||||
// these are sent inverted so we get true when the server sends nothing
|
// these are sent inverted so we get true when the server sends nothing
|
||||||
writeU8(os, !sneak);
|
writeU8(os, !sneak);
|
||||||
writeU8(os, !sneak_glitch);
|
writeU8(os, !sneak_glitch);
|
||||||
|
|
|
@ -67,7 +67,7 @@ std::string gob_cmd_punched(s16 damage, s16 result_hp);
|
||||||
std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups);
|
std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups);
|
||||||
|
|
||||||
std::string gob_cmd_update_physics_override(float physics_override_speed,
|
std::string gob_cmd_update_physics_override(float physics_override_speed,
|
||||||
float physics_override_jump, float physics_override_gravity, bool sneak, bool sneak_glitch);
|
float physics_override_jump, float physics_override_gravity, float physics_override_slip, bool sneak, bool sneak_glitch);
|
||||||
|
|
||||||
std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend, bool frame_loop);
|
std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend, bool frame_loop);
|
||||||
|
|
||||||
|
|
|
@ -610,19 +610,25 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
||||||
else
|
else
|
||||||
incH = incV = movement_acceleration_default * BS * dtime;
|
incH = incV = movement_acceleration_default * BS * dtime;
|
||||||
|
|
||||||
// Accelerate to target speed with maximum increment
|
int slippery;
|
||||||
|
if (!free_move && !control.sneak && !is_climbing)
|
||||||
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
Map *map = &env->getMap();
|
Map *map = &env->getMap();
|
||||||
v3s16 p = floatToInt(getPosition() - v3f(0,BS/2,0), BS);
|
v3s16 position = floatToInt(getPosition() - v3f(0,BS/2,0), BS);
|
||||||
ContentFeatures node = nodemgr->get(map->getNodeNoEx(p));
|
ContentFeatures node = nodemgr->get(map->getNodeNoEx(position));
|
||||||
int slippery = itemgroup_get(node.groups, "slippery");
|
|
||||||
// Sliding onto a non-walkable node, set a default to allow sliding off edges
|
|
||||||
if (slippery==0 && node.walkable==false && !free_move && !is_climbing && !control.sneak)
|
|
||||||
{
|
|
||||||
slippery = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed, slippery);
|
slippery = itemgroup_get(node.groups, "slippery");
|
||||||
|
|
||||||
|
// Sliding onto a non-walkable node that you should fall through?
|
||||||
|
if (slippery==0 && !node.walkable)
|
||||||
|
slippery = 100; // override to allow sliding off edges into
|
||||||
|
}
|
||||||
|
else
|
||||||
|
slippery = 0;
|
||||||
|
|
||||||
|
// Accelerate to target speed with maximum increment
|
||||||
|
accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed, slippery * physics_override_slip);
|
||||||
accelerateVertical(speedV * physics_override_speed, incV * physics_override_speed);
|
accelerateVertical(speedV * physics_override_speed, incV * physics_override_speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,9 +132,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
|
Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
|
||||||
PROTOCOL_VERSION 26:
|
PROTOCOL_VERSION 26:
|
||||||
Add TileDef tileable_horizontal, tileable_vertical flags
|
Add TileDef tileable_horizontal, tileable_vertical flags
|
||||||
|
PROTOCOL_VERSION 27:
|
||||||
|
Add physics_override_slip
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LATEST_PROTOCOL_VERSION 26
|
#define LATEST_PROTOCOL_VERSION 27
|
||||||
|
|
||||||
// Server's supported network protocol range
|
// Server's supported network protocol range
|
||||||
#define SERVER_PROTOCOL_VERSION_MIN 13
|
#define SERVER_PROTOCOL_VERSION_MIN 13
|
||||||
|
|
|
@ -95,6 +95,7 @@ Player::Player(IGameDef *gamedef, const char *name):
|
||||||
physics_override_speed = 1;
|
physics_override_speed = 1;
|
||||||
physics_override_jump = 1;
|
physics_override_jump = 1;
|
||||||
physics_override_gravity = 1;
|
physics_override_gravity = 1;
|
||||||
|
physics_override_slip = 1;
|
||||||
physics_override_sneak = true;
|
physics_override_sneak = true;
|
||||||
physics_override_sneak_glitch = true;
|
physics_override_sneak_glitch = true;
|
||||||
|
|
||||||
|
@ -121,9 +122,9 @@ void Player::accelerateHorizontal(v3f target_speed, f32 max_increase, int slippe
|
||||||
if (slippery)
|
if (slippery)
|
||||||
{
|
{
|
||||||
if (target_speed == v3f(0))
|
if (target_speed == v3f(0))
|
||||||
d_wanted = -m_speed*.5/slippery;
|
d_wanted = -m_speed * 5 / slippery;
|
||||||
else
|
else
|
||||||
d_wanted = target_speed*.1 - m_speed*.1;
|
d_wanted = target_speed * .1 - m_speed * .1;
|
||||||
}
|
}
|
||||||
d_wanted.Y = 0;
|
d_wanted.Y = 0;
|
||||||
f32 dl = d_wanted.getLength();
|
f32 dl = d_wanted.getLength();
|
||||||
|
|
|
@ -352,6 +352,7 @@ public:
|
||||||
float physics_override_speed;
|
float physics_override_speed;
|
||||||
float physics_override_jump;
|
float physics_override_jump;
|
||||||
float physics_override_gravity;
|
float physics_override_gravity;
|
||||||
|
float physics_override_slip;
|
||||||
bool physics_override_sneak;
|
bool physics_override_sneak;
|
||||||
bool physics_override_sneak_glitch;
|
bool physics_override_sneak_glitch;
|
||||||
|
|
||||||
|
|
|
@ -401,7 +401,7 @@ int ObjectRef::l_get_armor_groups(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set_physics_override(self, physics_override_speed, physics_override_jump,
|
// set_physics_override(self, physics_override_speed, physics_override_jump,
|
||||||
// physics_override_gravity, sneak, sneak_glitch)
|
// physics_override_gravity, physics_override_slip, sneak, sneak_glitch)
|
||||||
int ObjectRef::l_set_physics_override(lua_State *L)
|
int ObjectRef::l_set_physics_override(lua_State *L)
|
||||||
{
|
{
|
||||||
NO_MAP_LOCK_REQUIRED;
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
@ -413,6 +413,7 @@ int ObjectRef::l_set_physics_override(lua_State *L)
|
||||||
co->m_physics_override_speed = getfloatfield_default(L, 2, "speed", co->m_physics_override_speed);
|
co->m_physics_override_speed = getfloatfield_default(L, 2, "speed", co->m_physics_override_speed);
|
||||||
co->m_physics_override_jump = getfloatfield_default(L, 2, "jump", co->m_physics_override_jump);
|
co->m_physics_override_jump = getfloatfield_default(L, 2, "jump", co->m_physics_override_jump);
|
||||||
co->m_physics_override_gravity = getfloatfield_default(L, 2, "gravity", co->m_physics_override_gravity);
|
co->m_physics_override_gravity = getfloatfield_default(L, 2, "gravity", co->m_physics_override_gravity);
|
||||||
|
co->m_physics_override_slip = getfloatfield_default(L, 2, "slip", co->m_physics_override_slip);
|
||||||
co->m_physics_override_sneak = getboolfield_default(L, 2, "sneak", co->m_physics_override_sneak);
|
co->m_physics_override_sneak = getboolfield_default(L, 2, "sneak", co->m_physics_override_sneak);
|
||||||
co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
|
co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
|
||||||
co->m_physics_override_sent = false;
|
co->m_physics_override_sent = false;
|
||||||
|
@ -450,6 +451,8 @@ int ObjectRef::l_get_physics_override(lua_State *L)
|
||||||
lua_setfield(L, -2, "jump");
|
lua_setfield(L, -2, "jump");
|
||||||
lua_pushnumber(L, co->m_physics_override_gravity);
|
lua_pushnumber(L, co->m_physics_override_gravity);
|
||||||
lua_setfield(L, -2, "gravity");
|
lua_setfield(L, -2, "gravity");
|
||||||
|
lua_pushnumber(L, co->m_physics_override_slip);
|
||||||
|
lua_setfield(L, -2, "slip");
|
||||||
lua_pushboolean(L, co->m_physics_override_sneak);
|
lua_pushboolean(L, co->m_physics_override_sneak);
|
||||||
lua_setfield(L, -2, "sneak");
|
lua_setfield(L, -2, "sneak");
|
||||||
lua_pushboolean(L, co->m_physics_override_sneak_glitch);
|
lua_pushboolean(L, co->m_physics_override_sneak_glitch);
|
||||||
|
|
|
@ -105,7 +105,7 @@ private:
|
||||||
static int l_get_armor_groups(lua_State *L);
|
static int l_get_armor_groups(lua_State *L);
|
||||||
|
|
||||||
// set_physics_override(self, physics_override_speed, physics_override_jump,
|
// set_physics_override(self, physics_override_speed, physics_override_jump,
|
||||||
// physics_override_gravity, sneak, sneak_glitch)
|
// physics_override_gravity, physics_override_slip, sneak, sneak_glitch)
|
||||||
static int l_set_physics_override(lua_State *L);
|
static int l_set_physics_override(lua_State *L);
|
||||||
|
|
||||||
// get_physics_override(self)
|
// get_physics_override(self)
|
||||||
|
|
|
@ -149,7 +149,7 @@ public:
|
||||||
{}
|
{}
|
||||||
virtual ItemGroupList getArmorGroups()
|
virtual ItemGroupList getArmorGroups()
|
||||||
{ return ItemGroupList(); }
|
{ return ItemGroupList(); }
|
||||||
virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity)
|
virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity, float physics_override_slip)
|
||||||
{}
|
{}
|
||||||
virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
|
virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
|
||||||
{}
|
{}
|
||||||
|
|
Loading…
Reference in New Issue