Mi2dRPGamEng/resources/logic/swimming.py

30 lines
1.3 KiB
Python

from __future__ import annotations
from engine.character import Character
from engine.world import World
def in_water(character: Character, world: World) -> bool:
"""True if the character is currently standing in a water tile (resources/defs/tiles.json's
"water" flooring def) - gates the free vertical swim movement (req 6) the same way
resources/logic/steering.py::at_helm gates ship-steering movement in main.py.
"""
if character.position is None:
return False
map_ = world.maps[character.position.map_id]
tile = map_.get_tile(character.position.x, character.position.y, character.position.z)
return tile.layer_id("flooring") == "water"
def try_swim_vertical(character: Character, world: World, dz: int) -> bool:
"""Moves one z-level up/down while submerged - unlike land staircases this needs no placed
connector tile, since every water column is swimmable end to end (see
engine/worldgen/terrain.py's underground fill: a water column stays water all the way
down, rather than turning to solid rock like dry land does). No-op if not currently in
water, or if the target z isn't itself walkable (e.g. surfacing above the waterline into a
solid tile, or diving below the seabed).
"""
if not in_water(character, world):
return False
return world.try_move(character, 0, 0, dz)