Fix inverted dialogue functions (NotClass etc.)

The comparison present is useless for these functions.
This commit is contained in:
Emanuel Guevel 2013-03-17 02:02:09 +01:00
parent 3bd545ed8e
commit ad3478c8f2
3 changed files with 25 additions and 16 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;

View file

@ -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_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,16 +251,13 @@ 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[] =
@ -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

@ -50,7 +50,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 +68,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!