# "Cookbook: blasts, craters and digging"

# Cookbook: blasts, craters and digging

The guides behind these: explosions (skill `ferret-physics-combustion-explosions`), [terrain](../reference/terrain.md). Each recipe says what to build and what to expect; the runnable versions, with the numbers they must produce, are in `tests/unit/examples/physics-cookbook-blasts-and-ground.test.ts`.

## 1. Danger rings for a charge

How far must the player stand? Overpressure falls with distance by the scaled law, so a ring for each level of harm is one call:

```ts
const lethal  = radiusFor(200e3, 5);     // radius in metres where a 5 kg charge gives 200 kPa
const eardrum = radiusFor(35e3, 5);
const glass   = radiusFor(2e3, 5);
const there   = blastAt(eardrum, 5).overpressure;
```

Higher pressure, smaller ring. Eight times the charge gives twice the radius. Draw the rings on the ground as the player's warning, or apply `explosion:exposure` damage by pressure band.

## 2. A crater in sand, and in rock

The crater radius is `k W^(1/3.4)`; the constant `k` is a property of the soil. Rock gives a small crater, sand a wide one, and a bigger charge opens a bigger one slowly: ten times the charge gives `10^(1/3.4)` times the radius.

```ts
const sand = craterRadius(EXAMPLE_CRATERS.sand, 50);
const rock = craterRadius(EXAMPLE_CRATERS.rock, 50);
```

Plug in your own `CraterLaw` (`k`, `depthRatio`, `camouflet`, `throw`) per soil with `explosions({ craters })`.

## 3. A charge buried too deep

Bury it and the ground swallows the blast; deep enough and **no crater opens at all**: a camouflet. A mine works by being shallow; a mining charge by being deep.

```ts
craterRadius(law, 10, 0);                                       // on the surface
craterRadius(law, 10, 0.5);                                     // slightly buried: bigger, the ground couples the blast
craterRadius(law, 10, law.camouflet * Math.cbrt(10) * 1.01);    // past the limit: 0
```

In a world, `detonate({ burst: 'buried', burial })` returns `camouflet: true` for the deep case and emits `explosion:camouflet`; the terrain stays flat.

## 4. A crater in a real terrain

Hook a terrain to the capability and a surface burst excavates it; the heap that is thrown out equals the hole times the soil's bulking, so no matter is lost.

```ts
const ground = new Terrain({ nx: 121, nz: 121, cell: 0.25, soils: new SoilLibrary(EXAMPLE_SOILS),
                             strata: [{ soil: 'sand', thickness: 5 }] });
const blast = explosions({ terrain: ground });
host.register(blast);
host.enable('explosion');
const result = blast.detonate({ at: [15, 5, 15], tnt: 50, burst: 'surface' });
```

`result.crater` has the radius, the depth and the volume removed. The `explosion:crater` event carries the speed at the rim and the range of the fastest ejecta. See [terrain](../reference/terrain.md) for what the ground does next: the sides slump to their angle of repose.

## 5. A wall that shields

A body between the charge and a target blocks the rays; the target receives only the `transmission` share (0.1 by default). Two bodies at equal distance, one with a static shield in front of it:

```ts
make('open', -10); make('hidden', 10); make('shield', 5, 'static', 2);
blast.detonate({ at: [0, 0, 0], tnt: 10 });
```

The open one receives the impulse the blast law gives times its cross-section; the hidden one a tenth of it. A thin screen has a `transmission` of 0.5, a bunker door 0.01. Set it per entity.

## 6. Water carries a blast further

Water is almost incompressible, so an underwater burst gives a much higher pressure at the same distance, and the front travels at 1480 m/s:

```ts
const air = blastAt(20, 10), water = underwaterAt(20, 10);
```

`detonate({ burst: 'water' })` uses the liquid curve for everything in range: a hull is pushed far harder than the same charge in air would push it, which is why depth charges work.

## 7. A trench that holds, and one that slumps

A vertical cut in cohesive soil stands to the critical height `(4c/γ) tan(45° + φ/2)`; deeper and the walls slump. Dry sand stands no vertical cut at all.

```ts
const limit = criticalHeight(clay);
const result = terrain.dig({ footprint: { box: [4, 4, 6, 6] }, depth: 0.9 * limit, tool, dt: 1 });
result.slump.moved;        // 0 at 90 % of the limit, more than 0 at 110 %
```

`DigResult.slump` reports what the walls did after the dig. Use `criticalHeight` and `culmannHeight` (for a sloped face) in your own tool tips: *"this trench will fail at 1.6 m"*. Shore it up (a lined tunnel, a wall) and it stands.
