1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 08:53:52 +00:00
openmw/apps/opencs/model/tools/classcheck.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.5 KiB
C++
Raw Normal View History

2013-04-04 08:10:26 +00:00
#include "classcheck.hpp"
#include <map>
2022-10-19 17:02:00 +00: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 08:10:26 +00:00
#include <components/esm3/loadclas.hpp>
#include <components/esm3/loadskil.hpp>
2013-04-04 08:10:26 +00:00
#include "../prefs/state.hpp"
2013-04-04 08:10:26 +00:00
CSMTools::ClassCheckStage::ClassCheckStage(const CSMWorld::IdCollection<ESM::Class>& classes)
: mClasses(classes)
{
mIgnoreBaseRecords = false;
}
2013-04-04 08:10:26 +00:00
int CSMTools::ClassCheckStage::setup()
{
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
2013-04-04 08:10:26 +00:00
return mClasses.getSize();
}
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);
// Skip "Base" records (setting!) and "Deleted" records
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);
// A class should have a name
2013-04-04 08:10:26 +00:00
if (class_.mName.empty())
messages.add(id, "Name is missing", "", CSMDoc::Message::Severity_Error);
// A playable class should have a description
if (class_.mData.mIsPlayable != 0 && class_.mDescription.empty())
messages.add(id, "Description of a playable class is missing", "", CSMDoc::Message::Severity_Warning);
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)
{
messages.add(id, "Attribute #" + std::to_string(i) + " is not set", "", CSMDoc::Message::Severity_Error);
2013-04-04 08:10:26 +00:00
}
if (class_.mData.mAttribute[0] == class_.mData.mAttribute[1] && class_.mData.mAttribute[0] != -1)
{
messages.add(id, "Same attribute is listed twice", "", CSMDoc::Message::Severity_Error);
}
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]];
for (auto& skill : skills)
if (skill.second > 1)
2013-04-04 08:10:26 +00:00
{
messages.add(id, "Skill " + ESM::Skill::indexToRefId(skill.first).toString() + " is listed more than once",
"", CSMDoc::Message::Severity_Error);
2013-04-04 08:10:26 +00:00
}
2015-03-11 14:54:45 +00:00
}