Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

### Added

- Two house rules for character creation, which the SRD doesn't print and `Ruleset()` leaves off (#341). [`Ruleset.ability_score_method`][osrlib.core.ruleset.Ruleset.ability_score_method] is `"3d6"` by default. With `"4d6_drop_lowest"`, [`create_character`][osrlib.core.character.create_character] throws four d6 for each ability and drops the lowest, the first of them thrown when two or more tie, and [`roll_ability_scores`][osrlib.core.character.roll_ability_scores] does the same when you pass the method to its new `method` keyword. [`AbilityScoreRolls.rolls`][osrlib.core.character.AbilityScoreRolls.rolls] keeps the three dice that count, and the new [`AbilityScoreRolls.dropped`][osrlib.core.character.AbilityScoreRolls.dropped] has the dropped die of each ability, so a client can show all four. The method draws 24 dice instead of 18, so the same seed gives a different character, and NPC adventurers always roll 3d6. With [`Ruleset.max_hp_at_first_level`][osrlib.core.ruleset.Ruleset.max_hp_at_first_level] on, a first-level character's hit points are the hit die's size plus the CON modifier, and at least 1, and the new [`HitPointRoll.maximized`][osrlib.core.character.HitPointRoll.maximized] is true. The hit die and any rerolls of `hp_reroll_at_first_level` are still thrown, so the starting gold is the same as with the flag off. `examples/rulesets/creation_house_rules.json` is a ruleset with both house rules on and every other field at its default, for a front end to copy. With both flags at their defaults, every draw and result is what 2.8.0 gave. A 2.8.0 save loads with both off, a 2.8.0 creation result parses with an empty `dropped` and a false `maximized`, and [`SCHEMA_VERSION`][osrlib.versioning.SCHEMA_VERSION] stays 4.

## [2.8.0] - 2026-11-25

### Added
Expand Down
32 changes: 29 additions & 3 deletions docs/adaptations.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Adaptations and interpretations

osrlib follows OSE rules-as-written (RAW). Every place where that isn't enough is recorded here, as one of two kinds of entry:
osrlib follows OSE rules-as-written (RAW). Every place where that isn't enough, and every house rule osrlib offers, is recorded here, as one of three kinds of entry:

- **Interpretations**, where the SRD text is ambiguous or silent, and osrlib commits to one reading.
- **Documented adaptations**, where the tabletop game assumes a human referee, and osrlib provides a default behind a `Ruleset` flag.
- **House rules**, which change a procedure in a way the SRD doesn't print. Each one is a `Ruleset` flag that's off by default, so `Ruleset()` is the SRD as written.

Look here instead of searching docstrings. Every entry is also stated in the docstring of the member it applies to and locked by a test.

Expand All @@ -19,7 +20,7 @@ Each entry also cites the source files and test names that lock it. Those citati
- **Stable order** - When the engine sorts things that tie, it keeps them in the order it was given them, so the result never depends on chance.
- **Kernel and session** - The kernel is `osrlib.core`, the rules functions you can call directly (see [Rules without a session](guides/rules-without-a-session.md)). The session is a [`GameSession`][osrlib.crawl.session.GameSession], which runs a whole adventure through commands and calls the kernel for you.
- **Caller** - The code that calls a kernel function: your game, or the session. A value "the caller supplies" is an argument that code passes, because the kernel can't work it out.
- **Ruleset flags** - Options on [`Ruleset`][osrlib.core.ruleset.Ruleset]. Some switch the SRD's optional rules on or off, and others switch the defaults that [Documented adaptations](#documented-adaptations) lists.
- **Ruleset flags** - Options on [`Ruleset`][osrlib.core.ruleset.Ruleset]. Some switch the SRD's optional rules on or off, others switch the defaults that [Documented adaptations](#documented-adaptations) lists, and the rest turn on the rules that [House rules](#house-rules) lists.
- **Marching order** - The order of the party's members. In battle, it decides who stands in front among members at the same distance from a group who got there in the same round. It also decides which member a rule means by "the first living member".
- **Front rank and back rank** - In battle, the ranks toward a monster group are the living members sorted by their distance to it and cut into rows as wide as the formation width. The first row is the front rank toward that group, and every member behind it is in the back rank. Melee reaches only the members of the front rank who stand within 5' of the group. See [The battle round](#the-battle-round).
- **Range track** - In battle, each monster group has a separate distance from the party line, where the party stood when the encounter opened, in the style of The Bard's Tale, instead of a position on a map. Each party member has a place on the same track, in feet forward of the line.
Expand Down Expand Up @@ -1883,7 +1884,7 @@ Locked by `test_session.py` and the phase 5 milestone golden.

