Painted Metropolis
README.md
pursuitKit
Being noticed, being hunted, getting away, getting caught: as data-configured, engine-free logic any game can drive. Nothing in it names a game, a city, a guard or a crime. The host says where observers and the suspect are and whether the line between them is clear; the kit answers with states, timers and events, and with intents for pursuers on foot and in vehicles.
Status: every module's logic is covered by case modules that run in the engine's Luau VM in edit mode
(tests/cases/{core,response,standing}, 92 cases; see "Tests"). The kit has NOT been run against a scene: the
raycast adapter and everything a host stages (animation, vehicles, sound) are untested here.
What is in it
Module (require("pursuitKit.modules.<name>")) | What it does |
|---|---|
config | DEFAULTS, merge(base, over) (Config.NONE drops a default), validate(cfg): the whole kit's behaviour as one table |
hub | named events: on, onAny, emit |
perception | view cone in 2D or 3D (inView3, vertical), range by light, fill rate, panning (sweep) |
awareness | one 0..1 meter per observer with suspicious/alert thresholds and events |
reports | pending reports with delays, holds, relays that can be jammed |
heat | offences → points → named levels; pursuit tick; decay after a grace; escape factor |
incident | the state machine: clear, noticed, reported, pursuit, search, escaped, arrest, released; last known position; search area |
grab | the telegraphed reach on foot (reach) and the vehicle box-in (box) |
arrest | the staged arrest with hooks, break-free and skip; several sequences (arrest, detain-and-eject, hand-over); Arrest.bill(rules, facts) |
dispatch | who is sent where for a heat level: plan, sweepPoints, cordon, entry |
pursuer | one pursuer's intent by profile (cfg.pursuer[name]: speeds, leash, home, look-round on arrival); writers for the character bus and the vehicle bus |
description | what the pursuers know the suspect looks like (strength 0..1), shedding it |
firefight | pursuers who shoot back: who is armed at a level, the aim telegraph, bursts, led and spread shots. Holds no projectile |
roadblocks | blocks and bridge checkpoints on a road GRAPH the host supplies: ordered, standing, lifted; plan forecasts |
vehiclePursuit | pursuit cars that work together: shadow, chase, box, ram, block, dismount where a car cannot go |
theft | taking a vehicle: the offence by its state, the owner's delayed report, the hot list, lawful kinds |
roster | pursuers as named people: beats, shifts, bribes and leverage, arrangements found out, faces remembered |
record | strikes that fade; confiscated things in an impound with a growing fee and a sale date |
party | several suspects in one world: heat is each one's own, shared with accomplices standing close |
director | perception, awareness, reports, heat, incident, grab, arrest and description assembled behind setObserver / setSuspect / tick |
engineAdapters | lineOfSight on Physics.raycast; lightAt / lightByHour (the only module that calls the engine) |
Every module's header comment is its reference: the calls, the shapes they return, and its section of the config.
Using it
local Config = require("pursuitKit.modules.config")
local Director = require("pursuitKit.modules.director")
local Adapters = require("pursuitKit.modules.engineAdapters")
local Arrest = require("pursuitKit.modules.arrest")
local cfg = Config.merge(Config.DEFAULTS, myGameConfig) -- see the schema in modules/config
assert(Config.validate(cfg))
local dir = Director.new(cfg, {
hasLine = Adapters.lineOfSight({ pass = isGlassOrCrowd }),
light = Adapters.lightByHour(function() return clock.hour end),
bill = function(level, ctx) return Arrest.bill(myBillRules, factsFor(level)) end,
})
dir.hub:on("state", function(e) hud.setPursuit(e.to) end)
dir.hub:on("arrestStage", function(e) cast.play(e.stage); camera.cut(e.stage); hud.arrest(e) end)
-- every frame
dir:setObserver(id, { kind = "guard", x = x, y = y, z = z, fx = fx, fz = fz })
dir:setSuspect({ x = px, y = py, z = pz, act = currentAct, concealment = tags, hidden = inHide,
appearance = { jacket = jacket }, inVehicle = driving, speed = speed, charges = slips })
dir:input({ breakHeld = interactHeld, skip = confirmPressed })
local view = dir:tick(dt) -- everything a HUD draws
dir:offence("fired_arm") -- something the game saw her do
dir:report({ offence = "stolen_vehicle", x = x, z = z, delay = 8, appearance = tags }) -- a report from outside
dir:noise({ x = x, z = z, radius = 30 }) -- observers in earshot grow suspicious
Pursuers (the host owns their entities):
local Dispatch = require("pursuitKit.modules.dispatch")
local Pursuer = require("pursuitKit.modules.pursuer")
local orders = Dispatch.plan(cfg, view.level, view, units) -- units: { { id, kind, x, z, available } }
for _, u in units do
local senses = dir:senses(u.id) -- sees, sx, sz, stunned, grabbing
senses.x, senses.z, senses.order, senses.path = u.x, u.z, orders[u.id], route(u, orders[u.id])
local intent = u.brain:decide(dt, senses) -- u.brain = Pursuer.new(cfg, "foot")
if u.kind == "foot" then
u.controller.inputX, u.controller.inputZ = Pursuer.characterBus(intent, u.x, u.z)
else
u.vehicle.inputThrottle, u.vehicle.inputSteer, u.vehicle.inputBrake, u.vehicle.inputHandbrake =
Pursuer.vehicleBus(intent, u.x, u.z, u.fx, u.fz, u.forwardSpeed, cfg.frame.right)
end
end
The response beyond the chase (each is independent; use what the game needs):
local ff = Firefight.new(cfg.firefight, rng) -- rng() -> [0, 1): the kit ships no generator
for _, e in ff:tick(dt, { level = view.level, suspect = s, shooters = shooters }) do
-- "aim" (stage the telegraph), "shot" { from, at, wash, speed, gravity, ... } (fly it), "lower"
end
local rb = Roadblocks.new(cfg.roadblocks, graph) -- graph = { nodes = { [id] = { x, z } }, edges = { { id, a, b, class, bridge } } }
for _, e in rb:update(dt, { level = view.level, state = view.state, x = lkp.x, z = lkp.z, radius = r }) do end
Roadblocks.plan(cfg.roadblocks, graph, { level = view.level + 1, x = x, z = z, radius = r }) -- forecast for a map
local vp = VehiclePursuit.new(cfg.vehiclePursuit, cfg.frame.right)
local intents = vp:tick(dt, { level = view.level, target = car, units = cars }) -- shadow | chase | box | ram | block | dismount
local theft = Theft.new(cfg.theft)
local r = theft:take(vehicle, { witnessed = seen, x = x, z = z }) -- the offence now, the owner's report later
for _, landed in theft:tick(dt) do dir:report(landed) end
local roster = Roster.new(cfg.roster, people, rng) -- named pursuers: onDuty, cover, arrange, use, sawFace
local record = Record.new(cfg.record) -- strike, confiscate, impounded, fee, release, dayPassed
local party = Party.new(cfg.party) -- join, place, together, charge, reported
Interfaces the host provides
- Line of sight
hasLine(observer, suspect) -> boolean.engineAdapters.lineOfSightis one implementation. - Light
light(x, z) -> 0..1(optional). - The bill
bill(level, ctx) -> table(optional;Arrest.billbuilds one from rules). - A generator
rng() -> [0, 1)for firefight spread and roster rolls. Seed it: the kit is deterministic for a given sequence of inputs and rolls. - A road graph for road blocks, and a
path = { { x, z }, ... }per pursuer per order (roads for cars, a nav path on foot). The kit does not pathfind. - Movers: a character with
inputX,inputZ,inputJumpand a vehicle withinputThrottle,inputSteer,inputBrake,inputHandbrake, or any AI driver that accepts the intent (mode, a point, a speed). - Projectiles: whatever flies a
shotevent fromfromtowardsatand reports what it hit. - Staging: animation, camera and UI for
grabWindup,grabMissed, firefightaim, and eacharrestStage; the kit gives the moments and durations and waits for nobody.
Frame
Positions are (x, y, z) with y up; where only the ground matters (x, z). cfg.frame.right is the sign of x
on the right of someone facing +z: -1 in the Zero engine's frame (+x east, +z south), 1 in a z-north frame.
It decides flank sides and steering.
Events (on dir.hub)
| Event | Payload | When |
|---|---|---|
state | from, to, level | the incident changes state |
heat / heatLevel | value, level, name, delta, offence / from, to, name | heat changes / crosses a level |
observer | type = suspicious, alert or calm; id; kind | an observer crosses a threshold |
cheer | id | an observer whose kind answers alert with "cheer" becomes certain |
reportOpened / reportLanded | id, delay, via, relay / id, offence, x, z | a report starts its delay / arrives |
lkp | x, z | the last known position moves by more than a metre outside a pursuit |
searchStarted | x, z, radius, duration | a search begins |
escaped | level, name, heatBefore | a search ran out |
grabWindup / grabMissed | by | a pursuer starts / fails a reach |
arrested | level | a grab landed |
arrestStage | stage, control, duration, ctx | each stage of the sequence begins |
arrestBroke / arrestDone | {} / bill, level, sequence, outcome | the suspect broke free / the sequence ended |
released | {} | the incident is over after an arrest |
firefight, roadblocks, vehiclePursuit, theft and record return their events from tick / update /
dayPassed instead of emitting: the host decides which hub they go on.
Rules the config must keep
acts.wanted (what a certain observer takes the suspect to be doing), heat.offences.seen, the offence named by
arrest.breakOffence, one response entry per heat level, heat.levels[1].at == 0, a firefight.levels,
roadblocks.levels and vehiclePursuit.levels entry per heat level when those sections are used.
Config.validate checks the structural ones and names what is wrong.
Tests
The cases are modules (tests/cases/*.module, each returns function(Test)), registered by
tests/pursuitKit.testSuite for the engine's runner. The engine's runner closes and reloads the open scene, so
while a scene is being worked on run them in-process instead with caseBench (see its README): same cases, no
scene touched.