forked from mirror/openmw-tes3mp
Issue #219: moved first batch of integer type functions from DialogueManager to Filter
This commit is contained in:
parent
e912b5bed2
commit
91afef140b
4 changed files with 88 additions and 28 deletions
|
@ -345,32 +345,6 @@ namespace MWDialogue
|
|||
|
||||
return true;
|
||||
|
||||
case '4'://journal
|
||||
if(select.mType==ESM::VT_Int)
|
||||
{
|
||||
if(!selectCompare<int,int>(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<int,int>(comp,sum,select.mI)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case '6': // dead
|
||||
|
||||
return selectCompare<int,int> (comp,
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
|
||||
#include "selectwrapper.hpp"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
||||
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<typename T1, typename T2>
|
||||
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<int> (value))!=IsInverted(); // logic XOR
|
||||
}
|
||||
|
||||
std::string MWDialogue::SelectWrapper::getName() const
|
||||
{
|
||||
return toLower (mSelect.mSelectRule.substr (5));
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue