1

Simplified exclusion arguments

This commit is contained in:
Eddoursul 2022-06-24 20:32:16 +02:00
parent d899a2a03f
commit 20462fa9d3
9 changed files with 23 additions and 77 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,54 +2,6 @@
namespace Papyrus::ArtifactTracker namespace Papyrus::ArtifactTracker
{ {
inline bool is_excluded(RE::TESForm* a_form, RE::TESForm* a_excludeForm = NULL, bool nested = true)
{
if (!a_excludeForm) {
return false;
}
const RE::BGSListForm* list = a_excludeForm->As<RE::BGSListForm>();
if (list) {
if (list->HasForm(a_form)) {
return true;
} else if (nested) {
bool isExcluded = false;
list->ForEachForm([&](RE::TESForm& a_exform) {
const auto exlist = a_exform.As<RE::BGSListForm>();
if (exlist) {
if (exlist->forms.size() > 0) {
if (exlist->forms[0]->Is(RE::FormType::Keyword) ? a_form->HasKeywordInList(exlist, false) : exlist->HasForm(a_form)) {
isExcluded = true;
return false;
}
}
} else {
const auto exkeyword = a_exform.As<RE::BGSKeyword>();
if (exkeyword && a_form->As<RE::BGSKeywordForm>()->HasKeyword(exkeyword)) {
isExcluded = true;
return false;
}
}
return true;
});
return isExcluded;
}
}
const RE::BGSKeyword* keyword = a_excludeForm->As<RE::BGSKeyword>();
if (keyword) {
if (a_form->As<RE::BGSKeywordForm>()->HasKeyword(keyword)) {
return true;
}
}
return false;
}
inline bool is_artifact(RE::TESForm* a_form) inline bool is_artifact(RE::TESForm* a_form)
{ {
switch (a_form->GetFormType()) { switch (a_form->GetFormType()) {
@ -69,8 +21,8 @@ namespace Papyrus::ArtifactTracker
inline std::int32_t AddAllFormsToList(RE::StaticFunctionTag*, inline std::int32_t AddAllFormsToList(RE::StaticFunctionTag*,
RE::BGSListForm* a_targetList, RE::BGSListForm* a_targetList,
short a_formType, short a_formType,
RE::TESForm* a_excludeForm = NULL, RE::BGSListForm* a_storedList,
bool excludeNested = true) RE::BGSListForm* a_foundList)
{ {
const auto formType = static_cast<RE::FormType>(a_formType); const auto formType = static_cast<RE::FormType>(a_formType);
@ -78,7 +30,7 @@ namespace Papyrus::ArtifactTracker
case RE::FormType::Book: case RE::FormType::Book:
for (auto const& item : BookCheck::GetBookList()) { for (auto const& item : BookCheck::GetBookList()) {
if (!a_excludeForm || !is_excluded(item.second, a_excludeForm, excludeNested)) { if (!a_storedList->HasForm(item.second) && !a_foundList->HasForm(item.second)) {
a_targetList->AddForm(item.second); a_targetList->AddForm(item.second);
} }
} }
@ -86,7 +38,7 @@ namespace Papyrus::ArtifactTracker
case RE::FormType::Misc: case RE::FormType::Misc:
for (auto const& item : MiscCheck::GetMiscList()) { for (auto const& item : MiscCheck::GetMiscList()) {
if (!a_excludeForm || !is_excluded(item.second, a_excludeForm, excludeNested)) { if (!a_storedList->HasForm(item.second) && !a_foundList->HasForm(item.second)) {
a_targetList->AddForm(item.second); a_targetList->AddForm(item.second);
} }
} }
@ -106,7 +58,7 @@ namespace Papyrus::ArtifactTracker
if (!form || !form->GetPlayable()) { if (!form || !form->GetPlayable()) {
continue; continue;
} }
if (a_excludeForm && is_excluded(form, a_excludeForm, excludeNested)) { if (a_storedList->HasForm(form) || a_foundList->HasForm(form)) {
continue; continue;
} }
a_targetList->AddForm(form); a_targetList->AddForm(form);
@ -119,8 +71,7 @@ namespace Papyrus::ArtifactTracker
inline std::int32_t AddArtifactsToList(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*, inline std::int32_t AddArtifactsToList(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*,
RE::TESForm* a_refOrList, RE::TESForm* a_refOrList,
RE::BGSListForm* a_targetList, RE::BGSListForm* a_targetList,
RE::TESForm* a_excludeForm = NULL, RE::BGSListForm* a_excludeList = NULL)
bool excludeNested = false)
{ {
if (!a_refOrList) { if (!a_refOrList) {
a_vm->TraceStack("a_refOrList in AddArtifactsToList is None", a_stackID); a_vm->TraceStack("a_refOrList in AddArtifactsToList is None", a_stackID);
@ -135,7 +86,7 @@ namespace Papyrus::ArtifactTracker
a_refOrList->As<RE::BGSListForm>()->ForEachForm([&](RE::TESForm& a_exform) { a_refOrList->As<RE::BGSListForm>()->ForEachForm([&](RE::TESForm& a_exform) {
const auto refrItem = a_exform.As<RE::TESObjectREFR>(); const auto refrItem = a_exform.As<RE::TESObjectREFR>();
if (refrItem) { if (refrItem) {
AddArtifactsToList(a_vm, a_stackID, nullptr, refrItem, a_targetList, a_excludeForm); AddArtifactsToList(a_vm, a_stackID, nullptr, refrItem, a_targetList, a_excludeList);
} }
return true; return true;
}); });
@ -149,8 +100,8 @@ namespace Papyrus::ArtifactTracker
return 0; return 0;
} }
auto inv = containerRef->GetInventory([&](RE::TESBoundObject& a_exform) { const auto inv = containerRef->GetInventory([&](RE::TESBoundObject& a_exform) {
return is_artifact(&a_exform) && !is_excluded(&a_exform, a_excludeForm, excludeNested); return is_artifact(&a_exform) && (!a_excludeList || !a_excludeList->HasForm(&a_exform));
}); });
for (const auto& item : inv) { for (const auto& item : inv) {
@ -198,8 +149,7 @@ namespace Papyrus::ArtifactTracker
inline void SyncCellStorage(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*, inline void SyncCellStorage(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*,
RE::TESObjectREFR* a_cellStorage, RE::TESObjectREFR* a_cellStorage,
RE::BGSListForm* a_excludeContainers, RE::BGSListForm* a_excludeContainers)
RE::TESForm* a_excludeForm = NULL)
{ {
if (!a_cellStorage) { if (!a_cellStorage) {
return; return;
@ -226,7 +176,7 @@ namespace Papyrus::ArtifactTracker
if (data.first > 0) { if (data.first > 0) {
cellItems[item->formID] = true; cellItems[item->formID] = true;
if (inv.find(item) == inv.end()) { if (inv.find(item) == inv.end()) {
if (is_artifact(item) && !is_excluded(item, a_excludeForm)) { if (is_artifact(item)) {
a_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr); a_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr);
} }
} }
@ -251,11 +201,9 @@ namespace Papyrus::ArtifactTracker
} }
if (inv.find(baseObj) == inv.end()) { if (inv.find(baseObj) == inv.end()) {
if (!a_excludeForm || !is_excluded(baseObj, a_excludeForm)) {
a_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr); a_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr);
} }
} }
}
for (const auto& [item, data] : inv) { for (const auto& [item, data] : inv) {
const auto& [count, entry] = data; const auto& [count, entry] = data;
@ -285,12 +233,11 @@ namespace Papyrus::ArtifactTracker
inline std::int32_t AddArtifactsFromFollowersToList(RE::StaticFunctionTag*, inline std::int32_t AddArtifactsFromFollowersToList(RE::StaticFunctionTag*,
RE::BGSListForm* a_targetList, RE::BGSListForm* a_targetList,
RE::TESForm* a_excludeForm = NULL, RE::BGSListForm* a_excludeList = NULL)
bool excludeNested = false)
{ {
for (const auto& actor : GetPlayerFollowers(nullptr)) { for (const auto& actor : GetPlayerFollowers(nullptr)) {
auto inv = actor->GetInventory([&](RE::TESBoundObject& a_exform) { const auto inv = actor->GetInventory([&](RE::TESBoundObject& a_exform) {
return is_artifact(&a_exform) && !is_excluded(&a_exform, a_excludeForm, excludeNested); return is_artifact(&a_exform) && (!a_excludeList || !a_excludeList->HasForm(&a_exform));
}); });
for (const auto& item : inv) { for (const auto& item : inv) {

View File

@ -1,17 +1,17 @@
Scriptname ETR_Functions Hidden Scriptname ETR_Functions Hidden
int function AddAllFormsToList(FormList targetList, int formType, Form excludeForm = None, bool excludeNested = true) native global int function AddAllFormsToList(FormList targetList, int formType, FormList storedList, FormList foundList) native global
int function AddArtifactsToList(Form refOrList, FormList targetList, Form excludeForm = None, bool excludeNested = false) native global int function AddArtifactsToList(Form refOrList, FormList targetList, FormList excludeList = None) native global
int function GetItemCountInList(FormList refList, Form baseForm) native global int function GetItemCountInList(FormList refList, Form baseForm) native global
ObjectReference function GetCellStorage(ObjectReference ref, FormList refList, Form refToCreate, bool autoCreate = true) native global ObjectReference function GetCellStorage(ObjectReference ref, FormList refList, Form refToCreate, bool autoCreate = true) native global
function SyncCellStorage(ObjectReference cellStorage, FormList excludeContainers, Form excludeForm = None) native global function SyncCellStorage(ObjectReference cellStorage, FormList excludeContainers) native global
Actor[] function GetPlayerFollowers() native global Actor[] function GetPlayerFollowers() native global
bool function FollowersHaveItem(Form baseForm) native global bool function FollowersHaveItem(Form baseForm) native global
int function AddArtifactsFromFollowersToList(FormList targetList, Form excludeForm = None, bool excludeNested = false) native global int function AddArtifactsFromFollowersToList(FormList targetList, FormList excludeList = None) native global

View File

@ -6,7 +6,6 @@ FormList Property ETR_ItemsNew Auto
FormList Property ETR_ItemsFound Auto FormList Property ETR_ItemsFound Auto
FormList Property ETR_ItemsStored Auto FormList Property ETR_ItemsStored Auto
FormList Property ETR_PersistentStorageList Auto FormList Property ETR_PersistentStorageList Auto
FormList Property ETR_FoundAndStored Auto
GlobalVariable Property ETR_NotifyNewArtifact Auto GlobalVariable Property ETR_NotifyNewArtifact Auto
@ -48,10 +47,10 @@ event OnPlayerLoadGame()
ETR_Functions.AddArtifactsFromFollowersToList(ETR_ItemsFound, ETR_ItemsStored) ETR_Functions.AddArtifactsFromFollowersToList(ETR_ItemsFound, ETR_ItemsStored)
ETR_ItemsNew.Revert() ETR_ItemsNew.Revert()
ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 41, ETR_FoundAndStored) ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 41, ETR_ItemsStored, ETR_ItemsFound)
ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 32, ETR_FoundAndStored) ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 32, ETR_ItemsStored, ETR_ItemsFound)
ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 27, ETR_FoundAndStored) ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 27, ETR_ItemsStored, ETR_ItemsFound)
ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 26, ETR_FoundAndStored) ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 26, ETR_ItemsStored, ETR_ItemsFound)
endevent endevent