forked from mirror/openmw-tes3mp
[Server] Move script functions for cells to a new CellFunctions class
parent
5a22032a41
commit
0cc20d26ce
@ -0,0 +1,88 @@
|
||||
#include "Cells.hpp"
|
||||
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <apps/openmw-mp/Player.hpp>
|
||||
#include <apps/openmw-mp/Networking.hpp>
|
||||
#include <components/openmw-mp/Log.hpp>
|
||||
|
||||
#include <iostream>
|
||||
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);
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue