QuestWeaver
A procedural quest generator
weave::QuestTemplate Class Referenceabstract

Defines a blueprint from which a specific type of quest can be generated. More...

#include <QuestTemplate.h>

Public Member Functions

 QuestTemplate (std::string title, std::vector< TemplateQuestProperty > properties, std::vector< TemplateQuestDescription > descriptions, FormatterType formatterType, int rarity=0)
 Creates a new quest template. More...
 
virtual ~QuestTemplate ()=default
 
std::vector< TemplateQuestProperty > GetProperties () const noexcept
 Returns a list of all the template parts that (mandatory) must be filled and (optional) can be filled with world entities. More...
 
virtual std::vector< PropertyCandidateGetPropertyCandidates (const TemplateQuestProperty &property, const WorldModel &worldModel) const =0
 This method creates a list of possible candidates for a given template property. More...
 
int GetRarity () const noexcept
 
virtual bool HasPriority () const noexcept
 
virtual bool IsValid (const WorldModel &worldModel, const QuestModel &questModel) const noexcept
 
virtual std::shared_ptr< QuestToQuest (const std::vector< QuestPropertyValue > &questPropertyValues, const std::string &questStory) const =0
 Creates a new quest based on this template and the given parameters. More...
 
std::shared_ptr< QuestToQuest (const std::vector< QuestPropertyValue > &questPropertyValues) const
 Creates a new quest based on this template and the given parameters. More...
 

Protected Member Functions

std::string getBestFittingDescription (const std::vector< QuestPropertyValue > &questPropertyValues) const
 Returns the first description that supports all of the given property values. More...
 
std::string getTitle (const std::vector< QuestPropertyValue > &questPropertyValues) const noexcept
 Returns the quest title and uses the given property values to replace any placeholders. More...
 
virtual std::map< std::string, std::string > resolveAdditionalPlaceholders (QuestPropertyValue questPropertyValue) const noexcept
 

Static Protected Member Functions

static ID getEntityIdFromProperty (std::string propertyName, const std::vector< QuestPropertyValue > &questPropertyValues) noexcept
 Returns the ID of the entitiy referenced by the property with the given name or returns 0 if no property with such a name can be found. More...
 

Protected Attributes

FormatterType formatterType
 

Detailed Description

Defines a blueprint from which a specific type of quest can be generated.

Each template contains the information necessary to create variations of a specific quest.

The template data itself is kept in JSON format in a file and loaded via the QuestTemplateFactory.

Example

A template might define the variables and entities necessary to create a "fetch" quest. Some of these entities might be optional, e.g. who gave the player the quest. Some of them are mandatory, e.g. what the player has to fetch.

A quest generated from such a template might be "Get the king's crown from the dragon" or "fetch 10 eggs to make breakfast", depending on the entities the world model creates.

Definition at line 82 of file QuestTemplate.h.

Constructor & Destructor Documentation

weave::QuestTemplate::QuestTemplate ( std::string  title,
std::vector< TemplateQuestProperty >  properties,
std::vector< TemplateQuestDescription descriptions,
FormatterType  formatterType,
int  rarity = 0 
)

Creates a new quest template.

Parameters
titleThe quest title (can contain placeholders for mandatory properties).
propertiesThe properties used by the quest system to select world entities for the quest. The names of these properties will also be used when substituting the placeholders in the title and description texts.
descriptionsThe possible description texts. One of these descriptions will be used to create the quest description, depending on the optional properties used by the quest system.
formatterTypeThe format used when creating the texts for a new quest.
virtual weave::QuestTemplate::~QuestTemplate ( )
virtualdefault

Member Function Documentation

std::string weave::QuestTemplate::getBestFittingDescription ( const std::vector< QuestPropertyValue > &  questPropertyValues) const
protected

Returns the first description that supports all of the given property values.

static ID weave::QuestTemplate::getEntityIdFromProperty ( std::string  propertyName,
const std::vector< QuestPropertyValue > &  questPropertyValues 
)
staticprotectednoexcept

Returns the ID of the entitiy referenced by the property with the given name or returns 0 if no property with such a name can be found.

std::vector<TemplateQuestProperty> weave::QuestTemplate::GetProperties ( ) const
noexcept

Returns a list of all the template parts that (mandatory) must be filled and (optional) can be filled with world entities.

Which entities can be used to fill a certain TemplateQuestProperty is determined by the template itself, by the GetPropertyCandidates() method.

virtual std::vector<PropertyCandidate> weave::QuestTemplate::GetPropertyCandidates ( const TemplateQuestProperty &  property,
const WorldModel worldModel 
) const
pure virtual

This method creates a list of possible candidates for a given template property.

Subclasses implementing this method may search the world model for fitting entities or they may use the world model to create new entities.

For every candidate, the template may add some metadata (e.g. relationship changes caused by the quest or markers to not choose the entity for another quest). If a candidate is chosen from the list, the corresponding WorldModelActions are executed in the world model.

int weave::QuestTemplate::GetRarity ( ) const
noexcept
std::string weave::QuestTemplate::getTitle ( const std::vector< QuestPropertyValue > &  questPropertyValues) const
protectednoexcept

Returns the quest title and uses the given property values to replace any placeholders.

virtual bool weave::QuestTemplate::HasPriority ( ) const
virtualnoexcept
virtual bool weave::QuestTemplate::IsValid ( const WorldModel worldModel,
const QuestModel &  questModel 
) const
virtualnoexcept
virtual std::map<std::string, std::string> weave::QuestTemplate::resolveAdditionalPlaceholders ( QuestPropertyValue  questPropertyValue) const
protectedvirtualnoexcept
virtual std::shared_ptr<Quest> weave::QuestTemplate::ToQuest ( const std::vector< QuestPropertyValue > &  questPropertyValues,
const std::string &  questStory 
) const
pure virtual

Creates a new quest based on this template and the given parameters.

Parameters
questPropertyValuesthe values for the template's mandatory and optional properties.
questStorythe quest's background story.
std::shared_ptr<Quest> weave::QuestTemplate::ToQuest ( const std::vector< QuestPropertyValue > &  questPropertyValues) const

Creates a new quest based on this template and the given parameters.

The resulting quest has no background story.

Parameters
questPropertyValuesthe values for the template's mandatory and optional properties.

Member Data Documentation

FormatterType weave::QuestTemplate::formatterType
protected

Definition at line 167 of file QuestTemplate.h.


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