mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
added quest tracking to the journal
This commit is contained in:
parent
65e43c448a
commit
944291d34f
6 changed files with 209 additions and 5 deletions
|
@ -72,11 +72,13 @@ set(GAMEDIALOGUE_HEADER
|
||||||
mwdialogue/dialoguemanager.hpp
|
mwdialogue/dialoguemanager.hpp
|
||||||
mwdialogue/journal.hpp
|
mwdialogue/journal.hpp
|
||||||
mwdialogue/journalentry.hpp
|
mwdialogue/journalentry.hpp
|
||||||
|
mwdialogue/quest.hpp
|
||||||
)
|
)
|
||||||
set(GAMEDIALOGUE
|
set(GAMEDIALOGUE
|
||||||
mwdialogue/dialoguemanager.cpp
|
mwdialogue/dialoguemanager.cpp
|
||||||
mwdialogue/journal.cpp
|
mwdialogue/journal.cpp
|
||||||
mwdialogue/journalentry.cpp
|
mwdialogue/journalentry.cpp
|
||||||
|
mwdialogue/quest.cpp
|
||||||
)
|
)
|
||||||
source_group(apps\\openmw\\mwdialogue FILES ${GAMEDIALOGUE_HEADER} ${GAMEDIALOGUE})
|
source_group(apps\\openmw\\mwdialogue FILES ${GAMEDIALOGUE_HEADER} ${GAMEDIALOGUE})
|
||||||
|
|
||||||
|
|
|
@ -3,22 +3,44 @@
|
||||||
|
|
||||||
#include "../mwworld/environment.hpp"
|
#include "../mwworld/environment.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
namespace MWDialogue
|
namespace MWDialogue
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
Journal::Journal (MWWorld::Environment& environment)
|
Journal::Journal (MWWorld::Environment& environment)
|
||||||
: mEnvironment (environment)
|
: mEnvironment (environment)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void Journal::addEntry (const std::string& id, int index)
|
void Journal::addEntry (const std::string& id, int index)
|
||||||
{
|
{
|
||||||
mJournal.push_back (StampedJournalEntry::makeFromQuest (id, index, *mEnvironment.mWorld));
|
StampedJournalEntry entry =
|
||||||
std::cout << "journal: " << id << " at " << index << std::endl;
|
StampedJournalEntry::makeFromQuest (id, index, *mEnvironment.mWorld);
|
||||||
|
|
||||||
|
mJournal.push_back (entry);
|
||||||
|
|
||||||
|
Quest& quest = getQuest (id);
|
||||||
|
|
||||||
|
quest.addEntry (entry, *mEnvironment.mWorld); // we are doing slicing on purpose here
|
||||||
}
|
}
|
||||||
|
|
||||||
void Journal::setJournalIndex (const std::string& id, int index)
|
void Journal::setJournalIndex (const std::string& id, int index)
|
||||||
{
|
{
|
||||||
std::cout << "journal (no entry): " << id << " at " << index << std::endl;
|
Quest& quest = getQuest (id);
|
||||||
|
|
||||||
|
quest.setIndex (index, *mEnvironment.mWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Journal::getJournalIndex (const std::string& id) const
|
int Journal::getJournalIndex (const std::string& id) const
|
||||||
|
@ -35,4 +57,14 @@ namespace MWDialogue
|
||||||
{
|
{
|
||||||
return mJournal.end();
|
return mJournal.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Journal::TQuestIter Journal::questBegin() const
|
||||||
|
{
|
||||||
|
return mQuests.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
Journal::TQuestIter Journal::questEnd() const
|
||||||
|
{
|
||||||
|
return mQuests.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "journalentry.hpp"
|
#include "journalentry.hpp"
|
||||||
|
#include "quest.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
|
@ -13,17 +15,23 @@ namespace MWWorld
|
||||||
|
|
||||||
namespace MWDialogue
|
namespace MWDialogue
|
||||||
{
|
{
|
||||||
|
/// \brief The player's journal
|
||||||
class Journal
|
class Journal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef std::deque<StampedJournalEntry> TEntryContainer;
|
typedef std::deque<StampedJournalEntry> TEntryContainer;
|
||||||
typedef TEntryContainer::const_iterator TEntryIter;
|
typedef TEntryContainer::const_iterator TEntryIter;
|
||||||
|
typedef std::map<std::string, Quest> TQuestContainer; // topc, quest
|
||||||
|
typedef TQuestContainer::const_iterator TQuestIter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
MWWorld::Environment& mEnvironment;
|
MWWorld::Environment& mEnvironment;
|
||||||
TEntryContainer mJournal;
|
TEntryContainer mJournal;
|
||||||
|
TQuestContainer mQuests;
|
||||||
|
|
||||||
|
Quest& getQuest (const std::string& id);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -45,6 +53,12 @@ namespace MWDialogue
|
||||||
|
|
||||||
TEntryIter end() const;
|
TEntryIter end() const;
|
||||||
///< Iterator pointing past the end of the main journal.
|
///< Iterator pointing past the end of the main journal.
|
||||||
|
|
||||||
|
TQuestIter questBegin() const;
|
||||||
|
///< Iterator pointing to the first quest (sorted by topic ID)
|
||||||
|
|
||||||
|
TQuestIter questEnd() const;
|
||||||
|
///< Iterator pointing past the last quest.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef GAME_MMDIALOGUE_JOURNALENTRY_H
|
#ifndef GAME_MMDIALOGUE_JOURNALENTRY_H
|
||||||
#define GAME_MWDIALOGUE_JOURNALENTRY_H
|
#define GAME_MMDIALOGUE_JOURNALENTRY_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
96
apps/openmw/mwdialogue/quest.cpp
Normal file
96
apps/openmw/mwdialogue/quest.cpp
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
60
apps/openmw/mwdialogue/quest.hpp
Normal file
60
apps/openmw/mwdialogue/quest.hpp
Normal file
|
@ -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
|
Loading…
Reference in a new issue