Merge remote-tracking branch 'potatoesmaster/dialogue' into next

This commit is contained in:
Marc Zinnschlag 2013-03-20 20:53:14 +01:00
commit 775f9e8402
4 changed files with 53 additions and 19 deletions

View file

@ -136,8 +136,12 @@ bool MWDialogue::Filter::testDisposition (const ESM::DialInfo& info, bool invert
bool MWDialogue::Filter::testSelectStruct (const SelectWrapper& select) const bool MWDialogue::Filter::testSelectStruct (const SelectWrapper& select) const
{ {
if (select.isNpcOnly() && mActor.getTypeName()!=typeid (ESM::NPC).name()) if (select.isNpcOnly() && (mActor.getTypeName() != typeid (ESM::NPC).name()))
return select.isInverted(); // If the actor is a creature, we do not test the conditions applicable
// only to NPCs. Such conditions can never be satisfied, apart
// inverted ones (NotClass, NotRace, NotFaction return true
// because creatures are not of any race, class or faction).
return select.getType() == SelectWrapper::Type_Inverted;
switch (select.getType()) switch (select.getType())
{ {
@ -145,6 +149,9 @@ bool MWDialogue::Filter::testSelectStruct (const SelectWrapper& select) const
case SelectWrapper::Type_Integer: return select.selectCompare (getSelectStructInteger (select)); case SelectWrapper::Type_Integer: return select.selectCompare (getSelectStructInteger (select));
case SelectWrapper::Type_Numeric: return testSelectStructNumeric (select); case SelectWrapper::Type_Numeric: return testSelectStructNumeric (select);
case SelectWrapper::Type_Boolean: return select.selectCompare (getSelectStructBoolean (select)); case SelectWrapper::Type_Boolean: return select.selectCompare (getSelectStructBoolean (select));
// We must not do the comparison for inverted functions (eg. Function_NotClass)
case SelectWrapper::Type_Inverted: return getSelectStructBoolean (select);
} }
return true; return true;
@ -433,6 +440,30 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co
return Misc::StringUtils::lowerCase (mActor.getCell()->mCell->mName)!=select.getName(); return Misc::StringUtils::lowerCase (mActor.getCell()->mCell->mName)!=select.getName();
case SelectWrapper::Function_NotLocal:
{
std::string scriptName = MWWorld::Class::get (mActor).getScript (mActor);
if (scriptName.empty())
// This actor has no attached script, so there is no local variable
return true;
const ESM::Script *script =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (scriptName);
std::string name = select.getName();
int i = 0;
for (; i < script->mVarNames.size(); ++i)
if (Misc::StringUtils::lowerCase(script->mVarNames[i]) == name)
break;
if (i >= script->mVarNames.size())
return true; // script does not have a variable of this name
return false;
}
case SelectWrapper::Function_SameGender: case SelectWrapper::Function_SameGender:
return (player.get<ESM::NPC>()->mBase->mFlags & ESM::NPC::Female)== return (player.get<ESM::NPC>()->mBase->mFlags & ESM::NPC::Female)==

View file

@ -117,7 +117,7 @@ MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() con
case '9': return Function_NotClass; case '9': return Function_NotClass;
case 'A': return Function_NotRace; case 'A': return Function_NotRace;
case 'B': return Function_NotCell; case 'B': return Function_NotCell;
case 'C': return Function_Local; case 'C': return Function_NotLocal;
} }
return Function_None; return Function_None;
@ -219,7 +219,6 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
static const Function booleanFunctions[] = static const Function booleanFunctions[] =
{ {
Function_False, Function_False,
Function_NotId, Function_NotFaction, Function_NotClass, Function_NotRace, Function_NotCell,
Function_SameGender, Function_SameRace, Function_SameFaction, Function_SameGender, Function_SameRace, Function_SameFaction,
Function_PcCommonDisease, Function_PcBlightDisease, Function_PcCorprus, Function_PcCommonDisease, Function_PcBlightDisease, Function_PcCorprus,
Function_PcExpelled, Function_PcExpelled,
@ -231,6 +230,13 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
Function_None // end marker Function_None // end marker
}; };
static const Function invertedBooleanFunctions[] =
{
Function_NotId, Function_NotFaction, Function_NotClass,
Function_NotRace, Function_NotCell, Function_NotLocal,
Function_None // end marker
};
Function function = getFunction(); Function function = getFunction();
for (int i=0; integerFunctions[i]!=Function_None; ++i) for (int i=0; integerFunctions[i]!=Function_None; ++i)
@ -245,21 +251,18 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
if (booleanFunctions[i]==function) if (booleanFunctions[i]==function)
return Type_Boolean; return Type_Boolean;
for (int i=0; invertedBooleanFunctions[i]!=Function_None; ++i)
if (invertedBooleanFunctions[i]==function)
return Type_Inverted;
return Type_None; return Type_None;
} }
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 bool MWDialogue::SelectWrapper::isNpcOnly() const
{ {
static const Function functions[] = static const Function functions[] =
{ {
Function_NotFaction, SelectWrapper::Function_NotClass, SelectWrapper::Function_NotRace, Function_NotFaction, Function_NotClass, Function_NotRace,
Function_SameGender, Function_SameRace, Function_SameFaction, Function_SameGender, Function_SameRace, Function_SameFaction,
Function_PcSkill, Function_PcSkill,
Function_PcExpelled, Function_PcExpelled,
@ -283,17 +286,17 @@ bool MWDialogue::SelectWrapper::isNpcOnly() const
bool MWDialogue::SelectWrapper::selectCompare (int value) const bool MWDialogue::SelectWrapper::selectCompare (int value) const
{ {
return selectCompareImp (mSelect, value)!=isInverted(); // logic XOR return selectCompareImp (mSelect, value);
} }
bool MWDialogue::SelectWrapper::selectCompare (float value) const bool MWDialogue::SelectWrapper::selectCompare (float value) const
{ {
return selectCompareImp (mSelect, value)!=isInverted(); // logic XOR return selectCompareImp (mSelect, value);
} }
bool MWDialogue::SelectWrapper::selectCompare (bool value) const bool MWDialogue::SelectWrapper::selectCompare (bool value) const
{ {
return selectCompareImp (mSelect, static_cast<int> (value))!=isInverted(); // logic XOR return selectCompareImp (mSelect, static_cast<int> (value));
} }
std::string MWDialogue::SelectWrapper::getName() const std::string MWDialogue::SelectWrapper::getName() const

View file

@ -22,6 +22,7 @@ namespace MWDialogue
Function_NotClass, Function_NotClass,
Function_NotRace, Function_NotRace,
Function_NotCell, Function_NotCell,
Function_NotLocal,
Function_Local, Function_Local,
Function_Global, Function_Global,
Function_SameGender, Function_SameRace, Function_SameFaction, Function_SameGender, Function_SameRace, Function_SameFaction,
@ -50,7 +51,8 @@ namespace MWDialogue
Type_None, Type_None,
Type_Integer, Type_Integer,
Type_Numeric, Type_Numeric,
Type_Boolean Type_Boolean,
Type_Inverted
}; };
private: private:
@ -67,8 +69,6 @@ namespace MWDialogue
Type getType() const; Type getType() const;
bool isInverted() const;
bool isNpcOnly() const; bool isNpcOnly() const;
///< \attention Do not call any of the select functions for this select struct! ///< \attention Do not call any of the select functions for this select struct!

View file

@ -169,7 +169,7 @@ namespace MWWorld
bool Class::hasDetected (const MWWorld::Ptr& ptr, const MWWorld::Ptr& ptr2) const bool Class::hasDetected (const MWWorld::Ptr& ptr, const MWWorld::Ptr& ptr2) const
{ {
return false; return true;
} }
float Class::getArmorRating (const MWWorld::Ptr& ptr) const float Class::getArmorRating (const MWWorld::Ptr& ptr) const