mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-31 15:32:45 +00:00
partially store creature state in saved game files (only attributes and dynamics for now)
This commit is contained in:
parent
b0532e0c85
commit
9788bbcab9
@ -766,8 +766,11 @@ namespace MWClass
|
||||
|
||||
ensureCustomData (ptr);
|
||||
|
||||
dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore->
|
||||
readState (state2.mInventory);
|
||||
CustomData& customData = dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData());
|
||||
|
||||
customData.mContainerStore->readState (state2.mInventory);
|
||||
customData.mCreatureStats.readState (state2.mCreatureStats);
|
||||
|
||||
}
|
||||
|
||||
void Creature::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
|
||||
@ -777,8 +780,10 @@ namespace MWClass
|
||||
|
||||
ensureCustomData (ptr);
|
||||
|
||||
dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore->
|
||||
writeState (state2.mInventory);
|
||||
CustomData& customData = dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData());
|
||||
|
||||
customData.mContainerStore->writeState (state2.mInventory);
|
||||
customData.mCreatureStats.writeState (state2.mCreatureStats);
|
||||
}
|
||||
|
||||
const ESM::GameSetting* Creature::fMinWalkSpeedCreature;
|
||||
|
@ -1282,6 +1282,7 @@ namespace MWClass
|
||||
|
||||
customData.mInventoryStore.readState (state2.mInventory);
|
||||
customData.mNpcStats.readState (state2.mNpcStats);
|
||||
static_cast<MWMechanics::CreatureStats&> (customData.mNpcStats).readState (state2.mCreatureStats);
|
||||
}
|
||||
|
||||
void Npc::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
|
||||
@ -1295,6 +1296,7 @@ namespace MWClass
|
||||
|
||||
customData.mInventoryStore.writeState (state2.mInventory);
|
||||
customData.mNpcStats.writeState (state2.mNpcStats);
|
||||
static_cast<const MWMechanics::CreatureStats&> (customData.mNpcStats).writeState (state2.mCreatureStats);
|
||||
}
|
||||
|
||||
const ESM::GameSetting *Npc::fMinWalkSpeed;
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <components/esm/creaturestats.hpp>
|
||||
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
@ -457,4 +459,21 @@ namespace MWMechanics
|
||||
mAttackStrength = value;
|
||||
}
|
||||
|
||||
void CreatureStats::writeState (ESM::CreatureStats& state) const
|
||||
{
|
||||
for (int i=0; i<8; ++i)
|
||||
mAttributes[i].writeState (state.mAttributes[i]);
|
||||
|
||||
for (int i=0; i<3; ++i)
|
||||
mDynamic[i].writeState (state.mDynamic[i]);
|
||||
}
|
||||
|
||||
void CreatureStats::readState (const ESM::CreatureStats& state)
|
||||
{
|
||||
for (int i=0; i<8; ++i)
|
||||
mAttributes[i].readState (state.mAttributes[i]);
|
||||
|
||||
for (int i=0; i<3; ++i)
|
||||
mDynamic[i].readState (state.mDynamic[i]);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,11 @@
|
||||
#include "aisequence.hpp"
|
||||
#include "drawstate.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
struct CreatureStats;
|
||||
}
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
/// \brief Common creature stats
|
||||
@ -212,6 +217,10 @@ namespace MWMechanics
|
||||
std::set<int> mBoundItems;
|
||||
// Same as above
|
||||
std::map<int, std::string> mSummonedCreatures;
|
||||
|
||||
void writeState (ESM::CreatureStats& state) const;
|
||||
|
||||
void readState (const ESM::CreatureStats& state);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -437,7 +437,6 @@ void MWMechanics::NpcStats::writeState (ESM::NpcStats& state) const
|
||||
{
|
||||
mSkill[i].writeState (state.mSkills[i].mRegular);
|
||||
mWerewolfSkill[i].writeState (state.mSkills[i].mWerewolf);
|
||||
state.mSkills[i].mIncrease = mSkillIncreases[i];
|
||||
}
|
||||
|
||||
state.mBounty = mBounty;
|
||||
@ -456,6 +455,9 @@ void MWMechanics::NpcStats::writeState (ESM::NpcStats& state) const
|
||||
state.mAttackStrength = mAttackStrength;
|
||||
state.mLevelProgress = mLevelProgress;
|
||||
|
||||
for (int i=0; i<8; ++i)
|
||||
state.mSkillIncrease[i] = mSkillIncreases[i];
|
||||
|
||||
std::copy (mUsedIds.begin(), mUsedIds.end(), std::back_inserter (state.mUsedIds));
|
||||
|
||||
state.mTimeToStartDrowning = mTimeToStartDrowning;
|
||||
@ -484,7 +486,6 @@ void MWMechanics::NpcStats::readState (const ESM::NpcStats& state)
|
||||
{
|
||||
mSkill[i].readState (state.mSkills[i].mRegular);
|
||||
mWerewolfSkill[i].readState (state.mSkills[i].mWerewolf);
|
||||
mSkillIncreases[i] = state.mSkills[i].mIncrease;
|
||||
}
|
||||
|
||||
mBounty = state.mBounty;
|
||||
@ -494,6 +495,9 @@ void MWMechanics::NpcStats::readState (const ESM::NpcStats& state)
|
||||
mAttackStrength = state.mAttackStrength;
|
||||
mLevelProgress = state.mLevelProgress;
|
||||
|
||||
for (int i=0; i<8; ++i)
|
||||
mSkillIncreases[i] = state.mSkillIncrease[i];
|
||||
|
||||
std::copy (state.mUsedIds.begin(), state.mUsedIds.end(), std::inserter (mUsedIds, mUsedIds.begin()));
|
||||
|
||||
mTimeToStartDrowning = state.mTimeToStartDrowning;
|
||||
|
@ -88,6 +88,18 @@ namespace MWMechanics
|
||||
{
|
||||
mModified = mBase + modifier;
|
||||
}
|
||||
|
||||
void writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModified;
|
||||
}
|
||||
|
||||
void readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModified = state.mMod;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -192,6 +204,18 @@ namespace MWMechanics
|
||||
mStatic.setModifier (modifier);
|
||||
setCurrent (getCurrent()+diff);
|
||||
}
|
||||
|
||||
void writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
mStatic.writeState (state);
|
||||
state.mCurrent = mCurrent;
|
||||
}
|
||||
|
||||
void readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mStatic.readState (state);
|
||||
mCurrent = state.mCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -45,7 +45,7 @@ add_component_dir (esm
|
||||
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
|
||||
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
|
||||
savedgame journalentry queststate locals globalscript player objectstate cellid cellstate globalmap lightstate inventorystate containerstate npcstate creaturestate dialoguestate statstate
|
||||
npcstats
|
||||
npcstats creaturestats
|
||||
)
|
||||
|
||||
add_component_dir (misc
|
||||
|
@ -6,6 +6,8 @@ void ESM::CreatureState::load (ESMReader &esm)
|
||||
ObjectState::load (esm);
|
||||
|
||||
mInventory.load (esm);
|
||||
|
||||
mCreatureStats.load (esm);
|
||||
}
|
||||
|
||||
void ESM::CreatureState::save (ESMWriter &esm, bool inInventory) const
|
||||
@ -13,4 +15,6 @@ void ESM::CreatureState::save (ESMWriter &esm, bool inInventory) const
|
||||
ObjectState::save (esm, inInventory);
|
||||
|
||||
mInventory.save (esm);
|
||||
|
||||
mCreatureStats.save (esm);
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "objectstate.hpp"
|
||||
#include "inventorystate.hpp"
|
||||
#include "creaturestats.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
@ -11,6 +12,7 @@ namespace ESM
|
||||
struct CreatureState : public ObjectState
|
||||
{
|
||||
InventoryState mInventory;
|
||||
CreatureStats mCreatureStats;
|
||||
|
||||
virtual void load (ESMReader &esm);
|
||||
virtual void save (ESMWriter &esm, bool inInventory = false) const;
|
||||
|
20
components/esm/creaturestats.cpp
Normal file
20
components/esm/creaturestats.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
#include "creaturestats.hpp"
|
||||
|
||||
void ESM::CreatureStats::load (ESMReader &esm)
|
||||
{
|
||||
for (int i=0; i<8; ++i)
|
||||
mAttributes[i].load (esm);
|
||||
|
||||
for (int i=0; i<3; ++i)
|
||||
mDynamic[i].load (esm);
|
||||
}
|
||||
|
||||
void ESM::CreatureStats::save (ESMWriter &esm) const
|
||||
{
|
||||
for (int i=0; i<8; ++i)
|
||||
mAttributes[i].save (esm);
|
||||
|
||||
for (int i=0; i<3; ++i)
|
||||
mDynamic[i].save (esm);
|
||||
}
|
27
components/esm/creaturestats.hpp
Normal file
27
components/esm/creaturestats.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef OPENMW_ESM_CREATURESTATS_H
|
||||
#define OPENMW_ESM_CREATURESTATS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "statstate.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
// format 0, saved games only
|
||||
|
||||
struct CreatureStats
|
||||
{
|
||||
StatState<int> mAttributes[8];
|
||||
StatState<float> mDynamic[3];
|
||||
|
||||
void load (ESMReader &esm);
|
||||
void save (ESMWriter &esm) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -13,6 +13,7 @@ namespace ESM
|
||||
{
|
||||
T mBase;
|
||||
T mMod;
|
||||
T mCurrent;
|
||||
T mDamage;
|
||||
float mProgress;
|
||||
|
||||
@ -23,13 +24,15 @@ namespace ESM
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
StatState<T>::StatState() : mBase (0), mMod (0), mDamage (0), mProgress (0) {}
|
||||
StatState<T>::StatState() : mBase (0), mMod (0), mCurrent (0), mDamage (0), mProgress (0) {}
|
||||
|
||||
template<typename T>
|
||||
void StatState<T>::load (ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mBase, "STBA");
|
||||
esm.getHNT (mMod, "STMO");
|
||||
mCurrent = 0;
|
||||
esm.getHNOT (mCurrent, "STCU");
|
||||
mDamage = 0;
|
||||
esm.getHNOT (mDamage, "STDA");
|
||||
mProgress = 0;
|
||||
@ -42,6 +45,9 @@ namespace ESM
|
||||
esm.writeHNT ("STBA", mBase);
|
||||
esm.writeHNT ("STMO", mMod);
|
||||
|
||||
if (mCurrent)
|
||||
esm.writeHNT ("STCU", mCurrent);
|
||||
|
||||
if (mDamage)
|
||||
esm.writeHNT ("STDA", mDamage);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user