QuestWeaver

Coverage Status

Procedurally generated quests and stories for computer games.

This project is still in its early stages and under heavy development!

Features

Documentation

Have a look at the API documentation!

Usage

The quest system of a game is not an isolated part of the system as it is heavily involved in the current world state and events. Therefore, the game has to provide the quest system with the necessary information about the game's state and has to fulfill change requests made by the quest system (otherwise the state will be inconsistent).

To use the QuestWeaver system, you have to follow these steps:

QuestWeaver Init() {
    // Create your template factories
    shared_ptr<QuestTemplateFactory> questFactory = make_shared<MyQuestTemplateFactory>();
    shared_ptr<StoryTemplateFactory> storyFactory = make_shared<MyStoryTemplateFactory>();

    // Create Configuration
    WeaverConfig config;
    config.worldModel = make_unique<MyWorldModel>();
    config.dirs.modDirectory = "./Template/";
    shared_ptr<WorldListener> myWorldListener = make_shared<MyWorldListener>();

    // Create the quest system
    QuestWeaver weaver(config);
    weaver.RegisterQuestTemplateFactory(questFactory);
    weaver.RegisterStoryTemplateFactory(storyFactory);
    weaver.GetWorldModel().AddListener(myWorldListener);

    return weaver;
}

// Create new quests
shared_ptr<Quest> newQuest = weaver.CreateNewQuest();

Quests usually want to change the world state as well as their own state (e.g. when a quest succeeds). To do that, you can tick the quest system in your game loop and it will take care of the rest by ticking each quest separately. The WorldListener allows you to change the game state whenever the world model was changed by the quest system.

while (true) {
   // game loop ...

   weaver.Tick(delta); // updates the world state 
}

You can also fully serialize the quest system, e.g. to create a save game or to debug it:

void SerialTest() {
    QuestWeaver weaver = Init();

    // serialize
    stringstream ss; // can also be a file stream
    weaver.Serialize(ss, StreamType::JSON);
    cout << ss.str() << endl; // or save it to disk

    // deserialize - it is important to re-register the template factories and the world model listener!
    QuestWeaver deserialized = QuestWeaver::Deserialize(ss, StreamType::JSON, config.dirs);
    weaver.RegisterQuestTemplateFactory(questFactory);
    weaver.RegisterStoryTemplateFactory(storyFactory);
    weaver.GetWorldModel().AddListener(myWorldListener);
}

Included projects

This project uses the help of some very fine frameworks: