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, the cameras and the citizen app (police-citizens.ts) at five; at six the SWAT van and its team (police-swat.ts), a K9 unit on the player's trail (police-k9.ts) and the negotiator for a player holding a captive (police-negotiator.ts); 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); the tech division at eight (police-tech-division.ts: the kill switch, the swarm, the ComplianceBots™, the robot dog). A district with a force of its own sends it in the place of cruisers (M15). - Non-lethal pays (M7): until the player has used lethal force on the police (shot at, shot or killed an officer, shot a police car:
wanted.ts'lethalForce), the officers stick to the taser, the foam gun (six stars), tear gas and flashbangs; from then they answer in kind. Taking an officer down without killing them costs half a kill's Heat. - Two kinds of Heat (
police-heat.ts, M1): the car a wanted player is seen in takes their stars; the police hunt the car they see and the face they know. - The robbers' tech (
police-tech.ts): the gadgets and the phone's hacks the police answer, a jammer's reach cutting the radio among them (and a GPS tag's signal). - 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) below six stars; from six, one lying down or stunned (a taser, a flashbang, the sonic cannon, a dog's bite) with an officer at their side for a second and a half. 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).