[General] Make WorldEvents store information about multiple objects

pull/163/head
David Cernat 8 years ago
parent 624b85347a
commit 9f1e491a75

@ -416,7 +416,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
WorldPacket *myPacket = worldController->GetPacket(packet->data[0]);
WorldEvent *event = new WorldEvent(player->guid);
event->cellRef.blank();
mwmp::WorldObject worldObject;
switch (packet->data[0])
{
@ -429,11 +429,16 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
myPacket->Read(event);
myPacket->Send(event, true);
Script::Call<Script::CallbackIdentity("OnObjectPlace")>(
player->getId(),
event->cellRef.mRefID.c_str(),
(int) event->cellRef.mRefNum.mIndex,
event->cell.getDescription().c_str());
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
worldObject = event->objectChanges.objects[i];
Script::Call<Script::CallbackIdentity("OnObjectPlace")>(
player->getId(),
worldObject.refId.c_str(),
(int) worldObject.refNumIndex,
event->cell.getDescription().c_str());
}
break;
}
@ -444,19 +449,20 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
myPacket->Send(event, true);
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());
ESM::CellRef cellRef;
myPacket->Send(event, true);
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
worldObject = event->objectChanges.objects[i];
Script::Call<Script::CallbackIdentity("OnObjectDelete")>(
player->getId(),
event->cellRef.mRefID.c_str(),
(int) event->cellRef.mRefNum.mIndex,
event->cell.getDescription().c_str());
Script::Call<Script::CallbackIdentity("OnObjectDelete")>(
player->getId(),
worldObject.refId.c_str(),
(int) worldObject.refNumIndex,
event->cell.getDescription().c_str());
}
break;
}
@ -467,12 +473,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -484,12 +484,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -501,12 +495,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -518,12 +506,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -535,12 +517,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -552,12 +528,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -569,12 +539,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -586,12 +550,6 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
@ -603,108 +561,72 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
}
case ID_MUSIC_PLAY:
case ID_SCRIPT_LOCAL_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY from %s",
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT from %s",
player->npc.mName.c_str());
myPacket->Read(event);
LOG_APPEND(Log::LOG_WARN, "- filename: %s",
event->filename.c_str());
myPacket->Send(event, true);
break;
}
case ID_VIDEO_PLAY:
case ID_SCRIPT_LOCAL_FLOAT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY from %s",
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT from %s",
player->npc.mName.c_str());
myPacket->Read(event);
LOG_APPEND(Log::LOG_WARN, "- filename: %s\n- allowSkipping: %s",
event->filename.c_str(),
event->allowSkipping ? "true" : "false");
myPacket->Send(event, true);
break;
}
case ID_SCRIPT_LOCAL_SHORT:
case ID_SCRIPT_MEMBER_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT from %s",
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT from %s",
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
}
case ID_SCRIPT_LOCAL_FLOAT:
case ID_SCRIPT_GLOBAL_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT from %s",
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT from %s",
player->npc.mName.c_str());
myPacket->Read(event);
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());
myPacket->Send(event, true);
break;
}
case ID_SCRIPT_MEMBER_SHORT:
case ID_MUSIC_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT from %s",
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY from %s",
player->npc.mName.c_str());
myPacket->Read(event);
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s",
event->cellRef.mRefID.c_str());
myPacket->Send(event, true);
break;
}
case ID_SCRIPT_GLOBAL_SHORT:
case ID_VIDEO_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT from %s",
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY from %s",
player->npc.mName.c_str());
myPacket->Read(event);
LOG_APPEND(Log::LOG_WARN, "- varName: %s\n- shortVal: %i",
event->varName.c_str(),
event->shortVal);
myPacket->Send(event, true);
break;

