ludic/packages/ludic.gear/hand.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

72 lines
2.6 KiB
Text

# hand.ludic - what is held, and the charges: a held one runs only while it is in the hand, and
# each burns down by the game hours while it runs
export function gear_hand(gear_st: GearState) -> int { return gear_st.gear__hand }
# a new thing in the hand (-1 empty): whatever the old one was running goes out
export function gear_set_hand(gear_st: mut GearState, it: int) -> void {
gear__ensure(gear_st)
gear_st.gear__hand = it
for c in 0 .. CHARGE_COUNT { if GearCharges[c].hand { gear_st.gear__on[c] = false } }
}
# the charge an item carries, -1 none
export function gear_charge_of(it: int) -> int {
for c in 0 .. CHARGE_COUNT { if GearCharges[c].item == it { return c } }
return -1
}
export function gear_charge(gear_st: mut GearState, c: int) -> float {
gear__ensure(gear_st)
return gear_st.gear__left[c]
}
export function gear_charge_set(gear_st: mut GearState, c: int, v: float) -> void {
gear__ensure(gear_st)
gear_st.gear__left[c] = Math.clamp(v, 0.0, GearCharges[c].full)
}
export function gear_charge_fill(gear_st: mut GearState, c: int) -> void { gear_charge_set(gear_st, c, GearCharges[c].full) }
export function gear_running(gear_st: mut GearState, c: int) -> bool {
gear__ensure(gear_st)
return gear_st.gear__on[c]
}
# on or off; false when it has nothing left, or is held and not in the hand
export function gear_run(gear_st: mut GearState, c: int, on: bool) -> bool {
gear__ensure(gear_st)
if not on {
gear_st.gear__on[c] = false
return true
}
if gear_st.gear__left[c] < 1.0 { return false }
if GearCharges[c].hand and GearCharges[c].item != gear_st.gear__hand { return false }
gear_st.gear__on[c] = true
return true
}
# the hand's own charge is running (a torch lit, a flashlight on)
export function gear_lit(gear_st: mut GearState) -> bool {
if gear_st.gear__hand < 0 { return false }
let c = gear_charge_of(gear_st.gear__hand)
return c >= 0 and GearCharges[c].hand and gear_running(gear_st, c)
}
function gear__rate(gear_st: mut GearState, c: int) -> float {
let d = GearCharges[c]
if d.rate >= 0 { return gear_value(gear_st, d.rate) }
return d.per_hour
}
# the game hours of a tick burn every running charge; one that runs out stops and says so
function gear__burn(gear_st: mut GearState, hours: float) -> void {
gear__ensure(gear_st)
for c in 0 .. CHARGE_COUNT {
if not gear_st.gear__on[c] { continue }
gear_st.gear__left[c] = gear_st.gear__left[c] - hours * gear__rate(gear_st, c)
if gear_st.gear__left[c] > 0.0 { continue }
gear_st.gear__left[c] = 0.0
gear_st.gear__on[c] = false
gear__fact(gear_st, GEAR_RAN_OUT, -1, c, 0)
}
}