From 69bf2749a5eabf2be67beba4f7bc795e36efa21e Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 10 Apr 2017 06:15:03 +0300 Subject: [PATCH] [Server] Add ActorFunctions for getting and setting basic actor data --- apps/openmw-mp/Script/Functions/Actors.cpp | 79 +++++++++++++++++++++- apps/openmw-mp/Script/Functions/Actors.hpp | 38 +++++++++-- apps/openmw-mp/Script/Functions/World.cpp | 3 +- 3 files changed, 110 insertions(+), 10 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 8833a8cb8..225592ea9 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -10,9 +10,11 @@ using namespace mwmp; BaseActorList scriptActorList; -BaseActor tempActor; -void ActorFunctions::InitActorList(unsigned short pid) noexcept +BaseActor tempActor; +const BaseActor emptyActor = {}; + +void ActorFunctions::InitScriptActorList(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -24,7 +26,78 @@ void ActorFunctions::InitActorList(unsigned short pid) noexcept unsigned int ActorFunctions::GetActorListSize() noexcept { - return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.count; + return mwmp::Networking::getPtr()->getLastActorList()->count; +} + +unsigned char ActorFunctions::GetLastActorListAction() noexcept +{ + return mwmp::Networking::getPtr()->getLastActorList()->action; +} + +const char *ActorFunctions::GetActorRefId(unsigned int i) noexcept +{ + return mwmp::Networking::getPtr()->getLastActorList()->baseActors.at(i).refId.c_str(); +} + +int ActorFunctions::GetActorRefNumIndex(unsigned int i) noexcept +{ + return mwmp::Networking::getPtr()->getLastActorList()->baseActors.at(i).refNumIndex; +} + +int ActorFunctions::GetActorMpNum(unsigned int i) noexcept +{ + return mwmp::Networking::getPtr()->getLastActorList()->baseActors.at(i).mpNum; +} + +void ActorFunctions::SetScriptActorListCell(const char* cellDescription) noexcept +{ + static std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$"); + std::string description = cellDescription; + std::smatch baseMatch; + + if (std::regex_match(description, baseMatch, exteriorCellPattern)) + { + scriptActorList.cell.mData.mFlags &= ~ESM::Cell::Interior; + + // The first sub match is the whole string, so check for a length of 3 + if (baseMatch.size() == 3) + { + scriptActorList.cell.mData.mX = stoi(baseMatch[1].str()); + scriptActorList.cell.mData.mY = stoi(baseMatch[2].str()); + } + } + else + { + scriptActorList.cell.mData.mFlags |= ESM::Cell::Interior; + scriptActorList.cell.mName = description; + } +} + +void ActorFunctions::SetScriptActorListAction(unsigned char action) noexcept +{ + scriptActorList.action = action; +} + +void ActorFunctions::SetActorRefId(const char* refId) noexcept +{ + tempActor.refId = refId; +} + +void ActorFunctions::SetActorRefNumIndex(int refNumIndex) noexcept +{ + tempActor.refNumIndex = refNumIndex; +} + +void ActorFunctions::SetActorMpNum(int mpNum) noexcept +{ + tempActor.mpNum = mpNum; +} + +void ActorFunctions::AddActor() noexcept +{ + scriptActorList.baseActors.push_back(tempActor); + + tempActor = emptyActor; } void ActorFunctions::SendActorList() noexcept diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index e0f1833a3..151e1e9fd 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -2,20 +2,48 @@ #define OPENMW_ACTORAPI_HPP #define ACTORAPI \ - {"InitActorList", ActorFunctions::InitActorList},\ + {"InitScriptActorList", ActorFunctions::InitScriptActorList},\ \ - {"GetActorListSize", ActorFunctions::GetActorListSize},\ + {"GetActorListSize", ActorFunctions::GetActorListSize},\ + {"GetLastActorListAction", ActorFunctions::GetLastActorListAction},\ \ - {"SendActorList", ActorFunctions::SendActorList},\ - {"SendActorAuthority", ActorFunctions::SendActorAuthority}\ + {"GetActorRefId", ActorFunctions::GetActorRefId},\ + {"GetActorRefNumIndex", ActorFunctions::GetActorRefNumIndex},\ + {"GetActorMpNum", ActorFunctions::GetActorMpNum},\ + \ + {"SetScriptActorListCell", ActorFunctions::SetScriptActorListCell},\ + {"SetScriptActorListAction", ActorFunctions::SetScriptActorListAction},\ + \ + {"SetActorRefId", ActorFunctions::SetActorRefId},\ + {"SetActorRefNumIndex", ActorFunctions::SetActorRefNumIndex},\ + {"SetActorMpNum", ActorFunctions::SetActorMpNum},\ + \ + {"AddActor", ActorFunctions::AddActor},\ + \ + {"SendActorList", ActorFunctions::SendActorList},\ + {"SendActorAuthority", ActorFunctions::SendActorAuthority} class ActorFunctions { public: - static void InitActorList(unsigned short pid) noexcept; + static void InitScriptActorList(unsigned short pid) noexcept; static unsigned int GetActorListSize() noexcept; + static unsigned char GetLastActorListAction() noexcept; + + static const char *GetActorRefId(unsigned int i) noexcept; + static int GetActorRefNumIndex(unsigned int i) noexcept; + static int GetActorMpNum(unsigned int i) noexcept; + + static void SetScriptActorListCell(const char* cellDescription) noexcept; + static void SetScriptActorListAction(unsigned char action) noexcept; + + static void SetActorRefId(const char* refId) noexcept; + static void SetActorRefNumIndex(int refNumIndex) noexcept; + static void SetActorMpNum(int mpNum) noexcept; + + static void AddActor() noexcept; static void SendActorList() noexcept; static void SendActorAuthority() noexcept; diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index ccae84ff2..886b95431 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -17,8 +17,6 @@ const WorldObject emptyWorldObject = {}; ContainerItem tempContainerItem; const ContainerItem emptyContainerItem = {}; -std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$"); - void WorldFunctions::InitScriptEvent(unsigned short pid) noexcept { Player *player; @@ -145,6 +143,7 @@ int WorldFunctions::GetContainerItemActionCount(unsigned int objectIndex, unsign void WorldFunctions::SetScriptEventCell(const char* cellDescription) noexcept { + static std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$"); std::string description = cellDescription; std::smatch baseMatch;