ludic/packages/ludic.steps/check.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

43 lines
1.9 KiB
Text

# check.ludic - once a frame on the machine that owns the story: every open step of the current
# chapter that is met now sticks (STEPS_MET), and a chapter with all of them done moves the arc on
# (STEPS_CHAPTER). A step asks about STATE, so one met before its chapter opened ticks at once.
export function steps_check(steps_st: mut StepsState) -> void {
if steps_finished(steps_st) { return }
let ch = steps_st.steps__cur
let n = steps_in(steps_st, ch)
var all = true
for i in 0 .. n {
if not steps_done(steps_st, i) and steps_met(steps_st, i) {
steps_st.steps__done = steps_st.steps__done | (1 << i)
steps__fact(steps_st, STEPS_MET, ch, i)
}
if not steps_done(steps_st, i) { all = false }
}
if not all { return }
steps_st.steps__cur = ch + 1
steps_st.steps__done = 0
steps__fact(steps_st, STEPS_CHAPTER, ch, n)
}
# is step i of chapter ch met by this machine's own state? (a chapter not being played, a panel)
export function steps_check_at(steps_st: StepsState, ch: int, i: int) -> bool {
if ch < 0 or ch >= steps_count(steps_st) or i < 0 or i >= steps_in(steps_st, ch) { return false }
return steps_eval(steps_st, steps_kind(steps_st, ch, i), steps_param(steps_st, ch, i), steps_need(steps_st, ch, i))
}
# is an open step of the current chapter asking for this kind (and this param, unless < 0)?
export function steps_wants(steps_st: StepsState, kind: int, param: int) -> bool {
if steps_finished(steps_st) { return false }
for i in 0 .. steps_in(steps_st, steps_st.steps__cur) {
if steps_done(steps_st, i) or steps_kind(steps_st, steps_st.steps__cur, i) != kind { continue }
if param < 0 or steps_param(steps_st, steps_st.steps__cur, i) == param { return true }
}
return false
}
# back to no arc and no party (tests)
export function steps_reset(steps_st: mut StepsState) -> void {
steps_arc_clear(steps_st)
steps__party_clear(steps_st)
q_clear(steps_facts(steps_st))
}