Werewolf stats compatibility with old save files

c++11
scrawl 10 years ago
parent d6a7255391
commit 2ce269c0fc

@ -447,16 +447,8 @@ void MWMechanics::NpcStats::writeState (ESM::NpcStats& state) const
state.mDisposition = mDisposition;
for (int i=0; i<ESM::Skill::Length; ++i)
{
mSkill[i].writeState (state.mSkills[i].mRegular);
//mWerewolfSkill[i].writeState (state.mSkills[i].mWerewolf);
}
/*
for (int i=0; i<ESM::Attribute::Length; ++i)
{
mWerewolfAttributes[i].writeState (state.mWerewolfAttributes[i]);
}
*/
mSkill[i].writeState (state.mSkills[i]);
state.mIsWerewolf = mIsWerewolf;
state.mCrimeId = mCrimeId;
@ -504,16 +496,7 @@ void MWMechanics::NpcStats::readState (const ESM::NpcStats& state)
mDisposition = state.mDisposition;
for (int i=0; i<ESM::Skill::Length; ++i)
{
mSkill[i].readState (state.mSkills[i].mRegular);
//mWerewolfSkill[i].readState (state.mSkills[i].mWerewolf);
}
/*
for (int i=0; i<ESM::Attribute::Length; ++i)
{
mWerewolfAttributes[i].readState (state.mWerewolfAttributes[i]);
}
*/
mSkill[i].readState (state.mSkills[i]);
mIsWerewolf = state.mIsWerewolf;

@ -301,6 +301,12 @@ namespace MWWorld
for (int i=0; i<ESM::Skill::Length; ++i)
mSaveSkills[i].readState(player.mSaveSkills[i]);
if (player.mObject.mNpcStats.mWerewolfDeprecatedData && player.mObject.mNpcStats.mIsWerewolf)
{
saveSkillsAttributes();
setWerewolfSkillsAttributes();
}
getPlayer().getClass().getCreatureStats(getPlayer()).getAiSequence().clear();
MWBase::World& world = *MWBase::Environment::get().getWorld();

@ -174,6 +174,17 @@ bool ESMReader::isNextSub(const char* name)
return !mCtx.subCached;
}
bool ESMReader::peekNextSub(const char *name)
{
if (!mCtx.leftRec)
return false;
getSubName();
mCtx.subCached = true;
return mCtx.subName == name;
}
// Read subrecord name. This gets called a LOT, so I've optimized it
// slightly.
void ESMReader::getSubName()

@ -185,6 +185,8 @@ public:
*/
bool isNextSub(const char* name);
bool peekNextSub(const char* name);
// Read subrecord name. This gets called a LOT, so I've optimized it
// slightly.
void getSubName();

@ -1,4 +1,3 @@
#include "npcstats.hpp"
#include "esmreader.hpp"
@ -31,18 +30,43 @@ void ESM::NpcStats::load (ESMReader &esm)
esm.getHNOT (mDisposition, "DISP");
for (int i=0; i<27; ++i)
mSkills[i].load (esm);
if (esm.peekNextSub("STBA"))
{
mSkills[i].mRegular.load (esm);
mSkills[i].mWerewolf.load (esm);
// we have deprecated werewolf skills, stored interleaved
// Load into one big vector, then remove every 2nd value
mWerewolfDeprecatedData = true;
std::vector<ESM::StatState<int> > skills(mSkills, mSkills + sizeof(mSkills)/sizeof(mSkills[0]));
for (int i=0; i<27; ++i)
{
ESM::StatState<int> skill;
skill.load(esm);
skills.push_back(skill);
}
int i=0;
for (std::vector<ESM::StatState<int> >::iterator it = skills.begin(); it != skills.end(); ++i)
{
if (i%2 == 1)
it = skills.erase(it);
else
++it;
}
assert(skills.size() == 27);
std::copy(skills.begin(), skills.end(), mSkills);
}
// No longer used
bool hasWerewolfAttributes = false;
esm.getHNOT (hasWerewolfAttributes, "HWAT");
if (hasWerewolfAttributes)
{
ESM::StatState<int> dummy;
for (int i=0; i<8; ++i)
mWerewolfAttributes[i].load (esm);
dummy.load(esm);
mWerewolfDeprecatedData = true;
}
mIsWerewolf = false;
@ -112,10 +136,7 @@ void ESM::NpcStats::save (ESMWriter &esm) const
esm.writeHNT ("DISP", mDisposition);
for (int i=0; i<27; ++i)
{
mSkills[i].mRegular.save (esm);
mSkills[i].mWerewolf.save (esm);
}
mSkills[i].save (esm);
if (mIsWerewolf)
esm.writeHNT ("WOLF", mIsWerewolf);
@ -147,6 +168,7 @@ void ESM::NpcStats::save (ESMWriter &esm) const
void ESM::NpcStats::blank()
{
mWerewolfDeprecatedData = false;
mIsWerewolf = false;
mDisposition = 0;
mBounty = 0;

@ -16,12 +16,6 @@ namespace ESM
struct NpcStats
{
struct Skill
{
StatState<int> mRegular;
StatState<int> mWerewolf;
};
struct Faction
{
bool mExpelled;
@ -31,12 +25,13 @@ namespace ESM
Faction();
};
StatState<int> mWerewolfAttributes[8];
bool mIsWerewolf;
bool mWerewolfDeprecatedData;
std::map<std::string, Faction> mFactions; // lower case IDs
int mDisposition;
Skill mSkills[27];
StatState<int> mSkills[27];
int mBounty;
int mReputation;
int mWerewolfKills;

Loading…
Cancel
Save