2013-04-04 08:39:43 +00:00
|
|
|
#include "factioncheck.hpp"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <components/esm/loadskil.hpp>
|
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
#include "../prefs/state.hpp"
|
|
|
|
|
2013-04-04 08:39:43 +00:00
|
|
|
#include "../world/universalid.hpp"
|
|
|
|
|
|
|
|
CSMTools::FactionCheckStage::FactionCheckStage (const CSMWorld::IdCollection<ESM::Faction>& factions)
|
|
|
|
: mFactions (factions)
|
2018-06-19 22:20:03 +00:00
|
|
|
{
|
2018-06-20 09:29:38 +00:00
|
|
|
mIgnoreBaseRecords = false;
|
2018-06-19 22:20:03 +00:00
|
|
|
}
|
2013-04-04 08:39:43 +00:00
|
|
|
|
|
|
|
int CSMTools::FactionCheckStage::setup()
|
|
|
|
{
|
2018-06-19 22:20:03 +00:00
|
|
|
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
|
|
|
|
|
2013-04-04 08:39:43 +00:00
|
|
|
return mFactions.getSize();
|
|
|
|
}
|
|
|
|
|
2014-12-07 17:57:47 +00:00
|
|
|
void CSMTools::FactionCheckStage::perform (int stage, CSMDoc::Messages& messages)
|
2013-04-04 08:39:43 +00:00
|
|
|
{
|
2013-09-27 08:08:09 +00:00
|
|
|
const CSMWorld::Record<ESM::Faction>& record = mFactions.getRecord (stage);
|
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
// Skip "Base" records (setting!) and "Deleted" records
|
2018-06-20 09:29:38 +00:00
|
|
|
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
|
2013-09-27 08:08:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const ESM::Faction& faction = record.get();
|
2013-04-04 08:39:43 +00:00
|
|
|
|
|
|
|
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Faction, faction.mId);
|
|
|
|
|
|
|
|
// test for empty name
|
|
|
|
if (faction.mName.empty())
|
2018-09-04 13:08:09 +00:00
|
|
|
messages.add(id, "Name is missing", "", CSMDoc::Message::Severity_Error);
|
2013-04-04 08:39:43 +00:00
|
|
|
|
|
|
|
// test for invalid attributes
|
2013-04-04 08:58:53 +00:00
|
|
|
if (faction.mData.mAttribute[0]==faction.mData.mAttribute[1] && faction.mData.mAttribute[0]!=-1)
|
2013-04-04 08:39:43 +00:00
|
|
|
{
|
2018-09-04 13:08:09 +00:00
|
|
|
messages.add(id, "Same attribute is listed twice", "", CSMDoc::Message::Severity_Error);
|
2013-04-04 08:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test for non-unique skill
|
|
|
|
std::map<int, int> skills; // ID, number of occurrences
|
|
|
|
|
2014-06-15 21:05:38 +00:00
|
|
|
for (int i=0; i<7; ++i)
|
2013-04-04 08:39:43 +00:00
|
|
|
if (faction.mData.mSkills[i]!=-1)
|
|
|
|
++skills[faction.mData.mSkills[i]];
|
|
|
|
|
2018-08-24 18:41:10 +00:00
|
|
|
for (auto &skill : skills)
|
|
|
|
if (skill.second>1)
|
2013-04-04 08:39:43 +00:00
|
|
|
{
|
2018-09-04 13:08:09 +00:00
|
|
|
messages.add(id, "Skill " + ESM::Skill::indexToId (skill.first) + " is listed more than once", "", CSMDoc::Message::Severity_Error);
|
2013-04-04 08:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \todo check data members that can't be edited in the table view
|
2014-06-15 21:05:38 +00:00
|
|
|
}
|