wip(0.S3): the packages migrated by ludic migrate state packages - every package test green
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1e8b5b0523
commit
07505e7ef2
294 changed files with 14996 additions and 14675 deletions
|
|
@ -8,104 +8,95 @@ export const SES_MAY_HOSTS: int = 3 # a guest: it is for the host to ask
|
|||
|
||||
const SESSION_VOTE_SECS: float = 30.0
|
||||
|
||||
var session__vote_id: int = 0
|
||||
var session__vote_kind: int = 0
|
||||
var session__vote_param: int = 0
|
||||
var session__vote_text: string = ""
|
||||
var session__vote_t: float = 0.0
|
||||
var session__vote_yes: int = 0
|
||||
var session__vote_no: int = 0
|
||||
var session__vote_mine: int = -1 # -1 not voted, 0 no, 1 yes
|
||||
var session__vote_passed: int = -1 # the last vote: -1 none, 0 failed, 1 passed
|
||||
|
||||
# a world-changing act: may it go ahead now, or does the party have to be asked first?
|
||||
export function ses_may(kind: int, param: int, text: string) -> int {
|
||||
if not ses_live() { return SES_MAY_GO }
|
||||
if session__role == SES_GUEST { return SES_MAY_HOSTS }
|
||||
if ply_count() <= 1 { return SES_MAY_GO }
|
||||
if not ses_vote_open(kind, param, text) { return SES_MAY_BUSY }
|
||||
export function ses_may(base_st: mut BaseState, session_st: mut SessionState, kind: int, param: int, text: string) -> int {
|
||||
if not ses_live(session_st) { return SES_MAY_GO }
|
||||
if session_st.session__role == SES_GUEST { return SES_MAY_HOSTS }
|
||||
if ply_count(session_st) <= 1 { return SES_MAY_GO }
|
||||
if not ses_vote_open(base_st, session_st, kind, param, text) { return SES_MAY_BUSY }
|
||||
return SES_MAY_ASKED
|
||||
}
|
||||
|
||||
# the host puts it to the party, voting yes itself
|
||||
export function ses_vote_open(kind: int, param: int, text: string) -> bool {
|
||||
if session__role != SES_HOST or ses_vote_live() { return false }
|
||||
session__vote_id += 1
|
||||
session__vote_kind = kind
|
||||
session__vote_param = param
|
||||
session__vote_text = text
|
||||
session__vote_t = SESSION_VOTE_SECS
|
||||
session__vote_yes = 1
|
||||
session__vote_no = 0
|
||||
session__vote_mine = 1
|
||||
session__vote_passed = -1
|
||||
let f = session__vote_fact(SES_VOTE_OPENED)
|
||||
export function ses_vote_open(base_st: mut BaseState, session_st: mut SessionState, kind: int, param: int, text: string) -> bool {
|
||||
if session_st.session__role != SES_HOST or ses_vote_live(session_st) { return false }
|
||||
session_st.session__vote_id += 1
|
||||
session_st.session__vote_kind = kind
|
||||
session_st.session__vote_param = param
|
||||
session_st.session__vote_text = text
|
||||
session_st.session__vote_t = SESSION_VOTE_SECS
|
||||
session_st.session__vote_yes = 1
|
||||
session_st.session__vote_no = 0
|
||||
session_st.session__vote_mine = 1
|
||||
session_st.session__vote_passed = -1
|
||||
let f = session__vote_fact(base_st, session_st, SES_VOTE_OPENED)
|
||||
f.yes = true
|
||||
session__vote_check()
|
||||
session__vote_check(base_st, session_st)
|
||||
return true
|
||||
}
|
||||
|
||||
# this player's answer; a guest's goes to the host as SES_VOTE_CAST
|
||||
export function ses_vote_cast(yes: bool) -> void {
|
||||
if not ses_vote_live() or session__vote_mine >= 0 { return }
|
||||
if yes { session__vote_mine = 1 } else { session__vote_mine = 0 }
|
||||
if session__role == SES_GUEST {
|
||||
let f = session__vote_fact(SES_VOTE_CAST)
|
||||
export function ses_vote_cast(base_st: mut BaseState, session_st: mut SessionState, yes: bool) -> void {
|
||||
if not ses_vote_live(session_st) or session_st.session__vote_mine >= 0 { return }
|
||||
if yes { session_st.session__vote_mine = 1 } else { session_st.session__vote_mine = 0 }
|
||||
if session_st.session__role == SES_GUEST {
|
||||
let f = session__vote_fact(base_st, session_st, SES_VOTE_CAST)
|
||||
f.yes = yes
|
||||
return
|
||||
}
|
||||
ses_vote_heard(session__vote_id, yes)
|
||||
ses_vote_heard(base_st, session_st, session_st.session__vote_id, yes)
|
||||
}
|
||||
|
||||
# the host: a player's answer to vote `id`
|
||||
export function ses_vote_heard(id: int, yes: bool) -> void {
|
||||
if session__role != SES_HOST or id != session__vote_id or not ses_vote_live() { return }
|
||||
if yes { session__vote_yes += 1 } else { session__vote_no += 1 }
|
||||
session__vote_check()
|
||||
export function ses_vote_heard(base_st: mut BaseState, session_st: mut SessionState, id: int, yes: bool) -> void {
|
||||
if session_st.session__role != SES_HOST or id != session_st.session__vote_id or not ses_vote_live(session_st) { return }
|
||||
if yes { session_st.session__vote_yes += 1 } else { session_st.session__vote_no += 1 }
|
||||
session__vote_check(base_st, session_st)
|
||||
}
|
||||
|
||||
# a guest: the host opened vote `id`, or ended it
|
||||
export function ses_vote_told(id: int, kind: int, text: string) -> void {
|
||||
session__vote_id = id
|
||||
session__vote_kind = kind
|
||||
session__vote_text = text
|
||||
session__vote_t = SESSION_VOTE_SECS
|
||||
session__vote_mine = -1
|
||||
export function ses_vote_told(session_st: mut SessionState, id: int, kind: int, text: string) -> void {
|
||||
session_st.session__vote_id = id
|
||||
session_st.session__vote_kind = kind
|
||||
session_st.session__vote_text = text
|
||||
session_st.session__vote_t = SESSION_VOTE_SECS
|
||||
session_st.session__vote_mine = -1
|
||||
}
|
||||
|
||||
export function ses_vote_ended(id: int, passed: bool) -> void {
|
||||
if id != session__vote_id { return }
|
||||
session__vote_t = 0.0
|
||||
if passed { session__vote_passed = 1 } else { session__vote_passed = 0 }
|
||||
export function ses_vote_ended(session_st: mut SessionState, id: int, passed: bool) -> void {
|
||||
if id != session_st.session__vote_id { return }
|
||||
session_st.session__vote_t = 0.0
|
||||
if passed { session_st.session__vote_passed = 1 } else { session_st.session__vote_passed = 0 }
|
||||
}
|
||||
|
||||
# the vote's thirty seconds; on the host, running out decides it
|
||||
export function ses_vote_tick(dt: float) -> void {
|
||||
if not ses_vote_live() { return }
|
||||
session__vote_t = session__vote_t - dt
|
||||
if session__role == SES_HOST and not ses_vote_live() { session__vote_finish() }
|
||||
export function ses_vote_tick(base_st: mut BaseState, session_st: mut SessionState, dt: float) -> void {
|
||||
if not ses_vote_live(session_st) { return }
|
||||
session_st.session__vote_t = session_st.session__vote_t - dt
|
||||
if session_st.session__role == SES_HOST and not ses_vote_live(session_st) { session__vote_finish(base_st, session_st) }
|
||||
}
|
||||
|
||||
function session__vote_check() -> void {
|
||||
let n = ply_count()
|
||||
let yes = session__vote_yes
|
||||
let no = session__vote_no
|
||||
if yes * 2 > n or no * 2 >= n or yes + no >= n { session__vote_finish() }
|
||||
function session__vote_check(base_st: mut BaseState, session_st: mut SessionState) -> void {
|
||||
let n = ply_count(session_st)
|
||||
let yes = session_st.session__vote_yes
|
||||
let no = session_st.session__vote_no
|
||||
if yes * 2 > n or no * 2 >= n or yes + no >= n { session__vote_finish(base_st, session_st) }
|
||||
}
|
||||
|
||||
function session__vote_finish() -> void {
|
||||
let passed = session__vote_yes * 2 > ply_count()
|
||||
session__vote_t = 0.0
|
||||
if passed { session__vote_passed = 1 } else { session__vote_passed = 0 }
|
||||
let f = session__vote_fact(SES_VOTE_RESOLVED)
|
||||
function session__vote_finish(base_st: mut BaseState, session_st: mut SessionState) -> void {
|
||||
let passed = session_st.session__vote_yes * 2 > ply_count(session_st)
|
||||
session_st.session__vote_t = 0.0
|
||||
if passed { session_st.session__vote_passed = 1 } else { session_st.session__vote_passed = 0 }
|
||||
let f = session__vote_fact(base_st, session_st, SES_VOTE_RESOLVED)
|
||||
f.yes = passed
|
||||
}
|
||||
|
||||
function session__vote_fact(what: int) -> SessionFact {
|
||||
let f = session__fact(what, -1, 0)
|
||||
f.id = session__vote_id
|
||||
f.kind = session__vote_kind
|
||||
f.param = session__vote_param
|
||||
f.text = session__vote_text
|
||||
function session__vote_fact(base_st: mut BaseState, session_st: mut SessionState, what: int) -> SessionFact {
|
||||
let f = session__fact(base_st, session_st, what, -1, 0)
|
||||
f.id = session_st.session__vote_id
|
||||
f.kind = session_st.session__vote_kind
|
||||
f.param = session_st.session__vote_param
|
||||
f.text = session_st.session__vote_text
|
||||
return f
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue