Skip to content

Missions the classic way ​

A classic RTS campaign mission has the same parts every time: a loading screen with the mission's words, an intro cinematic, a hero and a base, a quest log with main and optional quests, characters who talk with their faces in the HUD, triggers on the map, an enemy base that builds and attacks, and an outro before the victory screen. This page puts each part in its place in V12 and builds one whole mission.

ts
// in src/missions/ford.ts
export const ford = game.mission('ford', (m) => {
	const burnTheCamp = m.objective({ id: 'burn', text: 'quest.burn', detail: 'quest.burn.detail' }) // a main quest
	const kaelenLives = m.objective({ id: 'kaelen', text: 'quest.kaelen' }) // a main quest
	const freeTheVillagers = m.objective({ id: 'villagers', text: 'quest.villagers', required: false }) // an optional quest

	const opening = m.sequence({ id: 'opening', steps: [
		wait(0),
		cinematic('ford.intro', { hold: true, wait: 'ended' }), // the intro, the game held under it
		...talk(PLAYER, [{ speaker: 'kaelen', text: 'line.ford.1', seconds: 5 }]),
		(world) => world.objectives.add(PLAYER, burnTheCamp, { progress: { value: 0, max: 6 } }), // "New objective"
		(world) => world.objectives.add(PLAYER, kaelenLives),
		(world) => world.hint(PLAYER, 'hint.ford.tents', { seconds: 10 })
	] })

	m.plays('ford').onStart((world, { fresh }) => {
		if (!fresh) return
		world.computers.seat(ENEMY, { brain: bloodfang })
		world.sequences.start(opening)
	})
})

On the map ford: the intro plays, Kaelen speaks, the quest log fills with two main quests ("New objective: Burn the Bloodfang camp", with a 0/6 bar) and a hint shows. The enemy's camp holds its ground.

The parts of a classic mission ​

In a classic RTSIn V12Page
The loading screen with the mission's textMissionDef.loading (text, picture), or the map's loading and previewLoading screens
The briefing before the missionMissionDef.briefing (words, a picture, the objectives)The campaign menu
The intro cinematic, letterboxed, skippablecinematic(id, { hold: true, wait: 'ended' }) as a sequence's stepTriggering from a mission
"Quest discovered" / main and optional questsdefineObjective (required: false for optional), world.objectives.addObjective recipes
"Quest updated" / "Quest completed" / "Quest failed"objectives.progress, complete, fail: the HUD announces eachObjective recipes
The quest log (its requirements and description)the HUD's objectives part: text, and detail that opens under itYour own HUD
A character talks, face in the portraittalk(to, lines) with a speaker (face, colour, voice in GameView.cinematics.speakers)Missions
A hint on the screenworld.hint(player, key, { seconds })Missions
A region trigger ("a unit enters region")an area (a named region of the map), heard as enteredArea, leftAreaTriggers
"A unit dies" triggerentityDiedTriggers
A timer window counting downworld.timers.after, then world.timers.show(player, id, { label })Objective recipes
The camera pans to show somethingcameraFor(world, player, { pan: { x, z, seconds: 2 } })
Fog lifted over a spot for a momentworld.reveal(team, point, radius, seconds)
A ping on the minimapping(world, player, point)
Units placed on the map, namedthe editor's Inspector name, read with world.named('hero')Make a map
The enemy base that builds and attacksa computer seat with a brain: world.computers.seatAI for missions and campaigns
Neutral hostile campscreep campsCreeps
Victory and defeatRules.victory: objectiveVictory: every main quest done wins, any main quest failed losesWinning and losing
The outro cinematica sequence: waitFor the moment, cinematic(id, { hold: true }), then complete the questsThe mission
The hero carried to the next missionMissionDef.carry, heroesAtA campaign
"Retry from checkpoint"world.checkpoint(key)Missions

Triggers ​

A classic trigger is an event, conditions, and actions. In V12 that is a listener (always on) or a sequence (a script that waits, then acts, then may wait again). Both are saved with the game.

ts
// always on: "when a unit of the player enters the ruins, and the quest is open, complete it"
const ruinsReached = defineListener({
	id: 'ford.ruinsReached',
	event: enteredArea,
	run(world, { area, entity }) {
		if (area !== 'ruins' || entity.owner !== PLAYER) return
		if (!world.objectives.has(PLAYER, 'ford.ruins') || world.objectives.get(PLAYER, 'ford.ruins').status !== 'open') return
		world.objectives.complete(PLAYER, 'ford.ruins')
	}
})

