ludic/packages/ludic.gear/state.ludic

48 lines
1.5 KiB
Text

# state.ludic - the level of each kind, the hand, each charge's units and whether it runs, the facts
export state GearState {
gear__lv: []int = gear__starts()
gear__hand: int = -1
gear__left: []float = gear__fulls()
gear__on: []bool = gear__offs()
gear__q: Queue<GearFact> = gear__queue()
}
# what a new state starts with: every kind at its start, every charge full and off
function gear__starts() -> []int {
let xs = new []int
for k in 0 .. GEAR_COUNT { push(xs, GearKinds[k].start) }
return xs
}
function gear__fulls() -> []float {
let xs = new []float
for c in 0 .. CHARGE_COUNT { push(xs, GearCharges[c].full) }
return xs
}
function gear__queue() -> Queue<GearFact> { return queue_new("gear.facts") }
function gear__offs() -> []bool {
let xs = new []bool
for c in 0 .. CHARGE_COUNT { push(xs, false) }
return xs
}
export function gear_facts(gear_st: GearState) -> Queue<GearFact> { return gear_st.gear__q }
function gear__fact(gear_st: GearState, what: int, k: int, c: int, cost: int) -> void {
var f = q_rec(gear_facts(gear_st))
if f == null {
@alloc_ok("past the ring: more of these in a frame than its records, then kept in it")
f = new GearFact
q_ring_add(gear_facts(gear_st), f)
}
f.what = what
f.cost = cost
f.kind = k
f.charge = c
f.level = 0
f.item = -1
if k >= 0 {
f.level = gear_st.gear__lv[k]
f.item = GearKinds[k].item
}
if c >= 0 { f.item = GearCharges[c].item }
q_push(gear_facts(gear_st), f)
}