code wiki / _hdl_build / nx_mw_spawn_probe.nx

nx_mw_spawn_probe.nx source

↩ module page · 59 lines · 2191 B

1// nx_mw_spawn_probe.nx -- find a good MineWorld spawn: plains biome, mid height, flat-ish, no trees nearby. 2// Diagnostic only. license_tier: ORIGINAL 3import "nx_syscalls.nx" 4import "nx_f32_hw.nx" 5import "nx_wasm_mineworld.nx" 6 7func shw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 8func spn(v: i64) -> i64 { 9 let b: *u8 = sys_mmap(32) as *u8 10 var x: i64 = v 11 var neg: i64 = 0 12 if x < 0 { neg = 1; x = 0 - x } 13 var i: i64 = 31 14 if x == 0 { b[i] = 48 as u8; i = i - 1 } 15 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 } 16 if neg == 1 { b[i] = 45 as u8; i = i - 1 } 17 sys_write(1, (b as i64 + i + 1) as *u8, 31 - i) 18 return 0 19} 20 21func main() -> i64 { 22 var found: i64 = 0 23 var gz: i64 = 0 - 96 24 while gz <= 96 { 25 var gx: i64 = 0 - 96 26 while gx <= 96 { 27 if found < 12 { 28 let h: i64 = terrain_h0(gx, gz) 29 let bio: i64 = biome_of(gx, gz) 30 if bio == 0 { if h >= 6 { if h <= 10 { 31 var ok: i64 = 1 32 var dz: i64 = 0 - 3 33 while dz <= 3 { 34 var dx: i64 = 0 - 3 35 while dx <= 3 { 36 let nh: i64 = terrain_h0(gx + dx, gz + dz) 37 let nb: i64 = biome_of(gx + dx, gz + dz) 38 if has_tree(gx + dx, gz + dz, nh, nb) == 1 { ok = 0 } 39 var dh: i64 = nh - h 40 if dh < 0 { dh = 0 - dh } 41 if dh > 2 { ok = 0 } 42 if nh <= WWATER { ok = 0 } 43 dx = dx + 1 44 } 45 dz = dz + 1 46 } 47 if ok == 1 { 48 shw("SPAWN gx=" as *u8); spn(gx); shw(" gz=" as *u8); spn(gz); shw(" h=" as *u8); spn(h); shw("\n" as *u8) 49 found = found + 1 50 } 51 } } } 52 } 53 gx = gx + 6 54 } 55 gz = gz + 6 56 } 57 if found == 0 { shw("NO CANDIDATE\n" as *u8) } 58 return 0 59}