Utils: grid¶
Grid utilities.
Provides common functions for grid-based operations, such as boundary checks and collision detection.
Functions here are used by movement and pathfinding systems to validate entity positions and movements within the grid world.
is_blocked_at(state, pos, check_blocking=True, check_collidable=True, check_pushable=True, position_index=None)
¶
Return True if any blocking entity occupies pos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
World state. |
required |
pos
|
Position
|
Candidate destination. |
required |
check_blocking
|
bool
|
If True, treat |
True
|
check_collidable
|
bool
|
If True, treat |
True
|
check_pushable
|
bool
|
If True, treat |
True
|
position_index
|
Mapping[Position, Iterable[EntityID]] | None
|
Optional cached position index to avoid rebuilding. |
None
|
is_entity_blocked_at(state, entity_id, pos, position_index=None)
¶
Return True if entity_id would be blocked at pos.
If the entity is blocking or pushable, collidable entities are also checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
World state. |
required |
entity_id
|
EntityID
|
Entity. |
required |
pos
|
Position
|
Candidate destination. |
required |
position_index
|
Mapping[Position, Iterable[EntityID]] | None
|
Optional cached position index to avoid rebuilding. |
None
|
is_in_bounds(state, pos)
¶
Return True if pos lies within the level rectangle.
wrap_position(x, y, width, height)
¶
Toroidal wrap for coordinates (used by wrap movement).