2011-04-19 08:54:11 +00:00
|
|
|
|
|
|
|
#include "journalentry.hpp"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <components/esm_store/store.hpp>
|
|
|
|
|
2011-04-21 09:05:49 +00:00
|
|
|
#include "../mwworld/world.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
|
|
|
{}
|
|
|
|
|
|
|
|
std::string JournalEntry::getText (const ESMS::ESMStore& store) const
|
|
|
|
{
|
|
|
|
const ESM::Dialogue *dialogue = store.dialogs.find (mTopic);
|
|
|
|
|
|
|
|
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin());
|
|
|
|
iter!=dialogue->mInfo.end(); ++iter)
|
|
|
|
if (iter->id==mInfoId)
|
|
|
|
return iter->response;
|
|
|
|
|
|
|
|
throw std::runtime_error ("unknown info ID " + mInfoId + " for topic " + mTopic);
|
|
|
|
}
|
2011-04-21 09:05:49 +00:00
|
|
|
|
|
|
|
JournalEntry JournalEntry::makeFromQuest (const std::string& topic, int index,
|
|
|
|
const MWWorld::World& world)
|
2011-04-22 09:16:39 +00:00
|
|
|
{
|
|
|
|
return JournalEntry (topic, idFromIndex (topic, index, world));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string JournalEntry::idFromIndex (const std::string& topic, int index,
|
|
|
|
const MWWorld::World& world)
|
2011-04-21 09:05:49 +00:00
|
|
|
{
|
|
|
|
const ESM::Dialogue *dialogue = world.getStore().dialogs.find (topic);
|
|
|
|
|
|
|
|
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin());
|
|
|
|
iter!=dialogue->mInfo.end(); ++iter)
|
|
|
|
if (iter->data.disposition==index) /// \todo cleanup info structure
|
|
|
|
{
|
2011-12-29 16:32:57 +00:00
|
|
|
return iter->id;
|
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)
|
|
|
|
{}
|
|
|
|
|
|
|
|
StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index,
|
|
|
|
const MWWorld::World& world)
|
|
|
|
{
|
|
|
|
int day = world.getGlobalVariable ("dayspassed").mLong;
|
|
|
|
int month = world.getGlobalVariable ("day").mLong;
|
|
|
|
int dayOfMonth = world.getGlobalVariable ("month").mLong;
|
|
|
|
|
|
|
|
return StampedJournalEntry (topic, idFromIndex (topic, index, world), day, month, dayOfMonth);
|
|
|
|
}
|
2011-04-19 08:54:11 +00:00
|
|
|
}
|