forked from teamnwah/openmw-tes3coop
added test for select type '3' (Local)
This commit is contained in:
parent
a25c7bb2c0
commit
8f4359db08
2 changed files with 108 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
|||
|
||||
#include "dialoguemanager.hpp"
|
||||
|
||||
#include <components/esm/loadinfo.hpp>
|
||||
#include <components/esm/loaddial.hpp>
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
@ -9,11 +8,110 @@
|
|||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/environment.hpp"
|
||||
#include "../mwworld/world.hpp"
|
||||
#include "../mwworld/refdata.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T1, typename T2>
|
||||
bool selectCompare (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 checkLocal (char comp, const std::string& name, T value, const MWWorld::Ptr& actor,
|
||||
const ESMS::ESMStore& store)
|
||||
{
|
||||
std::string scriptName = MWWorld::Class::get (actor).getScript (actor);
|
||||
|
||||
if (scriptName.empty())
|
||||
return false; // no script
|
||||
|
||||
const ESM::Script *script = store.scripts.find (scriptName);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (; i<static_cast<int> (script->varNames.size()); ++i)
|
||||
if (script->varNames[i]==name)
|
||||
break;
|
||||
|
||||
if (i>=static_cast<int> (script->varNames.size()))
|
||||
return false; // script does not have a variable of this name
|
||||
|
||||
const MWScript::Locals& locals = actor.getRefData().getLocals();
|
||||
|
||||
if (i<script->data.numShorts)
|
||||
return selectCompare (comp, locals.mShorts[i], value);
|
||||
else
|
||||
i -= script->data.numShorts;
|
||||
|
||||
if (i<script->data.numLongs)
|
||||
return selectCompare (comp, locals.mLongs[i], value);
|
||||
else
|
||||
i -= script->data.numShorts;
|
||||
|
||||
return selectCompare (comp, locals.mFloats.at (i), value);
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWDialogue
|
||||
{
|
||||
bool DialogueManager::isMatching (const MWWorld::Ptr& actor,
|
||||
const ESM::DialInfo::SelectStruct& select) const
|
||||
{
|
||||
char type = select.selectRule[1];
|
||||
|
||||
if (type!='0')
|
||||
{
|
||||
char comp = select.selectRule[4];
|
||||
std::string name = select.selectRule.substr (5);
|
||||
|
||||
// TODO types 1, 2, 4, 5, 6, 7, 8, 9, A, B, C
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case '3': // local
|
||||
|
||||
if (select.type==ESM::VT_Short || select.type==ESM::VT_Int ||
|
||||
select.type==ESM::VT_Long)
|
||||
{
|
||||
if (!checkLocal (comp, name, select.i, actor,
|
||||
mEnvironment.mWorld->getStore()))
|
||||
return false;
|
||||
}
|
||||
else if (select.type==ESM::VT_Float)
|
||||
{
|
||||
if (!checkLocal (comp, name, select.f, actor,
|
||||
mEnvironment.mWorld->getStore()))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error (
|
||||
"unsupported variable type in dialogue info select");
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
||||
std::cout << "unchecked select: " << type << " " << comp << " " << name << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DialogueManager::isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const
|
||||
{
|
||||
// TODO check actor id
|
||||
|
@ -28,7 +126,11 @@ namespace MWDialogue
|
|||
return false;
|
||||
|
||||
// TODO check DATAstruct
|
||||
// TODO check select structures
|
||||
|
||||
for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.selects.begin());
|
||||
iter != info.selects.end(); ++iter)
|
||||
if (!isMatching (actor, *iter))
|
||||
return false;
|
||||
|
||||
std::cout
|
||||
<< "unchecked entries:" << std::endl
|
||||
|
@ -39,10 +141,6 @@ namespace MWDialogue
|
|||
<< " player faction: " << info.pcFaction << std::endl
|
||||
<< " DATAstruct" << std::endl;
|
||||
|
||||
for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.selects.begin());
|
||||
iter != info.selects.end(); ++iter)
|
||||
std::cout << " select: " << iter->selectRule << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
#ifndef GAME_MMDIALOG_DIALOGUEMANAGER_H
|
||||
#define GAME_MWDIALOG_DIALOGUEMANAGER_H
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include <components/esm/loadinfo.hpp>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
struct DialInfo;
|
||||
}
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
@ -19,6 +16,8 @@ namespace MWDialogue
|
|||
{
|
||||
MWWorld::Environment& mEnvironment;
|
||||
|
||||
bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo::SelectStruct& select) const;
|
||||
|
||||
bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue