Painted Metropolis
README.md
vehiclePursuit
Pursuit cars that work together: who shadows, who boxes, who rams, who blocks.
Each tick it gives every pursuing car a TACTIC and a point to drive at, as an intent the vehicle AI executes
(the same intent shape modules/pursuer makes, so `Pursuer.vehicleBus` or `VehiclePursuit.drive` turns it into
throttle, steer and brake). The tactics a heat level allows are data; the roles are dealt out so cars do not all
go for the same bumper: the nearest sits on the tail, the next two take the flanks, another gets ahead to block.
local VehiclePursuit = require("~.modules.vehiclePursuit")
local vp = VehiclePursuit.new(cfg.vehiclePursuit, cfg.frame.right)
-- (frame.right: the sign of x on the right of someone facing +z; -1 in the engine's frame, see modules/config)
local intents = vp:tick(dt, {
level = 3,
target = { x, z, fx, fz, speed, onFoot = false, roadClass = "avenue" }, -- the suspect's vehicle (or the suspect on foot)
units = { { id, x, z, fx, fz, speed, sees = true, stunned = false, roadClass = "avenue", path = nil } },
})
-- intents[id] = { mode = "shadow" | "chase" | "box" | "ram" | "block" | "dismount" | "search" | "stunned",
-- slot = "rear" | "left" | "right" | "front" | nil, x, z, speed, hold, ram = bool }
-- dismount: the suspect went where a car cannot follow (cfg.impassable[roadClass]); the host puts the crew
-- on foot. ram: the host treats contact as deliberate (damage, and the pursuers' own rule for force).
vp:role(id) -- the slot a unit holds now
local throttle, steer, brake, handbrake = vp:drive(intents[id], unit) -- the vehicle bus
VehiclePursuit.topSpeed(cfg, roadClass) -- what a pursuit car may do on a class of road
Config (cfg.vehiclePursuit):
levels[level + 1] = { tactics = { "shadow" | "chase" | "box" | "ram" | "block" }, cars } what is allowed
speeds[roadClass] = m/s top speed by class of road (default = speeds.default)
impassable[roadClass] = true classes a car cannot enter (stairs, alleys): the crew dismounts
shadow = { distance } metres kept behind when only shadowing
box = { beside, ahead, behind } metres: flank offset, how far ahead the blocker gets, how close the tail sits
ram = { minSpeed, closing, cooldown } only rams a target going at least minSpeed; closes at +closing m/s;
a unit that has just rammed waits `cooldown` seconds
lost = seconds a unit that has not seen the target for this long searches instead
The interface is documented in the header of init.luau; this file repeats it for the asset browser.