Skip to content

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's pavementsOf, laid beside every paved road) walks them in its role, at its own pace. A civilian wanders, a random way at each node and now and then a rest; a commuter walks 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 goes inside there; a jogger runs a loop of three corners; a shopkeeper stands 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_walker strolls as a civilian does, stopping often, its dog on a lead beside it (a pedestrian of the role dog, an NPC of its own: dogs.ts runs it from here, and the walker slows and waits for it); a street_sweeper sweeps along slowly, rarely stopping (its cart is the client's); a foot_officer walks a beat, a loop as a jogger's at a walk, waiting at the crossings (an officer: the police's eyes, @foi/ai's police.ts); a smoker stands beside a door for a cigarette and goes back in at it; a vendor stands beside its kiosk's or stall's counter (@foi/world's spots of kind vend); a queuer waits in line at a bus stop facing the road and boards a bus that stands there (walks to its door and is inside); a sitter walks 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 inside there, 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.

Interfaces ​

Type Aliases ​

Variables ​

Functions ​