# state.ludic - the clock's port, its facts, and what it holds # what the clock asks the world: whether this machine runs it, how much the rest speeds it (1 when # nobody rests), and a seed for a new trip's moon # (unbound: this machine runs it, nobody rests, and a seed of 1) export port ClockWorld { owns_world: fn() -> bool = fn ck_owns_alone rest_scale: fn() -> float = fn ck_no_rest seed: fn() -> int = fn ck_seed_one } function ck_owns_alone() -> bool { return true } function ck_no_rest() -> float { return 1.0 } function ck_seed_one() -> int { return 1 } # how a day turned: the hour ran past midnight, or a verb turned it (a night slept, a collapse) export const DAY_STAYED_UP: int = 0 export const DAY_SLEPT: int = 1 export property DayTurned { day: int = 0 how: int = 0 } export state ClockState { ck_hhmm_tab: []string = ck_hhmm_table() # "00:00" .. "23:59", made with the state: asked every frame cal_month_days: int = 30 cal_year_months: int = 12 cal_season: []int = null ck_day: int = 1 ck_hours: float = 0.0 ck_moon: float = 0.0 ck_scale: float = 60.0 # game seconds per real second ck_start_hours: float = 8.0 ck_night_from: float = 20.0 ck_night_to: float = 6.0 ck_moon_days: float = 29.5 ck_moon_lo: float = 0.0 ck_moon_hi: float = 1.0 ck_dice: Rng = null ck_days: Queue = ck_days__new() } # the facts: each day that turned, in order; the game drains it and runs its morning export function clock_days(clock_st: ClockState) -> Queue { return clock_st.ck_days } function ck_owns() -> bool { return ClockWorld.owns_world() } function ck_rest() -> float { return ClockWorld.rest_scale() } # when a trip starts, when the night is, and how long the moon's month is export function clock_config(clock_st: mut ClockState, start_hours: float, night_from: float, night_to: float) -> void { clock_st.ck_start_hours = start_hours clock_st.ck_night_from = night_from clock_st.ck_night_to = night_to } # a new trip's moon falls in [lo, hi) of its month; the month is `days` long export function clock_config_moon(clock_st: mut ClockState, days: float, lo: float, hi: float) -> void { clock_st.ck_moon_days = days clock_st.ck_moon_lo = lo clock_st.ck_moon_hi = hi } function ck_days__new() -> Queue { return queue_new("clock.days") }