five-on-it / packages/sim/src/zones
packages/sim/src/zones
Areas that act over time (the ten-star Wanted's gear): a cloud of tear gas, a cloud of smoke, a patch of sticky foam, a ground fire. Each is an entity with a centre (its pose, on the ground), a kind, a reach, the ticks it has lived and lives in all, and whoever made it (a player's client id, 0 for an NPC or the police). A zone grows to its full reach over its first second (GROW_TICKS) and shrinks away over its last (FADE_TICKS); rain (sim.sky.rain, at least RAIN_THINS) wears gas, smoke and fire out twice as fast; water (a cannon's jet, douseAt) puts a fire out and thins a cloud.
What each does, once a tick to whoever stands in it (zoneSystem):
- gas stings: ZONES
.gas.perSecondhit points a second (never the last: tear gas takes down, it does not kill), and the breather is gassed while in it and GASSED_TICKS after (gear.ts: coughing, which the AI hears, its aim swaying, its player's screen blurred); a gas mask or the juggernaut suit keeps it all out. - smoke hides: no line of sight passes through it, either way (sightBlocked:
@foi/ai's eyes and the security cameras ask it). - foam glues: a person in it moves at ZONES
.foam.paceof their pace, a car's tyres stick (vehicle.ts: little drive, little grip). - fire burns: ZONES
.fire.perSeconda second to a person in it, and a car standing in it takes the heat as hits (fire.tsthen lights it as a blast's hit would).
The server makes zones (ordnance.ts: what a thrown canister, a bottle does) and the snapshots carry them; every client's world has a twin of each, a proxy kept at the snapshot's reach (setZone), so its prediction slows the player and the player's car in foam as the server does. The harm (the gas, the burns) is the server's alone: a twin only slows. Deterministic: zones in ascending id order, people and cars in theirs, everything in ticks, and the state hashed.