1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 12:42:11 +00:00
OpenMW/apps/openmw/mwdialogue/quest.cpp

91 lines
2.5 KiB
C++
Raw Normal View History

2011-04-26 18:08:37 +00:00
#include "quest.hpp"
2012-10-01 15:17:04 +00:00
#include "../mwworld/esmstore.hpp"
2011-04-26 18:08:37 +00:00
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
2011-04-26 18:08:37 +00:00
namespace MWDialogue
{
Quest::Quest()
: Topic(), mIndex (0), mFinished (false)
2011-04-26 18:08:37 +00:00
{}
Quest::Quest (const std::string& topic)
: Topic (topic), mIndex (0), mFinished (false)
2011-04-26 18:08:37 +00:00
{}
std::string Quest::getName() const
2011-04-26 18:08:37 +00:00
{
const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (mTopic);
2011-04-26 18:08:37 +00:00
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin());
iter!=dialogue->mInfo.end(); ++iter)
2012-09-17 07:37:50 +00:00
if (iter->mQuestStatus==ESM::DialInfo::QS_Name)
return iter->mResponse;
2011-04-26 18:08:37 +00:00
return "";
}
int Quest::getIndex() const
{
return mIndex;
}
void Quest::setIndex (int index)
2011-04-26 18:08:37 +00:00
{
const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (mTopic);
2011-04-26 18:08:37 +00:00
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin());
iter!=dialogue->mInfo.end(); ++iter)
2012-09-17 07:37:50 +00:00
if (iter->mData.mDisposition==index && iter->mQuestStatus!=ESM::DialInfo::QS_Name)
2011-04-26 18:08:37 +00:00
{
mIndex = index;
2012-09-17 07:37:50 +00:00
if (iter->mQuestStatus==ESM::DialInfo::QS_Finished)
2011-04-26 18:08:37 +00:00
mFinished = true;
2012-09-17 07:37:50 +00:00
else if (iter->mQuestStatus==ESM::DialInfo::QS_Restart)
2011-04-26 18:08:37 +00:00
mFinished = false;
return;
}
throw std::runtime_error ("unknown journal index for topic " + mTopic);
}
bool Quest::isFinished() const
{
return mFinished;
}
void Quest::addEntry (const JournalEntry& entry)
2011-04-26 18:08:37 +00:00
{
int index = -1;
const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (entry.mTopic);
2011-04-26 18:08:37 +00:00
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin());
iter!=dialogue->mInfo.end(); ++iter)
if (iter->mId == entry.mInfoId)
2011-04-26 18:08:37 +00:00
{
2012-09-17 07:37:50 +00:00
index = iter->mData.mDisposition; /// \todo cleanup info structure
2011-04-26 18:08:37 +00:00
break;
}
if (index==-1)
throw std::runtime_error ("unknown journal entry for topic " + mTopic);
setIndex (index);
2011-04-26 18:08:37 +00:00
for (TEntryIter iter (mEntries.begin()); iter!=mEntries.end(); ++iter)
if (*iter==entry.mInfoId)
2011-04-26 18:08:37 +00:00
return;
mEntries.push_back (entry.mInfoId);
2011-04-26 18:08:37 +00:00
}
}