five-on-it / packages/ai/src/system
packages/ai/src/system
The AI world: everything the NPC brains keep beside the simulation. Built once per server from the simulation and the level's road graph: the navigation grids (a person's and a car's), the search graphs over them and over the roads, the A* scratch, the random stream, the planning budget, the police's book (wanted.ts, which police.ts keeps), and the NPCs themselves, kept sorted by entity id. aiSystem runs them in that order every tick, before the simulation steps, and each writes an ordinary input; nothing else touches the world. Before that it reads the carjacks of the last step: an NPC that sat in a car that was carjacked and is now on foot flees its carjacker (chaser.ts); one at the wheel of a car with a siren runs it. The sentries of stealth (sentry.ts) are NPCs too, with a brain of their own, and the room's book of stealth (stealth.ts: the cameras, the bodies, the alert, each player's counts) is kept around them. The role NPCs (roles.ts: drivers, targets, VIPs, racers) are NPCs too, and an NPC with a schedule (schedule.ts) follows its hours before its brain runs (indoors, it does nothing). The restricted zones (restricted.ts) are watched first. After them the ambient traffic drives (traffic.ts) and the crowd of pedestrians is kept around the players (crowd.ts). Deterministic: two worlds fed the same inputs run the same NPCs and the same traffic, which hashAiState can check.