From bdb53e1cb41d894ad6e79f12d5a53786ac6fa7d8 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 25 Oct 2016 10:40:55 +0300 Subject: [PATCH] Implement ID_WORLD_DOOR_ACTIVATE and send it from MWBase::World --- apps/openmw/mwbase/world.hpp | 3 ++ apps/openmw/mwmp/Networking.cpp | 22 ++++++++++ apps/openmw/mwworld/worldimp.cpp | 40 +++++++++++++++++++ apps/openmw/mwworld/worldimp.hpp | 3 ++ components/openmw-mp/Base/WorldEvent.hpp | 1 + .../Packets/World/PacketDoorActivate.cpp | 10 +++++ 6 files changed, 79 insertions(+) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 0178a3f2b..e95b04416 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -410,6 +410,9 @@ namespace MWBase /// @note throws an exception when invoked on a teleport door virtual void activateDoor(const MWWorld::Ptr& door, int state) = 0; + // Added by tes3mp to allow saving a door state received from a packet + virtual void saveDoorState(const MWWorld::Ptr& door, int state) = 0; + virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is standing on \a object virtual bool getActorStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if any actor is standing on \a object virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is colliding with \a object diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 6260b251e..42e31fe00 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -788,6 +788,28 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } + case ID_WORLD_DOOR_ACTIVATE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_DOOR_ACTIVATE"); + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + + MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + + ptrFound.getClass().setDoorState(ptrFound, event->state); + MWBase::Environment::get().getWorld()->saveDoorState(ptrFound, event->state); + } + + break; + } case ID_WORLD_VIDEO_PLAY: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_VIDEO_PLAY"); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 96422fe9e..c34063a81 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -5,6 +5,9 @@ #include #include +#include +#include "../mwmp/Main.hpp" + #include #include #include @@ -2247,18 +2250,55 @@ namespace MWWorld state = 2; // if opening, then close break; } + + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cell = *door.getCell()->getCell(); + event->cellRef.mRefID = door.getCellRef().getRefId(); + event->cellRef.mRefNum = door.getCellRef().getRefNum(); + event->state = state; + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_DOOR_ACTIVATE)->Send(event); + + printf("Door activation 1\n- cellRef: %s, %i\n- cell: %s\n- state: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str(), + event->state ? "true" : "false"); + door.getClass().setDoorState(door, state); mDoorStates[door] = state; } void World::activateDoor(const Ptr &door, int state) { + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cell = *door.getCell()->getCell(); + event->cellRef.mRefID = door.getCellRef().getRefId(); + event->cellRef.mRefNum = door.getCellRef().getRefNum(); + event->state = state; + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_DOOR_ACTIVATE)->Send(event); + + printf("Door activation 2\n- cellRef: %s, %i\n- cell: %s\n- state: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str(), + event->state ? "true" : "false"); + door.getClass().setDoorState(door, state); mDoorStates[door] = state; if (state == 0) mDoorStates.erase(door); } + // Added by tes3mp to allow saving a door state received from a packet + void World::saveDoorState(const Ptr &door, int state) + { + mDoorStates[door] = state; + if (state == 0) + mDoorStates.erase(door); + } + bool World::getPlayerStandingOn (const MWWorld::ConstPtr& object) { MWWorld::Ptr player = getPlayerPtr(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index a5e250452..2ffca0d9b 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -515,6 +515,9 @@ namespace MWWorld /// @note throws an exception when invoked on a teleport door virtual void activateDoor(const MWWorld::Ptr& door, int state); + // Added by tes3mp to allow saving a door state received from a packet + virtual void saveDoorState(const MWWorld::Ptr& door, int state); + virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object); ///< @return true if the player is standing on \a object virtual bool getActorStandingOn (const MWWorld::ConstPtr& object); ///< @return true if any actor is standing on \a object virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object); ///< @return true if the player is colliding with \a object diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index 5baa6d786..4b84c48a2 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -26,6 +26,7 @@ namespace mwmp ESM::Cell cell; ESM::CellRef cellRef; + int state; int lockLevel; float scale; diff --git a/components/openmw-mp/Packets/World/PacketDoorActivate.cpp b/components/openmw-mp/Packets/World/PacketDoorActivate.cpp index ff882b36b..a48fdfd07 100644 --- a/components/openmw-mp/Packets/World/PacketDoorActivate.cpp +++ b/components/openmw-mp/Packets/World/PacketDoorActivate.cpp @@ -11,4 +11,14 @@ PacketDoorActivate::PacketDoorActivate(RakNet::RakPeerInterface *peer) : WorldPa void PacketDoorActivate::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) { WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum.mIndex, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); + RW(event->cell.mName, send); + + RW(event->state, send); }