@adatechnology/game-terrain 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,13 +12,18 @@ terrain.heightAt(x, z) // what things stand on
12
12
 
13
13
  ## What it does
14
14
 
15
- - **Profiles** (`TERRAIN_PROFILES`, replace or add through `profiles`): `lawn` (turf 5 cm, soil 1.5 m, rock), `dirt`, `sand`, `road` (asphalt 5 cm, gravel, soil), `concrete_slab` (12 cm with rebar at 3 cm), `tile_floor` (tile, mortar, slab), `wood_floor`, `stone_paving`.
15
+ - **Profiles** (`TERRAIN_PROFILES`, replace or add through `profiles`): `lawn` (turf 5 cm, soil 1.5 m, rock), `dirt`, `sand`, `road` (asphalt 5 cm, gravel, soil), `concrete_slab` (12 cm with rebar at 3 cm), `tile_floor` (tile, mortar, slab), `wood_floor`, `stone_paving`, `mud`, `gravel_bed`, `dry_clay`, `snow`, `cobblestone`, `paver_floor`, `shallow_water`.
16
16
  - **Digging**: a blow removes `energy / specificEnergy` cubic metres (`TERRAIN_MATERIALS`, per blow type: ballistic, blunt, slash, explosive) as a bowl with the shape of the material. It takes the top stratum and spends what is left on the next. The strata end at the digging limit: **a slab is never pierced**, and a crater has a floor.
17
17
  - **Bars**: bare bars bend with each blow and give way at `yieldJoules`. A slab on the ground stays the floor; `suspended_slab` (`TerrainProfile.drop`) opens onto the floor below.
18
18
  - **Fine marks**: a bowl under 1.5 cells stays a mark, not a change of the height field. Blows on the same mark grow it until it is dug in.
19
19
  - **Budget** (`budget`): marks per area and in total (past it the closest two merge, then the oldest goes), thrown pieces, chunks redrawn per frame, cells checked for sliding, cells on fire.
20
20
  - **What comes out**: soft ground heaps a rim and throws clods that land and join the height field, so they can be walked over; rigid material throws chips that stay as rubble. Loose ground slides to its angle of repose.
21
21
  - **Fire**: `fire` of each material says how black it gets and whether it burns away and spreads: turf and wood char and carry the fire, concrete only soots.
22
+ - **Feet** (`footing` of a material): `footAt` is the height a foot stands at, `walkFactorAt` what is left of the speed, `press` the print it leaves (`createFootprints` keeps the trail of a walker, a wheel presses with `kind: 'rut'`).
23
+ - **Decals** (`decals()`): marks with no depth, under `budget.maxDecals`: cracks of a brittle crust (`cracks`), splats where the pieces of a wet ground land (`splats`), prints and ruts, rings on water.
24
+ - **Pieces** (`units` of a material): cobbles and pavers are not dug. A blow adds to the joules each piece has taken, and past `looseJoules` the piece comes off its bed whole and is thrown, showing the sand under it.
25
+ - **Loose stones** (`scatters`): gravel throws stones that stay as loose stones instead of joining the height field.
26
+ - **Water** (`water` of a profile): everything stands on the bed, which banks up to the shore. `waterAt` says the level; a blow reaches the bed with `blowShare` of its energy and reports `result.water`, so that the surface splashes and shows no crater while the bed is dug. It does not burn. `waterLift` is Archimedes for whatever is in it.
22
27
  - `serialize()` / `load()`: only what changed, as plain JSON.
23
28
 
24
29
  Draw it with [`@adatechnology/game-terrain-three`](../game-terrain-three). The test room's floor is one of these.
@@ -26,3 +31,5 @@ Draw it with [`@adatechnology/game-terrain-three`](../game-terrain-three). The t
26
31
  ## Português
27
32
 
