feat(combat): support partial and improved cover levels

This commit is contained in:
2026-09-10 11:32:08 +02:00
parent 2eed752f7f
commit e6125b04f6
6 changed files with 401 additions and 23 deletions
+12 -1
View File
@@ -11,7 +11,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
import yaml
from pydantic import BaseModel, ConfigDict, Field, ValidationError
from pydantic import BaseModel, ConfigDict, Field, ValidationError, field_validator
if TYPE_CHECKING:
from pathlib import Path
@@ -20,6 +20,8 @@ Pos = tuple[int, int] # (row, col), 0-indexed
_ELEVATION_CHARS = frozenset("0123456789.") # digit = height, '.' = ground level
_COVER_BONUS_LEVELS = frozenset({0, 2, 4, 8}) # PF1e: none / partial / standard / improved
class MapValidationError(Exception):
"""Raised when a map YAML file fails validation; carries path and reason."""
@@ -38,8 +40,17 @@ class TerrainType(BaseModel):
type: str
move_cost: int | None = Field(default=None, ge=1)
cover: bool = False
cover_bonus: int = 0
blocks_los: bool = False
@field_validator("cover_bonus", mode="after")
@classmethod
def _check_cover_bonus(cls, value: int) -> int:
if value not in _COVER_BONUS_LEVELS:
msg = f"cover_bonus must be one of {sorted(_COVER_BONUS_LEVELS)}, got {value}"
raise ValueError(msg)
return value
class MapSpec(BaseModel):
"""A fully validated map, ready for Grid construction."""