AlternateSelection.h header

#include <ew/app/branching/AlternateSelection.h>

Namespace ew::app::branching

Functions

std::optional< std::size_t > ew::app::branching::chooseAlternate(const ew::core::branching::BranchNode &node, std::size_t visitIndex, const VariableState &state, const ew::core::project::Project &project, std::uint64_t seed)

Which of node's alternate takes the reader gets on their visitIndex'th arrival (0 for the first), or std::nullopt when the node has nothing to say this time.

Deterministic given its arguments, including the random mode, which is what makes a playthrough reproducible: seed is mixed with the node's identity and the visit index rather than a global generator being advanced, so stepping back and forward over a random line shows the same take, and a bug report that says "on the third visit" can be reproduced. A seed of zero is a seed like any other.

Returns nullopt only for ew::core::branching::AlternateMode::Once past its last take (the greeting that stops greeting) or when no take is eligible – ew::core::branching::AlternateMode::FirstMatch with every condition false. A node with no alternates also returns nullopt: it says ew::core::branching::BranchNode::text, and that is the caller's business rather than a take.

state is the story state the conditions are read against, and project supplies the variable declarations they name.

QString ew::app::branching::spokenText(const ew::core::branching::BranchNode &node, std::size_t visitIndex, const VariableState &state, const ew::core::project::Project &project, std::uint64_t seed)

The words the reader hears on their visitIndex'th arrival at node: the chosen take's text, the node's own text when it has no alternates, or empty when a Once node has run out.

The one place that answers "what does this node say now", so the playthrough, the preview and anything else asking cannot disagree.