fix(rules): distinguish natural reach from reach weapons

PF1e CRB 'Big and Little Creatures in Combat': a creature's natural
reach is a disk (a Large creature still threatens and strikes adjacent
squares), while a reach weapon doubles the wielder's natural reach but
'can't strike at their natural reach or less' (a ring whose dead zone is
the natural reach). The engine keyed the ring off reach_ft > 5, so
reach-10 natural attacks (giant belostomatid bite/claw, mounted
hooves) wrongly got a 5-ft dead zone.

AttackSpec gains reach_weapon (parsed from the combatant JSON); the
disk-vs-ring rule is centralized in _melee_reach_zone_cells and applied
consistently to weapon selection, melee usability, threatened squares
and charge end placement. Esha's Lance is the only reach weapon in the
shipped data; Large natural attackers keep the default (disk).

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-09-11 22:06:46 +02:00
parent 4f6b076a49
commit 4d89305881
11 changed files with 292 additions and 80 deletions
+124 -11
View File
@@ -1,10 +1,14 @@
"""Tests for B5.3: melee reach depends on weapon reach and creature size.
Covers the PF1e reach rules implemented in this phase:
- non-reach weapons (``reach_ft == 5``) threaten the disk of effective reach;
- reach weapons (``reach_ft > 5``) threaten only the ring at exactly their
reach (the PF1e reach dead zone: a longspear cannot hit an adjacent target);
- a Large creature's natural reach (10 ft) extends its non-reach weapons;
Covers the PF1e reach rules implemented in this phase (R1 conformance:
CRB "Big and Little Creatures in Combat" — natural reach is a disk, a
reach weapon is a ring):
- natural reach (plain weapons and natural attacks) threatens the DISK of
effective reach: a Large creature's 10 ft bite still strikes and
threatens ADJACENT squares;
- reach weapons (``reach_weapon=True``) threaten only the RING beyond the
wielder's natural reach up to double it (the PF1e reach dead zone: a
longspear cannot hit an adjacent target);
- ``weapon_for`` respects the reach dead zone;
- AoOs trigger from ring squares threatened by a reach weapon.
"""
@@ -31,6 +35,7 @@ def make_combatant(
*,
size: str = "Medium",
reach_ft: int = 5,
reach_weapon: bool = False,
hp: int = 20,
ac: int = 15,
attack_bonus: int = 5,
@@ -39,11 +44,12 @@ def make_combatant(
"""Build a single-melee-weapon combatant (used by most reach tests)."""
attack = AttackSpec(
id=f"{cid}-w",
name="longspear" if reach_ft > 5 else "short sword",
name="longspear" if reach_weapon else "short sword",
kind="melee",
attack_bonus=attack_bonus,
damage=[DamageComponent(formula=parse_dice("1d6"), types=["piercing"])],
reach_ft=reach_ft,
reach_weapon=reach_weapon,
)
return Combatant(
id=cid,
@@ -125,8 +131,11 @@ def test_medium_5ft_weapon_threatens_adjacent_only() -> None:
def test_reach_weapon_threatens_ring_not_adjacent() -> None:
"""A longspear (reach 10 ft) threatens the ring at distance 2, not adjacent squares."""
spearman = make_combatant("spearman", reach_ft=10)
"""A longspear (reach weapon) threatens the ring at distance 2, not adjacent squares.
R1: the ring is now driven by ``reach_weapon=True``, not by ``reach_ft > 5``.
"""
spearman = make_combatant("spearman", reach_ft=10, reach_weapon=True)
state = make_state(spearman, "players", (3, 3))
engine = make_engine([state])
threatened = engine.threatened_squares(state)
@@ -154,6 +163,7 @@ def test_sword_plus_reach_weapon_union() -> None:
attack_bonus=5,
damage=[DamageComponent(formula=parse_dice("1d6"), types=["piercing"])],
reach_ft=10,
reach_weapon=True,
)
combatant = Combatant(
id="dual",
@@ -205,9 +215,108 @@ def test_unknown_size_defaults_to_5ft() -> None:
assert engine.threatened_squares(state) == frozenset(_adjacent((3, 3)))
# ── R1 conformance: natural reach is a disk, a reach weapon is a ring ────────
def _natural_attack_combatant(
cid: str, *, size: str, reach_ft: int, reach_weapon: bool
) -> Combatant:
"""Combatant with one melee attack carrying the given reach flags."""
attack = AttackSpec(
id=f"{cid}-w",
name="bite" if not reach_weapon else "longspear",
kind="melee",
attack_bonus=5,
damage=[DamageComponent(formula=parse_dice("1d6"), types=["piercing"])],
reach_ft=reach_ft,
reach_weapon=reach_weapon,
)
return Combatant(
id=cid,
name=cid,
level=1,
size=size,
abilities=AbilityScores(
str_score=10, dex_score=10, con_score=12,
int_score=10, wis_score=10, cha_score=10,
),
hp_max=20,
ac=ACProfile(total=15, touch=15, flat_footed=15),
bab=5,
initiative_mod=0,
speed_land_ft=30,
saves=Saves(fort=0, ref=0, will=0),
attacks=[attack],
)
def test_large_natural_attack_threatens_adjacent_disk() -> None:
"""R1 (CRB "Big and Little Creatures in Combat"): a Large creature's
natural 10 ft bite is a DISK — it threatens adjacent squares too, unlike
a reach weapon's ring. The old model keyed the ring off ``reach_ft > 5``
and wrongly gave the bite a 5 ft dead zone (giant_belostomatid.json,
esha_mount.json, jeanne.json all have reach-10 natural attacks)."""
bug = _natural_attack_combatant("bug", size="Large", reach_ft=10, reach_weapon=False)
state = make_state(bug, "players", (3, 3))
engine = make_engine([state])
threatened = engine.threatened_squares(state)
footprint = state.occupied_cells()
expected: set[tuple[int, int]] = set()
for cell in footprint:
expected |= _disk(cell, 2)
expected -= footprint
assert threatened == frozenset(expected)
# Adjacent to the footprint (1 cell) is threatened: the disk, not a ring.
assert (3, 2) in threatened
assert (2, 2) in threatened
def _bug_attack_policy(engine: CombatEngine, state: CombatantState) -> tuple[Action, ...]:
if state.combatant.id == "bug":
return (Action(kind="attack", target_id="rider-target"),)
return (Action(kind="wait"),)
def test_large_natural_attack_hits_adjacent_target() -> None:
"""R1: the reach-10 natural attack of a Large creature STRIKES an adjacent
target (disk), which the old ring model refused."""
bug = _natural_attack_combatant("bug", size="Large", reach_ft=10, reach_weapon=False)
target = make_combatant("rider-target", hp=20, ac=12)
bug_state = make_state(bug, "players", (3, 3))
target_state = make_state(target, "monsters", (3, 5)) # adjacent to (3, 4)
engine = CombatEngine(
ScriptedRng([20, 1, 15, 3]),
make_grid(), [bug_state, target_state],
round_cap=1, policy=_bug_attack_policy,
)
result = engine.run()
assert any("bite vs rider-target" in line and "-> HIT" in line
for line in result.transcript), result.transcript
assert target_state.hp == 17 # 20 - 1d6(3)
def test_large_reach_weapon_ring_beyond_natural_reach() -> None:
"""R1 (CRB): "Large or larger creatures using reach weapons can strike up
to double their natural reach but can't strike at their natural reach or
less" — for a Large longspear wielder the usable band is 15..20 ft: dead
at 10 ft (natural reach), live at 15 ft, dead beyond 20 ft."""
giant = _natural_attack_combatant(
"giant", size="Large", reach_ft=10, reach_weapon=True
)
target = make_combatant("target")
attacker = make_state(giant, "players", (3, 3))
# Footprint spans cols 3-4; distance = foe_col - 4 cells (x5 ft).
# (3, 6): 10 ft = natural reach -> dead zone. (3, 7): 15 ft -> in ring.
for foe_col, in_ring in ((6, False), (7, True)):
foe = make_state(target, "monsters", (3, foe_col))
engine = make_engine([attacker, foe])
weapon = engine.weapon_for(attacker, foe)
assert (weapon is not None) is in_ring, f"distance {foe_col - 4} cells"
def test_weapon_for_reach_weapon_at_distance_2_not_1() -> None:
"""weapon_for selects a reach weapon at distance 2 but not at distance 1 (dead zone)."""
spearman = make_combatant("spearman", reach_ft=10)
spearman = make_combatant("spearman", reach_ft=10, reach_weapon=True)
target = make_combatant("target")
attacker = make_state(spearman, "players", (3, 3))
@@ -242,7 +351,9 @@ def _move_to_dest(engine: CombatEngine, state: CombatantState) -> tuple[Action,
def test_aoo_from_reach_ring() -> None:
"""Moving through a ring square threatened by a longspear provokes an AoO."""
runner = make_combatant("runner", hp=20, ac=12, speed=30)
spearman = make_combatant("spearman", hp=20, ac=15, attack_bonus=5, speed=0, reach_ft=10)
spearman = make_combatant(
"spearman", hp=20, ac=15, attack_bonus=5, speed=0, reach_ft=10, reach_weapon=True,
)
dest = make_combatant("dest", hp=20, ac=15, attack_bonus=0, speed=0)
states = [
make_state(runner, "players", (4, 3)),
@@ -269,7 +380,9 @@ def test_aoo_from_reach_ring() -> None:
def test_no_aoo_from_adjacent_to_reach_weapon() -> None:
"""A longspear does not threaten adjacent squares: no AoO when leaving one."""
runner = make_combatant("runner", hp=20, ac=12, speed=30)
spearman = make_combatant("spearman", hp=20, ac=15, attack_bonus=5, speed=0, reach_ft=10)
spearman = make_combatant(
"spearman", hp=20, ac=15, attack_bonus=5, speed=0, reach_ft=10, reach_weapon=True,
)
dest = make_combatant("dest", hp=20, ac=15, attack_bonus=0, speed=0)
states = [
make_state(runner, "players", (4, 1)),