From e68bb3481e3150bc3b3f70ecaeadb9b3ea32860a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 8 Nov 2012 21:48:17 +0100 Subject: [PATCH] Issue #219: moved over the second batch of functions (boolean and one integer I forgot last time) --- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 82 ------------------- apps/openmw/mwdialogue/filter.cpp | 28 +++++++ apps/openmw/mwdialogue/selectwrapper.cpp | 41 +++++++--- apps/openmw/mwdialogue/selectwrapper.hpp | 13 ++- 4 files changed, 70 insertions(+), 94 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 3f7f954f6d..5d3bebbc0e 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -289,8 +289,6 @@ namespace MWDialogue bool DialogueManager::isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo::SelectStruct& select) const { - bool isCreature = (actor.getTypeName() != typeid(ESM::NPC).name()); - char type = select.mSelectRule[1]; if (type!='0') @@ -345,86 +343,6 @@ namespace MWDialogue return true; - case '6': // dead - - return selectCompare (comp, - MWBase::Environment::get().getMechanicsManager()->countDeaths (toLower (name)), select.mI); - - case '7':// not ID - if(select.mType==ESM::VT_String ||select.mType==ESM::VT_Int)//bug in morrowind here? it's not a short, it's a string - { - int isID = int(toLower(name)==toLower(MWWorld::Class::get (actor).getId (actor))); - if (selectCompare(comp,!isID,select.mI)) return false; - } - else - throw std::runtime_error ( - "unsupported variable type in dialogue info select"); - - return true; - - case '8':// not faction - if (isCreature) - return false; - - if(select.mType==ESM::VT_Int) - { - MWWorld::LiveCellRef* npc = actor.get(); - int isFaction = int(toLower(npc->mBase->mFaction) == toLower(name)); - if(selectCompare(comp,!isFaction,select.mI)) - return false; - } - else - throw std::runtime_error ( - "unsupported variable type in dialogue info select"); - - return true; - - case '9':// not class - if (isCreature) - return false; - - if(select.mType==ESM::VT_Int) - { - MWWorld::LiveCellRef* npc = actor.get(); - int isClass = int(toLower(npc->mBase->mClass) == toLower(name)); - if(selectCompare(comp,!isClass,select.mI)) - return false; - } - else - throw std::runtime_error ( - "unsupported variable type in dialogue info select"); - - return true; - - case 'A'://not Race - if (isCreature) - return false; - - if(select.mType==ESM::VT_Int) - { - MWWorld::LiveCellRef* npc = actor.get(); - int isRace = int(toLower(npc->mBase->mRace) == toLower(name)); - if(selectCompare(comp,!isRace,select.mI)) - return false; - } - else - throw std::runtime_error ( - "unsupported variable type in dialogue info select"); - - return true; - - case 'B'://not Cell - if(select.mType==ESM::VT_Int) - { - int isCell = int(toLower(actor.getCell()->mCell->mName) == toLower(name)); - if(selectCompare(comp,!isCell,select.mI)) - return false; - } - else - throw std::runtime_error ( - "unsupported variable type in dialogue info select"); - return true; - case 'C'://not local if (select.mType==ESM::VT_Short || select.mType==ESM::VT_Int || select.mType==ESM::VT_Long) diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index eca7752e6e..9d14dbafcb 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -4,6 +4,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/journal.hpp" +#include "../mwbase/mechanicsmanager.hpp" #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" @@ -125,6 +126,9 @@ bool MWDialogue::Filter::testSelectStructs (const ESM::DialInfo& info) const bool MWDialogue::Filter::testSelectStruct (const SelectWrapper& select) const { + if (select.isNpcOnly() && mActor.getTypeName()!=typeid (ESM::NPC).name()) + return select.isInverted(); + switch (select.getType()) { case SelectWrapper::Type_None: return true; @@ -169,6 +173,10 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con return sum; } + + case SelectWrapper::Function_Dead: + + return MWBase::Environment::get().getMechanicsManager()->countDeaths (select.getName()); default: @@ -180,6 +188,26 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co { switch (select.getFunction()) { + case SelectWrapper::Function_Id: + + return select.getName()==toLower (MWWorld::Class::get (mActor).getId (mActor)); + + case SelectWrapper::Function_Faction: + + return toLower (mActor.get()->mBase->mFaction)==select.getName(); + + case SelectWrapper::Function_Class: + + return toLower (mActor.get()->mBase->mClass)==select.getName(); + + case SelectWrapper::Function_Race: + + return toLower (mActor.get()->mBase->mRace)==select.getName(); + + case SelectWrapper::Function_Cell: + + return toLower (mActor.getCell()->mCell->mName)==select.getName(); + default: throw std::runtime_error ("unknown boolean select function"); diff --git a/apps/openmw/mwdialogue/selectwrapper.cpp b/apps/openmw/mwdialogue/selectwrapper.cpp index 8cd739d6a2..90aa77f944 100644 --- a/apps/openmw/mwdialogue/selectwrapper.cpp +++ b/apps/openmw/mwdialogue/selectwrapper.cpp @@ -62,6 +62,12 @@ MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() con { case '4': return Function_Journal; case '5': return Function_Item; + case '6': return Function_Dead; + case '7': return Function_Id; + case '8': return Function_Faction; + case '9': return Function_Class; + case 'A': return Function_Race; + case 'B': return Function_Cell; } return Function_None; @@ -71,7 +77,7 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const { static const Function integerFunctions[] = { - Function_Journal, Function_Item, + Function_Journal, Function_Item, Function_Dead, Function_None // end marker }; @@ -82,14 +88,12 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const static const Function booleanFunctions[] = { + Function_Id, Function_Faction, Function_Class, Function_Race, Function_Cell, Function_None // end marker }; Function function = getFunction(); - - if (function==Function_None) - return Type_None; - + for (int i=0; integerFunctions[i]!=Function_None; ++i) if (integerFunctions[i]==function) return Type_Integer; @@ -102,29 +106,46 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const if (booleanFunctions[i]==function) return Type_Boolean; - throw std::runtime_error ("failed to determine type of select function"); + return Type_None; } -bool MWDialogue::SelectWrapper::IsInverted() const +bool MWDialogue::SelectWrapper::isInverted() const { char type = mSelect.mSelectRule[1]; return type=='7' || type=='8' || type=='9' || type=='A' || type=='B' || type=='C'; } +bool MWDialogue::SelectWrapper::isNpcOnly() const +{ + static const Function functions[] = + { + Function_Faction, SelectWrapper::Function_Class, SelectWrapper::Function_Race, + Function_None // end marker + }; + + Function function = getFunction(); + + for (int i=0; functions[i]!=Function_None; ++i) + if (functions[i]==function) + return true; + + return false; +} + bool MWDialogue::SelectWrapper::selectCompare (int value) const { - return selectCompareImp (mSelect, value)!=IsInverted(); // logic XOR + return selectCompareImp (mSelect, value)!=isInverted(); // logic XOR } bool MWDialogue::SelectWrapper::selectCompare (float value) const { - return selectCompareImp (mSelect, value)!=IsInverted(); // logic XOR + return selectCompareImp (mSelect, value)!=isInverted(); // logic XOR } bool MWDialogue::SelectWrapper::selectCompare (bool value) const { - return selectCompareImp (mSelect, static_cast (value))!=IsInverted(); // logic XOR + return selectCompareImp (mSelect, static_cast (value))!=isInverted(); // logic XOR } std::string MWDialogue::SelectWrapper::getName() const diff --git a/apps/openmw/mwdialogue/selectwrapper.hpp b/apps/openmw/mwdialogue/selectwrapper.hpp index 1ba39128e6..10a20ef746 100644 --- a/apps/openmw/mwdialogue/selectwrapper.hpp +++ b/apps/openmw/mwdialogue/selectwrapper.hpp @@ -15,7 +15,13 @@ namespace MWDialogue { Function_None, Function_Journal, - Function_Item + Function_Item, + Function_Dead, + Function_Id, + Function_Faction, + Function_Class, + Function_Race, + Function_Cell }; enum Type @@ -34,7 +40,10 @@ namespace MWDialogue Type getType() const; - bool IsInverted() const; + bool isInverted() const; + + bool isNpcOnly() const; + ///< \attention Do not call any of the select functions for this select struct! bool selectCompare (int value) const;