@ -68,22 +68,30 @@ namespace MWGui
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *dropped.getCell()->getCell();
event->addCellRef(dropped.getCellRef());
mwmp::WorldObject worldObject;
worldObject.refId = dropped.getCellRef().getRefId();
worldObject.refNumIndex = dropped.getCellRef().getRefNum().mIndex;
// Make sure we send the RefData position instead of the CellRef one, because that's what
// we actually see on this client
event->pos = dropped.getRefData().getPosition();
worldObject.pos = dropped.getRefData().getPosition();
// We have to get the count from the dropped object because it gets changed
// automatically for stacks of gold
event->count = dropped.getRefData().getCount();
worldObject.count = dropped.getRefData().getCount();
// Get the real count of gold in a stack
worldObject.goldValue = dropped.getCellRef().getGoldValue();
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE\n- cellRef: %s, %i\n- count: %i",
dropped.getCellRef().getRefId().c_str(),
dropped.getCellRef().getRefNum().mIndex,
event->count);
worldObject.refId.c_str(),
worldObject.refNumIndex,
worldObject.count);
return dropped;
}

@ -637,7 +637,12 @@ namespace MWGui
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *object.getCell()->getCell();
event->addCellRef(object.getCellRef());
mwmp::WorldObject worldObject;
worldObject.refId = object.getCellRef().getRefId();
worldObject.refNumIndex = object.getCellRef().getRefNum().mIndex;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(event);
// remove from world

@ -61,7 +61,12 @@ namespace MWMechanics
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *lock.getCell()->getCell();
event->addCellRef(lock.getCellRef());
mwmp::WorldObject worldObject;
worldObject.refId = lock.getCellRef().getRefId();
worldObject.refNumIndex = lock.getCellRef().getRefNum().mIndex;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(event);
lock.getClass().unlock(lock);

@ -2,6 +2,18 @@
#include "Networking.hpp"
#include "Main.hpp"
#include <components/openmw-mp/Log.hpp>
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/manualref.hpp"
using namespace mwmp;
using namespace std;
@ -20,14 +32,388 @@ Networking *LocalEvent::getNetworking()
return mwmp::Main::get().getNetworking();
}
void LocalEvent::addCellRef(MWWorld::CellRef worldCellRef)
void LocalEvent::addObject(WorldObject worldObject)
{
objectChanges.objects.push_back(worldObject);
}
void LocalEvent::placeObjects(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- count: %i",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str(),
worldObject.count);
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), worldObject.refId, 1);
MWWorld::Ptr newPtr = ref.getPtr();
if (worldObject.count > 1)
newPtr.getRefData().setCount(worldObject.count);
newPtr.getCellRef().setGoldValue(worldObject.goldValue);
newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, cellStore, worldObject.pos);
// Change RefNum here because the line above unsets it
newPtr.getCellRef().setRefNumIndex(worldObject.refNumIndex);
// If this RefNum is higher than the last we've recorded for this CellStore,
// start using it as our new last one
if (cellStore->getLastRefNumIndex() < worldObject.refNumIndex)
cellStore->setLastRefNumIndex(worldObject.refNumIndex);
}
}
void LocalEvent::deleteObjects(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->deleteObject(ptrFound);
}
}
}
void LocalEvent::lockObjects(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getClass().lock(ptrFound, worldObject.lockLevel);
}
}
}
void LocalEvent::unlockObjects(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getClass().unlock(ptrFound);
}
}
}
void LocalEvent::scaleObjects(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->scaleObject(ptrFound, worldObject.scale);
}
}
}
void LocalEvent::moveObjects(MWWorld::CellStore* cellStore)
{
cellRef.mRefID = worldCellRef.getRefId();
cellRef.mRefNum = worldCellRef.getRefNum();
cellRef.mGoldValue = worldCellRef.getGoldValue();
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->moveObject(ptrFound,
worldObject.pos.pos[0], worldObject.pos.pos[1], worldObject.pos.pos[2]);
}
}
}
void LocalEvent::addRefId(std::string refId)
void LocalEvent::rotateObjects(MWWorld::CellStore* cellStore)
{
cellRef.mRefID = refId;
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->rotateObject(ptrFound,
worldObject.pos.rot[0], worldObject.pos.rot[1], worldObject.pos.rot[2]);
}
}
}
void LocalEvent::animateObjects(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptrFound,
worldObject.animGroup, worldObject.animMode, std::numeric_limits<int>::max(), true);
}
}
}
void LocalEvent::activateDoors(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getClass().setDoorState(ptrFound, worldObject.state);
MWBase::Environment::get().getWorld()->saveDoorState(ptrFound, worldObject.state);
}
}
}
void LocalEvent::playMusic()
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- filename: %s",
worldObject.filename.c_str());
MWBase::Environment::get().getSoundManager()->streamMusic(worldObject.filename);
}
}
void LocalEvent::playVideo()
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- filename: %s\n- allowSkipping: %s",
worldObject.filename.c_str(),
worldObject.allowSkipping ? "true" : "false");
MWBase::Environment::get().getWindowManager()->playVideo(worldObject.filename, worldObject.allowSkipping);
}
}
void LocalEvent::setLocalShorts(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- index: %i\n- shortVal: %i",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str(),
worldObject.index,
worldObject.shortVal);
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getRefData().getLocals().mShorts.at(worldObject.index) = worldObject.shortVal;
}
}
}
void LocalEvent::setLocalFloats(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- index: %i\n- floatVal: %f",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str(),
worldObject.index,
worldObject.floatVal);
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getRefData().getLocals().mFloats.at(worldObject.index) = worldObject.floatVal;
}
}
}
void LocalEvent::setMemberShorts()
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s\n- index: %i\n- shortVal: %i\n",
worldObject.refId.c_str(),
worldObject.index,
worldObject.shortVal);
// Mimic the way a Ptr is fetched in InterpreterContext for similar situations
MWWorld::Ptr ptrFound = MWBase::Environment::get().getWorld()->getPtr(worldObject.refId, false);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
std::string scriptId = ptrFound.getClass().getScript(ptrFound);
ptrFound.getRefData().setLocals(
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find(scriptId));
ptrFound.getRefData().getLocals().mShorts.at(worldObject.index) = worldObject.shortVal;;
}
}
}
void LocalEvent::setGlobalShorts()
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- varName: %s\n- shortVal: %i",
worldObject.varName.c_str(),
worldObject.shortVal);
MWBase::Environment::get().getWorld()->setGlobalInt(worldObject.varName, worldObject.shortVal);
}
}

@ -15,8 +15,25 @@ namespace mwmp
LocalEvent(RakNet::RakNetGUID guid);
virtual ~LocalEvent();
void addCellRef(MWWorld::CellRef worldCellRef);
void addRefId(std::string refId);
void addObject(WorldObject worldObject);
void placeObjects(MWWorld::CellStore* cellStore);
void deleteObjects(MWWorld::CellStore* cellStore);
void lockObjects(MWWorld::CellStore* cellStore);
void unlockObjects(MWWorld::CellStore* cellStore);
void scaleObjects(MWWorld::CellStore* cellStore);
void moveObjects(MWWorld::CellStore* cellStore);
void rotateObjects(MWWorld::CellStore* cellStore);
void animateObjects(MWWorld::CellStore* cellStore);
void activateDoors(MWWorld::CellStore* cellStore);
void setLocalShorts(MWWorld::CellStore* cellStore);
void setLocalFloats(MWWorld::CellStore* cellStore);
void setMemberShorts();
void setGlobalShorts();
void playMusic();
void playVideo();
private:
Networking *getNetworking();

@ -9,9 +9,6 @@
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/esmstore.hpp"
@ -743,29 +740,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_PLACE");
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- count: %i",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
event->cell.getDescription().c_str(),
event->count);
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), event->cellRef.mRefID, 1);
MWWorld::Ptr newPtr = ref.getPtr();
if (event->count > 1)
newPtr.getRefData().setCount(event->count);
newPtr.getCellRef().setGoldValue(event->cellRef.mGoldValue);
newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, ptrCellStore, event->pos);
// Change RefNum here because the line above unsets it
newPtr.getCellRef().setRefNumIndex(event->cellRef.mRefNum.mIndex);
// If this RefNum is higher than the last we've recorded for this CellStore,
// start using it as our new last one
if (ptrCellStore->getLastRefNumIndex() < event->cellRef.mRefNum.mIndex)
ptrCellStore->setLastRefNumIndex(event->cellRef.mRefNum.mIndex);
event->placeObjects(ptrCellStore);
break;
}
@ -776,21 +751,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_DELETE");
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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->deleteObject(ptrFound);
}
event->deleteObjects(ptrCellStore);
break;
}
@ -801,21 +762,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_LOCK");
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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getClass().lock(ptrFound, event->lockLevel);
}
event->lockObjects(ptrCellStore);
break;
}
@ -826,21 +773,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_UNLOCK");
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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getClass().unlock(ptrFound);
}
event->unlockObjects(ptrCellStore);
break;
}
@ -851,21 +784,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_OBJECT_SCALE");
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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->scaleObject(ptrFound, event->scale);
}
event->scaleObjects(ptrCellStore);
break;
}
@ -876,22 +795,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_MOVE");
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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->moveObject(ptrFound,
event->pos.pos[0], event->pos.pos[1], event->pos.pos[2]);
}
event->moveObjects(ptrCellStore);
break;
}
@ -902,22 +806,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ROTATE");
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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getWorld()->rotateObject(ptrFound,
event->pos.rot[0], event->pos.rot[1], event->pos.rot[2]);
}
event->rotateObjects(ptrCellStore);
break;
}
@ -928,22 +817,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ANIM_PLAY");
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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptrFound,
event->animGroup, event->animMode, std::numeric_limits<int>::max(), true);
}
event->animateObjects(ptrCellStore);
break;
}
@ -954,43 +828,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_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->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
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_MUSIC_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY");
LOG_APPEND(Log::LOG_WARN, "- filename: %s",
event->filename.c_str());
MWBase::Environment::get().getSoundManager()->streamMusic(event->filename);
break;
}
case ID_VIDEO_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY");
LOG_APPEND(Log::LOG_WARN, "- filename: %s\n- allowSkipping: %s",
event->filename.c_str(),
event->allowSkipping ? "true" : "false");
MWBase::Environment::get().getWindowManager()->playVideo(event->filename, event->allowSkipping);
event->activateDoors(ptrCellStore);
break;
}
@ -1001,23 +839,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT");
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- index: %i\n- shortVal: %i",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
event->cell.getDescription().c_str(),
event->index,
event->shortVal);
MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getRefData().getLocals().mShorts.at(event->index) = event->shortVal;
}
event->setLocalShorts(ptrCellStore);
break;
}
@ -1028,61 +850,35 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT");
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s\n- index: %i\n- floatVal: %f",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
event->cell.getDescription().c_str(),
event->index,
event->floatVal);
MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
ptrFound.getRefData().getLocals().mFloats.at(event->index) = event->floatVal;
}
event->setLocalFloats(ptrCellStore);
break;
}
case ID_SCRIPT_MEMBER_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT");
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s\n- index: %i\n- shortVal: %i\n",
event->cellRef.mRefID.c_str(),
event->index,
event->shortVal);
// Mimic the way a Ptr is fetched in InterpreterContext for similar situations
MWWorld::Ptr ptrFound = MWBase::Environment::get().getWorld()->getPtr(event->cellRef.mRefID, false);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
std::string scriptId = ptrFound.getClass().getScript(ptrFound);
ptrFound.getRefData().setLocals(
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find(scriptId));
ptrFound.getRefData().getLocals().mShorts.at(event->index) = event->shortVal;;
}
event->setMemberShorts();
break;
}
case ID_SCRIPT_GLOBAL_SHORT:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT");
LOG_APPEND(Log::LOG_WARN, "- varName: %s\n- shortVal: %i",
event->varName.c_str(),
event->shortVal);
event->setGlobalShorts();
MWBase::Environment::get().getWorld()->setGlobalInt(event->varName, event->shortVal);
break;
}
case ID_MUSIC_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY");
event->playMusic();
break;
}
case ID_VIDEO_PLAY:
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY");
event->playVideo();
break;
}

