# Implementation Plan - Phase 1: Dungeon Generation ## Goal Description Build a robust, data-driven procedural dungeon generator that supports campaign-specific requirements (custom exits vs. objective rooms). This logic will be decoupled from the 3D visualization to ensure testability. ## Architecture The engine will consist of three main components: 1. **Tile Registry**: Definitions of all available board sections (Rooms, Corridors, T-Junctions, Corners). 2. **Dungeon Deck**: A deck manager that handles the probability of drawing specific room types. 3. **Generator Core**: The state machine that places tiles on a virtual grid. ## User Review Required > [!IMPORTANT] > **Campaign Logic Deviation**: The rulebook specifies random dungeons. We are implementing a constrained "Mission" system where: > * Current functionality must support "Forced Exits" after X tiles for early campaign missions. > * Final missions revert to standard "Objective Room" search. ## Proposed Changes ### [NEW] `src/engine/dungeon/` We will structure the engine purely in JS logic first. #### [NEW] `TileDefinitions.js` - **Data Structure**: ```javascript { id: 'corridor_straight', type: 'corridor', // 'room', 'objective' width: 2, length: 5, exits: [ {x:0, y:0, dir:'N'}, ... ] // Local coords } ``` #### [NEW] `DungeonDeck.js` - Handles the stack of cards. - Methods: `draw()`, `shuffle()`, `insert(card, position)`. - **Campaign Injection**: Ability to inject specific "Events" or "Rooms" at certain deck depths (e.g., "After 10 cards, shuffle the Exit card into the top 3"). #### [NEW] `Generator.js` - **Grid System**: A virtual 2D array or Map `Map<"x,y", TileID>` to track occupancy. - **Algorithm**: 1. Place Entry Room at (0,0). 2. Add Entry Exits to `OpenExitsList`. 3. **Step**: - Pick an Exit from `OpenExitsList`. - Draw Card from `DungeonDeck`. - Attempt to place Tile at Exit. - **IF Collision**: Discard and try alternative (or end path). - **IF Success**: Register Tile, Remove used Exit, Add new Exits. ### Campaign Integration - **Mission Config Payload**: ```javascript { missionId: "campaign_1_mission_1", deckComposition: [ ... ], specialRules: { forceExitAfter: 10, // Logic: Treat specific room as 'Objective' for generation purposes exitType: "ladder_room" } } ``` ## Verification Plan ### Automated Tests - **Unit Tests**: Verify `Generator` can place tiles without overlapping. - **Logic Tests**: Verify "Exit functionality" triggers correctly after N tiles.