five-on-it / packages/ai/src/schedule
packages/ai/src/schedule
Schedules (GAME_DESIGN §5.4): an NPC's day by the room clock (@foi/shared's clock.ts). A schedule is hours, each from a time of day: go to a place and stay (goto), keep a post there (post), walk a patrol through its points (patrol), go home (home): walk to a door and vanish indoors (the simulation's setIndoors), to come back out of that door when the next hour starts, or take a break (break): walk to a place and stand there off guard, its phone out (a sentry sees less far and less wide, sentry.ts).
A plain hour lasts until the next plain hour begins: a shift. The one in force is the last begun (yesterday's last before today's first), so an NPC spawned at any time does what it should then. A timed hour (for so many minutes) interrupts the plain one and hands it back when it is over, or when the next plain hour begins (a shift ends on time, whoever is on a break): a break, a round of the yard; it may recur (every so many minutes from its time, until the next plain hour begins), so "a ten minute break every hour at twenty to, on the night shift" is one hour of the schedule. Between timed hours, a schedule of nothing but timed ones gives the NPC its own rounds back (a sentry's spawner's post or patrol).
followSchedule runs before an NPC's brain every tick: it notices a new hour and hands it to the brain (a sentry's rounds are rewritten, a role NPC's routine follows routineOf), walks a home-goer in at its door, and says whether the NPC is indoors (its brain then has nothing to do). Deterministic: the clock is a function of the tick; the state is hashed with the NPC's (scheduleHashFields).