W6: Water and swimming

The simulation has a global sea level (Simulation.sea_level, changed with
set_sea_level and read every tick, so the tide can move it mid-match).
Walkers wade more slowly in water over WADE_DEPTH; in water SWIM_DEPTH deep
they swim: floating head-out, sprint-swimming, diving with crouch, kicking
out with jump, and standing again in the shallows. Falling into deep water
does no fall damage. Water tracks breath, stamina and drowning in whole
ticks: swimming spends stamina, an exhausted swimmer slips under, and with
no breath left the tide phase's drown damage lands once a second. All of
it, plus the sea level, is in the state hash.

WaterView draws the sea surface at the simulation's level with a
procedural shader: depth-tinted colour, foam at the waterline, ripples.

Closes #13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 12:24:50 -05:00
co-authored by Claude Opus 5.5
parent 5db53de4e8
commit be987b6f82
18 changed files with 641 additions and 10 deletions
+20 -2
View File
@@ -21,6 +21,11 @@ var pois: PoiSet = PoiSet.new()
## Trees, scrub, boulders, wrecks and crates, whose boxes are part of `ground`. Empty
## when a test supplied its own ground.
var props: PropSet = PropSet.new()
## Height of the sea surface, in metres. The tide changes it during a match; movement
## and drowning read it every tick, so a change takes effect on the next step.
var sea_level: float = Tuning.SEA_LEVEL_START
## Damage per second to a player underwater with no breath left. Set by the tide phase.
var drown_dps: int = Tuning.TIDE_PHASES[0]["drown_dps"]
## Player entity ID -> { command tick -> PlayerCommand }
var _pending: Dictionary = {}
@@ -59,6 +64,7 @@ func add_player() -> int:
player.position = Vector3(x, ground.terrain_height(x, z), z)
player.on_ground = true
player.health = Tuning.PLAYER_MAX_HEALTH
Water.reset(player)
_players.append(player.id)
_pending[player.id] = {}
return player.id
@@ -94,7 +100,14 @@ func step() -> void:
func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
Movement.step(player, command, ground)
Movement.step(player, command, ground, sea_level)
var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT)
Water.update(player, sea_level, drown_dps, sprinting)
## Moves the sea surface. Takes effect on the next step.
func set_sea_level(level: float) -> void:
sea_level = level
## Damages a prop. Returns true if this destroyed it; its collision goes at once.
@@ -119,12 +132,17 @@ func state_hash() -> String:
buffer.put_32(entity.health)
buffer.put_32(entity.yaw)
buffer.put_32(entity.pitch)
buffer.put_u8((1 if entity.on_ground else 0) | (2 if entity.crouching else 0))
buffer.put_u8((1 if entity.on_ground else 0) | (2 if entity.crouching else 0) | (4 if entity.swimming else 0))
buffer.put_32(entity.breath_ticks)
buffer.put_32(entity.stamina_ticks)
buffer.put_32(entity.drown_ticks)
for value: float in [entity.position.x, entity.position.y, entity.position.z]:
buffer.put_64(roundi(value * 1000.0))
for value: float in [entity.velocity.x, entity.velocity.y, entity.velocity.z]:
buffer.put_64(roundi(value * 1000.0))
buffer.put_64(roundi(sea_level * 1000.0))
buffer.put_32(drown_dps)
buffer.put_64(props.count())
buffer.put_data(props.health.to_byte_array())