28
33
  Chão deformável: mapa de altura em chunks com estratos por coluna, cada estrato um material do catálogo de destruição. O golpe escava o estrato de cima e só passa ao de baixo quando ele acaba; a laje no chão nunca é atravessada e a cratera tem fundo. Vergalhão exposto entorta a cada golpe e cede; laje sobre vão (`suspended_slab`) abre para o andar de baixo. Marcas finas de tiro com limite por área (fundem, depois reciclam a mais antiga); a terra removida vira borda e torrões que caem e somam na altura; areia escorrega até o ângulo de repouso; grama e madeira carbonizam e o fogo se espalha, concreto só escurece.
34
+
35
+ Lama afunda o pé, espirra e deixa pegada; a explosão espalha lama pelo chão em volta. Cascalho solta pedrinhas e faz pouca cratera. Barro seco racha. Neve guarda pegada e o fogo a derrete até a terra. Paralelepípedo e bloquete soltam peças inteiras, que deixam a areia à vista. Água rasa espirra sem cratera na superfície, escava o fundo, não pega fogo, e o que é mais leve que ela boia.
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ interface TerrainBlowResponse {
14
14
  /** The bowl is never narrower: a tile comes off as a piece, not as the size of the bullet. */
15
15
  readonly minRadius?: number;
16
16
  }
17
- type TerrainDebrisKind = 'clods' | 'chips' | 'shards' | 'splinters' | 'dust';
17
+ type TerrainDebrisKind = 'clods' | 'chips' | 'shards' | 'splinters' | 'dust' | 'blocks';
18
18
  /** How a material of the destruction catalogue behaves as ground. `id` is the catalogue's. */
