QuestWeaver
A procedural quest generator
weave::QuestWeaver Class Reference

Main entry point for applications using the quest system. More...

#include <QuestWeaver.h>

Public Member Functions

 QuestWeaver (WeaverConfig &config)
 Creates a new weaver instance with the given config. More...
 
bool ChangeQuestState (QuestModelAction questAction)
 Directly changes the state of a quest. More...
 
void ChangeWorkingDirectories (Directories directories)
 Changes the directories used by the quest system to load files such as templates. More...
 
std::vector< std::shared_ptr< Quest > > CreateNewQuests ()
 Creates at least one new quest. More...
 
std::vector< std::shared_ptr< Quest > > GetAllQuests () const
 Returns a list of all quests. More...
 
std::shared_ptr< QuestGetQuest (ID questId) const
 Returns the quest with the given ID. More...
 
std::vector< std::shared_ptr< Quest > > GetQuestsWithState (QuestState state) const
 Returns a list of all quests with the given state. More...
 
WorldModelGetWorldModel () const
 Returns a reference to the world model. More...
 
void RegisterQuestTemplateFactory (std::unique_ptr< QuestTemplateFactory > factory)
 Registers a new quest template factory with the quest system. More...
 
void RegisterStoryTemplateFactory (std::unique_ptr< StoryTemplateFactory > factory)
 Registers a new story template factory with the quest system. More...
 
void Serialize (std::ostream &outputStream, StreamType type)
 Serializes the whole quest system including the quest model and world model. More...
 
void Tick (float delta)
 Advances the quest system state by ticking all quests and executing their desired world and quest changes. More...
 

Static Public Member Functions

static QuestWeaver Deserialize (std::istream &inputStream, StreamType type)
 Deserializes the quest system including the quest model and world model. More...
 
static QuestWeaver Deserialize (std::istream &inputStream, StreamType type, Directories currentDirectories)
 Deserializes the quest system including the quest model and world model. More...
 

Detailed Description

Main entry point for applications using the quest system.

This class represents a complete quest system and is the main entry point for an application to create and manage quests. To be usable, the caller has to provide a world model and matching template factories from which the quest weaver will generate new and interesting quest.

Instances of this class are not thread safe.

See also
WeaverConfig

Definition at line 40 of file QuestWeaver.h.

Constructor & Destructor Documentation

weave::QuestWeaver::QuestWeaver ( WeaverConfig config)
explicit

Creates a new weaver instance with the given config.

The config needs to contain a valid world model or else an exception is thrown.

Parameters
configthe config to use - must contain a valid world model

Member Function Documentation

bool weave::QuestWeaver::ChangeQuestState ( QuestModelAction  questAction)

Directly changes the state of a quest.

A quest itself can change its state once it is ticked, which should be the preferred method.

Returns
true if the action was completed, false if the state change was not permitted.
void weave::QuestWeaver::ChangeWorkingDirectories ( Directories  directories)

Changes the directories used by the quest system to load files such as templates.

std::vector<std::shared_ptr<Quest> > weave::QuestWeaver::CreateNewQuests ( )

Creates at least one new quest.

This node does not have any input because it is the responsibility of the quest weaver to decide which quest should be created next. The previously registered template factories and the world model are used to create the quest.

Once a quest is created, it is active in the world (and most likely already started to change it). The caller of this API cannot decide to undo that or delete the quest, it can only change the state to a "completed" type.

static QuestWeaver weave::QuestWeaver::Deserialize ( std::istream &  inputStream,
StreamType  type 
)
static

Deserializes the quest system including the quest model and world model.

Please note that the template factories and the world model listeners must be registered again as they are not serialized. In addition, the current working directory info must be updated or the default is used.

The StreamType parameter must be the same as the one used to serialize the data.

static QuestWeaver weave::QuestWeaver::Deserialize ( std::istream &  inputStream,
StreamType  type,
Directories  currentDirectories 
)
static

Deserializes the quest system including the quest model and world model.

Please note that the template factories and the world model listeners must be registered again as they are not serialized.

The StreamType parameter must be the same as the one used to serialize the data.

std::vector<std::shared_ptr<Quest> > weave::QuestWeaver::GetAllQuests ( ) const

Returns a list of all quests.

std::shared_ptr<Quest> weave::QuestWeaver::GetQuest ( ID  questId) const

Returns the quest with the given ID.

std::vector<std::shared_ptr<Quest> > weave::QuestWeaver::GetQuestsWithState ( QuestState  state) const

Returns a list of all quests with the given state.

WorldModel& weave::QuestWeaver::GetWorldModel ( ) const

Returns a reference to the world model.

To change the world model, you should consider to use the Tick() method which gathers changes from the quests.

After the quest system was deserialized, the world model listener has to be registered again.

void weave::QuestWeaver::RegisterQuestTemplateFactory ( std::unique_ptr< QuestTemplateFactory factory)

Registers a new quest template factory with the quest system.

Usually, the factories are already registered when creating an instance using the WeaverConfig parameter. However, this is not true when creating a new instance by deserialization. This method MUST be used on newly deserialized objects, otherwise it is impossible to create new quests

void weave::QuestWeaver::RegisterStoryTemplateFactory ( std::unique_ptr< StoryTemplateFactory factory)

Registers a new story template factory with the quest system.

Usually, the factories are already registered when creating an instance using the WeaverConfig parameter. However, this is not true when creating a new instance by deserialization. This method MUST be used on newly deserialized objects, otherwise new quests will be created without backstories.

void weave::QuestWeaver::Serialize ( std::ostream &  outputStream,
StreamType  type 
)

Serializes the whole quest system including the quest model and world model.

Please note that upon deserialization, the template factories and the world model listeners must be registered again as they are not serialized. The data is serialized in a portable way, so no extra steps must be taken to serialize and deserialize on different platforms.

void weave::QuestWeaver::Tick ( float  delta)

Advances the quest system state by ticking all quests and executing their desired world and quest changes.

Until this method is called, quests are unable to directly change the world model or their quest state.

Parameters
deltaThe time elapsed since the last tick.

The documentation for this class was generated from the following file: