Skip to content

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 cars. 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, and nothing here moves a body.

  • 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.
  • Sight. A player with stars is seen when an officer has them in its line of sight (cover hides). Then every officer after that player hears where they are on the radio, and the clocks of cooling down and of losing the police start again.
  • Units. A wanted player is sent one police car at one star, two at two, four at three (a crew of two from three stars), one at a time, out of the player's sight on the roads around them, toward where the police think the player is. 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 (@foi/sim's PURSUIT_TUNE: an interceptor's engine). Every officer carries a pistol and its rounds in its pockets. An officer that loses the player searches where they were last seen, and goes there again after giving up while the player is still wanted. 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.
  • Nail strips at three stars, laid on the road ahead of a player who drives (nail-strips.ts) and picked up once they have passed.
  • Arrests. A player on foot who stands still near an officer 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 and the book is hashed with the NPCs (hashAiState).

Variables ​

Functions ​