@ -68,9 +68,14 @@ namespace MWScript
{
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->addCellRef(ptr.getCellRef());
event->animGroup = group;
event->animMode = mode;
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.animGroup = group;
worldObject.animMode = mode;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->Send(event);
}

@ -191,17 +191,22 @@ namespace MWScript
{
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *mReference.getCell()->getCell();
event->addCellRef(mReference.getCellRef());
event->index = index;
event->shortVal = value;
mwmp::WorldObject worldObject;
worldObject.refId = mReference.getCellRef().getRefId();
worldObject.refNumIndex = mReference.getCellRef().getRefNum().mIndex;
worldObject.index = index;
worldObject.shortVal = value;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_SHORT)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_SHORT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- shortVal: %i",
mReference.getCellRef().getRefId().c_str(),
mReference.getCellRef().getRefNum().mIndex,
worldObject.refId.c_str(),
worldObject.refNumIndex,
event->cell.getDescription().c_str(),
event->index,
event->shortVal);
worldObject.index,
worldObject.shortVal);
}
}
@ -227,17 +232,22 @@ namespace MWScript
{
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *mReference.getCell()->getCell();
event->addCellRef(mReference.getCellRef());
event->index = index;
event->floatVal = value;
mwmp::WorldObject worldObject;
worldObject.refId = mReference.getCellRef().getRefId();
worldObject.refNumIndex = mReference.getCellRef().getRefNum().mIndex;
worldObject.index = index;
worldObject.floatVal = value;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_FLOAT)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_FLOAT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- floatVal: %f",
mReference.getCellRef().getRefId().c_str(),
mReference.getCellRef().getRefNum().mIndex,
worldObject.refId.c_str(),
worldObject.refNumIndex,
event->cell.getDescription().c_str(),
event->index,
event->floatVal);
worldObject.index,
worldObject.floatVal);
}
}
@ -286,13 +296,17 @@ namespace MWScript
if (sendPackets)
{
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->varName = name;
event->shortVal = value;
mwmp::WorldObject worldObject;
worldObject.varName = name;
worldObject.shortVal = value;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_GLOBAL_SHORT)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_GLOBAL_SHORT\n- varName: %s\n- shortVal: %i",
event->varName.c_str(),
event->shortVal);
worldObject.varName.c_str(),
worldObject.shortVal);
}
MWBase::Environment::get().getWorld()->setGlobalInt (name, value);
@ -619,15 +633,19 @@ namespace MWScript
if (sendPackets && !global)
{
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->addRefId(id);
event->index = index;
event->shortVal = value;
mwmp::WorldObject worldObject;
worldObject.refId = id;
worldObject.index = index;
worldObject.shortVal = value;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_MEMBER_SHORT)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_MEMBER_SHORT\n- cellRef: %s\n- index: %i\n- shortVal: %i",
id.c_str(),
event->index,
event->shortVal);
worldObject.refId.c_str(),
worldObject.index,
worldObject.shortVal);
}
}

