game/rules.module — Smog's ONE shared module: constants, round state, and the
event bus every slice talks through.
OWNED BY THE LEAD. Slices read the constants, call the functions and listen
to the events; none of them edits this file. Need a constant or an event
that is not here? Report it back to the lead rather than adding it.
local Rules = require("game.rules")
local off = Rules.on("evidence", function(i) ... end) -- off() unsubscribes
Rules.damage(12, "choked")
Everything here runs in PLAY. Scene builders never run in play, so nothing
a builder does reaches this module's state; components and the scene
entrypoint do. The scene entrypoint calls Rules.reset() on load and
Rules.tick(dt) every frame — no slice calls either.
on(event: string, fn: (...any) → void
| arg | type | description |
|---|
| event | string | |
| fn | (...any | |
emit(event: string, ...: any) → void
| arg | type | description |
|---|
| event | string | |
| ... | any | |
setPhase(p: string) → void
| arg | type | description |
|---|
| p | string | |
reset( ) → void
A fresh round at the title (scene load, or New Game from a screen).
startGame( ) → void
The title screen's "Begin Investigation" (and "New Game" after a win/loss).
retry( ) → void
The defeat screen's Retry: health and oil refilled, evidence and valves
kept, Crane put back at R.checkpointPos() by the player slice.
checkpointPos( ) → void
Where a retry puts Crane: beside the last evidence found, else the spawn.
damage(amount: number, source: string?) → void
| arg | type | description |
|---|
| amount | number | |
| source | string? | |
heal(amount: number) → void
| arg | type | description |
|---|
| amount | number | |
setLantern(lit: boolean) → void
| arg | type | description |
|---|
| lit | boolean | |
addOil(amount: number) → void
| arg | type | description |
|---|
| amount | number | |
spendOil(amount: number) → boolean
Spend oil for a flare; false (and nothing spent) when there is not enough.
| arg | type | description |
|---|
| amount | number | |
hasEvidence(i: number) → boolean
| arg | type | description |
|---|
| i | number | |
evidenceCount( ) → number
collectEvidence(i: number) → boolean
Take evidence i. Only the next one in the trail can be taken. Opens the
examine overlay (phase "examine"); the UI calls R.closeExamine() to resume.
| arg | type | description |
|---|
| i | number | |
closeValve(i: number) → boolean
| arg | type | description |
|---|
| i | number | |
setPrompt(owner: string, text: string?) → void
One interact prompt on screen at a time. Only the owner (any string) that
set it clears it: setPrompt(owner, nil).
| arg | type | description |
|---|
| owner | string | |
| text | string? | |
addSafeLight(id: string, x: number, z: number, r: number, seconds: number?) → void
| arg | type | description |
|---|
| id | string | |
| x | number | |
| z | number | |
| r | number | |
| seconds | number? | |
removeSafeLight(id: string) → void
| arg | type | description |
|---|
| id | string | |
addSmogCloud(id: string, x: number, z: number, r: number, seconds: number, smog: number?) → void
| arg | type | description |
|---|
| id | string | |
| x | number | |
| z | number | |
| r | number | |
| seconds | number | |
| smog | number? | |
removeSmogCloud(id: string) → void
| arg | type | description |
|---|
| id | string | |
clearSmogNear(x: number, z: number, r: number) → void
A flare burns back every cloud it touches and holds the smog off its patch.
| arg | type | description |
|---|
| x | number | |
| z | number | |
| r | number | |
within(x: number, z: number, cx: number, cz: number, r: number) → boolean
| arg | type | description |
|---|
| x | number | |
| z | number | |
| cx | number | |
| cz | number | |
| r | number | |
smogAt(x: number, z: number) → number
How thick the smog is at a point: street smog (none under a lamp, in a
flare's patch, or once the Engine is down) plus any censer clouds.
| arg | type | description |
|---|
| x | number | |
| z | number | |
smogDrainAt(x: number, z: number, lanternLit: boolean) → number
Health lost per second to the smog at a point, given the lantern state.
| arg | type | description |
|---|
| x | number | |
| z | number | |
| lanternLit | boolean | |
registerPlayer(e: any) → void
tick(dt: number) → void
Called once per frame by the scene entrypoint: expires clouds and flare
patches, runs the overload countdown, lifts the smog after victory.
| arg | type | description |
|---|
| dt | number | |