forked from zinnschlag/openmw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65e43c4
commit 944291d
Showing
6 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
#include "quest.hpp" | ||
|
||
#include <components/esm_store/store.hpp> | ||
|
||
#include "../mwworld/world.hpp" | ||
|
||
namespace MWDialogue | ||
{ | ||
Quest::Quest() | ||
: mIndex (0), mFinished (false) | ||
{} | ||
|
||
Quest::Quest (const std::string& topic) | ||
: mTopic (topic), mIndex (0), mFinished (false) | ||
{} | ||
|
||
const std::string Quest::getName (const MWWorld::World& world) const | ||
{ | ||
const ESM::Dialogue *dialogue = world.getStore().dialogs.find (mTopic); | ||
|
||
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin()); | ||
iter!=dialogue->mInfo.end(); ++iter) | ||
if (iter->questStatus==ESM::DialInfo::QS_Name) | ||
return iter->response; | ||
|
||
return ""; | ||
} | ||
|
||
int Quest::getIndex() const | ||
{ | ||
return mIndex; | ||
} | ||
|
||
void Quest::setIndex (int index, const MWWorld::World& world) | ||
{ | ||
const ESM::Dialogue *dialogue = world.getStore().dialogs.find (mTopic); | ||
|
||
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin()); | ||
iter!=dialogue->mInfo.end(); ++iter) | ||
if (iter->data.disposition==index && iter->questStatus!=ESM::DialInfo::QS_Name) | ||
{ | ||
mIndex = index; | ||
|
||
if (iter->questStatus==ESM::DialInfo::QS_Finished) | ||
mFinished = true; | ||
else if (iter->questStatus==ESM::DialInfo::QS_Restart) | ||
mFinished = false; | ||
|
||
return; | ||
} | ||
|
||
throw std::runtime_error ("unknown journal index for topic " + mTopic); | ||
} | ||
|
||
bool Quest::isFinished() const | ||
{ | ||
return mFinished; | ||
} | ||
|
||
void Quest::addEntry (const JournalEntry& entry, const MWWorld::World& world) | ||
{ | ||
int index = -1; | ||
|
||
const ESM::Dialogue *dialogue = world.getStore().dialogs.find (entry.mTopic); | ||
|
||
for (std::vector<ESM::DialInfo>::const_iterator iter (dialogue->mInfo.begin()); | ||
iter!=dialogue->mInfo.end(); ++iter) | ||
if (iter->id==entry.mInfoId) | ||
{ | ||
index = iter->data.disposition; /// \todo cleanup info structure | ||
break; | ||
} | ||
|
||
if (index==-1) | ||
throw std::runtime_error ("unknown journal entry for topic " + mTopic); | ||
|
||
setIndex (index, world); | ||
|
||
for (TEntryIter iter (mEntries.begin()); iter!=mEntries.end(); ++iter) | ||
if (iter->mInfoId==entry.mInfoId) | ||
return; | ||
|
||
mEntries.push_back (entry); | ||
} | ||
|
||
Quest::TEntryIter Quest::begin() | ||
{ | ||
return mEntries.begin(); | ||
} | ||
|
||
Quest::TEntryIter Quest::end() | ||
{ | ||
return mEntries.end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef GAME_MMDIALOG_QUEST_H | ||
#define GAME_MWDIALOG_QUEST_H | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "journalentry.hpp" | ||
|
||
namespace MWWorld | ||
{ | ||
class World; | ||
} | ||
|
||
namespace MWDialogue | ||
{ | ||
/// \brief A quest in progress or a compelted quest | ||
class Quest | ||
{ | ||
public: | ||
|
||
typedef std::vector<JournalEntry> TEntryContainer; | ||
typedef TEntryContainer::const_iterator TEntryIter; | ||
|
||
private: | ||
|
||
std::string mTopic; | ||
int mIndex; | ||
std::vector<JournalEntry> mEntries; | ||
bool mFinished; | ||
|
||
public: | ||
|
||
Quest(); | ||
|
||
Quest (const std::string& topic); | ||
|
||
const std::string getName (const MWWorld::World& world) const; | ||
///< May be an empty string | ||
|
||
int getIndex() const; | ||
|
||
void setIndex (int index, const MWWorld::World& world); | ||
///< Calling this function with a non-existant index while throw an exception. | ||
|
||
bool isFinished() const; | ||
|
||
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. | ||
}; | ||
} | ||
|
||
#endif |