ludic/examples/chronorift/rules.ludic
Orkuncakilkaya b7745a4600 refactor(lang): rename the str type (and stringify builtin) to string
Expand the abbreviated string type and its conversion builtin to the full
word everywhere:
  str            ->  string        (the immutable-string type)
  str(x) -> str  ->  string(x) -> string   (the stringify builtin;
                                            what `{…}` interpolation calls)

Types are recognized by identifier, and llty maps both spellings to LLVM
`ptr`, so this is an atomic source rewrite: type annotations, the Ludic
type tags, the builtin name/dispatch, and the interpolation desugar, plus
the grammars, LSP, docs (type-str -> type-string, fn-str -> fn-string), and
inventory. int/bool stay (universally accepted, like Math).

Reseeded; C-free fixpoint holds; all suites green (45/24/29); site + check.py OK.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 01:51:11 +03:00

86 lines
3.2 KiB
Text

# rules.ludic — pure game rules & map data (functions only, no systems).
function tile_sprite(c: int) -> int {
match c {
'T', '#' => return SPR_TREE
'H' => return SPR_HOUSE
'D' => return SPR_DOOR
'r', 'h' => return SPR_PATH
',', 'S', 'B' => return SPR_FLOOR
'=' => return SPR_WALL
}
return SPR_GRASS
}
function walkable(x: int, y: int) -> bool {
let c = Map.tile(x, y)
return c == '.' or c == 'D' or c == 'r' or c == ',' or c == 'S' or c == 'B' or c == 'h'
}
function is_confirm(k: int) -> bool { return k == 32 or k == 10 or k == 13 }
function enemy_name(et: int) -> string {
if et == 0 { return "SLIME" }
if et == 1 { return "SKELETON" }
return "RIFT WARDEN"
}
function build_field(x: int) -> int {
Map.size(40, 18)
Map.row(0, "########################################")
Map.row(1, "#......................................#")
Map.row(2, "#...TT.........................TT.....D#")
Map.row(3, "#..TT.......................TT.........#")
Map.row(4, "#..T.........................T.........#")
Map.row(5, "#....................................T.#")
Map.row(6, "#.....TT....................TT.......T.#")
Map.row(7, "#....TT.....................T..........#")
Map.row(8, "#...........rrrrrrrr........HH.........#")
Map.row(9, "#..........r........r.......HH.........#")
Map.row(10, "#......TT...r........rrrrrrrrhr......T.#")
Map.row(11, "#.....TT...r.................r.......T.#")
Map.row(12, "#..........r.......TT.......r..........#")
Map.row(13, "#..........rrrrrrrrrrrrrrrrr.........T.#")
Map.row(14, "#.........TT.........................T.#")
Map.row(15, "#........TT..........................T.#")
Map.row(16, "#....................................T.#")
Map.row(17, "########################################")
return 0
}
function build_dungeon(x: int) -> int {
Map.size(40, 18)
Map.row(0, "========================================")
Map.row(1, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(2, "=,S,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(3, "=,,,,,====,,,,,,,,,,,,,,,====,,,,,,,,,,=")
Map.row(4, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(5, "=,,,,,,,,,,,,,====,,,,,,,,,,,,,,,,,,,,,=")
Map.row(6, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,====,,,,,=")
Map.row(7, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(8, "=,,,====,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(9, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(10, "=,,,,,,,,,,,,,,,,,,====,,,,,,,,,,,,,,,,=")
Map.row(11, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(12, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,====,,,,,,,=")
Map.row(13, "=,,,,,,,,,====,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(14, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(15, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,B,,=")
Map.row(16, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(17, "========================================")
return 0
}
function grant_xp(amount: int) -> int {
for (t) in query [Stats, {Party}] {
if t.hp > 0 {
t.xp = t.xp + amount
while t.xp >= t.lvl * 20 {
t.xp = t.xp - t.lvl * 20
t.lvl = t.lvl + 1
t.maxhp = t.maxhp + 8
t.hp = t.maxhp
t.maxmp = t.maxmp + 2
t.atk = t.atk + 2
t.def = t.def + 1
}
}
}
return 0
}