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).
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.