store NPC state in saved game files
parent
9f721fd144
commit
b0532e0c85
@ -0,0 +1,29 @@
|
||||
|
||||
#include "stat.hpp"
|
||||
|
||||
void MWMechanics::AttributeValue::writeState (ESM::StatState<int>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModifier;
|
||||
state.mDamage = mDamage;
|
||||
}
|
||||
|
||||
void MWMechanics::AttributeValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModifier = state.mMod;
|
||||
mDamage = state.mDamage;
|
||||
}
|
||||
|
||||
|
||||
void MWMechanics::SkillValue::writeState (ESM::StatState<int>& state) const
|
||||
{
|
||||
AttributeValue::writeState (state);
|
||||
state.mProgress = mProgress;
|
||||
}
|
||||
|
||||
void MWMechanics::SkillValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
AttributeValue::readState (state);
|
||||
mProgress = state.mProgress;
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
|
||||
#include "npcstats.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
ESM::NpcStats::Faction::Faction() : mExpelled (false), mRank (0), mReputation (0) {}
|
||||
|
||||
void ESM::NpcStats::load (ESMReader &esm)
|
||||
{
|
||||
while (esm.isNextSub ("FACT"))
|
||||
{
|
||||
std::string id = esm.getHString();
|
||||
|
||||
Faction faction;
|
||||
|
||||
int expelled = 0;
|
||||
esm.getHNOT (expelled, "FAEX");
|
||||
|
||||
if (expelled)
|
||||
faction.mExpelled = true;
|
||||
|
||||
esm.getHNOT (faction.mRank, "FARA");
|
||||
|
||||
esm.getHNOT (faction.mReputation, "FARE");
|
||||
|
||||
mFactions.insert (std::make_pair (id, faction));
|
||||
}
|
||||
|
||||
mDisposition = 0;
|
||||
esm.getHNOT (mDisposition, "DISP");
|
||||
|
||||
for (int i=0; i<27; ++i)
|
||||
{
|
||||
mSkills[i].mRegular.load (esm);
|
||||
mSkills[i].mWerewolf.load (esm);
|
||||
}
|
||||
|
||||
mBounty = 0;
|
||||
esm.getHNOT (mBounty, "BOUN");
|
||||
|
||||
mReputation = 0;
|
||||
esm.getHNOT (mReputation, "REPU");
|
||||
|
||||
mWerewolfKills = 0;
|
||||
esm.getHNOT (mWerewolfKills, "WKIL");
|
||||
|
||||
mProfit = 0;
|
||||
esm.getHNOT (mProfit, "PROF");
|
||||
|
||||
mAttackStrength = 0;
|
||||
esm.getHNOT (mAttackStrength, "ASTR");
|
||||
|
||||
mLevelProgress = 0;
|
||||
esm.getHNOT (mLevelProgress, "LPRO");
|
||||
|
||||
esm.getHNT (mSkillIncrease, "INCR");
|
||||
|
||||
while (esm.isNextSub ("USED"))
|
||||
mUsedIds.push_back (esm.getHString());
|
||||
|
||||
mTimeToStartDrowning = 0;
|
||||
esm.getHNOT (mTimeToStartDrowning, "DRTI");
|
||||
|
||||
mLastDrowningHit = 0;
|
||||
esm.getHNOT (mLastDrowningHit, "DRLH");
|
||||
|
||||
mLevelHealthBonus = 0;
|
||||
esm.getHNOT (mLevelHealthBonus, "LVLH");
|
||||
}
|
||||
|
||||
void ESM::NpcStats::save (ESMWriter &esm) const
|
||||
{
|
||||
for (std::map<std::string, Faction>::const_iterator iter (mFactions.begin());
|
||||
iter!=mFactions.end(); ++iter)
|
||||
{
|
||||
esm.writeHNString ("FACT", iter->first);
|
||||
|
||||
if (iter->second.mExpelled)
|
||||
{
|
||||
int expelled = 1;
|
||||
esm.writeHNT ("FAEX", expelled);
|
||||
}
|
||||
|
||||
if (iter->second.mRank)
|
||||
esm.writeHNT ("FARA", iter->second.mRank);
|
||||
|
||||
if (iter->second.mReputation)
|
||||
esm.writeHNT ("FARE", iter->second.mReputation);
|
||||
}
|
||||
|
||||
if (mDisposition)
|
||||
esm.writeHNT ("DISP", mDisposition);
|
||||
|
||||
for (int i=0; i<27; ++i)
|
||||
{
|
||||
mSkills[i].mRegular.save (esm);
|
||||
mSkills[i].mWerewolf.save (esm);
|
||||
}
|
||||
|
||||
if (mBounty)
|
||||
esm.writeHNT ("BOUN", mBounty);
|
||||
|
||||
if (mReputation)
|
||||
esm.writeHNT ("REPU", mReputation);
|
||||
|
||||
if (mWerewolfKills)
|
||||
esm.writeHNT ("WKIL", mWerewolfKills);
|
||||
|
||||
if (mProfit)
|
||||
esm.writeHNT ("PROF", mProfit);
|
||||
|
||||
if (mAttackStrength)
|
||||
esm.writeHNT ("ASTR", mAttackStrength);
|
||||
|
||||
if (mLevelProgress)
|
||||
esm.writeHNT ("LPRO", mLevelProgress);
|
||||
|
||||
esm.writeHNT ("INCR", mSkillIncrease);
|
||||
|
||||
for (std::vector<std::string>::const_iterator iter (mUsedIds.begin()); iter!=mUsedIds.end();
|
||||
++iter)
|
||||
esm.writeHNT ("USED", *iter);
|
||||
|
||||
if (mTimeToStartDrowning)
|
||||
esm.writeHNT ("DRTI", mTimeToStartDrowning);
|
||||
|
||||
if (mLastDrowningHit)
|
||||
esm.writeHNT ("DRLH", mLastDrowningHit);
|
||||
|
||||
if (mLevelHealthBonus)
|
||||
esm.writeHNT ("LVLH", mLevelHealthBonus);
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
#ifndef OPENMW_ESM_NPCSTATS_H
|
||||
#define OPENMW_ESM_NPCSTATS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "statstate.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
// format 0, saved games only
|
||||
|
||||
struct NpcStats
|
||||
{
|
||||
struct Skill
|
||||
{
|
||||
StatState<int> mRegular;
|
||||
StatState<int> mWerewolf;
|
||||
};
|
||||
|
||||
struct Faction
|
||||
{
|
||||
bool mExpelled;
|
||||
int mRank;
|
||||
int mReputation;
|
||||
|
||||
Faction();
|
||||
};
|
||||
|
||||
std::map<std::string, Faction> mFactions;
|
||||
int mDisposition;
|
||||
Skill mSkills[27];
|
||||
int mBounty;
|
||||
int mReputation;
|
||||
int mWerewolfKills;
|
||||
int mProfit;
|
||||
float mAttackStrength;
|
||||
int mLevelProgress;
|
||||
int mSkillIncrease[8];
|
||||
std::vector<std::string> mUsedIds;
|
||||
float mTimeToStartDrowning;
|
||||
float mLastDrowningHit;
|
||||
float mLevelHealthBonus;
|
||||
|
||||
void load (ESMReader &esm);
|
||||
void save (ESMWriter &esm) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,53 @@
|
||||
#ifndef OPENMW_ESM_STATSTATE_H
|
||||
#define OPENMW_ESM_STATSTATE_H
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
// format 0, saved games only
|
||||
|
||||
template<typename T>
|
||||
struct StatState
|
||||
{
|
||||
T mBase;
|
||||
T mMod;
|
||||
T mDamage;
|
||||
float mProgress;
|
||||
|
||||
StatState();
|
||||
|
||||
void load (ESMReader &esm);
|
||||
void save (ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
StatState<T>::StatState() : mBase (0), mMod (0), mDamage (0), mProgress (0) {}
|
||||
|
||||
template<typename T>
|
||||
void StatState<T>::load (ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mBase, "STBA");
|
||||
esm.getHNT (mMod, "STMO");
|
||||
mDamage = 0;
|
||||
esm.getHNOT (mDamage, "STDA");
|
||||
mProgress = 0;
|
||||
esm.getHNOT (mProgress, "STPR");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void StatState<T>::save (ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT ("STBA", mBase);
|
||||
esm.writeHNT ("STMO", mMod);
|
||||
|
||||
if (mDamage)
|
||||
esm.writeHNT ("STDA", mDamage);
|
||||
|
||||
if (mProgress)
|
||||
esm.writeHNT ("STPR", mProgress);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue