2013-04-04 08:10:26 +00:00
|
|
|
#include "classcheck.hpp"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <components/esm/loadclas.hpp>
|
|
|
|
#include <components/esm/loadskil.hpp>
|
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
#include "../prefs/state.hpp"
|
|
|
|
|
2013-04-04 08:10:26 +00:00
|
|
|
#include "../world/universalid.hpp"
|
|
|
|
|
|
|
|
CSMTools::ClassCheckStage::ClassCheckStage (const CSMWorld::IdCollection<ESM::Class>& classes)
|
|
|
|
: mClasses (classes)
|
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:10:26 +00:00
|
|
|
|
|
|
|
int CSMTools::ClassCheckStage::setup()
|
|
|
|
{
|
2018-06-19 22:20:03 +00:00
|
|
|
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
|
|
|
|
|
2013-04-04 08:10:26 +00:00
|
|
|
return mClasses.getSize();
|
|
|
|
}
|
|
|
|
|
2014-12-07 17:57:47 +00:00
|
|
|
void CSMTools::ClassCheckStage::perform (int stage, CSMDoc::Messages& messages)
|
2013-04-04 08:10:26 +00:00
|
|
|
{
|
2013-09-27 08:08:09 +00:00
|
|
|
const CSMWorld::Record<ESM::Class>& record = mClasses.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::Class& class_ = record.get();
|
2013-04-04 08:10:26 +00:00
|
|
|
|
|
|
|
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Class, class_.mId);
|
|
|
|
|
2018-05-26 19:17:27 +00:00
|
|
|
// A class should have a name
|
2013-04-04 08:10:26 +00:00
|
|
|
if (class_.mName.empty())
|
2018-08-24 18:15:43 +00:00
|
|
|
messages.push_back (std::make_pair (id, "Name is missing"));
|
2018-05-26 19:17:27 +00:00
|
|
|
|
|
|
|
// A playable class should have a description
|
|
|
|
if (class_.mData.mIsPlayable != 0 && class_.mDescription.empty())
|
2018-08-24 18:15:43 +00:00
|
|
|
messages.push_back (std::make_pair (id, "Description of a playable class is missing"));
|
2013-04-04 08:10:26 +00:00
|
|
|
|
|
|
|
// test for invalid attributes
|
|
|
|
for (int i=0; i<2; ++i)
|
|
|
|
if (class_.mData.mAttribute[i]==-1)
|
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
|
2018-08-24 18:15:43 +00:00
|
|
|
stream << "Attribute #" << i << " is not set";
|
2013-04-04 08:10:26 +00:00
|
|
|
|
2014-05-08 10:42:29 +00:00
|
|
|
messages.push_back (std::make_pair (id, stream.str()));
|
2013-04-04 08:10:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 08:31:10 +00:00
|
|
|
if (class_.mData.mAttribute[0]==class_.mData.mAttribute[1] && class_.mData.mAttribute[0]!=-1)
|
|
|
|
{
|
2018-08-24 18:15:43 +00:00
|
|
|
messages.push_back (std::make_pair (id, "Same attribute is listed twice"));
|
2013-04-04 08:31:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 08:10:26 +00:00
|
|
|
// test for non-unique skill
|
|
|
|
std::map<int, int> skills; // ID, number of occurrences
|
|
|
|
|
|
|
|
for (int i=0; i<5; ++i)
|
|
|
|
for (int i2=0; i2<2; ++i2)
|
|
|
|
++skills[class_.mData.mSkills[i][i2]];
|
|
|
|
|
2018-08-24 18:15:43 +00:00
|
|
|
for (auto &skill : skills)
|
|
|
|
if (skill.second>1)
|
2013-04-04 08:10:26 +00:00
|
|
|
{
|
2018-08-24 18:15:43 +00:00
|
|
|
messages.push_back (std::make_pair (id, "Skill " + ESM::Skill::indexToId (skill.first) + " is listed more than once"));
|
2013-04-04 08:10:26 +00:00
|
|
|
}
|
2015-03-11 14:54:45 +00:00
|
|
|
}
|