diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 37de30c961..3f7f954f6d 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -345,32 +345,6 @@ namespace MWDialogue return true; - case '4'://journal - if(select.mType==ESM::VT_Int) - { - if(!selectCompare(comp,MWBase::Environment::get().getJournal()->getJournalIndex(toLower(name)),select.mI)) return false; - } - else - throw std::runtime_error ( - "unsupported variable type in dialogue info select"); - - return true; - - case '5'://item - { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - MWWorld::ContainerStore& store = MWWorld::Class::get (player).getContainerStore (player); - - int sum = 0; - - for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) - if (toLower(iter->getCellRef().mRefID) == toLower(name)) - sum += iter->getRefData().getCount(); - if(!selectCompare(comp,sum,select.mI)) return false; - } - - return true; - case '6': // dead return selectCompare (comp, diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index bded2aaec6..eca7752e6e 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -3,9 +3,11 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include "../mwbase/journal.hpp" #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" +#include "../mwworld/containerstore.hpp" #include "../mwmechanics/npcstats.hpp" @@ -148,6 +150,26 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con { switch (select.getFunction()) { + case SelectWrapper::Function_Journal: + + return MWBase::Environment::get().getJournal()->getJournalIndex (select.getName()); + + case SelectWrapper::Function_Item: + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWWorld::ContainerStore& store = MWWorld::Class::get (player).getContainerStore (player); + + int sum = 0; + + std::string name = select.getName(); + + for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) + if (toLower(iter->getCellRef().mRefID) == name) + sum += iter->getRefData().getCount(); + + return sum; + } + default: throw std::runtime_error ("unknown integer select function"); diff --git a/apps/openmw/mwdialogue/selectwrapper.cpp b/apps/openmw/mwdialogue/selectwrapper.cpp index 5efb93ed5f..8cd739d6a2 100644 --- a/apps/openmw/mwdialogue/selectwrapper.cpp +++ b/apps/openmw/mwdialogue/selectwrapper.cpp @@ -1,10 +1,23 @@ #include "selectwrapper.hpp" +#include + #include +#include namespace { + std::string toLower (const std::string& name) + { + std::string lowerCase; + + std::transform (name.begin(), name.end(), std::back_inserter (lowerCase), + (int(*)(int)) std::tolower); + + return lowerCase; + } + template bool selectCompareImp (char comp, T1 value1, T2 value2) { @@ -43,12 +56,53 @@ MWDialogue::SelectWrapper::SelectWrapper (const ESM::DialInfo::SelectStruct& sel MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() const { + char type = mSelect.mSelectRule[1]; + + switch (type) + { + case '4': return Function_Journal; + case '5': return Function_Item; + } + return Function_None; } MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const { - return Type_None; + static const Function integerFunctions[] = + { + Function_Journal, Function_Item, + Function_None // end marker + }; + + static const Function numericFunctions[] = + { + Function_None // end marker + }; + + static const Function booleanFunctions[] = + { + 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; + + for (int i=0; numericFunctions[i]!=Function_None; ++i) + if (numericFunctions[i]==function) + return Type_Numeric; + + for (int i=0; booleanFunctions[i]!=Function_None; ++i) + if (booleanFunctions[i]==function) + return Type_Boolean; + + throw std::runtime_error ("failed to determine type of select function"); } bool MWDialogue::SelectWrapper::IsInverted() const @@ -72,3 +126,8 @@ bool MWDialogue::SelectWrapper::selectCompare (bool value) const { return selectCompareImp (mSelect, static_cast (value))!=IsInverted(); // logic XOR } + +std::string MWDialogue::SelectWrapper::getName() const +{ + return toLower (mSelect.mSelectRule.substr (5)); +} diff --git a/apps/openmw/mwdialogue/selectwrapper.hpp b/apps/openmw/mwdialogue/selectwrapper.hpp index f1ac252097..1ba39128e6 100644 --- a/apps/openmw/mwdialogue/selectwrapper.hpp +++ b/apps/openmw/mwdialogue/selectwrapper.hpp @@ -13,7 +13,9 @@ namespace MWDialogue enum Function { - Function_None + Function_None, + Function_Journal, + Function_Item }; enum Type @@ -39,6 +41,9 @@ namespace MWDialogue bool selectCompare (float value) const; bool selectCompare (bool value) const; + + std::string getName() const; + ///< Return case-smashed name. }; }