@ -91,8 +91,12 @@ namespace MWScript
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->filename = name;
event->allowSkipping = allowSkipping;
mwmp::WorldObject worldObject;
worldObject.filename = name;
worldObject.allowSkipping = allowSkipping;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->Send(event);
MWBase::Environment::get().getWindowManager()->playVideo (name, allowSkipping);
@ -196,8 +200,13 @@ namespace MWScript
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->addCellRef(ptr.getCellRef());
event->lockLevel = lockLevel;
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.lockLevel = lockLevel;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->Send(event);
ptr.getClass().lock (ptr, lockLevel);
@ -229,7 +238,12 @@ namespace MWScript
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->addCellRef(ptr.getCellRef());
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(event);
ptr.getClass().unlock (ptr);
@ -695,7 +709,12 @@ namespace MWScript
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->addCellRef(ptr.getCellRef());
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(event);
MWBase::Environment::get().getWorld()->deleteObject(ptr);

@ -72,7 +72,11 @@ namespace MWScript
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->filename = sound;
mwmp::WorldObject worldObject;
worldObject.filename = sound;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->Send(event);
MWBase::Environment::get().getSoundManager()->streamMusic (sound);

@ -49,9 +49,13 @@ namespace MWScript
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->addCellRef(ptr.getCellRef());
event->cellRef.mPos = ptr.getCellRef().getPosition();
event->scale = scale;
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.scale = scale;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send(event);
MWBase::Environment::get().getWorld()->scaleObject(ptr,scale);
@ -548,19 +552,24 @@ namespace MWScript
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->addCellRef(ptr.getCellRef());
mwmp::WorldObject worldObject;
worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.count = 1;
// Make sure we send the RefData position instead of the CellRef one, because that's what
// we actually see on this client
event->pos = ptr.getRefData().getPosition();
worldObject.pos = ptr.getRefData().getPosition();
event->addObject(worldObject);
event->count = 1;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE\n- cellRef: %s, %i\n- count: %i",
ptr.getCellRef().getRefId().c_str(),
ptr.getCellRef().getRefNum().mIndex,
event->count);
worldObject.refId.c_str(),
worldObject.refNumIndex,
worldObject.count);
}
}
};

