From 4e828dd6ffd004928d02a4e999e23a11269605b4 Mon Sep 17 00:00:00 2001 From: Telvanni 4Life Date: Tue, 3 Feb 2026 16:48:09 -0500 Subject: [PATCH] Changed skills and attributes in IRDTstruct to use RefIds instead of indices --- apps/esmtool/record.cpp | 8 ++++---- apps/opencs/model/tools/effectlistcheck.cpp | 6 ++++-- .../opencs/model/world/nestedcoladapterimp.hpp | 2 -- apps/opencs/model/world/refidadapterimp.cpp | 12 ++++++------ apps/openmw/mwclass/ingredient.cpp | 4 ++-- apps/openmw/mwgui/spellcreationdialog.cpp | 2 -- apps/openmw/mwlua/types/ingredient.cpp | 4 ++-- apps/openmw/mwmechanics/alchemy.cpp | 12 ++++-------- apps/openmw/mwmechanics/spellutil.cpp | 4 ++-- components/esm3/loadingr.cpp | 18 ++++++++++-------- components/esm3/loadingr.hpp | 4 ++-- 11 files changed, 36 insertions(+), 40 deletions(-) diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index 611d6fd247..e0fcc6bcbf 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -851,11 +851,11 @@ namespace EsmTool continue; int effectIdx = ESM::MagicEffect::refIdToIndex(mData.mData.mEffectID[i]); + int skillIdx = ESM::Skill::refIdToIndex(mData.mData.mSkills[i]); + int attributeIdx = ESM::Attribute::refIdToIndex(mData.mData.mAttributes[i]); std::cout << " Effect: " << magicEffectLabel(effectIdx) << " (" << effectIdx << ")" << std::endl; - std::cout << " Skill: " << skillLabel(mData.mData.mSkills[i]) << " (" << mData.mData.mSkills[i] << ")" - << std::endl; - std::cout << " Attribute: " << attributeLabel(mData.mData.mAttributes[i]) << " (" - << mData.mData.mAttributes[i] << ")" << std::endl; + std::cout << " Skill: " << skillLabel(skillIdx) << " (" << skillIdx << ")" << std::endl; + std::cout << " Attribute: " << attributeLabel(attributeIdx) << " (" << attributeIdx << ")" << std::endl; } std::cout << " Deleted: " << mIsDeleted << std::endl; } diff --git a/apps/opencs/model/tools/effectlistcheck.cpp b/apps/opencs/model/tools/effectlistcheck.cpp index 4ad8d908d0..f80b7e3841 100644 --- a/apps/opencs/model/tools/effectlistcheck.cpp +++ b/apps/opencs/model/tools/effectlistcheck.cpp @@ -76,13 +76,15 @@ namespace CSMTools hasEffects = true; int effectIndex = ESM::MagicEffect::refIdToIndex(ingredient.mData.mEffectID[i]); + int skillIndex = ESM::Skill::refIdToIndex(ingredient.mData.mSkills[i]); + int attributeIndex = ESM::Attribute::refIdToIndex(ingredient.mData.mAttributes[i]); const std::string number = std::to_string(i + 1); if (effectIndex < -1 || effectIndex >= ESM::MagicEffect::Length) messages.add(id, "Effect #" + number + ": invalid effect ID", "", CSMDoc::Message::Severity_Error); - if (ingredient.mData.mSkills[i] < -1 || ingredient.mData.mSkills[i] >= ESM::Skill::Length) + if (skillIndex < -1 || skillIndex >= ESM::Skill::Length) messages.add(id, "Effect #" + number + ": invalid skill", "", CSMDoc::Message::Severity_Error); - if (ingredient.mData.mAttributes[i] < -1 || ingredient.mData.mAttributes[i] >= ESM::Attribute::Length) + if (attributeIndex < -1 || attributeIndex >= ESM::Attribute::Length) messages.add(id, "Effect #" + number + ": invalid attribute", "", CSMDoc::Message::Severity_Error); } diff --git a/apps/opencs/model/world/nestedcoladapterimp.hpp b/apps/opencs/model/world/nestedcoladapterimp.hpp index 276ea48d5d..12327aa0eb 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.hpp +++ b/apps/opencs/model/world/nestedcoladapterimp.hpp @@ -269,8 +269,6 @@ namespace CSMWorld ESM::IndexedENAMstruct effect; effect.mIndex = position; effect.mData.mEffectID = ESM::MagicEffect::WaterBreathing; - effect.mData.mSkill = ESM::RefId(); - effect.mData.mAttribute = ESM::RefId(); effect.mData.mRange = 0; effect.mData.mArea = 0; effect.mData.mDuration = 0; diff --git a/apps/opencs/model/world/refidadapterimp.cpp b/apps/opencs/model/world/refidadapterimp.cpp index cd03c9236d..ea25a3180f 100644 --- a/apps/opencs/model/world/refidadapterimp.cpp +++ b/apps/opencs/model/world/refidadapterimp.cpp @@ -160,14 +160,14 @@ QVariant CSMWorld::IngredEffectRefIdAdapter::getNestedData( case 1: { if (targetSkill) - return record.get().mData.mSkills[subRowIndex]; + return ESM::Skill::refIdToIndex(record.get().mData.mSkills[subRowIndex]); else return QVariant(); } case 2: { if (targetAttribute) - return record.get().mData.mAttributes[subRowIndex]; + return ESM::Attribute::refIdToIndex(record.get().mData.mAttributes[subRowIndex]); else return QVariant(); } @@ -205,15 +205,15 @@ void CSMWorld::IngredEffectRefIdAdapter::setNestedData( } if (!targetSkill) - ingredient.mData.mSkills[subRowIndex] = -1; + ingredient.mData.mSkills[subRowIndex] = ESM::RefId(); if (!targetAttribute) - ingredient.mData.mAttributes[subRowIndex] = -1; + ingredient.mData.mAttributes[subRowIndex] = ESM::RefId(); break; case 1: - ingredient.mData.mSkills[subRowIndex] = value.toInt(); + ingredient.mData.mSkills[subRowIndex] = ESM::Skill::indexToRefId(value.toInt()); break; case 2: - ingredient.mData.mAttributes[subRowIndex] = value.toInt(); + ingredient.mData.mAttributes[subRowIndex] = ESM::Attribute::indexToRefId(value.toInt()); break; default: throw std::runtime_error("Trying to access non-existing column in the nested table!"); diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 071dc05f54..1dceccd4cc 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -135,8 +135,8 @@ namespace MWClass continue; MWGui::Widgets::SpellEffectParams params; params.mEffectID = ref->mBase->mData.mEffectID[i]; - params.mAttribute = ESM::Attribute::indexToRefId(ref->mBase->mData.mAttributes[i]); - params.mSkill = ESM::Skill::indexToRefId(ref->mBase->mData.mSkills[i]); + params.mAttribute = ref->mBase->mData.mAttributes[i]; + params.mSkill = ref->mBase->mData.mSkills[i]; params.mKnown = alchemySkill >= fWortChanceValue * (i + 1); list.push_back(params); diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 17d4c35456..47cf02e2e8 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -48,8 +48,6 @@ namespace effect.mMagnMax = 0; effect.mMagnMin = 0; effect.mRange = 0; - effect.mSkill = ESM::RefId(); - effect.mAttribute = ESM::RefId(); } } diff --git a/apps/openmw/mwlua/types/ingredient.cpp b/apps/openmw/mwlua/types/ingredient.cpp index ec9cbf693c..b2efc57870 100644 --- a/apps/openmw/mwlua/types/ingredient.cpp +++ b/apps/openmw/mwlua/types/ingredient.cpp @@ -50,8 +50,8 @@ namespace MWLua continue; ESM::IndexedENAMstruct effect; effect.mData.mEffectID = rec.mData.mEffectID[i]; - effect.mData.mSkill = ESM::Skill::indexToRefId(rec.mData.mSkills[i]); - effect.mData.mAttribute = ESM::Attribute::indexToRefId(rec.mData.mAttributes[i]); + effect.mData.mSkill = rec.mData.mSkills[i]; + effect.mData.mAttribute = rec.mData.mAttributes[i]; effect.mData.mRange = ESM::RT_Self; effect.mData.mArea = 0; effect.mData.mDuration = 0; diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index eeb4a60bfb..c68f1d8b8c 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -33,9 +33,9 @@ namespace { if (ingredient.mData.mEffectID[i].empty()) return {}; - ESM::RefId arg = ESM::Skill::indexToRefId(ingredient.mData.mSkills[i]); + ESM::RefId arg = ingredient.mData.mSkills[i]; if (arg.empty()) - arg = ESM::Attribute::indexToRefId(ingredient.mData.mAttributes[i]); + arg = ingredient.mData.mAttributes[i]; return MWMechanics::EffectKey(ingredient.mData.mEffectID[i], arg); } @@ -220,9 +220,6 @@ void MWMechanics::Alchemy::updateEffects() ESM::ENAMstruct effect; effect.mEffectID = effectKey.mId; - effect.mAttribute = ESM::RefId(); - effect.mSkill = ESM::RefId(); - if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill) effect.mSkill = effectKey.mArg; else if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute) @@ -624,9 +621,8 @@ std::vector MWMechanics::Alchemy::effectsDescription( if (!effectID.empty()) { - const ESM::Attribute* attribute - = store->get().search(ESM::Attribute::indexToRefId(data.mAttributes[i])); - const ESM::Skill* skill = store->get().search(ESM::Skill::indexToRefId(data.mSkills[i])); + const ESM::Attribute* attribute = store->get().search(data.mAttributes[i]); + const ESM::Skill* skill = store->get().search(data.mSkills[i]); std::string effect = getMagicEffectString(*mgef.find(effectID), attribute, skill); effects.push_back(std::move(effect)); diff --git a/apps/openmw/mwmechanics/spellutil.cpp b/apps/openmw/mwmechanics/spellutil.cpp index 27d2a9e9c9..2186f53f5a 100644 --- a/apps/openmw/mwmechanics/spellutil.cpp +++ b/apps/openmw/mwmechanics/spellutil.cpp @@ -167,8 +167,8 @@ namespace MWMechanics ESM::ENAMstruct effect; effect.mEffectID = ingredient->mData.mEffectID[index]; - effect.mSkill = ESM::Skill::indexToRefId(ingredient->mData.mSkills[index]); - effect.mAttribute = ESM::Attribute::indexToRefId(ingredient->mData.mAttributes[index]); + effect.mSkill = ingredient->mData.mSkills[index]; + effect.mAttribute = ingredient->mData.mAttributes[index]; effect.mRange = ESM::RT_Self; effect.mArea = 0; diff --git a/components/esm3/loadingr.cpp b/components/esm3/loadingr.cpp index 76a47f5178..14abf0ae6a 100644 --- a/components/esm3/loadingr.cpp +++ b/components/esm3/loadingr.cpp @@ -3,7 +3,9 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include #include +#include #include namespace ESM @@ -24,8 +26,8 @@ namespace ESM for (int i = 0; i < 4; ++i) { dst.mEffectID[i] = ESM::MagicEffect::refIdToIndex(src.mEffectID[i]); - dst.mSkills[i] = src.mSkills[i]; - dst.mAttributes[i] = src.mAttributes[i]; + dst.mSkills[i] = ESM::Skill::refIdToIndex(src.mSkills[i]); + dst.mAttributes[i] = ESM::Attribute::refIdToIndex(src.mAttributes[i]); } } @@ -36,8 +38,8 @@ namespace ESM for (int i = 0; i < 4; ++i) { dst.mEffectID[i] = ESM::MagicEffect::indexToRefId(src.mEffectID[i]); - dst.mSkills[i] = src.mSkills[i]; - dst.mAttributes[i] = src.mAttributes[i]; + dst.mSkills[i] = ESM::Skill::indexToRefId(src.mSkills[i]); + dst.mAttributes[i] = ESM::Attribute::indexToRefId(src.mAttributes[i]); } } } @@ -106,7 +108,7 @@ namespace ESM && mData.mEffectID[i] != ESM::MagicEffect::FortifyAttribute && mData.mEffectID[i] != ESM::MagicEffect::RestoreAttribute) { - mData.mAttributes[i] = -1; + mData.mAttributes[i] = ESM::RefId(); } // is this relevant in cycle from 0 to 4? @@ -116,7 +118,7 @@ namespace ESM && mData.mEffectID[i] != ESM::MagicEffect::FortifySkill && mData.mEffectID[i] != ESM::MagicEffect::RestoreSkill) { - mData.mSkills[i] = -1; + mData.mSkills[i] = ESM::RefId(); } } } @@ -148,8 +150,8 @@ namespace ESM for (int i = 0; i < 4; ++i) { mData.mEffectID[i] = ESM::MagicEffect::WaterBreathing; - mData.mSkills[i] = 0; - mData.mAttributes[i] = 0; + mData.mSkills[i] = ESM::RefId(); + mData.mAttributes[i] = ESM::RefId(); } mName.clear(); diff --git a/components/esm3/loadingr.hpp b/components/esm3/loadingr.hpp index 289cf839a4..0a7b8d4e7a 100644 --- a/components/esm3/loadingr.hpp +++ b/components/esm3/loadingr.hpp @@ -28,8 +28,8 @@ namespace ESM float mWeight; int32_t mValue; RefId mEffectID[4]; // Effect, EmptyRefId means none - int32_t mSkills[4]; // SkillEnum related to effect - int32_t mAttributes[4]; // Attribute related to effect + RefId mSkills[4]; // SkillEnum related to effect + RefId mAttributes[4]; // Attribute related to effect }; IRDTstruct mData;