2018-08-29 22:21:27 +00:00
|
|
|
#include "enchantmentcheck.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
2024-06-07 08:12:38 +00:00
|
|
|
#include <components/esm/attr.hpp>
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <components/esm3/effectlist.hpp>
|
|
|
|
#include <components/esm3/loadench.hpp>
|
|
|
|
|
2018-08-29 22:21:27 +00:00
|
|
|
#include "../prefs/state.hpp"
|
|
|
|
|
|
|
|
#include "../world/universalid.hpp"
|
|
|
|
|
|
|
|
CSMTools::EnchantmentCheckStage::EnchantmentCheckStage(const CSMWorld::IdCollection<ESM::Enchantment>& enchantments)
|
|
|
|
: mEnchantments(enchantments)
|
|
|
|
{
|
|
|
|
mIgnoreBaseRecords = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSMTools::EnchantmentCheckStage::setup()
|
|
|
|
{
|
|
|
|
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
|
|
|
|
|
|
|
|
return mEnchantments.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMTools::EnchantmentCheckStage::perform(int stage, CSMDoc::Messages& messages)
|
|
|
|
{
|
|
|
|
const CSMWorld::Record<ESM::Enchantment>& record = mEnchantments.getRecord(stage);
|
|
|
|
|
|
|
|
// Skip "Base" records (setting!) and "Deleted" records
|
|
|
|
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const ESM::Enchantment& enchantment = record.get();
|
|
|
|
|
|
|
|
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Enchantment, enchantment.mId);
|
|
|
|
|
|
|
|
if (enchantment.mData.mType < 0 || enchantment.mData.mType > 3)
|
|
|
|
messages.add(id, "Invalid type", "", CSMDoc::Message::Severity_Error);
|
|
|
|
|
|
|
|
if (enchantment.mData.mCost < 0)
|
|
|
|
messages.add(id, "Cost is negative", "", CSMDoc::Message::Severity_Error);
|
|
|
|
|
|
|
|
if (enchantment.mData.mCharge < 0)
|
|
|
|
messages.add(id, "Charge is negative", "", CSMDoc::Message::Severity_Error);
|
|
|
|
|
2018-09-11 18:40:41 +00:00
|
|
|
if (enchantment.mData.mCost > enchantment.mData.mCharge)
|
|
|
|
messages.add(id, "Cost is higher than charge", "", CSMDoc::Message::Severity_Error);
|
|
|
|
|
|
|
|
if (enchantment.mEffects.mList.empty())
|
|
|
|
{
|
|
|
|
messages.add(id, "Enchantment doesn't have any magic effects", "", CSMDoc::Message::Severity_Warning);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
std::vector<ESM::IndexedENAMstruct>::const_iterator effect = enchantment.mEffects.mList.begin();
|
2018-09-11 18:40:41 +00:00
|
|
|
|
|
|
|
for (size_t i = 1; i <= enchantment.mEffects.mList.size(); i++)
|
|
|
|
{
|
|
|
|
const std::string number = std::to_string(i);
|
2024-06-07 08:12:38 +00:00
|
|
|
// At the time of writing this effects, attributes and skills are mostly hardcoded
|
|
|
|
if (effect->mData.mEffectID < 0 || effect->mData.mEffectID > ESM::MagicEffect::Length)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(id, "Effect #" + number + " is invalid", "", CSMDoc::Message::Severity_Error);
|
2024-06-07 08:12:38 +00:00
|
|
|
if (effect->mData.mSkill < -1 || effect->mData.mSkill > ESM::Skill::Length)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(
|
|
|
|
id, "Effect #" + number + " affected skill is invalid", "", CSMDoc::Message::Severity_Error);
|
2024-06-07 08:12:38 +00:00
|
|
|
if (effect->mData.mAttribute < -1 || effect->mData.mAttribute > ESM::Attribute::Length)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(
|
|
|
|
id, "Effect #" + number + " affected attribute is invalid", "", CSMDoc::Message::Severity_Error);
|
2024-03-25 13:50:23 +00:00
|
|
|
if (effect->mData.mRange < 0 || effect->mData.mRange > 2)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(id, "Effect #" + number + " range is invalid", "", CSMDoc::Message::Severity_Error);
|
2024-03-25 13:50:23 +00:00
|
|
|
if (effect->mData.mArea < 0)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(id, "Effect #" + number + " area is negative", "", CSMDoc::Message::Severity_Error);
|
2024-03-25 13:50:23 +00:00
|
|
|
if (effect->mData.mDuration < 0)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(id, "Effect #" + number + " duration is negative", "", CSMDoc::Message::Severity_Error);
|
2024-03-25 13:50:23 +00:00
|
|
|
if (effect->mData.mMagnMin < 0)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(
|
|
|
|
id, "Effect #" + number + " minimum magnitude is negative", "", CSMDoc::Message::Severity_Error);
|
2024-03-25 13:50:23 +00:00
|
|
|
if (effect->mData.mMagnMax < 0)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(
|
|
|
|
id, "Effect #" + number + " maximum magnitude is negative", "", CSMDoc::Message::Severity_Error);
|
2024-06-07 09:32:59 +00:00
|
|
|
else if (effect->mData.mMagnMax == 0)
|
|
|
|
messages.add(
|
|
|
|
id, "Effect #" + number + " maximum magnitude is zero", "", CSMDoc::Message::Severity_Warning);
|
2024-03-25 13:50:23 +00:00
|
|
|
if (effect->mData.mMagnMin > effect->mData.mMagnMax)
|
2018-09-11 18:40:41 +00:00
|
|
|
messages.add(id, "Effect #" + number + " minimum magnitude is higher than maximum magnitude", "",
|
|
|
|
CSMDoc::Message::Severity_Error);
|
|
|
|
++effect;
|
|
|
|
}
|
|
|
|
}
|
2018-08-29 22:21:27 +00:00
|
|
|
}
|