mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-04 08:15:33 +00:00
splitting of topic class from quest class
This commit is contained in:
parent
3406d2fa89
commit
7a1b215b6a
5 changed files with 105 additions and 45 deletions
|
@ -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})
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,14 @@
|
|||
#ifndef GAME_MMDIALOG_QUEST_H
|
||||
#define GAME_MWDIALOG_QUEST_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<std::string> 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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
46
apps/openmw/mwdialogue/topic.cpp
Normal file
46
apps/openmw/mwdialogue/topic.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
#include "topic.hpp"
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
52
apps/openmw/mwdialogue/topic.hpp
Normal file
52
apps/openmw/mwdialogue/topic.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef GAME_MMDIALOG_TOPIC_H
|
||||
#define GAME_MWDIALOG_TOPIC_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "journalentry.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace MWDialogue
|
||||
{
|
||||
/// \brief Collection of seen responses for a topic
|
||||
class Topic
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<std::string> 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
|
Loading…
Reference in a new issue