Set grass on fire
Make a style flammable, add foliagePack, and call ignite where the fire starts. It spreads to the cells around it, more likely downwind, uphill and through dry grass. Each cell burns for its style's burns seconds, then turns burnt.
// in src/rules.ts
import { defineCellLayer, type Entity, foliagePack, ignite, type Rules, type World } from '@v12-engine/engine'
import { rules } from './rules'
export const fireRules: Rules = {
...rules,
cellLayers: [defineCellLayer({ id: 'grass', name: 'Grass', values: [{ value: 1, name: 'Dry grass', foliage: { flammable: 1, burns: 5, regrows: 120 } }] })],
// units standing in it take 8 damage a second, dealt by whoever lit it
packs: [...(rules.packs ?? []), foliagePack({ layer: 'grass', fire: { damage: 8 } })]
}
export function torch(world: World, hero: Entity): number[] {
return ignite(world, 'grass', { kind: 'circle', x: hero.pos.x, z: hero.pos.z, radius: 1.5 }, { by: hero })
}Done: the grass around the hero catches. A front spreads out, roughly round in still air and stretched downwind in a wind, leaving black, burnt grass that grows back two minutes later.
A fire that runs with the wind and jumps gaps
import { foliagePack } from '@v12-engine/engine'
export const pack = foliagePack({
layer: 'grass',
fire: {
wind: 2, // the wind decides the way twice as much
jump: 0.6, // in a wind of 0.6 or more it jumps a gap of one cell downwind
every: 0.2, // a burning cell tries its neighbours 5 times a second
maxBurning: 3000,
lasts: 90 // every fire dies after 90 seconds
}
})The wind is the map's (world.setEnvironment({ wind: { around, strength } })).
Know what burns
import { burningCells, defineListener, foliageAt, foliageIgnited, type World } from '@v12-engine/engine'
export const heard = defineListener({
event: foliageIgnited,
id: 'mygame.fireSeen',
run(world, { cells, cause }) {
if (cause === 'ignite') world.log.info('fire', 'grass set alight', { cells: cells.length })
}
})
export function onFire(world: World, x: number, z: number): boolean {
return foliageAt(world, 'grass', x, z)?.burning ?? false
}
export const burning = (world: World): number => burningCells(world, 'grass').lengthPut listeners in Rules.listeners. A computer player can steer round burningCells.
In the editor
- In a style's Gameplay, set Flammable, Burns for (s), Fuel and Grows back after (s).
- Press Play here, open the Cheats panel, pick Grass › Ignite, and click the grass.
- Set the Wind under it to watch the front turn. View › Grass state (Shift+U) shows burning cells in orange and burnt ones in black.
- In Grass and bushes › Fire, set Flames, Smoke, Embers, Lights around, Glowing edge, Bright, Smoky, Ash, Sound and Catching, or untick Burns on the screen.
Reference
FoliageStyleDef | Default | |
|---|---|---|
flammable | 0 | 0 never catches, 1 catches as dry grass does |
burns | 6 | Seconds a cell burns |
fuel | 1 | How strongly it lights its neighbours |
regrows, grows | never, 10 | When burnt grass starts to grow back, and how long it takes |
FoliageFire fields and their defaults are in Grass and bushes. Grass on water, a road (the road tile), blocked cells and under buildings never burns. Grass that is cut, crushed or already burnt doesn't burn either. A fire runs the same on every machine, in a save and in a replay. With burningPack too, fire: { lights: true } lets burning grass set trees alight, over its tries as it spreads, not at once: see Let trees burn.
On the screen, a blade chars from its tip down over the cell's burn time, its edge glowing, and ends as black stubble over ash that fades as the grass grows back; bushes char and lose their leaves. Flames (at most 32 a layer, nearest the camera), smoke leaning with the wind, embers, up to four lights (only at the high quality of lights) and a crackle play along the front where the player sees it. Change or turn off each part in the look's fire group:
import { foliage } from '@v12-engine/client'
export const look = foliage({ fire: { smoke: false, scorch: 0.6 }, styles: { 2: { fire: { bright: 1.4 } } } })