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
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2011-04-26 18:08:37 +00:00
|
|
|
|
|
|
|
namespace MWDialogue
|
|
|
|
{
|
|
|
|
Quest::Quest()
|
2011-04-26 18:39:59 +00:00
|
|
|
: Topic(), mIndex (0), mFinished (false)
|
2011-04-26 18:08:37 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
Quest::Quest (const std::string& topic)
|
2011-04-26 18:39:59 +00:00
|
|
|
: Topic (topic), mIndex (0), mFinished (false)
|
2011-04-26 18:08:37 +00:00
|
|
|
{}
|
|
|
|
|
2013-11-30 11:41:18 +00:00
|
|
|
std::string Quest::getName() const
|
2011-04-26 18:08:37 +00:00
|
|
|
{
|
2012-11-05 17:45:18 +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;
|
|
|
|
}
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
void Quest::setIndex (int index)
|
2011-04-26 18:08:37 +00:00
|
|
|
{
|
2012-11-05 17:45:18 +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;
|
|
|
|
}
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
void Quest::addEntry (const JournalEntry& entry)
|
2011-04-26 18:08:37 +00:00
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
|
2012-11-05 17:45:18 +00:00
|
|
|
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)
|
2012-09-30 19:34:53 +00:00
|
|
|
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);
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
setIndex (index);
|
2011-04-26 18:08:37 +00:00
|
|
|
|
|
|
|
for (TEntryIter iter (mEntries.begin()); iter!=mEntries.end(); ++iter)
|
2011-04-26 18:22:50 +00:00
|
|
|
if (*iter==entry.mInfoId)
|
2011-04-26 18:08:37 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-26 18:22:50 +00:00
|
|
|
mEntries.push_back (entry.mInfoId);
|
2011-04-26 18:08:37 +00:00
|
|
|
}
|
|
|
|
}
|