five-on-it / packages/ai/src/roles
packages/ai/src/roles
The NPC roles beyond the chasers and the sentries (GAME_DESIGN §5.4), each a small brain that writes an ordinary input like every NPC's:
- Driver: at the wheel of a car, it drives its route (places, in order, looping or once) over the roads (
steer-vehicle.ts), or follows an entity (a mission's actor) at a distance; with neither it stays parked. A driver can race (startRace): from its start it drives the race's gates in order, lap after lap, flat out, never minding a light, and parks once it has finished; a mission's chase sends it off fleeing (fleeRole), flat out to its getaway. Out of its car (carjacked), it stands. - Target: it goes about its routine (its route, looping, or its schedule's hour) on foot until it is threatened: a weapon aimed at it from near, a shot or a blast near it (as far as the weapon is heard, ROLES'
noiseRangeat most), a hit, or a guard near it on alert (its bodyguards). The tranquilizer threatens nobody: aimed, fired or in the body, a dart only makes it drowsy. Threatened, it runs to its refuge (its home when it has none) and, there, cowers in plain sight: safe (still a body to put to sleep, knock out or search); ROLES'hideSecondslater it gets up and goes back to its routine, the scare over. - VIP: it waits until a player comes up to it and follows that player (its leader) from then on, on foot a couple of metres behind, and into their car as a passenger when they drive (it walks to the passenger's side and gets in), out again when they get out (once the car is at a crawl). Its death is the simulation's (and a mission's rules decide what it fails).
- Hostage: it waits, tied up (restrained:
@foi/sim'scaptives.ts) unless its spec says otherwise, for a player to free it (the interaction key held at it) or, not tied up, to take it at gunpoint (holdup.ts); from then on it follows that player as a VIP does, on foot and in their car. Left alone (its leader farther thanleaveRangeforleaveSeconds, or down for good), it flees: it runs for its refuge and cowers there, until a player comes up to it again and it follows them. - Witness: it goes about its rounds as a target does until it witnesses something (what threatens a target, or a body lying in its sight): then it runs for its refuge (its place when it has none: a phone box, a shop's counter) and calls the police from there, its phone to its ear for
callSeconds; once through, the player it saw doing it is reported (police.ts'reportToPolice: the Heat of a crime reported) and it hides there as a target does. Held up (holdup.ts) or restrained in time, it calls nobody; let go, it runs to call again.
Their state (RoleState) sits on the NPC and is part of the AI's hash (roleHashFields). The missions read what matters (threatened, safe, arrived, its leader, riding, a race's progress) off it through the server.