From a752536ceac31dbb72352f058ee2119867f5fc2b Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 10 Nov 2012 09:35:50 +0100 Subject: [PATCH] Issue #219: added function decoding and moved same faction function from DialogueManager to Filter --- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 19 ------------------- apps/openmw/mwdialogue/filter.cpp | 8 ++++++++ apps/openmw/mwdialogue/selectwrapper.cpp | 13 +++++++++++++ apps/openmw/mwdialogue/selectwrapper.hpp | 9 +++++++-- apps/openmw/mwmechanics/npcstats.cpp | 10 ++++++++++ apps/openmw/mwmechanics/npcstats.hpp | 3 +++ 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 15852198f7..74ee44aa9b 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -97,8 +97,6 @@ namespace MWDialogue bool DialogueManager::functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info,bool choice) { - bool isCreature = (actor.getTypeName() != typeid(ESM::NPC).name()); - for (std::vector::const_iterator iter (info.mSelects.begin()); iter != info.mSelects.end(); ++iter) { @@ -131,23 +129,6 @@ namespace MWDialogue if(!selectCompare(comp,0,select.mI)) return false; break; - case 46://Same faction - { - if (isCreature) - return false; - - MWMechanics::NpcStats PCstats = MWWorld::Class::get(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()).getNpcStats(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); - MWMechanics::NpcStats NPCstats = MWWorld::Class::get(actor).getNpcStats(actor); - int sameFaction = 0; - if(!NPCstats.getFactionRanks().empty()) - { - std::string NPCFaction = NPCstats.getFactionRanks().begin()->first; - if(PCstats.getFactionRanks().find(toLower(NPCFaction)) != PCstats.getFactionRanks().end()) sameFaction = 1; - } - if(!selectCompare(comp,sameFaction,select.mI)) return false; - } - break; - case 48://Detected if(!selectCompare(comp,1,select.mI)) return false; break; diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 4ad7bc1578..1e03864bae 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -250,6 +250,14 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co return toLower (mActor.getCell()->mCell->mName)==select.getName(); + case SelectWrapper::Function_SameFaction: + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + + return MWWorld::Class::get (mActor).getNpcStats (mActor).isSameFaction ( + MWWorld::Class::get (player).getNpcStats (player)); + } + default: throw std::runtime_error ("unknown boolean select function"); diff --git a/apps/openmw/mwdialogue/selectwrapper.cpp b/apps/openmw/mwdialogue/selectwrapper.cpp index effb431108..1ffdd208cd 100644 --- a/apps/openmw/mwdialogue/selectwrapper.cpp +++ b/apps/openmw/mwdialogue/selectwrapper.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace { @@ -52,6 +53,15 @@ namespace } } +MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::decodeFunction() const +{ + int index = 0; + + std::istringstream (mSelect.mSelectRule.substr(2,2)) >> index; + + return static_cast (index); +} + MWDialogue::SelectWrapper::SelectWrapper (const ESM::DialInfo::SelectStruct& select) : mSelect (select) {} MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() const @@ -60,6 +70,7 @@ MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() con switch (type) { + case '1': return decodeFunction(); case '2': return Function_Global; case '3': return Function_Local; case '4': return Function_Journal; @@ -93,6 +104,7 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const static const Function booleanFunctions[] = { Function_Id, Function_Faction, Function_Class, Function_Race, Function_Cell, + Function_SameFaction, Function_None // end marker }; @@ -125,6 +137,7 @@ bool MWDialogue::SelectWrapper::isNpcOnly() const static const Function functions[] = { Function_Faction, SelectWrapper::Function_Class, SelectWrapper::Function_Race, + Function_SameFaction, Function_None // end marker }; diff --git a/apps/openmw/mwdialogue/selectwrapper.hpp b/apps/openmw/mwdialogue/selectwrapper.hpp index 1bd528be05..052f738376 100644 --- a/apps/openmw/mwdialogue/selectwrapper.hpp +++ b/apps/openmw/mwdialogue/selectwrapper.hpp @@ -13,7 +13,7 @@ namespace MWDialogue enum Function { - Function_None, + Function_None = 0, Function_Journal, Function_Item, Function_Dead, @@ -23,7 +23,8 @@ namespace MWDialogue Function_Race, Function_Cell, Function_Local, - Function_Global + Function_Global, + Function_SameFaction }; enum Type @@ -33,6 +34,10 @@ namespace MWDialogue Type_Numeric, Type_Boolean }; + + private: + + Function decodeFunction() const; public: diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 5b2ce739f2..cc054c1dcd 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -86,6 +86,16 @@ const std::map& MWMechanics::NpcStats::getFactionRanks() const return mFactionRank; } +bool MWMechanics::NpcStats::isSameFaction (const NpcStats& npcStats) const +{ + for (std::map::const_iterator iter (mFactionRank.begin()); iter!=mFactionRank.end(); + ++iter) + if (npcStats.mFactionRank.find (iter->first)!=npcStats.mFactionRank.end()) + return true; + + return false; +} + float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& class_, int usageType, int level) const { diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index 35af4afa02..a6f7adaf11 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -76,6 +76,9 @@ namespace MWMechanics std::map& getFactionRanks(); + bool isSameFaction (const NpcStats& npcStats) const; + ///< Do *this and \a npcStats share a faction? + const std::map& getFactionRanks() const; float getSkillGain (int skillIndex, const ESM::Class& class_, int usageType = -1,