@ -28,7 +28,12 @@ namespace MWWorld
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *getTarget().getCell()->getCell();
event->addCellRef(getTarget().getCellRef());
mwmp::WorldObject worldObject;
worldObject.refId = getTarget().getCellRef().getRefId();
worldObject.refNumIndex = getTarget().getCellRef().getRefNum().mIndex;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_DELETE about\n- cellRef: %s, %i\n- cell: %s.",

@ -2268,15 +2268,20 @@ namespace MWWorld
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *door.getCell()->getCell();
event->addCellRef(door.getCellRef());
event->state = state;
mwmp::WorldObject worldObject;
worldObject.refId = door.getCellRef().getRefId();
worldObject.refNumIndex = door.getCellRef().getRefNum().mIndex;
worldObject.state = state;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_ACTIVATE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Door activation 1\n- cellRef: %s, %i\n- cell: %s\n- state: %s",
door.getCellRef().getRefId().c_str(),
door.getCellRef().getRefNum().mIndex,
worldObject.refId.c_str(),
worldObject.refNumIndex,
event->cell.getDescription().c_str(),
event->state ? "true" : "false");
worldObject.state ? "true" : "false");
door.getClass().setDoorState(door, state);
mDoorStates[door] = state;
@ -2287,15 +2292,20 @@ namespace MWWorld
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *door.getCell()->getCell();
event->addCellRef(door.getCellRef());
event->state = state;
mwmp::WorldObject worldObject;
worldObject.refId = door.getCellRef().getRefId();
worldObject.refNumIndex = door.getCellRef().getRefNum().mIndex;
worldObject.state = state;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_ACTIVATE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Door activation 2\n- cellRef: %s, %i\n- cell: %s\n- state: %s",
door.getCellRef().getRefId().c_str(),
door.getCellRef().getRefNum().mIndex,
worldObject.refId.c_str(),
worldObject.refNumIndex,
event->cell.getDescription().c_str(),
event->state ? "true" : "false");
worldObject.state ? "true" : "false");
door.getClass().setDoorState(door, state);
mDoorStates[door] = state;

@ -7,27 +7,14 @@
namespace mwmp
{
class WorldEvent
struct WorldObject
{
public:
WorldEvent(RakNet::RakNetGUID guid) : guid(guid)
{
}
WorldEvent()
{
}
RakNet::RakNetGUID guid;
ESM::Cell cell;
ESM::CellRef cellRef;
std::string refId;
int refNumIndex;
int goldValue;
int count;
ESM::Position pos;
int count;
int state;
int lockLevel;
float scale;
@ -43,6 +30,32 @@ namespace mwmp
float floatVal;
std::string varName;
};
class WorldEvent
{
public:
WorldEvent(RakNet::RakNetGUID guid) : guid(guid)
{
}
WorldEvent()
{
}
struct ObjectChanges
{
std::vector<WorldObject> objects;
unsigned int count;
};
RakNet::RakNetGUID guid;
ObjectChanges objectChanges;
ESM::Cell cell;
};
}
#endif //OPENMW_WORLDEVENT_HPP

