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
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
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
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
world.computers.seat(2, { settings: { army: { raid: false, harass: false, creep: false } } })Never surrender
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
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
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
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)
| Field | Default | What it does |
|---|---|---|
group | A group id from groups, or units in place (AttackGroup: { footman: 4 }, { caster: 1 }) | |
after | Seconds from the wave before, or from the start | |
when | A condition; a wave whose condition does not hold when its turn comes is skipped | |
minForces | Share of the group that is enough | |
gatherFor | 15 | Seconds it gathers at the rally |
rally | just out of home | A point or a name |
repeat | true, or a number of times | |
together | Wait for the team (see below) | |
target | nearestBase | weakestBase, 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.
| Goal | Score | What it does |
|---|---|---|
attack | 0.8 | Its 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) |
raid | 0.6 | Three fast units at their workers where their army is not, at most once a minute (retreatAt 0.5) |
harass | 0.5 | The hero and a few at their main before the first wave |
expand | 0.7 | Two guards at a new base with no tower |
creep | 0.5 | Takes a camp near home with the hero, between waves |
defend | The defence's (Build plans) | |
help | 0.7 | The team's: answers an ally's call for help |
scout | 0.3 | The scouting's |
army option | Default | What it does |
|---|---|---|
firstAttack | Seconds before the first wave | |
attackEvery | Seconds between waves | |
waveSize | Fighters in the first wave (two more each wave) | |
goOdds | 0.4 | Odds a wave needs to go |
waitAtMost | 2 × attackEvery | Then 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)
| Option | Default | What it does |
|---|---|---|
lookEvery | 90 | Seconds out of sight before a place is due again |
scout | on | false for none; a function for your own points |
flyers | Use an idle flyer first | |
expansions, army | on | Look at their likely expansions, and where their army was seen |
from | 15 | Seconds 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)
| Option | Default | What it does |
|---|---|---|
askForHelp | on | Posts help when a raid is more than it can meet |
defendUsers | on | Answers calls for help (weight 0.7) with a squad at odds helpOdds (0.5) |
answerPings | on | A person's push, hold and retreat pings (weight 0.75) |
together | Waves of the team go at one target at one time | |
gatherFor | 20 | Seconds to wait for the others |
say, lines | off | Chat 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.