ludic.needs: a body's four needs, their rates, meals and the countdown to a collapse as a fact

Warmth, food, water and energy as bars of 0..100; what an hour of doing something
costs them (the package's rates: a full bar is a day at a trip's median); the
countdown when one runs out, reported as NEEDS_CRITICAL / NEEDS_RESTORED /
NEEDS_COLLAPSED facts. The body's work, the air, clothing, the sun, the
difficulty and the effects come through the NeedsWorld port. Its own save
section. Uses ludic_base only; 13 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 06:03:57 +03:00
parent 31e6740033
commit cf42214974
11 changed files with 631 additions and 0 deletions

View file

@ -0,0 +1,58 @@
# 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(k: int, n: float) -> void {
if nd_ok(k) { nd_add(k, n) }
}
# a meal: food, water and energy at once
export function needs_meal(food: float, water: float, energy: float) -> void {
nd_add(NEED_FOOD, food)
nd_add(NEED_WATER, water)
nd_add(NEED_ENERGY, energy)
}
export function needs_set(k: int, v: float) -> void {
if nd_ok(k) { nd_lv()[k] = Math.clamp(v, 0.0, 100.0) }
}
# at least `v`
export function needs_floor(k: int, v: float) -> void {
if nd_ok(k) and nd_lv()[k] < v { needs_set(k, v) }
}
# a night: rested to what it was worth, hungrier and thirstier for it, but never empty
export function needs_after_night(rested: float, food_lost: float, water_lost: float) -> void {
let lv = nd_lv()
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() -> void { nd_legs = 0.0 }
# the body went down, however: one more collapse, and no countdown running
export function needs_went_down() -> void {
nd_collapses += 1
nd_legs = 0.0
}
# a hand up: the cost is in the body, and nothing goes below twenty
export function needs_helped_up() -> void {
let lv = nd_lv()
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)
nd_legs = 0.0
}
# a new trip: fed, watered, rested and warm, and never walked out
export function needs_reset() -> void {
nd_lv()
nd_fill()
nd_legs = 0.0
nd_last = 0
nd_collapses = 0
q_clear(needs_facts())
}