five-on-it / packages/ai/src/chaser
packages/ai/src/chaser
The chaser: what an NPC on foot does with what it perceives. A small state machine: idle until something is seen or heard; alert for the profile's reaction time, facing it; chase while the target is in sight or fresh in memory (the heading leads a moving target, several chasers fan out by their flank offset; with the target in its line of sight it keeps the approach distance and pulls the trigger in bursts within range, and a profile that tracks its target through walls still closes in until it sees it); search where it was last seen or heard, looking around for a while; then back home, or standing where it gave up. Being shot reveals the shooter. A target it brought down is watched from the approach distance, never shot at, until it is up again or out of sight. A knocked-down chaser is deaf to its input; a dead one comes back at its home or is removed, as its profile says.
At the wheel the same modes drive (steer-vehicle.ts): the chase keeps the approach distance as a gap behind the target, or rams it when the profile says so, or, for a profile that boxes in (the police), takes a side of the target's car once it has stopped (ahead, behind, left, right: one per such driver after it), the crew shooting the pistol out of the windows when it does; the search and the return park at their spot. A driver whose car is wrecked, or stalled for good, or parked where the car can go no nearer a target on foot, or whose target is on foot and near, gets out when its profile lets it, and one that dismounts gets out as soon as it has pulled up near its target; the passengers follow their driver out and fight on foot. Getting out is the simulation's, by the car's speed (exitMode): the crew of a wreck press to leave it at once, staying in while it is too fast and bailing out rolling below the bail-out limit; any other crew waits for the car to be at a crawl and steps out at its doors. A car on fire (@foi/sim's fire.ts) is left by its whole crew, whatever the profile, as a wreck is, and never taken again. Killed in its seat by a wreck's crash, a chaser does nothing more. A chaser on foot whose target drives off takes a free car nearby when its profile lets it (it goes to the door and gets in, boarding.ts).
Carjacked (pulled out at the wheel, or put out as a passenger: aiSystem notices), a chaser flees (GAME_DESIGN §5.4): it runs from the carjacker for the profile's fleeSeconds, counted from when it is on its feet, around what its rays find, never shooting; then it goes after the carjacker, as a chase (an armed crew fights back).