Skip to content

Commit

Permalink
Implemented a way to overwrite outfits with linked outfits.
Browse files Browse the repository at this point in the history
  • Loading branch information
adya committed Mar 31, 2024
1 parent 78f3468 commit cb7e295
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
22 changes: 0 additions & 22 deletions SPID/include/Distribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,6 @@ namespace Distribute
}
#pragma endregion

// TODO: Is this unused?
// outfits/sleep outfits
template <class Form>
void for_each_form(
const NPCData& a_npcData,
Forms::Distributables<Form>& a_distributables,
std::function<bool(Form*)> a_callback,
DistributedForms* accumulatedForms = nullptr)
{
auto& vec = a_distributables.GetForms(false);

for (auto& formData : vec) { // Vector is reversed in FinishLookupForms
if (!a_npcData.HasMutuallyExclusiveForm(formData.form) && detail::passed_filters(a_npcData, formData) && a_callback(formData.form)) {
if (accumulatedForms) {
accumulatedForms->insert({ formData.form, formData.path });
}
++formData.npcCount;
break;
}
}
}

#pragma region Items
// countable items
template <class Form>
Expand Down
15 changes: 8 additions & 7 deletions SPID/src/Distribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ namespace Distribute
/// <param name="npcData">General information about NPC that is being processed.</param>
/// <param name="input">Leveling information about NPC that is being processed.</param>
/// <param name="forms">A set of forms that should be distributed to NPC.</param>
/// <param name="allowOverwrites">If true, overwritable forms (like Outfits) will be to overwrite last distributed form on NPC.</param>
/// <param name="accumulatedForms">An optional pointer to a set that will accumulate all distributed forms.</param>
void distribute(NPCData& npcData, const PCLevelMult::Input& input, Forms::DistributionSet& forms, DistributedForms* accumulatedForms)
void distribute(NPCData& npcData, const PCLevelMult::Input& input, Forms::DistributionSet& forms, bool allowOverwrites, DistributedForms* accumulatedForms)
{
const auto npc = npcData.GetNPC();

Expand Down Expand Up @@ -124,7 +125,7 @@ namespace Distribute

for_each_form<RE::BGSOutfit>(
npcData, forms.outfits, input, [&](auto* a_outfit) {
if (npc->defaultOutfit != a_outfit && !npc->HasKeyword(processedOutfit)) {
if (npc->defaultOutfit != a_outfit && (allowOverwrites || !npc->HasKeyword(processedOutfit))) {
npc->AddKeyword(processedOutfit);
npc->defaultOutfit = a_outfit;
return true;
Expand Down Expand Up @@ -193,13 +194,13 @@ namespace Distribute

DistributedForms distributedForms{};

detail::distribute(npcData, input, entries, &distributedForms);
detail::distribute(npcData, input, entries, false, &distributedForms);
// TODO: We can now log per-NPC distributed forms.

if (!distributedForms.empty()) {
// This only does one-level linking. So that linked entries won't trigger another level of distribution.
// TODO: This only does one-level linking. So that linked entries won't trigger another level of distribution.
LinkedDistribution::Manager::GetSingleton()->ForEachLinkedDistributionSet(distributedForms, [&](Forms::DistributionSet& set) {
detail::distribute(npcData, input, set, nullptr); // TODO: Accumulate forms here? to log what was distributed.
detail::distribute(npcData, input, set, true, nullptr); // TODO: Accumulate forms here? to log what was distributed.
});
}
}
Expand Down Expand Up @@ -229,12 +230,12 @@ namespace Distribute
Forms::DistributionSet::empty<RE::TESObjectARMO>()
};

detail::distribute(npcData, input, entries, &distributedForms);
detail::distribute(npcData, input, entries, false, &distributedForms);
// TODO: We can now log per-NPC distributed forms.

if (!distributedForms.empty()) {
LinkedDistribution::Manager::GetSingleton()->ForEachLinkedDeathDistributionSet(distributedForms, [&](Forms::DistributionSet& set) {
detail::distribute(npcData, input, set, nullptr); // TODO: Accumulate forms here? to log what was distributed.
detail::distribute(npcData, input, set, true, nullptr); // TODO: Accumulate forms here? to log what was distributed.
});
}
}
Expand Down

0 comments on commit cb7e295

Please sign in to comment.