diff options
author | MirceaKitsune <sonichedgehog_hyperblast00@yahoo.com> | 2013-04-05 01:03:28 -1000 |
---|---|---|
committer | PilzAdam <pilzadam@minetest.net> | 2013-04-05 02:00:59 +0200 |
commit | c5a8448c41e4ea9d33a43cebef61425d4568a46d (patch) | |
tree | bd612dd0d2b8e7589f14a2c403b423480af5798d | |
parent | 2a0badf2d565ce4bebe2910c88795c0fe51a0341 (diff) | |
download | minetest-c5a8448c41e4ea9d33a43cebef61425d4568a46d.tar.gz minetest-c5a8448c41e4ea9d33a43cebef61425d4568a46d.tar.bz2 minetest-c5a8448c41e4ea9d33a43cebef61425d4568a46d.zip |
Allow modifying movement speed, jump height and gravity per-player via the Lua API.
-rw-r--r-- | doc/lua_api.txt | 4 | ||||
-rw-r--r-- | src/clientserver.h | 4 | ||||
-rw-r--r-- | src/content_cao.cpp | 13 | ||||
-rw-r--r-- | src/content_sao.cpp | 17 | ||||
-rw-r--r-- | src/content_sao.h | 9 | ||||
-rw-r--r-- | src/environment.cpp | 2 | ||||
-rw-r--r-- | src/genericobject.cpp | 12 | ||||
-rw-r--r-- | src/genericobject.h | 3 | ||||
-rw-r--r-- | src/localplayer.cpp | 6 | ||||
-rw-r--r-- | src/player.cpp | 5 | ||||
-rw-r--r-- | src/player.h | 4 | ||||
-rw-r--r-- | src/scriptapi_object.cpp | 23 | ||||
-rw-r--r-- | src/scriptapi_object.h | 3 | ||||
-rw-r--r-- | src/serverobject.h | 2 |
14 files changed, 97 insertions, 10 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 029c84d03..a61ffce64 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1348,6 +1348,10 @@ 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) + 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. InvRef: Reference to an inventory methods: diff --git a/src/clientserver.h b/src/clientserver.h index 28b579971..8b1e0a7e4 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -88,9 +88,11 @@ SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed); PROTOCOL_VERSION 18: damageGroups added to ToolCapabilities sound_place added to ItemDefinition + PROTOCOL_VERSION 19: + GENERIC_CMD_SET_PHYSICS_OVERRIDE */ -#define LATEST_PROTOCOL_VERSION 18 +#define LATEST_PROTOCOL_VERSION 19 // Server's supported network protocol range #define SERVER_PROTOCOL_VERSION_MIN 13 diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 84fc0bf79..0a1a92271 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -1679,6 +1679,19 @@ public: updateTexturePos(); } + else if(cmd == GENERIC_CMD_SET_PHYSICS_OVERRIDE) + { + float override_speed = readF1000(is); + float override_jump = readF1000(is); + float override_gravity = readF1000(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; + } + } else if(cmd == GENERIC_CMD_SET_ANIMATION) { m_animation_range = readV2F1000(is); diff --git a/src/content_sao.cpp b/src/content_sao.cpp index ae08b4260..e6c8c725c 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -935,7 +935,11 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_, m_moved(false), m_inventory_not_sent(false), m_hp_not_sent(false), - m_wielded_item_not_sent(false) + m_wielded_item_not_sent(false), + m_physics_override_speed(1), + m_physics_override_jump(1), + m_physics_override_gravity(1), + m_physics_override_sent(false) { assert(m_player); assert(m_peer_id != 0); @@ -1019,7 +1023,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) writeF1000(os, m_player->getYaw()); writeS16(os, getHP()); - writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here + writeU8(os, 5 + m_bone_position.size()); // number of messages stuffed in here os<<serializeLongString(getPropertyPacket()); // message 1 os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3 @@ -1027,6 +1031,7 @@ 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 } else { @@ -1196,6 +1201,14 @@ void PlayerSAO::step(float dtime, bool send_recommended) m_messages_out.push_back(aom); } + 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); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push_back(aom); + } + if(m_animation_sent == false){ m_animation_sent = true; std::string str = gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend); diff --git a/src/content_sao.h b/src/content_sao.h index 60ca8f319..dca02bb00 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -101,7 +101,7 @@ private: float m_last_sent_position_timer; float m_last_sent_move_precision; bool m_armor_groups_sent; - + v2f m_animation_range; float m_animation_speed; float m_animation_blend; @@ -257,8 +257,6 @@ private: ItemGroupList m_armor_groups; bool m_armor_groups_sent; - - bool m_properties_sent; struct ObjectProperties m_prop; // Cached privileges for enforcement @@ -285,6 +283,11 @@ public: bool m_inventory_not_sent; bool m_hp_not_sent; bool m_wielded_item_not_sent; + + float m_physics_override_speed; + float m_physics_override_jump; + float m_physics_override_gravity; + bool m_physics_override_sent; }; #endif diff --git a/src/environment.cpp b/src/environment.cpp index 07cdb24d1..385e5b955 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2057,7 +2057,7 @@ void ClientEnvironment::step(float dtime) // Gravity v3f speed = lplayer->getSpeed(); if(lplayer->in_liquid == false) - speed.Y -= lplayer->movement_gravity * dtime_part * 2; + speed.Y -= lplayer->movement_gravity * lplayer->physics_override_gravity * dtime_part * 2; // Liquid floating / sinking if(lplayer->in_liquid && !lplayer->swimming_vertical) diff --git a/src/genericobject.cpp b/src/genericobject.cpp index f7b272b00..e2fbde838 100644 --- a/src/genericobject.cpp +++ b/src/genericobject.cpp @@ -117,6 +117,18 @@ 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::ostringstream os(std::ios::binary); + // command + writeU8(os, GENERIC_CMD_SET_PHYSICS_OVERRIDE); + // parameters + writeF1000(os, physics_override_speed); + writeF1000(os, physics_override_jump); + writeF1000(os, physics_override_gravity); + return os.str(); +} + std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend) { std::ostringstream os(std::ios::binary); diff --git a/src/genericobject.h b/src/genericobject.h index 9a21baa67..276865ab9 100644 --- a/src/genericobject.h +++ b/src/genericobject.h @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define GENERIC_CMD_SET_ANIMATION 6 #define GENERIC_CMD_SET_BONE_POSITION 7 #define GENERIC_CMD_SET_ATTACHMENT 8 +#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9 #include "object_properties.h" std::string gob_cmd_set_properties(const ObjectProperties &prop); @@ -62,6 +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_animation(v2f frames, float frame_speed, float frame_blend); std::string gob_cmd_update_bone_position(std::string bone, v3f position, v3f rotation); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index a90ae6967..b69bdb24f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -529,7 +529,7 @@ void LocalPlayer::applyControl(float dtime) v3f speedJ = getSpeed(); if(speedJ.Y >= -0.5 * BS) { - speedJ.Y = movement_speed_jump; + speedJ.Y = movement_speed_jump * physics_override_jump; setSpeed(speedJ); MtEvent *e = new SimpleTriggerEvent("PlayerJump"); @@ -584,8 +584,8 @@ void LocalPlayer::applyControl(float dtime) incH = incV = movement_acceleration_default * BS * dtime; // Accelerate to target speed with maximum increment - accelerateHorizontal(speedH, incH); - accelerateVertical(speedV, incV); + accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed); + accelerateVertical(speedV * physics_override_speed, incV * physics_override_speed); } v3s16 LocalPlayer::getStandingNodePos() diff --git a/src/player.cpp b/src/player.cpp index 4c81887be..1ca9423b0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -71,6 +71,11 @@ Player::Player(IGameDef *gamedef): movement_liquid_fluidity_smooth = 0.5 * BS; movement_liquid_sink = 10 * BS; 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; } Player::~Player() diff --git a/src/player.h b/src/player.h index 496c99532..d95e535ff 100644 --- a/src/player.h +++ b/src/player.h @@ -222,6 +222,10 @@ public: f32 movement_liquid_sink; f32 movement_gravity; + float physics_override_speed; + float physics_override_jump; + float physics_override_gravity; + u16 hp; float hurt_tilt_timer; diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index a0f93cbba..05433a598 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -297,6 +297,28 @@ int ObjectRef::l_set_armor_groups(lua_State *L) return 0; } +// set_physics_override(self, physics_override_speed, physics_override_jump, physics_override_gravity) +int ObjectRef::l_set_physics_override(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + PlayerSAO *co = (PlayerSAO *) getobject(ref); + if(co == NULL) return 0; + // Do it + if(!lua_isnil(L, 2)){ + co->m_physics_override_speed = lua_tonumber(L, 2); + co->m_physics_override_sent = false; + } + if(!lua_isnil(L, 3)){ + co->m_physics_override_jump = lua_tonumber(L, 3); + co->m_physics_override_sent = false; + } + if(!lua_isnil(L, 4)){ + co->m_physics_override_gravity = lua_tonumber(L, 4); + co->m_physics_override_sent = false; + } + return 0; +} + // set_animation(self, frame_range, frame_speed, frame_blend) int ObjectRef::l_set_animation(lua_State *L) { @@ -756,6 +778,7 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, get_wielded_item), luamethod(ObjectRef, set_wielded_item), luamethod(ObjectRef, set_armor_groups), + luamethod(ObjectRef, set_physics_override), luamethod(ObjectRef, set_animation), luamethod(ObjectRef, set_bone_position), luamethod(ObjectRef, set_attach), diff --git a/src/scriptapi_object.h b/src/scriptapi_object.h index a37abbb78..a44016933 100644 --- a/src/scriptapi_object.h +++ b/src/scriptapi_object.h @@ -103,6 +103,9 @@ 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) + static int l_set_physics_override(lua_State *L); + // set_animation(self, frame_range, frame_speed, frame_blend) static int l_set_animation(lua_State *L); diff --git a/src/serverobject.h b/src/serverobject.h index 7a5b47bd1..13a075a25 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -152,6 +152,8 @@ public: virtual void setArmorGroups(const ItemGroupList &armor_groups) {} + virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity) + {} virtual void setAnimation(v2f frames, float frame_speed, float frame_blend) {} virtual void setBonePosition(std::string bone, v3f position, v3f rotation) |