Skip to content

3. Mission one: the base ​

Goal: Homecoming. Burn the Red Hand's camp and keep your hall. Along the way: named places, objectives, an area that triggers dialog, an optional objective, a prefab, and a computer that raids.

Make the map, with names ​

  1. In the editor, build the homestead: your hall, farms, barracks, a mine and two peasants for player 1; the Red Hand's barracks, farms, tower, raiders and warlocks for player 2; woods, a stream with a ford, and a road.
  2. Select the hall and name it hall in the Inspector. Name the knight hero and two footmen escort1 and escort2.
  3. Add points (Markers › Point) camp at the enemy camp and outpost.
  4. Add regions (Markers › Region) ford over the ford and caravan over a wreck in the woods.
  5. In Map settings › Players, make player 2 the computer. Save.

The rules never hold coordinates: they ask world.named('hall'), world.map.point('camp'), areaShapeOf({ region: 'ford' }, world.map.regions).

Add objectives ​

ts
// src/campaign/missions/homecoming.ts
export const razeCamp = defineObjective({ id: 'campaign.raze', text: MSG.objectiveRaze })
export const keepHall = defineObjective({ id: 'campaign.hall', text: MSG.objectiveHall })
export const findCaravan = defineObjective({ id: 'campaign.caravan', text: MSG.objectiveCaravan, required: false })

Under objectiveVictory you win when every required objective is done and lose when one fails. text is a message key; the words live in the view.

Start the mission once ​

Set up only for a fresh game: a loaded save already has objectives, areas, sequences, the computer and timers.

ts
export function homecoming(world: World, fresh: boolean): void {
	if (!fresh) return
	const { objectives } = world
	objectives.add(PLAYER, razeCamp, { progress: { value: 0, max: enemyBuildings(world).length } })
	objectives.add(PLAYER, keepHall)
	objectives.add(PLAYER, findCaravan)
	for (const [id, region] of REGIONS) {
		const shape = areaShapeOf({ region }, world.map.regions)
		if (shape) world.areas.add({ id, shape })
	}
	// the outpost, where the map says: a prefab spawned by the rules
	world.spawnPrefab(outpost, { at: world.map.point('outpost'), owner: PLAYER })
	// the Red Hand's computer, remembered with the world: a save seats it again as it loads
	const hall = world.named('hall')
	world.computers.seat(ENEMY, redHand, { enemyBases: [hall ? { x: hall.pos.x, z: hall.pos.z } : world.map.point('outpost')] })
	world.timers.every(90, reinforcements, {})
	world.sequences.start(briefing)
	world.sequences.start(atTheFord)
}

The campaign scene calls it (chapter 7); everything else (Play here, a server, tests) goes through startMission, which picks by map:

ts
// src/campaign/index.ts
const MISSIONS: Record<string, (world: World, fresh: boolean) => void> = { homestead: homecoming, fort: siege, pass: warlord }

export function startMission(world: World, map: Pick<GameMap, 'name'> | undefined, fresh = true): void {
	const key = map && mapKeyOf(map)
	const mission = key && MISSIONS[key]
	if (mission) mission(world, fresh)
}

Move the objectives with a listener ​

ts
export const buildingFell = defineListener({
	event: entityDied,
	id: 'campaign.homeBuildingFell',
	run(world, { entity }) {
		if (entity.def.kind !== 'building' || !world.objectives.has(PLAYER, razeCamp.id)) return
		const { objectives } = world
		if (entity.owner === ENEMY) {
			const left = enemyBuildings(world).length
			const total = objectives.get(PLAYER, razeCamp.id).progress?.max ?? left
			objectives.progress(PLAYER, razeCamp.id, total - left)
			if (left) return
			objectives.complete(PLAYER, razeCamp.id)
			objectives.complete(PLAYER, keepHall.id)
			if (objectives.get(PLAYER, findCaravan.id).status === 'open') objectives.fail(PLAYER, findCaravan.id)
			world.sequences.start(wellDone)
		} else if (entity.owner === PLAYER && entity.def.id === UNIT.hall) objectives.fail(PLAYER, keepHall.id, MSG.hallFell)
	}
})

Declare listeners and list them in the rules so a loaded game has them; world.events.on doesn't survive a save. The has check keeps free play on the map quiet. fail's reason is what the defeat screen says.

Trigger dialog from an area ​

ts
export const atTheFord = defineSequence({ id: 'campaign.atTheFord', steps: [
	waitFor(enteredArea, (_world, { area, entity }) => area === FORD && entity.owner === PLAYER),
	(world) => {
		const camp = world.map.point('camp')
		world.reveal(world.player(PLAYER).team, camp, 12, 10)
	},
	...talk(PLAYER, [{ speaker: BRANN, text: MSG.homeFord, seconds: 5 }])
] })

A sequence waits for an event, says lines, runs functions, and is saved mid-way. Speakers' names and colours are the view's (cinematics.speakers).

Spawn a prefab ​

ts
export const outpost = definePrefab({
	id: 'campaign.outpost',
	name: 'Outpost',
	contents: {
		objects: [
			{ type: UNIT.tower, x: 0, z: 0 },
			{ type: UNIT.wall, x: -2.5, z: 0.5 },
			{ type: UNIT.wall, x: 2.5, z: 0.5 },
			{ type: UNIT.archer, x: 0, z: -1.8, facing: Math.PI }
		]
	}
})

Or select things in the editor and Save as a prefab: the starter's watchpost.prefab.json is one, loaded with prefabsFrom.

Add a computer that holds and raids ​

ts
export const redHand = missionBrain({
	id: 'campaign.redHand',
	modules: [holdPosition('camp'), waveFrom('camp', { group: 3, every: 90 })]
})

export const reinforcements = defineTimer({ id: 'campaign.reinforcements', run: (world) => {
	if (world.winner !== null) return
	const camp = world.map.point('camp')
	if (!enemyBuildings(world).length) return
	for (const dx of [-1.5, 1.5]) world.spawn(UNIT.raider, ENEMY, { x: camp.x + dx, z: camp.z + 1 })
} })

A mission brain only uses what it has: it holds camp and sends groups of three at your hall every 90 seconds. See Add a computer player.

List it all in the rules ​

ts
// src/campaign/index.ts
export const campaign: Rules = layData(
	{
		// …
		prefabs: [outpost, ...prefabsFrom({ 'watchpost.prefab.json': watchpost }, { prefix: 'campaign.' })],
		brains: [redHand],
		listeners: [...homecomingListeners],
		timers: [reinforcements],
		sequences: [...homecomingSequences],
		victory: objectiveVictory
	},
	dataFile
)

Try it ​

Open the homestead and click Play here. Walk Aldric to the ford: Brann speaks and the camp lights up. Find the wreck for gold. Burn the camp to win; lose the hall to lose.

Next: 4. Mission two: the siege.