// a script: wait for the moment, then a scene of talk
const atTheBridge = defineSequence({ id: 'ford.atTheBridge', steps: [
	waitFor(enteredArea, (_world, { area, entity }) => area === 'bridge' && entity.owner === PLAYER),
	(world) => cameraFor(world, PLAYER, { pan: { ...world.map.point('camp'), seconds: 2 } }),
	(world) => void world.reveal(world.player(PLAYER).team, world.map.point('camp'), 12, 8),
	...talk(PLAYER, [{ speaker: 'scout', text: 'line.bridge.camp', seconds: 4 }])
] })
Classic triggerV12
Map initializationm.plays(map).onStart((world, { fresh }) => …), with fresh true only for a new game
Elapsed game time is 300 secondswaitUntil((world) => world.time >= 300), or world.timers.after(300, timer)
Every 60 secondsworld.timers.every(60, timer, { times })
A unit enters / leaves a regionenteredArea, leftArea; the region is the map's, or world.areas.add
A unit diesentityDied (entity, killer)
A hero acquires an itemitemPicked (entity, item)
A unit is trainedunitTrained
A hero becomes revivedheroRevived
A quest changesobjectiveChanged (player, objective, was)
Wait for a conditionwaitUntil((world) => …) in a sequence
Wait for a cinematic to endcinematic(id, { wait: 'ended' })
Turn a trigger offa listener checks a state first; world.sequences.stop(id)
Integer and boolean variablesa component of the world (defineComponent, world.state), saved with it

Regions are drawn and named in the editor's Markers panel; the mission adds those it watches as areas (world.areas.add({ id, shape: areaShapeOf({ region: 'bridge' }, world.map.regions)! })), or the rules list them in Rules.areas. A sequence is a list of steps, not an async function, so a save made halfway resumes at the same step. world.objectives.get expects a quest the player was given: ask has first where it may not be yet.

Triggers can also be made without code: the editor's Rules panel writes mission rules into the map (when a condition, do a list of actions).

Winning and losing ​

ts
export const rules: Rules = { ...game, victory: objectiveVictory }

With objectiveVictory, the mission is won when every main quest (required, the default) is done, and lost when any main quest fails. Optional quests never end it. That gives the classic defeats for free:

Classic defeatA main quest that fails
The hero dies"Kaelen must survive", failed on entityDied
The town hall is destroyed"The hall must stand", failed on entityDied
Time runs out"Reach the gate before dawn", failed by a timer
The escorted unit dies"Bring the caravan home", failed on entityDied

fail(player, id, reason) gives the defeat screen its words ("Kaelen has fallen."). The end screen's own words are GameView.hud.outcome.

The whole mission ​

The ford: burn the Bloodfang camp's six tents, keep Kaelen alive, and, if you find them, free the villagers held at the mill. The camp attacks at five minutes.

ts
// in src/missions/ford.ts
import {
	areaShapeOf, cinematic, defineListener, defineObjective, defineSequence, enteredArea, entityDied,
	talk, wait, waitFor, waitUntil, type World
} from '@v12-engine/engine'
import { holdPosition, missionBrain, waveFrom, when } from '@v12-engine/engine/ai'

const PLAYER = 1
const ENEMY = 2

// the quests
export const burnTheCamp = defineObjective({ id: 'ford.burn', text: 'quest.burn', detail: 'quest.burn.detail' })
export const kaelenLives = defineObjective({ id: 'ford.kaelen', text: 'quest.kaelen' })
export const freeTheVillagers = defineObjective({ id: 'ford.villagers', text: 'quest.villagers', required: false })

// the enemy: holds its camp, sends what spawns at the pit, and goes for the hall at five minutes
export const bloodfang = missionBrain({
	id: 'ford.bloodfang',
	modules: [holdPosition('camp', { radius: 14 }), waveFrom('pit', { group: 4, every: 120, first: 300 })],
	rules: [when({ time: { after: 300 } }).once().do({ say: 'attack', data: { at: 'hall' } })]
})

const tentsLeft = (world: World) => world.find({ owner: ENEMY, type: 'tent' }).length

