[General] Use ObjectSpawn instead of ObjectPlace for actors

0.6.1
David Cernat 8 years ago
parent c211d53190
commit 4e5c8873e0

@ -119,11 +119,6 @@ double WorldFunctions::GetObjectRotZ(unsigned int i) noexcept
return readEvent->worldObjects.at(i).position.rot[2]; 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 unsigned int WorldFunctions::GetContainerChangesSize(unsigned int objectIndex) noexcept
{ {
return readEvent->worldObjects.at(objectIndex).containerItemCount; return readEvent->worldObjects.at(objectIndex).containerItemCount;
@ -256,18 +251,24 @@ void WorldFunctions::AddContainerItem() noexcept
tempContainerItem = emptyContainerItem; 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 void WorldFunctions::SendObjectPlace() noexcept
{ {
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->setEvent(&writeEvent); mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->setEvent(&writeEvent);
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->Send(writeEvent.guid); 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 void WorldFunctions::SendObjectLock() noexcept
{ {
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->setEvent(&writeEvent); mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->setEvent(&writeEvent);

@ -23,7 +23,6 @@
{"GetObjectRotX", WorldFunctions::GetObjectRotX},\ {"GetObjectRotX", WorldFunctions::GetObjectRotX},\
{"GetObjectRotY", WorldFunctions::GetObjectRotY},\ {"GetObjectRotY", WorldFunctions::GetObjectRotY},\
{"GetObjectRotZ", WorldFunctions::GetObjectRotZ},\ {"GetObjectRotZ", WorldFunctions::GetObjectRotZ},\
{"GetObjectIsActor", WorldFunctions::GetObjectIsActor},\
\ \
{"GetContainerChangesSize", WorldFunctions::GetContainerChangesSize},\ {"GetContainerChangesSize", WorldFunctions::GetContainerChangesSize},\
{"GetContainerItemRefId", WorldFunctions::GetContainerItemRefId},\ {"GetContainerItemRefId", WorldFunctions::GetContainerItemRefId},\
@ -54,8 +53,9 @@
{"AddWorldObject", WorldFunctions::AddWorldObject},\ {"AddWorldObject", WorldFunctions::AddWorldObject},\
{"AddContainerItem", WorldFunctions::AddContainerItem},\ {"AddContainerItem", WorldFunctions::AddContainerItem},\
\ \
{"SendObjectDelete", WorldFunctions::SendObjectDelete},\
{"SendObjectPlace", WorldFunctions::SendObjectPlace},\ {"SendObjectPlace", WorldFunctions::SendObjectPlace},\
{"SendObjectSpawn", WorldFunctions::SendObjectSpawn},\
{"SendObjectDelete", WorldFunctions::SendObjectDelete},\
{"SendObjectLock", WorldFunctions::SendObjectLock},\ {"SendObjectLock", WorldFunctions::SendObjectLock},\
{"SendObjectTrap", WorldFunctions::SendObjectTrap},\ {"SendObjectTrap", WorldFunctions::SendObjectTrap},\
{"SendObjectScale", WorldFunctions::SendObjectScale},\ {"SendObjectScale", WorldFunctions::SendObjectScale},\
@ -91,7 +91,6 @@ public:
static double GetObjectRotX(unsigned int i) noexcept; static double GetObjectRotX(unsigned int i) noexcept;
static double GetObjectRotY(unsigned int i) noexcept; static double GetObjectRotY(unsigned int i) noexcept;
static double GetObjectRotZ(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 unsigned int GetContainerChangesSize(unsigned int objectIndex) noexcept;
static const char *GetContainerItemRefId(unsigned int objectIndex, unsigned int itemIndex) noexcept; static const char *GetContainerItemRefId(unsigned int objectIndex, unsigned int itemIndex) noexcept;
@ -122,8 +121,9 @@ public:
static void AddWorldObject() noexcept; static void AddWorldObject() noexcept;
static void AddContainerItem() noexcept; static void AddContainerItem() noexcept;
static void SendObjectDelete() noexcept;
static void SendObjectPlace() noexcept; static void SendObjectPlace() noexcept;
static void SendObjectSpawn() noexcept;
static void SendObjectDelete() noexcept;
static void SendObjectLock() noexcept; static void SendObjectLock() noexcept;
static void SendObjectTrap() noexcept; static void SendObjectTrap() noexcept;
static void SendObjectScale() noexcept; static void SendObjectScale() noexcept;

@ -144,11 +144,11 @@ public:
{"OnCellDeletion", Function<void, const char*>()}, {"OnCellDeletion", Function<void, const char*>()},
{"OnContainer", Function<void, unsigned short, const char*>()}, {"OnContainer", Function<void, unsigned short, const char*>()},
{"OnDoorState", 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*>()}, {"OnObjectDelete", Function<void, unsigned short, const char*>()},
{"OnObjectLock", 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*>()}, {"OnObjectScale", Function<void, unsigned short, const char*>()},
{"OnObjectSpawn", Function<void, unsigned short, const char*>()},
{"OnObjectTrap", Function<void, unsigned short, const char*>()}, {"OnObjectTrap", Function<void, unsigned short, const char*>()},
{"OnActorList", Function<void, unsigned short, const char*>()}, {"OnActorList", Function<void, unsigned short, const char*>()},
{"OnActorEquipment", 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); MWWorld::ManualRef manualRef(store, id);
manualRef.getPtr().getCellRef().setPosition(ptr.getCellRef().getPosition()); manualRef.getPtr().getCellRef().setPosition(ptr.getCellRef().getPosition());
MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->placeObject(manualRef.getPtr(), ptr.getCell(), 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); MWBase::Environment::get().getWorld()->deleteObject(placed);
} }
} }
worldEvent->sendObjectPlace(); worldEvent->sendObjectSpawn();
} }
Attack *MechanicsHelper::getLocalAttack(const MWWorld::Ptr& ptr) 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) void WorldEvent::deleteObjects(MWWorld::CellStore* cellStore)
{ {
WorldObject worldObject; WorldObject worldObject;
@ -506,7 +536,21 @@ void WorldEvent::addObjectPlace(const MWWorld::Ptr& ptr)
// Get the real count of gold in a stack // Get the real count of gold in a stack
worldObject.goldValue = ptr.getCellRef().getGoldValue(); 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); addObject(worldObject);
} }
@ -658,6 +702,22 @@ void WorldEvent::sendObjectPlace()
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(); 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() void WorldEvent::sendObjectDelete()
{ {
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->setEvent(this); mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->setEvent(this);

@ -21,6 +21,7 @@ namespace mwmp
void editContainers(MWWorld::CellStore* cellStore); void editContainers(MWWorld::CellStore* cellStore);
void placeObjects(MWWorld::CellStore* cellStore); void placeObjects(MWWorld::CellStore* cellStore);
void spawnObjects(MWWorld::CellStore* cellStore);
void deleteObjects(MWWorld::CellStore* cellStore); void deleteObjects(MWWorld::CellStore* cellStore);
void lockObjects(MWWorld::CellStore* cellStore); void lockObjects(MWWorld::CellStore* cellStore);
void triggerTrapObjects(MWWorld::CellStore* cellStore); void triggerTrapObjects(MWWorld::CellStore* cellStore);
@ -39,6 +40,7 @@ namespace mwmp
void playVideo(); void playVideo();
void addObjectPlace(const MWWorld::Ptr& ptr); void addObjectPlace(const MWWorld::Ptr& ptr);
void addObjectSpawn(const MWWorld::Ptr& ptr);
void addObjectDelete(const MWWorld::Ptr& ptr); void addObjectDelete(const MWWorld::Ptr& ptr);
void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel); void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel);
void addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed); 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 addScriptGlobalShort(std::string varName, int shortVal);
void sendObjectPlace(); void sendObjectPlace();
void sendObjectSpawn();
void sendObjectDelete(); void sendObjectDelete();
void sendObjectLock(); void sendObjectLock();
void sendObjectTrap(); void sendObjectTrap();

