[Server] Add ActorFunctions for getting and setting basic actor data

This commit is contained in:
David Cernat 2017-04-10 06:15:03 +03:00
parent e9c3abc2c3
commit 69bf2749a5
3 changed files with 110 additions and 10 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;