forked from mirror/openmw-tes3mp
[General] Use ObjectSpawn instead of ObjectPlace for actors
This commit is contained in:
parent
c211d53190
commit
4e5c8873e0
12 changed files with 101 additions and 31 deletions
|
@ -119,11 +119,6 @@ double WorldFunctions::GetObjectRotZ(unsigned int i) noexcept
|
|||
return readEvent->worldObjects.at(i).position.rot[2];
|
||||
}
|
||||
|
||||
bool WorldFunctions::GetObjectIsActor(unsigned int i) noexcept
|
||||
{
|
||||
return readEvent->worldObjects.at(i).isActor;
|
||||
}
|
||||
|
||||
unsigned int WorldFunctions::GetContainerChangesSize(unsigned int objectIndex) noexcept
|
||||
{
|
||||
return readEvent->worldObjects.at(objectIndex).containerItemCount;
|
||||
|
@ -256,18 +251,24 @@ void WorldFunctions::AddContainerItem() noexcept
|
|||
tempContainerItem = emptyContainerItem;
|
||||
}
|
||||
|
||||
void WorldFunctions::SendObjectDelete() noexcept
|
||||
{
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->setEvent(&writeEvent);
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->Send(writeEvent.guid);
|
||||
}
|
||||
|
||||
void WorldFunctions::SendObjectPlace() noexcept
|
||||
{
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->setEvent(&writeEvent);
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->Send(writeEvent.guid);
|
||||
}
|
||||
|
||||
void WorldFunctions::SendObjectSpawn() noexcept
|
||||
{
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SPAWN)->setEvent(&writeEvent);
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SPAWN)->Send(writeEvent.guid);
|
||||
}
|
||||
|
||||
void WorldFunctions::SendObjectDelete() noexcept
|
||||
{
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->setEvent(&writeEvent);
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->Send(writeEvent.guid);
|
||||
}
|
||||
|
||||
void WorldFunctions::SendObjectLock() noexcept
|
||||
{
|
||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->setEvent(&writeEvent);
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
{"GetObjectRotX", WorldFunctions::GetObjectRotX},\
|
||||
{"GetObjectRotY", WorldFunctions::GetObjectRotY},\
|
||||
{"GetObjectRotZ", WorldFunctions::GetObjectRotZ},\
|
||||
{"GetObjectIsActor", WorldFunctions::GetObjectIsActor},\
|
||||
\
|
||||
{"GetContainerChangesSize", WorldFunctions::GetContainerChangesSize},\
|
||||
{"GetContainerItemRefId", WorldFunctions::GetContainerItemRefId},\
|
||||
|
@ -54,8 +53,9 @@
|
|||
{"AddWorldObject", WorldFunctions::AddWorldObject},\
|
||||
{"AddContainerItem", WorldFunctions::AddContainerItem},\
|
||||
\
|
||||
{"SendObjectDelete", WorldFunctions::SendObjectDelete},\
|
||||
{"SendObjectPlace", WorldFunctions::SendObjectPlace},\
|
||||
{"SendObjectSpawn", WorldFunctions::SendObjectSpawn},\
|
||||
{"SendObjectDelete", WorldFunctions::SendObjectDelete},\
|
||||
{"SendObjectLock", WorldFunctions::SendObjectLock},\
|
||||
{"SendObjectTrap", WorldFunctions::SendObjectTrap},\
|
||||
{"SendObjectScale", WorldFunctions::SendObjectScale},\
|
||||
|
@ -91,7 +91,6 @@ public:
|
|||
static double GetObjectRotX(unsigned int i) noexcept;
|
||||
static double GetObjectRotY(unsigned int i) noexcept;
|
||||
static double GetObjectRotZ(unsigned int i) noexcept;
|
||||
static bool GetObjectIsActor(unsigned int i) noexcept;
|
||||
|
||||
static unsigned int GetContainerChangesSize(unsigned int objectIndex) noexcept;
|
||||
static const char *GetContainerItemRefId(unsigned int objectIndex, unsigned int itemIndex) noexcept;
|
||||
|
@ -122,8 +121,9 @@ public:
|
|||
static void AddWorldObject() noexcept;
|
||||
static void AddContainerItem() noexcept;
|
||||
|
||||
static void SendObjectDelete() noexcept;
|
||||
static void SendObjectPlace() noexcept;
|
||||
static void SendObjectSpawn() noexcept;
|
||||
static void SendObjectDelete() noexcept;
|
||||
static void SendObjectLock() noexcept;
|
||||
static void SendObjectTrap() noexcept;
|
||||
static void SendObjectScale() noexcept;
|
||||
|
|
|
@ -144,11 +144,11 @@ public:
|
|||
{"OnCellDeletion", Function<void, const char*>()},
|
||||
{"OnContainer", Function<void, unsigned short, const char*>()},
|
||||
{"OnDoorState", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectPlace", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectSpawn", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectDelete", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectLock", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectPlace", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectScale", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectSpawn", Function<void, unsigned short, const char*>()},
|
||||
{"OnObjectTrap", Function<void, unsigned short, const char*>()},
|
||||
{"OnActorList", Function<void, unsigned short, const char*>()},
|
||||
{"OnActorEquipment", Function<void, unsigned short, const char*>()},
|
||||
|
|
|
@ -63,12 +63,12 @@ void MechanicsHelper::spawnLeveledCreatures(MWWorld::CellStore* cellStore)
|
|||
MWWorld::ManualRef manualRef(store, id);
|
||||
manualRef.getPtr().getCellRef().setPosition(ptr.getCellRef().getPosition());
|
||||
MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->placeObject(manualRef.getPtr(), ptr.getCell(), ptr.getCellRef().getPosition());
|
||||
worldEvent->addObjectPlace(placed);
|
||||
worldEvent->addObjectSpawn(placed);
|
||||
MWBase::Environment::get().getWorld()->deleteObject(placed);
|
||||
}
|
||||
}
|
||||
|
||||
worldEvent->sendObjectPlace();
|
||||
worldEvent->sendObjectSpawn();
|
||||
}
|
||||
|
||||
Attack *MechanicsHelper::getLocalAttack(const MWWorld::Ptr& ptr)
|
||||
|
|
|
@ -162,6 +162,36 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore)
|
|||
}
|
||||
}
|
||||
|
||||
void WorldEvent::spawnObjects(MWWorld::CellStore* cellStore)
|
||||
{
|
||||
WorldObject worldObject;
|
||||
|
||||
for (unsigned int i = 0; i < worldObjectCount; i++)
|
||||
{
|
||||
worldObject = worldObjects.at(i);
|
||||
|
||||
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i", worldObject.refId.c_str(),
|
||||
worldObject.refNumIndex, worldObject.mpNum);
|
||||
|
||||
MWWorld::Ptr ptrFound = cellStore->searchExact(0, worldObject.mpNum);
|
||||
|
||||
// Only create this object if it doesn't already exist
|
||||
if (!ptrFound)
|
||||
{
|
||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), worldObject.refId, 1);
|
||||
MWWorld::Ptr newPtr = ref.getPtr();
|
||||
|
||||
newPtr.getCellRef().setMpNum(worldObject.mpNum);
|
||||
|
||||
newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, cellStore, worldObject.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_APPEND(Log::LOG_VERBOSE, "-- Object already existed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WorldEvent::deleteObjects(MWWorld::CellStore* cellStore)
|
||||
{
|
||||
WorldObject worldObject;
|
||||
|
@ -506,7 +536,21 @@ void WorldEvent::addObjectPlace(const MWWorld::Ptr& ptr)
|
|||
// Get the real count of gold in a stack
|
||||
worldObject.goldValue = ptr.getCellRef().getGoldValue();
|
||||
|
||||
worldObject.isActor = ptr.getClass().isActor();
|
||||
addObject(worldObject);
|
||||
}
|
||||
|
||||
void WorldEvent::addObjectSpawn(const MWWorld::Ptr& ptr)
|
||||
{
|
||||
cell = *ptr.getCell()->getCell();
|
||||
|
||||
mwmp::WorldObject worldObject;
|
||||
worldObject.refId = ptr.getCellRef().getRefId();
|
||||
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
|
||||
worldObject.mpNum = 0;
|
||||
|
||||
// Make sure we send the RefData position instead of the CellRef one, because that's what
|
||||
// we actually see on this client
|
||||
worldObject.position = ptr.getRefData().getPosition();
|
||||
|
||||
addObject(worldObject);
|
||||
}
|
||||
|
@ -658,6 +702,22 @@ void WorldEvent::sendObjectPlace()
|
|||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send();
|
||||
}
|
||||
|
||||
void WorldEvent::sendObjectSpawn()
|
||||
{
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_SPAWN about %s", cell.getDescription().c_str());
|
||||
|
||||
for (std::vector<mwmp::WorldObject>::iterator it = worldObjects.begin(); it != worldObjects.end(); ++it)
|
||||
{
|
||||
mwmp::WorldObject worldObject = (*it);
|
||||
|
||||
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s-%i",
|
||||
worldObject.refId.c_str(), worldObject.refNumIndex);
|
||||
}
|
||||
|
||||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SPAWN)->setEvent(this);
|
||||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SPAWN)->Send();
|
||||
}
|
||||
|
||||
void WorldEvent::sendObjectDelete()
|
||||
{
|
||||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->setEvent(this);
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace mwmp
|
|||
void editContainers(MWWorld::CellStore* cellStore);
|
||||
|
||||
void placeObjects(MWWorld::CellStore* cellStore);
|
||||
void spawnObjects(MWWorld::CellStore* cellStore);
|
||||
void deleteObjects(MWWorld::CellStore* cellStore);
|
||||
void lockObjects(MWWorld::CellStore* cellStore);
|
||||
void triggerTrapObjects(MWWorld::CellStore* cellStore);
|
||||
|
@ -39,6 +40,7 @@ namespace mwmp
|
|||
void playVideo();
|
||||
|
||||
void addObjectPlace(const MWWorld::Ptr& ptr);
|
||||
void addObjectSpawn(const MWWorld::Ptr& ptr);
|
||||
void addObjectDelete(const MWWorld::Ptr& ptr);
|
||||
void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel);
|
||||
void addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed);
|
||||
|
@ -53,6 +55,7 @@ namespace mwmp
|
|||
void addScriptGlobalShort(std::string varName, int shortVal);
|
||||
|
||||
void sendObjectPlace();
|
||||
void sendObjectSpawn();
|
||||
void sendObjectDelete();
|
||||
void sendObjectLock();
|
||||
void sendObjectTrap();
|
||||
|
|
|
@ -17,9 +17,8 @@ namespace mwmp
|
|||
{
|
||||
BaseObjectProcessor::Do(packet, event);
|
||||
|
||||
//event.spawnObjects(ptrCellStore);
|
||||
event.spawnObjects(ptrCellStore);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -554,13 +554,22 @@ namespace MWScript
|
|||
/*
|
||||
Start of tes3mp addition
|
||||
|
||||
Send an ID_OBJECT_PLACE packet every time an object is placed in the world
|
||||
through a script
|
||||
Send an ID_OBJECT_PLACE or ID_OBJECT_SPAWN packet every time an object is placed
|
||||
in the world through a script
|
||||
*/
|
||||
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
||||
worldEvent->reset();
|
||||
worldEvent->addObjectPlace(ptr);
|
||||
worldEvent->sendObjectPlace();
|
||||
|
||||
if (ptr.getClass().isActor())
|
||||
{
|
||||
worldEvent->addObjectSpawn(ptr);
|
||||
worldEvent->sendObjectSpawn();
|
||||
}
|
||||
else
|
||||
{
|
||||
worldEvent->addObjectPlace(ptr);
|
||||
worldEvent->sendObjectPlace();
|
||||
}
|
||||
/*
|
||||
End of tes3mp addition
|
||||
*/
|
||||
|
|
|
@ -3402,8 +3402,8 @@ namespace MWWorld
|
|||
|
||||
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
||||
worldEvent->reset();
|
||||
worldEvent->addObjectPlace(ptr);
|
||||
worldEvent->sendObjectPlace();
|
||||
worldEvent->addObjectSpawn(ptr);
|
||||
worldEvent->sendObjectSpawn();
|
||||
|
||||
MWBase::Environment::get().getWorld()->deleteObject(ptr);
|
||||
/*
|
||||
|
|
|
@ -47,7 +47,6 @@ namespace mwmp
|
|||
float floatVal;
|
||||
std::string varName;
|
||||
|
||||
bool isActor;
|
||||
bool isDisarmed;
|
||||
|
||||
std::vector<ContainerItem> containerItems;
|
||||
|
|
|
@ -36,7 +36,7 @@ void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send)
|
|||
RW(actor.cell.mName, send, 1);
|
||||
|
||||
RW(actor.position, send, 1);
|
||||
RW(actor.direction, send, 1);
|
||||
RW(actor.direction.pos, send, 1);
|
||||
|
||||
if (!send)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,6 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, bool send)
|
|||
RW(worldObject.charge, send);
|
||||
RW(worldObject.goldValue, send);
|
||||
RW(worldObject.position, send);
|
||||
RW(worldObject.isActor, send);
|
||||
|
||||
if (!send)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue