RandomTableRoll.h header

#include <ew/app/RandomTableRoll.h>

Namespace ew::app

RandomTableRollResult struct

struct ew::app::RandomTableRollResult

The outcome of rolling on a random table.

Members

bool ew::app::RandomTableRollResult::valid = false

Whether a result was produced. False only when the table has no entries.

int ew::app::RandomTableRollResult::index = -1

The index of the chosen entry within the table's entries (-1 when invalid).

QString ew::app::RandomTableRollResult::text

The chosen entry's result text, with any inline references expanded (see rollOnTable).

Types

using ew::app::RandomTableResolver = std::function<const ew::core::RandomTable*(const QString& title)>

Resolves a random-table title (as written inside a [[...]] reference) to the table it names, so a roll can chain into a sub-table. Returns null when no such table exists, in which case the reference is left literal. Case-insensitive matching is the caller's responsibility.

Functions

RandomTableRollResult ew::app::rollOnTable(const ew::core::RandomTable &table, quint64 seed)

Rolls once on table, returning a weight-proportional random entry driven by seed, so the same table and seed always give the same result – reproducible and unit-testable, and suitable for a shareable "seeded roll" (mirroring rollDice). An entry with twice the weight is twice as likely; weights below 1 count as 1. An empty table returns a result with valid = false.

The chosen entry's text is expanded: any [[NdM]] (or other dice expression, e.g. [[2d6+1]]) is replaced by the rolled total. [[Other Table]] references are left literal by this overload (it has no way to find another table); use the resolver overload to chain into sub-tables.

RandomTableRollResult ew::app::rollOnTable(const ew::core::RandomTable &table, quint64 seed, const RandomTableResolver &resolver)

As above, but also expands [[Other Table]] references by rolling on the table resolver returns, so a sub-table may itself reference further tables. Sub-rolls use seeds derived from seed, so the whole nested result stays reproducible; nesting is depth-bounded so a self-referential table cannot expand forever. A reference that is neither a dice expression nor a known table is left literal (nothing is silently dropped). Dice take precedence, so a reference like [[2d6]] rolls dice even if a table happens to be titled "2d6".