From 7a1b215b6abdf00d36d5bba9341a9c0b9ac7a6e5 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 26 Apr 2011 20:39:59 +0200 Subject: [PATCH] splitting of topic class from quest class --- apps/openmw/CMakeLists.txt | 2 ++ apps/openmw/mwdialogue/quest.cpp | 19 ++---------- apps/openmw/mwdialogue/quest.hpp | 31 ++----------------- apps/openmw/mwdialogue/topic.cpp | 46 ++++++++++++++++++++++++++++ apps/openmw/mwdialogue/topic.hpp | 52 ++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 45 deletions(-) create mode 100644 apps/openmw/mwdialogue/topic.cpp create mode 100644 apps/openmw/mwdialogue/topic.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8fa6d6591..3145082ed 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -73,12 +73,14 @@ set(GAMEDIALOGUE_HEADER mwdialogue/journal.hpp mwdialogue/journalentry.hpp mwdialogue/quest.hpp + mwdialogue/topic.hpp ) set(GAMEDIALOGUE mwdialogue/dialoguemanager.cpp mwdialogue/journal.cpp mwdialogue/journalentry.cpp mwdialogue/quest.cpp + mwdialogue/topic.cpp ) source_group(apps\\openmw\\mwdialogue FILES ${GAMEDIALOGUE_HEADER} ${GAMEDIALOGUE}) diff --git a/apps/openmw/mwdialogue/quest.cpp b/apps/openmw/mwdialogue/quest.cpp index d47c78c6e..1f387e862 100644 --- a/apps/openmw/mwdialogue/quest.cpp +++ b/apps/openmw/mwdialogue/quest.cpp @@ -8,11 +8,11 @@ namespace MWDialogue { Quest::Quest() - : mIndex (0), mFinished (false) + : Topic(), mIndex (0), mFinished (false) {} Quest::Quest (const std::string& topic) - : mTopic (topic), mIndex (0), mFinished (false) + : Topic (topic), mIndex (0), mFinished (false) {} const std::string Quest::getName (const MWWorld::World& world) const @@ -83,19 +83,4 @@ namespace MWDialogue mEntries.push_back (entry.mInfoId); } - - Quest::TEntryIter Quest::begin() - { - return mEntries.begin(); - } - - Quest::TEntryIter Quest::end() - { - return mEntries.end(); - } - - JournalEntry Quest::getEntry (const std::string& infoId) - { - return JournalEntry (mTopic, infoId); - } } diff --git a/apps/openmw/mwdialogue/quest.hpp b/apps/openmw/mwdialogue/quest.hpp index 9f173f6d3..c162c03f4 100644 --- a/apps/openmw/mwdialogue/quest.hpp +++ b/apps/openmw/mwdialogue/quest.hpp @@ -1,31 +1,14 @@ #ifndef GAME_MMDIALOG_QUEST_H #define GAME_MWDIALOG_QUEST_H -#include -#include - -#include "journalentry.hpp" - -namespace MWWorld -{ - class World; -} +#include "topic.hpp" namespace MWDialogue { /// \brief A quest in progress or a compelted quest - class Quest + class Quest : public Topic { - public: - - typedef std::vector TEntryContainer; - typedef TEntryContainer::const_iterator TEntryIter; - - private: - - std::string mTopic; int mIndex; - TEntryContainer mEntries; // info-IDs bool mFinished; public: @@ -44,18 +27,10 @@ namespace MWDialogue bool isFinished() const; - void addEntry (const JournalEntry& entry, const MWWorld::World& world); + virtual void addEntry (const JournalEntry& entry, const MWWorld::World& world); ///< Add entry and adjust index accordingly. /// /// \note Redundant entries are ignored, but the index is still adjusted. - - TEntryIter begin(); - ///< Iterator pointing to the begin of the journal for this quest. - - TEntryIter end(); - ///< Iterator pointing past the end of the journal for this quest. - - JournalEntry getEntry (const std::string& infoId); }; } diff --git a/apps/openmw/mwdialogue/topic.cpp b/apps/openmw/mwdialogue/topic.cpp new file mode 100644 index 000000000..8f165d3c8 --- /dev/null +++ b/apps/openmw/mwdialogue/topic.cpp @@ -0,0 +1,46 @@ + +#include "topic.hpp" + +#include + +#include "../mwworld/world.hpp" + +namespace MWDialogue +{ + Topic::Topic() + {} + + Topic::Topic (const std::string& topic) + : mTopic (topic) + {} + + Topic::~Topic() + {} + + void Topic::addEntry (const JournalEntry& entry, const MWWorld::World& world) + { + if (entry.mTopic!=mTopic) + throw std::runtime_error ("topic does not match: " + mTopic); + + for (TEntryIter iter = begin(); iter!=end(); ++iter) + if (*iter==entry.mInfoId) + return; + + mEntries.push_back (entry.mInfoId); + } + + Topic::TEntryIter Topic::begin() + { + return mEntries.begin(); + } + + Topic::TEntryIter Topic::end() + { + return mEntries.end(); + } + + JournalEntry Topic::getEntry (const std::string& infoId) + { + return JournalEntry (mTopic, infoId); + } +} diff --git a/apps/openmw/mwdialogue/topic.hpp b/apps/openmw/mwdialogue/topic.hpp new file mode 100644 index 000000000..c085f1ed9 --- /dev/null +++ b/apps/openmw/mwdialogue/topic.hpp @@ -0,0 +1,52 @@ +#ifndef GAME_MMDIALOG_TOPIC_H +#define GAME_MWDIALOG_TOPIC_H + +#include +#include + +#include "journalentry.hpp" + +namespace MWWorld +{ + class World; +} + +namespace MWDialogue +{ + /// \brief Collection of seen responses for a topic + class Topic + { + public: + + typedef std::vector TEntryContainer; + typedef TEntryContainer::const_iterator TEntryIter; + + protected: + + std::string mTopic; + TEntryContainer mEntries; // info-IDs + + public: + + Topic(); + + Topic (const std::string& topic); + + virtual ~Topic(); + + virtual void addEntry (const JournalEntry& entry, const MWWorld::World& world); + ///< Add entry + /// + /// \note Redundant entries are ignored. + + TEntryIter begin(); + ///< Iterator pointing to the begin of the journal for this topic. + + TEntryIter end(); + ///< Iterator pointing past the end of the journal for this topic. + + JournalEntry getEntry (const std::string& infoId); + }; +} + +#endif