You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw/mwdialogue/selectwrapper.cpp

63 lines
1.7 KiB
C++

#include "selectwrapper.hpp"
#include <stdexcept>
namespace
{
template<typename T1, typename T2>
bool selectCompareImp (char comp, T1 value1, T2 value2)
{
switch (comp)
{
case '0': return value1==value2;
case '1': return value1!=value2;
case '2': return value1>value2;
case '3': return value1>=value2;
case '4': return value1<value2;
case '5': return value1<=value2;
}
throw std::runtime_error ("unknown compare type in dialogue info select");
}
template<typename T>
bool selectCompareImp (const ESM::DialInfo::SelectStruct& select, T value1)
{
if (select.mType==ESM::VT_Short || select.mType==ESM::VT_Int ||
select.mType==ESM::VT_Long)
{
return selectCompareImp (select.mSelectRule[4], value1, select.mI);
}
else if (select.mType==ESM::VT_Float)
{
return selectCompareImp (select.mSelectRule[4], value1, select.mF);
}
else
throw std::runtime_error (
"unsupported variable type in dialogue info select");
}
}
MWDialogue::SelectWrapper::SelectWrapper (const ESM::DialInfo::SelectStruct& select) : mSelect (select) {}
MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() const
{
return Function_None;
}
MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
{
return Type_None;
}
bool MWDialogue::SelectWrapper::selectCompare (int value) const
{
return selectCompareImp (mSelect, value);
}
bool MWDialogue::SelectWrapper::selectCompare (float value) const
{
return selectCompareImp (mSelect, value);
}