From 099f85be0a31fc80d0ff9d8d3b121177de93d6d3 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 29 Apr 2018 23:47:17 +0300 Subject: [PATCH] [General] Implement PlayerMomentum packet & associated script functions --- apps/openmw-mp/Script/Functions/Positions.cpp | 19 +++++++++++++ apps/openmw-mp/Script/Functions/Positions.hpp | 28 ++++++++++++++++++- apps/openmw/mwmp/LocalPlayer.cpp | 7 +++++ apps/openmw/mwmp/LocalPlayer.hpp | 1 + .../player/ProcessorPlayerMomentum.hpp | 2 +- components/openmw-mp/Base/BasePlayer.hpp | 1 + .../Packets/Player/PacketPlayerMomentum.cpp | 3 +- 7 files changed, 58 insertions(+), 3 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Positions.cpp b/apps/openmw-mp/Script/Functions/Positions.cpp index 11c5d4f40..58a569bc1 100644 --- a/apps/openmw-mp/Script/Functions/Positions.cpp +++ b/apps/openmw-mp/Script/Functions/Positions.cpp @@ -118,6 +118,16 @@ void PositionFunctions::SetRot(unsigned short pid, double x, double z) noexcept player->position.rot[2] = z; } +void PositionFunctions::SetMomentum(unsigned short pid, double x, double y, double z) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->momentum.pos[0] = x; + player->momentum.pos[1] = y; + player->momentum.pos[2] = z; +} + void PositionFunctions::SendPos(unsigned short pid) noexcept { Player *player; @@ -126,3 +136,12 @@ void PositionFunctions::SendPos(unsigned short pid) noexcept mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->Send(false); } + +void PositionFunctions::SendMomentum(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MOMENTUM)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MOMENTUM)->Send(false); +} diff --git a/apps/openmw-mp/Script/Functions/Positions.hpp b/apps/openmw-mp/Script/Functions/Positions.hpp index 49cb9f863..071dd6ee4 100644 --- a/apps/openmw-mp/Script/Functions/Positions.hpp +++ b/apps/openmw-mp/Script/Functions/Positions.hpp @@ -19,8 +19,10 @@ \ {"SetPos", PositionFunctions::SetPos},\ {"SetRot", PositionFunctions::SetRot},\ + {"SetMomentum", PositionFunctions::SetMomentum},\ \ - {"SendPos", PositionFunctions::SendPos} + {"SendPos", PositionFunctions::SendPos},\ + {"SendMomentum", PositionFunctions::SendMomentum} class PositionFunctions @@ -144,6 +146,20 @@ public: */ static void SetRot(unsigned short pid, double x, double z) noexcept; + /** + * \brief Set the momentum of a player. + * + * This changes the coordinates recorded for that player's momentum in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param x The X momentum. + * \param y The Y momentum. + * \param z The Z momentum. + * \return void + */ + static void SetMomentum(unsigned short pid, double x, double y, double z) noexcept; + /** * \brief Send a PlayerPosition packet about a player. * @@ -153,6 +169,16 @@ public: * \return void */ static void SendPos(unsigned short pid) noexcept; + + /** + * \brief Send a PlayerMomentum packet about a player. + * + * It is only sent to the affected player. + * + * \param pid The player ID. + * \return void + */ + static void SendMomentum(unsigned short pid) noexcept; }; #endif //OPENMW_POSITIONAPI_HPP diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 1e07fc203..8d329e1b6 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1002,6 +1002,13 @@ void LocalPlayer::setPosition() updateAnimFlags(true); } +void LocalPlayer::setMomentum() +{ + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); + world->setInertialForce(ptrPlayer, momentum.asVec3()); +} + void LocalPlayer::setCell() { MWBase::World *world = MWBase::Environment::get().getWorld(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 0c25f374e..741c9279f 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -54,6 +54,7 @@ namespace mwmp void setBounty(); void setReputation(); void setPosition(); + void setMomentum(); void setCell(); void setClass(); void setEquipment(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerMomentum.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerMomentum.hpp index 6d1aa4820..87e1a9d2a 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerMomentum.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerMomentum.hpp @@ -23,7 +23,7 @@ namespace mwmp if (!isRequest()) { LocalPlayer &localPlayer = static_cast(*player); - //localPlayer.setMomentum(); + localPlayer.setMomentum(); } } }; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 65aebb05e..9484ff9f0 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -294,6 +294,7 @@ namespace mwmp ESM::Position position; ESM::Position direction; ESM::Position previousCellPosition; + ESM::Position momentum; ESM::Cell cell; ESM::NPC npc; ESM::NpcStats npcStats; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerMomentum.cpp b/components/openmw-mp/Packets/Player/PacketPlayerMomentum.cpp index ceaebc0be..00eb49e9d 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerMomentum.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerMomentum.cpp @@ -12,5 +12,6 @@ PacketPlayerMomentum::PacketPlayerMomentum(RakNet::RakPeerInterface *peer) : Pla void PacketPlayerMomentum::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - // Placeholder + + RW(player->momentum.pos, send, 1); }