diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index dcbe1ef42..ec7289d63 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -215,11 +215,11 @@ void WorldstateFunctions::AddKill(const char* refId, int number) noexcept writeWorldstate.killChanges.push_back(kill); } -void WorldstateFunctions::AddClientGlobalInteger(const char* id, int intValue) noexcept +void WorldstateFunctions::AddClientGlobalInteger(const char* id, int intValue, unsigned int variableType) noexcept { mwmp::ClientVariable clientVariable; clientVariable.id = id; - clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER; + clientVariable.variableType = variableType; clientVariable.intValue = intValue; writeWorldstate.clientGlobals.push_back(clientVariable); diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index 601e6d12b..1d828eeb3 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -419,10 +419,11 @@ public: * \brief Add a new client global integer to the client globals. * * \param id The id of the client global. + * \param variableType The variable type (0 for SHORT, 1 for LONG). * \param intValue The integer value of the client global. * \return void */ - static void AddClientGlobalInteger(const char* id, int intValue) noexcept; + static void AddClientGlobalInteger(const char* id, int intValue, unsigned int variableType = 0) noexcept; /** * \brief Add a new client global float to the client globals. diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp index 9b1f2235d..d1333e771 100644 --- a/apps/openmw/mwmp/ObjectList.cpp +++ b/apps/openmw/mwmp/ObjectList.cpp @@ -867,21 +867,21 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore) for (const auto &baseObject : baseObjects) { std::string valueAsString; - std::string variableType; + std::string variableTypeAsString; - if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::INTEGER) + if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT) { valueAsString = std::to_string(baseObject.clientVariable.intValue); - variableType = "integer"; + variableTypeAsString = "short"; } else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) { valueAsString = std::to_string(baseObject.clientVariable.floatValue); - variableType = "float"; + variableTypeAsString = "float"; } LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i, index: %i, type %s, value: %s", baseObject.refId.c_str(), - baseObject.refNum, baseObject.mpNum, baseObject.index, variableType.c_str(), valueAsString.c_str()); + baseObject.refNum, baseObject.mpNum, baseObject.index, variableTypeAsString.c_str(), valueAsString.c_str()); MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum); @@ -890,7 +890,7 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore) LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Found %s %i-%i", ptrFound.getCellRef().getRefId().c_str(), ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum()); - if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::INTEGER) + if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT) ptrFound.getRefData().getLocals().mShorts.at(baseObject.index) = baseObject.clientVariable.intValue; else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) ptrFound.getRefData().getLocals().mFloats.at(baseObject.index) = baseObject.clientVariable.floatValue; @@ -1166,13 +1166,13 @@ void ObjectList::addVideoPlay(std::string filename, bool allowSkipping) addBaseObject(baseObject); } -void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value) +void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value, mwmp::VARIABLE_TYPE variableType) { cell = *ptr.getCell()->getCell(); mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr); baseObject.clientVariable.index = index; - baseObject.clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER; + baseObject.clientVariable.variableType = variableType; baseObject.clientVariable.intValue = value; addBaseObject(baseObject); } @@ -1312,10 +1312,10 @@ void ObjectList::sendClientScriptLocal() std::string valueAsString; std::string variableType; - if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::INTEGER) + if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT) { valueAsString = std::to_string(baseObject.clientVariable.intValue); - variableType = "integer"; + variableType = "short"; } else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) { diff --git a/apps/openmw/mwmp/ObjectList.hpp b/apps/openmw/mwmp/ObjectList.hpp index 8d6e5e4b8..4a8e4452d 100644 --- a/apps/openmw/mwmp/ObjectList.hpp +++ b/apps/openmw/mwmp/ObjectList.hpp @@ -66,7 +66,7 @@ namespace mwmp void addDoorState(const MWWorld::Ptr& ptr, MWWorld::DoorState state); void addMusicPlay(std::string filename); void addVideoPlay(std::string filename, bool allowSkipping); - void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value); + void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value, mwmp::VARIABLE_TYPE variableType); void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, float value); void addScriptMemberShort(std::string refId, int index, int shortVal); diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp index f57c2a154..a4b97c13a 100644 --- a/apps/openmw/mwmp/Worldstate.cpp +++ b/apps/openmw/mwmp/Worldstate.cpp @@ -349,13 +349,24 @@ void Worldstate::setClientGlobals() if (!debugMessage.empty()) debugMessage += ", "; - std::string valueAsString = clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER ? - std::to_string(clientGlobal.intValue) : std::to_string(clientGlobal.floatValue); + std::string variableTypeAsString; + std::string valueAsString; - debugMessage += clientGlobal.id + ": " + valueAsString; + if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG) + { + variableTypeAsString = clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long"; + valueAsString = std::to_string(clientGlobal.intValue); + } + else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT) + { + variableTypeAsString = "float"; + valueAsString = std::to_string(clientGlobal.floatValue); + } + + debugMessage += clientGlobal.id + ": " + variableTypeAsString + " " + valueAsString; } - if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER) + if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG) MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.intValue); else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT) MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.floatValue); @@ -419,16 +430,24 @@ void Worldstate::setWeather() weather.queuedWeather, weather.transitionFactor, forceWeather); } -void Worldstate::sendClientGlobal(std::string varName, int value) +void Worldstate::sendClientGlobal(std::string varName, int value, mwmp::VARIABLE_TYPE variableType) { clientGlobals.clear(); mwmp::ClientVariable clientVariable; clientVariable.id = varName; - clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER; + clientVariable.variableType = variableType; clientVariable.intValue = value; - LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_CLIENT_SCRIPT_GLOBAL with name %s, type integer, value %i", varName.c_str(), value); + std::string variableTypeAsString; + + if (variableType == mwmp::VARIABLE_TYPE::SHORT) + variableTypeAsString = "short"; + else if (variableType == mwmp::VARIABLE_TYPE::LONG) + variableTypeAsString = "long"; + + LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_CLIENT_SCRIPT_GLOBAL with name %s, type %s, value %i", + varName.c_str(), variableTypeAsString.c_str(), value); clientGlobals.push_back(clientVariable); diff --git a/apps/openmw/mwmp/Worldstate.hpp b/apps/openmw/mwmp/Worldstate.hpp index 049448502..695a9d814 100644 --- a/apps/openmw/mwmp/Worldstate.hpp +++ b/apps/openmw/mwmp/Worldstate.hpp @@ -23,7 +23,7 @@ namespace mwmp void setMapExplored(); void setWeather(); - void sendClientGlobal(std::string varName, int value); + void sendClientGlobal(std::string varName, int value, mwmp::VARIABLE_TYPE variableType); void sendClientGlobal(std::string varName, float value); void sendMapExplored(int cellX, int cellY, const std::vector& imageData); void sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor); diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 1461cba85..f35ed34ee 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -242,7 +242,7 @@ namespace MWScript mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); objectList->reset(); objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType()); - objectList->addClientScriptLocal(mReference, index, value); + objectList->addClientScriptLocal(mReference, index, value, mwmp::VARIABLE_TYPE::SHORT); objectList->sendClientScriptLocal(); } /* @@ -364,7 +364,7 @@ namespace MWScript */ if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) { - mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value); + mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value, mwmp::VARIABLE_TYPE::SHORT); } /* End of tes3mp addition @@ -394,7 +394,7 @@ namespace MWScript */ if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) { - mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value); + mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value, mwmp::VARIABLE_TYPE::LONG); } /* End of tes3mp addition diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index c22774178..bef694d7e 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -22,7 +22,8 @@ namespace mwmp enum VARIABLE_TYPE { - INTEGER, + SHORT, + LONG, FLOAT }; diff --git a/components/openmw-mp/Packets/Object/PacketClientScriptLocal.cpp b/components/openmw-mp/Packets/Object/PacketClientScriptLocal.cpp index 5ca275852..b1c0abcd1 100644 --- a/components/openmw-mp/Packets/Object/PacketClientScriptLocal.cpp +++ b/components/openmw-mp/Packets/Object/PacketClientScriptLocal.cpp @@ -15,7 +15,7 @@ void PacketClientScriptLocal::Object(BaseObject &baseObject, bool send) RW(baseObject.clientVariable.index, send); RW(baseObject.clientVariable.variableType, send); - if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::INTEGER) + if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT || baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG) RW(baseObject.clientVariable.intValue, send); else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) RW(baseObject.clientVariable.floatValue, send); diff --git a/components/openmw-mp/Packets/Worldstate/PacketClientScriptGlobal.cpp b/components/openmw-mp/Packets/Worldstate/PacketClientScriptGlobal.cpp index 1407f6790..2c2519b85 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketClientScriptGlobal.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketClientScriptGlobal.cpp @@ -31,7 +31,7 @@ void PacketClientScriptGlobal::Packet(RakNet::BitStream *newBitstream, bool send RW(clientGlobal.id, send, true); RW(clientGlobal.variableType, send); - if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER) + if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG) RW(clientGlobal.intValue, send); else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT) RW(clientGlobal.floatValue, send);