Make ESM::Faction skills optional (Fixes #1508)

Also increased size of mSkills array to 7. Some factions with 7 skills can be found in the vanilla CS. The previously "mUnknown" int appears to be the 7th element of the skills array.
This commit is contained in:
scrawl 2014-06-15 23:05:38 +02:00
parent ee2b81763e
commit d5b97005ab
7 changed files with 33 additions and 19 deletions

View file

@ -682,13 +682,11 @@ void Record<ESM::Faction>::print()
{
std::cout << " Name: " << mData.mName << std::endl;
std::cout << " Hidden: " << mData.mData.mIsHidden << std::endl;
if (mData.mData.mUnknown != -1)
std::cout << " Unknown: " << mData.mData.mUnknown << std::endl;
std::cout << " Attribute1: " << attributeLabel(mData.mData.mAttribute[0])
<< " (" << mData.mData.mAttribute[0] << ")" << std::endl;
std::cout << " Attribute2: " << attributeLabel(mData.mData.mAttribute[1])
<< " (" << mData.mData.mAttribute[1] << ")" << std::endl;
for (int i = 0; i != 6; i++)
for (int i = 0; i < 7; i++)
if (mData.mData.mSkills[i] != -1)
std::cout << " Skill: " << skillLabel(mData.mData.mSkills[i])
<< " (" << mData.mData.mSkills[i] << ")" << std::endl;

View file

@ -42,7 +42,7 @@ void CSMTools::FactionCheckStage::perform (int stage, Messages& messages)
// test for non-unique skill
std::map<int, int> skills; // ID, number of occurrences
for (int i=0; i<6; ++i)
for (int i=0; i<7; ++i)
if (faction.mData.mSkills[i]!=-1)
++skills[faction.mData.mSkills[i]];
@ -54,4 +54,4 @@ void CSMTools::FactionCheckStage::perform (int stage, Messages& messages)
}
/// \todo check data members that can't be edited in the table view
}
}

View file

@ -102,7 +102,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding)
mFactions.addColumn (new AttributesColumn<ESM::Faction> (0));
mFactions.addColumn (new AttributesColumn<ESM::Faction> (1));
mFactions.addColumn (new HiddenColumn<ESM::Faction>);
for (int i=0; i<6; ++i)
for (int i=0; i<7; ++i)
mFactions.addColumn (new SkillsColumn<ESM::Faction> (i));
mRaces.addColumn (new StringIdColumn<ESM::Race>);
@ -742,4 +742,4 @@ void CSMWorld::Data::dataChanged (const QModelIndex& topLeft, const QModelIndex&
void CSMWorld::Data::rowsChanged (const QModelIndex& parent, int start, int end)
{
emit idListChanged();
}
}

View file

@ -504,11 +504,18 @@ namespace MWGui
text += "\n\n#DDC79E#{sFavoriteSkills}";
text += "\n#BF9959";
for (int i=0; i<6; ++i)
bool firstSkill = true;
for (int i=0; i<7; ++i)
{
text += "#{"+ESM::Skill::sSkillNameIds[faction->mData.mSkills[i]]+"}";
if (i<5)
text += ", ";
if (faction->mData.mSkills[i] != -1)
{
if (!firstSkill)
text += ", ";
firstSkill = false;
text += "#{"+ESM::Skill::sSkillNameIds[faction->mData.mSkills[i]]+"}";
}
}
text += "\n";

View file

@ -361,8 +361,14 @@ bool MWMechanics::NpcStats::hasSkillsForRank (const std::string& factionId, int
std::vector<int> skills;
for (int i=0; i<6; ++i)
skills.push_back (static_cast<int> (getSkill (faction.mData.mSkills[i]).getModified()));
for (int i=0; i<7; ++i)
{
if (faction.mData.mSkills[i] != -1)
skills.push_back (static_cast<int> (getSkill (faction.mData.mSkills[i]).getModified()));
}
if (skills.empty())
return true;
std::sort (skills.begin(), skills.end());
@ -373,6 +379,9 @@ bool MWMechanics::NpcStats::hasSkillsForRank (const std::string& factionId, int
if (*iter<rankData.mSkill1)
return false;
if (skills.size() < 2)
return true;
return *++iter>=rankData.mSkill2;
}

View file

@ -12,7 +12,7 @@ namespace ESM
int& Faction::FADTstruct::getSkill (int index, bool ignored)
{
if (index<0 || index>=6)
if (index<0 || index>=7)
throw std::logic_error ("skill index out of range");
return mSkills[index];
@ -20,7 +20,7 @@ namespace ESM
int Faction::FADTstruct::getSkill (int index, bool ignored) const
{
if (index<0 || index>=6)
if (index<0 || index>=7)
throw std::logic_error ("skill index out of range");
return mSkills[index];
@ -75,7 +75,6 @@ void Faction::save(ESMWriter &esm) const
{
mName.clear();
mData.mAttribute[0] = mData.mAttribute[1] = 0;
mData.mUnknown = -1;
mData.mIsHidden = 0;
for (int i=0; i<10; ++i)
@ -87,7 +86,7 @@ void Faction::save(ESMWriter &esm) const
mRanks[i].clear();
}
for (int i=0; i<6; ++i)
for (int i=0; i<7; ++i)
mData.mSkills[i] = 0;
mReactions.clear();

View file

@ -40,8 +40,9 @@ struct Faction
RankData mRankData[10];
int mSkills[6]; // IDs of skills this faction require
int mUnknown; // Always -1?
int mSkills[7]; // IDs of skills this faction require
// Each element will either contain an ESM::Skill index, or -1.
int mIsHidden; // 1 - hidden from player
int& getSkill (int index, bool ignored = false);