# explored.ludic - walking reveals the cells round you; "explored" is the share of the core's LAND # that has been seen, since open water has nothing on it to miss # every cell any part of which is within r of (x, z) export function minimap_reveal(minimap_st: mut MinimapState, x: float, z: float, r: float) -> void { mm_grid(minimap_st) let c = minimap_cell(minimap_st, x, z) let reach = int(r / minimap_st.mm_cell_m) + 1 let x0 = minimap_grid_x0(minimap_st) let z0 = minimap_grid_z0(minimap_st) let ci = int(Math.floor((x - x0) / minimap_st.mm_cell_m)) let cj = int(Math.floor((z - z0) / minimap_st.mm_cell_m)) for j in cj - reach .. cj + reach + 1 { for i in ci - reach .. ci + reach + 1 { if i < 0 or j < 0 or i >= minimap_st.mm_cells or j >= minimap_st.mm_cells { continue } let nx = Math.clamp(x, x0 + float(i) * minimap_st.mm_cell_m, x0 + float(i + 1) * minimap_st.mm_cell_m) let nz = Math.clamp(z, z0 + float(j) * minimap_st.mm_cell_m, z0 + float(j + 1) * minimap_st.mm_cell_m) if (nx - x) * (nx - x) + (nz - z) * (nz - z) <= r * r { minimap_reveal_cell(minimap_st, j * minimap_st.mm_cells + i) } } } if c >= 0 { minimap_reveal_cell(minimap_st, c) } } export function minimap_reveal_cell(minimap_st: mut MinimapState, c: int) -> void { mm_grid(minimap_st) if c < 0 or c >= minimap_st.mm_cells * minimap_st.mm_cells or minimap_st.mm_seen[c] != 0 { return } minimap_st.mm_seen[c] = 1 minimap_st.mm_version += 1 } export function minimap_seen(minimap_st: MinimapState, c: int) -> bool { if minimap_st.mm_seen == null or c < 0 or c >= minimap_st.mm_cells * minimap_st.mm_cells { return false } return minimap_st.mm_seen[c] != 0 } export function minimap_seen_at(minimap_st: MinimapState, x: float, z: float) -> bool { return minimap_seen(minimap_st, minimap_cell(minimap_st, x, z)) } export function minimap_seen_count(minimap_st: MinimapState) -> int { var n = 0 if minimap_st.mm_seen == null { return 0 } for c in 0 .. len(minimap_st.mm_seen) { if minimap_st.mm_seen[c] != 0 { n += 1 } } return n } # goes up whenever what has been seen changes: a picture of the fog is baked again when it does export function minimap_version(minimap_st: MinimapState) -> int { return minimap_st.mm_version } export function minimap_explored_pct(minimap_st: mut MinimapState) -> int { mm_land_count(minimap_st) var n = 0 for j in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n { for i in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n { if minimap_seen(minimap_st, j * minimap_st.mm_cells + i) and mm_land(minimap_st, i, j) { n += 1 } } } return Math.min(n * 100 / minimap_st.mm_land_n, 100) } function mm_land(minimap_st: MinimapState, i: int, j: int) -> bool { return MinimapWorld.land(minimap_cell_x(minimap_st, i), minimap_cell_z(minimap_st, j)) } function mm_land_count(minimap_st: mut MinimapState) -> void { let ox = MinimapWorld.origin_x() let oz = MinimapWorld.origin_z() if minimap_st.mm_land_n > 0 and ox == minimap_st.mm_land_ox and oz == minimap_st.mm_land_oz { return } minimap_st.mm_land_ox = ox minimap_st.mm_land_oz = oz minimap_st.mm_land_n = 0 for j in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n { for i in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n { if mm_land(minimap_st, i, j) { minimap_st.mm_land_n += 1 } } } minimap_st.mm_land_n = Math.max(minimap_st.mm_land_n, 1) } # the ground under the grid is not what it was (a new world): count its land again export function minimap_land_changed(minimap_st: mut MinimapState) -> void { minimap_st.mm_land_n = 0 } # the grid as one string of 0 / 1, row by row, and back (a shorter string leaves the rest unseen) @alloc_ok("on a save: the explored grid written out") export function minimap_seen_text(minimap_st: mut MinimapState) -> string { mm_grid(minimap_st) var s = "" for j in 0 .. minimap_st.mm_cells { var row = "" for i in 0 .. minimap_st.mm_cells { if minimap_st.mm_seen[j * minimap_st.mm_cells + i] != 0 { row = row + "1" } else { row = row + "0" } } s = s + row } return s } export function minimap_seen_from_text(minimap_st: mut MinimapState, s: string) -> void { mm_grid(minimap_st) let n = len(s) for c in 0 .. minimap_st.mm_cells * minimap_st.mm_cells { minimap_st.mm_seen[c] = 0 if c < n and s[c] == 49 { minimap_st.mm_seen[c] = 1 } } minimap_st.mm_version += 1 }