ludic/packages/ludic.photo/worth.ludic
Orkuncakilkaya 71735b10a2 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>
2026-09-26 04:19:56 +03:00

38 lines
1.4 KiB
Text

# worth.ludic - what a buyer pays for a frame: the first frame of each subject and every legend,
# on the grade's curve and the lens's worth; sold is sold
export function photo_value(photo_st: PhotoState, i: int) -> int {
if i < 0 or i >= photo_st.pht_n or photo_st.pht_sold[i] != 0 { return 0 }
var v = 0
for sp in 0 .. 32 {
if (photo_st.pht_mask[i] & (1 << sp)) == 0 { continue }
var first = true
for k in 0 .. photo_st.pht_n { if k != i and photo_st.pht_sold[k] != 0 and (photo_st.pht_mask[k] & (1 << sp)) != 0 { first = false } }
if first { v += PhotoRules.subject_value(sp) }
if (photo_st.pht_legend[i] & (1 << sp)) != 0 { v += PhotoRules.legend_value(sp) }
}
if v > 0 { v = int(float(v) * (PhotoRules.mult() * photo_grade_mult(photo_st.pht_grade[i]))) }
return v
}
# every frame with a price, sold: the total, and a fact a frame
export function photo_sell_all(photo_st: mut PhotoState) -> int {
var total = 0
for i in 0 .. photo_st.pht_n {
let v = photo_value(photo_st, i)
if v > 0 {
total += v
photo_st.pht_sold[i] = 1
let f = pht_fact(photo_st, PHOTO_SOLD, i)
f.v = v
f.mask = photo_st.pht_mask[i]
}
}
return total
}
# what the roll would fetch now
export function photo_worth(photo_st: PhotoState) -> int {
var total = 0
for i in 0 .. photo_st.pht_n { total += photo_value(photo_st, i) }
return total
}