# DISPATCH: Explorer M4 1 (Fog of War Multi-State Engine & Persistence)

## Assigned Agent
- Name: `explorer_m4_1`
- Type: `teamwork_preview_explorer`
- Working Directory: `c:\Projects\FreeExile\.agents\teamwork\explorer_m4_1`

## Mandatory Reference Documents
1. `c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md` (specifically section `## 2026-10-01T19:19:13Z` - R4)
2. `c:\Projects\FreeExile\GEMINI.md`
3. `c:\Projects\FreeExile\AGENTS.md`
4. `c:\Projects\FreeExile\.agents\teamwork\orchestrator_11\PROJECT.md`
5. `client/webapp/js/ui/war_fog.js` (existing implementation if any)

## Exploration Scope & Instructions
Investigate Fog of War multi-state core engine and persistence:
1. Examine `client/webapp/js/ui/war_fog.js`:
   - 3-State Fog Model:
     - `0 = UNEXPLORED` (shrouded in pitch darkness)
     - `1 = EXPLORED_FOGGED` (terrain previously discovered, dimly visible, monsters hidden)
     - `2 = VISIBLE` (currently inside player vision radius)
   - Dynamic vision reveal:
     - Vision radius: 8 tiles around player.
     - Formulate vision update logic: previous `VISIBLE` (2) tiles decay to `EXPLORED_FOGGED` (1); new tiles within radius become `VISIBLE` (2).
     - Performance: Avoid allocating arrays in `updatePlayerVision(wx, wy)`.
   - `localStorage` persistence:
     - Key format: `fe_fog_${zoneId}_${seed}`.
     - Bit-packing: Pack explored bits (1 bit/tile or byte run-length) so saving/loading is instantaneous and compact (< 2 KB for $120 \times 90$ grid).
     - Auto-save on zone exit / debounced timer.
2. Code constraints:
   - `client/webapp/js/ui/war_fog.js` must remain $\le 300$ lines (Soft cap 350, Hard cap 500 lines).
   - Clean ES Module with Node.js require compatibility.
3. Deliver a detailed technical report in `report.md` and self-contained `handoff.md`.
Notify parent when complete.

## 2026-10-01T21:24:35Z
You are Explorer M4 1 (explorer_m4_1).
Your working directory is: c:\Projects\FreeExile\.agents\teamwork\explorer_m4_1
Your dispatch assignment is: c:\Projects\FreeExile\.agents\teamwork\explorer_m4_1\DISPATCH.md
MANDATORY: Read the authoritative user request at:
c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md (specifically section ## 2026-10-01T19:19:13Z - R4).
Also consult c:\Projects\FreeExile\GEMINI.md, c:\Projects\FreeExile\AGENTS.md, and c:\Projects\FreeExile\.agents\teamwork\orchestrator_11\PROJECT.md.

Investigate Fog of War multi-state core engine and persistence:
1. Examine client/webapp/js/ui/war_fog.js:
   - 3-state model: 0=UNEXPLORED, 1=EXPLORED_FOGGED, 2=VISIBLE.
   - Dynamic vision reveal with radius 8 tiles around player with zero-heap decay/update.
   - localStorage persistence keyed by fe_fog_${zoneId}_${seed} with compact bit-packing (< 2 KB for 120x90).
2. Ensure war_fog.js stays <= 300 lines (Soft cap 350, Hard cap 500 lines).

Write report.md and handoff.md in your working directory and notify parent when complete.
