ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1 KiB
Text
30 lines
1 KiB
Text
# pick.ludic - the next spell, drawn from weights, and how long one lasts. The weights are the
|
|
# kind's own unless the world leans on them (a season, a wet week); every draw is this package's
|
|
function wx_odds(from: int) -> []float {
|
|
return WeatherWorld.odds(from)
|
|
}
|
|
|
|
# the kind a set of weights lands on; no weights (or all zero) keeps the kind it came from
|
|
export function weather_draw_from(w: []float, from: int, roll: float) -> int {
|
|
if w == null { return from }
|
|
var total = 0.0
|
|
for k in 0 .. len(w) { if w[k] > 0.0 { total = total + w[k] } }
|
|
if not (total > 0.0) { return from }
|
|
var at = roll * total
|
|
for k in 0 .. len(w) {
|
|
if w[k] > 0.0 {
|
|
if at < w[k] { return k }
|
|
at = at - w[k]
|
|
}
|
|
}
|
|
return len(w) - 1
|
|
}
|
|
|
|
function wx_pick_next(weather_st: WeatherState, from: int) -> int {
|
|
return weather_draw_from(wx_odds(from), from, rng_float(weather_st.wx_dice))
|
|
}
|
|
|
|
function wx_spell_hours(weather_st: WeatherState, k: int) -> float {
|
|
let kd = weather_st.wx_kinds[k]
|
|
return rng_span(weather_st.wx_dice, kd.spell_lo, kd.spell_hi)
|
|
}
|