Skip to content

Terrain

TheGenieOfTheCode edited this page Oct 29, 2026 · 1 revision

Terrain

CTLib gives every scene a ground and a height for each square, so line of effect, cover and range can count height. Directors shape it with the Terrain region behavior; modules read it through SceneTerrain and terrainAt.

The Terrain region behavior

Add a region to the scene, give it the Terrain behavior, and pick its Kind. The region's bottom and top elevation are the bottom and top of the terrain.

Kind What it does
Solid Block The space between the region's bottom and top is solid. It blocks line of effect, and creatures can stand on top of it. A solid block with no bottom raises the ground under it to its top.
Pit Lowers the ground to the region's bottom. A token down in the pit is drawn at the pit's mouth, so it stays visible on the map.

Material says what a solid block is made of, from the materials in Materials and Tags, for modules that let a creature force moved into it break through. Something Solid never breaks.

Ground heights

Each square has a ground height, 0 by default. A solid block with no bottom raises it, and a pit lowers it.

On a scene built with DS Terrain Designer, while that module is active, its per-square ground heights are the ground under each square, so creatures stand on its raised and lowered ground.

Foundry's own floors count too: a Define Surface region with Restricts Movement on is a floor creatures can stand on, and one with Restricts Sight on blocks line of effect.

Heights and units

CTLib measures heights in squares: a token's elevation divided by the scene's grid distance. A creature's space is as many squares tall as its size, at least 1, or as its token's depth when that is more.

SceneGrid

new SceneGrid(scene = canvas.scene) converts between pixels, squares and elevation for one scene.

Member What it is
size One square in pixels.
unit The scene's grid distance: how much elevation one square is.
cellOf(point) The square { x, y } a canvas point is in.
center(cell), topLeft(cell) The pixel position of a square's centre or top left corner.
toSquares(elevation) An elevation in squares. null stays null.
toElevation(z) A height in squares as an elevation.

Reading the scene

SceneTerrain

new SceneTerrain({ scene = canvas.scene }) reads a scene's walls, regions and tiles once, for many questions about it. Build a new one after the scene changes. Its ground is the scene's ground height, from the ground flag under CTLib's scope, 0 when unset.

Method Returns
slabsAt(cell) Everything solid or standable in a square, as slabs sorted from the lowest up.
wallsBetween(from, to, zMin, zMax) The walls that block movement across the line between the centres of two adjacent squares, and reach into the height range zMin to zMax.

A slab is { id, bottom, top, label, material }, heights in squares. material is the material it breaks as, or null when it can't break; a liquid has none. It also carries one of these:

Field The slab is
id: 'ground' The ground under the square, from below the map up to its height, from the scene or DS Terrain Designer.
region A region's UUID: a solid block, a pit's floor, a ground a solid block raised, or a floor with surface: true. A liquid has liquid: true.
tile A wall block tile's UUID, as tall as its walls' Wall Height flags say, endless when they have none.

Each wall from wallsBetween is { id, kind: 'wall', material, bottom, top, wall }, where wall is its UUID. material is set only on an obstacle wall tagged breakable and not broken.

SceneTerrain is a plain class, so a module can extend it with what it needs about the battlefield.

Other helpers

Name What it is
TERRAIN_BEHAVIOR The behavior's type, 'draw-steel-ctlib.terrain'. Its data is system.kind, system.material, system.damage and system.damageType.
solidTerrainRegions(scene = canvas.scene) Every region with an enabled solid block, as { region, bottom, top } in squares.
terrainAt(scene, { x, y, elevation = 0 }) The movement terrain at a canvas point and elevation, see below.

Movement terrain

provideTerrainMovement() tells CTLib that your module handles movement. Call it once, for example in your init hook. The Terrain behavior's Kind list then also offers:

Kind Meaning
Liquid A body of liquid between the region's bottom and top. It doesn't block line of effect.
Difficult Terrain Difficult terrain within the region's elevation, fliers included.
Damaging Terrain Terrain that deals Damage of a Damage Type for each square of it a creature enters, within the region's elevation, fliers included.

Until a module calls it, those kinds stay hidden, since nothing would act on them. A region already set to one of them keeps showing its own kind.

CTLib only stores and reports these kinds: your module applies them. Liquid shows up in slabsAt as a slab with liquid: true. Difficult and damaging terrain come from terrainAt(scene, { x, y, elevation }), with x and y in pixels and elevation in the scene's units:

const here = ctlib.terrainAt(canvas.scene, { x: point.x, y: point.y, elevation: token.document.elevation });
if (here.difficult) cost += 1;
for (const d of here.damaging) await dealDamage(actor, d.damage, d.type);

It returns { difficult, damaging }. damaging lists one { region, name, damage, type } per damaging behavior there, where region is the region's UUID and type is '' for untyped damage. A region counts from its bottom up to, but not including, its top.

Related Pages

Clone this wiki locally