[Server] Add and use Utils::getCellFromDescription()

0.6.1
David Cernat 8 years ago
parent cc3dfd7da0
commit 9c5eb47e90

@ -1,10 +1,11 @@
#include <regex> #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/Player.hpp>
#include <apps/openmw-mp/Utils.hpp>
#include <apps/openmw-mp/Script/ScriptFunctions.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 "Actors.hpp" #include "Actors.hpp"
using namespace mwmp; using namespace mwmp;
@ -86,26 +87,7 @@ double ActorFunctions::GetActorRotZ(unsigned int i) noexcept
void ActorFunctions::SetScriptActorListCell(const char* cellDescription) noexcept void ActorFunctions::SetScriptActorListCell(const char* cellDescription) noexcept
{ {
static std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$"); scriptActorList.cell = Utils::getCellFromDescription(cellDescription);
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;
}
} }
void ActorFunctions::SetScriptActorListAction(unsigned char action) noexcept void ActorFunctions::SetScriptActorListAction(unsigned char action) noexcept

@ -1,10 +1,11 @@
#include <regex> #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/Player.hpp>
#include <apps/openmw-mp/Utils.hpp>
#include <apps/openmw-mp/Script/ScriptFunctions.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 "World.hpp" #include "World.hpp"
using namespace mwmp; using namespace mwmp;
@ -143,26 +144,7 @@ int WorldFunctions::GetContainerItemActionCount(unsigned int objectIndex, unsign
void WorldFunctions::SetScriptEventCell(const char* cellDescription) noexcept void WorldFunctions::SetScriptEventCell(const char* cellDescription) noexcept
{ {
static std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$"); scriptEvent.cell = Utils::getCellFromDescription(cellDescription);
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;
}
} }
void WorldFunctions::SetScriptEventAction(unsigned char action) noexcept 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)); result.push_back(move(buffer));
return result; 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,11 +5,15 @@
#ifndef OPENMW_UTILS_HPP #ifndef OPENMW_UTILS_HPP
#define OPENMW_UTILS_HPP #define OPENMW_UTILS_HPP
#include <components/openmw-mp/Utils.hpp>
#include <components/openmw-mp/Log.hpp>
#include <cstddef> #include <cstddef>
#include <regex>
#include <vector> #include <vector>
#include <components/esm/loadcell.hpp>
#include <components/openmw-mp/Utils.hpp>
#include <components/openmw-mp/Log.hpp>
#if (!defined(DEBUG_PRINTF) && defined(DEBUG)) #if (!defined(DEBUG_PRINTF) && defined(DEBUG))
#define DEBUG_PRINTF(...) LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, __VA_ARGS__) #define DEBUG_PRINTF(...) LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, __VA_ARGS__)
#else #else
@ -21,6 +25,8 @@ namespace Utils
{ {
const std::vector<std::string> split(const std::string &str, int delimiter); const std::vector<std::string> split(const std::string &str, int delimiter);
ESM::Cell getCellFromDescription(std::string cellDescription);
template<size_t N> template<size_t N>
constexpr unsigned int hash(const char(&str)[N], size_t I = N) constexpr unsigned int hash(const char(&str)[N], size_t I = N)
{ {

Loading…
Cancel
Save