Skip to content

Grass and bushes ​

New to grass?

Start at the Grass and bushes section: an overview, every setting with examples, and a cookbook of real-world recipes. This page is the reference: every field, call and event in one place.

Cover the ground with grass and bushes that sway in the wind, part as units walk through, hide who stands in them, and can be cut, trampled, burnt and grown back. Grass is a layer of cells; each value painted on it is a style with its own look and its own rules.

ts
// in src/rules.ts: add `cellLayers` and `packs` to the `createGame` call, and paint a field as the game starts
import { createGame, defineCellLayer, foliagePack, presetFoliageStyles } from '@v12-engine/engine'

export const game = createGame({
	id: 'my-game',
	name: 'My game',
	cellLayers: [defineCellLayer({ id: 'grass', name: 'Grass', values: [{ value: 1, name: 'Meadow', foliage: presetFoliageStyles.meadow }] })],
	packs: [foliagePack({ layer: 'grass' })]
})
game.onStart((world) => {
	world.setCells('grass', { kind: 'circle', x: 16, z: 16, radius: 12 }, 1)
})
ts
// in src/view.ts: in `ground`, how the layer is drawn
import { foliage, type GameView, presetFoliage } from '@v12-engine/client'

export const ground: GameView['ground'] = { cellLayers: { grass: foliage(presetFoliage.meadow) } }

Done: a round meadow with a few flowers covers the middle of the empty starter's field, sways in the wind and parts round your scout. It burns if something lights it, and grows back 90 seconds after.

