2013-04-07 17:39:13 +00:00
|
|
|
#include "regioncheck.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
#include "../prefs/state.hpp"
|
|
|
|
|
2013-04-07 17:39:13 +00:00
|
|
|
#include "../world/universalid.hpp"
|
|
|
|
|
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 <components/esm3/loadregn.hpp>
|
|
|
|
|
2013-04-07 17:39:13 +00:00
|
|
|
CSMTools::RegionCheckStage::RegionCheckStage(const CSMWorld::IdCollection<ESM::Region>& regions)
|
|
|
|
: mRegions(regions)
|
2018-06-19 22:20:03 +00:00
|
|
|
{
|
2018-06-20 09:29:38 +00:00
|
|
|
mIgnoreBaseRecords = false;
|
2018-06-19 22:20:03 +00:00
|
|
|
}
|
2013-04-07 17:39:13 +00:00
|
|
|
|
|
|
|
int CSMTools::RegionCheckStage::setup()
|
|
|
|
{
|
2018-06-19 22:20:03 +00:00
|
|
|
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
|
|
|
|
|
2013-04-07 17:39:13 +00:00
|
|
|
return mRegions.getSize();
|
|
|
|
}
|
|
|
|
|
2014-12-07 17:57:47 +00:00
|
|
|
void CSMTools::RegionCheckStage::perform(int stage, CSMDoc::Messages& messages)
|
2013-04-07 17:39:13 +00:00
|
|
|
{
|
2013-09-27 08:08:09 +00:00
|
|
|
const CSMWorld::Record<ESM::Region>& record = mRegions.getRecord(stage);
|
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
// Skip "Base" records (setting!) and "Deleted" records
|
2018-06-20 09:29:38 +00:00
|
|
|
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
|
2013-09-27 08:08:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const ESM::Region& region = record.get();
|
2013-04-07 17:39:13 +00:00
|
|
|
|
|
|
|
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Region, region.mId);
|
|
|
|
|
|
|
|
// test for empty name
|
|
|
|
if (region.mName.empty())
|
2018-08-24 19:01:08 +00:00
|
|
|
messages.add(id, "Name is missing", "", CSMDoc::Message::Severity_Error);
|
2013-04-07 17:39:13 +00:00
|
|
|
|
|
|
|
/// \todo test that the ID in mSleeplist exists
|
|
|
|
|
2016-04-06 07:11:28 +00:00
|
|
|
// test that chances add up to 100
|
2023-10-14 14:36:45 +00:00
|
|
|
auto chances = std::accumulate(region.mData.mProbabilities.begin(), region.mData.mProbabilities.end(), 0u);
|
2016-04-06 07:11:28 +00:00
|
|
|
if (chances != 100)
|
|
|
|
messages.add(id, "Weather chances do not add up to 100", "", CSMDoc::Message::Severity_Error);
|
|
|
|
|
2018-12-20 16:32:16 +00:00
|
|
|
for (const ESM::Region::SoundRef& sound : region.mSoundList)
|
|
|
|
{
|
|
|
|
if (sound.mChance > 100)
|
2022-10-06 17:39:46 +00:00
|
|
|
messages.add(id, "Chance of '" + sound.mSound.getRefIdString() + "' sound to play is over 100 percent", "",
|
2019-10-10 09:29:25 +00:00
|
|
|
CSMDoc::Message::Severity_Warning);
|
2018-12-20 16:32:16 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 17:39:13 +00:00
|
|
|
/// \todo check data members that can't be edited in the table view
|
2015-03-11 14:54:45 +00:00
|
|
|
}
|