diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index d71704fd7..c15f63abe 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -10,16 +10,24 @@ void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state) { mRef = state.mRef; mData = RefData (state); + Ptr ptr (this); + + if (state.mHasLocals) + mData.setLocals (state.mLocals, mClass->getScript (ptr)); + mClass->readAdditionalState (ptr, state); } void MWWorld::LiveCellRefBase::saveImp (ESM::ObjectState& state) const { state.mRef = mRef; - mData.write (state); + /// \todo get rid of this cast once const-correct Ptr are available Ptr ptr (const_cast (this)); + + mData.write (state, mClass->getScript (ptr)); + mClass->writeAdditionalState (ptr, state); } diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index 8d48078b1..907204739 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -76,9 +76,13 @@ namespace MWWorld } } - void RefData::write (ESM::ObjectState& objectState) const + void RefData::write (ESM::ObjectState& objectState, const std::string& scriptId) const { - objectState.mHasLocals = false; + objectState.mHasLocals = mHasLocals; + + if (mHasLocals) + mLocals.write (objectState.mLocals, scriptId); + objectState.mEnabled = mEnabled; objectState.mCount = mCount; objectState.mPosition = mPosition; @@ -148,6 +152,12 @@ namespace MWWorld } } + void RefData::setLocals (const ESM::Locals& locals, const std::string& scriptId) + { + mHasLocals = true; + mLocals.read (locals, scriptId); + } + void RefData::setCount (int count) { if(count == 0) diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 19e3d4882..a74eb838c 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -64,9 +64,9 @@ namespace MWWorld ~RefData(); - void write (ESM::ObjectState& objectState) const; - ///< Ignores local variables and custom data (not enough context available here to - /// perform these operations). + void write (ESM::ObjectState& objectState, const std::string& scriptId = "") const; + ///< Ignores custom data (not enough context available here to + /// perform this operations). RefData& operator= (const RefData& refData); @@ -83,6 +83,8 @@ namespace MWWorld void setLocals (const ESM::Script& script); + void setLocals (const ESM::Locals& locals, const std::string& scriptId); + void setCount (int count); /// Set object count (an object pile is a simple object with a count >1). ///