Stop a fire spreading
Call extinguish to put out what burns in an area, firebreak to cut a strip the fire can't cross, or stopFire to put out every fire at once. To decide cell by cell what may catch, use the foliageIgnite hook.
// anywhere in your rules
import { extinguish, firebreak, stopFire, type World } from '@v12-engine/engine'
export function fightFire(world: World): void {
extinguish(world, 'grass', { kind: 'circle', x: 30, z: 30, radius: 4 }) // what burns here stops, left burnt
firebreak(world, 'grass', { kind: 'rect', x: 40, z: 30, width: 2, depth: 24 }) // cut to stubble
if (world.tick > 30 * 60 * 5) stopFire(world, 'grass') // after five minutes, every fire of the layer
}Done: the fire dies inside the circle, stops at the cut strip, and after five minutes nothing burns.
A firebreak cut ahead of a front
Cut a line across the wind, a few cells downwind of what burns now:
import { burningCells, exactMath, firebreak, type World } from '@v12-engine/engine'
export function breakAhead(world: World, around: number, ahead = 6): number[] {
const cells = burningCells(world, 'grass')
if (!cells.length) return []
const { width } = world.terrain
let x = 0
let z = 0
for (const cell of cells) {
x += (cell % width) + 0.5
z += Math.floor(cell / width) + 0.5
}
x /= cells.length
z /= cells.length
// the way the wind blows, as the map's wind says it (degrees from north, clockwise); the same on every machine
const way = { x: exactMath.sin((around * Math.PI) / 180), z: -exactMath.cos((around * Math.PI) / 180) }
const cut: number[] = []
for (let i = -8; i <= 8; i++) {
const cx = Math.floor(x + way.x * ahead - way.z * i)
const cz = Math.floor(z + way.z * ahead + way.x * i)
if (cx >= 0 && cz >= 0 && cx < width && cz < world.terrain.depth) cut.push(cz * width + cx)
}
return firebreak(world, 'grass', cut)
}In a strong wind a fire with fire.jump set can jump a one-cell break, so cut two cells wide where that matters.
A rain spell that puts a fire out
import type { AbilityDef } from '@v12-engine/engine'
export const rain: AbilityDef = {
id: 'rain',
name: 'Rain',
target: 'point',
range: 12,
cooldown: 40,
effects: [{ type: 'foliage', act: 'extinguish', radius: 7 }]
}Real weather works too: rain or snow in the map's environment damps every fire and puts burning cells out a little at a time, unless the pack says fire: { weather: false }.
import type { World } from '@v12-engine/engine'
export const storm = (world: World): void => world.setEnvironment({ weather: { kind: 'rain', amount: 0.9 } }, { over: 4 })Refuse or slow a catch
import { defineHook, foliageIgnite } from '@v12-engine/engine'
export const blessedGrove = defineHook({
hook: foliageIgnite,
id: 'mygame.blessedGrove',
run(_world, event) {
if (event.x > 60 && event.z < 20) event.cancel() // the grove never burns
else if (event.cause === 'spread') event.chance *= 0.5 // everything else catches half as often
}
})Put it in Rules.hooks. The hook runs for every cell a fire tries, so keep it quick.
In the editor
- Press Play here, open the Cheats panel › Grass.
- Pick Extinguish or Cut, set How far round, and drag over the fire.
- Set a style's Flammable to 0 under Gameplay to make grass that never burns.
Reference
| Way | What it does |
|---|---|
extinguish(world, layer, where) | Puts out what burns there; the cells stay burnt |
firebreak(world, layer, where, { by }) | Cuts to stubble, which doesn't burn |
stopFire(world, layer?) | Puts out every fire of a layer, or of every layer of the pack |
foliageIgnite | A hook before each catch: cancel(), or change chance |
fire.spread: false | Only what is set alight burns |
fire.maxBurning | At most this many cells burn at once (4000); the rest wait their turn |
fire.lasts | Every fire dies after so many seconds |
fire.wet, fire.weather | Everything damp; rain and snow put it out |
flammable: 0 | A style that never burns |
foliage effect, act: 'extinguish' | An ability that puts it out |
foliageFireOut tells you when the last fire of a layer goes out.