diff --git a/skse64/GameFormComponents.h b/skse64/GameFormComponents.h index 15e8533..5b2983c 100644 --- a/skse64/GameFormComponents.h +++ b/skse64/GameFormComponents.h @@ -1332,7 +1332,7 @@ class BGSSkillPerkTreeNode virtual bool Accept(BGSPerk * node) = 0; }; - bool VisitPerks(PerkVisitor & visitor) + bool VisitPerks(PerkVisitor & visitor, const int depth = 0) { if(visitor.Accept(perk)) return true; @@ -1342,7 +1342,7 @@ class BGSSkillPerkTreeNode BGSSkillPerkTreeNode* connector = NULL; connections.GetNthItem(i, connector); - if(connector->VisitPerks(visitor)) + if(depth < 32 && connector->VisitPerks(visitor, depth + 1)) return true; } diff --git a/skse64/PapyrusActorValueInfo.cpp b/skse64/PapyrusActorValueInfo.cpp index 752f035..b94ca01 100644 --- a/skse64/PapyrusActorValueInfo.cpp +++ b/skse64/PapyrusActorValueInfo.cpp @@ -15,43 +15,19 @@ class MatchSkillPerks : public BGSSkillPerkTreeNode::PerkVisitor virtual bool Accept(BGSPerk * perk) { - if(perk) + if(perk && !GetPerkAdded(perk)) { - bool addPerk = true; - if(m_actor) { - if(!CALL_MEMBER_FN(m_actor, HasPerk)(perk)) - addPerk = m_unowned; - else - addPerk = !m_unowned; - } - - if(addPerk) { - AddPerk(perk); - } - - if(m_allRanks) { - BGSPerk * nextPerk = perk->nextPerk; - while(nextPerk) { - addPerk = true; - if(m_actor) { - if(!CALL_MEMBER_FN(m_actor, HasPerk)(nextPerk)) - addPerk = m_unowned; - else - addPerk = !m_unowned; - } - - if(addPerk) { - AddPerk(nextPerk); - } - - nextPerk = nextPerk->nextPerk; - } - } + do + { if (!m_actor || (!CALL_MEMBER_FN(m_actor, HasPerk)(perk) ? m_unowned : !m_unowned) ) + AddPerk(perk); + perk = m_allRanks ? perk->nextPerk : nullptr; + } while (perk); } return false; } virtual void AddPerk(BGSPerk * perk) = 0; + virtual bool GetPerkAdded(BGSPerk *perk) = 0; }; class PerkFormListVisitor : public MatchSkillPerks @@ -67,6 +43,13 @@ class PerkFormListVisitor : public MatchSkillPerks { CALL_MEMBER_FN(m_formList, AddFormToList)(perk); } + + virtual bool GetPerkAdded(BGSPerk *perk) + { + TESForm *base = perk; + + return ((*m_formList).forms.GetItemIndex(base) > -1); + } }; class PerkArrayVisitor : public MatchSkillPerks @@ -81,6 +64,17 @@ class PerkArrayVisitor : public MatchSkillPerks { m_perks->push_back(perk); } + virtual bool GetPerkAdded(BGSPerk *perk) + { + std::vector::const_iterator offbounds = (*m_perks).cend(); + + for (std::vector::const_iterator i = (*m_perks).cbegin(); i != offbounds; ++i) + { if (*i != perk) + continue ; + return (true); + } + return (false); + } }; namespace papyrusActorValueInfo