refactor(packages): 0.R5 - a question no longer starts its state - 64 lazy starts ('if st.x == null { st.x = ... }' inside a getter) are the state's defaults, gear__ensure is gone, and ludic migrate state --tighten took mut off 208 package parameters: things_all, thing_find, gear_charge, gear_level, jobs_state and the rest read
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
54f5efb23f
commit
9862ec82e3
102 changed files with 320 additions and 351 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# buy.ludic - a tier bought with money once the standing is there; the kind's item follows
|
||||
export function gear_can_buy(gear_st: mut GearState, k: int) -> bool {
|
||||
export function gear_can_buy(gear_st: GearState, k: int) -> bool {
|
||||
if not gear_ok(k) or gear_best(gear_st, k) or GearWorld.hidden(k) { return false }
|
||||
return GearPurse.rep() >= gear_next_rep(gear_st, k) and GearPurse.money() >= gear_next_cost(gear_st, k)
|
||||
}
|
||||
|
|
@ -17,7 +17,6 @@ export function gear_buy(gear_st: mut GearState, k: int) -> bool {
|
|||
|
||||
# a kind whose item is already carried counts as its first tier
|
||||
export function gear_sync(gear_st: mut GearState) -> void {
|
||||
gear__ensure(gear_st)
|
||||
for k in 0 .. GEAR_COUNT {
|
||||
let it = GearKinds[k].item
|
||||
if it >= 0 and gear_st.gear__lv[k] == 0 and GearPack.count(it) > 0 { gear_st.gear__lv[k] = 1 }
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ export function gear_hand(gear_st: GearState) -> int { return gear_st.gear__hand
|
|||
|
||||
# a new thing in the hand (-1 empty): whatever the old one was running goes out
|
||||
export function gear_set_hand(gear_st: mut GearState, it: int) -> void {
|
||||
gear__ensure(gear_st)
|
||||
gear_st.gear__hand = it
|
||||
for c in 0 .. CHARGE_COUNT { if GearCharges[c].hand { gear_st.gear__on[c] = false } }
|
||||
}
|
||||
|
|
@ -15,26 +14,22 @@ export function gear_charge_of(it: int) -> int {
|
|||
return -1
|
||||
}
|
||||
|
||||
export function gear_charge(gear_st: mut GearState, c: int) -> float {
|
||||
gear__ensure(gear_st)
|
||||
export function gear_charge(gear_st: GearState, c: int) -> float {
|
||||
return gear_st.gear__left[c]
|
||||
}
|
||||
|
||||
export function gear_charge_set(gear_st: mut GearState, c: int, v: float) -> void {
|
||||
gear__ensure(gear_st)
|
||||
gear_st.gear__left[c] = Math.clamp(v, 0.0, GearCharges[c].full)
|
||||
}
|
||||
|
||||
export function gear_charge_fill(gear_st: mut GearState, c: int) -> void { gear_charge_set(gear_st, c, GearCharges[c].full) }
|
||||
|
||||
export function gear_running(gear_st: mut GearState, c: int) -> bool {
|
||||
gear__ensure(gear_st)
|
||||
export function gear_running(gear_st: GearState, c: int) -> bool {
|
||||
return gear_st.gear__on[c]
|
||||
}
|
||||
|
||||
# on or off; false when it has nothing left, or is held and not in the hand
|
||||
export function gear_run(gear_st: mut GearState, c: int, on: bool) -> bool {
|
||||
gear__ensure(gear_st)
|
||||
if not on {
|
||||
gear_st.gear__on[c] = false
|
||||
return true
|
||||
|
|
@ -46,13 +41,13 @@ export function gear_run(gear_st: mut GearState, c: int, on: bool) -> bool {
|
|||
}
|
||||
|
||||
# the hand's own charge is running (a torch lit, a flashlight on)
|
||||
export function gear_lit(gear_st: mut GearState) -> bool {
|
||||
export function gear_lit(gear_st: GearState) -> bool {
|
||||
if gear_st.gear__hand < 0 { return false }
|
||||
let c = gear_charge_of(gear_st.gear__hand)
|
||||
return c >= 0 and GearCharges[c].hand and gear_running(gear_st, c)
|
||||
}
|
||||
|
||||
function gear__rate(gear_st: mut GearState, c: int) -> float {
|
||||
function gear__rate(gear_st: GearState, c: int) -> float {
|
||||
let d = GearCharges[c]
|
||||
if d.rate >= 0 { return gear_value(gear_st, d.rate) }
|
||||
return d.per_hour
|
||||
|
|
@ -60,7 +55,6 @@ function gear__rate(gear_st: mut GearState, c: int) -> float {
|
|||
|
||||
# the game hours of a tick burn every running charge; one that runs out stops and says so
|
||||
function gear__burn(gear_st: mut GearState, hours: float) -> void {
|
||||
gear__ensure(gear_st)
|
||||
for c in 0 .. CHARGE_COUNT {
|
||||
if not gear_st.gear__on[c] { continue }
|
||||
gear_st.gear__left[c] = gear_st.gear__left[c] - hours * gear__rate(gear_st, c)
|
||||
|
|
|
|||
|
|
@ -1,30 +1,32 @@
|
|||
# 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 = null
|
||||
gear__lv: []int = gear__starts()
|
||||
gear__hand: int = -1
|
||||
gear__left: []float = null
|
||||
gear__on: []bool = null
|
||||
gear__q: Queue<GearFact> = null
|
||||
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
|
||||
}
|
||||
|
||||
function gear__ensure(gear_st: mut GearState) -> void {
|
||||
if gear_st.gear__lv != null { return }
|
||||
gear_st.gear__lv = new []int
|
||||
for k in 0 .. GEAR_COUNT { push(gear_st.gear__lv, GearKinds[k].start) }
|
||||
gear_st.gear__left = new []float
|
||||
gear_st.gear__on = new []bool
|
||||
for c in 0 .. CHARGE_COUNT {
|
||||
push(gear_st.gear__left, GearCharges[c].full)
|
||||
push(gear_st.gear__on, false)
|
||||
}
|
||||
}
|
||||
export function gear_facts(gear_st: GearState) -> Queue<GearFact> { return gear_st.gear__q }
|
||||
|
||||
export function gear_facts(gear_st: mut GearState) -> Queue<GearFact> {
|
||||
if gear_st.gear__q == null { gear_st.gear__q = queue_new("gear.facts") }
|
||||
return gear_st.gear__q
|
||||
}
|
||||
|
||||
function gear__fact(gear_st: mut GearState, what: int, k: int, c: int, cost: int) -> void {
|
||||
function gear__fact(gear_st: GearState, what: int, k: int, c: int, cost: int) -> void {
|
||||
let f = new GearFact
|
||||
f.what = what
|
||||
f.cost = cost
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
# system.ludic - gear as a system: the burn each tick, and the levels and charges saved by key (the
|
||||
# hand is not saved: a trip opens with empty hands)
|
||||
export function gear_reset(gear_st: mut GearState) -> void {
|
||||
gear__ensure(gear_st)
|
||||
for k in 0 .. GEAR_COUNT { gear_st.gear__lv[k] = GearKinds[k].start }
|
||||
for c in 0 .. CHARGE_COUNT {
|
||||
gear_st.gear__left[c] = GearCharges[c].full
|
||||
|
|
@ -11,8 +10,7 @@ export function gear_reset(gear_st: mut GearState) -> void {
|
|||
q_clear(gear_facts(gear_st))
|
||||
}
|
||||
|
||||
export function gear_save(gear_st: mut GearState) -> Val {
|
||||
gear__ensure(gear_st)
|
||||
export function gear_save(gear_st: GearState) -> Val {
|
||||
let v = Value.object()
|
||||
let lv = Value.object()
|
||||
for k in 0 .. GEAR_COUNT { sv_put_int(lv, GearKinds[k].key, gear_st.gear__lv[k]) }
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ program GearTest {
|
|||
gear_reset(gear_st)
|
||||
}
|
||||
|
||||
function ran_out(gear_st: mut GearState) -> int {
|
||||
function ran_out(gear_st: GearState) -> int {
|
||||
let fs = q_drain(gear_facts(gear_st))
|
||||
var n = -1
|
||||
for i in 0 .. len(fs) { if fs[i].what == GEAR_RAN_OUT { n = fs[i].charge } }
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
# tiers.ludic - what is owned and what a tier is worth
|
||||
export function gear_ok(k: int) -> bool { return k >= 0 and k < GEAR_COUNT }
|
||||
|
||||
export function gear_level(gear_st: mut GearState, k: int) -> int {
|
||||
gear__ensure(gear_st)
|
||||
export function gear_level(gear_st: GearState, k: int) -> int {
|
||||
return gear_st.gear__lv[k]
|
||||
}
|
||||
|
||||
# outright: staging, a test, a camera handed over with the trip
|
||||
export function gear_set_level(gear_st: mut GearState, k: int, lv: int) -> void {
|
||||
gear__ensure(gear_st)
|
||||
gear_st.gear__lv[k] = lv
|
||||
}
|
||||
|
||||
export function gear_owned(gear_st: mut GearState, k: int) -> bool { return gear_level(gear_st, k) > 0 }
|
||||
export function gear_owned(gear_st: GearState, k: int) -> bool { return gear_level(gear_st, k) > 0 }
|
||||
|
||||
export function gear_best(gear_st: mut GearState, k: int) -> bool { return gear_level(gear_st, k) >= GearKinds[k].tiers }
|
||||
export function gear_best(gear_st: GearState, k: int) -> bool { return gear_level(gear_st, k) >= GearKinds[k].tiers }
|
||||
|
||||
# a tier's name, "" for none
|
||||
export function gear_level_name(k: int, lv: int) -> string {
|
||||
|
|
@ -23,14 +21,14 @@ export function gear_level_name(k: int, lv: int) -> string {
|
|||
}
|
||||
|
||||
# the tier on offer next: its name, cost and the standing it wants
|
||||
export function gear_next_name(gear_st: mut GearState, k: int) -> string { return gear_level_name(k, gear_level(gear_st, k) + 1) }
|
||||
export function gear_next_name(gear_st: GearState, k: int) -> string { return gear_level_name(k, gear_level(gear_st, k) + 1) }
|
||||
|
||||
export function gear_next_cost(gear_st: mut GearState, k: int) -> int {
|
||||
export function gear_next_cost(gear_st: GearState, k: int) -> int {
|
||||
if gear_best(gear_st, k) { return 0 }
|
||||
return GearKinds[k].cost[gear_level(gear_st, k)]
|
||||
}
|
||||
|
||||
export function gear_next_rep(gear_st: mut GearState, k: int) -> int {
|
||||
export function gear_next_rep(gear_st: GearState, k: int) -> int {
|
||||
if gear_best(gear_st, k) { return 0 }
|
||||
return GearKinds[k].rep[gear_level(gear_st, k)]
|
||||
}
|
||||
|
|
@ -43,10 +41,10 @@ function gear__pick(xs: []float, lv: int, fallback: float) -> float {
|
|||
}
|
||||
|
||||
# the kind's own number at its level (1.0 when it has none)
|
||||
export function gear_mult(gear_st: mut GearState, k: int) -> float { return gear__pick(GearKinds[k].mult, gear_level(gear_st, k), 1.0) }
|
||||
export function gear_mult(gear_st: GearState, k: int) -> float { return gear__pick(GearKinds[k].mult, gear_level(gear_st, k), 1.0) }
|
||||
|
||||
# a value its kind's tier decides
|
||||
export function gear_value(gear_st: mut GearState, v: int) -> float {
|
||||
export function gear_value(gear_st: GearState, v: int) -> float {
|
||||
let d = GearValues[v]
|
||||
return gear__pick(d.at, gear_level(gear_st, d.gear), 0.0)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue