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:
parent
31e6740033
commit
cf42214974
11 changed files with 631 additions and 0 deletions
36
packages/ludic.needs/queries.ludic
Normal file
36
packages/ludic.needs/queries.ludic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# queries.ludic - what the world asks the body
|
||||
export function needs_level(k: int) -> float {
|
||||
if not nd_ok(k) { return 0.0 }
|
||||
return nd_lv()[k]
|
||||
}
|
||||
|
||||
export function needs_warmth() -> float { return nd_lv()[NEED_WARMTH] }
|
||||
export function needs_food() -> float { return nd_lv()[NEED_FOOD] }
|
||||
export function needs_water() -> float { return nd_lv()[NEED_WATER] }
|
||||
export function needs_energy() -> float { return nd_lv()[NEED_ENERGY] }
|
||||
|
||||
# seconds left before a collapse (0: no countdown), and the need it is for
|
||||
export function needs_last_legs() -> float { return nd_legs }
|
||||
export function needs_last_need() -> int { return nd_last }
|
||||
export function needs_collapses() -> int { return nd_collapses }
|
||||
|
||||
# the walk's pace, times: the ramp of each need, and 0.6 more on last legs
|
||||
export function needs_pace() -> float {
|
||||
let lv = nd_lv()
|
||||
var m = nd_pace(lv[NEED_WARMTH]) * nd_pace(lv[NEED_FOOD])
|
||||
if NeedsWorld.thirst() { m = m * nd_pace(lv[NEED_WATER]) }
|
||||
if nd_legs > 0.0 { m = m * 0.6 }
|
||||
return m
|
||||
}
|
||||
|
||||
# running needs legs, calories and a body that is not already in trouble
|
||||
export function needs_can_run() -> bool {
|
||||
let lv = nd_lv()
|
||||
return lv[NEED_ENERGY] > 8.0 and lv[NEED_FOOD] > 20.0 and lv[NEED_WARMTH] > 20.0 and lv[NEED_WATER] > 20.0
|
||||
}
|
||||
|
||||
# the lowest of the four
|
||||
export function needs_lowest() -> float {
|
||||
let lv = nd_lv()
|
||||
return Math.min(Math.min(lv[NEED_WARMTH], lv[NEED_FOOD]), Math.min(lv[NEED_WATER], lv[NEED_ENERGY]))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue