Missions, objectives and triggers
What a mission says and asks of the player: dialog, objectives, winning and losing, hints, timers, checkpoints, triggers on the map, and capture points. The tutorial that builds a campaign is Let's make a basic campaign. A whole classic mission, part by part, is Missions the classic way, and every classic objective is in Objective recipes.
Quick start
const hold = defineObjective({ id: 'td.hold', text: 'objectiveHold' }) // required
const frost = defineObjective({ id: 'td.frost', text: 'objectiveFrost', required: false })
export const rules: Rules = { ...game, victory: objectiveVictory }
// in the mission's start
world.objectives.add(DEFENDER, hold, { params: { wave: 0, waves: 10 }, progress: { value: 0, max: 10 } })
world.dialog.say(DEFENDER, { speaker: 'td.commander', text: 'holdTheGate', seconds: 4 })The player sees "Hold" in the quest list with a 0/10 bar, and the commander says a line. Complete every required objective to win; fail one to lose.
Common tasks
Move an objective along, complete it or fail it
world.objectives.progress(DEFENDER, hold.id, 3, { params: { wave: 3 } })
world.objectives.complete(DEFENDER, hold.id)
world.objectives.fail(DEFENDER, lives.id, 'outOfLives') // the defeat screen shows whyAdd detail: 'hold.detail' to defineObjective for text that opens under it in the quest panel.
Play a conversation
defineSequence({
id: 'td.beforeTheBoss',
steps: talk(DEFENDER, [
{ speaker: 'td.commander', text: 'bossComing', seconds: 5 },
{ speaker: 'td.commander', text: 'bossHint', seconds: 5 }
])
})text is a message key, so the words can be translated. Don't speak while the world is being made: start with a wait.
Show a hint
world.hint(player, 'hint.buildTowers', { seconds: 12 }) // hidden for players who turned Hints offShow a countdown
world.timers.show(player, id, { label: 'timer.raiders' }) // a timer from world.timers.after or every
world.timers.hide(player, id)Add a checkpoint
world.checkpoint({ key: 'checkpointWave', params: { wave: 6 } })The defeat screen offers "Retry from wave 6". Where the game has saves (GameScene.saves), the last checkpoint of each mission survives a page reload (client.saves.checkpoint(); saveCheckpoint, loadCheckpoint in code).
Triggers: rules on the map
import { missionRules } from '@v12-engine/engine/ai'
export const rules: Rules = { ...game, packs: [missionRules()] }Now the map's rules from the editor's Rules panel run: when a condition holds, do a list of actions.
{
"id": "gate-reached",
"when": { "region": { "name": "gate" } },
"do": [{ "objective": { "id": "campaign.gate", "do": "complete" } }, { "say": { "speaker": "captain", "text": "weAreIn", "seconds": 4 } }],
"once": true
}Conditions are the computer players' conditions. Code talks to them with tellRules(world, 'bell') (a { told: 'bell' } condition) and hears them as ruleFired.
Objectives on the map
export const rules: Rules = { ...game, packs: [mapObjectives()] }
giveMapObjective(world, 'campaign.gate') // one marked at: 'rule'; or { players, params, progress }Objectives from the editor's Objectives panel with at: 'start' are given to every human player when the map starts.
Make a unit's face talk
world.dialog.say(DEFENDER, { speaker: 'td.commander', text: 'halfway', seconds: 4, unit: 'commander', emotion: 'angry' })The unit's portrait in the HUD talks while the line is said (The HUD).
Capture points (king of the hill)
import { captured, capturePoint, capturesOf, type Rules, capturePack } from '@v12-engine/engine'
export const rules: Rules = {
...game,
packs: [capturePack({ points: [{ id: 'hill', name: 'The hill', at: { x: 40, z: 40 }, radius: 5, time: 12, contested: 'majority' }] })]
}
world.events.on(captured, ({ id, owner, from }) => world.message(owner!, MSG.taken))
capturePoint(world, 'hill', PLAYER) // give one outrightEditor
- Open the Objectives panel, add an objective, set its words and whether it is required, and choose at start or by a rule.
- Open the Rules panel, add a rule, pick its When form (units in a region, time, an objective's status, a word told…) and fill the fields from the map's names.
- Add actions under Do: give or complete an objective, say a line, play a cinematic, spawn a prefab, start a timer, win, lose.
- To place a capture point, add the client's
captureKindto an editor extension'skinds, then place one like any thing.
Reference
Dialog
- Speakers, portraits and voices come from the view:
GameView.cinematics.speakers(name, portrait, colour, voice) andGameView.cinematics.voices(recorded lines by key). A line may name a unit (LineDef.unit, by entity id or map name) and anemotion. - Everyone it is said to hears it at once; a save knows where a conversation was.
- The voice plays on the voice bus and the music ducks under it.
skipLine(a click on the box) ends a line; only a line said to one player alone can be skipped.
Objectives
- Kept per player, saved, and sent in snapshots; the HUD lists them. The
objectiveChangedevent fires on every change. objectiveVictory: a player who does every required objective wins for their team; one who fails one loses. Optional ones never end the game.- Map objectives:
GameMap.data.objectives(MapObjective:{ id, text, detail?, required?, at: 'start' | 'rule' }), given tomapObjectivePlayersas themapStarthook runs.mapObjectivesOf(world.map)reads them;checkMapObjectiveschecks them.
Mission rules (MissionRule)
GameMap.data.rules, each { id, when, do, once?, every?, as? }. A rule fires as its condition turns true, once with once, again every every seconds while it holds. Rules are checked once a second, asked as a player (as; the first human player if left out). What they remember is saved.
Action (MissionActionData) | What it does |
|---|---|
{ objective: { id, do: 'give' | 'complete' | 'fail' } } | One of the map's objectives |
{ say: { speaker, text, seconds, unit, emotion } } | A line |
{ cinematic: { id } } | Plays a cinematic |
{ spawn: { prefab, at, owner } } | A prefab at a point, region or named thing |
{ tell: { computer, word } } | A word to a computer player |
{ relation: { a, b, how } } | Changes two players' relation |
{ timer: { id, seconds, label } } | Starts a timer (shown counting down with label); its id is told to the rules when it goes off |
{ win: true }, { lose: true } | Ends the game |
Each action goes to every human player unless to says otherwise. missionRules({ rules }) adds rules from code beside the map's; missionRuleState(world, id) says whether one holds and how often it fired; checkMissionRules finds problems. There are no variables and no code by name: for more, write a pack of your own that the rules tell and that tells them.
Capture points
capturePack({ points }); points also come from the map as things of the capture kind.
| Field | What it does |
|---|---|
id, name, at, radius | Where it is |
time | Seconds for a side alone in it to take it |
contested | With two sides in it: 'pause' (nothing moves), 'reset' (gains are lost) or 'majority' (the larger side takes it) |
Living units count; buildings, scenery and the neutral player's do not. Events: capturing, captured. capturesOf(world), captureOf(world, id) give CaptureState (owner, by a team, progress 0 to 1). The game's report has captures, for capturePanel and captureMinimap on the HUD. Computer squads have a capture task.
Examples
The campaign starter's src/campaign/missions/siege.ts: two required objectives and an optional one, moved by events (waveBeaten, entityDied), a briefing sequence, and a checkpoint every wave (src/campaign/waves.ts). src/campaign/missions/homecoming.ts uses areas heard through enteredArea. A hook type of your own (defineHookType) lets a mod join in a moment of your game.