2011-04-04 09:16:56 +00:00
|
|
|
|
2012-08-09 10:56:03 +00:00
|
|
|
#include "journalimp.hpp"
|
2011-04-04 09:16:56 +00:00
|
|
|
|
2013-12-03 13:28:46 +00:00
|
|
|
#include <iterator>
|
|
|
|
|
|
|
|
#include <components/esm/esmwriter.hpp>
|
|
|
|
#include <components/esm/esmreader.hpp>
|
|
|
|
#include <components/esm/queststate.hpp>
|
|
|
|
#include <components/esm/journalentry.hpp>
|
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-08-12 12:36:46 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2011-04-04 09:23:15 +00:00
|
|
|
|
2012-03-19 18:18:08 +00:00
|
|
|
#include "../mwgui/messagebox.hpp"
|
|
|
|
|
2011-04-04 09:16:56 +00:00
|
|
|
namespace MWDialogue
|
|
|
|
{
|
2011-04-26 18:08:37 +00:00
|
|
|
Quest& Journal::getQuest (const std::string& id)
|
|
|
|
{
|
|
|
|
TQuestContainer::iterator iter = mQuests.find (id);
|
|
|
|
|
|
|
|
if (iter==mQuests.end())
|
|
|
|
{
|
|
|
|
std::pair<TQuestContainer::iterator, bool> result =
|
|
|
|
mQuests.insert (std::make_pair (id, Quest (id)));
|
|
|
|
|
|
|
|
iter = result.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
2013-12-03 13:28:46 +00:00
|
|
|
Topic& Journal::getTopic (const std::string& id)
|
|
|
|
{
|
|
|
|
TTopicContainer::iterator iter = mTopics.find (id);
|
|
|
|
|
|
|
|
if (iter==mTopics.end())
|
|
|
|
{
|
|
|
|
std::pair<TTopicContainer::iterator, bool> result
|
|
|
|
= mTopics.insert (std::make_pair (id, Topic (id)));
|
|
|
|
|
|
|
|
iter = result.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
bool Journal::isThere (const std::string& topicId, const std::string& infoId) const
|
|
|
|
{
|
|
|
|
if (const ESM::Dialogue *dialogue =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().search (topicId))
|
|
|
|
{
|
|
|
|
if (infoId.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin());
|
|
|
|
iter!=dialogue->mInfo.end(); ++iter)
|
|
|
|
if (iter->mId == infoId)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-03 13:28:46 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
Journal::Journal()
|
2011-04-04 09:16:56 +00:00
|
|
|
{}
|
|
|
|
|
2013-05-15 15:54:18 +00:00
|
|
|
void Journal::clear()
|
|
|
|
{
|
|
|
|
mJournal.clear();
|
|
|
|
mQuests.clear();
|
|
|
|
mTopics.clear();
|
|
|
|
}
|
|
|
|
|
2011-04-04 09:23:15 +00:00
|
|
|
void Journal::addEntry (const std::string& id, int index)
|
|
|
|
{
|
2013-01-20 00:21:15 +00:00
|
|
|
// bail out of we already have heard this...
|
2013-01-20 14:24:55 +00:00
|
|
|
std::string infoId = JournalEntry::idFromIndex (id, index);
|
|
|
|
for (TEntryIter i = mJournal.begin (); i != mJournal.end (); ++i)
|
2013-01-20 00:21:15 +00:00
|
|
|
if (i->mTopic == id && i->mInfoId == infoId)
|
|
|
|
return;
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
StampedJournalEntry entry = StampedJournalEntry::makeFromQuest (id, index);
|
2011-04-26 18:08:37 +00:00
|
|
|
|
|
|
|
mJournal.push_back (entry);
|
|
|
|
|
|
|
|
Quest& quest = getQuest (id);
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
quest.addEntry (entry); // we are doing slicing on purpose here
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2012-03-19 18:18:08 +00:00
|
|
|
std::vector<std::string> empty;
|
2012-09-22 19:35:57 +00:00
|
|
|
std::string notification = "#{sJournalEntry}";
|
2012-04-23 13:27:03 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox (notification, empty);
|
2011-04-04 09:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Journal::setJournalIndex (const std::string& id, int index)
|
|
|
|
{
|
2011-04-26 18:08:37 +00:00
|
|
|
Quest& quest = getQuest (id);
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
quest.setIndex (index);
|
2011-04-04 09:23:15 +00:00
|
|
|
}
|
|
|
|
|
2014-01-25 22:53:50 +00:00
|
|
|
void Journal::addTopic (const std::string& topicId, const std::string& infoId, const std::string& actorName)
|
2011-04-26 18:48:36 +00:00
|
|
|
{
|
2013-12-03 13:28:46 +00:00
|
|
|
Topic& topic = getTopic (topicId);
|
2011-04-26 18:48:36 +00:00
|
|
|
|
2014-01-25 22:53:50 +00:00
|
|
|
JournalEntry entry(topicId, infoId);
|
|
|
|
entry.mActorName = actorName;
|
|
|
|
topic.addEntry (entry);
|
2011-04-26 18:48:36 +00:00
|
|
|
}
|
|
|
|
|
2011-04-04 09:23:15 +00:00
|
|
|
int Journal::getJournalIndex (const std::string& id) const
|
|
|
|
{
|
2012-03-18 18:05:35 +00:00
|
|
|
TQuestContainer::const_iterator iter = mQuests.find (id);
|
|
|
|
|
|
|
|
if (iter==mQuests.end())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return iter->second.getIndex();
|
2011-04-04 09:23:15 +00:00
|
|
|
}
|
2011-04-19 09:02:22 +00:00
|
|
|
|
|
|
|
Journal::TEntryIter Journal::begin() const
|
|
|
|
{
|
|
|
|
return mJournal.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
Journal::TEntryIter Journal::end() const
|
|
|
|
{
|
|
|
|
return mJournal.end();
|
|
|
|
}
|
2011-04-26 18:08:37 +00:00
|
|
|
|
|
|
|
Journal::TQuestIter Journal::questBegin() const
|
|
|
|
{
|
|
|
|
return mQuests.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
Journal::TQuestIter Journal::questEnd() const
|
|
|
|
{
|
|
|
|
return mQuests.end();
|
|
|
|
}
|
2011-04-26 18:48:36 +00:00
|
|
|
|
|
|
|
Journal::TTopicIter Journal::topicBegin() const
|
|
|
|
{
|
|
|
|
return mTopics.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
Journal::TTopicIter Journal::topicEnd() const
|
|
|
|
{
|
|
|
|
return mTopics.end();
|
|
|
|
}
|
2013-12-03 13:28:46 +00:00
|
|
|
|
|
|
|
int Journal::countSavedGameRecords() const
|
|
|
|
{
|
|
|
|
int count = static_cast<int> (mQuests.size());
|
|
|
|
|
|
|
|
for (TQuestIter iter (mQuests.begin()); iter!=mQuests.end(); ++iter)
|
|
|
|
count += std::distance (iter->second.begin(), iter->second.end());
|
|
|
|
|
|
|
|
count += std::distance (mJournal.begin(), mJournal.end());
|
|
|
|
|
|
|
|
for (TTopicIter iter (mTopics.begin()); iter!=mTopics.end(); ++iter)
|
|
|
|
count += std::distance (iter->second.begin(), iter->second.end());
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-04-28 09:29:57 +00:00
|
|
|
void Journal::write (ESM::ESMWriter& writer, Loading::Listener& progress) const
|
2013-12-03 13:28:46 +00:00
|
|
|
{
|
|
|
|
for (TQuestIter iter (mQuests.begin()); iter!=mQuests.end(); ++iter)
|
|
|
|
{
|
|
|
|
const Quest& quest = iter->second;
|
|
|
|
|
|
|
|
ESM::QuestState state;
|
|
|
|
quest.write (state);
|
|
|
|
writer.startRecord (ESM::REC_QUES);
|
|
|
|
state.save (writer);
|
|
|
|
writer.endRecord (ESM::REC_QUES);
|
2014-04-28 09:29:57 +00:00
|
|
|
progress.increaseProgress();
|
2013-12-03 13:28:46 +00:00
|
|
|
|
|
|
|
for (Topic::TEntryIter iter (quest.begin()); iter!=quest.end(); ++iter)
|
|
|
|
{
|
|
|
|
ESM::JournalEntry entry;
|
|
|
|
entry.mType = ESM::JournalEntry::Type_Quest;
|
|
|
|
entry.mTopic = quest.getTopic();
|
|
|
|
iter->write (entry);
|
|
|
|
writer.startRecord (ESM::REC_JOUR);
|
|
|
|
entry.save (writer);
|
|
|
|
writer.endRecord (ESM::REC_JOUR);
|
2014-04-28 09:29:57 +00:00
|
|
|
progress.increaseProgress();
|
2013-12-03 13:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (TEntryIter iter (mJournal.begin()); iter!=mJournal.end(); ++iter)
|
|
|
|
{
|
|
|
|
ESM::JournalEntry entry;
|
|
|
|
entry.mType = ESM::JournalEntry::Type_Journal;
|
|
|
|
iter->write (entry);
|
|
|
|
writer.startRecord (ESM::REC_JOUR);
|
|
|
|
entry.save (writer);
|
|
|
|
writer.endRecord (ESM::REC_JOUR);
|
2014-04-28 09:29:57 +00:00
|
|
|
progress.increaseProgress();
|
2013-12-03 13:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (TTopicIter iter (mTopics.begin()); iter!=mTopics.end(); ++iter)
|
|
|
|
{
|
|
|
|
const Topic& topic = iter->second;
|
|
|
|
|
|
|
|
for (Topic::TEntryIter iter (topic.begin()); iter!=topic.end(); ++iter)
|
|
|
|
{
|
|
|
|
ESM::JournalEntry entry;
|
|
|
|
entry.mType = ESM::JournalEntry::Type_Topic;
|
|
|
|
entry.mTopic = topic.getTopic();
|
|
|
|
iter->write (entry);
|
|
|
|
writer.startRecord (ESM::REC_JOUR);
|
|
|
|
entry.save (writer);
|
|
|
|
writer.endRecord (ESM::REC_JOUR);
|
2014-04-28 09:29:57 +00:00
|
|
|
progress.increaseProgress();
|
2013-12-03 13:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Journal::readRecord (ESM::ESMReader& reader, int32_t type)
|
|
|
|
{
|
|
|
|
if (type==ESM::REC_JOUR)
|
|
|
|
{
|
|
|
|
ESM::JournalEntry record;
|
|
|
|
record.load (reader);
|
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
if (isThere (record.mTopic, record.mInfo))
|
|
|
|
switch (record.mType)
|
|
|
|
{
|
|
|
|
case ESM::JournalEntry::Type_Quest:
|
2013-12-03 13:28:46 +00:00
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
getQuest (record.mTopic).insertEntry (record);
|
|
|
|
break;
|
2013-12-03 13:28:46 +00:00
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
case ESM::JournalEntry::Type_Journal:
|
2013-12-03 13:28:46 +00:00
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
mJournal.push_back (record);
|
|
|
|
break;
|
2013-12-03 13:28:46 +00:00
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
case ESM::JournalEntry::Type_Topic:
|
2013-12-03 13:28:46 +00:00
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
getTopic (record.mTopic).insertEntry (record);
|
|
|
|
break;
|
|
|
|
}
|
2013-12-03 13:28:46 +00:00
|
|
|
}
|
|
|
|
else if (type==ESM::REC_QUES)
|
|
|
|
{
|
|
|
|
ESM::QuestState record;
|
|
|
|
record.load (reader);
|
|
|
|
|
2013-12-03 13:39:54 +00:00
|
|
|
if (isThere (record.mTopic))
|
|
|
|
mQuests.insert (std::make_pair (record.mTopic, record));
|
2013-12-03 13:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-04 09:16:56 +00:00
|
|
|
}
|