[Server] Add script functions for dealing w/ WorldEvents & WorldObjects

pull/163/head
David Cernat 8 years ago
parent 9f1e491a75
commit f11df211fa

@ -1,13 +1,83 @@
//
// Created by koncord on 30.08.16.
//
#include <regex>
#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>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "World.hpp"
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;
}
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);
}
void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept
{
Player *player;

@ -1,11 +1,19 @@
//
// Created by koncord on 30.08.16.
//
#ifndef OPENMW_WORLD_HPP
#define OPENMW_WORLD_HPP
#define WORLDFUNCTIONS \
{"CreateWorldEvent", WorldFunctions::CreateWorldEvent},\
\
{"AddWorldObject", WorldFunctions::AddWorldObject},\
{"SetWorldEventCell", WorldFunctions::SetWorldEventCell},\
\
{"SetObjectRefId", WorldFunctions::SetObjectRefId},\
{"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\
{"SetObjectPosition", WorldFunctions::SetObjectPosition},\
\
{"SendObjectDelete", WorldFunctions::SendObjectDelete},\
{"SendObjectPlace", WorldFunctions::SendObjectPlace},\
\
{"SetHour", WorldFunctions::SetHour},\
{"SetMonth", WorldFunctions::SetMonth},\
{"SetDay", WorldFunctions::SetDay}
@ -13,6 +21,19 @@
class WorldFunctions
{
public:
static void CreateWorldEvent(unsigned short pid) noexcept;
static void AddWorldObject() noexcept;
static void SetWorldEventCell(const char* cellDescription) noexcept;
static void SetObjectRefId(unsigned int i, const char* refId) noexcept;
static void SetObjectRefNumIndex(unsigned int i, int refNumIndex) noexcept;
static void SetObjectPosition(unsigned int i, double x, double y, double z) noexcept;
static void SendObjectDelete() noexcept;
static void SendObjectPlace() noexcept;
static void SetHour(unsigned short pid, double hour) noexcept;
static void SetMonth(unsigned short pid, int month) noexcept;
static void SetDay(unsigned short pid, int day) noexcept;

Loading…
Cancel
Save