2017-01-28 14:22:30 +00:00
|
|
|
#include <regex>
|
2016-08-30 05:24:31 +00:00
|
|
|
|
|
|
|
#include <apps/openmw-mp/Player.hpp>
|
|
|
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
|
|
|
#include <apps/openmw-mp/Networking.hpp>
|
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
2017-01-28 14:22:30 +00:00
|
|
|
#include <components/openmw-mp/Base/WorldEvent.hpp>
|
2016-08-30 05:24:31 +00:00
|
|
|
#include "World.hpp"
|
|
|
|
|
2017-01-28 14:22:30 +00:00
|
|
|
using namespace mwmp;
|
|
|
|
|
|
|
|
static WorldEvent *worldEvent;
|
|
|
|
|
|
|
|
std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$");
|
|
|
|
|
|
|
|
void WorldFunctions::CreateWorldEvent(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
worldEvent = new WorldEvent(player->guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldFunctions::AddWorldObject() noexcept
|
|
|
|
{
|
|
|
|
WorldObject worldObject;
|
|
|
|
|
|
|
|
worldEvent->objectChanges.objects.push_back(worldObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldFunctions::SetWorldEventCell(const char* cellDescription) noexcept
|
|
|
|
{
|
|
|
|
std::string description = cellDescription;
|
|
|
|
std::smatch baseMatch;
|
|
|
|
|
|
|
|
if (std::regex_match(description, baseMatch, exteriorCellPattern))
|
|
|
|
{
|
|
|
|
worldEvent->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) {
|
|
|
|
|
|
|
|
worldEvent->cell.mData.mX = stoi(baseMatch[1].str());
|
|
|
|
worldEvent->cell.mData.mY = stoi(baseMatch[2].str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
worldEvent->cell.mData.mFlags |= ESM::Cell::Interior;
|
|
|
|
worldEvent->cell.mName = description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldFunctions::SetObjectRefId(unsigned int i, const char* refId) noexcept
|
|
|
|
{
|
|
|
|
worldEvent->objectChanges.objects[i].refId = refId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldFunctions::SetObjectRefNumIndex(unsigned int i, int refNumIndex) noexcept
|
|
|
|
{
|
|
|
|
worldEvent->objectChanges.objects[i].refNumIndex = refNumIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldFunctions::SetObjectPosition(unsigned int i, double x, double y, double z) noexcept
|
|
|
|
{
|
|
|
|
worldEvent->objectChanges.objects[i].pos.pos[0] = x;
|
|
|
|
worldEvent->objectChanges.objects[i].pos.pos[1] = y;
|
|
|
|
worldEvent->objectChanges.objects[i].pos.pos[2] = z;
|
|
|
|
}
|
|
|
|
|
2017-01-29 11:21:41 +00:00
|
|
|
unsigned int WorldFunctions::GetObjectChangesSize() noexcept
|
|
|
|
{
|
|
|
|
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *WorldFunctions::GetObjectRefId(unsigned int i) noexcept
|
|
|
|
{
|
|
|
|
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects[i].refId.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
int WorldFunctions::GetObjectRefNumIndex(unsigned int i) noexcept
|
|
|
|
{
|
|
|
|
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects[i].refNumIndex;
|
|
|
|
}
|
|
|
|
|
2017-01-28 14:22:30 +00:00
|
|
|
void WorldFunctions::SendObjectDelete() noexcept
|
|
|
|
{
|
|
|
|
mwmp::Networking::get().getWorldController()->GetPacket(ID_OBJECT_DELETE)->Send(worldEvent, worldEvent->guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldFunctions::SendObjectPlace() noexcept
|
|
|
|
{
|
|
|
|
mwmp::Networking::get().getWorldController()->GetPacket(ID_OBJECT_PLACE)->Send(worldEvent, worldEvent->guid);
|
|
|
|
}
|
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept
|
2016-08-30 05:24:31 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
|
|
|
player->hour = hour;
|
|
|
|
player->month = -1;
|
|
|
|
player->day = -1;
|
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false);
|
2016-08-30 05:24:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
void WorldFunctions::SetMonth(unsigned short pid, int month) noexcept
|
2016-08-30 05:24:31 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
|
|
|
player->hour = -1;
|
|
|
|
player->month = month;
|
|
|
|
player->day = -1;
|
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false);
|
2016-08-30 05:24:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
void WorldFunctions::SetDay(unsigned short pid, int day) noexcept
|
2016-08-30 05:24:31 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
|
|
|
player->hour = -1;
|
|
|
|
player->month = -1;
|
|
|
|
player->day = day;
|
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false);
|
2016-08-30 05:24:31 +00:00
|
|
|
}
|