Skip to content

Commit

Permalink
Rewrite FactionStealing to check all unique/persistent members of t…
Browse files Browse the repository at this point in the history
…he faction
  • Loading branch information
powerof3 committed Oct 18, 2024
1 parent 9b8974a commit 68ae037
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion extern/CommonLibSSE
55 changes: 28 additions & 27 deletions src/Tweaks/FactionStealing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
//removes steal tag if all faction members have appropriate relationship rank
namespace Tweaks::FactionStealing
{
struct CanTake
struct detail
{
struct detail
static std::int32_t GetFavorCost(RE::TESNPC* a_player, RE::TESNPC* a_owner)
{
static std::int32_t GetFavorCost(RE::TESNPC* a_player, RE::TESNPC* a_owner)
{
using func_t = decltype(&GetFavorCost);
static REL::Relocation<func_t> func{ REL_ID(23626, 24078) };
return func(a_player, a_owner);
}
using func_t = decltype(&GetFavorCost);
static REL::Relocation<func_t> func{ REL_ID(23626, 24078) };
return func(a_player, a_owner);
}

static bool CanTake(RE::TESNPC* a_playerBase, RE::TESNPC* a_npc, std::int32_t a_cost)
{
const auto favorCost = GetFavorCost(a_playerBase, a_npc);
return favorCost > 1 ?
a_cost <= favorCost :
false;
}
};
static bool CanTake(RE::TESNPC* a_playerBase, RE::TESNPC* a_npc, std::int32_t a_cost)
{
const auto favorCost = GetFavorCost(a_playerBase, a_npc);
return favorCost > 1 ?
a_cost <= favorCost :
false;
}
};

struct CanTake
{
static bool func(const RE::PlayerCharacter* a_player, RE::TESForm* a_owner, std::int32_t a_cost)
{
if (!a_owner) {
Expand All @@ -43,20 +43,21 @@ namespace Tweaks::FactionStealing
return true;
}

if (const auto processLists = RE::ProcessLists::GetSingleton(); processLists && processLists->numberHighActors > 0) {
std::vector<RE::TESNPC*> vec;
for (auto& handle : processLists->highActorHandles) {
const auto actor = handle.get();
if (actor && actor->IsInFaction(faction)) {
if (const auto base = actor->GetActorBase(); base) {
vec.push_back(base);
}
std::vector<RE::TESNPC*> factionNPCs{};

for (auto& npc : RE::TESDataHandler::GetSingleton()->GetFormArray<RE::TESNPC>()) {
if (npc && !npc->IsDeleted()) {
if (npc->IsInFaction(faction)) {
factionNPCs.push_back(npc);
} else if (auto actor = npc->GetUniqueActor(); actor && actor->IsInFaction(faction)) {
factionNPCs.push_back(npc);
}
}
return std::ranges::all_of(vec, [&](const auto& npc) {
return detail::CanTake(playerBase, npc, a_cost);
});
}

return std::ranges::all_of(factionNPCs, [&](const auto& npc) {
return detail::CanTake(playerBase, npc, a_cost);
});
}

return false;
Expand Down

0 comments on commit 68ae037

Please sign in to comment.