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

108 lines
3.1 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
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
bool found=false;
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
{
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;
found = true;
// Don't return here. Quest status may actually be in a different info record, since we don't merge these (yet?)
2011-04-26 18:08:37 +00:00
}
if (found)
mIndex = index;
else
throw std::runtime_error ("unknown journal index for topic " + mTopic);
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
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);
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
}
}