forked from mirror/openmw-tes3mp
[Server] Add and use Utils::getCellFromDescription()
This commit is contained in:
parent
cc3dfd7da0
commit
9c5eb47e90
4 changed files with 51 additions and 53 deletions
|
@ -1,10 +1,11 @@
|
|||
#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/BaseActor.hpp>
|
||||
|
||||
#include <apps/openmw-mp/Networking.hpp>
|
||||
#include <apps/openmw-mp/Player.hpp>
|
||||
#include <apps/openmw-mp/Utils.hpp>
|
||||
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
||||
|
||||
#include "Actors.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
@ -86,26 +87,7 @@ double ActorFunctions::GetActorRotZ(unsigned int i) noexcept
|
|||
|
||||
void ActorFunctions::SetScriptActorListCell(const char* cellDescription) noexcept
|
||||
{
|
||||
static std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$");
|
||||
std::string description = cellDescription;
|
||||
std::smatch baseMatch;
|
||||
|
||||
if (std::regex_match(description, baseMatch, exteriorCellPattern))
|
||||
{
|
||||
scriptActorList.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)
|
||||
{
|
||||
scriptActorList.cell.mData.mX = stoi(baseMatch[1].str());
|
||||
scriptActorList.cell.mData.mY = stoi(baseMatch[2].str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scriptActorList.cell.mData.mFlags |= ESM::Cell::Interior;
|
||||
scriptActorList.cell.mName = description;
|
||||
}
|
||||
scriptActorList.cell = Utils::getCellFromDescription(cellDescription);
|
||||
}
|
||||
|
||||
void ActorFunctions::SetScriptActorListAction(unsigned char action) noexcept
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#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/BaseEvent.hpp>
|
||||
|
||||
#include <apps/openmw-mp/Networking.hpp>
|
||||
#include <apps/openmw-mp/Player.hpp>
|
||||
#include <apps/openmw-mp/Utils.hpp>
|
||||
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
||||
|
||||
#include "World.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
@ -143,26 +144,7 @@ int WorldFunctions::GetContainerItemActionCount(unsigned int objectIndex, unsign
|
|||
|
||||
void WorldFunctions::SetScriptEventCell(const char* cellDescription) noexcept
|
||||
{
|
||||
static std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$");
|
||||
std::string description = cellDescription;
|
||||
std::smatch baseMatch;
|
||||
|
||||
if (std::regex_match(description, baseMatch, exteriorCellPattern))
|
||||
{
|
||||
scriptEvent.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)
|
||||
{
|
||||
scriptEvent.cell.mData.mX = stoi(baseMatch[1].str());
|
||||
scriptEvent.cell.mData.mY = stoi(baseMatch[2].str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scriptEvent.cell.mData.mFlags |= ESM::Cell::Interior;
|
||||
scriptEvent.cell.mName = description;
|
||||
}
|
||||
scriptEvent.cell = Utils::getCellFromDescription(cellDescription);
|
||||
}
|
||||
|
||||
void WorldFunctions::SetScriptEventAction(unsigned char action) noexcept
|
||||
|
|
|
@ -23,4 +23,32 @@ const vector<string> Utils::split(const string &str, int delimiter)
|
|||
result.push_back(move(buffer));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
ESM::Cell Utils::getCellFromDescription(std::string cellDescription)
|
||||
{
|
||||
ESM::Cell cell;
|
||||
cell.blank();
|
||||
|
||||
static std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$");
|
||||
std::smatch baseMatch;
|
||||
|
||||
if (std::regex_match(cellDescription, baseMatch, exteriorCellPattern))
|
||||
{
|
||||
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)
|
||||
{
|
||||
cell.mData.mX = stoi(baseMatch[1].str());
|
||||
cell.mData.mY = stoi(baseMatch[2].str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.mData.mFlags |= ESM::Cell::Interior;
|
||||
cell.mName = cellDescription;
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
|
|
@ -5,10 +5,14 @@
|
|||
#ifndef OPENMW_UTILS_HPP
|
||||
#define OPENMW_UTILS_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <regex>
|
||||
#include <vector>
|
||||
|
||||
#include <components/esm/loadcell.hpp>
|
||||
|
||||
#include <components/openmw-mp/Utils.hpp>
|
||||
#include <components/openmw-mp/Log.hpp>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#if (!defined(DEBUG_PRINTF) && defined(DEBUG))
|
||||
#define DEBUG_PRINTF(...) LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, __VA_ARGS__)
|
||||
|
@ -21,6 +25,8 @@ namespace Utils
|
|||
{
|
||||
const std::vector<std::string> split(const std::string &str, int delimiter);
|
||||
|
||||
ESM::Cell getCellFromDescription(std::string cellDescription);
|
||||
|
||||
template<size_t N>
|
||||
constexpr unsigned int hash(const char(&str)[N], size_t I = N)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue