refactor(packages): 0.R5 - the shop's week is rolled by its tick and asking reads it; needs start filled and vehicles start with their list; character, physics, vehicles and nativeecho's lazy starts are defaults; --tighten over all four
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67d8079c47
commit
87259f989d
31 changed files with 104 additions and 111 deletions
|
|
@ -35,7 +35,7 @@ function shop_roll_vendor(shop_st: mut ShopState, v: int) -> void {
|
|||
}
|
||||
|
||||
# the week's lists, rolled again only when the week turns
|
||||
function shop_roll(shop_st: mut ShopState) -> void {
|
||||
export function shop_roll(shop_st: mut ShopState) -> void {
|
||||
let week = shop_week(shop_st)
|
||||
if week == shop_st.shop_week_rolled and shop_st.shop_want_list != null { return }
|
||||
shop_st.shop_week_rolled = week
|
||||
|
|
@ -48,24 +48,21 @@ function shop_roll(shop_st: mut ShopState) -> void {
|
|||
for v in 0 .. shop_vendors(shop_st) { shop_roll_vendor(shop_st, v) }
|
||||
}
|
||||
|
||||
export function shop_wants(shop_st: mut ShopState, v: int, it: int) -> bool {
|
||||
if not shop_vendor_ok(shop_st, v) { return false }
|
||||
shop_roll(shop_st)
|
||||
export function shop_wants(shop_st: ShopState, v: int, it: int) -> bool {
|
||||
if not shop_vendor_ok(shop_st, v) or shop_st.shop_want_list == null { return false }
|
||||
for k in 0 .. shop_st.shop_wants_n { if shop_st.shop_want_list[v * shop_st.shop_wants_n + k] == it { return true } }
|
||||
return false
|
||||
}
|
||||
|
||||
export function shop_glutted(shop_st: mut ShopState, v: int, it: int) -> bool {
|
||||
if not shop_vendor_ok(shop_st, v) { return false }
|
||||
shop_roll(shop_st)
|
||||
export function shop_glutted(shop_st: ShopState, v: int, it: int) -> bool {
|
||||
if not shop_vendor_ok(shop_st, v) or shop_st.shop_full_list == null { return false }
|
||||
return shop_st.shop_full_list[v] == it
|
||||
}
|
||||
|
||||
# what a vendor wants this week, in its order
|
||||
export function shop_wanted(shop_st: mut ShopState, v: int) -> []int {
|
||||
export function shop_wanted(shop_st: ShopState, v: int) -> []int {
|
||||
let out = new []int
|
||||
if not shop_vendor_ok(shop_st, v) { return out }
|
||||
shop_roll(shop_st)
|
||||
if not shop_vendor_ok(shop_st, v) or shop_st.shop_want_list == null { return out }
|
||||
for k in 0 .. shop_st.shop_wants_n {
|
||||
let it = shop_st.shop_want_list[v * shop_st.shop_wants_n + k]
|
||||
if it >= 0 { push(out, it) }
|
||||
|
|
@ -74,7 +71,7 @@ export function shop_wanted(shop_st: mut ShopState, v: int) -> []int {
|
|||
}
|
||||
|
||||
# the week's multiplier on what `v` pays for `it` (1 with no vendor)
|
||||
export function shop_demand_mult(shop_st: mut ShopState, v: int, it: int) -> float {
|
||||
export function shop_demand_mult(shop_st: ShopState, v: int, it: int) -> float {
|
||||
if shop_wants(shop_st, v, it) { return shop_st.shop_want_mult }
|
||||
if shop_glutted(shop_st, v, it) { return shop_st.shop_glut_mult }
|
||||
return 1.0
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export function shop_price_buy(shop_st: ShopState, it: int) -> int {
|
|||
|
||||
# what vendor `v` pays (-1: no vendor, no demand). ROUNDED, so cheap raw material keeps its
|
||||
# order; and a vendor that stocks the thing never pays what it charges, not even a floor of $1
|
||||
export function shop_price_sell_at(shop_st: mut ShopState, v: int, it: int) -> int {
|
||||
export function shop_price_sell_at(shop_st: ShopState, v: int, it: int) -> int {
|
||||
if not shop_item_ok(shop_st, it) { return 0 }
|
||||
let f = shop_sell_factor(shop_st) * shop_st.shop_sell_frac[it] * shop_demand_mult(shop_st, v, it)
|
||||
var p = Math.max(int(float(shop_st.shop_base[it]) * f + 0.5), 1)
|
||||
|
|
@ -23,7 +23,7 @@ export function shop_price_sell_at(shop_st: mut ShopState, v: int, it: int) -> i
|
|||
}
|
||||
|
||||
# what the vendor at the counter pays
|
||||
export function shop_price_sell(shop_st: mut ShopState, it: int) -> int { return shop_price_sell_at(shop_st, shop_st.shop_at, it) }
|
||||
export function shop_price_sell(shop_st: ShopState, it: int) -> int { return shop_price_sell_at(shop_st, shop_st.shop_at, it) }
|
||||
|
||||
export function shop_stocks(shop_st: ShopState, v: int, it: int) -> bool {
|
||||
if not shop_vendor_ok(shop_st, v) or shop_st.shop_vendor_list[v].stock == null { return false }
|
||||
|
|
|
|||
|
|
@ -9,5 +9,8 @@ export function shop_reset(shop_st: mut ShopState) -> void {
|
|||
export function shop_system() -> System {
|
||||
let s = system_new("shop", PH_COMMIT)
|
||||
s.reset = fn shop_reset
|
||||
s.tick = fn shop_tick
|
||||
return s
|
||||
}
|
||||
# the week's demand, rolled when the week turns - the questions read it
|
||||
function shop_tick(shop_st: mut ShopState, t: Tick) -> void { shop_roll(shop_st) }
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ program ShopTest {
|
|||
|
||||
test "the week's demand is the shop's own dice, and turns with the week" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
|
||||
fresh(shop_st, shop_test_st)
|
||||
shop_roll(shop_st) # the shop's tick rolls the week; asking only reads it
|
||||
let a = shop_wanted(shop_st, 0)
|
||||
expect(len(a) > 0)
|
||||
for k in 0 .. len(a) { expect(shop_buys(shop_st, 0, a[k])) }
|
||||
|
|
@ -167,6 +168,7 @@ program ShopTest {
|
|||
var moved = false
|
||||
for w in 1 .. 12 {
|
||||
shop_test_st.day = 1 + w * 7
|
||||
shop_roll(shop_st)
|
||||
let b = shop_wanted(shop_st, 0)
|
||||
if len(b) != len(a) or b[0] != a[0] { moved = true }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export function shop_buy(shop_st: ShopState, it: int) -> bool {
|
|||
}
|
||||
|
||||
# `n` to the vendor at the counter (as many as the pack has); how many went
|
||||
export function shop_sell(shop_st: mut ShopState, it: int, n: int) -> int {
|
||||
export function shop_sell(shop_st: ShopState, it: int, n: int) -> int {
|
||||
if not shop_buys(shop_st, shop_st.shop_at, it) { return 0 }
|
||||
let k = Math.min(n, ShopPack.count(it))
|
||||
if k <= 0 { return 0 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue