Fog of war: unexplored darkness until the dungeon's ground, creatures or towers come close

- explored tiles stay known (saved compactly as bits), enemies are only drawn while in sight; sight runs along open ground, walls block it
- unexplored tiles are black blocks; units, towers, torches, furniture, portals, gate and rival cores in the dark are hidden; minimap and tile info too
- the nearest portal is known from the start; the seer's eye opens a wide area for 20 seconds without remembering it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Opus 5.5 committed 2026-11-04 07:18:55 +01:00
1 parent 7f4d5ca7b4
commit 240e89d9cb
11 files changed
+244 -17

No files matched your search

+7 -3
View File
@@ -290,6 +290,10 @@ pub struct Map {
pub gate: (i32, i32),
#[serde(default)]
pub treasures: Vec<(i32, i32)>, // centres of the treasure caves
#[serde(default, with = "crate::fog::bits")]
pub explored: Vec<bool>, // fog of war: tiles the dungeon knows (empty: no fog)
#[serde(skip)]
pub visible: Vec<bool>, // fog of war: tiles in sight right now
}
fn default_size() -> usize {
@@ -527,7 +531,7 @@ impl Map {
tl.hp = 6.0;
}
}
Map { w, h, t, core, portals, legacy_portal: None, gate, treasures }
Map { w, h, t, core, portals, legacy_portal: None, gate, treasures, explored: Vec::new(), visible: Vec::new() }
}
// Carves a meandering river; the player's area, the core and portals stay dry.
@@ -712,7 +716,7 @@ impl Map {
const B64: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
fn b64_encode(data: &[u8]) -> String {
pub fn b64_encode(data: &[u8]) -> String {
let mut out = String::with_capacity(data.len() * 4 / 3 + 4);
for chunk in data.chunks(3) {
let b = [chunk[0], *chunk.get(1).unwrap_or(&0), *chunk.get(2).unwrap_or(&0)];
@@ -728,7 +732,7 @@ fn b64_encode(data: &[u8]) -> String {
out
}
fn b64_decode(s: &str) -> Option<Vec<u8>> {
pub fn b64_decode(s: &str) -> Option<Vec<u8>> {
let mut val = [255u8; 256];
for (i, &c) in B64.iter().enumerate() {
val[c as usize] = i as u8;