five-on-it / packages/ai/src/police
packages/ai/src/police
The police (GAME_DESIGN §12): the system that turns the players' crimes into stars and the stars into police: the orchestrator of the police's modules. It runs on the server every tick before the NPCs decide (aiSystem), reading the simulation's events of the last step, and acts through the AI's ordinary means: the officers are chasers of the police profile (profiles.ts) in police cars, the drones flyers flown on their input, and nothing here moves a body. What each star brings is a row of the ladder (police-ladder.ts).
- Crimes raise the Heat of the player who did them (
wanted.ts); so does speeding past an officer, who notices it all around within its sight's reach; a respray in a garage clears it unless the police saw the car go in. Stars six to ten come from escalations only, said on the radio. - Sight. A player with stars is seen when one of the police's eyes has them: an officer of a unit after them, one on a beat, one at a roadblock (cover hides from all of them), the drone overhead (
police-drones.ts), a security or traffic camera from five stars (police-cameras.ts). Every sighting goes through one function, radioSighting: the radio net (every officer after that player hears where they are), and the clocks of cooling down and of losing the police start again. - Units. A wanted player is sent the cruisers their stars ask for, one at a time, the most wanted player first: out of the player's sight on the roads around them, or, from four stars (PreCrime™,
police-precrime.ts), ahead of them on the road they are predicted to take; at four stars and up a dispatch may send a rolling block of two or three (police-roadblocks.ts). The officers' profile follows the stars: they tail and box in at one star, ram from two, get out and shoot at three, when their cars have the pursuit tune. Every officer carries a pistol and its rounds. An officer that loses the player searches where they were last seen. As the stars drop, the units no longer needed (the newest first) give up: blind to the player, they drive off and are gone after a while, or once far from every player. - The room's cap. Every officer, police car and drone counts against POLICE_RESPONSE
.maxActors(the 60 fps target and the AI's planning budget); the drones, the roadblocks and the cruisers share it, the most wanted player first. - Nail strips at three stars (
nail-strips.ts), roadblocks and the green wave (police-signals.ts) and the police bikes at four, the drone and the cameras at five; the heavy response at seven (police-heavy.ts: the APC, the water cannon, the helicopter and its searchlight, the rooftop snipers, the police boats on the water, the cruisers' Grappler and GPS dart, a tagged car followed from afar). - Arrests. A player on foot who stands still near an officer on their floor that sees them, at one star, is arrested; so is one the police knock down (a shot, a car) at any star. The player is put back at the nearest spawn, the stars are cleared and a fine is charged, which the server reports (takeArrests).
Deterministic: everything goes in entity and client order (or the players by stars, then client id) and the book is hashed with the NPCs (hashAiState).