1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-24 09:53:53 +00:00
openmw/apps/opencs/model/tools/factioncheck.cpp

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

83 lines
2.5 KiB
C++
Raw Normal View History

2013-04-04 08:39:43 +00:00
#include "factioncheck.hpp"
#include <map>
2022-10-19 17:02:00 +00:00
#include <string>
#include <utility>
2013-04-04 08:39:43 +00:00
2022-10-19 17:02:00 +00:00
#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>
#include <components/esm3/loadfact.hpp>
#include <components/esm3/loadskil.hpp>
2013-04-04 08:39:43 +00:00
#include "../prefs/state.hpp"
2013-04-04 08:39:43 +00:00
CSMTools::FactionCheckStage::FactionCheckStage(const CSMWorld::IdCollection<ESM::Faction>& factions)
: mFactions(factions)
{
mIgnoreBaseRecords = false;
}
2013-04-04 08:39:43 +00:00
int CSMTools::FactionCheckStage::setup()
{
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
2013-04-04 08:39:43 +00:00
return mFactions.getSize();
}
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);
// 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::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())
messages.add(id, "Name is missing", "", CSMDoc::Message::Severity_Error);
2013-04-04 08:39:43 +00:00
// test for invalid attributes
2023-06-03 11:11:49 +00:00
std::map<int, int> attributeCount;
for (size_t i = 0; i < faction.mData.mAttribute.size(); ++i)
2013-04-04 08:39:43 +00:00
{
2023-06-03 11:11:49 +00:00
int attribute = faction.mData.mAttribute[i];
if (attribute != -1)
{
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 08:39:43 +00:00
}
// test for non-unique skill
std::map<int, int> skills; // ID, number of occurrences
2023-06-03 11:11:49 +00:00
for (int skill : faction.mData.mSkills)
if (skill != -1)
++skills[skill];
2013-04-04 08:39:43 +00:00
for (auto& skill : skills)
if (skill.second > 1)
2013-04-04 08:39:43 +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:39:43 +00:00
}
/// \todo check data members that can't be edited in the table view
}