diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 0f5abd684..12691c241 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -88,7 +88,8 @@ set(SERVER Script/Functions/Chat.cpp Script/Functions/Dialogue.cpp Script/Functions/Factions.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/Mechanics.cpp Script/Functions/Positions.cpp Script/Functions/Quests.cpp Script/Functions/Settings.cpp - Script/Functions/Spells.cpp Script/Functions/Stats.cpp Script/Functions/Timer.cpp + Script/Functions/Shapeshift.cpp Script/Functions/Spells.cpp Script/Functions/Stats.cpp + Script/Functions/Timer.cpp Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp ${PawnScript_Sources} diff --git a/apps/openmw-mp/Script/Functions/Mechanics.cpp b/apps/openmw-mp/Script/Functions/Mechanics.cpp index 4197300c0..f8d63be84 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.cpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.cpp @@ -76,38 +76,6 @@ const char *MechanicsFunctions::GetSelectedSpellId(unsigned short pid) noexcept return player->selectedSpellId.c_str(); } -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; - GET_PLAYER(pid, player, 0); - - return player->isWerewolf; -} - -const char *MechanicsFunctions::GetCreatureRefId(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->creatureRefId.c_str(); -} - -bool MechanicsFunctions::GetCreatureNameDisplayState(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->displayCreatureName; -} - void MechanicsFunctions::SetMarkCell(unsigned short pid, const char *cellDescription) noexcept { Player *player; @@ -143,38 +111,6 @@ void MechanicsFunctions::SetSelectedSpellId(unsigned short pid, const char *spel player->selectedSpellId = spellId; } -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, ); - - player->isWerewolf = isWerewolf; -} - -void MechanicsFunctions::SetCreatureRefId(unsigned short pid, const char *refId) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->creatureRefId = refId; -} - -void MechanicsFunctions::SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->displayCreatureName = displayState; -} - void MechanicsFunctions::SendMarkLocation(unsigned short pid) { Player *player; @@ -197,16 +133,6 @@ void MechanicsFunctions::SendSelectedSpell(unsigned short pid) mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->Send(false); } -void MechanicsFunctions::SendShapeshift(unsigned short pid) -{ - Player *player; - GET_PLAYER(pid, player, ); - - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(true); -} - void MechanicsFunctions::Jail(unsigned short pid, int jailDays, bool ignoreJailTeleportation, bool ignoreJailSkillIncreases, const char* jailProgressText, const char* jailEndText) noexcept { diff --git a/apps/openmw-mp/Script/Functions/Mechanics.hpp b/apps/openmw-mp/Script/Functions/Mechanics.hpp index cd067a0b7..737c03750 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.hpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.hpp @@ -14,24 +14,13 @@ {"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\ {"GetSelectedSpellId", MechanicsFunctions::GetSelectedSpellId},\ \ - {"GetScale", MechanicsFunctions::GetScale},\ - {"IsWerewolf", MechanicsFunctions::IsWerewolf},\ - {"GetCreatureRefId", MechanicsFunctions::GetCreatureRefId},\ - {"GetCreatureNameDisplayState", MechanicsFunctions::GetCreatureNameDisplayState},\ - \ {"SetMarkCell", MechanicsFunctions::SetMarkCell},\ {"SetMarkPos", MechanicsFunctions::SetMarkPos},\ {"SetMarkRot", MechanicsFunctions::SetMarkRot},\ {"SetSelectedSpellId", MechanicsFunctions::SetSelectedSpellId},\ \ - {"SetScale", MechanicsFunctions::SetScale},\ - {"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\ - {"SetCreatureRefId", MechanicsFunctions::SetCreatureRefId},\ - {"SetCreatureNameDisplayState", MechanicsFunctions::SetCreatureNameDisplayState},\ - \ {"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\ {"SendSelectedSpell", MechanicsFunctions::SendSelectedSpell},\ - {"SendShapeshift", MechanicsFunctions::SendShapeshift},\ \ {"Jail", MechanicsFunctions::Jail},\ {"Resurrect", MechanicsFunctions::Resurrect} @@ -104,43 +93,6 @@ public: */ static const char *GetSelectedSpellId(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. - * - * This is based on the last PlayerShapeshift packet received or sent for that player. - * - * \param pid The player ID. - * \return The werewolf state. - */ - static bool IsWerewolf(unsigned short pid) noexcept; - - /** - * \brief Get the refId of the creature the player is disguised as. - * - * \param pid The player ID. - * \return The creature refId. - */ - static const char *GetCreatureRefId(unsigned short pid) noexcept; - - /** - * \brief Check whether a player's name is replaced by that of the creature they are - * disguised as when other players hover over them. - * - * This is based on the last PlayerShapeshift packet received or sent for that player. - * - * \param pid The player ID. - * \return The creature name display state. - */ - static bool GetCreatureNameDisplayState(unsigned short pid) noexcept; - /** * \brief Set the Mark cell of a player. * @@ -195,54 +147,6 @@ public: */ static void SetSelectedSpellId(unsigned short pid, const char *spellId) 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 scale The new scale. - * \return void - */ - static void SetScale(unsigned short pid, double scale) noexcept; - - /** - * \brief Set the werewolf state of a player. - * - * This changes the werewolf state recorded for that player in the server memory, but - * does not by itself send a packet. - * - * \param pid The player ID. - * \param isWerewolf The new werewolf state. - * \return void - */ - static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept; - - /** - * \brief Set the refId of the creature a player is disguised as. - * - * This changes the creature refId recorded for that player in the server memory, but - * does not by itself send a packet. - * - * \param pid The player ID. - * \param refId The creature refId. - * \param displaysCreatureName Whether the player's name appears as that of the creature - * when hovered over by others. - * \return void - */ - static void SetCreatureRefId(unsigned short pid, const char *refId) noexcept; - - /** - * \brief Set whether a player's name is replaced by that of the creature they are - * disguised as when other players hover over them. - * - * \param pid The player ID. - * \param displayState The creature name display state. - * \return void - */ - static void SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept; - /** * \brief Send a PlayerMiscellaneous packet with a Mark location to a player. * @@ -259,17 +163,6 @@ public: */ static void SendSelectedSpell(unsigned short pid); - /** - * \brief Send a PlayerShapeshift packet about a player. - * - * This sends the packet to all players connected to the server. It is currently used - * only to communicate werewolf states. - * - * \param pid The player ID. - * \return void - */ - static void SendShapeshift(unsigned short pid); - /** * \brief Send a PlayerJail packet about a player. * diff --git a/apps/openmw-mp/Script/Functions/Shapeshift.cpp b/apps/openmw-mp/Script/Functions/Shapeshift.cpp new file mode 100644 index 000000000..2ac33c701 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Shapeshift.cpp @@ -0,0 +1,84 @@ +#include "Shapeshift.hpp" + +#include +#include + +#include +#include + +#include +using namespace std; + +double ShapeshiftFunctions::GetScale(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.0f); + + return player->scale; +} + +bool ShapeshiftFunctions::IsWerewolf(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->isWerewolf; +} + +const char *ShapeshiftFunctions::GetCreatureRefId(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->creatureRefId.c_str(); +} + +bool ShapeshiftFunctions::GetCreatureNameDisplayState(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->displayCreatureName; +} + +void ShapeshiftFunctions::SetScale(unsigned short pid, double scale) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->scale = scale; +} + +void ShapeshiftFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->isWerewolf = isWerewolf; +} + +void ShapeshiftFunctions::SetCreatureRefId(unsigned short pid, const char *refId) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->creatureRefId = refId; +} + +void ShapeshiftFunctions::SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->displayCreatureName = displayState; +} + +void ShapeshiftFunctions::SendShapeshift(unsigned short pid) +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(false); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(true); +} diff --git a/apps/openmw-mp/Script/Functions/Shapeshift.hpp b/apps/openmw-mp/Script/Functions/Shapeshift.hpp new file mode 100644 index 000000000..4d211185e --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Shapeshift.hpp @@ -0,0 +1,120 @@ +#ifndef OPENMW_SHAPESHIFTAPI_HPP +#define OPENMW_SHAPESHIFTAPI_HPP + +#include "../Types.hpp" + +#define SHAPESHIFTAPI \ + {"GetScale", ShapeshiftFunctions::GetScale},\ + {"IsWerewolf", ShapeshiftFunctions::IsWerewolf},\ + {"GetCreatureRefId", ShapeshiftFunctions::GetCreatureRefId},\ + {"GetCreatureNameDisplayState", ShapeshiftFunctions::GetCreatureNameDisplayState},\ + \ + {"SetScale", ShapeshiftFunctions::SetScale},\ + {"SetWerewolfState", ShapeshiftFunctions::SetWerewolfState},\ + {"SetCreatureRefId", ShapeshiftFunctions::SetCreatureRefId},\ + {"SetCreatureNameDisplayState", ShapeshiftFunctions::SetCreatureNameDisplayState},\ + \ + {"SendShapeshift", ShapeshiftFunctions::SendShapeshift} + +class ShapeshiftFunctions +{ +public: + + /** + * \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. + * + * This is based on the last PlayerShapeshift packet received or sent for that player. + * + * \param pid The player ID. + * \return The werewolf state. + */ + static bool IsWerewolf(unsigned short pid) noexcept; + + /** + * \brief Get the refId of the creature the player is disguised as. + * + * \param pid The player ID. + * \return The creature refId. + */ + static const char *GetCreatureRefId(unsigned short pid) noexcept; + + /** + * \brief Check whether a player's name is replaced by that of the creature they are + * disguised as when other players hover over them. + * + * This is based on the last PlayerShapeshift packet received or sent for that player. + * + * \param pid The player ID. + * \return The creature name display state. + */ + static bool GetCreatureNameDisplayState(unsigned short pid) 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 scale The new scale. + * \return void + */ + static void SetScale(unsigned short pid, double scale) noexcept; + + /** + * \brief Set the werewolf state of a player. + * + * This changes the werewolf state recorded for that player in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param isWerewolf The new werewolf state. + * \return void + */ + static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept; + + /** + * \brief Set the refId of the creature a player is disguised as. + * + * This changes the creature refId recorded for that player in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param refId The creature refId. + * \param displaysCreatureName Whether the player's name appears as that of the creature + * when hovered over by others. + * \return void + */ + static void SetCreatureRefId(unsigned short pid, const char *refId) noexcept; + + /** + * \brief Set whether a player's name is replaced by that of the creature they are + * disguised as when other players hover over them. + * + * \param pid The player ID. + * \param displayState The creature name display state. + * \return void + */ + static void SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept; + + /** + * \brief Send a PlayerShapeshift packet about a player. + * + * This sends the packet to all players connected to the server. It is currently used + * only to communicate werewolf states. + * + * \param pid The player ID. + * \return void + */ + static void SendShapeshift(unsigned short pid); +}; + +#endif //OPENMW_SHAPESHIFTAPI_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index caaf3d593..af3ac8b75 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -17,6 +17,7 @@ #include