From 914b79fcc9c903a20ea1c4f767022427e12883c9 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 26 Jun 2018 16:56:08 +0300 Subject: [PATCH] [General] Make it possible to check which placed objects have containers --- apps/openmw-mp/Script/Functions/Objects.cpp | 5 +++++ apps/openmw-mp/Script/Functions/Objects.hpp | 14 ++++++++++++++ apps/openmw/mwmp/ObjectList.cpp | 1 + components/openmw-mp/Base/BaseObject.hpp | 2 ++ .../openmw-mp/Packets/Object/PacketObjectPlace.cpp | 1 + 5 files changed, 23 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index c8aa8a652..00f612bcb 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -178,6 +178,11 @@ int ObjectFunctions::GetContainerItemActionCount(unsigned int objectIndex, unsig .containerItems.at(itemIndex).actionCount; } +bool ObjectFunctions::DoesObjectHaveContainer(unsigned int i) noexcept +{ + return readObjectList->baseObjects.at(i).hasContainer; +} + void ObjectFunctions::SetObjectListCell(const char* cellDescription) noexcept { writeObjectList.cell = Utils::getCellFromDescription(cellDescription); diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index 47a3dffa5..ded7d5004 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -38,6 +38,8 @@ {"GetContainerItemEnchantmentCharge", ObjectFunctions::GetContainerItemEnchantmentCharge},\ {"GetContainerItemActionCount", ObjectFunctions::GetContainerItemActionCount},\ \ + {"DoesObjectHaveContainer", ObjectFunctions::DoesObjectHaveContainer},\ + \ {"SetObjectListCell", ObjectFunctions::SetObjectListCell},\ {"SetObjectListAction", ObjectFunctions::SetObjectListAction},\ {"SetObjectListConsoleCommand", ObjectFunctions::SetObjectListConsoleCommand},\ @@ -360,6 +362,18 @@ public: */ static int GetContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex) noexcept; + /** + * \brief Check whether the object at a certain index in the read object list's object + * changes has a container. + * + * Note: Only ObjectLists from ObjectPlace packets contain this information. Objects from + * received ObjectSpawn packets can always be assumed to have a container. + * + * \param i The index of the object. + * \return Whether the object has a container. + */ + static bool DoesObjectHaveContainer(unsigned int i) noexcept; + /** * \brief Set the cell of the temporary object list stored on the server. * diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp index 72fc20572..aee3cf804 100644 --- a/apps/openmw/mwmp/ObjectList.cpp +++ b/apps/openmw/mwmp/ObjectList.cpp @@ -809,6 +809,7 @@ void ObjectList::addObjectPlace(const MWWorld::Ptr& ptr, bool droppedByPlayer) baseObject.charge = ptr.getCellRef().getCharge(); baseObject.enchantmentCharge = ptr.getCellRef().getEnchantmentCharge(); baseObject.droppedByPlayer = droppedByPlayer; + baseObject.hasContainer = ptr.getClass().hasContainerStore(ptr); // Make sure we send the RefData position instead of the CellRef one, because that's what // we actually see on this client diff --git a/components/openmw-mp/Base/BaseObject.hpp b/components/openmw-mp/Base/BaseObject.hpp index 02f40097b..349b1af3f 100644 --- a/components/openmw-mp/Base/BaseObject.hpp +++ b/components/openmw-mp/Base/BaseObject.hpp @@ -60,6 +60,8 @@ namespace mwmp Target master; bool hasMaster; + bool hasContainer; + std::vector containerItems; unsigned int containerItemCount; diff --git a/components/openmw-mp/Packets/Object/PacketObjectPlace.cpp b/components/openmw-mp/Packets/Object/PacketObjectPlace.cpp index 2c65bee41..a9d3820ac 100644 --- a/components/openmw-mp/Packets/Object/PacketObjectPlace.cpp +++ b/components/openmw-mp/Packets/Object/PacketObjectPlace.cpp @@ -18,4 +18,5 @@ void PacketObjectPlace::Object(BaseObject &baseObject, bool send) RW(baseObject.goldValue, send); RW(baseObject.position, send); RW(baseObject.droppedByPlayer, send); + RW(baseObject.hasContainer, send); }