1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00

98 lines
2.6 KiB
C++
Raw Normal View History

2011-04-26 20:08:37 +02:00
#include "quest.hpp"
#include <components/esm3/queststate.hpp>
2013-12-03 14:28:46 +01:00
2012-10-01 19:17:04 +04:00
#include "../mwworld/esmstore.hpp"
2011-04-26 20:08:37 +02:00
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
2011-04-26 20:08:37 +02:00
namespace MWDialogue
{
Quest::Quest()
: Topic(), mIndex (0), mFinished (false)
2011-04-26 20:08:37 +02:00
{}
Quest::Quest (const std::string& topic)
: Topic (topic), mIndex (0), mFinished (false)
2011-04-26 20:08:37 +02:00
{}
2013-12-03 14:28:46 +01: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 20:08:37 +02:00
{
const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (mTopic);
2011-04-26 20:08:37 +02:00
2014-02-20 16:59:20 +01:00
for (ESM::Dialogue::InfoContainer::const_iterator iter (dialogue->mInfo.begin());
2011-04-26 20:08:37 +02:00
iter!=dialogue->mInfo.end(); ++iter)
2012-09-17 11:37:50 +04:00
if (iter->mQuestStatus==ESM::DialInfo::QS_Name)
return iter->mResponse;
2011-04-26 20:08:37 +02:00
return "";
}
int Quest::getIndex() const
{
return mIndex;
}
void Quest::setIndex (int index)
2011-04-26 20:08:37 +02:00
{
// The index must be set even if no related journal entry was found
mIndex = index;
2011-04-26 20:08:37 +02:00
}
bool Quest::isFinished() const
{
return mFinished;
}
void Quest::addEntry (const JournalEntry& entry)
2011-04-26 20:08:37 +02:00
{
int index = -1;
const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (entry.mTopic);
2011-04-26 20:08:37 +02:00
2014-02-20 16:59:20 +01:00
for (ESM::Dialogue::InfoContainer::const_iterator iter (dialogue->mInfo.begin());
2011-04-26 20:08:37 +02:00
iter!=dialogue->mInfo.end(); ++iter)
if (iter->mId == entry.mInfoId)
2011-04-26 20:08:37 +02:00
{
2015-01-27 02:21:53 +01:00
index = iter->mData.mJournalIndex;
2011-04-26 20:08:37 +02:00
break;
}
if (index==-1)
throw std::runtime_error ("unknown journal entry for topic " + mTopic);
for (auto &info : dialogue->mInfo)
{
if (info.mData.mJournalIndex == index
&& (info.mQuestStatus == ESM::DialInfo::QS_Finished || info.mQuestStatus == ESM::DialInfo::QS_Restart))
{
mFinished = (info.mQuestStatus == ESM::DialInfo::QS_Finished);
break;
}
}
if (index > mIndex)
mIndex = index;
2011-04-26 20:08:37 +02:00
for (TEntryIter iter (mEntries.begin()); iter!=mEntries.end(); ++iter)
if (iter->mInfoId==entry.mInfoId)
2011-04-26 20:08:37 +02:00
return;
mEntries.push_back (entry); // we want slicing here
2011-04-26 20:08:37 +02:00
}
2013-12-03 14:28:46 +01:00
void Quest::write (ESM::QuestState& state) const
{
state.mTopic = getTopic();
state.mState = mIndex;
state.mFinished = mFinished;
2011-04-26 20:08:37 +02:00
}
}