Log inGet started
World

Painted Metropolis

Branchmain
Commit1e1d3a3d4d

README.md

roadblocks

Closing the roads out: which arterial roads and bridges are blocked, and when.

It works on a road graph the host supplies (from whatever made the city) and never on straight distances:
a block stands on an EDGE of the graph, where a road of a class worth blocking crosses the ring round the
search area, and a checkpoint stands at the far end of every bridge whose near end is inside reach. Blocks
take time to stand and linger after the incident, so the map can show them coming and a driver can beat them.

  local Roadblocks = require("~.modules.roadblocks")
  -- graph = { nodes = { [id] = { x, z } }, edges = { { id, a, b, class, bridge = false, name = nil } } }
  local rb = Roadblocks.new(cfg.roadblocks, graph)
  local events = rb:update(dt, {
      level = 3,                       -- 0-based heat level
      state = "search",                -- the incident's state (blocks are ordered in "pursuit" and "search")
      x = 0, z = 0, radius = 90,       -- the area to close (the search area, or the last known position)
      heading = { x = 1, z = 0 }?,     -- where the suspect is going (roads ahead are closed first)
  })
  -- { type = "ordered", block }  { type = "standing", block }  { type = "lifted", block }
  -- block = { id, edge, kind = "block" | "checkpoint", x, z, fx, fz (along the road, pointing out of the area),
  --           class, name, state = "setting" | "standing", left (seconds until it stands), units }
  rb:list()                          -- every block, id order (for a map)
  rb:blocked(edgeId)                 -- true while a block STANDS on that edge (for routing)
  rb:near(x, z, radius)              -- standing blocks within radius, nearest first
  rb:clear()                         -- lift everything at once
  Roadblocks.plan(cfg, graph, { level, x, z, radius, heading? })   -- the blocks an area would get, without state
  -- (use it to FORECAST: a planner can show which roads will close if the heat reaches a level here)

Config (cfg.roadblocks):
  classes[class] = weight          how much a class of road is worth blocking (0 or missing: never)
  levels[level + 1] = { blocks, bridges = bool, units }     how many blocks, whether bridges are checked, units each
  ring = factor                    the ring's radius as a multiple of the area's radius (blocks stand outside it)
  minRadius                        metres: the ring is never tighter than this
  bridgeReach                      metres from the area's centre within which a bridge's near end is checked
  minGap                           metres two blocks keep between them
  setup, linger                    seconds a block takes to stand; seconds it stays after the incident ends
  replan                           metres the area must move before the blocks are planned again
  keep                             metres: on a replan a block already ordered stays while it is within this of
                                   the area (a chase does not dissolve the blocks it is driving towards)

The interface is documented in the header of init.luau; this file repeats it for the asset browser.