Skip to content

Commit

Permalink
Merge pull request #19 from powerof3/feature/exclusive-groups
Browse files Browse the repository at this point in the history
Exclusive Groups
  • Loading branch information
adya authored Mar 12, 2024
2 parents 601c0ba + 5a95589 commit 1e407a1
Show file tree
Hide file tree
Showing 15 changed files with 560 additions and 171 deletions.
4 changes: 2 additions & 2 deletions SPID/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ if (COPY_BUILD)
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> ${SkyrimPath}/SKSE/Plugins/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> ${SkyrimPath}/SKSE/Plugins/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> ${SkyrimPath}/Data/SKSE/Plugins/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> ${SkyrimPath}/Data/SKSE/Plugins/
)
else ()
message(
Expand Down
1 change: 1 addition & 0 deletions SPID/cmake/headerlist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(headers ${headers}
include/Distribute.h
include/DistributeManager.h
include/DistributePCLevelMult.h
include/ExclusiveGroups.h
include/FormData.h
include/KeywordDependencies.h
include/LogBuffer.h
Expand Down
1 change: 1 addition & 0 deletions SPID/cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(sources ${sources}
src/Distribute.cpp
src/DistributeManager.cpp
src/DistributePCLevelMult.cpp
src/ExclusiveGroups.cpp
src/FormData.cpp
src/KeywordDependencies.cpp
src/LogBuffer.cpp
Expand Down
16 changes: 8 additions & 8 deletions SPID/include/Distribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace Distribute
auto& vec = a_distributables.GetForms(a_input.onlyPlayerLevelEntries);

for (auto& formData : vec) {
if (detail::passed_filters(a_npcData, a_input, formData)) {
if (!a_npcData.HasMutuallyExclusiveForm(formData.form) && detail::passed_filters(a_npcData, a_input, formData)) {
a_callback(formData.form, formData.idxOrCount);
++formData.npcCount;
}
Expand All @@ -104,7 +104,7 @@ namespace Distribute
auto& vec = a_distributables.GetForms(a_input.onlyPlayerLevelEntries);

for (auto& formData : vec) { // Vector is reversed in FinishLookupForms
if (detail::passed_filters(a_npcData, a_input, formData) && a_callback(formData.form)) {
if (!a_npcData.HasMutuallyExclusiveForm(formData.form) && detail::passed_filters(a_npcData, a_input, formData) && a_callback(formData.form)) {
++formData.npcCount;
break;
}
Expand All @@ -121,7 +121,7 @@ namespace Distribute
auto& vec = a_distributables.GetForms(false);

for (auto& formData : vec) { // Vector is reversed in FinishLookupForms
if (detail::passed_filters(a_npcData, formData) && a_callback(formData.form)) {
if (!a_npcData.HasMutuallyExclusiveForm(formData.form) && detail::passed_filters(a_npcData, formData) && a_callback(formData.form)) {
++formData.npcCount;
break;
}
Expand All @@ -146,7 +146,7 @@ namespace Distribute
bool hasLeveledItems = false;

for (auto& formData : vec) {
if (detail::passed_filters(a_npcData, a_input, formData)) {
if (!a_npcData.HasMutuallyExclusiveForm(formData.form) && detail::passed_filters(a_npcData, a_input, formData)) {
if (formData.form->Is(RE::FormType::LeveledItem)) {
hasLeveledItems = true;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ namespace Distribute
continue;
}
if constexpr (std::is_same_v<RE::BGSKeyword, Form>) {
if (detail::passed_filters(a_npcData, a_input, formData) && a_npcData.InsertKeyword(form->GetFormEditorID())) {
if (!a_npcData.HasMutuallyExclusiveForm(form) && detail::passed_filters(a_npcData, a_input, formData) && a_npcData.InsertKeyword(form->GetFormEditorID())) {
collectedForms.emplace_back(form);
collectedFormIDs.emplace(formID);
if (formData.filters.HasLevelFilters()) {
Expand All @@ -201,7 +201,7 @@ namespace Distribute
++formData.npcCount;
}
} else {
if (detail::passed_filters(a_npcData, a_input, formData) && !detail::has_form(npc, form) && collectedFormIDs.emplace(formID).second) {
if (!a_npcData.HasMutuallyExclusiveForm(form) && detail::passed_filters(a_npcData, a_input, formData) && !detail::has_form(npc, form) && collectedFormIDs.emplace(formID).second) {
collectedForms.emplace_back(form);
if (formData.filters.HasLevelFilters()) {
collectedLeveledFormIDs.emplace(formID);
Expand Down Expand Up @@ -246,13 +246,13 @@ namespace Distribute
continue;
}
if constexpr (std::is_same_v<RE::BGSKeyword, Form>) {
if (detail::passed_filters(a_npcData, formData) && a_npcData.InsertKeyword(form->GetFormEditorID())) {
if (!a_npcData.HasMutuallyExclusiveForm(form) && detail::passed_filters(a_npcData, formData) && a_npcData.InsertKeyword(form->GetFormEditorID())) {
collectedForms.emplace_back(form);
collectedFormIDs.emplace(formID);
++formData.npcCount;
}
} else {
if (detail::passed_filters(a_npcData, formData) && !detail::has_form(npc, form) && collectedFormIDs.emplace(formID).second) {
if (!a_npcData.HasMutuallyExclusiveForm(form) && detail::passed_filters(a_npcData, formData) && !detail::has_form(npc, form) && collectedFormIDs.emplace(formID).second) {
collectedForms.emplace_back(form);
++formData.npcCount;
}
Expand Down
48 changes: 48 additions & 0 deletions SPID/include/ExclusiveGroups.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once
#include "LookupConfigs.h"

namespace ExclusiveGroups
{
using GroupName = std::string;
using LinkedGroups = std::unordered_map<RE::TESForm*, std::unordered_set<GroupName>>;
using Groups = std::unordered_map<GroupName, std::unordered_set<RE::TESForm*>>;

class Manager : public ISingleton<Manager>
{
public:
/// <summary>
/// Does a forms lookup similar to what Filters do.
///
/// As a result this method configures Manager with discovered valid exclusive groups.
/// </summary>
/// <param name=""></param>
/// <param name="rawExclusiveGroups">A raw exclusive group entries that should be processed/</param>
void LookupExclusiveGroups(RE::TESDataHandler* const dataHandler, INI::ExclusiveGroupsVec& rawExclusiveGroups);

/// <summary>
/// Gets a set of all forms that are in the same exclusive group as the given form.
/// Note that a form can appear in multiple exclusive groups, all of those groups are returned.
/// </summary>
/// <param name="form"></param>
/// <returns>A union of all groups that contain a given form.</returns>
std::unordered_set<RE::TESForm*> MutuallyExclusiveFormsForForm(RE::TESForm* form) const;

/// <summary>
/// Retrieves all exclusive groups.
/// </summary>
/// <returns>A reference to discovered exclusive groups</returns>
const Groups& GetGroups() const;

private:
/// <summary>
/// A map of exclusive group names related to each form in the exclusive groups.
/// Provides a quick and easy way to get names of all groups that need to be checked.
/// </summary>
LinkedGroups linkedGroups{};

/// <summary>
/// A map of exclusive groups names and the forms that are part of each exclusive group.
/// </summary>
Groups groups{};
};
}
Loading

0 comments on commit 1e407a1

Please sign in to comment.