# gizgame/sealife

what lives in a sea, by how warm its water is: the kinds of a region and where each swims about a place at a time. A game draws each swimmer with its own shapes; nothing here knows a scene.

```gizlang
import * as Sealife from "gizgame/sealife";
```

## Types

### `SeaKind`

```gizlang
type SeaKind = { name: string; model: string; length: f64; school: i64; under: f64; speed: f64; leaps: bool; rides?: bool; blows?: bool; water: Vec<f64>; ranges: Vec<Vec<f64>>; }
```

A kind of sea life: its NAME, its MODEL (a Poly Pizza model's name; "" for a swarm too small for one), its LENGTH
in meters as a game draws it, how many swim together, the meters under the surface it keeps, its speed in meters a
second, whether it LEAPS out of the water (a dolphin's arc, a whale's breach, a penguin's porpoising), whether it
RIDES a ship's bow wave and whether it BLOWS at the surface. It lives
in WATER of these degrees C, [least, most], and only in its RANGES, each [south, north, west, east] in degrees;
everywhere with none.

- `name`: `string`
- `model`: `string`
- `length`: `f64`
- `school`: `i64`
- `under`: `f64`
- `speed`: `f64`
- `leaps`: `bool`
- `rides`: `_gizlang_sdk_core.Option<bool>`
- `blows`: `_gizlang_sdk_core.Option<bool>`
- `water`: `Vec<f64>`
- `ranges`: `Vec<Vec<f64>>`

### `Swimmer`

```gizlang
type Swimmer = { kind: SeaKind; at: Point3; yaw: f64; pitch: f64; wag: f64; blow: f64; }
```

One of a sea's life as it is now: its KIND, where it is, the way it heads and tips, its tail's swing (-1 to 1) and how
far through a BLOW it is (0 for none, to 1).

- `kind`: `M257.SeaKind`
- `at`: `gizlang_geometry.Point3`
- `yaw`: `f64`
- `pitch`: `f64`
- `wag`: `f64`
- `blow`: `f64`

### `Hull`

```gizlang
type Hull = { at: Point3; yaw: f64; speed: f64; half: f64; }
```

A hull in the water the sea's life knows of: where its middle is, the way it heads (yaw), its speed in meters a
second and half its length. Dolphins ride its bow wave when it sails.

- `at`: `gizlang_geometry.Point3`
- `yaw`: `f64`
- `speed`: `f64`
- `half`: `f64`

### `Scare`

```gizlang
type Scare = { at: Point3; time: f64; reach: f64; }
```

What scares the sea's life: a blow or a shot AT a place at TIME, felt within REACH meters.

- `at`: `gizlang_geometry.Point3`
- `time`: `f64`
- `reach`: `f64`

### `SeaLife`

```gizlang
class SeaLife { private scares: Vec<Scare> = []; private seen = new Set<string>(); scare(at: Point3, time: f64, reach: f64): void { this.scares = [...this.scares.filter(s => time-s.time <SCARED), { at, time, reach }]; } about(x: f64, z: f64, time: f64, kinds: Vec<SeaKind>, depth: (x: f64, z: f64) => f64, hull?: Hull): Vec<Swimmer> { return swimmers(x, z, time, kinds, depth, 84.0, this.scares, hull); } sighted(swimmers: Vec<Swimmer>, at: Point3, near: f64 = 45.0): Vec<SeaKind> { let fresh: Vec<SeaKind> = []; for (const s of swimmers) { if (this.seen.has(s.kind.name) || Math.hypot(s.at.x-at.x, s.at.z-at.z)> near) { continue; } this.seen.add(s.kind.name); fresh.push(s.kind); } return fresh; } count(): i64 { return this.seen.size; } }
```

The sea's life of one game: what scared it lately and the kinds its player has sighted.

- `scares`: `Vec<M257.Scare>`
- `seen`: `_gizlang_sdk_collections.Set<string>`

## Functions

### `seaKinds`

```gizlang
function seaKinds(celsius: f64, lat?: f64, lon?: f64): Vec<SeaKind>
```

The kinds of a sea whose water is CELSIUS warm. With LAT and LON, the kinds that live at that place of the Earth:
penguins south of the Cape, belugas in the Arctic, manatees in the Caribbean; without, the kinds of every ocean.

Effects: fail, read, write, console, io, alloc.

### `swimmers`

```gizlang
function swimmers(x: f64, z: f64, time: f64, kinds: Vec<SeaKind>, depth: (x: f64, z: f64) => f64, reach: f64 = 84.0, scares: Vec<Scare> = [], hull?: Hull): Vec<Swimmer>
```

The sea life about X, Z at TIME, of KINDS (seaKinds): the schools of the squares of sea within REACH meters, each
where it always is at that time. DEPTH says how deep the sea is at a place; a school keeps to water deeper than
it swims. What a scare of SCARES reaches dives and stays under, and the small flee from it; the kinds that ride
leave their ring for the bow of HULL while it sails near.

Effects: fail, read, write, console, io, alloc.

### `struck`

```gizlang
function struck(swimmers: Vec<Swimmer>, at: Point3, half: f64): [Swimmer, Point3] | undefined
```

The solid swimmer of SWIMMERS that a hull of HALF meters about AT meets, and the meters to push the hull off it
(x, z): a body of SOLID meters or more, near the surface, is as wide as a fifth of its length along its way.

Effects: fail.

### `seaThing`

```gizlang
function seaThing(model: string): string
```

The thing a game draws a kind of MODEL as.

Effects: fail, alloc.

## Methods

### `SeaLife.scare`

```gizlang
scare(at: Point3, time: f64, reach: f64): void
```

A blow or a shot AT a place at TIME scares what is within REACH meters.

Effects: fail, read, write, alloc.

### `SeaLife.about`

```gizlang
about(x: f64, z: f64, time: f64, kinds: Vec<SeaKind>, depth: (x: f64, z: f64) => f64, hull?: Hull): Vec<Swimmer>
```

The swimmers about X, Z at TIME (swimmers), as its scares and HULL move them.

Effects: fail, read, write, console, io, alloc.

### `SeaLife.sighted`

```gizlang
sighted(swimmers: Vec<Swimmer>, at: Point3, near: f64 = 45.0): Vec<SeaKind>
```

The kinds of SWIMMERS within NEAR meters of AT that the player sees for the first time.

Effects: fail, read, write, alloc.

### `SeaLife.count`

```gizlang
count(): i64
```

How many kinds the player has sighted.

Effects: fail, read.

## Constants

### `SOLID`

```gizlang
const SOLID: f64 = 4.0
```

The length in meters from which a body is solid to a hull: a ship that meets it is struck, not passed through.

### `SEA_THINGS`

```gizlang
const SEA_THINGS: Vec<Thing3D> = [...new Set<string>(LIFE.map((k: SeaKind): string => k.model).filter((m: string): bool => m !== ""))] .map((m: string): Thing3D => ({ name: seaThing(m), file: `${m }/model.glb`, most: 64, casts: false }))
```

The models of the sea's life, each named as its kind's thing: a game with a sea lists these among its things, and
its lock pins their files (`giz assets add LOCK polypizza:ID`).

