code wiki / _hdl_build / nx_m2d_engine.nx
nx_m2d_engine.nx
buildroot/runtime/_hdl_build/nx_m2d_engine.nx
about
nx_m2d_engine.nx -- M2D "NISHI GLADE": the first TIER-1 game of the approved program plan
(2026-07-26, plans/temporal-meandering-moore.md rung 1) -- a top-down action-adventure in the
Steam-volume-floor class, COMPOSED ENTIRELY FROM CERTIFIED PARTS, zero re-authored game systems:
nx_worldpipe the staged six-parameter overworld (biomes/heights/surface colours)
nx_procgen the dungeon maze (pg_maze, flood-verified connectivity)
nx_pathfind enemy chase (pf_astar on the live maze grid)
nx_creature_battle combat resolution (typed moves, cb_damage/cb_best)
nx_rpgstats xp curve + derived hp (order-independent, saturating)
nx_loottable kill drops (weighted tiers, 0-dup law)
nx_wardrobe_state the adult invariant, FAIL-CLOSED BY CONSTRUCTION (age<18 refuse)
nx_input_abstract every policy drives the loop through SEMANTIC ACTIONS (device-independent)
nx_gamesave bit-exact mid-run save/load (transparency proof)
nx_game_raster the rendered frame; scored by
nx_game_critic the hardened visual critic (anti-noise, coherence-capped)
PROOF BATTERY (the M1/frontier standard -- a battery that cannot pass a hollow game):
P1 WINNABLE the cautious policy grinds, heals, then takes the warden -> WIN
P2 LOSABLE the reckless policy rushes the warden under-levelled -> DIES (real stakes)
P3 DETERMINISTIC two P1 replays produce bit-identical frame chains
P4 SAVE-TRANSPARENT save mid-run, load, continue -> same final chain as the unbroken run
P5 ADULT-GATE HOLDS the spring event tries to expose a gated zone: adult proceeds, a minor is
REFUSED with state bit-identical -- the invariant holds THROUGH the whole game loop
P6 DEPTH the two policies genuinely diverge (win vs death) AND each replays identically --
outcome differences are STRATEGY, not luck (the hardened nx_game_depth principle)
P7 QUALITY the rendered frame clears the critic's TOY line; score published, never inflated.
Emits its frame as knowledge/nx_m2d_frame.nxfh (the ecosystem's text-hex format) so nx_frame_score
can re-grade it over MCP -- the same instrument that grades the reference titles.
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
dependencies 13 imports · 0 importers
diagram shows first 10 each side; +3 more imports, +0 more importers in the complete lists below.
imports: nx_syscalls.nxnx_worldpipe.nxnx_procgen.nxnx_pathfind.nxnx_creature_battle.nxnx_rpgstats.nxnx_loottable.nxnx_wardrobe_state.nxnx_input_abstract_part.nxnx_gamesave.nxnx_game_raster.nxnx_game_critic.nxnx_game_engine_lib.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 41 | const MD_MAGIC_65536: i64 = 65536 |
| 42 | const MD_MAGIC_4096: i64 = 4096 |
| 45 | const MD_DW: i64 = 15 // dungeon maze width (odd, pg_maze contract) |
| 46 | const MD_DH: i64 = 9 |
| 47 | const MD_SEED: i64 = 20260726 |
| 48 | const MD_WSCALE: i64 = 280 // world units per overworld tile fed to wp_* |
| 50 | const MD_XP_BASE: i64 = 50 |
| 51 | const MD_XP_QUAD: i64 = 30 |
| 52 | const MD_CON: i64 = 10 |
| 53 | const MD_HPB: i64 = 20 |
| 54 | const MD_HPCON: i64 = 2 |
| 55 | const MD_HPLVL: i64 = 6 |
| 57 | const MD_F_PX: i64 = 0 |
| 58 | const MD_F_PY: i64 = 1 |
| 59 | const MD_F_HP: i64 = 2 |
| 60 | const MD_F_XP: i64 = 3 |
| 61 | const MD_F_POT: i64 = 4 // potions held |
| 62 | const MD_F_SHARD: i64 = 5 // key shards (3 open the warden door) |
| 63 | const MD_F_KILLS: i64 = 6 |
| 64 | const MD_F_TICK: i64 = 7 |
| 65 | const MD_F_CK: i64 = 8 // rolling frame chain |
| 66 | const MD_F_OVER: i64 = 9 // 0 running, 1 WIN, 2 DEAD |
| 67 | const MD_O_WARD: i64 = 10 // wardrobe vector [10..20) (WS_LEN=10) |
| 68 | const MD_O_ENHP: i64 = 20 // enemy hp x4 (3 lurkers + warden) [20..24) |
| 69 | const MD_O_ENX: i64 = 24 // enemy x x4 |
| 70 | const MD_O_ENY: i64 = 28 // enemy y x4 |
| 71 | const MD_NSV: i64 = 32 |
| 72 | const MD_SCHEMA: i64 = 2026 |
| 73 | const MD_SAVEAT: i64 = 1785100000 |
| 74 | const MD_CKM: i64 = 4611686018427387903 |
| 75 | const MD_TRBUF: i64 = 8192 |
| 76 | const MD_TRTICKS: i64 = 16 |
| 77 | const MD_PTYPE: i64 = 3 // player is GRASS: counters the Water warden (eff 4 out, 1 in) -- chart-read, not guessed |
| 78 | const MD_TICKS: i64 = 96 |
| 79 | const MD_HEAL_AT: i64 = 40 // measured: entering the Fire-lurker fight at 32hp was lethal; heal FIRST |
| 80 | const MD_SNARE_B: i64 = 4 // the den snare: (MD_SNARE_B - level) * MD_SNARE_L opening damage, floor 0. |
| 81 | const MD_SNARE_L: i64 = 18 // measured: chase-intercept XP let a rusher shrug the old snare; level 4 = earned |
| 82 | const MD_CK_PRIME: i64 = 16777619 |
| 83 | const MD_CK_SEED: i64 = 2166136261 |
| 84 | const MD_FAR: i64 = 1000000 // a LEVEL CHECK as a game rule -- rushing under-levelled is fatal by design |
functions
| 86 | func md_mix(ck: i64, v: i64) -> i64 {
called by 1: md_fold |
| 94 | func md_fold(s: *i64) -> i64 { |
| 102 | func md_level(s: *i64) -> i64 { return rs_level_for_xp(s[MD_F_XP], MD_XP_BASE, MD_XP_QUAD) } |
| 103 | func md_maxhp(s: *i64) -> i64 { return rs_derived_hp(MD_CON, md_level(s), MD_HPB, MD_HPCON, MD_HPLVL) } |
| 106 | func md_mkfoe(c: *i64, idx: i64, lvl: i64) -> i64 { |
| 120 | func md_battle(s: *i64, foe: i64, brng: *i64) -> i64 { |
| 166 | func md_step(s: *i64, grid: *i64, act: i64, brng: *i64) -> i64 { |
| 227 | func md_init(s: *i64, grid: *i64, age: i64) -> i64 { |
| 263 | func md_target(s: *i64, policy: i64) -> i64 {
called by 1: md_run |
| 280 | func md_run(s: *i64, grid: *i64, policy: i64, age: i64) -> i64 { |
| 323 | func md_render(s: *i64, grid: *i64, fb: *i64, W: i64, H: i64) -> i64 { |
| 373 | func ocat(o: *u8, at: i64, s: *u8) -> i64 { var i: i64=0; var a: i64=at; while s[i]!=(0 as u8){o[a]=s[i]; a=a+1; i=i+1} return a }
called by 1: main |
| 374 | func onum(o: *u8, at: i64, v: i64) -> i64 { |
| 384 | func hexd(v: i64) -> i64 { if v < 10 { return 48+v } return 87+v }
called by 1: main |
| 392 | func md_ansi_frame(s: *i64, grid: *i64, ob: *u8, off: *i64, plain: i64) -> i64 { |
| 437 | func md_key_raw(ch: i64) -> i64 {
called by 1: md_play |
| 445 | func md_play(grid: *i64, script: *u8) -> i64 { |
| 494 | func main(argc: i64, argv: *i64) -> i64 { |