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