19
19
  interface TerrainMaterial {
20
20
  readonly id: string;
@@ -33,6 +33,18 @@ interface TerrainMaterial {
33
33
  readonly crack?: TerrainCrackResponse;
34
34
  /** A rigid layer a contact charge breaks right through once it has enough for the whole thickness (the scabbing of a slab): `explosive` only. */
35
35
  readonly breach?: TerrainBreachResponse;
36
+ /** What a foot does on it. */
37
+ readonly footing?: TerrainFooting;
38
+ /** Liquid (of the fluids catalogue) a blow on it throws up. */
39
+ readonly splash?: string;
40
+ /** Its pieces do not join the ground where they land: they stay as loose stones. */
41
+ readonly scatters?: boolean;
42
+ /** Its pieces leave a splat on whatever they land on. */
43
+ readonly splats?: boolean;
44
+ /** A brittle crust: each blow runs cracks this many bowl radii around it. */
45
+ readonly cracks?: number;
46
+ /** Laid in separate pieces on a bed: a blow loosens whole pieces instead of digging a bowl. */
47
+ readonly units?: TerrainUnits;
36
48
  }
37
49
  interface TerrainCrackResponse {
38
50
  /** Metres the longest line runs for a blow of 1 MJ; it grows with the cube root of the energy. */
@@ -48,6 +60,22 @@ interface TerrainBreachResponse {
48
60
  /** Radius of the breach over the thickness at that energy; it grows with the cube root of the excess. */
49
61
  readonly radiusOverThickness: number;
50
62
  }
63
+ interface TerrainFooting {
64
+ /** Metres the foot goes in. */
65
+ readonly sink: number;
66
+ /** What is left of the walking speed, 0..1. */
67
+ readonly drag: number;
68
+ /** Keeps the print of what presses it. */
69
+ readonly prints?: boolean;
70
+ }
71
+ interface TerrainUnits {
72
+ /** Metres along x, in rows that shift every other one. Multiples of the cell keep the hole sharp. */
73
+ readonly length: number;
74
+ /** Metres along z. */
75
+ readonly width: number;
76
+ /** Joules a piece takes, added blow by blow, before it comes off its bed. */
77
+ readonly looseJoules: number;
78
+ }
51
79
  interface TerrainFireResponse {
52
80
  /** How black it gets, 0..1: concrete only soots, wood and turf char through. */
53
81
  readonly maxScorch: number;
@@ -58,7 +86,7 @@ interface TerrainFireResponse {
58
86
  /** Catches and carries the fire to the next cells on its own. */
59
87
  readonly flammable?: boolean;
60
88
  }
61
- declare const TERRAIN_PATTERNS: readonly ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone"];
89
+ declare const TERRAIN_PATTERNS: readonly ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone", "mud", "gravel", "clay", "snow", "cobble", "paver"];
62
90
  type TerrainPattern = (typeof TERRAIN_PATTERNS)[number];
63
91
  /** One layer of a column, from the top down. */
64
92
  interface TerrainStratum {
@@ -82,6 +110,18 @@ interface TerrainProfile {
82
110
  readonly strata: readonly TerrainStratum[];
83
111
  /** A slab with nothing under it: where its bars give way the floor opens, and the ground is this many metres further down (the floor below). Without it the ground under the slab holds it up. */
84
112
  readonly drop?: number;
113
+ /** Water standing over the column: the strata are its bed. */
114
+ readonly water?: TerrainWater;
115
+ }
116
+ interface TerrainWater {
117
+ /** A liquid of the fluids catalogue. */
118
+ readonly liquid: string;
119
+ /** Metres from the surface to the bed. */
120
+ readonly depth: number;
121
+ /** What is left of the walking speed, 0..1. */
122
+ readonly drag: number;
123
+ /** Share of a blow that reaches the bed. */
124
+ readonly blowShare: Partial<Record<TerrainBlow, number>>;
85
125
  }
86
126
  interface TerrainBudget {
87
127
  /** Side in metres of the squares that hold a limited number of marks. */
@@ -99,6 +139,8 @@ interface TerrainBudget {
99
139
  readonly maxBurningCells: number;
100
140
  /** Stars of cracks kept; past it the oldest goes. */
101
141
  readonly maxCracks: number;
142
+ /** Cracks, prints, ruts, splats and ripples at once; past it the oldest goes. */
143
+ readonly maxDecals: number;
102
144
  }
103
145
  interface TerrainOptions {
104
146
  /** World rectangle `[x0, z0, x1, z1]` in metres. */
@@ -135,6 +177,21 @@ interface TerrainMark {
135
177
  /** Order of creation: the oldest is the one recycled. */
136
178
  born: number;
137
179
  }
180
+ type TerrainDecalKind = 'crack' | 'print' | 'rut' | 'splat' | 'ripple';
181
+ /** A mark with no depth of its own: drawn over the surface, it changes nothing that stands there. */
182
+ interface TerrainDecal {
183
+ readonly id: number;
184
+ readonly kind: TerrainDecalKind;
185
+ readonly x: number;
186
+ readonly z: number;
187
+ readonly radius: number;
188
+ /** Radians around y. */
189
+ readonly angle: number;
190
+ /** The material whose colour it takes. */
191
+ readonly material: string;
192
+ /** Seconds it has been there; a ripple fades with it. */
193
+ age: number;
194
+ }
138
195
  interface TerrainDebris {
139
196
  readonly id: number;
140
197
  readonly material: string;
@@ -191,6 +248,17 @@ interface TerrainBlowResult {
191
248
  readonly crack?: TerrainCrack;
192
249
  /** A contact charge broke the rigid layer right through (`TerrainMaterial.breach`). */
193
250
  readonly breached?: boolean;
251
+ /** The water the blow crossed: `level` is where the splash goes up. */
252
+ readonly water?: {
253
+ readonly liquid: string;
254
+ readonly level: number;
255
+ };
256
+ }
257
+ /** The water standing at a point. */
258
+ interface TerrainWaterHere {
259
+ readonly liquid: string;
260
+ readonly level: number;
261
+ readonly depth: number;
194
262
  }
195
263
  interface TerrainRegion {
196
264
  readonly x: number;
@@ -281,6 +349,25 @@ interface Terrain {
281
349
  }): void;
282
350
  /** Applies a world hit (`Hit` of the destruction contract); null when it does nothing to the ground. */
283
351
  applyHit(hit: Hit): TerrainBlowResult | null;
352
+ /** Height a foot stands at: the ground less what it sinks in. */
353
+ footAt(x: number, z: number): number;
354
+ /** What is left of the walking speed here, 0..1. */
355
+ walkFactorAt(x: number, z: number): number;
356
+ /** The water standing here, or null. */
357
+ waterAt(x: number, z: number): TerrainWaterHere | null;
358
+ /** A foot or a wheel on the ground: it leaves its print where the ground keeps one, a ripple in water. False where it leaves nothing. */
359
+ press(spec: {
360
+ x: number;
361
+ z: number;
362
+ radius: number;
363
+ angle?: number;
364
+ kind?: 'print' | 'rut';
365
+ }): boolean;
366
+ /** Rings on the water at (x, z). */
367
+ ripple(x: number, z: number, radius: number): void;
368
+ decals(): readonly TerrainDecal[];
369
+ /** Goes up when the decals change. */
370
+ readonly decalsVersion: number;
284
371
  /** Follow the ground changing: `region` is the disc it changed in. What rests there has lost its support and must look again. Returns the unsubscribe function. */
285
372
  onDeform(listener: (region: TerrainRegion) => void): () => void;
286
373
  /** Moves the pieces, the sliding ground and the fire. */
@@ -313,6 +400,7 @@ interface TerrainSnapshot {
313
400
  readonly barBend?: readonly (readonly [number, number])[];
314
401
  readonly marks: readonly TerrainMark[];
315
402
  readonly cracks?: readonly TerrainCrack[];
403
+ readonly decals?: readonly TerrainDecal[];
316
404
  }
317
405
 
318
406
  declare const DEFAULT_TERRAIN_BUDGET: TerrainBudget;
@@ -354,4 +442,37 @@ interface CrackSegment {
354
442
  */
355
443
  declare function crackLines(crack: TerrainCrack): CrackSegment[];
356
444
 
357
- export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_YIELD_JOULES, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainFireResponse, type TerrainImplOptions, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, crackLines, createTerrain, createTerrainImpl };
445
+ interface Footprints {
446
+ /** Call as the walker moves; it leaves a print each stride, left and right in turn. */
447
+ update(x: number, z: number): void;
448
+ reset(): void;
449
+ }
450
+ /** The trail of something walking: whoever moves on the ground reports where it is, and the ground keeps the prints it can keep. */
451
+ declare function createFootprints(terrain: Terrain, options?: {
452
+ readonly stride?: number;
453
+ readonly footLength?: number;
454
+ }): Footprints;
455
+
456
+ interface WaterLiftParams {
457
+ /** Kilograms. */
458
+ readonly mass: number;
459
+ /** Cubic metres of the whole body. */
460
+ readonly volume: number;
461
+ /** Share of the body under the surface, 0..1. */
462
+ readonly submerged: number;
463
+ /** Kilograms per cubic metre of the liquid. */
464
+ readonly liquidDensity?: number;
465
+ readonly gravity?: number;
466
+ }
467
+ interface WaterLift {
468
+ /** Upward metres per second squared the liquid gives the body. */
469
+ readonly acceleration: number;
470
+ /** Per second, the part of the speed the liquid takes. */
471
+ readonly drag: number;
472
+ /** Lighter than the liquid it displaces. */
473
+ readonly floats: boolean;
474
+ }
475
+ /** Archimedes on a body in a liquid: what it displaces lifts it, so a light log floats and a concrete block goes to the bed. */
476
+ declare function waterLift(params: WaterLiftParams): WaterLift;
477
+
478
+ export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_YIELD_JOULES, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, type Footprints, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainDecal, type TerrainDecalKind, type TerrainFireResponse, type TerrainFooting, type TerrainImplOptions, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, type TerrainUnits, type TerrainWater, type TerrainWaterHere, type WaterLift, type WaterLiftParams, crackLines, createFootprints, createTerrain, createTerrainImpl, waterLift };