5. Mission three: the hero
Goal: march Aldric up the pass to Varga's hold. New: a shop and items, a cinematic from a trigger with a choice the rules branch on, prisoners who change sides, and the campaign's end. Aldric arrives with his level, abilities and items (chapter 7 carries him).
Make the map
The road up the pass, a trader by it, the hold at the top with a gate, cells to one side. Names: the knight hero, the trader trader, Varga warlord, his men guard1–guard3, a point hold, regions gate and cells. Place the prisoners for the neutral player.
Add a shop and items
export const trader = building({
id: UNIT.trader,
name: 'Trader',
radius: 1.2,
footprint: { w: 2, d: 2 },
stats: { health: 1000 },
invulnerable: true,
sight: 8,
sells: ['healingPotion', 'steelSword', 'swiftBoots']
})
export const items: ItemDef[] = [
{
id: 'healingPotion',
name: 'Healing Potion',
description: 'Drunk, heals 200. Three in the bottle',
cost: { gold: 60 },
charges: 3,
ability: 'drinkPotion'
},
{ id: 'steelSword', name: 'Steel Sword', description: '+12 attack damage', cost: { gold: 180 }, bonus: { stats: { attackDamage: 12 } } },
{ id: 'swiftBoots', name: 'Swift Boots', description: '+0.8 move speed', cost: { gold: 120 }, bonus: { stats: { moveSpeed: 0.8 } } }
]A building that sells is a shop for whoever stands near. An item gives a bonus to its carrier, or an ability with charges. The hero's six slots (inventory: 6) carry into the next mission.
Play a cinematic from a trigger
// src/campaign/missions/warlord.ts
export const atTheGate = defineSequence({ id: 'campaign.atTheGate', steps: [
waitFor(enteredArea, (_world, { area, entity }) => area === GATE && entity.owner === PLAYER),
(world) => {
const hero = world.named('hero')
const warlord = world.named('warlord')
playCinematic(world, PARLEY, { to: PLAYER, hold: true, params: { hero: hero?.id, warlord: warlord?.id } })
}
] })The cinematic is a script in the view: camera on Varga, then Aldric, a line each, then a question.
// src/campaign/view/cinematics.ts
export const parley: Cinematic = async (cut, params) => {
const { hero, warlord } = (params ?? {}) as { hero?: number; warlord?: number }
if (hero === undefined || warlord === undefined) return
await cut.camera({ at: { entity: warlord }, distance: 14, pitch: 0.4, yaw: 0.6 }, 1.2)
await cut.say(VARGA, 'So the knight walks up to my door, with what is left of his village behind him.', 5)
await cut.camera({ at: { entity: hero }, distance: 10, pitch: 0.3, yaw: -0.8 }, 1)
await cut.say(ALDRIC, 'Your camp is ash, Varga. Your siege broke on our walls. This ends here.', 5)
const answer = await cut.choose(
[
{ id: 'duel', label: 'Face him alone' },
{ id: 'charge', label: 'Charge, all of us' }
],
{ name: PARLEY_CHOICE, question: 'How does this end?', seconds: 15, default: 'charge' }
)
if (answer === 'duel') await cut.say(ALDRIC, 'Stand back, all of you. He is mine.', 3)
else await cut.say(BRANN, 'With me! For the village!', 3)
}Branch on the choice
The answer reaches the rules as the player's cinematicChoice command, so every screen and replay agrees:
export const theChoice = defineListener({
event: cinematicChoice,
id: 'campaign.theChoice',
run(world, { cinematic: id, choice, player }) {
if (id !== PARLEY || player !== PLAYER || !world.objectives.has(PLAYER, slayWarlord.id)) return
const warlord = world.named('warlord')
const hero = world.named('hero')
if (choice === 'duel') {
for (const man of guards(world)) world.setOwner(man, MAP_NEUTRAL)
if (warlord?.alive) applyBuff(world, warlord, 'rallied', 60)
world.sequences.start(duel)
} else {
if (hero?.alive) for (const man of guards(world)) man.order('attack', hero)
world.sequences.start(charge)
}
}
})A cinematic from the Cinematic panel asks the same way: a dialog clip with options. See Cinematics.
Free the prisoners
export const cellsOpened = defineListener({
event: enteredArea,
id: 'campaign.cellsOpened',
run(world, { area, entity }) {
if (area !== CELLS || entity.owner !== PLAYER || !world.objectives.has(PLAYER, freePrisoners.id)) return
if (world.objectives.get(PLAYER, freePrisoners.id).status !== 'open') return
for (const prisoner of [...world.index.ownedBy(MAP_NEUTRAL)])
if (prisoner.alive && prisoner.def.id === UNIT.prisoner) world.setOwner(prisoner, PLAYER)
world.objectives.complete(PLAYER, freePrisoners.id)
world.sequences.start(freed)
}
})world.setOwner is all it takes: they're the player's, in his colour, taking his orders.
End the campaign
The hold's brain keeps the guards by Varga (guard('warlord', { units: { named: ['guard1', 'guard2', 'guard3'] } })) and holds the rest (holdPosition('hold')). When Varga dies, play the outro and win:
export const theEnd = defineSequence({ id: 'campaign.theEnd', steps: [
waitFor(entityDied, (_world, { entity }) => entity.def.id === UNIT.warlord),
wait(1.5),
cinematic('campaign.outro', { hold: true }),
wait(0.5),
(world) => {
world.objectives.complete(PLAYER, slayWarlord.id)
world.objectives.complete(PLAYER, keepHero.id)
}
] })If Aldric falls, keepHero fails and so does the mission.
Try it
Open the pass and click Play here. Buy a potion, walk to the gate, choose, free the prisoners, face Varga.
Next: 6. The intro and the outro.