πŸ—ΊοΈ Dungeon Mechanics β€” Castle of the Winds
_
β–‘
βœ•
← Home Structure Generation Traps Interactive Demo
Interactive Dungeon Generator

A fully interactive, animated reconstruction of CotW's dungeon generation algorithm β€” reverse-engineered directly from the CASTLE1.EXE binary. Watch rooms and corridors appear step by step, adjust parameters, and see the algorithm's behavior in real time.

β–Ά Launch Generator

Each part of Castle of the Winds is built around a single large dungeon divided into named areas of increasing depth. Part I contains the Mine and the Fortress (11 levels total). Part II contains the Village dungeon, the Castle of the Winds itself, and the deep chambers where Surtur waits (25+ levels total).

Every dungeon level is procedurally generated β€” no two runs are alike. The levels connect vertically via staircases. The first level of every dungeon begins just below the overworld town. Characters carry their full inventory and stats between levels; there is no level-specific reset.

πŸ“ Map Data Structure

Discovered via disassembly of seg11. The map is stored at DS:0xCE2 as a flat 64Γ—64 grid, 3 bytes per cell, initialized by a rep stosb clearing 0x3000 bytes:


[+0]Tile type (bit 0 = floor; 0x12 = stairs↓; 0x13 = stairs↑)
[+1]Flags (0x20 = room interior; 0x0C = corridor; 0x40 = door)
[+2]Entity ID occupying the cell

Indexing: bx = row Γ— 192 + col Γ— 3 (seen in assembly as shl row, 6 then Γ—3)

🎲 Room Placement Algorithm

Found at seg11:0x0BCE. For each room attempt:


col = rand(W/3) + rand(W/3) + 1
row = rand(H/3) + rand(H/3) + 1
w = rand(8) + 4
h = rand(8) + 4


The double-rand for position biases rooms toward the map center. Size ranges from 4–11 tiles wide and 4–11 tall. A 1-tile buffer is enforced between all rooms (CanPlaceRoom at 0x164E).

After placing each room, a probabilistic roll determines whether a corridor connects it to the previous room. Corridors are L-shaped: a horizontal segment then a vertical segment, meeting at a corner. The corridor algorithm (seg11:0x1A88) only sets tiles that are currently walls β€” room tiles always take priority and are never overwritten by corridor placement.

Because the initial corridor placement is probabilistic, some rooms may be placed without a corridor to their neighbor. A flood-fill connectivity pass after all rooms are placed identifies isolated components and bridges any room not reachable from room zero (where the down stairs are placed). This guarantees the down stairs and up stairs are always connected through traversable floor.

Doors are placed at room-corridor junctions. They provide no mechanical barrier β€” monsters and the player pass through them freely β€” but they visually delineate room entrances and are tracked in the flags byte (0x40).

ConditionBehavior
All levelsDown stairs (tile 0x12) placed at first room, position [row+1][col+1]
Levels 1–3No up stairs β€” this is intentional level gating for the early game
Level 4+Up stairs (tile 0x13) placed at last room, same offset
Levels 6, 10, 20Branch points in stair logic β€” narrative checkpoints in the dungeon progression

Stair coordinates are stored in the level descriptor table at DS:0x3D90 (36 bytes per level entry). The down stair position is at [bx+0x3D92/93] and the up stair at [bx+0x3D96/97]. These coordinates are used by the Rune of Return spell and by level transition logic to place the player correctly when entering from above or below.

Traps are placed procedurally after the map is generated. They are invisible until revealed by Detect Traps or triggered by walking over them. Levitation makes the player immune to most trap types β€” this is the main reason Boots of Levitation and the Levitation potion are so highly valued.

The Detect Traps spell reveals traps within 10 tiles with certainty, and has a decreasing probability of revealing traps further away. It carries from floor to floor if still active when descending β€” cast it before taking the stairs down.

Trap types include pit traps (fall damage), poison traps, teleport traps, and various others. Some traps can be disarmed manually, providing experience on success. The Create Traps cursed-item spell deliberately places traps adjacent to the caster β€” exploitable with Levitation for experience farming.

Secret doors appear as wall tiles until discovered. They connect hidden rooms containing bonus treasure to the main dungeon. Clairvoyance reveals secret doors within its mapping radius. Detect Objects reveals items through walls but does not reveal the door itself β€” you'll see items floating in "wall" space, indicating a hidden room nearby. The Detect Objects strategy is the primary way experienced players find all treasure before descending.

dungeon.html
64Γ—64 map  Β·  3 bytes/cell  Β·  Procedurally generated  Β·  25 levels