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

58 lines
2.3 KiB
Text

# verbs.ludic - the only way the needs change from outside; each is held to 0..100
# `n` more of a need (less, when negative): a meal, a drink, a shove from a bear
export function needs_feed(needs_st: mut NeedsState, k: int, n: float) -> void {
if nd_ok(k) { nd_add(needs_st, k, n) }
}
# a meal: food, water and energy at once
export function needs_meal(needs_st: mut NeedsState, food: float, water: float, energy: float) -> void {
nd_add(needs_st, NEED_FOOD, food)
nd_add(needs_st, NEED_WATER, water)
nd_add(needs_st, NEED_ENERGY, energy)
}
export function needs_set(needs_st: mut NeedsState, k: int, v: float) -> void {
if nd_ok(k) { nd_lv(needs_st)[k] = Math.clamp(v, 0.0, 100.0) }
}
# at least `v`
export function needs_floor(needs_st: mut NeedsState, k: int, v: float) -> void {
if nd_ok(k) and nd_lv(needs_st)[k] < v { needs_set(needs_st, k, v) }
}
# a night: rested to what it was worth, hungrier and thirstier for it, but never empty
export function needs_after_night(needs_st: mut NeedsState, rested: float, food_lost: float, water_lost: float) -> void {
let lv = nd_lv(needs_st)
lv[NEED_ENERGY] = Math.clamp(rested, 0.0, 100.0)
lv[NEED_FOOD] = Math.max(lv[NEED_FOOD] - food_lost, 6.0)
if water_lost > 0.0 { lv[NEED_WATER] = Math.max(lv[NEED_WATER] - water_lost, 5.0) }
}
# the countdown called off, and nothing said (a wake, a load, a test)
export function needs_calm(needs_st: mut NeedsState) -> void { needs_st.nd_legs = 0.0 }
# the body went down, however: one more collapse, and no countdown running
export function needs_went_down(needs_st: mut NeedsState) -> void {
needs_st.nd_collapses += 1
needs_st.nd_legs = 0.0
}
# a hand up: the cost is in the body, and nothing goes below twenty
export function needs_helped_up(needs_st: mut NeedsState) -> void {
let lv = nd_lv(needs_st)
lv[NEED_WARMTH] = Math.max(20.0, lv[NEED_WARMTH] - 15.0)
lv[NEED_FOOD] = Math.max(20.0, lv[NEED_FOOD] - 15.0)
lv[NEED_WATER] = Math.max(20.0, lv[NEED_WATER] - 15.0)
lv[NEED_ENERGY] = Math.max(20.0, lv[NEED_ENERGY] - 25.0)
needs_st.nd_legs = 0.0
}
# a new trip: fed, watered, rested and warm, and never walked out
export function needs_reset(needs_st: mut NeedsState) -> void {
nd_lv(needs_st)
nd_fill(needs_st)
needs_st.nd_legs = 0.0
needs_st.nd_last = 0
needs_st.nd_collapses = 0
q_clear(needs_facts(needs_st))
}