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
+28
View File
@@ -49,6 +49,34 @@ const CROUCH_HEIGHT: float = 1.2
const FALL_DAMAGE_SAFE_METRES: float = 6.0
const FALL_DAMAGE_PER_METRE: float = 8.0
# Water, in metres and seconds. Depths are water over the floor under the player.
## The sea level a match starts at. The tide raises it from here.
const SEA_LEVEL_START: float = 0.0
## Deeper than this, walkers wade at WADE_SPEED and can't sprint.
const WADE_DEPTH: float = 0.4
## Water this deep over the floor lifts a player off it to swim.
const SWIM_DEPTH: float = 1.35
## A swimmer stands again where the water over the floor is shallower than this.
const SWIM_EXIT_DEPTH: float = 1.2
## A swimmer floats with the feet this far under the surface, head out.
const SWIM_FLOAT_DEPTH: float = 1.3
## With no stamina left a swimmer sinks until the feet are this far under: head under.
const SWIM_EXHAUSTED_DEPTH: float = 2.2
const SWIM_SPRINT_SPEED: float = 3.2
## Fraction of SWIM_SPEED left to an exhausted swimmer.
const SWIM_EXHAUSTED_FACTOR: float = 0.6
## Diving and rising speed, and how fast vertical speed changes in the water.
const SWIM_VERTICAL_SPEED: float = 2.0
const SWIM_VERTICAL_ACCEL: float = 12.0
## Fraction of downward speed kept on hitting deep water.
const WATER_ENTRY_DAMP: float = 0.25
## Seconds of paddling a full stamina bar allows. Sprint-swimming spends it faster.
const SWIM_STAMINA_SECONDS: float = 45.0
const SWIM_SPRINT_STAMINA_COST: int = 3
## Ticks of stamina and breath regained per tick out of the water or above it.
const STAMINA_RECOVERY_RATE: int = 3
const BREATH_RECOVERY_RATE: int = 4
# The island. Worldgen fills the whole world square; the island is about a kilometre
# across, sized for 24 players. Heights are metres above the starting sea level.
## Spacing of the terrain heightfield, in metres. The grid covers WORLD_SIZE_METRES.