2011-04-19 08:54:11 +00:00
|
|
|
|
|
|
|
#include "journalentry.hpp"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2011-04-21 09:05:49 +00:00
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
2011-04-19 08:54:11 +00:00
|
|
|
namespace MWDialogue
|
|
|
|
{
|
|
|
|
JournalEntry::JournalEntry() {}
|
|
|
|
|
2011-04-22 09:16:39 +00:00
|
|
|
JournalEntry::JournalEntry (const std::string& topic, const std::string& infoId)
|
|
|
|
: mTopic (topic), mInfoId (infoId)
|
2011-04-19 08:54:11 +00:00
|
|
|
{}
|
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
std::string JournalEntry::getText (const MWWorld::ESMStore& store) const
|
2011-04-19 08:54:11 +00:00
|
|
|
{
|
|
|
|
const ESM::Dialogue *dialogue = store.dialogs.find (mTopic);
|
|
|
|
|
|
|
|
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 == mInfoId)
|
2012-09-17 07:37:50 +00:00
|
|
|
return iter->mResponse;
|
2011-04-19 08:54:11 +00:00
|
|
|
|
|
|
|
throw std::runtime_error ("unknown info ID " + mInfoId + " for topic " + mTopic);
|
|
|
|
}
|
2011-04-21 09:05:49 +00:00
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
JournalEntry JournalEntry::makeFromQuest (const std::string& topic, int index)
|
2011-04-22 09:16:39 +00:00
|
|
|
{
|
2012-07-03 10:30:50 +00:00
|
|
|
return JournalEntry (topic, idFromIndex (topic, index));
|
2011-04-22 09:16:39 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
std::string JournalEntry::idFromIndex (const std::string& topic, int index)
|
2011-04-21 09:05:49 +00:00
|
|
|
{
|
2012-11-05 17:45:18 +00:00
|
|
|
const ESM::Dialogue *dialogue =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (topic);
|
2011-04-21 09:05:49 +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) /// \todo cleanup info structure
|
2011-04-21 09:05:49 +00:00
|
|
|
{
|
2012-09-30 19:34:53 +00:00
|
|
|
return iter->mId;
|
2011-04-21 09:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw std::runtime_error ("unknown journal index for topic " + topic);
|
|
|
|
}
|
2011-04-22 09:16:39 +00:00
|
|
|
|
|
|
|
StampedJournalEntry::StampedJournalEntry()
|
|
|
|
: mDay (0), mMonth (0), mDayOfMonth (0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
StampedJournalEntry::StampedJournalEntry (const std::string& topic, const std::string& infoId,
|
|
|
|
int day, int month, int dayOfMonth)
|
|
|
|
: JournalEntry (topic, infoId), mDay (day), mMonth (month), mDayOfMonth (dayOfMonth)
|
|
|
|
{}
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index)
|
2011-04-22 09:16:39 +00:00
|
|
|
{
|
2012-07-03 10:30:50 +00:00
|
|
|
int day = MWBase::Environment::get().getWorld()->getGlobalVariable ("dayspassed").mLong;
|
|
|
|
int month = MWBase::Environment::get().getWorld()->getGlobalVariable ("day").mLong;
|
|
|
|
int dayOfMonth = MWBase::Environment::get().getWorld()->getGlobalVariable ("month").mLong;
|
2011-04-22 09:16:39 +00:00
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
return StampedJournalEntry (topic, idFromIndex (topic, index), day, month, dayOfMonth);
|
2011-04-22 09:16:39 +00:00
|
|
|
}
|
2011-04-19 08:54:11 +00:00
|
|
|
}
|