1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Issue #219: added function decoding and moved same faction function from DialogueManager to Filter

This commit is contained in:
Marc Zinnschlag 2012-11-10 09:35:50 +01:00
parent 4994a253da
commit a752536cea
6 changed files with 41 additions and 21 deletions

View File

@ -97,8 +97,6 @@ namespace MWDialogue
bool DialogueManager::functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info,bool choice) 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()); for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.mSelects.begin());
iter != info.mSelects.end(); ++iter) iter != info.mSelects.end(); ++iter)
{ {
@ -131,23 +129,6 @@ namespace MWDialogue
if(!selectCompare<int,int>(comp,0,select.mI)) return false; if(!selectCompare<int,int>(comp,0,select.mI)) return false;
break; 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 case 48://Detected
if(!selectCompare<int,int>(comp,1,select.mI)) return false; if(!selectCompare<int,int>(comp,1,select.mI)) return false;
break; break;

View File

@ -250,6 +250,14 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co
return toLower (mActor.getCell()->mCell->mName)==select.getName(); return toLower (mActor.getCell()->mCell->mName)==select.getName();
case SelectWrapper::Function_SameFaction:
{
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
return MWWorld::Class::get (mActor).getNpcStats (mActor).isSameFaction (
MWWorld::Class::get (player).getNpcStats (player));
}
default: default:
throw std::runtime_error ("unknown boolean select function"); throw std::runtime_error ("unknown boolean select function");

View File

@ -5,6 +5,7 @@
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
#include <sstream>
namespace namespace
{ {
@ -52,6 +53,15 @@ namespace
} }
} }
MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::decodeFunction() const
{
int index = 0;
std::istringstream (mSelect.mSelectRule.substr(2,2)) >> index;
return static_cast<Function> (index);
}
MWDialogue::SelectWrapper::SelectWrapper (const ESM::DialInfo::SelectStruct& select) : mSelect (select) {} MWDialogue::SelectWrapper::SelectWrapper (const ESM::DialInfo::SelectStruct& select) : mSelect (select) {}
MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() const MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() const
@ -60,6 +70,7 @@ MWDialogue::SelectWrapper::Function MWDialogue::SelectWrapper::getFunction() con
switch (type) switch (type)
{ {
case '1': return decodeFunction();
case '2': return Function_Global; case '2': return Function_Global;
case '3': return Function_Local; case '3': return Function_Local;
case '4': return Function_Journal; case '4': return Function_Journal;
@ -93,6 +104,7 @@ MWDialogue::SelectWrapper::Type MWDialogue::SelectWrapper::getType() const
static const Function booleanFunctions[] = static const Function booleanFunctions[] =
{ {
Function_Id, Function_Faction, Function_Class, Function_Race, Function_Cell, Function_Id, Function_Faction, Function_Class, Function_Race, Function_Cell,
Function_SameFaction,
Function_None // end marker Function_None // end marker
}; };
@ -125,6 +137,7 @@ bool MWDialogue::SelectWrapper::isNpcOnly() const
static const Function functions[] = static const Function functions[] =
{ {
Function_Faction, SelectWrapper::Function_Class, SelectWrapper::Function_Race, Function_Faction, SelectWrapper::Function_Class, SelectWrapper::Function_Race,
Function_SameFaction,
Function_None // end marker Function_None // end marker
}; };

View File

@ -13,7 +13,7 @@ namespace MWDialogue
enum Function enum Function
{ {
Function_None, Function_None = 0,
Function_Journal, Function_Journal,
Function_Item, Function_Item,
Function_Dead, Function_Dead,
@ -23,7 +23,8 @@ namespace MWDialogue
Function_Race, Function_Race,
Function_Cell, Function_Cell,
Function_Local, Function_Local,
Function_Global Function_Global,
Function_SameFaction
}; };
enum Type enum Type
@ -33,6 +34,10 @@ namespace MWDialogue
Type_Numeric, Type_Numeric,
Type_Boolean Type_Boolean
}; };
private:
Function decodeFunction() const;
public: public:

View File

@ -86,6 +86,16 @@ const std::map<std::string, int>& MWMechanics::NpcStats::getFactionRanks() const
return mFactionRank; return mFactionRank;
} }
bool MWMechanics::NpcStats::isSameFaction (const NpcStats& npcStats) const
{
for (std::map<std::string, int>::const_iterator iter (mFactionRank.begin()); iter!=mFactionRank.end();
++iter)
if (npcStats.mFactionRank.find (iter->first)!=npcStats.mFactionRank.end())
return true;
return false;
}
float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& class_, int usageType, float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& class_, int usageType,
int level) const int level) const
{ {

View File

@ -76,6 +76,9 @@ namespace MWMechanics
std::map<std::string, int>& getFactionRanks(); std::map<std::string, int>& getFactionRanks();
bool isSameFaction (const NpcStats& npcStats) const;
///< Do *this and \a npcStats share a faction?
const std::map<std::string, int>& getFactionRanks() const; const std::map<std::string, int>& getFactionRanks() const;
float getSkillGain (int skillIndex, const ESM::Class& class_, int usageType = -1, float getSkillGain (int skillIndex, const ESM::Class& class_, int usageType = -1,