include local variable state in saved games

This commit is contained in:
Marc Zinnschlag 2014-03-22 15:00:49 +01:00
parent 4d80bc009a
commit 6bd3b3ee78
3 changed files with 26 additions and 6 deletions

View file

@ -10,16 +10,24 @@ void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state)
{ {
mRef = state.mRef; mRef = state.mRef;
mData = RefData (state); mData = RefData (state);
Ptr ptr (this); Ptr ptr (this);
if (state.mHasLocals)
mData.setLocals (state.mLocals, mClass->getScript (ptr));
mClass->readAdditionalState (ptr, state); mClass->readAdditionalState (ptr, state);
} }
void MWWorld::LiveCellRefBase::saveImp (ESM::ObjectState& state) const void MWWorld::LiveCellRefBase::saveImp (ESM::ObjectState& state) const
{ {
state.mRef = mRef; state.mRef = mRef;
mData.write (state);
/// \todo get rid of this cast once const-correct Ptr are available /// \todo get rid of this cast once const-correct Ptr are available
Ptr ptr (const_cast<LiveCellRefBase *> (this)); Ptr ptr (const_cast<LiveCellRefBase *> (this));
mData.write (state, mClass->getScript (ptr));
mClass->writeAdditionalState (ptr, state); mClass->writeAdditionalState (ptr, state);
} }

View file

@ -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.mEnabled = mEnabled;
objectState.mCount = mCount; objectState.mCount = mCount;
objectState.mPosition = mPosition; 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) void RefData::setCount (int count)
{ {
if(count == 0) if(count == 0)

View file

@ -64,9 +64,9 @@ namespace MWWorld
~RefData(); ~RefData();
void write (ESM::ObjectState& objectState) const; void write (ESM::ObjectState& objectState, const std::string& scriptId = "") const;
///< Ignores local variables and custom data (not enough context available here to ///< Ignores custom data (not enough context available here to
/// perform these operations). /// perform this operations).
RefData& operator= (const RefData& refData); RefData& operator= (const RefData& refData);
@ -83,6 +83,8 @@ namespace MWWorld
void setLocals (const ESM::Script& script); void setLocals (const ESM::Script& script);
void setLocals (const ESM::Locals& locals, const std::string& scriptId);
void setCount (int count); void setCount (int count);
/// Set object count (an object pile is a simple object with a count >1). /// Set object count (an object pile is a simple object with a count >1).
/// ///