Issue #219: moved over the second batch of functions (boolean and one integer I forgot last time)

actorid
Marc Zinnschlag 12 years ago
parent 91afef140b
commit e68bb3481e

@ -289,8 +289,6 @@ namespace MWDialogue
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')
@ -345,86 +343,6 @@ namespace MWDialogue
return true;
case '6': // dead
return selectCompare<int,int> (comp,
MWBase::Environment::get().getMechanicsManager()->countDeaths (toLower (name)), select.mI);
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)

@ -4,6 +4,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/journal.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/player.hpp"
@ -125,6 +126,9 @@ bool MWDialogue::Filter::testSelectStructs (const ESM::DialInfo& info) const
bool MWDialogue::Filter::testSelectStruct (const SelectWrapper& select) const
{
if (select.isNpcOnly() && mActor.getTypeName()!=typeid (ESM::NPC).name())
return select.isInverted();
switch (select.getType())
{
case SelectWrapper::Type_None: return true;
@ -169,6 +173,10 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con
return sum;
}
case SelectWrapper::Function_Dead:
return MWBase::Environment::get().getMechanicsManager()->countDeaths (select.getName());
default:
@ -180,6 +188,26 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co
{
switch (select.getFunction())
{
case SelectWrapper::Function_Id:
return select.getName()==toLower (MWWorld::Class::get (mActor).getId (mActor));
case SelectWrapper::Function_Faction:
return toLower (mActor.get<ESM::NPC>()->mBase->mFaction)==select.getName();
case SelectWrapper::Function_Class:
return toLower (mActor.get<ESM::NPC>()->mBase->mClass)==select.getName();
case SelectWrapper::Function_Race:
return toLower (mActor.get<ESM::NPC>()->mBase->mRace)==select.getName();
case SelectWrapper::Function_Cell:
return toLower (mActor.getCell()->mCell->mName)==select.getName();
default:
throw std::runtime_error ("unknown boolean select function");

@ -62,6 +62,12 @@ MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() con
{
case '4': return Function_Journal;
case '5': return Function_Item;
case '6': return Function_Dead;
case '7': return Function_Id;
case '8': return Function_Faction;
case '9': return Function_Class;
case 'A': return Function_Race;
case 'B': return Function_Cell;
}
return Function_None;
@ -71,7 +77,7 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
{
static const Function integerFunctions[] =
{
Function_Journal, Function_Item,
Function_Journal, Function_Item, Function_Dead,
Function_None // end marker
};
@ -82,14 +88,12 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
static const Function booleanFunctions[] =
{
Function_Id, Function_Faction, Function_Class, Function_Race, Function_Cell,
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;
@ -102,29 +106,46 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
if (booleanFunctions[i]==function)
return Type_Boolean;
throw std::runtime_error ("failed to determine type of select function");
return Type_None;
}
bool MWDialogue::SelectWrapper::IsInverted() const
bool MWDialogue::SelectWrapper::isInverted() const
{
char type = mSelect.mSelectRule[1];
return type=='7' || type=='8' || type=='9' || type=='A' || type=='B' || type=='C';
}
bool MWDialogue::SelectWrapper::isNpcOnly() const
{
static const Function functions[] =
{
Function_Faction, SelectWrapper::Function_Class, SelectWrapper::Function_Race,
Function_None // end marker
};
Function function = getFunction();
for (int i=0; functions[i]!=Function_None; ++i)
if (functions[i]==function)
return true;
return false;
}
bool MWDialogue::SelectWrapper::selectCompare (int value) const
{
return selectCompareImp (mSelect, value)!=IsInverted(); // logic XOR
return selectCompareImp (mSelect, value)!=isInverted(); // logic XOR
}
bool MWDialogue::SelectWrapper::selectCompare (float value) const
{
return selectCompareImp (mSelect, value)!=IsInverted(); // logic XOR
return selectCompareImp (mSelect, value)!=isInverted(); // logic XOR
}
bool MWDialogue::SelectWrapper::selectCompare (bool value) const
{
return selectCompareImp (mSelect, static_cast<int> (value))!=IsInverted(); // logic XOR
return selectCompareImp (mSelect, static_cast<int> (value))!=isInverted(); // logic XOR
}
std::string MWDialogue::SelectWrapper::getName() const

@ -15,7 +15,13 @@ namespace MWDialogue
{
Function_None,
Function_Journal,
Function_Item
Function_Item,
Function_Dead,
Function_Id,
Function_Faction,
Function_Class,
Function_Race,
Function_Cell
};
enum Type
@ -34,7 +40,10 @@ namespace MWDialogue
Type getType() const;
bool IsInverted() const;
bool isInverted() const;
bool isNpcOnly() const;
///< \attention Do not call any of the select functions for this select struct!
bool selectCompare (int value) const;

Loading…
Cancel
Save