#5b Active blocking for NPCs and creatures #20

Closed
opened 2026-11-12 18:31:38 +00:00 by claude · 1 comment
Member

Part of #5. Depends on #5a.

Acceptance

  • With real-time combat on, actors with a shield raise a block in response to an enemy's wind-up within reach. How often and how quickly they react scales with Block skill and agility, and they drop the block to attack.
  • Actors without a shield never block. Creatures follow their existing combat flags.
  • The AI uses the same stance and arc rules as the player, so blocking is fair in both directions.
  • Unit tests cover the reaction decision. A headless Game Template run shows no regressions in combat AI.
Part of #5. Depends on #5a. **Acceptance** - With real-time combat on, actors with a shield raise a block in response to an enemy's wind-up within reach. How often and how quickly they react scales with Block skill and agility, and they drop the block to attack. - Actors without a shield never block. Creatures follow their existing combat flags. - The AI uses the same stance and arc rules as the player, so blocking is fair in both directions. - Unit tests cover the reaction decision. A headless Game Template run shows no regressions in combat AI.
claude added this to the 2. Feel milestone 2026-11-12 18:31:38 +00:00
eric closed this issue 2026-11-13 09:31:41 +00:00
Author
Member

Done in 4e152c7c4e.

What changed

  • New [Game] ai active blocking setting, on by default, used with real time combat. With it on, NPCs and creatures resolve blocks through the same stance and arc rules as the player (usesActiveBlocking), so there's no classic block roll for them.
  • mwmechanics/aiblock.cpp: an enemy counts as a threat when it's winding up a melee attack (isAttackPreparing), its weapon is melee or hand-to-hand, it's within 1.5× its reach, and it's inside the blocker's fCombatBlockLeftAngle/RightAngle arc.
  • AI reaction: rolled once per wind-up. The chance is 0.1 + 0.7 × (Block + 0.2 × Agility)/100, capped at 90% and multiplied by the fatigue term. The reaction delay falls from 0.6 s to 0.15 s over the same range.
  • The block stays up 0.5 s after the wind-up ends, to catch the swing. It drops after 2 s at most, with a 1 s pause before the AI reacts again, so a player holding a wind-up can't pin an NPC behind its shield. The AI starts no attacks while blocking, and it doesn't block during its own attack.
  • Only actors with a shield ready and the weapon drawn block. Creatures need an inventory and shield support, so their existing combat flags decide it.
  • The AI's request is a separate, unsaved CreatureStats flag that is cleared every frame before AI runs. A block can't outlive the combat package, and a Lua self.controls.block request isn't overwritten.
  • Docs: the settings reference and the self.controls.block Lua doc are updated.

Testing

  • The build passes. components-tests: 1636 passed. openmw-tests: 578 passed, including 12 new MWMechanicsAiBlockTest tests covering chance, reaction time, the once-per-wind-up roll, the hold after the swing, the 2 s cap and retry, and the can't-block and no-threat cases.
  • The headless Game Template boot is clean: the screenshot renders normally and there are no new log errors.
  • Not verified end to end. The Game Template has no shields or hostile melee NPCs, so no NPC block happened in a run. Like #19, this needs test content or Eric's playtest. How the timing and frequency feel needs Eric's hands-on playtest.

Notes

  • With the setting on, NPCs without a shield, and NPCs outside combat AI, never block. That is a deliberate change from the classic roll.
  • NPCs slow to block stance speed while blocking, as the player does. Creatures don't, because the creature movement code doesn't apply that multiplier.
Done in `4e152c7c4e`. **What changed** - New `[Game] ai active blocking` setting, on by default, used with `real time combat`. With it on, NPCs and creatures resolve blocks through the same stance and arc rules as the player (`usesActiveBlocking`), so there's no classic block roll for them. - `mwmechanics/aiblock.cpp`: an enemy counts as a threat when it's winding up a melee attack (`isAttackPreparing`), its weapon is melee or hand-to-hand, it's within 1.5× its reach, and it's inside the blocker's `fCombatBlockLeftAngle`/`RightAngle` arc. - AI reaction: rolled **once per wind-up**. The chance is `0.1 + 0.7 × (Block + 0.2 × Agility)/100`, capped at 90% and multiplied by the fatigue term. The reaction delay falls from 0.6 s to 0.15 s over the same range. - The block stays up 0.5 s after the wind-up ends, to catch the swing. It drops after 2 s at most, with a 1 s pause before the AI reacts again, so a player holding a wind-up can't pin an NPC behind its shield. The AI starts no attacks while blocking, and it doesn't block during its own attack. - Only actors with a shield ready and the weapon drawn block. Creatures need an inventory and shield support, so their existing combat flags decide it. - The AI's request is a separate, unsaved `CreatureStats` flag that is cleared every frame before AI runs. A block can't outlive the combat package, and a Lua `self.controls.block` request isn't overwritten. - Docs: the settings reference and the `self.controls.block` Lua doc are updated. **Testing** - The build passes. components-tests: 1636 passed. openmw-tests: 578 passed, including 12 new `MWMechanicsAiBlockTest` tests covering chance, reaction time, the once-per-wind-up roll, the hold after the swing, the 2 s cap and retry, and the can't-block and no-threat cases. - The headless Game Template boot is clean: the screenshot renders normally and there are no new log errors. - **Not verified end to end.** The Game Template has no shields or hostile melee NPCs, so no NPC block happened in a run. Like #19, this needs test content or Eric's playtest. How the timing and frequency *feel* needs Eric's hands-on playtest. **Notes** - With the setting on, NPCs without a shield, and NPCs outside combat AI, never block. That is a deliberate change from the classic roll. - NPCs slow to `block stance speed` while blocking, as the player does. Creatures don't, because the creature movement code doesn't apply that multiplier.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Gaming/ashlar#20