five-on-it / packages/sim/src/pedestrians
packages/sim/src/pedestrians
Pedestrians: characters nobody plays. The server runs this system before each step (the clients never do: their twins of the pedestrians coast and take the server's poses from the snapshots), drawing its decisions from the world's seeded generator.
- On the pavements (GAME_DESIGN §5.4, roles, patrol and schedule): a pedestrian put on a node of the level's pavements (
@foi/world'spavementsOf, laid beside every paved road) walks them in its role, at its own pace. Acivilianwanders, a random way at each node and now and then a rest; acommuterwalks between two places by the shortest way and waits at the kerb before each crossing near a junction (and a moment at each end), or, on its way to work or home (the crowd's schedule by the hour), walks to its goal once and goesinsidethere; ajoggerruns a loop of three corners; ashopkeeperstands at a building's door, steps out along the pavement now and then and goes back to it, and goes inside at closing time (sendInside). - The city's routines: a
dog_walkerstrolls as a civilian does, stopping often, its dog on a lead beside it (a pedestrian of the roledog, an NPC of its own:dogs.tsruns it from here, and the walker slows and waits for it); astreet_sweepersweeps along slowly, rarely stopping (its cart is the client's); afoot_officerwalks a beat, a loop as a jogger's at a walk, waiting at the crossings (an officer: the police's eyes,@foi/ai'spolice.ts); asmokerstands beside a door for a cigarette and goes back in at it; avendorstands beside its kiosk's or stall's counter (@foi/world's spots of kindvend); aqueuerwaits in line at a bus stop facing the road and boards a bus that stands there (walks to its door and isinside); asitterwalks to a free bench, sits on it (sitting.ts, the seat its own as a player's) for a while, then gets up and strolls on. - Off them (a level without roads, the avenues of the test city): it picks a direction (or a rest) every so often, turns away when it walks into something and heads back when it strays out of the zone around the centre. A range dummy is a pedestrian that never roams: it stands at its post (on the ground, a pedestal or a tower) to be shot at, and respawns there.
- Gunfire scares everyone (GAME_DESIGN §5.4, Flee): a pedestrian within FLEE_RADIUS of a shot's muzzle, of where it ends or of a blast runs away from it for three seconds, turning aside when it runs into something, then goes back to the nearest pavement (a shopkeeper to its door). A shopkeeper instead ducks inside: it runs to its door and is
insidethere, which the crowd (@foi/ai) takes off the street; its door is staffed again later.
Cars hurt people on foot (character.ts): a knocked-down pedestrian forgets its plans and, up again, makes for the nearest pavement. Who walks where (how many, spawned near the players and gone far from them) is the crowd's business; this system only writes each pedestrian's input, and the character system does the walking.