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.
deque
scrawl 11 years ago
parent ee2b81763e
commit d5b97005ab

@ -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;

@ -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
}
}

@ -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();
}
}

@ -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";

@ -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;
}

@ -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();

@ -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);

Loading…
Cancel
Save