refactor(packages): 0.R5 - the rest of the lazy starts are defaults - hints' rail (sized by hints_config), lab's CRC table, rpg's crafting / items / inventory / quests / dialog, shooter's weapons, prefs, and npc's and gameplay's empty ensures gone; gameplay's faction table sits beside its state, since a default names only what is declared before it; --tighten over their tests and examples

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 03:07:29 +03:00
parent 9e4f4edb92
commit f516148e46
15 changed files with 73 additions and 169 deletions

View file

@ -10,20 +10,12 @@ const CRAFT_MAX: int = 128
const CRAFT_ING_MAX: int = 512
function craft_ensure(rpg_st: mut RpgState) -> void {
if rpg_st.recipe_reg == null {
rpg_st.recipe_reg = Dict.new()
rpg_st.recipe_out = pointers(CRAFT_MAX); rpg_st.recipe_outqty = words(CRAFT_MAX)
rpg_st.ing_rid = words(CRAFT_ING_MAX); rpg_st.ing_name = pointers(CRAFT_ING_MAX); rpg_st.ing_qty = words(CRAFT_ING_MAX)
}
}
event cancellable CraftRequested { e: int = 0, recipe: int = 0 }
event CraftCompleted { e: int = 0, recipe: int = 0 }
# Craft.recipe(name, out_item, out_qty) — declare a recipe; returns its id.
@Namespace(Craft) function craft_recipe(rpg_st: mut RpgState, name: pointer, out_item: pointer, out_qty: int) -> int {
craft_ensure(rpg_st)
if rpg_st.recipe_n >= CRAFT_MAX { return -1 }
let id = rpg_st.recipe_n
rpg_st.recipe_out[id] = out_item; rpg_st.recipe_outqty[id] = out_qty
@ -31,10 +23,9 @@ event CraftCompleted { e: int = 0, recipe: int = 0 }
Dict.set(rpg_st.recipe_reg, name, id)
return id
}
@Namespace(Craft) function craft_id(rpg_st: mut RpgState, name: pointer) -> int { craft_ensure(rpg_st); return Dict.get_or(rpg_st.recipe_reg, name, -1) }
@Namespace(Craft) function craft_id(rpg_st: mut RpgState, name: pointer) -> int { return Dict.get_or(rpg_st.recipe_reg, name, -1) }
# Craft.ingredient(recipe_name, item, qty) — add an ingredient requirement.
@Namespace(Craft) function craft_ingredient(rpg_st: mut RpgState, recipe_name: pointer, item: pointer, qty: int) -> void {
craft_ensure(rpg_st)
let rid = craft_id(rpg_st, recipe_name)
if rid < 0 { return }
if rpg_st.ing_n >= CRAFT_ING_MAX { return }
@ -44,7 +35,6 @@ event CraftCompleted { e: int = 0, recipe: int = 0 }
# Craft.can(e, recipe_name) — does the owner hold every ingredient?
@Namespace(Craft) function craft_can(rpg_st: mut RpgState, e: int, recipe_name: pointer) -> int {
craft_ensure(rpg_st)
let rid = craft_id(rpg_st, recipe_name)
if rid < 0 { return 0 }
var i = 0
@ -59,7 +49,6 @@ event CraftCompleted { e: int = 0, recipe: int = 0 }
# Craft.make(e, recipe_name) — consume ingredients + produce output; 1 on success.
@Namespace(Craft) function craft_make(rpg_st: mut RpgState, e: int, recipe_name: pointer) -> int {
craft_ensure(rpg_st)
let rid = craft_id(rpg_st, recipe_name)
if rid < 0 { return 0 }
if craft_can(rpg_st, e, recipe_name) == 0 { return 0 }