five-on-it / packages/ai/src/sentry
packages/ai/src/sentry
The sentry: an NPC of stealth (GAME_DESIGN §5.4, §8), a guard or a civilian placed by an NPC spawner (a level's, or a mission's npc actor), who walks a patrol path (looping or back and forth) or keeps a post (looking either way of its heading), and whose awareness (awareness.ts) runs a machine of alert phases:
- normal: on its patrol or at its post. Seeing a player fills its suspicion (faster near, slower far, slowly for one crouched behind low cover); any suspicion makes it suspicious ("?"), and so does a sound it hears.
- suspicious: it turns to the stimulus, then walks to it and looks around; with nothing more for a few seconds it goes back to its rounds. Full suspicion is the alarm.
- alert ("!"): it calls the guards near it (they come, alert, told where the player is), chases the player and shoots (a guard; a civilian runs away instead); out of sight for a while it searches.
- search: it sweeps the area where the player was last seen, a few points around it, looking at each; seen again, the alarm is quick. Time up, it goes on caution.
- caution: its rounds again, faster, its suspicion quicker, for a while; then normal.
On a break of its schedule (schedule.ts) and calm, a sentry is off guard, its phone out from the moment its break begins (on its way to the break's place and there): it sees less than half as far and a narrower cone, and hears as well as ever; anything that makes it suspicious puts the phone away. The phone in its hand is what the clients see of it (the snapshot's act), so the cone they draw is the one it has.
A guard who sees a body (an NPC asleep, knocked out or dead that nobody has reported) raises the alarm, calls the guards near it, stares a moment and walks to the body: it shakes one that sleeps or is knocked out awake (the interaction key), then searches around it. A sentry that was put down comes to searching where it lies. Like every NPC it writes an ordinary input; its phases and memory are part of the AI's hash.