From 65e43c448a9a31bfdbcc5d7aa5ef6c2da28f2515 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 22 Apr 2011 11:16:39 +0200 Subject: [PATCH] splitted StampedJournalEntry class off from JournalEntry --- apps/openmw/mwdialogue/journal.cpp | 2 +- apps/openmw/mwdialogue/journal.hpp | 4 ++-- apps/openmw/mwdialogue/journalentry.cpp | 32 +++++++++++++++++++++---- apps/openmw/mwdialogue/journalentry.hpp | 23 +++++++++++++++--- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwdialogue/journal.cpp b/apps/openmw/mwdialogue/journal.cpp index 8f84edabc..570d32d36 100644 --- a/apps/openmw/mwdialogue/journal.cpp +++ b/apps/openmw/mwdialogue/journal.cpp @@ -12,7 +12,7 @@ namespace MWDialogue void Journal::addEntry (const std::string& id, int index) { - mJournal.push_back (JournalEntry::makeFromQuest (id, index, *mEnvironment.mWorld)); + mJournal.push_back (StampedJournalEntry::makeFromQuest (id, index, *mEnvironment.mWorld)); std::cout << "journal: " << id << " at " << index << std::endl; } diff --git a/apps/openmw/mwdialogue/journal.hpp b/apps/openmw/mwdialogue/journal.hpp index 07090ef4a..6b2b12cac 100644 --- a/apps/openmw/mwdialogue/journal.hpp +++ b/apps/openmw/mwdialogue/journal.hpp @@ -17,13 +17,13 @@ namespace MWDialogue { public: - typedef std::deque TEntryContainer; + typedef std::deque TEntryContainer; typedef TEntryContainer::const_iterator TEntryIter; private: MWWorld::Environment& mEnvironment; - std::deque mJournal; + TEntryContainer mJournal; public: diff --git a/apps/openmw/mwdialogue/journalentry.cpp b/apps/openmw/mwdialogue/journalentry.cpp index 6cfee7cf4..5e9dfa674 100644 --- a/apps/openmw/mwdialogue/journalentry.cpp +++ b/apps/openmw/mwdialogue/journalentry.cpp @@ -11,8 +11,8 @@ namespace MWDialogue { JournalEntry::JournalEntry() {} - JournalEntry::JournalEntry (int day, const std::string& topic, const std::string& infoId) - : mDay (day), mTopic (topic), mInfoId (infoId) + JournalEntry::JournalEntry (const std::string& topic, const std::string& infoId) + : mTopic (topic), mInfoId (infoId) {} std::string JournalEntry::getText (const ESMS::ESMStore& store) const @@ -29,6 +29,12 @@ namespace MWDialogue JournalEntry JournalEntry::makeFromQuest (const std::string& topic, int index, const MWWorld::World& world) + { + return JournalEntry (topic, idFromIndex (topic, index, world)); + } + + std::string JournalEntry::idFromIndex (const std::string& topic, int index, + const MWWorld::World& world) { const ESM::Dialogue *dialogue = world.getStore().dialogs.find (topic); @@ -36,10 +42,28 @@ namespace MWDialogue iter!=dialogue->mInfo.end(); ++iter) if (iter->data.disposition==index) /// \todo cleanup info structure { - int day = world.getGlobalVariable ("dayspassed").mLong; - return JournalEntry (day, topic, iter->id); + iter->id; } throw std::runtime_error ("unknown journal index for topic " + topic); } + + 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); + } } diff --git a/apps/openmw/mwdialogue/journalentry.hpp b/apps/openmw/mwdialogue/journalentry.hpp index f19e9c52c..058843008 100644 --- a/apps/openmw/mwdialogue/journalentry.hpp +++ b/apps/openmw/mwdialogue/journalentry.hpp @@ -15,23 +15,40 @@ namespace MWWorld namespace MWDialogue { - /// \brief a quest or dialogue entry with a timestamp + /// \brief A quest or dialogue entry struct JournalEntry { - int mDay; std::string mTopic; std::string mInfoId; JournalEntry(); - JournalEntry (int day, const std::string& topic, const std::string& infoId); + JournalEntry (const std::string& topic, const std::string& infoId); std::string getText (const ESMS::ESMStore& store) const; static JournalEntry makeFromQuest (const std::string& topic, int index, const MWWorld::World& world); + + static std::string idFromIndex (const std::string& topic, int index, + const MWWorld::World& world); }; + /// \biref A quest entry with a timestamp. + struct StampedJournalEntry : public JournalEntry + { + int mDay; + int mMonth; + int mDayOfMonth; + + StampedJournalEntry(); + + StampedJournalEntry (const std::string& topic, const std::string& infoId, + int day, int month, int dayOfMonth); + + static StampedJournalEntry makeFromQuest (const std::string& topic, int index, + const MWWorld::World& world); + }; } #endif