ludic/packages/ludic.weather/verbs.ludic
Orkuncakilkaya 093ca0d260 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>
2026-09-25 04:48:38 +03:00

68 lines
2.1 KiB
Text

# verbs.ludic - the only way the sky changes from outside: a morning, a reset, the host's word
# a new trip: clear sky, a still-ish wind, nothing forecast; the dice from the world's seed
export function weather_reset() -> void {
var seed = 1
if wx_world != null and wx_world.seed != null { seed = wx_world.seed() }
wx_dice = rng_new(seed)
let clear = wx_clear_kind()
wx_state = clear
wx_next = clear
wx_forecast = clear
wx_left = 30.0
wx_amount = 0.0
wx_forced = false
wx_wind = 0.2
wx_dir = 0.0
wx_ground = 0.0
wx_flash = 0.0
wx_thunder_t = 0.0
wx_clear_t = 0.0
wx_wet_today = false
wx_wet_yesterday = false
q_clear(weather_facts())
}
# a new day's forecast: seven times in ten it is the next spell. A front already on its way
# stays on its way.
export function weather_morning() -> void {
if weather_kind_count() == 0 { return }
wx_wet_yesterday = wx_wet_today or wx_kinds[wx_state].wet
wx_wet_today = false
if wx_forced {
wx_forecast = wx_next
return
}
wx_forecast = wx_pick_next(wx_state)
if rng_float(wx_dice) < 0.7 { wx_next = wx_forecast }
}
# the sky outright: a spell of `kind` now, `left` hours of it, at full strength when not clear
# (staging, a test, a story beat)
export function weather_set(kind: int, next: int, left: float) -> void {
wx_state = kind
wx_next = next
wx_left = left
wx_amount = 1.0
if wx_kinds[kind].clear { wx_amount = 0.0 }
}
# what the machine that owns the world says the sky is; a new spell is a fact here too
export function weather_told(kind: int, next: int, left: float, amount: float, wind: float, dir: float, forecast: int) -> void {
let was = wx_state
wx_state = kind
wx_next = next
wx_left = left
wx_amount = amount
wx_wind = wind
wx_dir = dir
wx_forecast = forecast
if kind != was { wx_fact(WEATHER_BEGAN, kind, was) }
}
export function weather_set_wind(strength: float, dir: float) -> void {
wx_wind = strength
wx_dir = dir
}
export function weather_set_ground(wet: float) -> void { wx_ground = wet }
export function weather_set_flash(f: float) -> void { wx_flash = f }