Cut or crush grass
Call ruin with how: 'cut' to leave stubble, 'crush' to lay grass flat, or 'scorch' to burn it black. Ruined grass hides nobody and doesn't burn until it grows back. To have units crush a style as they walk over it, give that style trample: 'crush'.
// anywhere in your rules
import { ruin, type Entity, type World } from '@v12-engine/engine'
export function mow(world: World, worker: Entity): number[] {
return ruin(world, 'grass', { kind: 'rect', x: 32, z: 32, width: 12, depth: 8 }, { how: 'cut', by: worker })
}Done: the rectangle is cut down to short stubble with mown stripes painted under it if the look asks for them. A fire stops at its edge.
A mower unit
A system that cuts the grass under every mower, twice a second:
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 })
}
}import { foliage } from '@v12-engine/client'
// cut grass stands at a tenth of its height, with mown stripes painted under it
export const lawn = foliage({ ruined: { stubble: 0.1, paint: { cut: 'mown' } } })Put the system in Rules.systems.
Crushed under feet
import { defineCellLayer, foliagePack, type Rules } from '@v12-engine/engine'
import { rules } from './rules'
export const wheatRules: Rules = {
...rules,
cellLayers: [defineCellLayer({ id: 'grass', name: 'Grass', values: [{ value: 1, name: 'Wheat', foliage: { conceals: true, trample: 'crush', regrows: 60 } }] })],
// carts and big beasts crush it; when left out, every unit that walks does (not buildings, flyers or ships)
packs: [...(rules.packs ?? []), foliagePack({ layer: 'grass', tramples: (_world, unit) => unit.def.radius >= 1 })]
}A trampled cell is flattened. Like any ruin, trampling sends a foliageRuined event (how: 'crush') and the cell grows back by its style's regrows. Screens that just want grass to bend and lie down use the look's walked group: see Leave trails in grass.
Take grass away for good
clearFoliage(world, 'grass', where) sets the cells to no grass (value 0), so nothing grows back.
In the editor
- Under a style's Gameplay, set Trampled to Crushed flat.
- Under Ruined, set Cut to, Crushed, Burnt, Paint under cut and Paint under burnt.
- In Play here, the Cheats panel's Grass › Cut brush cuts grass in the running game.
Reference
how | State | Drawn as | Hides | Burns |
|---|---|---|---|---|
cut | cut | stubble at ruined.stubble (0.15); bushes become stumps | no | no |
crush | flattened | laid flat one way, browned (ruined.crushed) | no | no |
scorch | burnt | short and black (ruined.burnt); bushes charred | no | no |
ruin leaves cells that are already in that state, burnt cells, and cut cells (nothing left to crush) alone. It puts out anything burning there and returns the cells it ruined. It changes only the state layer, so it never re-cuts the navigation. firebreak is ruin with cut. ruined.paint: ash (under burnt grass by default), mown, a picture's path, or false.