Break away from OpenMW by giving RefNum indexes to new created objects

coverity_scan^2
David Cernat 8 years ago
parent 3c88f6f0cd
commit a4647de048

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

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

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

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

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

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

@ -75,6 +75,9 @@ namespace MWWorld
std::vector<std::string> 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);

Loading…
Cancel
Save