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.
// 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 RTS | In V12 | Page |
|---|---|---|
| The loading screen with the mission's text | MissionDef.loading (text, picture), or the map's loading and preview | Loading screens |
| The briefing before the mission | MissionDef.briefing (words, a picture, the objectives) | The campaign menu |
| The intro cinematic, letterboxed, skippable | cinematic(id, { hold: true, wait: 'ended' }) as a sequence's step | Triggering from a mission |
| "Quest discovered" / main and optional quests | defineObjective (required: false for optional), world.objectives.add | Objective recipes |
| "Quest updated" / "Quest completed" / "Quest failed" | objectives.progress, complete, fail: the HUD announces each | Objective recipes |
| The quest log (its requirements and description) | the HUD's objectives part: text, and detail that opens under it | Your own HUD |
| A character talks, face in the portrait | talk(to, lines) with a speaker (face, colour, voice in GameView.cinematics.speakers) | Missions |
| A hint on the screen | world.hint(player, key, { seconds }) | Missions |
| A region trigger ("a unit enters region") | an area (a named region of the map), heard as enteredArea, leftArea | Triggers |
| "A unit dies" trigger | entityDied | Triggers |
| A timer window counting down | world.timers.after, then world.timers.show(player, id, { label }) | Objective recipes |
| The camera pans to show something | cameraFor(world, player, { pan: { x, z, seconds: 2 } }) | |
| Fog lifted over a spot for a moment | world.reveal(team, point, radius, seconds) | |
| A ping on the minimap | ping(world, player, point) | |
| Units placed on the map, named | the editor's Inspector name, read with world.named('hero') | Make a map |
| The enemy base that builds and attacks | a computer seat with a brain: world.computers.seat | AI for missions and campaigns |
| Neutral hostile camps | creep camps | Creeps |
| Victory and defeat | Rules.victory: objectiveVictory: every main quest done wins, any main quest failed loses | Winning and losing |
| The outro cinematic | a sequence: waitFor the moment, cinematic(id, { hold: true }), then complete the quests | The mission |
| The hero carried to the next mission | MissionDef.carry, heroesAt | A 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.
// 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 trigger | V12 |
|---|---|
| Map initialization | m.plays(map).onStart((world, { fresh }) => …), with fresh true only for a new game |
| Elapsed game time is 300 seconds | waitUntil((world) => world.time >= 300), or world.timers.after(300, timer) |
| Every 60 seconds | world.timers.every(60, timer, { times }) |
| A unit enters / leaves a region | enteredArea, leftArea; the region is the map's, or world.areas.add |
| A unit dies | entityDied (entity, killer) |
| A hero acquires an item | itemPicked (entity, item) |
| A unit is trained | unitTrained |
| A hero becomes revived | heroRevived |
| A quest changes | objectiveChanged (player, objective, was) |
| Wait for a condition | waitUntil((world) => …) in a sequence |
| Wait for a cinematic to end | cinematic(id, { wait: 'ended' }) |
| Turn a trigger off | a listener checks a state first; world.sequences.stop(id) |
| Integer and boolean variables | a 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
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 defeat | A 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.
// 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
- Place the hero and name it
kaelenin the Inspector; draw the regionsmill,cage,camp,pitand the pointhallin the Markers panel. - Make the intro and outro in the Cinematic panel (Make a cinematic).
- Open the Campaign panel to add the mission, its loading words and its briefing.
- Or make the whole mission without code: Objectives for the quests, Rules for the triggers (Objectives, rules, campaign).
Reference
- Objective recipes: every classic objective, one recipe each.
- AI for missions and campaigns: enemy bases, waves, camps, allies, difficulty.
- Missions, objectives and triggers: dialog, hints, timers, checkpoints, mission rules, capture points.
- Make a mission, A campaign, and the tutorial Let's make a basic campaign.
- The
campaignstarter'ssrc/campaign/missions/: three missions written this way.