ludic/packages/ludic.steps/state.ludic

89 lines
3.1 KiB
Text

# state.ludic - the port, the kinds' shapes and pools, the facts, and the arc being played
# what a step kind measures, asked of the game: a count, a mask, or 1 / 0, for one player (0 is
# this machine's own); whether a party is playing, and whether a seat in it is taken
export port StepsWorld {
value: fn(int, int, int) -> int
party: fn() -> bool = fn steps__solo
present: fn(int) -> bool = fn steps__only_me
}
function steps__solo() -> bool { return false }
function steps__only_me(p: int) -> bool { return p == 0 }
# a kind's shape: met or not; a number against the need; a mask whose bits are counted against
# the need; every bit of the mask in `param`
export const STEPS_SHAPE_YES: int = 0
export const STEPS_SHAPE_COUNT: int = 1
export const STEPS_SHAPE_MASK: int = 2
export const STEPS_SHAPE_MASK_ALL: int = 3
# how a party combines a kind: the same for everyone already (asked of this machine); anyone
# having done it; the counts add up; the masks union; the best one; every player needs their own
export const STEPS_POOL_WORLD: int = 0
export const STEPS_POOL_ANY: int = 1
export const STEPS_POOL_SUM: int = 2
export const STEPS_POOL_OR: int = 3
export const STEPS_POOL_MAX: int = 4
export const STEPS_POOL_EACH: int = 5
# the most steps a chapter carries: its done steps are a bit mask
export const STEPS_PER_CHAPTER: int = 6
export property StepsKind {
key: string = ""
@OneOf(STEPS_SHAPE_) shape: int = STEPS_SHAPE_YES
@OneOf(STEPS_POOL_) pool: int = STEPS_POOL_WORLD
shows: bool = false # a panel shows its count against what it wants
}
export const STEPS_MET: int = 0 # a step of the current chapter was met (chapter, step)
export const STEPS_CHAPTER: int = 1 # every step of a chapter is met, and the next one is open
export property StepsFact {
what: int = 0
chapter: int = 0
step: int = 0
}
export state StepsState {
steps__players: int = 12
steps__col: []int = null # players * STEPS_PER_CHAPTER shares
steps__col_ch: int = -1 # the chapter they are about
steps__kinds: []StepsKind = null
steps__n: []int = null # steps per chapter
steps__kind: []int = null # STEPS_PER_CHAPTER per chapter
steps__param: []int = null
steps__need: []int = null
steps__cur: int = 0
steps__done: int = 0
steps__facts: Queue<StepsFact> = steps__facts__new()
}
export function steps_facts(steps_st: StepsState) -> Queue<StepsFact> {
return steps_st.steps__facts
}
@alloc_ok("a step's fact: once, when a step or a chapter is met")
function steps__fact(steps_st: StepsState, what: int, ch: int, i: int) -> void {
var f = q_rec(steps_facts(steps_st))
if f == null {
@alloc_ok("past the ring: more of these in a frame than its records, then kept in it")
f = new StepsFact
q_ring_add(steps_facts(steps_st), f)
}
f.what = what
f.chapter = ch
f.step = i
q_push(steps_facts(steps_st), f)
}
export function steps_popcount(m: int) -> int {
var n = 0
var v = m
while v != 0 {
n += v & 1
v = (v >> 1) & 0x7FFFFFFF
}
return n
}
function steps__facts__new() -> Queue<StepsFact> { return queue_new("steps.facts") }