Skip to content

Add the classic RTS rules ​

Tomes, mana burn, runes, waygates, breakable rocks and friendly fire are each a pack you add to packs. A game without one pays nothing for it.

RulePack
TomestomesPack()
Mana burnmanaBurnPack()
Runes (power-ups)runesPack()
Waygates, town portalportalsPack()
Rocks and gates to breakdestructiblesPack()
Friendly firefriendlyFirePack()
A handicapno pack: a stats hook

Tomes ​

The tome effect gives what it reaches a stat for good (gain), experience (xp) or levels (levels). A tome is an item with one charge.

ts
import type { AbilityDef, ItemDef } from '@v12-engine/engine'

export const readStrength: AbilityDef = {
	id: 'readStrength',
	name: 'Tome of Strength',
	target: 'none',
	effects: [{ type: 'tome', gain: { stats: { strength: 1 } } }]
}
export const readPower: AbilityDef = { id: 'readPower', name: 'Tome of Power', target: 'none', effects: [{ type: 'tome', levels: 1 }] }
export const tomes: ItemDef[] = [
	{ id: 'tomeOfStrength', name: 'Tome of Strength', cost: { gold: 150 }, charges: 1, ability: 'readStrength' },
	{ id: 'tomeOfPower', name: 'Tome of Power', cost: { gold: 500 }, charges: 1, ability: 'readPower' }
]

In code: gainStats(world, unit, { stats: { strength: 1 } }). Gains are kept in saves (gainedStats).

Mana burn ​

The manaBurn effect takes amount mana and deals as much damage, times ratio, as magic unless damageType says.

ts
import type { AbilityDef } from '@v12-engine/engine'

export const manaBurn: AbilityDef = {
	id: 'manaBurn',
	name: 'Mana Burn',
	target: 'unit',
	targets: { enemies: true },
	range: 8,
	cooldown: 7,
	manaCost: 50,
	effects: [{ type: 'manaBurn', amount: [50, 100, 150] }]
}
export const feedback: AbilityDef = {
	id: 'feedback',
	name: 'Feedback',
	target: 'passive',
	effects: [{ type: 'onHit', effects: [{ type: 'manaBurn', amount: 8 }] }]
}

In code: burnMana(world, target, amount, source, { ratio, damageType }).

Runes ​

With runesPack(), an item with powerUp: true is used the moment it's picked up, never carried.

ts
import type { AbilityDef, ItemDef } from '@v12-engine/engine'

export const runeHeal: AbilityDef = {
	id: 'runeHeal',
	name: 'Rune of Healing',
	target: 'none',
	effects: [{ type: 'heal', amount: 320, radius: 6, affects: 'allies' }]
}
export const runeOfHealing: ItemDef = { id: 'runeOfHealing', name: 'Rune of Healing', cost: {}, ability: 'runeHeal', powerUp: true }

runesPack({ powerUp, takes }) decides which items are power-ups and who picks them up; usePowerUp(world, unit, groundId) uses one.

Waygates and town portals ​

A building with waygate: true gets a Leads to field in the editor's Inspector. Units sent to it come out there. The townPortal effect takes the caster and up to count units within radius home.

ts
import type { AbilityDef, UnitTypeDef } from '@v12-engine/engine'

export const gate: UnitTypeDef = {
	id: 'waygate',
	name: 'Waygate',
	kind: 'building',
	radius: 1.5,
	sight: 4,
	footprint: { w: 3, d: 3 },
	stats: { health: 1000 },
	invulnerable: true,
	waygate: true
}
export const scroll: AbilityDef = {
	id: 'townPortal',
	name: 'Town Portal',
	target: 'point',
	range: Infinity,
	castTime: 3,
	effects: [{ type: 'townPortal', radius: 7, count: 12 }]
}

In code: setWaygate(gate, 'east'), waygateTarget(world, gate), portal(world, unit, to), townPortal(world, hero, near, radius, count). Screens hear portalUsed for a flash and a sound.

Rocks and gates to break down ​

With destructiblesPack(), a neutral destructible building is attacked when a unit is told to, never on its own.

ts
import { type UnitTypeDef, destructiblesPack } from '@v12-engine/engine'

export const rocks: UnitTypeDef = {
	id: 'rocks',
	name: 'Rocks',
	kind: 'building',
	radius: 1,
	sight: 0,
	footprint: { w: 2, d: 2 },
	stats: { health: 1500, armor: 5 },
	destructible: true
}
// in code, in place of the type's field: anything of the neutral player's that is not a tree
export const pack = destructiblesPack({ destructible: (world, thing) => world.player(thing.owner).neutral && !thing.def.fellable })

Friendly fire ​

With friendlyFirePack(), the attack command (A, then click) can target your own side or an ally. Units never pick them on their own.

ts
import { friendlyFirePack } from '@v12-engine/engine'

// only units, not buildings
export const pack = friendlyFirePack({ attacks: (_world, _attacker, target) => target.isUnit })

A player's handicap ​

A stats hook gives a player's units part of their health:

ts
import { defineHook, type Rules } from '@v12-engine/engine'

/** A player's handicap: the part of their units' health they have, by player */
const handicaps: Record<number, number> = { 2: 0.7 }

export const handicap = defineHook({
	hook: 'stats',
	id: 'handicap',
	run(_world, { entity, add }) {
		const part = handicaps[entity.owner]
		if (part !== undefined) add({ percent: { health: part - 1 } })
	}
})

export const game: Partial<Rules> = { hooks: [handicap] }

If the handicap changes mid-game, call invalidateStats(world).

See Give my game heroes and Making a game for what a pack is.