nx_tactics_engine_lib.nx
buildroot/runtime/nx_tactics_engine_lib.nx
about
nx_tactics_engine_lib.nx -- the GENERIC data-driven TACTICS SIMULATION engine (G-ECO-005 rung 1):
the SECOND genuine Nishi game engine, structurally distinct from the dungeon-crawler engine.
Generalizes the proven nx_tactics_native (XCOM-style turn-based squad combat) from HARDCODED
constants into a runtime CONFIG array -- exactly as nx_game_engine_lib did for the dungeon.
All per-game variation (squad/enemy counts, grid, hp/damage/moves/range, wall/cover density,
the hit-chance curve, seed) arrives in cfg; the turn loop + cover/hit-chance + enemy AI are the
reusable engine. A generated tactics game (future nx_tactics_emit rung) just fills cfg and calls
teng_init + drives teng_input; render + spec-emitter are the NEXT rungs (this rung = the SIM core).
Built native by Nishi's own toolchain (nx_cc->nxasm_x86, no gcc). HONEST AUTHORSHIP: this engine
library is TUTOR-authored tooling (like nx_game_engine_lib); the GAMES a future emitter writes
from tactics specs are the autonomy lever. license_tier: ORIGINAL
state (i64 at st): 0=turn(0play/1enemy) 1=cur(active player unit) 2=mode(0play/1win/2lose)
3=rng 4=msg 5=moves_left 6=has_shot | units i in 0..NUNITS-1 (team0=0..np-1, team1=np..np+ne-1):
ux=st[16+i] uy=st[22+i] hp=st[28+i] team=st[34+i] alive=st[40+i] (MAXU=6) | CONFIG copied in:
64=grid_w 65=grid_h 66=n_player 67=n_enemy 68=hp0 69=dmg 70=moves0 71=range 72=n_walls
73=n_cover 74=hit_base 75=hit_distdiv 76=cover_penalty | world grid bytes at (st)+2048 (0 floor
1 wall 2 cover), stride grid_w.
dependencies 2 imports · 5 importers
imports: nx_syscalls.nxnx_game_engine_lib.nx
imported by: _tac_laststand.nx_tac_skirmish.nxnx_play_parity.nxnx_tactics_emit.nxnx_tactics_engine_gate.nx
structs
| none |
consts
| 22 | const K_MAGIC_1103515245: i64 = 1103515245 |
| 23 | const K_MAGIC_12345: i64 = 12345 |
| 24 | const K_MAGIC_32767: i64 = 32767 |
| 25 | const K_MAGIC_2048: i64 = 2048 |
| 26 | const K_MAGIC_9999: i64 = 9999 |
| 27 | const K_MAGIC_8192: i64 = 8192 |
| 28 | const K_MAGIC_16384: i64 = 16384 |
functions
| 30 | func teng_nunits(st: *i64) -> i64 |
| 35 | func teng_rng(st: *i64) -> i64 |
| 41 | func teng_cell_get(st: *i64, x: i64, y: i64) -> i64 |
| 49 | func teng_cell_set(st: *i64, x: i64, y: i64, v: i64) -> i64 called by 1: teng_build |
| 54 | func teng_unit_at(st: *i64, x: i64, y: i64) -> i64 |
| 63 | func teng_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } |
| 64 | func teng_dist(ax: i64, ay: i64, bx: i64, by: i64) -> i64 { return teng_abs(ax - bx) + teng_abs(ay - by) } |
| 65 | func teng_team_alive(st: *i64, team: i64) -> i64 |
| 75 | func teng_nearest_foe(st: *i64, x: i64, y: i64, myteam: i64) -> i64 |
| 89 | func teng_first_player(st: *i64) -> i64 |
| 98 | func teng_next_player(st: *i64, from: i64) -> i64 |
| 107 | func teng_place_unit(st: *i64, idx: i64, x0: i64, y0: i64, team: i64) -> i64 |
| 125 | func teng_build(st: *i64) -> i64 |
| 174 | func teng_init(st: *i64, cfg: *i64) -> i64 called by 9: p_grid_blockp_coverp_rangep_enemy_pursuep_winp_lose+3 calls 2: teng_buildteng_first_player |
| 192 | func teng_check_end(st: *i64) -> i64 |
| 197 | func teng_chance(st: *i64, d: i64, cover: i64) -> i64 |
| 204 | func teng_move_unit(st: *i64, ui: i64, dx: i64, dy: i64) -> i64 |
| 214 | func teng_shoot(st: *i64, ui: i64) -> i64 |
| 229 | func teng_enemy_turn(st: *i64) -> i64 called by 2: p_enemy_pursueteng_end_unit calls 8: teng_nunitsteng_nearest_foeteng_absteng_cell_getteng_unit_atteng_dist+2 |
| 278 | func teng_end_unit(st: *i64) -> i64 |
| 290 | func teng_input(st: *i64, key: i64) -> i64 |
| 307 | func teng_draw_cell(buf: *u8, off: *i64, st: *i64, x: i64, y: i64) -> i64 |
| 327 | func teng_render(buf: *u8, st: *i64) -> i64 |
| 361 | func teng_key(c: i64) -> i64 called by 1: teng_run |
| 374 | func teng_run(cfg: *i64) -> i64 |