QuestWeaver
A procedural quest generator
weave::WorldModel Class Referenceabstract

Holds information about all entities relevant for quests and quest generation. More...

#include <WorldModel.h>

Public Member Functions

 WorldModel () noexcept
 Creates a new empty world model. More...
 
virtual ~WorldModel ()=default
 
void AddListener (std::shared_ptr< WorldListener > listener) const noexcept
 Adds a listener to the world model. More...
 
void Execute (std::vector< WorldModelAction > modelActions)
 Commits the given changes to the world model and informs the attached WorldLister. More...
 
std::vector< std::shared_ptr< WorldEntity > > GetEntities () const noexcept
 Returns a list of all entities known to this world model. More...
 
std::vector< std::shared_ptr< WorldEntity > > GetEntitiesWithType (std::string type) const noexcept
 Returns all entities with a given type. More...
 
std::shared_ptr< WorldEntityGetEntityById (ID id) const noexcept
 Returns the entity for a given ID, or a nullptr if no such entity is known. More...
 
std::vector< WorldModelActionGetHistory () const noexcept
 Returns the action history of all actions executed by this world model. More...
 
MetaData GetMetaData (ID entityId) const noexcept
 Returns the metadata for the entity with the given ID. More...
 
std::vector< WorldModelActionGetMetaDataHistoryForId (ID id) const noexcept
 Returns a list of all actions that changed the metadata of the entity with the given ID. More...
 
virtual const NameGeneratorGetNameGenerator () const =0
 The name generator used to create the names of world entities and story elements. More...
 

Protected Attributes

std::shared_ptr< RandomStreamrs
 The random stream can be used by subclasses to create randomized entities. More...
 

Detailed Description

Holds information about all entities relevant for quests and quest generation.

The WorldModel is provided by the caller of the API, so it can create game-specific quest entities (e.g cowboys for a wild-west game and aliens for a sci-fi game).

WorldEntity instances are immutable and stateless, so the world model also manages the entities MetaData. In addition, the world model keeps track of all changes ever made to any entities or meta data to create richer quests and back-stories.

Definition at line 28 of file WorldModel.h.

Constructor & Destructor Documentation

weave::WorldModel::WorldModel ( )
noexcept

Creates a new empty world model.

virtual weave::WorldModel::~WorldModel ( )
virtualdefault

Member Function Documentation

void weave::WorldModel::AddListener ( std::shared_ptr< WorldListener listener) const
noexcept

Adds a listener to the world model.

The listener will receive all updates of the world model's Execute method.

void weave::WorldModel::Execute ( std::vector< WorldModelAction modelActions)

Commits the given changes to the world model and informs the attached WorldLister.

This method is the only way to change the data of the world model and subclasses should not break that contract.

If one of the given actions is illegal (e.g. unknown entity ID), a ContractFailedException will be thrown. The actions executed up until that point will stay executed, the rest of the actions will not be executed.

Parameters
modelActionsThe actions to be executed. The actions are executed in order.
std::vector<std::shared_ptr<WorldEntity> > weave::WorldModel::GetEntities ( ) const
noexcept

Returns a list of all entities known to this world model.

std::vector<std::shared_ptr<WorldEntity> > weave::WorldModel::GetEntitiesWithType ( std::string  type) const
noexcept

Returns all entities with a given type.

std::shared_ptr<WorldEntity> weave::WorldModel::GetEntityById ( ID  id) const
noexcept

Returns the entity for a given ID, or a nullptr if no such entity is known.

std::vector<WorldModelAction> weave::WorldModel::GetHistory ( ) const
noexcept

Returns the action history of all actions executed by this world model.

If this history is executed on an empty world model, it should result in a copy of the current model.

MetaData weave::WorldModel::GetMetaData ( ID  entityId) const
noexcept

Returns the metadata for the entity with the given ID.

If no entity with that ID is known, an empty metadata object is returned.

std::vector<WorldModelAction> weave::WorldModel::GetMetaDataHistoryForId ( ID  id) const
noexcept

Returns a list of all actions that changed the metadata of the entity with the given ID.

If an action changed the entity itself (e.g. delete it), but not the metadata, it will not be returned.

virtual const NameGenerator& weave::WorldModel::GetNameGenerator ( ) const
pure virtual

The name generator used to create the names of world entities and story elements.

Member Data Documentation

std::shared_ptr<RandomStream> weave::WorldModel::rs
protected

The random stream can be used by subclasses to create randomized entities.

Definition at line 101 of file WorldModel.h.


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