Log inGet started
World

Painted Metropolis

Branchmain
Commit1e1d3a3d4d

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
configDEFAULTS, merge(base, over) (Config.NONE drops a default), validate(cfg): the whole kit's behaviour as one table
hubnamed events: on, onAny, emit
perceptionview cone in 2D or 3D (inView3, vertical), range by light, fill rate, panning (sweep)
awarenessone 0..1 meter per observer with suspicious/alert thresholds and events
reportspending reports with delays, holds, relays that can be jammed
heatoffences → points → named levels; pursuit tick; decay after a grace; escape factor
incidentthe state machine: clear, noticed, reported, pursuit, search, escaped, arrest, released; last known position; search area
grabthe telegraphed reach on foot (reach) and the vehicle box-in (box)
arrestthe staged arrest with hooks, break-free and skip; several sequences (arrest, detain-and-eject, hand-over); Arrest.bill(rules, facts)
dispatchwho is sent where for a heat level: plan, sweepPoints, cordon, entry
pursuerone pursuer's intent by profile (cfg.pursuer[name]: speeds, leash, home, look-round on arrival); writers for the character bus and the vehicle bus
descriptionwhat the pursuers know the suspect looks like (strength 0..1), shedding it
firefightpursuers who shoot back: who is armed at a level, the aim telegraph, bursts, led and spread shots. Holds no projectile
roadblocksblocks and bridge checkpoints on a road GRAPH the host supplies: ordered, standing, lifted; plan forecasts
vehiclePursuitpursuit cars that work together: shadow, chase, box, ram, block, dismount where a car cannot go
thefttaking a vehicle: the offence by its state, the owner's delayed report, the hot list, lawful kinds
rosterpursuers as named people: beats, shifts, bribes and leverage, arrangements found out, faces remembered
recordstrikes that fade; confiscated things in an impound with a growing fee and a sale date
partyseveral suspects in one world: heat is each one's own, shared with accomplices standing close
directorperception, awareness, reports, heat, incident, grab, arrest and description assembled behind setObserver / setSuspect / tick
engineAdapterslineOfSight 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.lineOfSight is one implementation.
  • Light light(x, z) -> 0..1 (optional).
  • The bill bill(level, ctx) -> table (optional; Arrest.bill builds 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, inputJump and a vehicle with inputThrottle, inputSteer, inputBrake, inputHandbrake, or any AI driver that accepts the intent (mode, a point, a speed).
  • Projectiles: whatever flies a shot event from from towards at and reports what it hit.
  • Staging: animation, camera and UI for grabWindup, grabMissed, firefight aim, and each arrestStage; 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)

EventPayloadWhen
statefrom, to, levelthe incident changes state
heat / heatLevelvalue, level, name, delta, offence / from, to, nameheat changes / crosses a level
observertype = suspicious, alert or calm; id; kindan observer crosses a threshold
cheeridan observer whose kind answers alert with "cheer" becomes certain
reportOpened / reportLandedid, delay, via, relay / id, offence, x, za report starts its delay / arrives
lkpx, zthe last known position moves by more than a metre outside a pursuit
searchStartedx, z, radius, durationa search begins
escapedlevel, name, heatBeforea search ran out
grabWindup / grabMissedbya pursuer starts / fails a reach
arrestedlevela grab landed
arrestStagestage, control, duration, ctxeach stage of the sequence begins
arrestBroke / arrestDone{} / bill, level, sequence, outcomethe 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.