## Documented adaptations

`Ruleset`-flagged deviations from rules-as-written. The flags `hp_reroll_at_first_level`, `encumbrance`, `variable_weapon_damage`, `individual_initiative`, `thac0_arithmetic`, `weapon_reload`, and `hd5_counts_as_magical` are SRD optional rules rather than adaptations, so this section doesn't list them.
`Ruleset`-flagged deviations from rules-as-written. The flags `hp_reroll_at_first_level`, `encumbrance`, `variable_weapon_damage`, `individual_initiative`, `thac0_arithmetic`, `weapon_reload`, and `hd5_counts_as_magical` are SRD optional rules rather than adaptations, so this section doesn't list them. The flags `ability_score_method` and `max_hp_at_first_level` are house rules, which [House rules](#house-rules) lists.

### `deprivation_penalties` (default off)

Expand Down Expand Up @@ -1933,3 +1934,28 @@ Items that survive go to the drop pile, a [`DropPile`][osrlib.crawl.dungeon.Drop
- Dropping treasure never refunds its XP, so the return to town then awards nothing.

Neither timing pays twice. Locked by `test_award.py::TestImmediateTiming`.

## House rules

These `Ruleset` flags turn on rules that the SRD doesn't print. Each one is off by default, so a game uses it only when you turn it on. `examples/rulesets/creation_house_rules.json` in the osrlib repository is a ruleset with both of these on.

### `ability_score_method` (default `3d6`)

`3d6` is RAW: each ability score is the sum of three d6.

`4d6_drop_lowest` throws four d6 for each ability, and the lowest die doesn't count, so the score is the sum of the other three, from 3 to 18:

- When two or more dice tie for lowest, the first of them thrown is dropped, so the same draws always give the same three dice in the same order.
- [`AbilityScoreRolls.rolls`][osrlib.core.character.AbilityScoreRolls.rolls] keeps the three dice that count, in the order thrown, and [`AbilityScoreRolls.dropped`][osrlib.core.character.AbilityScoreRolls.dropped] has the dropped die of each ability.
- All four dice of STR are thrown before any of INT, and so on in the SRD's order, so the scores take 24 draws from the creation stream instead of 18. The same seed gives different scores, and a different hit die and starting gold after them, than it gives with `3d6`.

The method affects only the characters you create, and NPC adventurers always roll 3d6. Locked by `test_creation_house_rules.py::test_4d6_drop_lowest_counts_three_dice_and_names_the_dropped_one` and `test_creation_house_rules.py::test_4d6_drop_lowest_throws_the_draws_in_order_and_advances_24_dice`.

### `max_hp_at_first_level` (default off)

With the flag off, a first-level character's hit points are the class's hit die as rolled plus the CON modifier, as RAW says. With the flag on, they're the hit die's size plus the CON modifier, and at least 1, and [`HitPointRoll.maximized`][osrlib.core.character.HitPointRoll.maximized] is `True`:

- The hit die is still thrown, and so are the rerolls of `hp_reroll_at_first_level`, so [`HitPointRoll.rolls`][osrlib.core.character.HitPointRoll.rolls] lists the same dice as with the flag off. The stream ends in the same place, so the starting gold roll after the hit die is the same either way.
- The flag affects only character creation. [`level_up`][osrlib.core.classes.level_up] rolls each later level's hit die as usual.

Locked by `test_creation_house_rules.py::test_the_maximum_draws_what_the_roll_draws_so_the_gold_is_the_same` and `test_creation_house_rules.py::test_the_maximum_is_the_die_size_plus_the_modifier_and_at_least_1`.
32 changes: 29 additions & 3 deletions docs/guides/ruleset-options.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Ruleset options

Configure optional B/X rules and referee adaptations by constructing a [`Ruleset`][osrlib.core.ruleset.Ruleset] and passing it to [`GameSession.new`][osrlib.crawl.session.GameSession.new] or to standalone `osrlib.core` functions. `Ruleset` is frozen (`extra="forbid"`), persists in saves and replays, and raises Pydantic's `ValidationError` if you pass an unrecognized flag name.
Configure optional B/X rules, referee adaptations, and house rules by constructing a [`Ruleset`][osrlib.core.ruleset.Ruleset] and passing it to [`GameSession.new`][osrlib.crawl.session.GameSession.new] or to standalone `osrlib.core` functions. `Ruleset` is frozen (`extra="forbid"`), persists in saves and replays, and raises Pydantic's `ValidationError` if you pass an unrecognized flag name.

## Construct a `Ruleset`

Call `Ruleset()` with no arguments for the default B/X configuration, or override specific flags such as [`EncumbranceMode`][osrlib.core.ruleset.EncumbranceMode] to change how functions such as [`Character.movement_rate`][osrlib.core.character.Character.movement_rate] behave:
Call `Ruleset()` with no arguments for the default B/X configuration, which is the SRD as written with no house rule on. You can also override specific flags such as [`EncumbranceMode`][osrlib.core.ruleset.EncumbranceMode] to change how functions such as [`Character.movement_rate`][osrlib.core.character.Character.movement_rate] behave:

```python
from pydantic import ValidationError
Expand Down Expand Up @@ -61,11 +61,13 @@ else:

## Quick reference

Every `Ruleset` field falls into one of two categories: optional rules printed in the OSE SRD alongside standard B/X procedures, or documented adaptations that supply a deterministic rule where tabletop B/X leaves a judgment call to a human referee (see [the adaptations register](../adaptations.md)):
Every `Ruleset` field falls into one of three categories: optional rules printed in the OSE SRD alongside standard B/X procedures, documented adaptations that supply a deterministic rule where tabletop B/X leaves a judgment call to a human referee (see [the adaptations register](../adaptations.md)), or house rules, which the SRD doesn't print and which `Ruleset()` leaves off:

| Flag | Kind | Type and default | Effect |
| --- | --- | --- | --- |
| `hp_reroll_at_first_level` | Optional rule | `bool`, `False` | Reroll a 1st-level Hit Die when the raw roll is 1 or 2. |
| `max_hp_at_first_level` | House rule | `bool`, `False` | Count a 1st-level Hit Die as its maximum, without changing the dice thrown. |
| `ability_score_method` | House rule | `"3d6" \| "4d6_drop_lowest"`, `"3d6"` | Roll each new character's ability scores as 3d6, or as 4d6 with the lowest die dropped. |
| `encumbrance` | Optional rule | `EncumbranceMode`, `BASIC` | Select which encumbrance rule tracks carried weight and movement rate. |
| `variable_weapon_damage` | Optional rule | `bool`, `True` | Roll each weapon or combat-gear item's listed damage die instead of a flat `1d6`. |
| `individual_initiative` | Optional rule | `bool`, `False` | Roll `1d6` initiative per combatant instead of once per side. |
Expand Down Expand Up @@ -104,6 +106,30 @@ These options govern rules where tabletop B/X leaves the outcome to referee judg
- **`failed_trap_removal_springs`** (`True` by default): When `True`, a thief who fails [`RemoveTreasureTrap`][osrlib.crawl.commands.RemoveTreasureTrap] immediately springs the trap on themselves. When `False`, a failed attempt emits [`TrapEvent`][osrlib.crawl.events.TrapEvent] (`exploration.trap.removal_failed`) and leaves the discovered trap armed: that thief cannot retry, another thief may try, and taking the treasure still has a 2-in-6 chance to spring the trap.
- **`back_stab_needs_both_skills`** (`True` by default): A thief who hides during a battle, with a [`BattleDeclaration`][osrlib.crawl.commands.BattleDeclaration] whose `action` is `hide`, can back-stab from hiding. The session rolls hide in shadows when the hide resolves and move silently when the back-stab comes up, and only the referee sees either roll. When `True`, the attack is a back-stab only when both rolls passed. When `False`, either roll passing is enough. The session makes both rolls under either setting, so the flag changes no draw, and the monsters' choice of targets reads the hide in shadows roll alone under either setting. At first level, where hide in shadows is 10% and move silently 20%, a thief's attack from hiding is a back-stab 2% of the time with the flag on and 28% with it off. At seventh level, where they're 45% and 55%, it's about 25% and about 75%. Neither setting is the rules as written, as [the adaptations register](../adaptations.md#a-back-stab-needs-surprised-monsters-or-a-hiding-thief) explains.

## House rules

These options change character creation in ways the OSE SRD doesn't print. `Ruleset()` leaves both off, so a game uses them only when you turn them on:

- **`ability_score_method`** (`"3d6"` by default): With `"3d6"`, each ability score is the sum of three d6, as the SRD says. With `"4d6_drop_lowest"`, each ability throws four d6 and the lowest one doesn't count. When two or more tie for lowest, the first of them thrown is dropped. [`AbilityScoreRolls.rolls`][osrlib.core.character.AbilityScoreRolls.rolls] keeps the three dice that count, and [`AbilityScoreRolls.dropped`][osrlib.core.character.AbilityScoreRolls.dropped] has the dropped die of each ability, so a client can show all four. The method draws 24 dice from the creation stream instead of 18, so the same seed gives different scores and a different character. NPC adventurers always roll 3d6.
- **`max_hp_at_first_level`** (`False` by default): When `True`, a first-level character's hit points are the class's hit die at its maximum plus the CON modifier, and at least 1, and [`HitPointRoll.maximized`][osrlib.core.character.HitPointRoll.maximized] is `True`. The hit die is still thrown, and so are the rerolls of `hp_reroll_at_first_level`, so the starting gold roll after them is the same either way. Later levels roll their hit dice as usual.

`examples/rulesets/creation_house_rules.json` in the osrlib repository is a ruleset document with both house rules on and every other field at its default. It writes out every field, so a copy shows the whole ruleset:

```json
--8<-- "examples/rulesets/creation_house_rules.json"
```

Load it with [`Ruleset.model_validate_json`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_validate_json), and pass the result wherever you'd pass a `Ruleset`:

```{.python .no-run}
from pathlib import Path

from osrlib.core.ruleset import Ruleset

rules = Ruleset.model_validate_json(Path("examples/rulesets/creation_house_rules.json").read_text(encoding="utf-8"))
assert rules == Ruleset(ability_score_method="4d6_drop_lowest", max_hp_at_first_level=True)
```

## Where next

- [The adaptations register](../adaptations.md) - rule citations and design rationale for each documented adaptation and settled SRD ambiguity.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/rng-streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The table below lists every key, the constant for it, and what it governs.

Character creation and in-play advancement are split into two separate streams so that changing one never disturbs the other's draws.

The [`CHARACTER_CREATION_STREAM`][osrlib.core.character.CHARACTER_CREATION_STREAM] (key `"character_creation"`) covers one-time creation draws: rolling ability scores, first-level hit points, and starting gold.
The [`CHARACTER_CREATION_STREAM`][osrlib.core.character.CHARACTER_CREATION_STREAM] (key `"character_creation"`) covers one-time creation draws: rolling ability scores, first-level hit points, and starting gold. The ability scores take 18 d6 draws with the default `"3d6"` method and 24 with the `"4d6_drop_lowest"` house rule of `Ruleset.ability_score_method`, so the hit die and the gold that follow come from different draws under the two methods. The `max_hp_at_first_level` house rule changes no draw.

The [`ADVANCEMENT_STREAM`][osrlib.core.character.ADVANCEMENT_STREAM] (key `"advancement"`) covers hit point rolls when a character levels up during play, and the hit point rolls for the levels or Hit Dice that energy drain takes away.

Expand Down
Loading
Loading