ludic/packages/ludic.session/state.ludic

102 lines
3.2 KiB
Text

# state.ludic - a roster slot, the local player's port, the roles, and the facts the game drains
export const PLY_MAX: int = 12 # a party: this player and eleven more
export const SES_SOLO: int = 0
export const SES_HOST: int = 1
export const SES_GUEST: int = 2
# what happened: a player in or out (slot, pid), the role changed (role), a vote opened, this
# guest's own vote to send, a vote decided (id, kind, param, passed, text), everyone in for the
# night (the host), this player turned in or got up (yes)
export const SES_JOINED: int = 0
export const SES_LEFT: int = 1
export const SES_ROLE: int = 2
export const SES_VOTE_OPENED: int = 3
export const SES_VOTE_CAST: int = 4
export const SES_VOTE_RESOLVED: int = 5
export const SES_NIGHT: int = 6
export const SES_SLEEP: int = 7
export property SessionFact {
what: int = 0,
slot: int = -1,
pid: int = 0,
role: int = 0,
id: int = 0,
kind: int = 0,
param: int = 0,
yes: bool = false,
text: string = ""
}
# a remote player, as its own machine reported it
property PartyMember {
on: bool = false,
pid: int = 0, # the session's id for them (0 is never a remote player)
name: string = "",
x: float = 0.0,
y: float = 0.0,
z: float = 0.0,
yaw: float = 0.0,
speed: float = 0.0,
rest: float = 1.0, # how much faster their rest runs the clock (1 on their feet)
sleeping: bool = false, # turned in, as their body says
ready: bool = false # turned in, as they told the host (the host's count for the night)
}
# this machine's player, read live
export port SessionLocal {
x: fn() -> float
y: fn() -> float
z: fn() -> float
yaw: fn() -> float = fn session__zero
speed: fn() -> float = fn session__zero
rest: fn() -> float = fn session__one
name: fn() -> string = fn session__nameless
}
function session__zero() -> float { return 0.0 }
function session__one() -> float { return 1.0 }
function session__nameless() -> string { return "" }
export state SessionState {
session__me_sleeping: bool = false
session__slot: []PartyMember = session__slots()
session__role: int = 0
session__max: int = 4
session__open: bool = true
session__near_i: int = 0
session__facts: Queue<SessionFact> = session__facts__new()
session__vote_id: int = 0
session__vote_kind: int = 0
session__vote_param: int = 0
session__vote_text: string = ""
session__vote_t: float = 0.0
session__vote_yes: int = 0
session__vote_no: int = 0
session__vote_mine: int = -1 # -1 not voted, 0 no, 1 yes
session__vote_passed: int = -1 # the last vote: -1 none, 0 failed, 1 passed
}
export function ses_facts(session_st: SessionState) -> Queue<SessionFact> {
return session_st.session__facts
}
function session__fact(session_st: SessionState, what: int, slot: int, pid: int) -> SessionFact {
let f = new SessionFact
f.what = what
f.slot = slot
f.pid = pid
f.role = session_st.session__role
q_push(ses_facts(session_st), f)
return f
}
function session__facts__new() -> Queue<SessionFact> { return queue_new("session.facts") }
# the roster's slots, slot 0 this machine's own and on
function session__slots() -> []PartyMember {
let out = new []PartyMember
for i in 0 .. PLY_MAX { push(out, new PartyMember) }
out[0].on = true
return out
}