incident.module
README.md
incident
The pursuit as a state machine with named, timed, observable states.
clear ──(someone is noticing)──> noticed ──(a report lands)──> reported ──(responders arrive / timeout)──┐
^ │ └────────(a pursuer is certain)────────┐ │ v
│ └─(nobody is)─> clear v └──(a pursuer is certain)──> pursuit <──(seen)── search
│ pursuit ──(unseen for loseSight)────────────────────> search
└──────────── escaped <──(the search timer runs out)──────────────────────────────────────────────────────┘
pursuit ──(a grab completes)──> arrest ──(the arrest sequence ends)──> released ──> clear
It owns the last known position (where the pursuers believe the suspect is) and the search area (centre,
radius growing with time, time left). It does not move anyone: pursuers read it.
local Incident = require("~.modules.incident")
local inc = Incident.new(cfg, heat, hub?) -- cfg: kit config; heat: a heat.module meter
inc:tick(dt, {
awareness = 0.4, -- highest observer meter
seen = false, -- a pursuer is certain AND has eyes on the suspect now
x = 0, z = 0, -- where the suspect is
hidden = false, -- the suspect is in a hiding place
reports = { { x, z, offence } }, -- reports that landed this tick
responderAt = false, -- a responder has reached the last known position
})
inc.state inc.time (seconds in this state) inc.lkp = { x, z }
inc.search = { x, z, radius, left, duration } while searching (else nil)
inc:arrest() -- a grab completed: state "arrest" (the arrest module runs the sequence)
inc:broke() -- the suspect broke free: back to pursuit
inc:release() -- the sequence ended: "released" for one tick, then clear; heat reset by the host's rules
inc:view() -- { state, time, level, levelName, heat, lkp, search, timer = { left, duration } } for a HUD
Events on the hub: "state" { from, to, level }, "lkp" { x, z }, "searchStarted" { x, z, radius, duration },
"escaped" { level, name, heatBefore }, "arrested" { level }, "released" {}.
The interface is documented in the header of init.luau; this file repeats it for the asset browser.