feat(packages): ludic.shop - prices by standing with the fountain guard, a weekly demand on its own dice, stock, buying and selling through purse and pack ports, a trade fact
Items (base price, sell fraction) and vendors (stock, buys, refuses) are the game's data handed over at boot; standing, the day, a shortage and "buys beyond its list" are the ShopWorld port; money is ShopPurse and the pack ShopPack. The week's wanted and glutted items come from an Rng seeded by the week, never the world's. The balance invariants - a shop is not a fountain, friction falls and never inverts, raw keeps its order - are the package's tests (nine). ludic.crafting: its private names carry the package's prefix too (a private name is still one global namespace with the game's - ludic.shop's `sp_seed` met the game's). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cc9cec922a
commit
12cfcb10ac
12 changed files with 663 additions and 28 deletions
|
|
@ -1,42 +1,42 @@
|
|||
# hold.ludic - a recipe made by holding a button for its `hold` seconds: letting go wastes
|
||||
# nothing, and it stops by itself the moment it can no longer be made
|
||||
var cr_hold: int = -1
|
||||
var cr_hold_t: float = 0.0
|
||||
var craft_hold_i: int = -1
|
||||
var craft_hold_t: float = 0.0
|
||||
|
||||
export function craft_holds(i: int) -> bool { return craft_ok(i) and CraftRecipes[i].hold > 0.0 }
|
||||
|
||||
# the recipe being held, or -1
|
||||
export function craft_holding() -> int { return cr_hold }
|
||||
export function craft_holding() -> int { return craft_hold_i }
|
||||
|
||||
# starts holding one that is made by holding and can be made now
|
||||
export function craft_hold_start(i: int) -> bool {
|
||||
if not craft_holds(i) or not craft_can(i) { return false }
|
||||
cr_hold = i
|
||||
cr_hold_t = 0.0
|
||||
craft_hold_i = i
|
||||
craft_hold_t = 0.0
|
||||
return true
|
||||
}
|
||||
|
||||
export function craft_hold_stop() -> void {
|
||||
cr_hold = -1
|
||||
cr_hold_t = 0.0
|
||||
craft_hold_i = -1
|
||||
craft_hold_t = 0.0
|
||||
}
|
||||
|
||||
# how far through the hold on `i` is, 0 to 1
|
||||
export function craft_hold_frac(i: int) -> float {
|
||||
if cr_hold != i or not craft_holds(i) { return 0.0 }
|
||||
return Math.clamp(cr_hold_t / CraftRecipes[i].hold, 0.0, 1.0)
|
||||
if craft_hold_i != i or not craft_holds(i) { return 0.0 }
|
||||
return Math.clamp(craft_hold_t / CraftRecipes[i].hold, 0.0, 1.0)
|
||||
}
|
||||
|
||||
# `dt` real seconds of holding; true on the frame it is made
|
||||
export function craft_hold_run(dt: float) -> bool {
|
||||
if cr_hold < 0 { return false }
|
||||
if not craft_can(cr_hold) {
|
||||
if craft_hold_i < 0 { return false }
|
||||
if not craft_can(craft_hold_i) {
|
||||
craft_hold_stop()
|
||||
return false
|
||||
}
|
||||
cr_hold_t = cr_hold_t + dt
|
||||
if cr_hold_t <= CraftRecipes[cr_hold].hold { return false }
|
||||
let i = cr_hold
|
||||
craft_hold_t = craft_hold_t + dt
|
||||
if craft_hold_t <= CraftRecipes[craft_hold_i].hold { return false }
|
||||
let i = craft_hold_i
|
||||
craft_hold_stop()
|
||||
return craft_make(i)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ export port CraftPack {
|
|||
count: fn(int) -> int
|
||||
take: fn(int, int) -> bool
|
||||
add: fn(int, int) -> int
|
||||
room: fn(int) -> int = fn cr_no_limit
|
||||
leaves: fn(int) -> int = fn cr_leaves_nothing
|
||||
room: fn(int) -> int = fn craft_no_limit
|
||||
leaves: fn(int) -> int = fn craft_leaves_nothing
|
||||
}
|
||||
function cr_no_limit(it: int) -> int { return 2147483647 }
|
||||
function cr_leaves_nothing(it: int) -> int { return -1 }
|
||||
function craft_no_limit(it: int) -> int { return 2147483647 }
|
||||
function craft_leaves_nothing(it: int) -> int { return -1 }
|
||||
|
||||
# the stations. Unbound, there are none: only the hands are ready, and nothing can be started.
|
||||
# `start(station, recipe)` puts a timed recipe in; false gives the makings back.
|
||||
export port CraftStations {
|
||||
ready: fn(int) -> bool = fn cr_hands_only
|
||||
start: fn(int, int) -> bool = fn cr_no_start
|
||||
ready: fn(int) -> bool = fn craft_hands_only
|
||||
start: fn(int, int) -> bool = fn craft_no_start
|
||||
}
|
||||
function cr_hands_only(station: int) -> bool { return station == CRAFT_HANDS }
|
||||
function cr_no_start(station: int, recipe: int) -> bool { return false }
|
||||
function craft_hands_only(station: int) -> bool { return station == CRAFT_HANDS }
|
||||
function craft_no_start(station: int, recipe: int) -> bool { return false }
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
# verbs.ludic - can it be made, taking and giving back its makings, and making it
|
||||
var cr_facts: Queue<Crafted> = null
|
||||
var craft_fact_q: Queue<Crafted> = null
|
||||
|
||||
export function craft_facts() -> Queue<Crafted> {
|
||||
if cr_facts == null { cr_facts = queue_new("crafting.crafted") }
|
||||
return cr_facts
|
||||
if craft_fact_q == null { craft_fact_q = queue_new("crafting.crafted") }
|
||||
return craft_fact_q
|
||||
}
|
||||
|
||||
# every making is in the pack
|
||||
|
|
@ -46,7 +46,7 @@ export function craft_refund(i: int) -> void {
|
|||
}
|
||||
}
|
||||
|
||||
function cr_fact(i: int, queued: bool) -> void {
|
||||
function craft_fact_push(i: int, queued: bool) -> void {
|
||||
let r = CraftRecipes[i]
|
||||
let c = new Crafted
|
||||
c.recipe = i
|
||||
|
|
@ -68,10 +68,10 @@ export function craft_make(i: int) -> bool {
|
|||
craft_refund(i)
|
||||
return false
|
||||
}
|
||||
cr_fact(i, true)
|
||||
craft_fact_push(i, true)
|
||||
return true
|
||||
}
|
||||
CraftPack.add(r.out, r.n)
|
||||
cr_fact(i, false)
|
||||
craft_fact_push(i, false)
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue