feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune
ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v), q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)). ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no longer uses, nor anything it calls, and the argument that fills it - including an argument for a parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8cf4b3fed6
commit
71735b10a2
151 changed files with 58668 additions and 54719 deletions
|
|
@ -4,14 +4,14 @@ export function gear_can_buy(gear_st: mut GearState, k: int) -> bool {
|
|||
return GearPurse.rep() >= gear_next_rep(gear_st, k) and GearPurse.money() >= gear_next_cost(gear_st, k)
|
||||
}
|
||||
|
||||
export function gear_buy(base_st: mut BaseState, gear_st: mut GearState, k: int) -> bool {
|
||||
export function gear_buy(gear_st: mut GearState, k: int) -> bool {
|
||||
if not gear_can_buy(gear_st, k) { return false }
|
||||
let cost = gear_next_cost(gear_st, k)
|
||||
if not GearPurse.spend(cost) { return false }
|
||||
gear_st.gear__lv[k] += 1
|
||||
let it = GearKinds[k].item
|
||||
if it >= 0 and GearPack.count(it) == 0 { GearPack.add(it, 1) }
|
||||
gear__fact(base_st, gear_st, GEAR_BOUGHT, k, -1, cost)
|
||||
gear__fact(gear_st, GEAR_BOUGHT, k, -1, cost)
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ 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(base_st: mut BaseState, gear_st: mut GearState, hours: float) -> void {
|
||||
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 }
|
||||
|
|
@ -67,6 +67,6 @@ function gear__burn(base_st: mut BaseState, gear_st: mut GearState, hours: float
|
|||
if gear_st.gear__left[c] > 0.0 { continue }
|
||||
gear_st.gear__left[c] = 0.0
|
||||
gear_st.gear__on[c] = false
|
||||
gear__fact(base_st, gear_st, GEAR_RAN_OUT, -1, c, 0)
|
||||
gear__fact(gear_st, GEAR_RAN_OUT, -1, c, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ function gear__ensure(gear_st: mut GearState) -> void {
|
|||
}
|
||||
}
|
||||
|
||||
export function gear_facts(base_st: mut BaseState, gear_st: mut GearState) -> Queue<GearFact> {
|
||||
if gear_st.gear__q == null { gear_st.gear__q = queue_new(base_st, "gear.facts") }
|
||||
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(base_st: mut BaseState, gear_st: mut GearState, what: int, k: int, c: int, cost: int) -> void {
|
||||
function gear__fact(gear_st: mut GearState, what: int, k: int, c: int, cost: int) -> void {
|
||||
let f = new GearFact
|
||||
f.what = what
|
||||
f.cost = cost
|
||||
|
|
@ -35,5 +35,5 @@ function gear__fact(base_st: mut BaseState, gear_st: mut GearState, what: int, k
|
|||
f.item = GearKinds[k].item
|
||||
}
|
||||
if c >= 0 { f.item = GearCharges[c].item }
|
||||
q_push(base_st, gear_facts(base_st, gear_st), f)
|
||||
q_push(gear_facts(gear_st), f)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +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(base_st: mut BaseState, gear_st: mut GearState) -> void {
|
||||
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 {
|
||||
|
|
@ -8,7 +8,7 @@ export function gear_reset(base_st: mut BaseState, gear_st: mut GearState) -> vo
|
|||
gear_st.gear__on[c] = false
|
||||
}
|
||||
gear_st.gear__hand = -1
|
||||
q_clear(base_st, gear_facts(base_st, gear_st))
|
||||
q_clear(gear_facts(gear_st))
|
||||
}
|
||||
|
||||
export function gear_save(gear_st: mut GearState) -> Val {
|
||||
|
|
@ -24,8 +24,8 @@ export function gear_save(gear_st: mut GearState) -> Val {
|
|||
}
|
||||
|
||||
# a kind the file does not name starts where a new trip does; then what the pack carries counts
|
||||
export function gear_load(base_st: mut BaseState, gear_st: mut GearState, v: Val, version: int) -> void {
|
||||
gear_reset(base_st, gear_st)
|
||||
export function gear_load(gear_st: mut GearState, v: Val, version: int) -> void {
|
||||
gear_reset(gear_st)
|
||||
if Value.has(v, "levels") != 0 {
|
||||
let lv = Value.get(v, "levels")
|
||||
for k in 0 .. GEAR_COUNT { gear_st.gear__lv[k] = sv_int(lv, GearKinds[k].key, GearKinds[k].start) }
|
||||
|
|
@ -37,7 +37,7 @@ export function gear_load(base_st: mut BaseState, gear_st: mut GearState, v: Val
|
|||
gear_sync(gear_st)
|
||||
}
|
||||
|
||||
function gear__tick(base_st: mut BaseState, gear_st: mut GearState, t: Tick) -> void { gear__burn(base_st, gear_st, t.hours) }
|
||||
function gear__tick(gear_st: mut GearState, t: Tick) -> void { gear__burn(gear_st, t.hours) }
|
||||
|
||||
export function gear_system() -> System {
|
||||
let s = system_new("gear", PH_SIMULATE)
|
||||
|
|
|
|||
|
|
@ -42,64 +42,64 @@ program GearTest {
|
|||
bind GearPack { count: fn pack_count, add: fn pack_add }
|
||||
bind GearWorld { hidden: fn hidden }
|
||||
|
||||
function fresh(base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) -> void {
|
||||
function fresh(gear_st: mut GearState, gear_test_st: mut GearTestState) -> void {
|
||||
gear_test_st.money = 0
|
||||
gear_test_st.rep = 0
|
||||
gear_test_st.hide_pack = false
|
||||
gear_test_st.pack = new []int
|
||||
for i in 0 .. 12 { push(gear_test_st.pack, 0) }
|
||||
gear_reset(base_st, gear_st)
|
||||
gear_reset(gear_st)
|
||||
}
|
||||
|
||||
function ran_out(base_st: mut BaseState, gear_st: mut GearState) -> int {
|
||||
let fs = q_drain(base_st, gear_facts(base_st, gear_st))
|
||||
function ran_out(gear_st: mut 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 } }
|
||||
return n
|
||||
}
|
||||
|
||||
test "a new trip starts where the kinds say" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
test "a new trip starts where the kinds say" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
expect_eq(gear_level(gear_st, GEAR_ROD), 0)
|
||||
expect_eq(gear_level(gear_st, GEAR_CAMERA), 1)
|
||||
expect(gear_next_name(gear_st, GEAR_CAMERA) == "Zoom")
|
||||
expect_eq(gear_next_cost(gear_st, GEAR_ROD), 30)
|
||||
}
|
||||
|
||||
test "bought with money once the standing is there, and the item follows" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
expect(not gear_buy(base_st, gear_st, GEAR_ROD))
|
||||
test "bought with money once the standing is there, and the item follows" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
expect(not gear_buy(gear_st, GEAR_ROD))
|
||||
gear_test_st.money = 200
|
||||
expect(gear_buy(base_st, gear_st, GEAR_ROD))
|
||||
expect(gear_buy(gear_st, GEAR_ROD))
|
||||
expect_eq(gear_test_st.money, 170)
|
||||
expect_eq(gear_test_st.pack[IT_ROD], 1)
|
||||
expect(not gear_can_buy(gear_st, GEAR_ROD))
|
||||
gear_test_st.rep = 10
|
||||
expect(gear_buy(base_st, gear_st, GEAR_ROD))
|
||||
expect(gear_buy(gear_st, GEAR_ROD))
|
||||
expect_eq(gear_test_st.pack[IT_ROD], 1)
|
||||
let fs = q_drain(base_st, gear_facts(base_st, gear_st))
|
||||
let fs = q_drain(gear_facts(gear_st))
|
||||
expect_eq(len(fs), 2)
|
||||
expect_eq(fs[1].what, GEAR_BOUGHT)
|
||||
expect_eq(fs[1].level, 2)
|
||||
expect_eq(fs[1].cost, 100)
|
||||
}
|
||||
|
||||
test "the best tier is the end, and a hidden kind is not for sale" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
test "the best tier is the end, and a hidden kind is not for sale" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
gear_test_st.money = 1000
|
||||
gear_test_st.rep = 50
|
||||
for i in 0 .. 5 { gear_buy(base_st, gear_st, GEAR_PACK) }
|
||||
for i in 0 .. 5 { gear_buy(gear_st, GEAR_PACK) }
|
||||
expect(gear_best(gear_st, GEAR_PACK))
|
||||
expect_eq(gear_level(gear_st, GEAR_PACK), 3)
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
fresh(gear_st, gear_test_st)
|
||||
gear_test_st.money = 100
|
||||
gear_test_st.hide_pack = true
|
||||
expect(not gear_buy(base_st, gear_st, GEAR_PACK))
|
||||
expect(not gear_buy(gear_st, GEAR_PACK))
|
||||
expect_eq(len(gear_kinds_at(-1)), 2)
|
||||
}
|
||||
|
||||
test "a tier decides a value and a mult, and the stack's room follows" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
test "a tier decides a value and a mult, and the stack's room follows" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
expect_eq(gear_value(gear_st, GV_BITE), 1.0)
|
||||
gear_set_level(gear_st, GEAR_ROD, 3)
|
||||
expect_eq(gear_value(gear_st, GV_BITE), 0.55)
|
||||
|
|
@ -112,15 +112,15 @@ program GearTest {
|
|||
expect_eq(gear_mult(gear_st, GEAR_ROD), 1.0)
|
||||
}
|
||||
|
||||
test "a carried item counts as the first tier" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
test "a carried item counts as the first tier" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
gear_test_st.pack[IT_ROD] = 1
|
||||
gear_sync(gear_st)
|
||||
expect_eq(gear_level(gear_st, GEAR_ROD), 1)
|
||||
}
|
||||
|
||||
test "a held charge runs only in the hand, burns by the hour and runs out" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
test "a held charge runs only in the hand, burns by the hour and runs out" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
let t = CHARGE_TORCH
|
||||
expect(not gear_run(gear_st, t, true))
|
||||
gear_set_hand(gear_st, IT_TORCH)
|
||||
|
|
@ -131,12 +131,12 @@ program GearTest {
|
|||
gear_system().tick(tick_new(0.1, 2, 0.6))
|
||||
expect_eq(gear_charge(gear_st, t), 0.0)
|
||||
expect(not gear_lit(gear_st))
|
||||
expect_eq(ran_out(base_st, gear_st), t)
|
||||
expect_eq(ran_out(gear_st), t)
|
||||
expect(not gear_run(gear_st, t, true))
|
||||
}
|
||||
|
||||
test "a charge's rate can be its tier's, and a new hand puts the light out" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
test "a charge's rate can be its tier's, and a new hand puts the light out" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
gear_set_hand(gear_st, IT_LAMP)
|
||||
gear_run(gear_st, CHARGE_LAMP, true)
|
||||
gear_system().tick(tick_new(0.1, 1, 1.0))
|
||||
|
|
@ -150,13 +150,13 @@ program GearTest {
|
|||
expect(gear_running(gear_st, CHARGE_RADIO))
|
||||
}
|
||||
|
||||
test "levels and charges are saved by key" (base_st: mut BaseState, gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
test "levels and charges are saved by key" (gear_st: mut GearState, gear_test_st: mut GearTestState) {
|
||||
fresh(gear_st, gear_test_st)
|
||||
gear_set_level(gear_st, GEAR_ROD, 2)
|
||||
gear_charge_set(gear_st, CHARGE_TORCH, 12.5)
|
||||
let v = gear_save(gear_st)
|
||||
fresh(base_st, gear_st, gear_test_st)
|
||||
gear_load(base_st, gear_st, v, 1)
|
||||
fresh(gear_st, gear_test_st)
|
||||
gear_load(gear_st, v, 1)
|
||||
expect_eq(gear_level(gear_st, GEAR_ROD), 2)
|
||||
expect_eq(gear_level(gear_st, GEAR_CAMERA), 1)
|
||||
expect_eq(gear_charge(gear_st, CHARGE_TORCH), 12.5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue