forked from OpenMW/openmw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadfact.cpp
136 lines (113 loc) · 3.68 KB
/
loadfact.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "loadfact.hpp"
#include <stdexcept>
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include "defs.hpp"
namespace ESM
{
unsigned int Faction::sRecordId = REC_FACT;
int& Faction::FADTstruct::getSkill (int index, bool ignored)
{
if (index<0 || index>=7)
throw std::logic_error ("skill index out of range");
return mSkills[index];
}
int Faction::FADTstruct::getSkill (int index, bool ignored) const
{
if (index<0 || index>=7)
throw std::logic_error ("skill index out of range");
return mSkills[index];
}
void Faction::load(ESMReader &esm, bool &isDeleted)
{
isDeleted = false;
mReactions.clear();
for (int i=0;i<10;++i)
mRanks[i].clear();
int rankCounter = 0;
bool hasName = false;
bool hasData = false;
while (esm.hasMoreSubs())
{
esm.getSubName();
switch (esm.retSubName().val)
{
case ESM::SREC_NAME:
mId = esm.getHString();
hasName = true;
break;
case ESM::FourCC<'F','N','A','M'>::value:
mName = esm.getHString();
break;
case ESM::FourCC<'R','N','A','M'>::value:
if (rankCounter >= 10)
esm.fail("Rank out of range");
mRanks[rankCounter++] = esm.getHString();
break;
case ESM::FourCC<'F','A','D','T'>::value:
esm.getHT(mData, 240);
if (mData.mIsHidden > 1)
esm.fail("Unknown flag!");
hasData = true;
break;
case ESM::FourCC<'A','N','A','M'>::value:
{
std::string faction = esm.getHString();
int reaction;
esm.getHNT(reaction, "INTV");
mReactions[faction] = reaction;
break;
}
case ESM::SREC_DELE:
esm.skipHSub();
isDeleted = true;
break;
default:
esm.fail("Unknown subrecord");
break;
}
}
if (!hasName)
esm.fail("Missing NAME subrecord");
if (!hasData && !isDeleted)
esm.fail("Missing FADT subrecord");
}
void Faction::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
if (isDeleted)
{
esm.writeHNCString("DELE", "");
return;
}
esm.writeHNOCString("FNAM", mName);
for (int i = 0; i < 10; i++)
{
if (mRanks[i].empty())
break;
esm.writeHNString("RNAM", mRanks[i], 32);
}
esm.writeHNT("FADT", mData, 240);
for (std::map<std::string, int>::const_iterator it = mReactions.begin(); it != mReactions.end(); ++it)
{
esm.writeHNString("ANAM", it->first);
esm.writeHNT("INTV", it->second);
}
}
void Faction::blank()
{
mName.clear();
mData.mAttribute[0] = mData.mAttribute[1] = 0;
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();
}
for (int i=0; i<7; ++i)
mData.mSkills[i] = 0;
mReactions.clear();
}
}