|
|
|
@ -6,39 +6,39 @@
|
|
|
|
|
#include <iterator>
|
|
|
|
|
|
|
|
|
|
#include <components/esm/loaddial.hpp>
|
|
|
|
|
#include <components/esm/loadinfo.hpp>
|
|
|
|
|
|
|
|
|
|
#include <components/compiler/exception.hpp>
|
|
|
|
|
#include <components/compiler/errorhandler.hpp>
|
|
|
|
|
#include <components/compiler/scanner.hpp>
|
|
|
|
|
#include <components/compiler/locals.hpp>
|
|
|
|
|
#include <components/compiler/output.hpp>
|
|
|
|
|
#include <components/compiler/scriptparser.hpp>
|
|
|
|
|
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
#include "../mwbase/scriptmanager.hpp"
|
|
|
|
|
#include "../mwbase/journal.hpp"
|
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
#include "../mwworld/refdata.hpp"
|
|
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwgui/dialogue.hpp"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include <components/compiler/exception.hpp>
|
|
|
|
|
#include <components/compiler/errorhandler.hpp>
|
|
|
|
|
#include <components/compiler/scanner.hpp>
|
|
|
|
|
#include <components/compiler/locals.hpp>
|
|
|
|
|
#include <components/compiler/output.hpp>
|
|
|
|
|
#include <components/compiler/scriptparser.hpp>
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
|
|
|
|
|
|
#include "../mwscript/compilercontext.hpp"
|
|
|
|
|
#include "../mwscript/interpretercontext.hpp"
|
|
|
|
|
#include "../mwscript/extensions.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwclass/npc.hpp"
|
|
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
|
|
|
|
|
#include "filter.hpp"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
std::string toLower (const std::string& name)
|
|
|
|
@ -66,87 +66,6 @@ namespace
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 MWWorld::ESMStore& store)
|
|
|
|
|
{
|
|
|
|
|
std::string scriptName = MWWorld::Class::get (actor).getScript (actor);
|
|
|
|
|
|
|
|
|
|
if (scriptName.empty())
|
|
|
|
|
return false; // no script
|
|
|
|
|
|
|
|
|
|
const ESM::Script *script =
|
|
|
|
|
store.get<ESM::Script>().find (scriptName);
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
for (; i<static_cast<int> (script->mVarNames.size()); ++i)
|
|
|
|
|
if (script->mVarNames[i]==name)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (i>=static_cast<int> (script->mVarNames.size()))
|
|
|
|
|
return false; // script does not have a variable of this name
|
|
|
|
|
|
|
|
|
|
const MWScript::Locals& locals = actor.getRefData().getLocals();
|
|
|
|
|
|
|
|
|
|
if (i<script->mData.mNumShorts)
|
|
|
|
|
return selectCompare (comp, locals.mShorts[i], value);
|
|
|
|
|
else
|
|
|
|
|
i -= script->mData.mNumShorts;
|
|
|
|
|
|
|
|
|
|
if (i<script->mData.mNumLongs)
|
|
|
|
|
return selectCompare (comp, locals.mLongs[i], value);
|
|
|
|
|
else
|
|
|
|
|
i -= script->mData.mNumShorts;
|
|
|
|
|
|
|
|
|
|
return selectCompare (comp, locals.mFloats.at (i), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
bool checkGlobal (char comp, const std::string& name, T value)
|
|
|
|
|
{
|
|
|
|
|
switch (MWBase::Environment::get().getWorld()->getGlobalVariableType (name))
|
|
|
|
|
{
|
|
|
|
|
case 's':
|
|
|
|
|
return selectCompare (comp, MWBase::Environment::get().getWorld()->getGlobalVariable (name).mShort, value);
|
|
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
|
|
|
|
|
|
return selectCompare (comp, MWBase::Environment::get().getWorld()->getGlobalVariable (name).mLong, value);
|
|
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
|
|
|
|
|
|
return selectCompare (comp, MWBase::Environment::get().getWorld()->getGlobalVariable (name).mFloat, value);
|
|
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->getGlobalVariable (name); // trigger exception
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
throw std::runtime_error ("unsupported gobal variable type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//helper function
|
|
|
|
|
std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos)
|
|
|
|
|
{
|
|
|
|
@ -156,432 +75,6 @@ namespace
|
|
|
|
|
|
|
|
|
|
namespace MWDialogue
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool DialogueManager::functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info,bool choice)
|
|
|
|
|
{
|
|
|
|
|
bool isCreature = (actor.getTypeName() != typeid(ESM::NPC).name());
|
|
|
|
|
|
|
|
|
|
for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.mSelects.begin());
|
|
|
|
|
iter != info.mSelects.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
ESM::DialInfo::SelectStruct select = *iter;
|
|
|
|
|
char type = select.mSelectRule[1];
|
|
|
|
|
if(type == '1')
|
|
|
|
|
{
|
|
|
|
|
char comp = select.mSelectRule[4];
|
|
|
|
|
std::string name = select.mSelectRule.substr (5);
|
|
|
|
|
std::string function = select.mSelectRule.substr(2,2);
|
|
|
|
|
|
|
|
|
|
int ifunction;
|
|
|
|
|
std::istringstream iss(function);
|
|
|
|
|
iss >> ifunction;
|
|
|
|
|
switch(ifunction)
|
|
|
|
|
{
|
|
|
|
|
case 39://PC Expelled
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 40://PC Common Disease
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 41://PC Blight Disease
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 43://PC Crime level
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 46://Same faction
|
|
|
|
|
{
|
|
|
|
|
if (isCreature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
MWMechanics::NpcStats PCstats = MWWorld::Class::get(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()).getNpcStats(MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
|
|
|
|
|
MWMechanics::NpcStats NPCstats = MWWorld::Class::get(actor).getNpcStats(actor);
|
|
|
|
|
int sameFaction = 0;
|
|
|
|
|
if(!NPCstats.getFactionRanks().empty())
|
|
|
|
|
{
|
|
|
|
|
std::string NPCFaction = NPCstats.getFactionRanks().begin()->first;
|
|
|
|
|
if(PCstats.getFactionRanks().find(toLower(NPCFaction)) != PCstats.getFactionRanks().end()) sameFaction = 1;
|
|
|
|
|
}
|
|
|
|
|
if(!selectCompare<int,int>(comp,sameFaction,select.mI)) return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 48://Detected
|
|
|
|
|
if(!selectCompare<int,int>(comp,1,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 49://Alarmed
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 50://choice
|
|
|
|
|
if(choice)
|
|
|
|
|
{
|
|
|
|
|
if(!selectCompare<int,int>(comp,mChoice,select.mI)) return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 60://PC Vampire
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 61://Level
|
|
|
|
|
if(!selectCompare<int,int>(comp,1,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 62://Attacked
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 63://Talked to PC
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 64://PC Health
|
|
|
|
|
if(!selectCompare<int,int>(comp,50,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 65://Creature target
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 66://Friend hit
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 67://Fight
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 68://Hello????
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 69://Alarm
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 70://Flee
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 71://Should Attack
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DialogueManager::isMatching (const MWWorld::Ptr& actor,
|
|
|
|
|
const ESM::DialInfo::SelectStruct& select) const
|
|
|
|
|
{
|
|
|
|
|
bool isCreature = (actor.getTypeName() != typeid(ESM::NPC).name());
|
|
|
|
|
|
|
|
|
|
char type = select.mSelectRule[1];
|
|
|
|
|
|
|
|
|
|
if (type!='0')
|
|
|
|
|
{
|
|
|
|
|
char comp = select.mSelectRule[4];
|
|
|
|
|
std::string name = select.mSelectRule.substr (5);
|
|
|
|
|
std::string function = select.mSelectRule.substr(1,2);
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case '1': // function
|
|
|
|
|
|
|
|
|
|
return true; // Done elsewhere.
|
|
|
|
|
|
|
|
|
|
case '2': // global
|
|
|
|
|
|
|
|
|
|
if (select.mType==ESM::VT_Short || select.mType==ESM::VT_Int ||
|
|
|
|
|
select.mType==ESM::VT_Long)
|
|
|
|
|
{
|
|
|
|
|
if (!checkGlobal (comp, toLower (name), select.mI))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (select.mType==ESM::VT_Float)
|
|
|
|
|
{
|
|
|
|
|
if (!checkGlobal (comp, toLower (name), select.mF))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw std::runtime_error (
|
|
|
|
|
"unsupported variable type in dialogue info select");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case '3': // local
|
|
|
|
|
|
|
|
|
|
if (select.mType==ESM::VT_Short || select.mType==ESM::VT_Int ||
|
|
|
|
|
select.mType==ESM::VT_Long)
|
|
|
|
|
{
|
|
|
|
|
if (!checkLocal (comp, toLower (name), select.mI, actor,
|
|
|
|
|
MWBase::Environment::get().getWorld()->getStore()))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (select.mType==ESM::VT_Float)
|
|
|
|
|
{
|
|
|
|
|
if (!checkLocal (comp, toLower (name), select.mF, actor,
|
|
|
|
|
MWBase::Environment::get().getWorld()->getStore()))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw std::runtime_error (
|
|
|
|
|
"unsupported variable type in dialogue info select");
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
if(!selectCompare<int,int>(comp,0,select.mI)) return false;
|
|
|
|
|
|
|
|
|
|
case '7':// not ID
|
|
|
|
|
if(select.mType==ESM::VT_String ||select.mType==ESM::VT_Int)//bug in morrowind here? it's not a short, it's a string
|
|
|
|
|
{
|
|
|
|
|
int isID = int(toLower(name)==toLower(MWWorld::Class::get (actor).getId (actor)));
|
|
|
|
|
if (selectCompare<int,int>(comp,!isID,select.mI)) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw std::runtime_error (
|
|
|
|
|
"unsupported variable type in dialogue info select");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case '8':// not faction
|
|
|
|
|
if (isCreature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(select.mType==ESM::VT_Int)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC>* npc = actor.get<ESM::NPC>();
|
|
|
|
|
int isFaction = int(toLower(npc->mBase->mFaction) == toLower(name));
|
|
|
|
|
if(selectCompare<int,int>(comp,!isFaction,select.mI))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw std::runtime_error (
|
|
|
|
|
"unsupported variable type in dialogue info select");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case '9':// not class
|
|
|
|
|
if (isCreature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(select.mType==ESM::VT_Int)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC>* npc = actor.get<ESM::NPC>();
|
|
|
|
|
int isClass = int(toLower(npc->mBase->mClass) == toLower(name));
|
|
|
|
|
if(selectCompare<int,int>(comp,!isClass,select.mI))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw std::runtime_error (
|
|
|
|
|
"unsupported variable type in dialogue info select");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case 'A'://not Race
|
|
|
|
|
if (isCreature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(select.mType==ESM::VT_Int)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC>* npc = actor.get<ESM::NPC>();
|
|
|
|
|
int isRace = int(toLower(npc->mBase->mRace) == toLower(name));
|
|
|
|
|
if(selectCompare<int,int>(comp,!isRace,select.mI))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw std::runtime_error (
|
|
|
|
|
"unsupported variable type in dialogue info select");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case 'B'://not Cell
|
|
|
|
|
if(select.mType==ESM::VT_Int)
|
|
|
|
|
{
|
|
|
|
|
int isCell = int(toLower(actor.getCell()->mCell->mName) == toLower(name));
|
|
|
|
|
if(selectCompare<int,int>(comp,!isCell,select.mI))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
throw std::runtime_error (
|
|
|
|
|
"unsupported variable type in dialogue info select");
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case 'C'://not local
|
|
|
|
|
if (select.mType==ESM::VT_Short || select.mType==ESM::VT_Int ||
|
|
|
|
|
select.mType==ESM::VT_Long)
|
|
|
|
|
{
|
|
|
|
|
if (checkLocal (comp, toLower (name), select.mI, actor,
|
|
|
|
|
MWBase::Environment::get().getWorld()->getStore()))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (select.mType==ESM::VT_Float)
|
|
|
|
|
{
|
|
|
|
|
if (checkLocal (comp, toLower (name), select.mF, actor,
|
|
|
|
|
MWBase::Environment::get().getWorld()->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
|
|
|
|
|
{
|
|
|
|
|
bool isCreature = (actor.getTypeName() != typeid(ESM::NPC).name());
|
|
|
|
|
|
|
|
|
|
// actor id
|
|
|
|
|
if (!info.mActor.empty())
|
|
|
|
|
if (toLower (info.mActor)!=MWWorld::Class::get (actor).getId (actor))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//NPC race
|
|
|
|
|
if (!info.mRace.empty())
|
|
|
|
|
{
|
|
|
|
|
if (isCreature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *cellRef = actor.get<ESM::NPC>();
|
|
|
|
|
|
|
|
|
|
if (!cellRef)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (toLower (info.mRace)!=toLower (cellRef->mBase->mRace))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//NPC class
|
|
|
|
|
if (!info.mClass.empty())
|
|
|
|
|
{
|
|
|
|
|
if (isCreature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *cellRef = actor.get<ESM::NPC>();
|
|
|
|
|
|
|
|
|
|
if (!cellRef)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (toLower (info.mClass)!=toLower (cellRef->mBase->mClass))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//NPC faction
|
|
|
|
|
if (!info.mNpcFaction.empty())
|
|
|
|
|
{
|
|
|
|
|
if (isCreature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//MWWorld::Class npcClass = MWWorld::Class::get(actor);
|
|
|
|
|
MWMechanics::NpcStats stats = MWWorld::Class::get(actor).getNpcStats(actor);
|
|
|
|
|
std::map<std::string,int>::iterator it = stats.getFactionRanks().find(toLower(info.mNpcFaction));
|
|
|
|
|
if(it!=stats.getFactionRanks().end())
|
|
|
|
|
{
|
|
|
|
|
//check rank
|
|
|
|
|
if(it->second < (int)info.mData.mRank) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//not in the faction
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO check player faction
|
|
|
|
|
if(!info.mPcFaction.empty())
|
|
|
|
|
{
|
|
|
|
|
MWMechanics::NpcStats stats = MWWorld::Class::get(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()).getNpcStats(MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
|
|
|
|
|
std::map<std::string,int>::iterator it = stats.getFactionRanks().find(toLower(info.mPcFaction));
|
|
|
|
|
if(it!=stats.getFactionRanks().end())
|
|
|
|
|
{
|
|
|
|
|
//check rank
|
|
|
|
|
if(it->second < (int)info.mData.mPCrank) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//not in the faction
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check gender
|
|
|
|
|
if (!isCreature)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC>* npc = actor.get<ESM::NPC>();
|
|
|
|
|
if(npc->mBase->mFlags & npc->mBase->Female)
|
|
|
|
|
{
|
|
|
|
|
if(static_cast<int> (info.mData.mGender)==0) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(static_cast<int> (info.mData.mGender)==1) return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check cell
|
|
|
|
|
if (!info.mCell.empty())
|
|
|
|
|
if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mName != info.mCell)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// TODO check DATAstruct
|
|
|
|
|
for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.mSelects.begin());
|
|
|
|
|
iter != info.mSelects.end(); ++iter)
|
|
|
|
|
if (!isMatching (actor, *iter))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DialogueManager::DialogueManager (const Compiler::Extensions& extensions) :
|
|
|
|
|
mCompilerContext (MWScript::CompilerContext::Type_Dialgoue),
|
|
|
|
|
mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream)
|
|
|
|
@ -609,7 +102,7 @@ namespace MWDialogue
|
|
|
|
|
mKnownTopics[toLower(topic)] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DialogueManager::parseText (std::string text)
|
|
|
|
|
void DialogueManager::parseText (const std::string& text)
|
|
|
|
|
{
|
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
for(it = mActorKnownTopics.begin();it != mActorKnownTopics.end();++it)
|
|
|
|
@ -636,6 +129,10 @@ namespace MWDialogue
|
|
|
|
|
mIsInChoice = false;
|
|
|
|
|
|
|
|
|
|
mActor = actor;
|
|
|
|
|
|
|
|
|
|
MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (actor).getCreatureStats (actor);
|
|
|
|
|
mTalkedTo = creatureStats.hasTalkedToPlayer();
|
|
|
|
|
creatureStats.talkedToPlayer();
|
|
|
|
|
|
|
|
|
|
mActorKnownTopics.clear();
|
|
|
|
|
|
|
|
|
@ -648,35 +145,28 @@ namespace MWDialogue
|
|
|
|
|
updateTopics();
|
|
|
|
|
|
|
|
|
|
//greeting
|
|
|
|
|
bool greetingFound = false;
|
|
|
|
|
const MWWorld::Store<ESM::Dialogue> &dialogs =
|
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
|
|
|
|
|
|
|
|
|
|
MWWorld::Store<ESM::Dialogue>::iterator it = dialogs.begin();
|
|
|
|
|
for (; it != dialogs.end(); ++it)
|
|
|
|
|
Filter filter (actor, mChoice, mTalkedTo);
|
|
|
|
|
|
|
|
|
|
for (MWWorld::Store<ESM::Dialogue>::iterator it = dialogs.begin(); it != dialogs.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if(it->mType == ESM::Dialogue::Greeting)
|
|
|
|
|
{
|
|
|
|
|
if (greetingFound) break;
|
|
|
|
|
for (std::vector<ESM::DialInfo>::const_iterator iter (it->mInfo.begin());
|
|
|
|
|
iter!=it->mInfo.end(); ++iter)
|
|
|
|
|
if (const ESM::DialInfo *info = filter.search (*it))
|
|
|
|
|
{
|
|
|
|
|
if (isMatching (actor, *iter) && functionFilter(mActor,*iter,true))
|
|
|
|
|
if (!info->mSound.empty())
|
|
|
|
|
{
|
|
|
|
|
if (!iter->mSound.empty())
|
|
|
|
|
{
|
|
|
|
|
// TODO play sound
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string text = iter->mResponse;
|
|
|
|
|
parseText(text);
|
|
|
|
|
win->addText(iter->mResponse);
|
|
|
|
|
executeScript(iter->mResultScript);
|
|
|
|
|
greetingFound = true;
|
|
|
|
|
mLastTopic = it->mId;
|
|
|
|
|
mLastDialogue = *iter;
|
|
|
|
|
break;
|
|
|
|
|
// TODO play sound
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseText (info->mResponse);
|
|
|
|
|
win->addText (info->mResponse);
|
|
|
|
|
executeScript (info->mResultScript);
|
|
|
|
|
mLastTopic = it->mId;
|
|
|
|
|
mLastDialogue = *info;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -724,7 +214,7 @@ namespace MWDialogue
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DialogueManager::executeScript(std::string script)
|
|
|
|
|
void DialogueManager::executeScript (const std::string& script)
|
|
|
|
|
{
|
|
|
|
|
std::vector<Interpreter::Type_Code> code;
|
|
|
|
|
if(compile(script,code))
|
|
|
|
@ -749,29 +239,24 @@ namespace MWDialogue
|
|
|
|
|
int choice = mChoice;
|
|
|
|
|
mChoice = -1;
|
|
|
|
|
mActorKnownTopics.clear();
|
|
|
|
|
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
|
|
|
|
|
|
|
|
|
|
const MWWorld::Store<ESM::Dialogue> &dialogs =
|
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
|
|
|
|
|
|
|
|
|
|
Filter filter (mActor, mChoice, mTalkedTo);
|
|
|
|
|
|
|
|
|
|
MWWorld::Store<ESM::Dialogue>::iterator it = dialogs.begin();
|
|
|
|
|
for (; it != dialogs.end(); ++it)
|
|
|
|
|
for (MWWorld::Store<ESM::Dialogue>::iterator iter = dialogs.begin(); iter != dialogs.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
if(it->mType == ESM::Dialogue::Topic)
|
|
|
|
|
if (iter->mType == ESM::Dialogue::Topic)
|
|
|
|
|
{
|
|
|
|
|
for (std::vector<ESM::DialInfo>::const_iterator iter (it->mInfo.begin());
|
|
|
|
|
iter!=it->mInfo.end(); ++iter)
|
|
|
|
|
if (filter.search (*iter))
|
|
|
|
|
{
|
|
|
|
|
if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,true))
|
|
|
|
|
mActorKnownTopics.push_back (toLower (iter->mId));
|
|
|
|
|
|
|
|
|
|
//does the player know the topic?
|
|
|
|
|
if (mKnownTopics.find (toLower (iter->mId)) != mKnownTopics.end())
|
|
|
|
|
{
|
|
|
|
|
mActorKnownTopics.push_back(toLower(it->mId));
|
|
|
|
|
//does the player know the topic?
|
|
|
|
|
if(mKnownTopics.find(toLower(it->mId)) != mKnownTopics.end())
|
|
|
|
|
{
|
|
|
|
|
keywordList.push_back(it->mId);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
keywordList.push_back (iter->mId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -822,6 +307,8 @@ namespace MWDialogue
|
|
|
|
|
if (services & ESM::NPC::Enchanting)
|
|
|
|
|
windowServices |= MWGui::DialogueWindow::Service_Enchant;
|
|
|
|
|
|
|
|
|
|
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
|
|
|
|
|
|
|
|
|
|
win->setServices (windowServices);
|
|
|
|
|
|
|
|
|
|
// sort again, because the previous sort was case-sensitive
|
|
|
|
@ -838,28 +325,25 @@ namespace MWDialogue
|
|
|
|
|
if(mDialogueMap.find(keyword) != mDialogueMap.end())
|
|
|
|
|
{
|
|
|
|
|
ESM::Dialogue ndialogue = mDialogueMap[keyword];
|
|
|
|
|
if(ndialogue.mType == ESM::Dialogue::Topic)
|
|
|
|
|
if (mDialogueMap[keyword].mType == ESM::Dialogue::Topic)
|
|
|
|
|
{
|
|
|
|
|
for (std::vector<ESM::DialInfo>::const_iterator iter = ndialogue.mInfo.begin();
|
|
|
|
|
iter!=ndialogue.mInfo.end(); ++iter)
|
|
|
|
|
Filter filter (mActor, mChoice, mTalkedTo);
|
|
|
|
|
|
|
|
|
|
if (const ESM::DialInfo *info = filter.search (mDialogueMap[keyword]))
|
|
|
|
|
{
|
|
|
|
|
if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,true))
|
|
|
|
|
{
|
|
|
|
|
std::string text = iter->mResponse;
|
|
|
|
|
std::string script = iter->mResultScript;
|
|
|
|
|
std::string text = info->mResponse;
|
|
|
|
|
std::string script = info->mResultScript;
|
|
|
|
|
|
|
|
|
|
parseText(text);
|
|
|
|
|
parseText (text);
|
|
|
|
|
|
|
|
|
|
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
|
|
|
|
|
win->addTitle(keyword);
|
|
|
|
|
win->addText(iter->mResponse);
|
|
|
|
|
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
|
|
|
|
|
win->addTitle (keyword);
|
|
|
|
|
win->addText (info->mResponse);
|
|
|
|
|
|
|
|
|
|
executeScript(script);
|
|
|
|
|
executeScript (script);
|
|
|
|
|
|
|
|
|
|
mLastTopic = keyword;
|
|
|
|
|
mLastDialogue = *iter;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
mLastTopic = keyword;
|
|
|
|
|
mLastDialogue = *info;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -875,7 +359,7 @@ namespace MWDialogue
|
|
|
|
|
// Apply disposition change to NPC's base disposition
|
|
|
|
|
if (mActor.getTypeName() == typeid(ESM::NPC).name())
|
|
|
|
|
{
|
|
|
|
|
MWMechanics::NpcStats npcStats = MWWorld::Class::get(mActor).getNpcStats(mActor);
|
|
|
|
|
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(mActor).getNpcStats(mActor);
|
|
|
|
|
npcStats.setBaseDisposition(npcStats.getBaseDisposition() + mPermanentDispositionChange);
|
|
|
|
|
}
|
|
|
|
|
mPermanentDispositionChange = 0;
|
|
|
|
@ -884,41 +368,36 @@ namespace MWDialogue
|
|
|
|
|
|
|
|
|
|
void DialogueManager::questionAnswered (const std::string& answer)
|
|
|
|
|
{
|
|
|
|
|
if(mChoiceMap.find(answer) != mChoiceMap.end())
|
|
|
|
|
if (mChoiceMap.find(answer) != mChoiceMap.end())
|
|
|
|
|
{
|
|
|
|
|
mChoice = mChoiceMap[answer];
|
|
|
|
|
|
|
|
|
|
std::vector<ESM::DialInfo>::const_iterator iter;
|
|
|
|
|
if(mDialogueMap.find(mLastTopic) != mDialogueMap.end())
|
|
|
|
|
if (mDialogueMap.find(mLastTopic) != mDialogueMap.end())
|
|
|
|
|
{
|
|
|
|
|
ESM::Dialogue ndialogue = mDialogueMap[mLastTopic];
|
|
|
|
|
if(ndialogue.mType == ESM::Dialogue::Topic)
|
|
|
|
|
if (mDialogueMap[mLastTopic].mType == ESM::Dialogue::Topic)
|
|
|
|
|
{
|
|
|
|
|
for (std::vector<ESM::DialInfo>::const_iterator iter = ndialogue.mInfo.begin();
|
|
|
|
|
iter!=ndialogue.mInfo.end(); ++iter)
|
|
|
|
|
Filter filter (mActor, mChoice, mTalkedTo);
|
|
|
|
|
|
|
|
|
|
if (const ESM::DialInfo *info = filter.search (mDialogueMap[mLastTopic]))
|
|
|
|
|
{
|
|
|
|
|
if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,true))
|
|
|
|
|
{
|
|
|
|
|
mChoiceMap.clear();
|
|
|
|
|
mChoice = -1;
|
|
|
|
|
mIsInChoice = false;
|
|
|
|
|
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
|
|
|
|
|
std::string text = iter->mResponse;
|
|
|
|
|
parseText(text);
|
|
|
|
|
win->addText(text);
|
|
|
|
|
executeScript(iter->mResultScript);
|
|
|
|
|
mLastTopic = mLastTopic;
|
|
|
|
|
mLastDialogue = *iter;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
mChoiceMap.clear();
|
|
|
|
|
mChoice = -1;
|
|
|
|
|
mIsInChoice = false;
|
|
|
|
|
std::string text = info->mResponse;
|
|
|
|
|
parseText (text);
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->getDialogueWindow()->addText (text);
|
|
|
|
|
executeScript (info->mResultScript);
|
|
|
|
|
mLastTopic = mLastTopic;
|
|
|
|
|
mLastDialogue = *info;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTopics();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DialogueManager::printError (std::string error)
|
|
|
|
|
void DialogueManager::printError (const std::string& error)
|
|
|
|
|
{
|
|
|
|
|
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
|
|
|
|
|
win->addText(error);
|
|
|
|
@ -932,22 +411,9 @@ namespace MWDialogue
|
|
|
|
|
mIsInChoice = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string DialogueManager::getFaction() const
|
|
|
|
|
MWWorld::Ptr DialogueManager::getActor() const
|
|
|
|
|
{
|
|
|
|
|
if (mActor.getTypeName() != typeid(ESM::NPC).name())
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
std::string factionID("");
|
|
|
|
|
MWMechanics::NpcStats stats = MWWorld::Class::get(mActor).getNpcStats(mActor);
|
|
|
|
|
if(stats.getFactionRanks().empty())
|
|
|
|
|
{
|
|
|
|
|
std::cout << "No faction for this actor!";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
factionID = stats.getFactionRanks().begin()->first;
|
|
|
|
|
}
|
|
|
|
|
return factionID;
|
|
|
|
|
return mActor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DialogueManager::goodbye()
|
|
|
|
@ -980,7 +446,6 @@ namespace MWDialogue
|
|
|
|
|
if (success)
|
|
|
|
|
MWWorld::Class::get(player).skillUsageSucceeded(player, ESM::Skill::Speechcraft, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add status message to dialogue window
|
|
|
|
|
std::string text;
|
|
|
|
|
|
|
|
|
|