ludic/packages/ludic.jobs/jobs.ludic
Orkuncakilkaya 71735b10a2 feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune
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>
2026-09-26 04:19:56 +03:00

96 lines
3.8 KiB
Text

# jobs.ludic - the written jobs: offered by standing and story, taken, readied, handed in and paid
export function jobs_ok(i: int) -> bool { return i >= 0 and i < JOB_COUNT }
export function jobs_state(jobs_st: mut JobsState, i: int) -> int {
jobs__ensure(jobs_st)
return jobs_st.jobs__st[i]
}
export function jobs_have(jobs_st: mut JobsState, i: int) -> int {
jobs__ensure(jobs_st)
return jobs_st.jobs__hv[i]
}
export function jobs_ready_now(jobs_st: mut JobsState, i: int) -> bool { return jobs_state(jobs_st, i) == JOBS_READY }
# taken and not yet paid
export function jobs_under_way(jobs_st: mut JobsState, i: int) -> bool {
let s = jobs_state(jobs_st, i)
return s == JOBS_ACTIVE or s == JOBS_READY
}
# on offer: not taken, the scope's standing and the story far enough, and the game allowing it
export function jobs_offered(jobs_st: mut JobsState, i: int) -> bool {
let d = Jobs[i]
if jobs_state(jobs_st, i) != JOBS_OFFERED { return false }
return JobsWorld.rep(d.scope) >= d.minrep and JobsWorld.stage() >= d.minstage and JobsWorld.open(i)
}
export function jobs_take(jobs_st: mut JobsState, i: int) -> bool {
if not jobs_ok(i) or jobs_state(jobs_st, i) != JOBS_OFFERED { return false }
jobs_st.jobs__st[i] = JOBS_ACTIVE
jobs_st.jobs__hv[i] = 0
jobs__recheck_one(jobs_st, i)
return true
}
# a count has moved: a job with a need is ready when it is met
function jobs__moved(jobs_st: mut JobsState, i: int, was: int) -> void {
let d = Jobs[i]
if d.need > 0 and jobs_st.jobs__hv[i] > d.need { jobs_st.jobs__hv[i] = d.need }
if jobs_st.jobs__hv[i] > was { jobs__fact(jobs_st, JOBS_F_PROGRESSED, i, -1, -1, jobs_st.jobs__hv[i], d.need) }
if jobs_st.jobs__st[i] == JOBS_ACTIVE and d.need > 0 and jobs_st.jobs__hv[i] >= d.need { jobs_ready(jobs_st, i) }
}
# the game's own play: a step counter, a mask of targets met
export function jobs_set_have(jobs_st: mut JobsState, i: int, v: int) -> void {
let was = jobs_have(jobs_st, i)
jobs_st.jobs__hv[i] = v
jobs__moved(jobs_st, i, was)
}
export function jobs_add_have(jobs_st: mut JobsState, i: int, n: int) -> void { jobs_set_have(jobs_st, i, jobs_have(jobs_st, i) + n) }
export function jobs_mark(jobs_st: mut JobsState, i: int, bit: int) -> void { jobs_set_have(jobs_st, i, jobs_have(jobs_st, i) | (1 << bit)) }
# everything in hand
export function jobs_ready(jobs_st: mut JobsState, i: int) -> void {
if jobs_state(jobs_st, i) != JOBS_ACTIVE { return }
jobs_st.jobs__st[i] = JOBS_READY
jobs__fact(jobs_st, JOBS_F_COMPLETED, i, -1, -1, jobs_st.jobs__hv[i], Jobs[i].need)
}
export function jobs_hand_in(jobs_st: mut JobsState, i: int) -> bool {
if not jobs_ok(i) or jobs_state(jobs_st, i) != JOBS_READY { return false }
let d = Jobs[i]
jobs_st.jobs__st[i] = JOBS_DONE
if d.group >= 0 and d.group < JOBS_GROUPS { jobs_st.jobs__done_n[d.group] += 1 }
JobsPay.reward(d.scope, d.money, d.rep)
jobs__fact(jobs_st, JOBS_F_HANDED_IN, i, -1, -1, jobs_st.jobs__hv[i], d.need)
return true
}
# finished and paid in one go, whatever the count says
export function jobs_complete(jobs_st: mut JobsState, i: int) -> bool {
if not jobs_ok(i) or not jobs_under_way(jobs_st, i) { return false }
jobs_ready(jobs_st, i)
return jobs_hand_in(jobs_st, i)
}
# the state outright: the host's word for a party job, a test
export function jobs_set(jobs_st: mut JobsState, i: int, state: int, have: int) -> void {
jobs__ensure(jobs_st)
jobs_st.jobs__st[i] = state
jobs_st.jobs__hv[i] = have
}
export function jobs_done(jobs_st: mut JobsState, group: int) -> int {
jobs__ensure(jobs_st)
if group < 0 or group >= JOBS_GROUPS { return 0 }
return jobs_st.jobs__done_n[group]
}
export function jobs_set_done(jobs_st: mut JobsState, group: int, n: int) -> void {
jobs__ensure(jobs_st)
if group >= 0 and group < JOBS_GROUPS { jobs_st.jobs__done_n[group] = n }
}