Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
adya committed Mar 25, 2024
2 parents 489af26 + f7fffe2 commit 7dd0328
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
PUBLISH_MOD_CHANGELOG_FILE: "FOMOD/changelog.txt"
PUBLISH_MOD_DESCRIPTION_FILE: "FOMOD/description.txt"
PUBLISH_ARCHIVE_TYPE: '7z'
VCPKG_COMMIT_ID: '53bef8994c541b6561884a8395ea35715ece75db'
VCPKG_COMMIT_ID: '9854d1d92200d81dde189e53b64c9ba6a305dc9f'
6 changes: 3 additions & 3 deletions .github/workflows/maintenance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'

- name: Run clang-format
run: find -type f \( -name *.h -o -name *.cpp \) | xargs clang-format-14 -style=file -i
Expand Down
2 changes: 1 addition & 1 deletion SPID/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
set(NAME "po3_SpellPerkItemDistributor" CACHE STRING "")
set(VERSION 6.8.2 CACHE STRING "")
set(VERSION 6.8.5 CACHE STRING "")
set(AE_VERSION 1)
set(VR_VERSION 1)

Expand Down
33 changes: 15 additions & 18 deletions SPID/include/Cache.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#pragma once

namespace Cache
namespace FormType
{
namespace FormType
{
inline constexpr std::array whitelist{
RE::FormType::Faction,
RE::FormType::Class,
RE::FormType::CombatStyle,
RE::FormType::Race,
RE::FormType::Outfit,
RE::FormType::NPC,
RE::FormType::VoiceType,
RE::FormType::FormList,
RE::FormType::Spell,
RE::FormType::Armor,
RE::FormType::Location
};
inline constexpr std::array whitelist{
RE::FormType::Faction,
RE::FormType::Class,
RE::FormType::CombatStyle,
RE::FormType::Race,
RE::FormType::Outfit,
RE::FormType::NPC,
RE::FormType::VoiceType,
RE::FormType::FormList,
RE::FormType::Spell,
RE::FormType::Armor,
RE::FormType::Location
};

bool GetWhitelisted(RE::FormType a_type);
}
bool GetWhitelisted(RE::FormType a_type);
}
1 change: 1 addition & 0 deletions SPID/include/DependencyResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class DependencyResolver
for (const auto& pair : nodes) {
delete pair.second;
}
nodes.clear();
}

/// Attempts to create a dependency rule between `parent` and `dependency` objects.
Expand Down
39 changes: 22 additions & 17 deletions SPID/include/Distribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ namespace Distribute
}
}

void equip_worn_outfit(RE::Actor* actor, const RE::BGSOutfit* a_outfit);
void add_item(RE::Actor* a_actor, RE::TESBoundObject* a_item, std::uint32_t a_itemCount);
void init_leveled_items(RE::Actor* a_actor);
bool can_equip_outfit(const RE::TESNPC* a_npc, RE::BGSOutfit* a_outfit);
}

#pragma region Packages, Death Items
Expand Down Expand Up @@ -143,21 +140,32 @@ namespace Distribute
// countable items
template <class Form>
void for_each_form(
const NPCData& a_npcData,
Forms::DataVec<Form>& forms,
const PCLevelMult::Input& a_input,
std::function<bool(std::map<Form*, Count>&, bool)> a_callback,
std::set<RE::TESForm*>* accumulatedForms = nullptr)
const NPCData& a_npcData,
Forms::DataVec<Form>& forms,
const PCLevelMult::Input& a_input,
std::function<bool(std::map<Form*, Count>&)> a_callback,
std::set<RE::TESForm*>* accumulatedForms = nullptr)
{
std::map<Form*, Count> collectedForms{};
bool hasLeveledItems = false;

for (auto& formData : forms) {
if (!a_npcData.HasMutuallyExclusiveForm(formData.form) && detail::passed_filters(a_npcData, a_input, formData)) {
if (formData.form->Is(RE::FormType::LeveledItem)) {
hasLeveledItems = true;
// TODO: Safe guard getting RandomCount and if for any reason there is a PackageIndex, default it to count = 1
auto count = std::get<RandomCount>(formData.idxOrCount).GetRandom();
if (auto leveledItem = formData.form->As<RE::TESLevItem>())
{
auto level = a_npcData.GetLevel();
RE::BSScrapArray<RE::CALCED_OBJECT> calcedObjects{};

leveledItem->CalculateCurrentFormList(level, count, calcedObjects, 0, true);
for (auto& calcObj : calcedObjects) {
collectedForms[static_cast<RE::TESBoundObject*>(calcObj.form)] += calcObj.count;
}
}
else
{
collectedForms[formData.form] += count;
}
collectedForms.emplace(formData.form, std::get<RandomCount>(formData.idxOrCount).GetRandom());
++formData.npcCount;
}
}
Expand All @@ -166,7 +174,7 @@ namespace Distribute
if (accumulatedForms) {
std::ranges::copy(collectedForms | std::views::keys, std::inserter(*accumulatedForms, accumulatedForms->end()));
}
a_callback(collectedForms, hasLeveledItems);
a_callback(collectedForms);
}
}
#pragma endregion
Expand Down Expand Up @@ -231,8 +239,5 @@ namespace Distribute
#pragma endregion

