93 lines
3.4 KiB
Text
93 lines
3.4 KiB
Text
# state.ludic - each job's state and count, the posts on the boards, the done counts, the dice and
|
|
# the facts, each sized from the registries when the state is made.
|
|
export state JobsState {
|
|
jobs__st: []int = jobs__ints(JOB_COUNT, JOBS_OFFERED)
|
|
jobs__hv: []int = jobs__ints(JOB_COUNT, 0)
|
|
jobs__seen: []bool = jobs__bools(JOB_COUNT) # an offer already said
|
|
jobs__back: []int = jobs__ints(JOB_COUNT, 0) # given up: the first day it may be taken again
|
|
jobs__primed: bool = false # the first tick after a reset learns the offers quietly
|
|
jobs__done_n: []int = jobs__ints(JOBS_GROUPS, 0) # handed in, per group
|
|
jobs__off: []int = jobs__offsets()
|
|
jobs__pk: []int = jobs__ints(jobs__slots(), -1) # kind, -1 empty
|
|
jobs__pp: []int = jobs__ints(jobs__slots(), -1)
|
|
jobs__pn: []int = jobs__ints(jobs__slots(), 0)
|
|
jobs__ph: []int = jobs__ints(jobs__slots(), 0)
|
|
jobs__pb: []int = jobs__ints(jobs__slots(), 0) # the evidence when it went up
|
|
jobs__pm: []int = jobs__ints(jobs__slots(), 0)
|
|
jobs__pr: []int = jobs__ints(jobs__slots(), 0)
|
|
jobs__ps: []int = jobs__ints(jobs__slots(), JOBS_OFFERED)
|
|
jobs__pd: []int = jobs__ints(jobs__slots(), 0) # the day it went up
|
|
jobs__total: []int = jobs__ints(BOARD_COUNT, 0) # handed in, per board
|
|
jobs__serial: []int = jobs__ints(BOARD_COUNT, 0) # posts made, per board: each roll its own seed
|
|
jobs__seed: int = 1000
|
|
jobs__dice: Rng = rng_new(1000)
|
|
jobs__q: Queue<JobsFact> = jobs__q__new()
|
|
@max(1024) jobs__fpool: []JobsFact = new []JobsFact # every fact record made, reused once no drain holds it (facts.ludic)
|
|
@max(1024) jobs__ffree: []JobsFact = new []JobsFact
|
|
jobs__fnext: []int = words(1)
|
|
}
|
|
|
|
# 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__bools(n: int) -> []bool {
|
|
let out = new []bool
|
|
for i in 0 .. n { push(out, false) }
|
|
return out
|
|
}
|
|
# every board's slots end to end: where each board's start, and how many in all
|
|
function jobs__offsets() -> []int {
|
|
let out = new []int
|
|
var n = 0
|
|
for b in 0 .. BOARD_COUNT {
|
|
push(out, n)
|
|
n += JobBoards[b].slots
|
|
}
|
|
return out
|
|
}
|
|
function jobs__slots() -> int {
|
|
var n = 0
|
|
for b in 0 .. BOARD_COUNT { n += JobBoards[b].slots }
|
|
return n
|
|
}
|
|
|
|
export function jobs_facts(jobs_st: JobsState) -> Queue<JobsFact> {
|
|
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 = jobs__fact_record(jobs_st)
|
|
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)
|
|
}
|
|
function jobs__q__new() -> Queue<JobsFact> { return queue_new("jobs.facts") }
|