1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 11:53:52 +00:00

Issue #219: added basic select struct analysis and type checking

This commit is contained in:
Marc Zinnschlag 2012-11-08 16:49:38 +01:00
parent 662054acf4
commit 4614d2bc8e
6 changed files with 159 additions and 7 deletions

View file

@ -34,7 +34,7 @@ add_openmw_dir (mwgui
) )
add_openmw_dir (mwdialogue add_openmw_dir (mwdialogue
dialoguemanagerimp journalimp journalentry quest topic filter dialoguemanagerimp journalimp journalentry quest topic filter selectwrapper
) )
add_openmw_dir (mwscript add_openmw_dir (mwscript

View file

@ -469,11 +469,6 @@ namespace MWDialogue
throw std::runtime_error ( throw std::runtime_error (
"unsupported variable type in dialogue info select"); "unsupported variable type in dialogue info select");
return true; return true;
default:
std::cout << "unchecked select: " << type << " " << comp << " " << name << std::endl;
} }
} }

View file

@ -9,6 +9,8 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "selectwrapper.hpp"
namespace namespace
{ {
std::string toLower (const std::string& name) std::string toLower (const std::string& name)
@ -109,9 +111,51 @@ bool MWDialogue::Filter::testPlayer (const ESM::DialInfo& info) const
return true; return true;
} }
bool MWDialogue::Filter::testSelectStructs (const ESM::DialInfo& info) const
{
for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.mSelects.begin());
iter != info.mSelects.end(); ++iter)
if (!testSelectStruct (*iter))
return false;
return true;
}
bool MWDialogue::Filter::testSelectStruct (const SelectWrapper& select) const
{
switch (select.getType())
{
case SelectWrapper::Type_None: return true;
case SelectWrapper::Type_Integer: return select.selectCompare (getSelectStructInteger (select));
case SelectWrapper::Type_Numeric: return testSelectStructNumeric (select);
}
return true;
}
bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) const
{
switch (select.getFunction())
{
default:
throw std::runtime_error ("unknown numeric select function");
}
}
int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) const
{
switch (select.getFunction())
{
default:
throw std::runtime_error ("unknown integer select function");
}
}
MWDialogue::Filter::Filter (const MWWorld::Ptr& actor) : mActor (actor) {} MWDialogue::Filter::Filter (const MWWorld::Ptr& actor) : mActor (actor) {}
bool MWDialogue::Filter::operator() (const ESM::DialInfo& info) const bool MWDialogue::Filter::operator() (const ESM::DialInfo& info) const
{ {
return testActor (info) && testPlayer (info); return testActor (info) && testPlayer (info) && testSelectStructs (info);
} }

View file

@ -10,6 +10,8 @@ namespace ESM
namespace MWDialogue namespace MWDialogue
{ {
class SelectWrapper;
class Filter class Filter
{ {
MWWorld::Ptr mActor; MWWorld::Ptr mActor;
@ -20,6 +22,15 @@ namespace MWDialogue
bool testPlayer (const ESM::DialInfo& info) const; bool testPlayer (const ESM::DialInfo& info) const;
///< Do the player and the cell the player is currently in match \a info? ///< Do the player and the cell the player is currently in match \a info?
bool testSelectStructs (const ESM::DialInfo& info) const;
///< Are all select structs matching?
bool testSelectStruct (const SelectWrapper& select) const;
bool testSelectStructNumeric (const SelectWrapper& select) const;
int getSelectStructInteger (const SelectWrapper& select) const;
public: public:
Filter (const MWWorld::Ptr& actor); Filter (const MWWorld::Ptr& actor);

View file

@ -0,0 +1,62 @@
#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);
}

View file

@ -0,0 +1,40 @@
#ifndef GAME_MWDIALOGUE_SELECTWRAPPER_H
#define GAME_MWDIALOGUE_SELECTWRAPPER_H
#include <components/esm/loadinfo.hpp>
namespace MWDialogue
{
class SelectWrapper
{
const ESM::DialInfo::SelectStruct& mSelect;
public:
enum Function
{
Function_None
};
enum Type
{
Type_None,
Type_Integer,
Type_Numeric
};
public:
SelectWrapper (const ESM::DialInfo::SelectStruct& select);
Function getFunction() const;
Type getType() const;
bool selectCompare (int value) const;
bool selectCompare (float value) const;
};
}
#endif