void Distribute(NPCData& a_npcData, const PCLevelMult::Input& a_input);
void DistributeItemOutfits(NPCData& a_npcData, const PCLevelMult::Input& a_input);

void Distribute(NPCData& a_npcData, bool a_onlyLeveledEntries, bool a_noItemOutfits = false);

void Distribute(NPCData& a_npcData, bool a_onlyLeveledEntries);
}
3 changes: 1 addition & 2 deletions SPID/include/DistributeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace Distribute
{
inline RE::BGSKeyword* processed{ nullptr };
inline RE::BGSKeyword* processedOnLoad{ nullptr };
inline RE::BGSKeyword* processedOutfit{ nullptr };

namespace detail
{
bool should_process_NPC(RE::TESNPC* a_npc, RE::BGSKeyword* a_keyword = processed);
void force_equip_outfit(RE::Actor* a_actor, const RE::TESNPC* a_npc);
void distribute_on_load(RE::Actor* a_actor, RE::TESNPC* a_npc);
}

namespace Actor
Expand Down
6 changes: 3 additions & 3 deletions SPID/include/FormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace Forms

if (whitelistedOnly && form) {
const auto formType = form->GetFormType();
if (Cache::FormType::GetWhitelisted(formType)) {
if (FormType::GetWhitelisted(formType)) {
return form;
} else {
throw InvalidFormTypeException(formType, formOrEditorID, path);
Expand Down Expand Up @@ -406,15 +406,15 @@ namespace Forms
void ForEachDistributable(Func&& a_func, Args&&... args)
{
a_func(keywords, std::forward<Args>(args)...);
a_func(factions, std::forward<Args>(args)...);
a_func(perks, std::forward<Args>(args)...);
a_func(spells, std::forward<Args>(args)...);
a_func(levSpells, std::forward<Args>(args)...);
a_func(perks, std::forward<Args>(args)...);
a_func(shouts, std::forward<Args>(args)...);
a_func(items, std::forward<Args>(args)...);
a_func(deathItems, std::forward<Args>(args)...);
a_func(outfits, std::forward<Args>(args)...);
a_func(sleepOutfits, std::forward<Args>(args)...);
a_func(factions, std::forward<Args>(args)...);
a_func(packages, std::forward<Args>(args)...);
a_func(skins, std::forward<Args>(args)...);
}
Expand Down
9 changes: 2 additions & 7 deletions SPID/include/LookupNPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ namespace NPC
[[nodiscard]] bool HasMutuallyExclusiveForm(RE::TESForm* otherForm) const;

[[nodiscard]] std::uint16_t GetLevel() const;
[[nodiscard]] RE::SEX GetSex() const;
[[nodiscard]] bool IsUnique() const;
[[nodiscard]] bool IsSummonable() const;
[[nodiscard]] bool IsChild() const;
[[nodiscard]] bool IsLeveled() const;
[[nodiscard]] bool IsTeammate() const;
Expand All @@ -41,6 +38,7 @@ namespace NPC
{
ID() = default;
explicit ID(const RE::TESActorBase* a_base);
~ID() = default;

[[nodiscard]] bool contains(const std::string& a_str) const;

Expand All @@ -57,14 +55,11 @@ namespace NPC

RE::TESNPC* npc;
RE::Actor* actor;
std::string name;
RE::TESRace* race;
std::vector<ID> IDs;
std::string name;
StringSet keywords{};
std::uint16_t level;
RE::SEX sex;
bool unique;
bool summonable;
bool child;
bool teammate;
bool leveled;
Expand Down
4 changes: 2 additions & 2 deletions SPID/include/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ struct overload : Ts...
};

template <class K, class D>
using Map = ankerl::unordered_dense::segmented_map<K, D>;
using Map = ankerl::unordered_dense::map<K, D>;
template <class K>
using Set = ankerl::unordered_dense::segmented_set<K>;
using Set = ankerl::unordered_dense::set<K>;

struct string_hash
{
Expand Down
7 changes: 2 additions & 5 deletions SPID/src/Cache.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "Cache.h"

namespace Cache
bool FormType::GetWhitelisted(const RE::FormType a_type)
{
bool FormType::GetWhitelisted(const RE::FormType a_type)
{
return std::ranges::find(whitelist, a_type) != whitelist.end();
}
return std::ranges::find(whitelist, a_type) != whitelist.end();
}
Loading

0 comments on commit 7dd0328

Please sign in to comment.