2013-04-04 10:10:26 +02:00
|
|
|
#include "classcheck.hpp"
|
|
|
|
|
|
|
|
#include <map>
|
2022-10-19 19:02:00 +02:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <apps/opencs/model/doc/messages.hpp>
|
|
|
|
#include <apps/opencs/model/prefs/category.hpp>
|
|
|
|
#include <apps/opencs/model/prefs/setting.hpp>
|
|
|
|
#include <apps/opencs/model/world/idcollection.hpp>
|
|
|
|
#include <apps/opencs/model/world/record.hpp>
|
|
|
|
#include <apps/opencs/model/world/universalid.hpp>
|
2013-04-04 10:10:26 +02:00
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loadclas.hpp>
|
|
|
|
#include <components/esm3/loadskil.hpp>
|
2013-04-04 10:10:26 +02:00
|
|
|
|
2018-06-20 00:20:03 +02:00
|
|
|
#include "../prefs/state.hpp"
|
|
|
|
|
2013-04-04 10:10:26 +02:00
|
|
|
CSMTools::ClassCheckStage::ClassCheckStage(const CSMWorld::IdCollection<ESM::Class>& classes)
|
|
|
|
: mClasses(classes)
|
2018-06-20 00:20:03 +02:00
|
|
|
{
|
2018-06-20 11:29:38 +02:00
|
|
|
mIgnoreBaseRecords = false;
|
2018-06-20 00:20:03 +02:00
|
|
|
}
|
2013-04-04 10:10:26 +02:00
|
|
|
|
|
|
|
int CSMTools::ClassCheckStage::setup()
|
|
|
|
{
|
2018-06-20 00:20:03 +02:00
|
|
|
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
|
|
|
|
|
2013-04-04 10:10:26 +02:00
|
|
|
return mClasses.getSize();
|
|
|
|
}
|
|
|
|
|
2014-12-07 18:57:47 +01:00
|
|
|
void CSMTools::ClassCheckStage::perform(int stage, CSMDoc::Messages& messages)
|
2013-04-04 10:10:26 +02:00
|
|
|
{
|
2013-09-27 10:08:09 +02:00
|
|
|
const CSMWorld::Record<ESM::Class>& record = mClasses.getRecord(stage);
|
|
|
|
|
2018-06-20 00:20:03 +02:00
|
|
|
// Skip "Base" records (setting!) and "Deleted" records
|
2018-06-20 11:29:38 +02:00
|
|
|
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
|
2013-09-27 10:08:09 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
const ESM::Class& class_ = record.get();
|
2013-04-04 10:10:26 +02:00
|
|
|
|
|
|
|
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Class, class_.mId);
|
|
|
|
|
2018-05-26 22:17:27 +03:00
|
|
|
// A class should have a name
|
2013-04-04 10:10:26 +02:00
|
|
|
if (class_.mName.empty())
|
2018-09-04 16:08:09 +03:00
|
|
|
messages.add(id, "Name is missing", "", CSMDoc::Message::Severity_Error);
|
2018-05-26 22:17:27 +03:00
|
|
|
|
|
|
|
// A playable class should have a description
|
|
|
|
if (class_.mData.mIsPlayable != 0 && class_.mDescription.empty())
|
2018-08-25 03:49:10 +03:00
|
|
|
messages.add(id, "Description of a playable class is missing", "", CSMDoc::Message::Severity_Warning);
|
2013-04-04 10:10:26 +02:00
|
|
|
|
|
|
|
// test for invalid attributes
|
2023-06-03 11:58:09 +02:00
|
|
|
std::map<int, int> attributeCount;
|
|
|
|
for (size_t i = 0; i < class_.mData.mAttribute.size(); ++i)
|
|
|
|
{
|
|
|
|
int attribute = class_.mData.mAttribute[i];
|
|
|
|
if (attribute == -1)
|
|
|
|
messages.add(id, "Attribute #" + std::to_string(i) + " is not set", {}, CSMDoc::Message::Severity_Error);
|
|
|
|
else
|
2013-04-04 10:10:26 +02:00
|
|
|
{
|
2023-06-03 11:58:09 +02:00
|
|
|
auto it = attributeCount.find(attribute);
|
|
|
|
if (it == attributeCount.end())
|
|
|
|
attributeCount.emplace(attribute, 1);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (it->second == 1)
|
|
|
|
messages.add(id, "Same attribute is listed twice", {}, CSMDoc::Message::Severity_Error);
|
|
|
|
++it->second;
|
|
|
|
}
|
2013-04-04 10:10:26 +02:00
|
|
|
}
|
2013-04-04 10:31:10 +02:00
|
|
|
}
|
|
|
|
|
2013-04-04 10:10:26 +02:00
|
|
|
// test for non-unique skill
|
|
|
|
std::map<int, int> skills; // ID, number of occurrences
|
|
|
|
|
2023-06-03 11:58:09 +02:00
|
|
|
for (const auto& s : class_.mData.mSkills)
|
|
|
|
for (int skill : s)
|
|
|
|
++skills[skill];
|
2013-04-04 10:10:26 +02:00
|
|
|
|
2018-08-24 21:15:43 +03:00
|
|
|
for (auto& skill : skills)
|
|
|
|
if (skill.second > 1)
|
2013-04-04 10:10:26 +02:00
|
|
|
{
|
2023-02-11 00:08:59 +01:00
|
|
|
messages.add(id, "Skill " + ESM::Skill::indexToRefId(skill.first).toString() + " is listed more than once",
|
|
|
|
"", CSMDoc::Message::Severity_Error);
|
2013-04-04 10:10:26 +02:00
|
|
|
}
|
2015-03-11 10:54:45 -04:00
|
|
|
}
|