diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 7def88ce9..11863815f 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -75,7 +75,7 @@ set(SERVER Script/Functions/CharClass.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/Quests.cpp Script/Functions/Stats.cpp Script/Functions/Spells.cpp Script/Functions/Timer.cpp Script/Functions/Positions.cpp - Script/Functions/World.cpp + Script/Functions/Cells.cpp Script/Functions/World.cpp Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp ${PawnScript_Sources} diff --git a/apps/openmw-mp/Script/Functions/Cells.cpp b/apps/openmw-mp/Script/Functions/Cells.cpp new file mode 100644 index 000000000..68e0fb3e5 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Cells.cpp @@ -0,0 +1,88 @@ +#include "Cells.hpp" +#include +#include +#include +#include +#include + +#include +using namespace std; + +const char* CellFunctions::GetCell(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->cell.mName.c_str(); +} + +void CellFunctions::SetCell(unsigned short pid, const char *name) noexcept +{ + Player *player; + GET_PLAYER(pid, player,); + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %s", + player->npc.mName.c_str(), + player->cell.getDescription().c_str(), + name); + + // If the player is currently in an exterior, turn on the interior flag + // from the cell so the player doesn't get teleported to their exterior + // grid position (which we haven't changed) + if (player->cell.isExterior()) { + player->cell.mData.mFlags |= ESM::Cell::Interior; + } + + player->cell.mName = name; +} + +void CellFunctions::SetExterior(unsigned short pid, int x, int y) noexcept +{ + Player *player; + GET_PLAYER(pid, player,); + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %i,%i", + player->npc.mName.c_str(), + player->cell.getDescription().c_str(), + x, + y); + + // If the player is currently in an interior, turn off the interior flag + // from the cell + if (!player->cell.isExterior()) { + player->cell.mData.mFlags &= ~ESM::Cell::Interior; + } + + player->cell.mData.mX = x; + player->cell.mData.mY = y; +} + +int CellFunctions::GetExteriorX(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player,0); + return player->cell.mData.mX; +} + +int CellFunctions::GetExteriorY(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player,0); + return player->cell.mData.mY; +} + +bool CellFunctions::IsInExterior(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, false); + + return player->cell.isExterior(); +} + +void CellFunctions::SendCell(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::Networking::get().getPlayerController()->GetPacket(ID_PLAYER_CELL_CHANGE)->Send(player, false); +} diff --git a/apps/openmw-mp/Script/Functions/Cells.hpp b/apps/openmw-mp/Script/Functions/Cells.hpp new file mode 100644 index 000000000..6c8489869 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Cells.hpp @@ -0,0 +1,30 @@ +#ifndef OPENMW_CELLAPI_HPP +#define OPENMW_CELLAPI_HPP + +#include "../Types.hpp" + +#define POSITIONAPI \ + {"GetCell", CellFunctions::GetCell},\ + {"SetCell", CellFunctions::SetCell},\ + {"SetExterior", CellFunctions::SetExterior},\ + {"GetExteriorX", CellFunctions::GetExteriorX},\ + {"GetExteriorY", CellFunctions::GetExteriorY},\ + {"IsInExterior", CellFunctions::IsInExterior},\ +\ + {"SendCell", CellFunctions::SendCell} + + +class CellFunctions +{ +public: + static const char *GetCell(unsigned short pid) noexcept; + static void SetCell(unsigned short pid, const char *name) noexcept; + static void SetExterior(unsigned short pid, int x, int y) noexcept; + static int GetExteriorX(unsigned short pid) noexcept; + static int GetExteriorY(unsigned short pid) noexcept; + static bool IsInExterior(unsigned short pid) noexcept; + + static void SendCell(unsigned short pid) noexcept; +}; + +#endif //OPENMW_CELLAPI_HPP diff --git a/apps/openmw-mp/Script/Functions/Positions.cpp b/apps/openmw-mp/Script/Functions/Positions.cpp index 55c83a0a0..eb14451fd 100644 --- a/apps/openmw-mp/Script/Functions/Positions.cpp +++ b/apps/openmw-mp/Script/Functions/Positions.cpp @@ -104,77 +104,6 @@ void PositionFunctions::SetAngle(unsigned short pid, double x, double y, double player->position.rot[2] = z; } -const char* PositionFunctions::GetCell(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->cell.mName.c_str(); -} - -void PositionFunctions::SetCell(unsigned short pid, const char *name) noexcept -{ - Player *player; - GET_PLAYER(pid, player,); - - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %s", - player->npc.mName.c_str(), - player->cell.getDescription().c_str(), - name); - - // If the player is currently in an exterior, turn on the interior flag - // from the cell so the player doesn't get teleported to their exterior - // grid position (which we haven't changed) - if (player->cell.isExterior()) { - player->cell.mData.mFlags |= ESM::Cell::Interior; - } - - player->cell.mName = name; -} - -void PositionFunctions::SetExterior(unsigned short pid, int x, int y) noexcept -{ - Player *player; - GET_PLAYER(pid, player,); - - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %i,%i", - player->npc.mName.c_str(), - player->cell.getDescription().c_str(), - x, - y); - - // If the player is currently in an interior, turn off the interior flag - // from the cell - if (!player->cell.isExterior()) { - player->cell.mData.mFlags &= ~ESM::Cell::Interior; - } - - player->cell.mData.mX = x; - player->cell.mData.mY = y; -} - -int PositionFunctions::GetExteriorX(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player,0); - return player->cell.mData.mX; -} - -int PositionFunctions::GetExteriorY(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player,0); - return player->cell.mData.mY; -} - -bool PositionFunctions::IsInExterior(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, false); - - return player->cell.isExterior(); -} - void PositionFunctions::SendPos(unsigned short pid) noexcept { Player *player; @@ -182,11 +111,3 @@ void PositionFunctions::SendPos(unsigned short pid) noexcept mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_POS)->Send(player, false); } - -void PositionFunctions::SendCell(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - mwmp::Networking::get().getPlayerController()->GetPacket(ID_PLAYER_CELL_CHANGE)->Send(player, false); -} diff --git a/apps/openmw-mp/Script/Functions/Positions.hpp b/apps/openmw-mp/Script/Functions/Positions.hpp index 68bf7358f..06a322534 100644 --- a/apps/openmw-mp/Script/Functions/Positions.hpp +++ b/apps/openmw-mp/Script/Functions/Positions.hpp @@ -17,15 +17,7 @@ {"SetPos", PositionFunctions::SetPos},\ {"SetAngle", PositionFunctions::SetAngle},\ \ - {"GetCell", PositionFunctions::GetCell},\ - {"SetCell", PositionFunctions::SetCell},\ - {"SetExterior", PositionFunctions::SetExterior},\ - {"GetExteriorX", PositionFunctions::GetExteriorX},\ - {"GetExteriorY", PositionFunctions::GetExteriorY},\ - {"IsInExterior", PositionFunctions::IsInExterior},\ -\ - {"SendPos", PositionFunctions::SendPos},\ - {"SendCell", PositionFunctions::SendCell} + {"SendPos", PositionFunctions::SendPos} class PositionFunctions @@ -44,15 +36,7 @@ public: static void SetPos(unsigned short pid, double x, double y, double z) noexcept; static void SetAngle(unsigned short pid, double x, double y, double z) noexcept; - static const char *GetCell(unsigned short pid) noexcept; - static void SetCell(unsigned short pid, const char *name) noexcept; - static void SetExterior(unsigned short pid, int x, int y) noexcept; - static int GetExteriorX(unsigned short pid) noexcept; - static int GetExteriorY(unsigned short pid) noexcept; - static bool IsInExterior(unsigned short pid) noexcept; - static void SendPos(unsigned short pid) noexcept; - static void SendCell(unsigned short pid) noexcept; }; #endif //OPENMW_POSITIONAPI_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 4352f640d..511a1b079 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -7,6 +7,7 @@ #include