mirror of https://github.com/OpenMW/openmw.git
added faction record verifier
parent
06533b8d71
commit
b5eaa464ad
@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
#include "factioncheck.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <components/esm/loadfact.hpp>
|
||||||
|
#include <components/esm/loadskil.hpp>
|
||||||
|
|
||||||
|
#include "../world/universalid.hpp"
|
||||||
|
|
||||||
|
CSMTools::FactionCheckStage::FactionCheckStage (const CSMWorld::IdCollection<ESM::Faction>& factions)
|
||||||
|
: mFactions (factions)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int CSMTools::FactionCheckStage::setup()
|
||||||
|
{
|
||||||
|
return mFactions.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMTools::FactionCheckStage::perform (int stage, std::vector<std::string>& messages)
|
||||||
|
{
|
||||||
|
const ESM::Faction& faction = mFactions.getRecord (stage).get();
|
||||||
|
|
||||||
|
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Faction, faction.mId);
|
||||||
|
|
||||||
|
// test for empty name
|
||||||
|
if (faction.mName.empty())
|
||||||
|
messages.push_back (id.toString() + "|" + faction.mId + " has an empty name");
|
||||||
|
|
||||||
|
// test for invalid attributes
|
||||||
|
if (faction.mData.mAttributes[0]==faction.mData.mAttributes[1] && faction.mData.mAttributes[0]!=-1)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
|
||||||
|
stream << id.toString() << "|Faction lists same attribute twice";
|
||||||
|
|
||||||
|
messages.push_back (stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// test for non-unique skill
|
||||||
|
std::map<int, int> skills; // ID, number of occurrences
|
||||||
|
|
||||||
|
for (int i=0; i<6; ++i)
|
||||||
|
if (faction.mData.mSkills[i]!=-1)
|
||||||
|
++skills[faction.mData.mSkills[i]];
|
||||||
|
|
||||||
|
for (std::map<int, int>::const_iterator iter (skills.begin()); iter!=skills.end(); ++iter)
|
||||||
|
if (iter->second>1)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
|
||||||
|
stream
|
||||||
|
<< id.toString() << "|"
|
||||||
|
<< ESM::Skill::indexToId (iter->first) << " is listed more than once";
|
||||||
|
|
||||||
|
messages.push_back (stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \todo check data members that can't be edited in the table view
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef CSM_TOOLS_FACTIONCHECK_H
|
||||||
|
#define CSM_TOOLS_FACTIONCHECK_H
|
||||||
|
|
||||||
|
#include <components/esm/loadfact.hpp>
|
||||||
|
|
||||||
|
#include "../world/idcollection.hpp"
|
||||||
|
|
||||||
|
#include "stage.hpp"
|
||||||
|
|
||||||
|
namespace CSMTools
|
||||||
|
{
|
||||||
|
/// \brief VerifyStage: make sure that faction records are internally consistent
|
||||||
|
class FactionCheckStage : public Stage
|
||||||
|
{
|
||||||
|
const CSMWorld::IdCollection<ESM::Faction>& mFactions;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FactionCheckStage (const CSMWorld::IdCollection<ESM::Faction>& factions);
|
||||||
|
|
||||||
|
virtual int setup();
|
||||||
|
///< \return number of steps
|
||||||
|
|
||||||
|
virtual void perform (int stage, std::vector<std::string>& messages);
|
||||||
|
///< Messages resulting from this tage will be appended to \a messages.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue