five-on-it / packages/sim/src/dogs
packages/sim/src/dogs
Dogs (GAME_DESIGN §5.6): NPCs of their own. A dog is a character in a dog's body (character.ts' BODIES: a low capsule, light and quick) and a pedestrian of the role dog, run by the pedestrian system on the server, before the step: like everybody else it only writes its input, and the character system does the trotting.
- On a lead, with its walker (a
dog_walker; the link is kept both ways,Pedestrian.owneron the dog andPedestrian.peton the walker, and holds only while both agree: entity ids are recycled): it keeps within the lead's length (DOGS.lead) of its walker, at no fixed place. It ranges to a place in its walker's frame (ahead, behind, on either side:heel), drawn anew every few seconds, on the other side now and then (it goes round its walker, never through it) and off the carriageway; it stops tosniffat what it passes (another dog, a lamp post, a tree, a hydrant, a bin:@foi/world's scents, or the ground) until its time is up or the lead has been taut a moment, then trots to catch up; it sits (sit) once its walker has stood for a while. Its walker is its pair (walkerPace): it slows while the dog sniffs, waits a moment on a taut lead, and waits for a dog that is off its lead to come back. - A stray (one spawned without a walker, or whose walker is gone, dead or indoors): it walks the pavements on its own (
wander: along them, never over a crossing unless there is no other way), stops (stand), sits, sniffs, follows a person for a while (follow, a step behind, as far as the kerb), and off the pavements makes for the nearest one. - Fear, for both: gunfire or a blast within DOGS
.fright, or a hit that did not kill it, and it bolts (bolt): flat out away from it, faster than anybody runs, turning aside when it runs into something. A dog on a lead pulls free. When it has calmed down it is a stray, and if its walker is alive and near it goes back (return) and is on its lead again; too far, or too long on the way, it stays a stray. - Cars: one coming at it fast, about to pass within a step of it, and it jumps aside (
dodge: a dash across the car's way, with a hop). - Hurt: it has DOG_HEALTH hit points; shot or run over it lies dead where it fell (
Character.stays: it never comes back at a post; the crowd takes its body off the street out of sight). A car's slow hit tumbles it for DOGS.tumbleTicks, and it bolts once up. It is no person: nobody searches, wakes, talks to or knocks it out, a dart does nothing to it (interaction.ts,weapons.ts), and it holds no gate open.
It barks now and then (the bark act, acts.ts: at another dog, setting off, yelping when it bolts). The snapshot tells its state in a character's spare bytes (leadWire): what it does, whether it is on its lead and whose. Everything is drawn from the world's seeded generator at its decisions, so two worlds agree; its state is part of the world's hash.