[Server] Move script functions for cells to a new CellFunctions class

coverity_scan^2
David Cernat 8 years ago
parent 5a22032a41
commit 0cc20d26ce

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

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

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

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

@ -7,6 +7,7 @@
#include <Script/Functions/CharClass.hpp>
#include <Script/Functions/Positions.hpp>
#include <Script/Functions/Cells.hpp>
#include <Script/Functions/GUI.hpp>
#include <Script/Functions/Stats.hpp>
#include <Script/Functions/Items.hpp>
@ -89,6 +90,7 @@ public:
{"SetHostname", ScriptFunctions::SetHostname},
POSITIONAPI,
CELLAPI,
STATSFUNCTIONS,
ITEMAPI,
QUESTAPI,

Loading…
Cancel
Save