Repository navigation
Docstrings: crawl battle and encounter - #90
Merged
Merged
Conversation
Rewrite the rendered docstrings of osrlib.crawl.battle and osrlib.crawl.encounter for a developer reading the published API reference: what each member does, when to call it, what it needs first, what takes its output, and what to use instead. Both module docstrings now lead with where the module sits and which events carry its results, and every model field, constant, and policy method has its own docstring instead of rendering as a bare name. Run the register pass over every docstring in both files, private members included, so each file lands in one voice. Claude-Session: https://claude.ai/code/session_01GL26QnA6dCrvUc3WmhzFSa
…the comments Review of #90 found four sentences in the battle module docstring that overstated what the code does. A mirror image figment pops on every incoming attack, hit or miss, with no attack roll made. A concentration spell releases on any declaration other than cast, turn_undead, or hold, not on any other action. A protection ward survives when its effect definition carries an unbreakable param. Casting breaks invisibility in the kernel's cast_spell, not in this module. Define the adaptations register in a clause and link it wherever either file names it, document what end_encounter does with no encounter open and its odometer reset, and point a caller who wants to change a fight in flight at the referee commands rather than at BattleState. Bring the code comments in both files into the same register as the docstrings: no em dashes, no minimizers, and the register named instead of its one-word shorthand. Claude-Session: https://claude.ai/code/session_01GL26QnA6dCrvUc3WmhzFSa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A developer reading the reference for osrlib.crawl.encounter and osrlib.crawl.battle can now start a fight and run it without opening the source. Each module docstring leads with where the module sits: what it takes from the session, which member is the entry point, which commands drive it, and which events carry its results. start_encounter, end_encounter, and start_battle each say when to call them, which command to use instead and why, and what comes back, with a runnable example. Every model field, module constant, and policy method has its own docstring, so nothing on the two pages renders as a bare name any more. ActionPolicy says how to register a policy of your own and shows one that runs, and BattleState points a caller who wants to change a fight in flight at the referee commands instead.
I corrected two docstrings because the code disagreed with them. BattleState said "the groups live on the encounter state" and nothing about its own fields; the round handler writes all nine, and each now says what it is for (src/osrlib/crawl/battle.py:245). EncounterState's round field is not incremented by every accepted encounter command, as a first draft of mine claimed: a chase counts its rounds on pursuit instead, and EngageBattle adds none (src/osrlib/crawl/encounter.py:243).
Review of the first push found four more claims in the battle module docstring that overstated the code, all now corrected against it. A mirror image figment pops on every incoming attack, hit or miss, and no attack roll is made at all. A concentration spell's effects release when the caster declares anything other than cast, turn_undead, or hold, not on any other action. A protection ward survives the melee that would break it when its effect definition carries an unbreakable param, which nothing in the shipped spell data sets. Casting breaks the caster's invisibility in the kernel's cast_spell rather than in this module, so the docstring now attributes it there.
Three things I rewrote because they named nothing a reader could look up. The battle module docstring said the machine "consumes marker conditions and battle-bound spell effects", a phrase that appears nowhere else in the package; it now names the four cases it stands for, each checked against the code. NPC_PARTY_MORALE said a morale 9 group breaks on a 2d6 of 10 or more "before modifiers", which reads as though the situational modifier were ignored; check_morale adds it before the comparison, so the docstring now says so (src/osrlib/crawl/battle.py:874). MELEE_RANGE_FEET said the party's own groups sit at 5 feet when it turns to fight mid-chase; the groups are the monsters', and the engage handler puts them at the current gap rather than at 5, so the sentence now describes the case that does land at 5, a pursuit that catches the party (src/osrlib/crawl/battle.py:219).
The adaptations register is now defined in a clause and linked wherever either file names it. The link is the full URL rather than the heading anchor, because the page's H1 contains a word the docs vocabulary gate bans inside a docstring and the anchor slug carries it too. end_encounter says what it does with no encounter open, which is to raise AttributeError on its first line, and that it resets session.odometer_thirds (src/osrlib/crawl/encounter.py:980). The code comments in both files are in the same register as the docstrings.
Every example runs under the docs harness. None is marked no-run.
Multi-line Returns descriptions need their continuation lines indented one level deeper than the first, or griffe splits each line into its own table row. The ones in these two files are written that way. Any later batch with a Returns section longer than one line will hit the same thing.
https://claude.ai/code/session_01GL26QnA6dCrvUc3WmhzFSa