2016-01-12 03:41:44 +00:00
|
|
|
//
|
|
|
|
// Created by koncord on 29.02.16.
|
|
|
|
//
|
2016-08-30 04:19:49 +00:00
|
|
|
#include "Translocations.hpp"
|
2016-01-12 03:41:44 +00:00
|
|
|
#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>
|
2016-09-27 08:28:44 +00:00
|
|
|
#include <components/openmw-mp/Log.hpp>
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::getPos(unsigned short pid, float *x, float *y, float *z) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
*x = 0.00;
|
|
|
|
*y = 0.00;
|
|
|
|
*z = 0.00;
|
|
|
|
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
|
|
|
*x = player->Position()->pos[0];
|
|
|
|
*y = player->Position()->pos[1];
|
|
|
|
*z = player->Position()->pos[2];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
double TranslocationFunctions::getPosX(unsigned short pid) noexcept
|
2016-07-16 08:19:35 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->Position()->pos[0];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
double TranslocationFunctions::getPosY(unsigned short pid) noexcept
|
2016-07-16 08:19:35 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->Position()->pos[1];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
double TranslocationFunctions::getPosZ(unsigned short pid) noexcept
|
2016-07-16 08:19:35 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->Position()->pos[2];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::getAngle(unsigned short pid, float *x, float *y, float *z) noexcept
|
2016-11-12 19:01:38 +00:00
|
|
|
{
|
|
|
|
*x = 0.00;
|
|
|
|
*y = 0.00;
|
|
|
|
*z = 0.00;
|
|
|
|
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
*x = player->Position()->rot[0];
|
|
|
|
*y = player->Position()->rot[1];
|
|
|
|
*z = player->Position()->rot[2];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
double TranslocationFunctions::getAngleX(unsigned short pid) noexcept
|
2016-11-12 19:01:38 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->Position()->rot[0];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
double TranslocationFunctions::getAngleY(unsigned short pid) noexcept
|
2016-11-12 19:01:38 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->Position()->rot[1];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
double TranslocationFunctions::getAngleZ(unsigned short pid) noexcept
|
2016-11-12 19:01:38 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->Position()->rot[2];
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::setPos(unsigned short pid, double x, double y, double z) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
|
|
|
player->Position()->pos[0] = x;
|
|
|
|
player->Position()->pos[1] = y;
|
|
|
|
player->Position()->pos[2] = z;
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::setAngle(unsigned short pid, double x, double y, double z) noexcept
|
2016-11-12 19:01:38 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->Position()->rot[0] = x;
|
|
|
|
player->Position()->rot[1] = y;
|
|
|
|
player->Position()->rot[2] = z;
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
const char* TranslocationFunctions::getCell(unsigned short pid) noexcept
|
2016-11-12 19:01:38 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
return player->GetCell()->mName.c_str();
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::setCell(unsigned short pid, const char *name) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
2016-09-27 08:28:44 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %s",
|
|
|
|
player->Npc()->mName.c_str(),
|
|
|
|
player->GetCell()->getDescription().c_str(),
|
|
|
|
name);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-27 08:28:44 +00:00
|
|
|
// 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->GetCell()->isExterior()) {
|
|
|
|
player->GetCell()->mData.mFlags |= ESM::Cell::Interior;
|
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
player->GetCell()->mName = name;
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::setExterior(unsigned short pid, int x, int y) noexcept
|
2016-07-29 17:33:28 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
2016-09-27 08:28:44 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %i,%i",
|
|
|
|
player->Npc()->mName.c_str(),
|
|
|
|
player->GetCell()->getDescription().c_str(),
|
|
|
|
x,
|
|
|
|
y);
|
|
|
|
|
|
|
|
// If the player is currently in an interior, turn off the interior flag
|
|
|
|
// from the cell
|
|
|
|
if (!player->GetCell()->isExterior()) {
|
|
|
|
player->GetCell()->mData.mFlags &= ~ESM::Cell::Interior;
|
|
|
|
}
|
2016-07-29 17:33:28 +00:00
|
|
|
|
2016-10-23 13:55:30 +00:00
|
|
|
player->GetCell()->mData.mX = x;
|
|
|
|
player->GetCell()->mData.mY = y;
|
2016-07-29 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
int TranslocationFunctions::getExteriorX(unsigned short pid) noexcept
|
2016-07-29 17:33:28 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,0);
|
2016-10-23 13:55:30 +00:00
|
|
|
return player->GetCell()->mData.mX;
|
2016-07-29 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
int TranslocationFunctions::getExteriorY(unsigned short pid) noexcept
|
2016-07-29 17:33:28 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,0);
|
2016-10-23 13:55:30 +00:00
|
|
|
return player->GetCell()->mData.mY;
|
2016-07-29 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
bool TranslocationFunctions::isInExterior(unsigned short pid) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, false);
|
|
|
|
|
2016-09-27 08:28:44 +00:00
|
|
|
return player->GetCell()->isExterior();
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::sendPos(unsigned short pid) noexcept
|
2016-11-12 19:16:05 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_POS)->Send(player, false);
|
2016-11-12 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 14:52:16 +00:00
|
|
|
void TranslocationFunctions::sendCell(unsigned short pid) noexcept
|
2016-11-12 19:27:09 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_CELL)->Send(player, false);
|
2016-11-12 19:27:09 +00:00
|
|
|
}
|
|
|
|
|