Implement ID_WORLD_DOOR_ACTIVATE and send it from MWBase::World

pull/112/merge
David Cernat 8 years ago
parent 7264f13b8e
commit bdb53e1cb4

@ -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

@ -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");

@ -5,6 +5,9 @@
#include <osg/Group>
#include <osg/ComputeBoundsVisitor>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include <components/esm/esmreader.hpp>
#include <components/esm/esmwriter.hpp>
#include <components/esm/cellid.hpp>
@ -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();

@ -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

@ -26,6 +26,7 @@ namespace mwmp
ESM::Cell cell;
ESM::CellRef cellRef;
int state;
int lockLevel;
float scale;

@ -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);
}

Loading…
Cancel
Save