diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index da8ec6bc4..95cea6918 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -55,6 +55,14 @@ namespace MWGui if (setNewOwner) dropped.getCellRef().setOwner(""); + // Major change done by tes3mp: + // When the object is dropped, generate a new RefNum index for it that follows the last one + // in the cell, so that packets can be sent and received specifically about it, instead + // of giving it a RefNum index of 0 as in regular OpenMW + MWWorld::CellStore *cellStore = dropped.getCell(); + cellStore->setLastRefNumIndex(cellStore->getLastRefNumIndex() + 1); + dropped.getCellRef().setRefNumIndex(cellStore->getLastRefNumIndex()); + // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); event->cell = *dropped.getCell()->getCell(); @@ -66,7 +74,7 @@ namespace MWGui // automatically for stacks of gold event->count = dropped.getRefData().getCount(); - // For the real count of gold in a stack + // Get the real count of gold in a stack event->cellRef.mGoldValue = dropped.getCellRef().getGoldValue(); mwmp::Main::get().getNetworking()->GetWorldPacket(ID_OBJECT_PLACE)->Send(event); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 450d9c0c0..d1eaef391 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -713,12 +713,21 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), event->cellRef.mRefID, 1); MWWorld::Ptr newPtr = ref.getPtr(); - newPtr.getCellRef().setGoldValue(event->cellRef.mGoldValue); if (event->count > 1) newPtr.getRefData().setCount(event->count); - MWBase::Environment::get().getWorld()->placeObject(newPtr, ptrCellStore, event->cellRef.mPos); + newPtr.getCellRef().setGoldValue(event->cellRef.mGoldValue); + + newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, ptrCellStore, event->cellRef.mPos); + + // 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); break; } diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 98d898d1a..256cd42f4 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -536,6 +536,14 @@ namespace MWScript MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(), actor, actor.getCell(), direction, distance); + // Major change done by tes3mp: + // When the object is dropped, generate a new RefNum index for it that follows the last one + // in the cell, so that packets can be sent and received specifically about it, instead + // of giving it a RefNum index of 0 as in regular OpenMW + MWWorld::CellStore *cellStore = ptr.getCell(); + cellStore->setLastRefNumIndex(cellStore->getLastRefNumIndex() + 1); + ptr.getCellRef().setRefNumIndex(cellStore->getLastRefNumIndex()); + // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); event->cell = *ptr.getCell()->getCell(); diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index 0d81e0636..61b977252 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -20,6 +20,13 @@ namespace MWWorld mCellRef.mRefNum.unset(); } + // Added by tes3mp to allow creation of new items with RefNum indexes + // specific to them + void CellRef::setRefNumIndex(int index) + { + mCellRef.mRefNum.mIndex = index; + } + std::string CellRef::getRefId() const { return mCellRef.mRefID; diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp index b8e85f286..7147e6aa6 100644 --- a/apps/openmw/mwworld/cellref.hpp +++ b/apps/openmw/mwworld/cellref.hpp @@ -28,6 +28,10 @@ namespace MWWorld // Set RefNum to its default state. void unsetRefNum(); + // Added by tes3mp to allow creation of new items with RefNum indexes + // specific to them + void setRefNumIndex(int index); + /// Does the RefNum have a content file? bool hasContentFile() const; diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index b833ea821..258acd698 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -265,7 +265,7 @@ namespace MWWorld // Objects with no refnum can't be handled correctly in the merging process that happens // on a save/load, so do a simple copy & delete for these objects. - // The code below is disabled for TES3MP for as long as player objects lack refnums, + // The code below is disabled for tes3mp for as long as player objects lack refnums, // because it will break exterior cell transitions for them /* if (!object.getCellRef().getRefNum().hasContentFile()) @@ -356,6 +356,9 @@ namespace MWWorld : mStore(esmStore), mReader(readerList), mCell (cell), mState (State_Unloaded), mHasState (false), mLastRespawn(0,0) { mWaterLevel = cell->mWater; + + // Added by tes3mp + lastRefNumIndex = 0; } const ESM::Cell *CellStore::getCell() const @@ -473,6 +476,18 @@ namespace MWWorld return searchVisitor.mFound; } + // Added by tes3mp and used to get the last reference number in the cell + int CellStore::getLastRefNumIndex() const + { + return lastRefNumIndex; + } + + // Added by tes3mp and used to record the last reference number in the cell + void CellStore::setLastRefNumIndex(int value) + { + lastRefNumIndex = value; + } + float CellStore::getWaterLevel() const { if (isExterior()) @@ -626,6 +641,8 @@ namespace MWWorld loadRef (ref, deleted, refNumToID); } + setLastRefNumIndex(refNumToID.rbegin()->first.mIndex); + updateMergedRefs(); } diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index be672665f..364480173 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -75,6 +75,9 @@ namespace MWWorld std::vector mIds; float mWaterLevel; + // Added by tes3mp + int lastRefNumIndex; + MWWorld::TimeStamp mLastRespawn; // List of refs owned by this cell @@ -234,6 +237,12 @@ namespace MWWorld Ptr searchExact (const std::string& id, int numIndex); ///< Added by tes3mp and used to find an object by both its ID and its reference number + int getLastRefNumIndex() const; + // Added by tes3mp and used to get the last reference number in the cell + + void setLastRefNumIndex(int value); + // Added by tes3mp and used to record the last reference number in the cell + float getWaterLevel() const; void setWaterLevel (float level);