2011-04-26 20:08:37 +02:00
|
|
|
#include "quest.hpp"
|
|
|
|
|
2022-02-12 13:25:27 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#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
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2011-04-26 20:08:37 +02:00
|
|
|
|
|
|
|
namespace MWDialogue
|
|
|
|
{
|
|
|
|
Quest::Quest()
|
2011-04-26 20:39:59 +02:00
|
|
|
: Topic(), mIndex (0), mFinished (false)
|
2011-04-26 20:08:37 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
Quest::Quest (const std::string& topic)
|
2011-04-26 20:39:59 +02:00
|
|
|
: 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)
|
|
|
|
{}
|
|
|
|
|
2013-11-30 12:41:18 +01:00
|
|
|
std::string Quest::getName() const
|
2011-04-26 20:08:37 +02:00
|
|
|
{
|
2012-11-05 21:45:18 +04: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;
|
|
|
|
}
|
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
void Quest::setIndex (int index)
|
2011-04-26 20:08:37 +02:00
|
|
|
{
|
2014-05-18 07:37:32 +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;
|
|
|
|
}
|
|
|
|
|
2022-02-12 13:25:27 +01:00
|
|
|
void Quest::setFinished(bool finished)
|
2011-04-26 20:08:37 +02:00
|
|
|
{
|
2022-02-12 13:25:27 +01:00
|
|
|
mFinished = finished;
|
|
|
|
}
|
2011-04-26 20:08:37 +02:00
|
|
|
|
2022-02-12 13:25:27 +01:00
|
|
|
bool Quest::addEntry (const JournalEntry& entry)
|
|
|
|
{
|
2012-11-05 21:45:18 +04:00
|
|
|
const ESM::Dialogue *dialogue =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (entry.mTopic);
|
2011-04-26 20:08:37 +02:00
|
|
|
|
2022-02-12 13:25:27 +01:00
|
|
|
auto info = std::find_if(dialogue->mInfo.begin(), dialogue->mInfo.end(), [&](const auto& info) { return info.mId == entry.mInfoId; });
|
2011-04-26 20:08:37 +02:00
|
|
|
|
2022-02-12 13:25:27 +01:00
|
|
|
if (info == dialogue->mInfo.end() || info->mData.mJournalIndex == -1)
|
2011-04-26 20:08:37 +02:00
|
|
|
throw std::runtime_error ("unknown journal entry for topic " + mTopic);
|
|
|
|
|
2022-02-12 13:25:27 +01:00
|
|
|
if (info->mQuestStatus == ESM::DialInfo::QS_Finished || info->mQuestStatus == ESM::DialInfo::QS_Restart)
|
|
|
|
mFinished = info->mQuestStatus == ESM::DialInfo::QS_Finished;
|
2019-01-26 01:03:52 +03:00
|
|
|
|
2022-02-12 13:25:27 +01:00
|
|
|
if (info->mData.mJournalIndex > mIndex)
|
|
|
|
mIndex = info->mData.mJournalIndex;
|
2011-04-26 20:08:37 +02:00
|
|
|
|
|
|
|
for (TEntryIter iter (mEntries.begin()); iter!=mEntries.end(); ++iter)
|
2013-12-01 14:50:25 +01:00
|
|
|
if (iter->mInfoId==entry.mInfoId)
|
2022-02-12 13:25:27 +01:00
|
|
|
return info->mQuestStatus == ESM::DialInfo::QS_Restart;
|
2011-04-26 20:08:37 +02:00
|
|
|
|
2013-12-01 14:50:25 +01:00
|
|
|
mEntries.push_back (entry); // we want slicing here
|
2022-02-12 13:25:27 +01:00
|
|
|
return info->mQuestStatus == ESM::DialInfo::QS_Restart;
|
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
|
|
|
}
|
|
|
|
}
|