From 029dfc56ba7dcc0ada82a99e457ab5fe2f30fc74 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 1 Feb 2018 02:11:45 +0200 Subject: [PATCH] [General] Implement player scale as part of PlayerShapeshift --- apps/openmw-mp/Player.cpp | 1 + apps/openmw-mp/Script/Functions/Mechanics.cpp | 18 +++++++++++- apps/openmw-mp/Script/Functions/Mechanics.hpp | 24 +++++++++++++++- apps/openmw/mwmp/DedicatedPlayer.cpp | 1 + apps/openmw/mwmp/LocalPlayer.cpp | 15 +++++++++- apps/openmw/mwmp/LocalPlayer.hpp | 3 +- apps/openmw/mwscript/statsextensions.cpp | 2 +- .../mwscript/transformationextensions.cpp | 28 +++++++++++++------ components/openmw-mp/Base/BasePlayer.hpp | 1 + .../Packets/Player/PacketPlayerShapeshift.cpp | 1 + 10 files changed, 81 insertions(+), 13 deletions(-) diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 4bdf0f6c9..4dea0b4a6 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -34,6 +34,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid) players[guid]->npcStats.blank(); players[guid]->creatureStats.blank(); players[guid]->charClass.blank(); + players[guid]->scale = 1; players[guid]->isWerewolf = false; for (unsigned int i = 0; i < mwmp::Networking::get().maxConnections(); i++) diff --git a/apps/openmw-mp/Script/Functions/Mechanics.cpp b/apps/openmw-mp/Script/Functions/Mechanics.cpp index 127efe473..b1a3ce413 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.cpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.cpp @@ -68,6 +68,14 @@ double MechanicsFunctions::GetMarkRotZ(unsigned short pid) noexcept return player->markPosition.rot[2]; } +double MechanicsFunctions::GetScale(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.0f); + + return player->scale; +} + bool MechanicsFunctions::IsWerewolf(unsigned short pid) noexcept { Player *player; @@ -103,7 +111,15 @@ void MechanicsFunctions::SetMarkRot(unsigned short pid, double x, double z) noex player->markPosition.rot[2] = z; } -void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) +void MechanicsFunctions::SetScale(unsigned short pid, double scale) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->scale = scale; +} + +void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept { Player *player; GET_PLAYER(pid, player, ); diff --git a/apps/openmw-mp/Script/Functions/Mechanics.hpp b/apps/openmw-mp/Script/Functions/Mechanics.hpp index d2c4f0ee0..7db879f0f 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.hpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.hpp @@ -13,12 +13,14 @@ {"GetMarkRotX", MechanicsFunctions::GetMarkRotX},\ {"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\ \ + {"GetScale", MechanicsFunctions::GetScale},\ {"IsWerewolf", MechanicsFunctions::IsWerewolf},\ \ {"SetMarkCell", MechanicsFunctions::SetMarkCell},\ {"SetMarkPos", MechanicsFunctions::SetMarkPos},\ {"SetMarkRot", MechanicsFunctions::SetMarkRot},\ \ + {"SetScale", MechanicsFunctions::SetScale},\ {"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\ \ {"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\ @@ -87,6 +89,14 @@ public: */ static double GetMarkRotZ(unsigned short pid) noexcept; + /** + * \brief Get the scale of a player. + * + * \param pid The player ID. + * \return The scale. + */ + static double GetScale(unsigned short pid) noexcept; + /** * \brief Check whether a player is a werewolf. * @@ -139,6 +149,18 @@ public: */ static void SetMarkRot(unsigned short pid, double x, double z) noexcept; + /** + * \brief Set the scale of a player. + * + * This changes the scale recorded for that player in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param bool The new scale. + * \return void + */ + static void SetScale(unsigned short pid, double scale) noexcept; + /** * \brief Set the werewolf state of a player. * @@ -149,7 +171,7 @@ public: * \param bool The new werewolf state. * \return void */ - static void SetWerewolfState(unsigned short pid, bool isWerewolf); + static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept; /** * \brief Send a PlayerMiscellaneous packet with a Mark location to a player. diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index d4fddab80..1333f5b1d 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -243,6 +243,7 @@ void DedicatedPlayer::setCell() void DedicatedPlayer::setShapeshift() { + MWBase::Environment::get().getWorld()->scaleObject(ptr, scale); MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptr, isWerewolf); } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 781c8d7dd..4eb824bde 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -64,6 +64,7 @@ LocalPlayer::LocalPlayer() jailProgressText = ""; jailEndText = ""; + scale = 1; isWerewolf = false; diedSinceArrestAttempt = false; @@ -1266,6 +1267,8 @@ void LocalPlayer::setMapExplored() void LocalPlayer::setShapeshift() { MWWorld::Ptr ptrPlayer = getPlayerPtr(); + + MWBase::Environment::get().getWorld()->scaleObject(ptrPlayer, scale); MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptrPlayer, isWerewolf); } @@ -1553,7 +1556,17 @@ void LocalPlayer::sendBook(const std::string& bookId) getNetworking()->getPlayerPacket(ID_PLAYER_BOOK)->Send(); } -void LocalPlayer::sendShapeshift(bool werewolfState) +void LocalPlayer::sendScale(float newScale) +{ + scale = newScale; + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_SHAPESHIFT with scale of %f", scale); + + getNetworking()->getPlayerPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(this); + getNetworking()->getPlayerPacket(ID_PLAYER_SHAPESHIFT)->Send(); +} + +void LocalPlayer::sendWerewolfState(bool werewolfState) { isWerewolf = werewolfState; diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 7f92de89b..5efe3ffb5 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -89,7 +89,8 @@ namespace mwmp void sendTopic(const std::string& topic); void sendKill(const std::string& refId, int number); void sendBook(const std::string& bookId); - void sendShapeshift(bool isWerewolf); + void sendScale(float newScale); + void sendWerewolfState(bool isWerewolf); void sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition); void clearCellStates(); diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 17ae6b304..c3618aa9e 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -1231,7 +1231,7 @@ namespace MWScript When the player's werewolf state changes, send an ID_PLAYER_SHAPESHIFT packet */ if (ptr == MWMechanics::getPlayer()) - mwmp::Main::get().getLocalPlayer()->sendShapeshift(set); + mwmp::Main::get().getLocalPlayer()->sendWerewolfState(set); /* End of tes3mp addition */ diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index ea0531fea..874cbe1b7 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -8,6 +8,8 @@ #include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" +#include "../mwmp/LocalPlayer.hpp" +#include "../mwmp/PlayerList.hpp" #include "../mwmp/WorldEvent.hpp" /* End of tes3mp addition @@ -57,16 +59,26 @@ namespace MWScript /* Start of tes3mp addition - Send an ID_OBJECT_SCALE every time an object's scale is changed - through a script + Send an ID_PLAYER_SHAPESHIFT every time a player changes + their own scale + + Otherwise, send an ID_OBJECT_SCALE every time an object's + scale is changed through a script */ - if (ptr.isInCell() && (ptr.getCellRef().getScale() != scale)) + if (ptr == MWMechanics::getPlayer()) + mwmp::Main::get().getLocalPlayer()->sendScale(scale); + else if (ptr.isInCell() && (ptr.getCellRef().getScale() != scale)) { - - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); - worldEvent->reset(); - worldEvent->addObjectScale(ptr, scale); - worldEvent->sendObjectScale(); + // Ignore attempts to change another player's scale + if (mwmp::PlayerList::isDedicatedPlayer(ptr)) + return; + else + { + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); + worldEvent->reset(); + worldEvent->addObjectScale(ptr, scale); + worldEvent->sendObjectScale(); + } } /* End of tes3mp addition diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 15939ee00..2865a22f6 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -283,6 +283,7 @@ namespace mwmp std::string sound; Animation animation; + float scale; bool isWerewolf; std::string creatureModel; bool useCreatureName; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp index 1e6c06a70..352342ccd 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp @@ -12,5 +12,6 @@ void PacketPlayerShapeshift::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + RW(player->scale, send); RW(player->isWerewolf, send); }