feat(packages): ludic.jobs - written jobs gated by standing and story, boards of posts rolled by the day on their own dice, progress counted from events and read back from state, handing in, rewards through a port, facts, a save section per scope

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 07:35:45 +03:00
parent e146c7a337
commit 411206e45a
14 changed files with 984 additions and 0 deletions

View file

@ -0,0 +1,93 @@
# state.ludic - each job's state and count, the posts on the boards, the done counts, the dice and
# the facts. Made on first use, so the registries are complete by then.
var jobs__st: []int = null
var jobs__hv: []int = null
var jobs__seen: []bool = null # an offer already said
var jobs__primed: bool = false # the first tick after a reset learns the offers quietly
var jobs__done_n: []int = null # handed in, per group
# the posts, every board's slots end to end from jobs__off[b]
var jobs__off: []int = null
var jobs__pk: []int = null # kind, -1 empty
var jobs__pp: []int = null
var jobs__pn: []int = null
var jobs__ph: []int = null
var jobs__pb: []int = null # the evidence when it went up
var jobs__pm: []int = null
var jobs__pr: []int = null
var jobs__ps: []int = null
var jobs__pd: []int = null # the day it went up
var jobs__total: []int = null # handed in, per board
var jobs__serial: []int = null # posts made, per board: each roll its own seed
var jobs__seed: int = 1000
var jobs__dice: Rng = null
var jobs__q: Queue<JobsFact> = null
function jobs__ints(n: int, v: int) -> []int {
let out = new []int
for i in 0 .. n { push(out, v) }
return out
}
function jobs__ensure() -> void {
if jobs__st != null { return }
jobs__st = jobs__ints(JOB_COUNT, JOBS_OFFERED)
jobs__hv = jobs__ints(JOB_COUNT, 0)
jobs__seen = new []bool
for i in 0 .. JOB_COUNT { push(jobs__seen, false) }
jobs__done_n = jobs__ints(JOBS_GROUPS, 0)
jobs__off = new []int
var n = 0
for b in 0 .. BOARD_COUNT {
push(jobs__off, n)
n += JobBoards[b].slots
}
jobs__pk = jobs__ints(n, -1)
jobs__pp = jobs__ints(n, -1)
jobs__pn = jobs__ints(n, 0)
jobs__ph = jobs__ints(n, 0)
jobs__pb = jobs__ints(n, 0)
jobs__pm = jobs__ints(n, 0)
jobs__pr = jobs__ints(n, 0)
jobs__ps = jobs__ints(n, JOBS_OFFERED)
jobs__pd = jobs__ints(n, 0)
jobs__total = jobs__ints(BOARD_COUNT, 0)
jobs__serial = jobs__ints(BOARD_COUNT, 0)
jobs__dice = rng_new(jobs__seed)
}
export function jobs_facts() -> Queue<JobsFact> {
if jobs__q == null { jobs__q = queue_new("jobs.facts") }
return jobs__q
}
function jobs__fact(what: int, job: int, b: int, s: int, have: int, need: int) -> void {
let f = new JobsFact
f.what = what
f.job = job
f.board = b
f.slot = s
f.have = have
f.need = need
if job >= 0 {
f.kind = Jobs[job].kind
f.param = Jobs[job].param
f.money = Jobs[job].money
f.rep = Jobs[job].rep
f.scope = Jobs[job].scope
} else {
f.kind = jobs__pk[jobs__off[b] + s]
f.param = jobs__pp[jobs__off[b] + s]
f.money = jobs__pm[jobs__off[b] + s]
f.rep = jobs__pr[jobs__off[b] + s]
f.scope = JobBoards[b].scope
}
q_push(jobs_facts(), f)
}
# the base of every roll: a post's seed is this, the day, the board, the slot and how many before
export function jobs_config_seed(seed: int) -> void {
jobs__seed = seed
jobs__dice = rng_new(seed)
}