refactor(runtime,packages,examples): named constants, package enums, idiom sweep

- runtime: HEADLESS_FRAME_PATH, STICK_DEADZONE / STICK_LEFT_X/Y, key and
  byte codes as char literals throughout (`k == 'w'`, `fill(rt_map, ' ', …)`)
- ludic.gameplay/stats: drop the duplicate `stat_field` (it answered "atk"
  for every build stat); Stats.base uses stats_field_name
- ludic.shooter: compare aim modes and fire patterns with AimMode.* and
  WeaponPattern.* instead of raw ints; STICK_RIGHT_X/Y
- ludic.npcai: DecisionMade / brain_set_state use AiState.*
- examples/games/menu.ludic uses Font.load / Ui.* with FONT_PATH and
  BACKDROP named; strings.ludic header says what it prints
- whole tree: `x = x + 1` → `x += 1` (single-term right-hand sides only),
  `0 - x` → `-x`, ASCII codes → char literals; every .ludic and every
  ```ludic fence reformatted with the fixed formatter (whitespace only)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-05 01:12:26 +03:00
parent e3e1bc7784
commit bf36bc8a8f
103 changed files with 1256 additions and 1252 deletions

View file

@ -53,7 +53,7 @@ var combat_pending: int = 0
# the attacker's build: damage_pct, then a crit_pct chance to double
var raw = amount * stats_field(src, "damage_pct", 100) / 100
let crit = stats_field(src, "crit_pct", 0)
if (crit > 0) and Random.chance(percent: crit) { raw = raw * 2; emit Crit(target: target, src: src) }
if (crit > 0) and Random.chance(percent: crit) { raw *= 2; emit Crit(target: target, src: src) }
combat_pending = combat_mitigate(target, raw)
if emit DamageAboutToApply(target: target, src: src, amount: combat_pending) != 0 { return 0 }
var dmg = combat_pending

View file

@ -55,10 +55,10 @@ function fac_ensure() -> void {
# Faction.id_of(e) — the faction id an entity carries (-1 if it has no Faction).
@Namespace(Faction) function faction_id_of(e: int) -> int {
let P = World.prop_id("Faction")
if P < 0 { return 0 - 1 }
if World.has(e, P) == 0 { return 0 - 1 }
if P < 0 { return -1 }
if World.has(e, P) == 0 { return -1 }
let f = World.field_id(P, "id")
if f < 0 { return 0 - 1 }
if f < 0 { return -1 }
return World.get(e, P, f)
}

View file

@ -89,21 +89,11 @@ model ModifierFx { Modifier }
}
}
# map a stat code to the matching Stats field name.
function stat_field(stat: int) -> pointer {
if stat == 0 { return "max_hp" }
if stat == 1 { return "atk" }
if stat == 2 { return "def" }
if stat == 3 { return "spd" }
if stat == 4 { return "max_mp" }
return "atk"
}
# Stats.base(e, stat) — the raw stored field, no modifiers.
@Namespace(Stats) function stats_base(e: int, stat: int) -> int {
let P = World.prop_id("Stats")
if P < 0 { return 0 }
let f = World.field_id(P, stat_field(stat))
let f = World.field_id(P, stats_field_name(stat))
if f < 0 { return 0 }
return World.get(e, P, f)
}
@ -123,7 +113,7 @@ function stat_field(stat: int) -> pointer {
while m >= 0 {
if (World.get(m, P, ft) == e) and (World.get(m, P, fs) == stat) {
let amt = World.get(m, P, fa)
if World.get(m, P, fo) == 1 { pct = pct + amt } else { flat = flat + amt }
if World.get(m, P, fo) == 1 { pct += amt } else { flat += amt }
}
m = World.query_next(P, m + 1)
}
@ -133,7 +123,7 @@ function stat_field(stat: int) -> pointer {
# Stats.modify(target, stat, op, amount, ttl) — push a modifier onto the stack.
@Namespace(Stats) function stats_modify(target: int, stat: int, op: int, amount: int, ttl: int) -> int {
let m = World.model_id("ModifierFx")
if m < 0 { return 0 - 1 }
if m < 0 { return -1 }
let e = World.spawn(m)
let P = World.prop_id("Modifier")
World.set(e, P, World.field_id(P, "target"), target)