diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index a4f385595..53dca6a78 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -10,6 +10,16 @@ #include +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include +/* + End of tes3mp addition +*/ + #include #include "../mwworld/ptr.hpp" @@ -175,6 +185,19 @@ namespace MWBase virtual void getDoorMarkers (MWWorld::CellStore* cell, std::vector& out) = 0; ///< get a list of teleport door markers for a given cell, to be displayed on the local map + /* + Start of tes3mp addition + + Make it possible to check whether global variables exist and to create + new ones + */ + virtual bool hasGlobal(const std::string& name) = 0; + + virtual void createGlobal(const std::string& name, ESM::VarType varType) = 0; + /* + End of tes3mp addition + */ + virtual void setGlobalInt (const std::string& name, int value) = 0; ///< Set value independently from real type. diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp index 7b3c0f0d0..2a0ac3cc1 100644 --- a/apps/openmw/mwmp/Worldstate.cpp +++ b/apps/openmw/mwmp/Worldstate.cpp @@ -381,10 +381,27 @@ void Worldstate::setClientGlobals() debugMessage += clientGlobal.id + ": " + variableTypeAsString + " " + valueAsString; } + MWBase::World* world = MWBase::Environment::get().getWorld(); + + // If this global doesn't exist, create it + if (!world->hasGlobal(clientGlobal.id)) + { + ESM::VarType varType; + + if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT) + varType = ESM::VarType::VT_Short; + else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG) + varType = ESM::VarType::VT_Long; + if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT) + varType = ESM::VarType::VT_Float; + + world->createGlobal(clientGlobal.id, varType); + } + if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG) - MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.intValue); + world->setGlobalInt(clientGlobal.id, clientGlobal.intValue); else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT) - MWBase::Environment::get().getWorld()->setGlobalFloat(clientGlobal.id, clientGlobal.floatValue); + world->setGlobalFloat(clientGlobal.id, clientGlobal.floatValue); } LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str()); diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index 8a481334e..b840e1e11 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -105,4 +105,30 @@ namespace MWWorld return false; } + + /* + Start of tes3mp addition + + Make it possible to add a global record from elsewhere + */ + void Globals::addRecord(const ESM::Global global) + { + mVariables.insert(std::make_pair(Misc::StringUtils::lowerCase(global.mId), global)); + } + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Make it possible to check whether a global exists + */ + bool Globals::hasRecord(const std::string& name) + { + return (mVariables.find(name) != mVariables.end()); + } + /* + End of tes3mp addition + */ } diff --git a/apps/openmw/mwworld/globals.hpp b/apps/openmw/mwworld/globals.hpp index 3468c2e71..11793a9eb 100644 --- a/apps/openmw/mwworld/globals.hpp +++ b/apps/openmw/mwworld/globals.hpp @@ -57,6 +57,26 @@ namespace MWWorld ///< Records for variables that do not exist are dropped silently. /// /// \return Known type? + + /* + Start of tes3mp addition + + Make it possible to add a global record from elsewhere + */ + void addRecord(const ESM::Global global); + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Make it possible to check whether a global exists + */ + bool hasRecord(const std::string& name); + /* + End of tes3mp addition + */ }; } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 99b3147f0..33efeec9e 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -658,6 +658,28 @@ namespace MWWorld return mWorldScene->hasCellChanged(); } + /* + Start of tes3mp addition + + Make it possible to check whether global variables exist and to create + new ones + */ + bool World::hasGlobal(const std::string& name) + { + return mGlobalVariables.hasRecord(name); + } + + void World::createGlobal(const std::string& name, ESM::VarType varType) + { + ESM::Global global; + global.mId = name; + global.mValue.setType(varType); + mGlobalVariables.addRecord(global); + } + /* + End of tes3mp addition + */ + void World::setGlobalInt (const std::string& name, int value) { bool dateUpdated = mCurrentDate->updateGlobalInt(name, value); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 60a9e9d79..68137303b 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -281,6 +281,19 @@ namespace MWWorld void getDoorMarkers (MWWorld::CellStore* cell, std::vector& out) override; ///< get a list of teleport door markers for a given cell, to be displayed on the local map + /* + Start of tes3mp addition + + Make it possible to check whether global variables exist and to create + new ones + */ + bool hasGlobal(const std::string& name); + + void createGlobal(const std::string& name, ESM::VarType varType); + /* + End of tes3mp addition + */ + void setGlobalInt (const std::string& name, int value) override; ///< Set value independently from real type.