ludic/packages/ludic.effects/verbs.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

80 lines
2.9 KiB
Text

# verbs.ludic - the only way the ring changes. The same kind from the same label replaces
# itself; a bonus past the cap pushes out the oldest bonus; a full ring drops the nearest end.
function ef_end(effects_st: mut EffectsState, i: int, why: int) -> void {
let all = ef_all(effects_st)
let e = new EffectEnded
e.kind = all[i].kind
e.label = all[i].label
e.why = why
e.bonus = all[i].bonus
q_push(effects_ended(effects_st), e)
ef_drop(effects_st, i)
}
function ef_drop(effects_st: mut EffectsState, i: int) -> void {
let all = ef_all(effects_st)
let rest = new []Effect
for k in 0 .. len(all) { if k != i { push(rest, all[k]) } }
effects_st.ef_list = rest
}
# the one with the least time left (of the bonuses only, when asked); -1 when there is none
function ef_nearest_end(effects_st: mut EffectsState, bonus_only: bool) -> int {
let all = ef_all(effects_st)
var at = -1
for i in 0 .. len(all) {
if bonus_only and not all[i].bonus { continue }
if at < 0 or all[i].left < all[at].left { at = i }
}
return at
}
function ef_make_room(effects_st: mut EffectsState, bonus: bool) -> void {
if bonus {
while effects_bonus_count(effects_st) >= effects_st.ef_bonus_max and ef_nearest_end(effects_st, true) >= 0 { ef_end(effects_st, ef_nearest_end(effects_st, true), EFFECT_PUSHED_OUT) }
}
if len(ef_all(effects_st)) >= effects_st.ef_max and ef_nearest_end(effects_st, false) >= 0 { ef_end(effects_st, ef_nearest_end(effects_st, false), EFFECT_CROWDED_OUT) }
}
# begin one `after` game minutes from now, lasting `minutes` once it has begun
export function effects_add_after(effects_st: mut EffectsState, after: float, kind: int, mag: float, minutes: float, bonus: bool, label: string) -> void {
let all = ef_all(effects_st)
for i in 0 .. len(all) {
if all[i].kind == kind and all[i].label == label {
all[i].mag = mag
all[i].left = minutes
return
}
}
ef_make_room(effects_st, bonus)
let e = new Effect
e.kind = kind
e.mag = mag
e.left = minutes
e.delay = after
e.bonus = bonus
e.label = label
push(ef_all(effects_st), e)
}
export function effects_add(effects_st: mut EffectsState, kind: int, mag: float, minutes: float, bonus: bool, label: string) -> void {
effects_add_after(effects_st, 0.0, kind, mag, minutes, bonus, label)
}
# everything stops at once, and says nothing: a new trip or a night's sleep
export function effects_clear(effects_st: mut EffectsState) -> void { effects_st.ef_list = new []Effect }
# run them down by `minutes` of game time; a delayed one waits first
export function effects_run(effects_st: mut EffectsState, minutes: float) -> void {
var i = 0
while i < len(ef_all(effects_st)) {
let e = ef_all(effects_st)[i]
if e.delay > 0.0 {
e.delay = e.delay - minutes
i += 1
continue
}
e.left = e.left - minutes
if e.left < 0.0 { ef_end(effects_st, i, EFFECT_RAN_OUT) } else { i += 1 }
}
}