// the opening: intro, a line, the quests, a hint
export const opening = defineSequence({ id: 'ford.opening', steps: [
	wait(0),
	cinematic('ford.intro', { hold: true, wait: 'ended' }),
	...talk(PLAYER, [
		{ speaker: 'kaelen', text: 'line.ford.1', seconds: 5 },
		{ speaker: 'captain', text: 'line.ford.2', seconds: 5 }
	]),
	(world) => world.objectives.add(PLAYER, burnTheCamp, { progress: { value: 0, max: tentsLeft(world) } }),
	(world) => world.objectives.add(PLAYER, kaelenLives),
	(world) => world.hint(PLAYER, 'hint.ford.tents', { seconds: 10 })
] })

// the optional quest is discovered at the mill, and done when the cage is reached
export const theMill = defineSequence({ id: 'ford.mill', steps: [
	waitFor(enteredArea, (_world, { area, entity }) => area === 'ford.mill' && entity.owner === PLAYER),
	...talk(PLAYER, [{ speaker: 'villager', text: 'line.mill.help', seconds: 4 }]),
	(world) => world.objectives.add(PLAYER, freeTheVillagers), // "New objective" (optional)
	waitFor(enteredArea, (_world, { area, entity }) => area === 'ford.cage' && entity.owner === PLAYER),
	(world) => {
		for (const villager of world.find({ owner: world.neutral, type: 'villager' })) world.setOwner(villager, PLAYER)
		world.objectives.complete(PLAYER, freeTheVillagers.id)
	}
] })

// a tent burns: the quest moves along; the last one, the outro and the win
export const tentBurned = defineListener({
	id: 'ford.tentBurned',
	event: entityDied,
	run(world, { entity }) {
		if (entity.owner !== ENEMY || entity.def.id !== 'tent' || !world.objectives.has(PLAYER, burnTheCamp.id)) return
		const quest = world.objectives.get(PLAYER, burnTheCamp.id)
		if (quest.status !== 'open') return
		world.objectives.progress(PLAYER, burnTheCamp.id, quest.progress!.max - tentsLeft(world))
		if (tentsLeft(world) === 0) world.sequences.start(ending)
	}
})

// the hero falls: the mission is lost, with the reason on the defeat screen
export const kaelenFell = defineListener({
	id: 'ford.kaelenFell',
	event: entityDied,
	run(world, { entity }) {
		if (world.nameOf(entity) !== 'kaelen' || !world.objectives.has(PLAYER, kaelenLives.id)) return
		if (world.objectives.get(PLAYER, kaelenLives.id).status === 'open') world.objectives.fail(PLAYER, kaelenLives.id, 'defeat.kaelen')
	}
})

export const ending = defineSequence({ id: 'ford.ending', steps: [
	wait(1),
	cinematic('ford.outro', { hold: true }),
	(world) => {
		const { objectives } = world
		if (objectives.has(PLAYER, freeTheVillagers.id) && objectives.get(PLAYER, freeTheVillagers.id).status === 'open') objectives.fail(PLAYER, freeTheVillagers.id)
		objectives.complete(PLAYER, kaelenLives.id)
		objectives.complete(PLAYER, burnTheCamp.id) // the last main quest: the mission is won
	}
] })

/** Given once, as a new game of the mission starts. A loaded game has all of it already */
export function startFord(world: World, fresh: boolean): void {
	if (!fresh) return
	for (const region of ['mill', 'cage']) world.areas.add({ id: `ford.${region}`, shape: areaShapeOf({ region }, world.map.regions)! })
	world.computers.seat(ENEMY, { brain: bloodfang, enemyBases: [world.map.point('hall')] })
	world.sequences.start(opening)
	world.sequences.start(theMill)
}

export const fordRules = {
	brains: [bloodfang],
	sequences: [opening, theMill, ending],
	listeners: [tentBurned, kaelenFell]
}

Spread the lists at the bottom into your Rules (with victory: objectiveVictory), and call startFord(world, fresh) from the mission's onStart in defineCampaign. The words (quest.burn, line.ford.1, defeat.kaelen) go in GameView.hud.messages; the speakers in GameView.cinematics.speakers.

Done: the intro plays, the quests appear, the camp holds and attacks at five minutes, the mill reveals an optional quest, the tents count down to the outro and the victory screen, and Kaelen's death ends it.

In the editor ​

  1. Place the hero and name it kaelen in the Inspector; draw the regions mill, cage, camp, pit and the point hall in the Markers panel.
  2. Make the intro and outro in the Cinematic panel (Make a cinematic).
  3. Open the Campaign panel to add the mission, its loading words and its briefing.
  4. Or make the whole mission without code: Objectives for the quests, Rules for the triggers (Objectives, rules, campaign).

Reference ​