"""Render top-down PNG inspection maps (`*_nav.png` and `*_cover.png`) from `.preview.bin` + `.pois.json`. Zero external dependencies (Python stdlib `struct` + `zlib` only). """ import argparse import json import math import os import struct import zlib def write_png(path: str, width: int, height: int, rgb: bytearray) -> None: def chunk(tag: bytes, data: bytes) -> bytes: crc = zlib.crc32(tag + data) & 0xFFFFFFFF return struct.pack(">I", len(data)) + tag + data + struct.pack(">I", crc) raw = bytearray() stride = width * 3 for y in range(height): raw.append(0) row = y * stride raw.extend(rgb[row : row + stride]) ihdr = struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0) png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", ihdr) + chunk(b"IDAT", zlib.compress(bytes(raw), 6)) + chunk(b"IEND", b"") os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True) with open(path, "wb") as f: f.write(png) def set_px(rgb: bytearray, w: int, h: int, x: int, y: int, r: int, g: int, b: int) -> None: if 0 <= x < w and 0 <= y < h: idx = (y * w + x) * 3 rgb[idx] = r rgb[idx + 1] = g rgb[idx + 2] = b def draw_line(rgb: bytearray, w: int, h: int, x0: int, y0: int, x1: int, y1: int, col, thick: int = 1) -> None: dx = abs(x1 - x0) dy = abs(y1 - y0) sx = 1 if x0 < x1 else -1 sy = 1 if y0 < y1 else -1 err = dx - dy r, g, b = col while True: for oy in range(-thick // 2, thick // 2 + 1): for ox in range(-thick // 2, thick // 2 + 1): set_px(rgb, w, h, x0 + ox, y0 + oy, r, g, b) if x0 == x1 and y0 == y1: break e2 = 2 * err if e2 > -dy: err -= dy x0 += sx if e2 < dx: err += dx y0 += sy def draw_circle(rgb: bytearray, w: int, h: int, cx: int, cy: int, rad: int, col, fill: bool = False) -> None: r, g, b = col r2 = rad * rad for dy in range(-rad, rad + 1): for dx in range(-rad, rad + 1): d2 = dx * dx + dy * dy if fill and d2 <= r2: set_px(rgb, w, h, cx + dx, cy + dy, r, g, b) elif not fill and abs(d2 - r2) <= max(2, rad * 2): set_px(rgb, w, h, cx + dx, cy + dy, r, g, b) def draw_square(rgb: bytearray, w: int, h: int, cx: int, cy: int, half: int, col) -> None: r, g, b = col for dy in range(-half, half + 1): for dx in range(-half, half + 1): set_px(rgb, w, h, cx + dx, cy + dy, r, g, b) def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--preview", required=True) ap.add_argument("--pois", required=True) ap.add_argument("--out-dir", required=True) ap.add_argument("--name", required=True) args = ap.parse_args() with open(args.preview, "rb") as f: data = f.read() with open(args.pois, "r", encoding="utf-8") as f: pois = json.load(f) assert data[:8] == b"WTOPREV1", "bad preview magic" off = 8 pw, ph, min_x, min_z, max_x, max_z, water_y = struct.unpack_from(" 0 and tac_rows > 0 else 0 if fl & 16: cr, cg, cb = 20, 48, 95 elif fl & 2: cr = min(255, int(base * 0.85 + exp_v * 0.18)) cg = min(255, int(base * 0.90 + 20)) cb = min(255, int(base * 0.85)) else: cr, cg, cb = 26, 26, 30 cov_rgb[idx] = cr cov_rgb[idx + 1] = cg cov_rgb[idx + 2] = cb # Overlay sample Detour paths (bright cyan) on nav map for path in paths: for i in range(len(path) - 1): x0, y0 = world_to_px(*path[i]) x1, y1 = world_to_px(*path[i + 1]) draw_line(nav_rgb, pw, ph, x0, y0, x1, y1, (0, 245, 255), thick=2) # Overlay spawns & capture zones on BOTH maps for rgb in (nav_rgb, cov_rgb): for sp in pois.get("team1Spawns", []): x, y = world_to_px(sp["x"], sp["z"]) draw_square(rgb, pw, ph, x, y, 5, (40, 130, 255)) draw_square(rgb, pw, ph, x, y, 2, (255, 255, 255)) for sp in pois.get("team2Spawns", []): x, y = world_to_px(sp["x"], sp["z"]) draw_square(rgb, pw, ph, x, y, 5, (255, 65, 65)) draw_square(rgb, pw, ph, x, y, 2, (255, 255, 255)) for cap in pois.get("captureZones", []): x, y = world_to_px(cap["x"], cap["z"]) rad_px = max(8, int(cap.get("radius", 25.0) / max(1.0, max_x - min_x) * pw)) draw_circle(rgb, pw, ph, x, y, rad_px, (255, 215, 0), fill=False) draw_circle(rgb, pw, ph, x, y, 4, (255, 230, 40), fill=True) # Overlay covers on cover map: Blue=FULL, Green=HULLDOWN, Yellow=PEEK for c in covers: px_w, py_w, pz_w = c[0], c[1], c[2] dx, dz = c[3], c[4] peek_l = (c[7], c[9]) peek_r = (c[10], c[12]) kind = c[16] has_pl, has_pr = c[17], c[18] x, y = world_to_px(px_w, pz_w) col = (60, 165, 255) if kind == 1 else (55, 240, 100) draw_circle(cov_rgb, pw, ph, x, y, 2, col, fill=True) # Direction tick pointing toward blocked threat x2, y2 = world_to_px(px_w + dx * 8.0, pz_w + dz * 8.0) draw_line(cov_rgb, pw, ph, x, y, x2, y2, col, thick=1) if has_pl: lx, ly = world_to_px(*peek_l) draw_circle(cov_rgb, pw, ph, lx, ly, 1, (255, 240, 60), fill=True) if has_pr: rx2, ry2 = world_to_px(*peek_r) draw_circle(cov_rgb, pw, ph, rx2, ry2, 1, (255, 240, 60), fill=True) nav_out = os.path.join(args.out_dir, f"{args.name}_nav.png") cov_out = os.path.join(args.out_dir, f"{args.name}_cover.png") write_png(nav_out, pw, ph, nav_rgb) write_png(cov_out, pw, ph, cov_rgb) print(f"Rendered {nav_out} and {cov_out} (covers={len(covers)}, paths={len(paths)})") if __name__ == "__main__": main()