The two halves never meet. The rules half (FoliageStyleDef, on the layer's values, and foliagePack) says what a style hides, slows and how it burns; it is the same on every machine. The look half (FoliageLook, given to foliage) says how it is drawn; it is the screen's alone. A game that only wants grass to look at can leave the pack out.

A look of your own ​

Grass is read by groups: shape, sizes, rotation, colors, placing, light, levels, wind, walked, ruined. Every field has a default, so say only what you change.

ts
import { foliage } from '@v12-engine/client'

export const grass = foliage({
	height: 1.4, // world units
	density: 6, // tufts a cell
	seed: 3, // the same seed lays the same field on every screen
	shape: { kind: 'blade', blades: 4, curve: 0.4, droop: 0.2 },
	sizes: { each: [0.7, 1.3], edge: { cells: 2, to: 0.5 } }, // smaller towards the edge of a patch
	rotation: { lean: 12, leanTo: 'wind' },
	colors: { foot: [0.18, 0.38, 0.1], tip: [0.6, 0.72, 0.3], vary: 0.15, patches: { amount: 0.5, to: [0.7, 0.6, 0.3] } },
	placing: { clump: { amount: 0.6 }, slope: [0, 35], notTiles: ['sand'] },
	light: { translucency: 0.4, footFade: 0.2 }
})

A blade field that clumps, with dry patches, and none on sand or on slopes over 35°. Grass keeps off water, cliff walls, buildings and scenery that blocks by itself (placing.keepOff). It grows on the road tile unless you ask: placing: { keepOff: { roads: true } }.

A look can be a function of the part's context, for one that needs the map:

ts
import { foliage } from '@v12-engine/client'

export const sparse = foliage(({ terrain }) => ({ density: terrain.width > 200 ? 2 : 4 }))

Two patches with different settings ​

Each value of the layer is a style. Its rules go on the value (foliage), its look in styles under the same number; what a style does not say is the layer's.

ts
import { defineCellLayer, foliagePack, presetFoliageStyles, type Rules, setFoliage, type World } from '@v12-engine/engine'
import { foliage, presetFoliage } from '@v12-engine/client'

declare const rules: Rules
declare const world: World

export const grassRules: Rules = {
	...rules,
	cellLayers: [
		defineCellLayer({
			id: 'grass',
			name: 'Grass',
			values: [
				{ value: 1, name: 'Meadow', foliage: presetFoliageStyles.meadow },
				{ value: 2, name: 'Tall grass', foliage: presetFoliageStyles.tallGrass }
			]
		})
	],
	packs: [...(rules.packs ?? []), foliagePack({ layer: 'grass' })]
}

export const grass = foliage({ ...presetFoliage.meadow, styles: { 2: presetFoliage.tallGrass } })

// a patch of tall grass, painted in play (checked: a value the layer has, or 0)
setFoliage(world, 'grass', { kind: 'rect', x: 40, z: 30, width: 10, depth: 6 }, 2)

Up to 255 styles a layer. Paint them on the map in the editor, in the map file (GameMap.cells), or with world.setCells and setFoliage. A value the game doesn't name is drawn as the layer and is nothing to the rules.

Bushes from your models ​

draw: 'models' (or just models) draws your models in place of grass, picked by weight, each turned, sized and leaned its own way.

ts
import { foliage } from '@v12-engine/client'

export const bushes = foliage({
	models: [{ src: 'forest/bush_common_flowers.glb' }, { src: 'forest/bush_common.glb', weight: 0.2 }], // a few with red leaves, as in autumn
	density: 0.8, // models a cell: a part of one is a chance of one
	height: 1.2,
	shadow: 'near' // cast shadows near the camera only
})

See Make bushes of my own for the rest.

Grass and bushes on one layer ​

A style draws grass or models, so one layer holds a meadow and a thicket side by side:

ts
import { foliage } from '@v12-engine/client'

export const mixed = foliage({
	density: 4, // value 1: grass
	styles: { 2: { draw: 'models', models: [{ src: 'forest/bush_common_flowers.glb' }], density: 0.7, colors: { tint: [0.9, 1, 0.8] } } },
	levels: { mid: 60, far: 100, cull: 160 }
})

Ready-made kinds ​

presetFoliage (looks) and presetFoliageStyles (rules) share their names: meadow, tallGrass, dryGrass, reeds, wheat, snowGrass, thicket, hedge. Take one whole, or change what you want.

ts
import { defineCellLayer, presetFoliageStyles } from '@v12-engine/engine'
import { foliage, presetFoliage } from '@v12-engine/client'

export const layer = defineCellLayer({
	id: 'grass',
	name: 'Grass',
	values: [
		{ value: 1, name: 'Wheat', foliage: { ...presetFoliageStyles.wheat, trample: 'none' } },
		{ value: 2, name: 'Reeds', foliage: presetFoliageStyles.reeds }
	]
})
export const look = foliage({ ...presetFoliage.wheat, styles: { 2: presetFoliage.reeds } })
NameLooksTo the rules
meadowshort blades, a few flowersburns, grows back after 90 s
tallGrass1.4 tall, droopinghides (1.4 tall), burns, grows back after 120 s
dryGrassshort, straw-colouredburns fast and hot, grows back after 150 s
reeds1.8 tall, stiff, brown heads; grows in waterhides, slows to 0.85, burns a little
wheatdense, gold, leans downwindhides units up to 1.1 tall, burns, crushed underfoot
snowGrassshort, pale patcheshardly burns, grows back after 180 s
thicketwide dark tufts, red berrieshides, slows to 0.6, burns long
hedgedense, stiffhides, nothing walks through it

All of them are grass made in code; thicket and hedge are not models.

Grass from ground tiles ​

on grows grass wherever the ground is painted with some tiles, kept in step as they are painted. It is the screen's alone: short and cheap by default, it hides nobody and never burns.

ts
import { foliage } from '@v12-engine/client'

export const grass = foliage({ density: 4, on: { tiles: ['grass', 'darkGrass'], density: 1, height: 0.6 } })

A cell painted with the layer wins over its tile. Grown cells are drawn as style 255 (FOLIAGE_TILE_STYLE: give it a look in styles[255]), or as on.style. For the rules to see them, paint them into the layer once as the world begins:

ts
import { growOnTiles, type World } from '@v12-engine/engine'

declare const world: World

// from now on these cells hide and burn as style 1 says; a tile painted later grows nothing to the rules
growOnTiles(world, 'grass', ['grass', 'darkGrass'], 1)

Flowers ​

scatter mixes small plants into a style of grass, laid in the same chunks. They sway, burn and are cut with it.

ts
import { foliage } from '@v12-engine/client'

export const meadow = foliage({
	scatter: [
		{ density: 0.15, height: 0.5, colors: [[0.95, 0.88, 0.35], [0.85, 0.4, 0.62]] }, // a flower's head on a short tuft
		{ density: 0.05, src: 'plants/fern.glb' } // a model of yours
	]
})

See-through grass ​

Any colour of the grass can say how much of it is seen: a fourth number, from 0 (not at all) to 1 (whole). A colour of three is whole, as it always was.

ts
import { foliage } from '@v12-engine/client'

export const fading = foliage({
	colors: { foot: [0.2, 0.42, 0.12], tip: [0.55, 0.72, 0.28, 0.2] }, // blades that fade out towards their tips
	styles: { 2: { colors: { tint: [1, 1, 1, 0.5] } } } // a style half seen, its bushes too
})

What each colour's fourth means:

ColourIts fourth
foot, tip, stopsHow much is seen at the foot, the tip and between: blades that fade towards the tip, or rise out of nothing
tintHow much of the whole style is seen, grass and models
patches.to, dry.toTurned towards as far as the colour is: thin patches, grass that dries to nothing
ruined.crushed, ruined.burntHow much of crushed (and cut) grass and of what is charred is seen
scatter coloursHow much of each kind of flower is seen

The glow of what burns (fire.color) and a light's colour (fire.light.color) take three numbers: they are light added, not a surface. How bright they are is fire.bright.

What is partly seen is drawn by leaving out a fixed pattern of its pixels, as the grass around your own units is seen through: nothing is sorted or blended, and the pattern stays put as the camera moves. Blades over each other leave out different pixels, so a thick field still covers more than a thin one. A colour that is whole costs nothing more. Changing only how much of the foot, tip, tint, crushed or burnt is seen lays nothing again; changing a patch's lays the chunks of that style. Bushes take the tint's and the patches': shadows they cast stay whole.

Wind and gusts ​

The map's wind (MapEnvironment.wind) rolls waves of bend downwind over a field. Each style answers in its own way (wind), and a gust bends grass at one place.

ts
import { gust, type World } from '@v12-engine/engine'
import { foliage, type GameClient } from '@v12-engine/client'

declare const world: World
declare const client: GameClient

export const look = foliage({
	wind: { stiffness: 0.2, waves: 1.2, sheen: 0.4 }, // a soft meadow
	styles: { 2: { wind: { stiffness: 0.9, waves: 0.2, flutter: 0 } } } // reeds that hardly move
})
// a storm gets up over 5 seconds
world.setEnvironment({ wind: { around: 90, strength: 1 } }, { over: 5 })
// a ring of wind out from a blast, on every screen that sees it
gust(world, { x: 20, z: 20 }, { radius: 6, strength: 1.5 })
// a push one way, on this screen alone
client.gust({ x: 20, z: 20 }, { radius: 4, strength: 1, around: 90, lasts: 1 })

A gust from every explosion of a barrel, as a game ships it:

ts
import { defineListener, entityDied, gust } from '@v12-engine/engine'

export const blast = defineListener({
	event: entityDied,
	id: 'mygame.barrelBlast',
	run(world, { entity }) {
		if (entity.def.id === 'barrel') gust(world, { x: entity.pos.x, z: entity.pos.z }, { radius: 7, strength: 2, lasts: 0.8 })
	}
})

Put it in Rules.listeners. Four gusts blow at once at most; another takes the place of the one nearest its end. A gust changes nothing of the world and is not saved. See Make grass follow the wind.

Hide units ​

A style with conceals hides who stands in it from the teams that have nobody in the same patch (connected cells of hiding grass) and nobody within reach (2 cells).

ts
import { defineCellLayer, foliagePack, type Rules } from '@v12-engine/engine'

declare const rules: Rules

export const hidingRules: Rules = {
	...rules,
	cellLayers: [
		defineCellLayer({
			id: 'grass',
			name: 'Grass',
			values: [
				{ value: 1, name: 'Meadow' },
				{ value: 2, name: 'Tall grass', foliage: { conceals: true, height: 2 } },
				// a unit taller than 1.2 (twice its radius) is seen over it
				{ value: 3, name: 'Reeds', foliage: { conceals: true, concealsTaller: false, height: 1.2 } }
			]
		})
	],
	// the hiding unit's moves shake the grass on the screens of those who don't see it
	packs: [...(rules.packs ?? []), foliagePack({ layer: 'grass', conceal: { rustle: true, reach: 1.5 } })]
}

Grass that is cut, burnt, burning or crushed hides nobody; growing grass hides again. See Hide units in tall grass.

Walked on, and trails ​

Every unit you see parts the grass, however many there are. With walked.flatten the grass lies down under feet and stands up again over recover seconds, leaving a trail behind who moves. It is your screen's alone.

ts
import { foliage } from '@v12-engine/client'

export const look = foliage({
	walked: { bend: 1, flatten: 0.7, recover: 12, radius: 'size' },
	// wheat stays down until it is grown again; reeds spring back and leave no trail
	styles: { 2: { walked: { recover: 0 } }, 3: { walked: { flatten: 0.3, trail: false } } }
})

See Leave trails in grass.

Trampling, and grass nothing walks through ​

To have the rules crush a style for good, give it trample: 'crush': a unit that moves over it lays it flat (state flattened), and it hides nobody until it grows back. walkable: false makes a style the ways go round, as a wall.

ts
import { defineCellLayer, foliagePack, type Rules } from '@v12-engine/engine'

declare const rules: Rules

export const fieldRules: Rules = {
	...rules,
	cellLayers: [
		defineCellLayer({
			id: 'grass',
			name: 'Grass',
			values: [
				{ value: 1, name: 'Wheat', foliage: { conceals: true, trample: 'crush', regrows: 60 } },
				{ value: 2, name: 'Hedge', foliage: { walkable: false } }
			]
		})
	],
	// only the big ones crush wheat; every unit that walks when left out
	packs: [...(rules.packs ?? []), foliagePack({ layer: 'grass', tramples: (_world, unit) => unit.def.radius >= 1 })]
}

See Cut or crush grass.

Ruin and regrow ​

ruin cuts (cut: stubble, a firebreak), crushes (crush: laid flat) or scorches (scorch: black, nothing left to burn). regrow brings it back; a style that regrows comes back by itself.

ts
import { regrow, ruin, type Entity, type World } from '@v12-engine/engine'

declare const world: World
declare const mower: Entity

const lawn = { kind: 'rect', x: 32, z: 32, width: 12, depth: 8 } as const
ruin(world, 'grass', lawn, { how: 'cut', by: mower })
// later: it rises from the ground over 20 seconds
regrow(world, 'grass', lawn, { over: 20 })

A mower that cuts the grass it drives over, as a game ships it:

ts
import { ruin, type System } from '@v12-engine/engine'

export const mowing: System = {
	name: 'mygame.mowing',
	phase: 'resolve',
	every: 15, // ticks: twice a second at 30 ticks a second
	update(world) {
		for (const unit of world.units.values())
			if (unit.def.id === 'mower') ruin(world, 'grass', { kind: 'circle', x: unit.pos.x, z: unit.pos.z, radius: 1.2 }, { how: 'cut', by: unit })
	}
}

Put it in Rules.systems. How ruined grass looks is the look's ruined group. See Cut or crush grass and Make grass grow back.

Fire: catch, spread, stop ​

A style burns where it is flammable. Set it alight with ignite; it spreads to the cells about it, likelier downwind, uphill and in dry grass, burns for the style's burns seconds and is burnt.

ts
import { defineCellLayer, foliagePack, ignite, type Entity, type Rules, type World } from '@v12-engine/engine'

declare const rules: Rules
declare const world: World
declare const hero: Entity

export const fireRules: Rules = {
	...rules,
	cellLayers: [defineCellLayer({ id: 'grass', name: 'Grass', values: [{ value: 1, name: 'Dry field', foliage: { flammable: 1, burns: 5, regrows: 120 } }] })],
	// 8 damage a second to who stands in it, dealt by whoever lit it
	packs: [...(rules.packs ?? []), foliagePack({ layer: 'grass', fire: { damage: 8, wind: 1.5, maxBurning: 3000 } })]
}

ignite(world, 'grass', { kind: 'circle', x: 30, z: 30, radius: 1.5 }, { by: hero })

Stop it in any of these ways:

ts
import { defineHook, extinguish, firebreak, foliageIgnite, stopFire, type World } from '@v12-engine/engine'

declare const world: World

extinguish(world, 'grass', { kind: 'circle', x: 30, z: 30, radius: 4 }) // put out what burns there: it stays burnt
firebreak(world, 'grass', { kind: 'rect', x: 40, z: 30, width: 2, depth: 20 }) // cut a strip fire does not cross
stopFire(world, 'grass') // every fire of the layer; every layer of the pack when none is named

// no fire crosses the river: a hook sees every cell about to catch
export const wetBanks = defineHook({
	hook: foliageIgnite,
	id: 'mygame.wetBanks',
	run(_world, event) {
		if (event.cause === 'spread' && event.z > 100) event.cancel()
	}
})

How it looks: a blade chars from the tip down with a glowing edge, flames, smoke and embers play along the front, and ash is left under what burnt. Change each part in the look's fire group, the layer's and each style's:

ts
import { foliage } from '@v12-engine/client'

export const grass = foliage({
	fire: { color: [1, 0.55, 0.15], scorch: 0.7, embers: false }, // a lighter ash, no embers
	styles: {
		2: { fire: { bright: 1.3, smoky: 0.5 } }, // dry grass: big, bright, little smoke
		3: { fire: { bright: 0.8, smoky: 2, sound: false } } // a thicket: low flames, thick smoke
	}
})

The loading screen plays the fire's effects once ahead where the rules burn grass, so the first fire does not hitch.

Rain and snow (MapEnvironment.weather) damp it and put it out, water, roads and blocked cells never burn, and fire.lasts ends every fire after so long. See Set grass on fire and Stop a fire spreading.

Burn it with an ability ​

The foliage effect does to the grass where it lands what its act says: ignite, extinguish, ruin, regrow or clear.

ts
import type { AbilityDef } from '@v12-engine/engine'

export const fireArrow: AbilityDef = { id: 'fireArrow', name: 'Fire Arrow', target: 'point', range: 9, cooldown: 12, effects: [{ type: 'foliage', act: 'ignite', radius: 1.5 }] }
export const rain: AbilityDef = { id: 'rain', name: 'Rain', target: 'point', range: 10, cooldown: 30, effects: [{ type: 'foliage', act: 'extinguish', radius: 6 }] }

See Burn grass with an ability.

Change it in play ​

From the rules, for every player: paint styles, and change looks through the map's environment.

ts
import { setFoliage, type World } from '@v12-engine/engine'

declare const world: World

setFoliage(world, 'grass', { kind: 'circle', x: 20, z: 20, radius: 5 }, 2)
// autumn: every screen eases the meadow's tips to gold over 30 seconds
world.setEnvironment({ bushes: { grass: { styles: { 1: { colors: { tip: [0.85, 0.7, 0.3] } } } } } }, { over: 30 })

On one screen, through the layer's handle:

ts
import type { GameClient } from '@v12-engine/client'

declare const client: GameClient

const grass = client.foliage('grass') // undefined where the layer is not drawn as grass or bushes
grass?.setStyle(2, { colors: { tip: [0.9, 0.6, 0.2] } })
grass?.setLook({ wind: { sway: 2 } })
grass?.disturb({ x: 20, z: 20 }, 2) // shake it, as one running through would
grass?.flatten({ kind: 'circle', x: 20, z: 20, radius: 3 }, 0.8) // lay it down: it stands again by `recover`
console.log(grass?.stats.instancesDrawn)

A change of how many, how big or what colour lays again only the chunks holding that style; a change of sway, shaking or distance lays nothing.

Quality ​

The player's Tall grass setting (Settings › View: None, Some, All; the quality knob foliage) draws none, a third, or all of the tufts, and thins bushes the same way. The rules are the same whatever it is: grass hides as much at None. The Detail setting (Settings › View: Near, Medium, Far; the quality knob detail) brings the levels nearer, the grass's levels as the bushes' and every model's: half as far on Near, three quarters on Medium, as the look says on Far. A fire's flames, smoke and embers are as many as the Effects setting says, and its lights only at the Lights setting's All. Laying a big map is spread over frames from the frame's budget, its foliage work (4 ms when left out):

ts
import type { GameView } from '@v12-engine/client'

export const world: GameView['world'] = { frameBudget: { most: { foliage: 6 } } }

The code that draws grass and bushes is fetched apart, as a game is made where its looks or its map draw any: a game without grass loads none of it. A world view made in code (createLiteWorldView) draws its grass as that code comes, a moment later.

See Graphics quality.

In the editor ​

  1. In the Terrain panel, under your layer's name (Grass), click one of its styles and paint it.
  2. Pick cells with the Patch tool (Rectangle, Circle, Polygon, Wand, By style) and press Its own settings to give them a style of their own.
  3. Open Grass and bushes to set the look group by group, or start from a Preset.
  4. In a style's settings, Gameplay sets what it is to the rules: hides, slows, burns, grows back, trampled.
  5. Play here, then light, put out, cut and regrow grass from the Cheats panel's Grass brushes.

See Grass and bushes in the editor.

Reference ​

Where each thing is kept ​

WhatIn codeEvery map, from the editorOne map, from the editor
A style's name, colour and rulesCellLayerDef.values[n] (name, color, foliage)data.json: cellLayers[layer].values[n]GameMap.definitions.cellLayers[layer].values[n]
The layer's base rules, fire, hiding, who tramplesfoliagePack(options)code onlycode only
A style's lookfoliage({ styles: { n: … } })cellLayers.json: [layer].styles[n]MapEnvironment.bushes[layer].styles[n]
The layer's lookfoliage(look)cellLayers.json: [layer]MapEnvironment.bushes[layer]
Which cells have which styleworld.setCells, setFoliageGameMap.cells[layer]
What happened to each cellruin, ignite…GameMap.cells['<layer>.state']

Each column lies over the one to its left, field by field. A look read from a file is checked by readMapBushes; a style's rules by foliageStyleProblem.

FoliageStyleDef: a style to the rules ​

FieldDefaultWhat it does
concealsnoHides who stands in it
concealsTalleryesWith false, a unit taller than height is seen over it (a unit stands twice its radius: FoliageConceal.heightOf)
height1How tall it stands to the rules, in cells
speed1A multiplier of the speed of who walks through it; the ways go round slow ground where that is quicker
walkableyesWith false, nothing on foot goes through it, whatever its state
flammable0How easily it catches, 0 (never) to 1
burns6Seconds a cell burns
fuel1How hot it burns: how much likelier it lights its neighbours
regrowsneverSeconds after it was burnt, cut or crushed that it starts to grow back by itself; false for never
grows10Seconds it takes to grow back once it starts by itself
trample'none''crush': lays flat under who walks over it, by tramples

The pack's style is the layer's base; each value's foliage lies over it (foliageStyle(game, layer, value) reads the result).

foliagePack(options) ​

OptionDefaultWhat it does
layerThe layer of cells (Rules.cellLayers)
styleWhat every style of the layer is where it says nothing
concealreach (2), hides (units on the ground), seenBy, rustle (no), rustleEvery (0.3 s), heightOf (twice the radius)
tramplesevery unit that walksWho crushes a style with trample: 'crush': not structures, flyers or ships
alsoMore layers, each with layer, style, conceal, tramples: fire passes between them
fireonFoliageFire, or false for grass that never burns

A layer given to foliagePack is not given to concealmentPack too. foliageLayers(options) lists the pack's layers.

FoliageFire ​

FieldDefaultWhat it does
spreadyesWhether a burning cell lights those beside it
every0.25Seconds between a burning cell's tries
wind1How much the wind decides the way: in a gale a try downwind is 7.4 times likelier, upwind a seventh
slope1How much faster uphill: about 2.7 times on a 45° slope
jumpneverFrom this wind strength (0 to 1), it jumps a gap of one cell downwind
wet0How wet everything is, 0 to 1 (nothing catches)
weatheryesRain and snow damp it and put it out
maxBurning4000The most cells burning at once, over all the pack's layers; past it, cells wait their turn
lastsneverSeconds after which a fire dies
damagenoneDamage a second to units in a burning cell, by whoever lit it
damageTypemagicThe damage's type
lightsnoA burning cell tries to set alight what burns on or beside it at each of its tries, with burningPack (Let trees burn)

A try lights a neighbour with chance 0.08 × flammable × fuel × (1 − wet), halved across a corner, then weighed by wind and slope. The rolls are the world's own numbers, so a fire burns the same on every machine and in a replay.

Calls ​

CallWhat it does
ignite(world, layer, where, { by })Sets it alight where it can burn; the cells that caught
extinguish(world, layer, where)Puts out what burns there, left burnt
firebreak(world, layer, where, { by })ruin with cut
stopFire(world, layer?)Puts out every fire of a layer, or of the pack; how many were burning
ruin(world, layer, where, { how, by })cut, crush or scorch (FoliageRuin)
regrow(world, layer, where, { over, by })Grows ruined or burnt grass back, over over seconds or at once
clearFoliage(world, layer, where)Takes the grass away: value 0, nothing grows back
setFoliage(world, layer, where, value)Paints a style, checked; the cells whole again
foliageAt(world, layer, x, z)FoliageCell: cell, value, style, state, burning, left (seconds), by
burningCells(world, layer)The cells burning now, in order: don't keep or change it
gust(world, at, gust)A gust on every screen that sees it (WindGust: radius, strength, around, lasts 0.6)
growOnTiles(world, layer, tiles, value)Paints the cells of these tiles with value, once
foliageStateLayer(layer)The id of the state layer: grass.state
patchCells(terrain, layer, cell, options)The cells of the patch a cell is in

where is a FoliageWhere: a shape (AreaShape) or cell indices. Each call throws for a layer that is not the pack's.

State ​

FOLIAGE_STATEValueHidesBurnsDrawn as
whole0if the style concealsif flammableas it grew
flattened1nonolaid one way, browned
cut2nono (a firebreak)stubble at ruined.stubble
burning3noburningcharring from the tip down, its edge glowing, under flames
burnt4nonoshort black stubble over ash; most copies gone
growing5yesyesrising from the ground

The state lives in the layer <layer>.state (foliageStateLayer), saved, sent to the players who see a cell and remembered through the fog by the others. foliageStateOf(value) names a value.

Events, the hook and the effect ​

NameKindCarries
foliageIgnitehook, before a cell catches, once a trylayer, cell, x, z, cause (ignite, spread, burning: from a burning tree), from, thing, by, chance (change it, held to 0 to 1), cancel()
foliageIgnitedeventlayer, cells, cause, by
foliageBurnteventlayer, cells
foliageRuinedeventlayer, cells, how, by (trampling too)
foliageRegrowneventlayer, cells, by
foliageFireOuteventlayer: its last fire went out
foliage effectact, layer?, how?, over?Over the effect's radius or shape, else the cell it landed on; every layer of the pack when layer is left out

The events are for your rules and computer players and are not sent to screens: screens see the state layer's cells as far as they see.

FoliageLook ​

Old flat fields still work: color, tip, size, sway, shake, tilt and far are colors.foot, colors.tip, sizes.each, wind.sway, walked, rotation.lean and levels said the old way.

FieldDefaultWhat it does
drawmodels where models names any, else grass'grass' or 'models'
models{ src, scale, weight } each
height0.6 (grass); as made (models)World units: a unit stands about 1.5, a tree 3.5 to 4.7
density3 tufts, 0.7 modelsA cell; fewer with the player's Tall grass setting
seed0The layout's seed
noise8Cells across the patches of sizes.noise, colors.patches, placing.clump
seeThroughyesSee-through round your own units in it
sound, volumenone, 0.7Heard as one moves through it: a sound by name ('rustle' is the client's own); none when left out
leavesnoneAn effect played as one steps in (the ready-made leaves)
shadownoModels cast shadows: true, 'near' or false. Grass never does
stylesA look for each value over the layer's; false for none drawn
onGrass from tiles: tiles, style (255), density (1), height (0.7 of the layer's)
scatterFlowers: { shape, src, density, height, colors, sizes } each
shapeDefault
kind'tuft''tuft', 'blade' (tapers and curves), 'cross' (crossed cards with a picture), 'mesh' (a model)
blades5Blades a tuft
width0.09A blade's width at its foot, of a tuft a unit tall
taper, curve, droop, spread1, 0.3, 0, 0Narrowing, lean of the tip, hang, how far apart the feet stand
segments[3, 2, 1]Parts of a blade near, further, far
cards, texture, alphaCutoff2, , 0.5A cross's cards and picture
srcA mesh's model
sizesDefault
each[0.8, 1.25]Each its size, of 1
width[1, 1]Each its width, of 1
noisenoneBigger in patches: { scale, amount }
edgenoneSmaller towards the edge: { cells, to }
rotationDefault
yaw[0, 360]Degrees, one or a range
faceWind0Turns to face downwind, 0 to 1
lean0 grass, 6 modelsDegrees
leanTo'random''random', 'wind' or degrees
uprightyesUpright on a slope, or square to it
colorsDefault
foot, tipgreensUp the blade (grass); a fourth number is how much is seen there
stopsMore colours up the blade: { at, color }, color with a fourth too
vary0.12 (0 models)Lighter and darker, each its own
hue, saturation0Each its own hue and strength (saturation: grass)
patchesnone{ scale, amount, to }: dry spots; to may have a fourth
ground0How much of the ground's colour it takes (grass)
drynone{ to, amount }: dried out; to may have a fourth
tintwhiteMultiplies everything, models too; its fourth is how much of the style is seen
placingDefault
clumpnoneThicker in patches: { scale, amount }
edgenoneThinner towards the edge: { cells, to }
jitter0.8 (0.7 models)0 in rows to 1 anywhere in the cell
slopeevery slope[least, steepest] in degrees
tiles, notTilesTile ids it grows only on, never on
keepOffwater, cliffs, buildings, scenery, for grass; none, for models unless saidwater, cliffs, buildings, doodads: false to grow through. roads: true keeps it off the road tile: left out, grass grows where it is painted whatever the ground's tile
light (grass)Default
shadowsnoShadows fall on it
normals'up''up' (soft, even) or 'true'
translucency, specular, footFade0Light through the tips, shine, fade into the ground at the foot
levelsDefault
mid, farCells from the camera where fewer, then the fewest, are drawn (models: their .lod1, .lod2 files)
cullneverNone past this
midKeepsa rampThe part kept from mid
farKeeps0.25The part kept from far
fade4Cells one level fades into the next over
windDefault
sway1How much it sways
stiffness0.40 soft to 1 stiff
waves1How much it joins the waves rolling over a field
flutter0.3Tips shivering in a strong wind
lean1Leaning downwind as the wind gets up
speed1How fast it sways
sheen0.3Lighter tips as the blades lie over
walkedDefault
bend1How far it bends away
radius1.6Cells, or 'size' (by each unit's size, at most 3.2)
wobble, settle, entry1, 1.2 s, 2Swing as it settles, how long, how much harder on stepping in
who'all''all', 'friends', 'none' or a function, of the units you see
flatten0How far it lies down underfoot, 0 to 1
recover8Seconds to stand again; 0 for never, until grown again
trailyesOne moving through leaves laid grass behind

walked: false turns it off.

ruinedDefault
stubble0.15Cut height, of its height (a bush's stump)
crusheda dry brownCrushed (and cut) colour; a fourth is how much of it is seen
burntnear blackBurnt colour; a fourth is how much of the charred part is seen
paint{ burnt: 'ash' }Ground paint under cut and burnt: 'ash', 'mown', a picture's path, or false

On the screen a blade chars from its tip down over the time its style burns, its edge glowing, and ends as black stubble over ash; a bush chars and loses its leaves. Flames, smoke, embers, a few lights and a crackle play along the front, the nearest the camera's that the player sees (fewer at a lower quality of effects, no lights below the lights' high quality). fire: false turns all of it off. A style says its own, but for color and scorch, which are the layer's. A cell that comes into sight already burning is shown half burnt.

fireDefault
flameslow flames over the groundAn effect by name (burning-ground, a game's own), or false
smoke, emberssmoke, embersEffects by name, or false
lightyesWhether the front lights what is round it, and how (color, range, intensity)
colororangeThe flames and the glowing edge: three numbers, no fourth
bright1How big and bright it burns
smoky1How much smoke, 0 for none
scorch1How dark the ash left under it is, or false
sound, catchesa crackle, a whooshSounds by name, or false

The handle: client.foliage(layer) ​

MemberWhat it does
lookThe look drawn now, by groups
setLook(change)Changes the layer's look, field by field
style(value), setStyle(value, change), removeStyle(value), styles()A style's look
disturb(at, strength)Shakes it at a place
flatten(where, amount)Lays grass down; it stands again by recover
statsFoliageStats: chunks, chunksDrawn, instances, instancesDrawn, layMs, frameMs
onChange(listener)Told when its look changes

Its changes are this screen's and stay over whatever look comes after. client.gust(at, gust) is a gust on this screen. foliageLookParts, layFoliageLook and foliageStyleLook read and lay looks as the engine does.

Limits ​

  • 255 styles a layer (values 1 to 255); value 255 is grass from tiles where on.style says none.
  • Four gusts at once; a gust's strength is held to 3.
  • Bushes (models) don't take shape, colors.foot, tip, stops, saturation, ground, light or scatter; they take the layer's wind, not a style's; they shake but are never laid flat or crushed-looking; far away they are their lightest model, then nothing (no pictures).
  • Grass grown from tiles (on) is nothing to the rules (no hiding, slowing or burning) until growOnTiles paints it.
  • Grass never casts shadows; by default none fall on it.
  • walked and flatten are each screen's own; trampling that matters is trample: 'crush'.

What costs time in play ​

  • Setting or clearing a style with speed, or with walkable: false, while the game runs cuts the navigation again where it changed, a piece of 12 × 12 cells at a time: under a millisecond for a small patch, about a third of a millisecond for each piece a large paint reaches and each unit size the game has (10 ms for a 20 × 100 band, 41 ms for the whole of a 128 × 128 map, one unit size). A layer with a walkable: false style also cuts the pieces beside a painted cell at a piece's edge. The calls of one tick are cut together, each piece of the navigation once, as the tick ends (or as soon as something asks the navigation, so nothing finds its way on the ground as it was). Do it in a few ticks, not every tick.
  • The state (fire, ruin, trampling) costs nothing of the navigation.
  • Hiding patches are worked out again only where cells change, once a tick at most.

Measured ​

Measured on an Apple M4 Max laptop, often while it was busy with other work; the browser numbers in headless Chromium with WebGPU, the rules on the CPU benchmark (npm run bench -- foliage).

WhatSceneMeasured
Triangles drawn256 × 256 meadow, 314,576 tufts1.57 M before chunks, 0.16 M with them
Laying 100 changed cells256 × 256 meadow0.6 ms in a browser (headless, the frame held to 60 a second, load 1–3); 0.30 ms on the CPU benchmark (load 1–3)
Laying the whole map256 × 256 meadowin slices of at most 4.0 ms, done in 225 ms, no frame over 16.8 ms (headless, the frame held to 60 a second, load 1–3); 41 ms at once on the CPU benchmark, nine tenths of it working out each tuft (its place, size, turn and colour)
A style's colour changedin play4.3 ms (only its chunks laid again); sway 0.05 ms
A style's look changed in the editor256 × 2564.7 ms median
Draw calls for grass and bushessix grass styles and two bush models32–37 (bushes 9); six styles of one shape cost what one does. The meadow 21–26, a fire 26–28 (headless, load 4–8)
Grass from tiles256 × 256, 85% grass tiles0.033–0.041 ms CPU a frame, 23–27 draws, whole lay 13.8 ms in pieces of ≤ 3.9 ms, 100 tiles painted 0.1–0.2 ms
Foliage CPU a frame200 units walking through grass0.11–0.18 ms in a browser (headless, load 1–8); 0.039 ms on the CPU benchmark (load 1–3). The meadow still 0.015 ms
Allocated a framethe meadow, 200 walkers; grass from tiles, still (CPU benchmark, load 1–19)0.30–0.59 KB and 0.23 KB, from run to run (0.40 and 0.45 before), numbers boxed by the JavaScript engine: no object, array or closure is made a frame
Fire, the rules' tick2,000–2,500 cells burning, 8 teams0.091 ms; the worst tick 0.24 ms (CPU benchmark, load 1–3; 0.105 and 0.84 ms at load 11–19)
Hiding patches worked out whole256 × 2560.8–1.2 ms (at most once a tick, where cells changed)
Grass waiting to grow back20,000 cellsnothing measurable a tick
What each team remembers of cells changed out of its sight20,000 cells cut, 8 teams; CPU benchmark, load 11–15 on 14 cores0.023–0.028 ms a tick (0.07 ms each time the fog is worked out, every third tick)
Burning trees (Let trees burn)2,000 trees alight0.078 ms a tick; 0.0003 ms with none
A speed style painted in play10 × 10 cells of the 256 × 256 meadow, one unit size; CPU benchmark, load 17–21 on 14 cores0.58–0.70 ms a tick (6–9 ms a call measured earlier on another scene)
Large speed paints in play128 × 128 rolling ground, 40 huts, one unit size (two); CPU benchmark, load 11–15 on 14 coresa 20 × 100 band 10.3 ms (23.9); over 66 of the 121 pieces 23.2 ms (49.4); the whole map 43.4 ms (87.4). A building put up and taken down again on pieces painted in play 0.21 ms (0.61), on ground painted as the world was made 0.16 ms (0.32)
Four speed paints in one tickfour 5 × 5 squares side by side, the same0.64–0.72 ms a tick, cut together (2.3–2.4 ms cut one by one)
The ground reshaped and painted in one tick10 × 10 cells levelled, then painted, the same12.4–14.0 ms a tick (12.9–13.6 ms cut one after the other): most of it the reshape's, which reads the whole ground again
Fire on the screen, foliage CPU a frameabout 3,800 cells burning, 1,590–1,600 in view (a field of 90% grass, the camera at the game's farthest); headless, load 1–80.025–0.17 ms
The first fire415 cells set alight, the warm-up on; headless, the frame held to 60 a second, load 1–3no frame over 20 ms (the worst 16.8 ms)
Fire on the screen, uploadsthe sameno texture upload beyond the cells newly lit
Fire on the screen, effects at oncethe sameflames 32, smoke 8, embers 8, lights 4

GPU time and frame times on a real display, at full resolution and its rate, are still to be taken: a headless page draws to no display.