1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
OpenMW/apps/opencs/model/tools/racecheck.cpp

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

90 lines
2.8 KiB
C++
Raw Normal View History

2013-04-06 17:35:36 +02:00
#include "racecheck.hpp"
2022-10-19 19:02:00 +02:00
#include <string>
#include "../prefs/state.hpp"
2013-04-06 17:35:36 +02:00
#include "../world/universalid.hpp"
2022-10-19 19:02:00 +02: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 <components/esm3/loadrace.hpp>
void CSMTools::RaceCheckStage::performPerRecord(int stage, CSMDoc::Messages& messages)
2013-04-06 17:35:36 +02:00
{
2013-09-27 10:08:09 +02:00
const CSMWorld::Record<ESM::Race>& record = mRaces.getRecord(stage);
if (record.isDeleted())
return;
const ESM::Race& race = record.get();
2013-04-06 17:35:36 +02:00
// Consider mPlayable flag even when "Base" records are ignored
if (race.mData.mFlags & 0x1)
mPlayable = true;
// Skip "Base" records (setting!)
if (mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly)
return;
2013-04-06 17:35:36 +02:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Race, race.mId);
// test for empty name and description
2018-09-14 21:42:11 +03:00
if (race.mName.empty())
messages.add(id, "Name is missing", "",
(race.mData.mFlags & 0x1) ? CSMDoc::Message::Severity_Error : CSMDoc::Message::Severity_Warning);
2013-04-06 17:35:36 +02:00
if (race.mDescription.empty())
messages.add(id, "Description is missing", "", CSMDoc::Message::Severity_Warning);
2013-04-06 17:35:36 +02:00
// test for positive height
2023-12-17 13:00:14 +01:00
if (race.mData.mMaleHeight <= 0)
messages.add(id, "Male height is non-positive", "", CSMDoc::Message::Severity_Error);
2013-04-06 17:35:36 +02:00
2023-12-17 13:00:14 +01:00
if (race.mData.mFemaleHeight <= 0)
messages.add(id, "Female height is non-positive", "", CSMDoc::Message::Severity_Error);
2013-04-06 17:35:36 +02:00
// test for non-negative weight
2023-12-17 13:00:14 +01:00
if (race.mData.mMaleWeight < 0)
messages.add(id, "Male weight is negative", "", CSMDoc::Message::Severity_Error);
2013-04-06 17:35:36 +02:00
2023-12-17 13:00:14 +01:00
if (race.mData.mFemaleWeight < 0)
messages.add(id, "Female weight is negative", "", CSMDoc::Message::Severity_Error);
2013-04-06 17:35:36 +02:00
/// \todo check data members that can't be edited in the table view
2013-04-06 19:20:59 +02:00
}
void CSMTools::RaceCheckStage::performFinal(CSMDoc::Messages& messages)
2013-04-06 19:20:59 +02:00
{
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Races);
if (!mPlayable)
messages.add(id, "No playable race", "", CSMDoc::Message::Severity_SeriousError);
2013-04-06 19:20:59 +02:00
}
CSMTools::RaceCheckStage::RaceCheckStage(const CSMWorld::IdCollection<ESM::Race>& races)
: mRaces(races)
, mPlayable(false)
{
mIgnoreBaseRecords = false;
}
2013-04-06 19:20:59 +02:00
int CSMTools::RaceCheckStage::setup()
{
mPlayable = false;
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
2013-04-06 19:20:59 +02:00
return mRaces.getSize() + 1;
}
void CSMTools::RaceCheckStage::perform(int stage, CSMDoc::Messages& messages)
2013-04-06 19:20:59 +02:00
{
if (stage == mRaces.getSize())
performFinal(messages);
else
performPerRecord(stage, messages);
2015-03-11 10:54:45 -04:00
}