From 6def751bb228357d7ea18a762339d11b8713ae85 Mon Sep 17 00:00:00 2001 From: Arkadii Hlushchevskyi Date: Sun, 7 Apr 2024 20:26:41 +0300 Subject: [PATCH] Allowed specifying LevSpell entries directly in Spell. LevSpell is still supported. --- SPID/src/LinkedDistribution.cpp | 24 +++++++++++++++++++++++- SPID/src/LookupForms.cpp | 19 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/SPID/src/LinkedDistribution.cpp b/SPID/src/LinkedDistribution.cpp index c839ac5..b06ed58 100644 --- a/SPID/src/LinkedDistribution.cpp +++ b/SPID/src/LinkedDistribution.cpp @@ -110,10 +110,32 @@ namespace LinkedDistribution void Manager::LookupLinkedForms(RE::TESDataHandler* dataHandler, INI::LinkedFormsConfig& rawLinkedForms) { - ForEachLinkedForms([&](LinkedForms
& forms) { + ForEachLinkedForms([&](LinkedForms& forms) { + // If it's spells distributable we want to manually lookup forms to pick LevSpells that are added into the list. + if constexpr (std::is_same_v) { + return; + } forms.LookupForms(dataHandler, rawLinkedForms[forms.GetType()]); }); + // Sort out Spells and Leveled Spells into two separate lists. + auto& rawSpells = rawLinkedForms[RECORD::kSpell]; + + for (auto& rawSpell : rawSpells) { + if (auto form = detail::LookupLinkedForm(dataHandler, rawSpell); form) { + auto& [formID, scope, parentFormIDs, idxOrCount, chance, path] = rawSpell; + FormVec parentForms{}; + if (!Forms::detail::formID_to_form(dataHandler, parentFormIDs.MATCH, parentForms, path, false, false)) { + continue; + } + if (const auto spell = form->As(); spell) { + spells.Link(spell, scope, parentForms, idxOrCount, chance, path); + } else if (const auto levSpell = form->As(); levSpell) { + levSpells.Link(levSpell, scope, parentForms, idxOrCount, chance, path); + } + } + } + auto& genericForms = rawLinkedForms[RECORD::kForm]; for (auto& rawForm : genericForms) { if (auto form = detail::LookupLinkedForm(dataHandler, rawForm); form) { diff --git a/SPID/src/LookupForms.cpp b/SPID/src/LookupForms.cpp index 7cc5950..6b88551 100644 --- a/SPID/src/LookupForms.cpp +++ b/SPID/src/LookupForms.cpp @@ -8,12 +8,29 @@ bool LookupDistributables(RE::TESDataHandler* const dataHandler) { using namespace Forms; - ForEachDistributable([&](Distributables& a_distributable) { + ForEachDistributable([&](Distributables& a_distributable) { + // If it's spells distributable we want to manually lookup forms to pick LevSpells that are added into the list. + if constexpr (std::is_same_v) { + return; + } const auto& recordName = RECORD::GetTypeName(a_distributable.GetType()); a_distributable.LookupForms(dataHandler, recordName, INI::configs[a_distributable.GetType()]); }); + // Sort out Spells and Leveled Spells into two separate lists. + auto& rawSpells = INI::configs[RECORD::kSpell]; + + for (auto& rawSpell : rawSpells) { + LookupGenericForm(dataHandler, rawSpell, [&](bool isValid, auto form, const auto& idxOrCount, const auto& filters, const auto& path) { + if (const auto spell = form->As(); spell) { + spells.EmplaceForm(isValid, spell, idxOrCount, filters, path); + } else if(const auto levSpell = form->As(); levSpell) { + levSpells.EmplaceForm(isValid, levSpell, idxOrCount, filters, path); + } + }); + } + auto& genericForms = INI::configs[RECORD::kForm]; for (auto& rawForm : genericForms) {