@ -12,13 +12,34 @@ void PacketDoorActivate::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.state, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,5 +12,27 @@ void PacketMusicPlay::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send
{
WorldPacket::Packet(bs, event, send);
RW(event->filename, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.filename, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,14 +12,35 @@ void PacketObjectAnimPlay::Packet(RakNet::BitStream *bs, WorldEvent *event, bool
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->animGroup, send);
RW(event->animMode, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.animGroup, send);
RW(worldObject.animMode, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,11 +12,33 @@ void PacketObjectDelete::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, send);
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,13 +12,34 @@ void PacketObjectLock::Packet(RakNet::BitStream *bs, WorldEvent *event, bool sen
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->lockLevel, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.lockLevel, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,15 +12,36 @@ void PacketObjectMove::Packet(RakNet::BitStream *bs, WorldEvent *event, bool sen
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->pos.pos[0], send);
RW(event->pos.pos[1], send);
RW(event->pos.pos[2], send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.pos.pos[0], send);
RW(worldObject.pos.pos[1], send);
RW(worldObject.pos.pos[2], send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,15 +12,36 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, WorldEvent *event, bool se
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
RW(event->cellRef.mGoldValue, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->pos, send);
RW(event->count, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.goldValue, send);
RW(worldObject.pos, send);
RW(worldObject.count, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,15 +12,36 @@ void PacketObjectRotate::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->pos.rot[0], send);
RW(event->pos.rot[1], send);
RW(event->pos.rot[2], send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.pos.rot[0], send);
RW(worldObject.pos.rot[1], send);
RW(worldObject.pos.rot[2], send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,13 +12,34 @@ void PacketObjectScale::Packet(RakNet::BitStream *bs, WorldEvent *event, bool se
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->scale, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.scale, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,11 +12,35 @@ void PacketObjectUnlock::Packet(RakNet::BitStream *bs, WorldEvent *event, bool s
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
WorldPacket::Packet(bs, event, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, send);
RW(event->cell.mData.mFlags, send);
RW(event->cell.mData.mX, send);
RW(event->cell.mData.mY, send);
RW(event->cell.mName, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,6 +12,28 @@ void PacketScriptGlobalShort::Packet(RakNet::BitStream *bs, WorldEvent *event, b
{
WorldPacket::Packet(bs, event, send);
RW(event->varName, send);
RW(event->shortVal, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.varName, send);
RW(worldObject.shortVal, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,14 +12,35 @@ void PacketScriptLocalFloat::Packet(RakNet::BitStream *bs, WorldEvent *event, bo
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->index, send);
RW(event->floatVal, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.index, send);
RW(worldObject.floatVal, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,14 +12,35 @@ void PacketScriptLocalShort::Packet(RakNet::BitStream *bs, WorldEvent *event, bo
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
RW(event->cellRef.mRefNum.mIndex, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, 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->index, send);
RW(event->shortVal, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.index, send);
RW(worldObject.shortVal, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,8 +12,29 @@ void PacketScriptMemberShort::Packet(RakNet::BitStream *bs, WorldEvent *event, b
{
WorldPacket::Packet(bs, event, send);
RW(event->cellRef.mRefID, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->index, send);
RW(event->shortVal, send);
RW(event->objectChanges.count, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.refId, send);
RW(worldObject.index, send);
RW(worldObject.shortVal, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

@ -12,6 +12,28 @@ void PacketVideoPlay::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send
{
WorldPacket::Packet(bs, event, send);
RW(event->filename, send);
RW(event->allowSkipping, send);
if (!send)
event->objectChanges.objects.clear();
else
event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size());
RW(event->objectChanges.count, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->objectChanges.count; i++)
{
if (send)
{
worldObject = event->objectChanges.objects[i];
}
RW(worldObject.filename, send);
RW(worldObject.allowSkipping, send);
if (!send)
{
event->objectChanges.objects.push_back(worldObject);
}
}
}

Loading…
Cancel
Save