five-on-it / apps/server/src/mission-host
apps/server/src/mission-host
The game's missions on the server: the bridge between the simulation and the mission interpreter (@foi/missions). Every MISSION_EVERY_TICKS ticks it gathers the facts (where each player is, how healthy and how wanted, what they carry, where each mission vehicle is, how healthy, who sits at its wheel, whether it is locked and whether it was carjacked, picked, resprayed or stored since (from the simulation's events it is shown every tick), the missions' garages and who and which of their vehicles stand in their bays, where each member of a mission's groups of enemies is, how healthy, whether it chases or is down for good, the missions' items on the ground and who picked them up, their containers and what they hold, their doors open or locked, and what the players did with items since the last step, from the item events), steps the interpreter, carries out its commands and sends each player their tracker when it changed and their notices as text frames.
The commands: a mission vehicle spawned at its place, on the ground there unless the place says how high, or beside or behind it when another vehicle stands there, as when two players play the same mission, whose (the mission's, nobody's, an NPC's), locked or not, its key's tag; a mission vehicle locked or unlocked, despawned, or let go as an ordinary car while somebody sits in it (one stored in a garage is the player's to keep); the level's garage nearest a place bound to a garage actor; some of a group of enemies spawned at a place as chasers of the AI (@foi/ai, after the mission's player, with the group's profile, never coming back once dead, unarmed when the group is), spread around the place, within MAX_ROOM_ENEMIES standing in the room; a group despawned, every member gone; a player's Wanted level set (the police's, @foi/ai); items laid on the ground at a place (an item actor's, or a rule's); a container put at a place with its items; the level's door nearest a place bound to a door actor, locked as it says, and locked or unlocked by the rules; items given to a player (what does not fit laid at their feet) or taken from them; an item actor's items despawned while they still lie there, a container with what it holds, a door let go (as it stands); an NPC actor of the guard or the civilian role put in the level as a sentry of the AI (@foi/ai's stealth: its patrol or post, its weapon, its pockets filled), the level's camera nearest a place bound to a camera actor and switched off and on, the alarm raised or called off; where a player comes back after going down (the start of their mission, under the game's respawn: mission). The facts add each NPC actor's phase and status, each camera actor's state and spots, the compound's alert and each player's kills, alarms and sightings. The AI alone moves them. The facts are cheap: nothing about the world beyond the players and the actors the missions spawned.
The phone (@foi/missions' phone.ts): a person (an NPC actor of the contact role) put at a place (a character of the contact role, standing on a free spot by it) and a terminal at a place (a box of the simulation's) are mission actors like the others; a door bound with a code is locked by a keypad, and the keypad's right code unlocks it and swings it open away from the player. The interaction key at a contact, a terminal or a keypad (the simulation's interact events) and the players' phone commands (text frames, checked by the interpreter like any input) reach the next mission step as facts; each player is sent their phone when it changed, as a text frame to them alone.
The city (GAME_DESIGN §5.3–§5.7, §14): a driver, a target or a VIP actor is the AI's role NPC (@foi/ai's spawnRole: a driver at the wheel of a car of its class on its route or after an actor, a target on its rounds with its refuge, a VIP), a guard, a civilian or a target may follow a schedule; a race's rivals are sent off on its gates; a shop actor is the simulation's shop at a place, at the actor's prices (else the game's, else the items'); the clock is set and run at a pace on the simulation's clock; a junction's signal is switched by hand (switchSignal); a reward is paid into the player's Cash, and a mission's give and take of cash go in and out of it. The facts add the room clock, each player's Cash (as a stack of cash they carry, for the conditions that count it), each NPC actor's health and whether it is indoors, and the roles' state. A group of enemies comes out of the room's guards' spawn points near its place when there are any.
The verbs past v1 (GAME_DESIGN §20): a prop actor binds the level's light piece nearest its place (the facts say whether it was knocked loose); a give to a person hands the player's items over into the person's pockets (handOver, reported as a handed item event with what changed hands); a chase sends its target off (flee: the AI's fleeRole); a photo taken with the phone's camera is framed here, along the character's aim through the physics world (@foi/ai's inFrame), and the facts list the mission actors and the game's places in it. The facts add each NPC actor's and enemy's speed and whether it has a player in sight, and the players the police arrested since the last step.
A run's room (run-host.ts) runs its one mission for its seats: the runtime holds it for every seat as the stand-in holder 0 (its actors' keys start 0:, and its checkpoint is kept under them), a player who comes back takes their seat under their new client id (rebind, the checkpoint's record of them renamed with it), the mission's enemies go after the nearest live seat (whoever stands nearest each of them, every step), and the facts add the hits players landed on the mission's enemies (the simulation's hit events, by whose shot), which credit their seats. A run of teams adds what a catch and the scores need: each player's speed (their car's while seated), whether they are seated, their car's health and their status, and who put them down (the hit that left them dead); its groups with a targets team go after the nearest member of that team alone; a player caught is sent back alive (respawn), one out of the run is taken out of the world to watch (spectate: their body set indoors, out of the snapshots, until a co-op attempt starts again).