feat(ludic.weather): spells of weather as a mechanic package

The kinds and their odds are data the game hands in; a port asks whether this
machine owns the world, the hour, the night, the odds from a kind, what the
story wants of the sky (a front, a hold, a clear night), the front's kind and
length, and a seed. Its own dice; a new spell, a clearing, lightning and a
wanted front are facts on weather_facts(); its own save section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 04:48:38 +03:00
parent a2012a5afe
commit 093ca0d260
12 changed files with 746 additions and 0 deletions

View file

@ -0,0 +1,50 @@
# system.ludic - the weather as a system: PH_SIMULATE, and its own save section
function weather_tick(t: Tick) -> void { weather_run(t.dt, t.hours) }
export function weather_save() -> Val {
let v = Value.object()
sv_put_int(v, "state", wx_state)
sv_put_int(v, "next", wx_next)
sv_put_float(v, "left", wx_left)
sv_put_int(v, "forecast", wx_forecast)
sv_put_bool(v, "forced", wx_forced)
sv_put_float(v, "dir", wx_dir)
sv_put_float(v, "ground", wx_ground)
sv_put_float(v, "clear_t", wx_clear_t)
sv_put_bool(v, "wet_today", wx_wet_today)
sv_put_bool(v, "wet_yesterday", wx_wet_yesterday)
sv_put_int(v, "dice", wx_dice.s)
return v
}
function wx_kind_ok(k: int) -> int {
if k < 0 or k >= weather_kind_count() { return wx_clear_kind() }
return k
}
export function weather_load(v: Val, version: int) -> void {
weather_reset()
wx_state = wx_kind_ok(sv_int(v, "state", 0))
wx_next = wx_kind_ok(sv_int(v, "next", 0))
wx_left = sv_float(v, "left", 10.0)
wx_forecast = wx_kind_ok(sv_int(v, "forecast", 0))
wx_forced = sv_bool(v, "forced", false)
wx_dir = sv_float(v, "dir", 0.0)
wx_ground = sv_float(v, "ground", 0.0)
wx_clear_t = sv_float(v, "clear_t", 0.0)
wx_wet_today = sv_bool(v, "wet_today", false)
wx_wet_yesterday = sv_bool(v, "wet_yesterday", false)
wx_dice.s = sv_int(v, "dice", wx_dice.s)
if weather_kind_count() == 0 { return }
if not wx_kinds[wx_state].clear { wx_amount = 1.0 }
wx_wind = wx_kinds[wx_state].wind
}
export function weather_system() -> System {
let s = system_new("weather", PH_SIMULATE)
s.reset = fn weather_reset
s.tick = fn weather_tick
s.save = fn weather_save
s.load = fn weather_load
return s
}