2011-04-08 13:58:21 +00:00
|
|
|
#include "loadfact.hpp"
|
|
|
|
|
2013-04-02 11:59:45 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2012-09-23 18:41:41 +00:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2013-09-24 11:17:28 +00:00
|
|
|
#include "defs.hpp"
|
2012-09-17 07:37:50 +00:00
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2013-09-24 11:17:28 +00:00
|
|
|
unsigned int Faction::sRecordId = REC_FACT;
|
|
|
|
|
2013-04-02 11:59:45 +00:00
|
|
|
int& Faction::FADTstruct::getSkill (int index, bool ignored)
|
|
|
|
{
|
2014-06-15 21:05:38 +00:00
|
|
|
if (index<0 || index>=7)
|
2013-04-02 11:59:45 +00:00
|
|
|
throw std::logic_error ("skill index out of range");
|
|
|
|
|
|
|
|
return mSkills[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int Faction::FADTstruct::getSkill (int index, bool ignored) const
|
|
|
|
{
|
2014-06-15 21:05:38 +00:00
|
|
|
if (index<0 || index>=7)
|
2013-04-02 11:59:45 +00:00
|
|
|
throw std::logic_error ("skill index out of range");
|
|
|
|
|
|
|
|
return mSkills[index];
|
|
|
|
}
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
void Faction::load(ESMReader &esm)
|
|
|
|
{
|
2014-04-13 11:23:50 +00:00
|
|
|
mName = esm.getHNOString("FNAM");
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
// Read rank names. These are optional.
|
|
|
|
int i = 0;
|
|
|
|
while (esm.isNextSub("RNAM") && i < 10)
|
2012-09-17 07:37:50 +00:00
|
|
|
mRanks[i++] = esm.getHString();
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
// Main data struct
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.getHNT(mData, "FADT", 240);
|
2011-04-08 13:58:21 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
if (mData.mIsHidden > 1)
|
2011-04-08 13:58:21 +00:00
|
|
|
esm.fail("Unknown flag!");
|
|
|
|
|
|
|
|
// Read faction response values
|
|
|
|
while (esm.hasMoreSubs())
|
|
|
|
{
|
2014-05-27 12:54:29 +00:00
|
|
|
std::string faction = esm.getHNString("ANAM");
|
|
|
|
int reaction;
|
|
|
|
esm.getHNT(reaction, "INTV");
|
|
|
|
mReactions[faction] = reaction;
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-16 10:32:35 +00:00
|
|
|
void Faction::save(ESMWriter &esm) const
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2014-04-13 11:23:50 +00:00
|
|
|
esm.writeHNOCString("FNAM", mName);
|
2013-04-02 10:00:45 +00:00
|
|
|
|
2012-04-08 15:04:52 +00:00
|
|
|
for (int i = 0; i < 10; i++)
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
if (mRanks[i].empty())
|
2012-04-12 12:00:58 +00:00
|
|
|
break;
|
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.writeHNString("RNAM", mRanks[i], 32);
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.writeHNT("FADT", mData, 240);
|
2013-04-02 10:00:45 +00:00
|
|
|
|
2014-05-27 12:54:29 +00:00
|
|
|
for (std::map<std::string, int>::const_iterator it = mReactions.begin(); it != mReactions.end(); ++it)
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2014-05-27 12:54:29 +00:00
|
|
|
esm.writeHNString("ANAM", it->first);
|
|
|
|
esm.writeHNT("INTV", it->second);
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 10:00:45 +00:00
|
|
|
void Faction::blank()
|
|
|
|
{
|
|
|
|
mName.clear();
|
2013-04-04 08:58:53 +00:00
|
|
|
mData.mAttribute[0] = mData.mAttribute[1] = 0;
|
2013-04-02 10:00:45 +00:00
|
|
|
mData.mIsHidden = 0;
|
|
|
|
|
|
|
|
for (int i=0; i<10; ++i)
|
|
|
|
{
|
|
|
|
mData.mRankData[i].mAttribute1 = mData.mRankData[i].mAttribute2 = 0;
|
|
|
|
mData.mRankData[i].mSkill1 = mData.mRankData[i].mSkill2 = 0;
|
|
|
|
mData.mRankData[i].mFactReaction = 0;
|
|
|
|
|
|
|
|
mRanks[i].clear();
|
|
|
|
}
|
|
|
|
|
2014-06-15 21:05:38 +00:00
|
|
|
for (int i=0; i<7; ++i)
|
2013-04-02 11:59:45 +00:00
|
|
|
mData.mSkills[i] = 0;
|
2013-04-02 10:00:45 +00:00
|
|
|
|
|
|
|
mReactions.clear();
|
|
|
|
}
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|