Skip to content

AI attack waves ​

When and how a computer attacks: the melee army's own timing, waves you script as data, scouting and attacking together with allies.

Quick start ​

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

export function seatEnemy(world: World): void {
	world.computers.seat(2, {
		settings: {
			waves: {
				groups: [{ id: 'push', units: { footman: 4, rifleman: 2 } }],
				waves: [
					{ group: 'push', after: 120, gatherFor: 20 },
					{ group: { footman: 6, priest: 2 }, after: 90, repeat: true, target: 'weakestBase', when: { time: { after: 300 } } }
				]
			}
		}
	})
}

At two minutes player 2 trains four footmen and two riflemen, gathers them for 20 seconds and attacks the nearest base it knows. Ninety seconds later, and every 90 seconds after that once five minutes have passed, it sends six footmen and two priests at the weakest base.

Common tasks ​

Change when the melee computer attacks ​

ts
world.computers.seat(2, { settings: { army: { firstAttack: 180, attackEvery: 90, waveSize: 8 } } })

Without scripted waves the melee brain makes its own: the first firstAttack seconds in, then every attackEvery, each wave two units bigger.

Only attack when it can win ​

ts
world.computers.seat(2, { settings: { army: { goOdds: 0.6 } } })

A wave that would lose against the enemy army as last seen waits and trains on (up to twice attackEvery).

Turn off raids, harassment and creeping ​

ts
world.computers.seat(2, { settings: { army: { raid: false, harass: false, creep: false } } })

Never surrender ​

ts
world.computers.seat(ENEMY, { settings: { army: { surrender: false } } })

By default the melee computer gives up when it has no hall, no worker and a beaten army for half a minute. A mission's computer should play to the last.

Make waves as the game goes ​

ts
settings: { waves: { waves: (ai, index) => ({ group: { grunt: 3 + index }, after: 60 }) } }

train: false sends what is there and trains nothing (a game of lanes or a defence map).

Scouting ​

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

export const lookOften = (world: World): void => {
	world.computers.seat(2, { settings: { scouting: { lookEvery: 45, flyers: true } } })
}

scout: false turns scouting off; scout: (ai) => points looks where you say.

Team play ​

ts
world.computers.seat(2, { settings: { team: { together: true, gatherFor: 25, say: true, lines: { attacking: 'Now!' } } } })

Computers on one team attack together, answer each other's calls for help, answer a person's pings, and share what they know.

Reference ​

Attack wave (AttackWave) ​

FieldDefaultWhat it does
groupA group id from groups, or units in place (AttackGroup: { footman: 4 }, { caster: 1 })
afterSeconds from the wave before, or from the start
whenA condition; a wave whose condition does not hold when its turn comes is skipped
minForcesShare of the group that is enough
gatherFor15Seconds it gathers at the rally
rallyjust out of homeA point or a name
repeattrue, or a number of times
togetherWait for the team (see below)
targetnearestBaseweakestBase, expansion, army, a point, or a function

The wave whose turn it is becomes wants of the production plan (waves.<type>), and nothing else of the army is trained meanwhile. It is sent as a squad (wave 1, wave 2…) that gathers then attacks; once over, its units are free again. Scripted waves replace the melee army's own attacks. A map's player may carry waves (MapPlayer.data.ai.settings.waves). { wave: { min: 3 } } in a condition counts waves. The report has them (AiReport.waves), and so does the AI tab (Waves).

The melee army's goals ​

Each sends what it holds as a squad. Numbers are MeleeArmyOptions, set under settings.army. A personality's weights scale them.

GoalScoreWhat it does
attack0.8Its own wave at the weakest enemy building it knows (target: 'nearest' for the nearest). Also goes early when their army is weak (No Mercy), answers a wave that fell at its gate (counter), strikes while their army is away (strike), reinforces from home, and presses on to the next target while strong enough (pressOn, pressOdds 0.5)
raid0.6Three fast units at their workers where their army is not, at most once a minute (retreatAt 0.5)
harass0.5The hero and a few at their main before the first wave
expand0.7Two guards at a new base with no tower
creep0.5Takes a camp near home with the hero, between waves
defendThe defence's (Build plans)
help0.7The team's: answers an ally's call for help
scout0.3The scouting's
army optionDefaultWhat it does
firstAttackSeconds before the first wave
attackEverySeconds between waves
waveSizeFighters in the first wave (two more each wave)
goOdds0.4Odds a wave needs to go
waitAtMost2 × attackEveryThen it goes with half, where that would hold
surrender{ when, after }, or false to play to the last
raid{ size: 3, odds: 0.6, every: 60, retreatAt: 0.5, … }, or false
harass{ size: 3, odds: 0.6, every: 90, retreatAt: 0.5 }, or false
expand{ guards: 2, spare: 0 }, or false
creep{ every: 40, from: 30, reach: 70, party: 3 }, or false
strike{ awayFor, odds }, or false

The army's memory (next wave's time and size, how many went, last raid) is kept under melee.army (meleeArmyOf(ai)).

Scouting (scouting settings) ​

OptionDefaultWhat it does
lookEvery90Seconds out of sight before a place is due again
scoutonfalse for none; a function for your own points
flyersUse an idle flyer first
expansions, armyonLook at their likely expansions, and where their army was seen
from15Seconds before it starts

It looks first at the enemy starts it was told (AiOptions.enemyBases), then their remembered bases, likely expansions and army. One unit goes (an idle flyer, else the fastest idle non-hero fighter, else a worker). A stuck scout tries twice, then skips the place.

Team play (team settings) ​

OptionDefaultWhat it does
askForHelponPosts help when a raid is more than it can meet
defendUsersonAnswers calls for help (weight 0.7) with a squad at odds helpOdds (0.5)
answerPingsonA person's push, hold and retreat pings (weight 0.75)
togetherWaves of the team go at one target at one time
gatherFor20Seconds to wait for the others
say, linesoffChat lines when it attacks, helps or retreats (attacking, helping, retreating)

A ping's meaning comes from RuleSettings.talk.pings.meanings (help, attack, defend, rally, ignore). The team's board (TeamBoard, core.ai.teams) is kept in a save and never sent to any player.