ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v), q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)). ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no longer uses, nor anything it calls, and the argument that fills it - including an argument for a parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
3.2 KiB
Text
95 lines
3.2 KiB
Text
# 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.
|
|
export state JobsState {
|
|
jobs__st: []int = null
|
|
jobs__hv: []int = null
|
|
jobs__seen: []bool = null # an offer already said
|
|
jobs__primed: bool = false # the first tick after a reset learns the offers quietly
|
|
jobs__done_n: []int = null # handed in, per group
|
|
jobs__off: []int = null
|
|
jobs__pk: []int = null # kind, -1 empty
|
|
jobs__pp: []int = null
|
|
jobs__pn: []int = null
|
|
jobs__ph: []int = null
|
|
jobs__pb: []int = null # the evidence when it went up
|
|
jobs__pm: []int = null
|
|
jobs__pr: []int = null
|
|
jobs__ps: []int = null
|
|
jobs__pd: []int = null # the day it went up
|
|
jobs__total: []int = null # handed in, per board
|
|
jobs__serial: []int = null # posts made, per board: each roll its own seed
|
|
jobs__seed: int = 1000
|
|
jobs__dice: Rng = null
|
|
jobs__q: Queue<JobsFact> = null
|
|
}
|
|
|
|
# the posts, every board's slots end to end from jobs__off[b]
|
|
|
|
|
|
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(jobs_st: mut JobsState) -> void {
|
|
if jobs_st.jobs__st != null { return }
|
|
jobs_st.jobs__st = jobs__ints(JOB_COUNT, JOBS_OFFERED)
|
|
jobs_st.jobs__hv = jobs__ints(JOB_COUNT, 0)
|
|
jobs_st.jobs__seen = new []bool
|
|
for i in 0 .. JOB_COUNT { push(jobs_st.jobs__seen, false) }
|
|
jobs_st.jobs__done_n = jobs__ints(JOBS_GROUPS, 0)
|
|
jobs_st.jobs__off = new []int
|
|
var n = 0
|
|
for b in 0 .. BOARD_COUNT {
|
|
push(jobs_st.jobs__off, n)
|
|
n += JobBoards[b].slots
|
|
}
|
|
jobs_st.jobs__pk = jobs__ints(n, -1)
|
|
jobs_st.jobs__pp = jobs__ints(n, -1)
|
|
jobs_st.jobs__pn = jobs__ints(n, 0)
|
|
jobs_st.jobs__ph = jobs__ints(n, 0)
|
|
jobs_st.jobs__pb = jobs__ints(n, 0)
|
|
jobs_st.jobs__pm = jobs__ints(n, 0)
|
|
jobs_st.jobs__pr = jobs__ints(n, 0)
|
|
jobs_st.jobs__ps = jobs__ints(n, JOBS_OFFERED)
|
|
jobs_st.jobs__pd = jobs__ints(n, 0)
|
|
jobs_st.jobs__total = jobs__ints(BOARD_COUNT, 0)
|
|
jobs_st.jobs__serial = jobs__ints(BOARD_COUNT, 0)
|
|
jobs_st.jobs__dice = rng_new(jobs_st.jobs__seed)
|
|
}
|
|
|
|
export function jobs_facts(jobs_st: mut JobsState) -> Queue<JobsFact> {
|
|
if jobs_st.jobs__q == null { jobs_st.jobs__q = queue_new("jobs.facts") }
|
|
return jobs_st.jobs__q
|
|
}
|
|
|
|
function jobs__fact(jobs_st: mut JobsState, 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_st.jobs__pk[jobs_st.jobs__off[b] + s]
|
|
f.param = jobs_st.jobs__pp[jobs_st.jobs__off[b] + s]
|
|
f.money = jobs_st.jobs__pm[jobs_st.jobs__off[b] + s]
|
|
f.rep = jobs_st.jobs__pr[jobs_st.jobs__off[b] + s]
|
|
f.scope = JobBoards[b].scope
|
|
}
|
|
q_push(jobs_facts(jobs_st), 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(jobs_st: mut JobsState, seed: int) -> void {
|
|
jobs_st.jobs__seed = seed
|
|
jobs_st.jobs__dice = rng_new(seed)
|
|
}
|