Triggering from a mission
The rules play a cinematic on the screens it is for, cue it while it plays, and hear how it ended, all as commands, so a story branches the same on every screen and in a replay. A cinematic can also wait on the world (a unit arrived, a gate fell) and stage fights with a fixed outcome.
Quick start
import { cinematic, cinematicCue, cinematicEnded, defineSequence, talk, wait, waitFor } from '@v12-engine/engine'
export const briefing = defineSequence({
id: 'td.briefing',
steps: [
// goes on once the player has seen it end, or skipped it
cinematic('td.intro', { hold: true, wait: 'ended' }),
...talk(PLAYER, lines),
cinematic('td.gate'), // not waited for: the game goes on
wait(4),
cinematicCue('gateOpen'), // the gate cinematic's `untilCue('gateOpen')` goes on (`cueCinematic(world, ...)` from code)
waitFor(cinematicEnded, (_world, event) => event.cinematic === 'td.gate' && event.outcome === 'skipped'),
(world) => world.message(PLAYER, 'impatient', 'info')
]
})The intro plays while the game waits, lines are said, the gate cinematic plays alongside the game and is cued to open, and the rules react if the player skipped it.
Common tasks
Play one from code in the rules
playCinematic(world, 'td.intro', { hold: true, params: { road } })Play one when a unit walks into a region
Set the region's cinematic in the editor's Content drawer (MapRegion.cinematic: { id: 'td.ford' }). It plays for everyone the first time a unit walks in, once (a save remembers). With play: 'code', the engine leaves it to your rules, which find it in world.map.regions.
Wait in a cinematic for something to happen
await cut.untilKey('Enter', 10) // any key but Esc when left out; 10 s at most
await cut.untilClick()
await cut.untilCue('gateOpen', 5) // the rules' cue
await cut.untilEvent('death', { unit: 'giant' })
await cut.untilWhen({ ref: 'gate', alive: false })
await cut.race([cut.untilKey(), cut.wait(4)]) // the first
await cut.all([cut.say('a', '…'), cut.untilClick()])Wait for a unit to arrive
{ "at": 4, "wait": "until", "until": { "arrived": "hero" }, "timeout": 20 }Script a sequence of moves
{
"at": 2,
"unit": "aldric",
"steps": [
{
"together": [
{ "order": "move", "to": { "x": 36, "z": 10 } },
{ "unit": "brann", "order": "move", "to": { "x": 36, "z": 14 } }
]
},
{ "clip": "attack" },
{ "order": "attack", "to": "raider" },
{ "unit": "raider", "for": 0.5, "flash": [1, 1, 1] },
{ "unit": "raider", "kill": true }
]
}Two units walk, one attacks, the raider flashes and dies: one item. In code: await cut.sequence(steps, 'aldric').
Stage a fight with a fixed outcome
{ "at": 2, "unit": "aldric", "fight": { "target": "raider", "outcome": "kill", "seconds": 4 } }The units really fight (walk up, swing, play clips), both invulnerable, and the target dies on the attacker's blow (its clip's hit mark). Insert › Duel in the panel puts one in.
Let a cinematic spawn and move any unit
packs: [directorPack()] // or directorPack({ cinematics: ['intro'] })With the director, a playing cinematic can put units down, remove, kill, move, size, protect, give away, order and turn any player's units. Without it, the units lane's orders are the player's, and the rules may refuse them.
Play a cinematic as a scene of its own
import { cinematicScene } from '@v12-engine/client/app'
import { readCinematic } from '@v12-engine/client'
import introFile from './cinematics/intro.json'
export const introScene = cinematicScene({
id: 'intro',
game, // the rules the map is made with, and the view
map: valleyMap, // or `world: (context) => makeWorld(context)`, as `gameScene` takes them
cinematic: readCinematic(introFile), // or an id of the view's, or a script
then: { scene: menu } // or (outcome, goTo) => goTo(outcome === 'skipped' ? menu : missionOne)
})For a title sequence or a story between missions. See A cinematic as a scene.
Run code at a marker
cinematics: {
defs: {
'td.intro': {
def: intro, // its markers: [{ "at": 4, "name": "gate" }]
hooks: {
'marker:gate': (cut) => cut.stage.fx?.('flare', { at: { x: 60, z: 30 } }),
flare: async (cut, event) => { await cut.wait(1) }, // a clip of the hooks lane: { "at": 5, "hook": "flare" }
end: (_cut, event) => console.log('the intro', event.outcome)
}
}
}
}Reference
How the rules hear the end
The screen sends a command ({ type: 'cinematic', cinematic, outcome }) as a cinematic the rules played ends; the engine emits cinematicEnded (player, cinematic, outcome). It is in the replay and heard in the same tick everywhere. The step's wait: ended (the player it was for), any (the first), all (everyone). Computer players aren't waited for, and the count is kept in a save. A player who leaves never says, so a sequence for many should wait for any, or add a timeout of its own. The client does all this itself (client.cinematics.fromRules(event), client.cinematics.cue(name, params)); a host of your own calls the same two.
The director (directorPack)
While a cinematic plays on the sender's screen (cinematicPlaying, sent as one with an id starts), its director commands may spawn (type, owner, place, facing, name), remove, kill, teleport, scale, make invulnerable, change owner, order (move, attack, attack-move, patrol, stop, hold) and turn any unit. Outside a cinematic they are refused and counted (commandRejected, notDirecting). They are in the replay. A held game is moved on a tick as they are sent, so they land at once. In the Inspector they are under Director.
World conditions (until, when, cut.untilWhen)
| Word | Holds when |
|---|---|
{ "arrived": "hero" } | it has nothing left to do, or is gone |
{ "dead": "gate" } | it is gone from what the screen sees |
{ "inRange": ["hero", "gate", 6] } | within 6 cells, middle to middle |
They read a CutWorld (Stage.world, the session's snapshots as this screen has them: EntityState.busy), so a remote screen answers as a local one. cutWorldOf({ entity, tick, tickRate, fog }) makes one. An order counts as arrived once the unit was seen busy and is idle again, or a second went by without it ever being busy. A unit walking into fog is never "dead" (give the wait a timeout); nothing arrives in a held game.
Control waits
{ at, wait: 'key' | 'click' | 'cue' | 'event' | 'until', key, cue, event, unit, match, until, timeout, parallel, hook }. It holds the cinematic's clock until it is over, unless parallel. Each is heard as lane:control:waited (params.came false where it gave up). A seek past a wait doesn't wait.
Sequence steps
A step is what an item does (clip, order, path, flash, kill…), together (several at once), or steps (a nested sequence), with an optional when.
| A step that… | ends |
|---|---|
has a for | when that is up |
| gives an order or a path | as the unit is idle, or its target is dead |
| plays a clip (not looped) | as the clip ends, or the unit is gone |
kills, removes or spawns | once it shows in the world, or a second went by |
gives stop or hold | at once (a patrol too, logged, unless it has a for) |
Without a for the clock stands on the sequence's end until the last step ends ("holds": false lets it run); with a for the rest is dropped when it is up (unless "holds": true).
Fights
outcome | What happens |
|---|---|
kill | the target dies on the first blow from seconds minus the clip's length on |
flee | at seconds the target runs 14 cells away, and the attacker stands down |
draw | they attack each other until seconds, then stand down |
The hit unit flashes (fight.flash) on each blow, told by the clip's mark (Stage.marks, client.renderer.kit.onMark). A model with no hit mark kills at seconds. A blow that never comes is made up three seconds later. The outcome is fixed: let go early (a skip), it happens then. Needs the director.
A cinematic as a scene
cinematicScene loads the map, holds it from its first tick, seats no computers, records no replay, keeps no saves, lifts the fog (reveal: false keeps it), hides the HUD and plays held. Esc skips (skippable: false says not). Then it goes where then says (a scene and args, or a function of ended, skipped, stopped). It also takes play, params, environment, lookAt, startView, pack, assets, loading, error. map: 'none' is a black stage for title cards and credits. playCinematicScene(client, options, goTo) does the same in a scene of your own. The example's Intro (apps/example/src/scenes/intro.ts) and Title (apps/example/src/scenes/title.ts) are two.
Markers and cues in code
cut.at('gate') (its time), cut.seekTo('gate'), await cut.untilMarker('gate'); await cut.untilCue('gateOpen', 10), cut.cue('gateOpen'). A cue that came before anything waited for it is kept for the first wait of its name.