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

101 lines
2.9 KiB
C++
Raw Normal View History

2011-04-26 18:08:37 +00:00
#include "quest.hpp"
2013-12-03 13:28:46 +00:00
#include <components/esm/queststate.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
{}
2013-12-03 13:28:46 +00:00
Quest::Quest (const ESM::QuestState& state)
: Topic (state.mTopic), mIndex (state.mState), mFinished (state.mFinished!=0)
{}
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
2014-02-20 15:59:20 +00:00
for (ESM::Dialogue::InfoContainer::const_iterator iter (dialogue->mInfo.begin());
2011-04-26 18:08:37 +00:00
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
2014-02-20 15:59:20 +00:00
for (ESM::Dialogue::InfoContainer::const_iterator iter (dialogue->mInfo.begin());
2011-04-26 18:08:37 +00:00
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
{
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;
}
// The index must be set even if no related journal entry was found
mIndex = index;
2011-04-26 18:08:37 +00:00
}
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
2014-02-20 15:59:20 +00:00
for (ESM::Dialogue::InfoContainer::const_iterator iter (dialogue->mInfo.begin());
2011-04-26 18:08:37 +00:00
iter!=dialogue->mInfo.end(); ++iter)
if (iter->mId == entry.mInfoId)
2011-04-26 18:08:37 +00:00
{
2015-01-27 01:21:53 +00:00
index = iter->mData.mJournalIndex;
2011-04-26 18:08:37 +00:00
break;
}
if (index==-1)
throw std::runtime_error ("unknown journal entry for topic " + mTopic);
if (index > mIndex)
setIndex (index);
2011-04-26 18:08:37 +00:00
for (TEntryIter iter (mEntries.begin()); iter!=mEntries.end(); ++iter)
if (iter->mInfoId==entry.mInfoId)
2011-04-26 18:08:37 +00:00
return;
mEntries.push_back (entry); // we want slicing here
2011-04-26 18:08:37 +00:00
}
2013-12-03 13:28:46 +00:00
void Quest::write (ESM::QuestState& state) const
{
state.mTopic = getTopic();
state.mState = mIndex;
state.mFinished = mFinished;
2011-04-26 18:08:37 +00:00
}
}