From 9f8bed9be1fdd4e3600e03b9850573fe67f18cb8 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 4 Feb 2017 21:32:06 +0200 Subject: [PATCH] [General] Add action types to WorldEvent's ContainerChanges --- components/openmw-mp/Base/BasePlayer.hpp | 6 ++-- components/openmw-mp/Base/WorldEvent.hpp | 34 ++++++++++++------- .../Packets/World/PacketContainer.cpp | 5 +++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index dea0a9954..e3c6db6b1 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -66,7 +66,7 @@ namespace mwmp { ESM::Cell cell; - enum CELl_STATE_ACTION + enum CELL_STATE_ACTION { LOAD = 0, UNLOAD = 1 @@ -91,7 +91,7 @@ namespace mwmp ADD, REMOVE }; - int action; //0 - Clear and set in entirety, 1 - Add item, 2 - Remove item + int action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item }; struct SpellbookChanges @@ -104,7 +104,7 @@ namespace mwmp ADD, REMOVE }; - int action; //0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell + int action; // 0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell }; struct CellStateChanges diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index 9b215f68b..a7e4b6158 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -36,12 +36,34 @@ namespace mwmp std::string refId; int count; int health; + inline bool operator==(const ContainerItem& rhs) { return refId == rhs.refId && count == rhs.count && health == rhs.health; } }; + struct ObjectChanges + { + std::vector objects; + unsigned int count; + }; + + struct ContainerChanges + { + std::vector items; + unsigned int count; + + enum CONTAINER_ACTION + { + SET = 0, + ADD = 1, + REMOVE = 2 + }; + + int action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item + }; + class WorldEvent { public: @@ -56,18 +78,6 @@ namespace mwmp } - struct ObjectChanges - { - std::vector objects; - unsigned int count; - }; - - struct ContainerChanges - { - std::vector items; - unsigned int count; - }; - RakNet::RakNetGUID guid; ObjectChanges objectChanges; ContainerChanges containerChanges; diff --git a/components/openmw-mp/Packets/World/PacketContainer.cpp b/components/openmw-mp/Packets/World/PacketContainer.cpp index ac065a132..b6b31ae27 100644 --- a/components/openmw-mp/Packets/World/PacketContainer.cpp +++ b/components/openmw-mp/Packets/World/PacketContainer.cpp @@ -12,8 +12,13 @@ void PacketContainer::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send { WorldPacket::Packet(bs, event, send); + RW(event->containerChanges.action, send); + if (!send) + { event->objectChanges.objects.clear(); + event->containerChanges.items.clear(); + } else { event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());