@ -17,9 +17,8 @@ namespace mwmp
{ {
BaseObjectProcessor::Do(packet, event); BaseObjectProcessor::Do(packet, event);
//event.spawnObjects(ptrCellStore); event.spawnObjects(ptrCellStore);
} }
}; };
} }

@ -554,13 +554,22 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_OBJECT_PLACE packet every time an object is placed in the world Send an ID_OBJECT_PLACE or ID_OBJECT_SPAWN packet every time an object is placed
through a script in the world through a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->reset(); 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 End of tes3mp addition
*/ */

@ -3402,8 +3402,8 @@ namespace MWWorld
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->reset(); worldEvent->reset();
worldEvent->addObjectPlace(ptr); worldEvent->addObjectSpawn(ptr);
worldEvent->sendObjectPlace(); worldEvent->sendObjectSpawn();
MWBase::Environment::get().getWorld()->deleteObject(ptr); MWBase::Environment::get().getWorld()->deleteObject(ptr);
/* /*

@ -47,7 +47,6 @@ namespace mwmp
float floatVal; float floatVal;
std::string varName; std::string varName;
bool isActor;
bool isDisarmed; bool isDisarmed;
std::vector<ContainerItem> containerItems; std::vector<ContainerItem> containerItems;

@ -36,7 +36,7 @@ void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send)
RW(actor.cell.mName, send, 1); RW(actor.cell.mName, send, 1);
RW(actor.position, send, 1); RW(actor.position, send, 1);
RW(actor.direction, send, 1); RW(actor.direction.pos, send, 1);
if (!send) if (!send)
{ {

@ -40,7 +40,6 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, bool send)
RW(worldObject.charge, send); RW(worldObject.charge, send);
RW(worldObject.goldValue, send); RW(worldObject.goldValue, send);
RW(worldObject.position, send); RW(worldObject.position, send);
RW(worldObject.isActor, send);
if (!send) if (!send)
{ {

Loading…
Cancel
Save