Skip to main content

Level maps (MAZ)

File formats · Field reference · Schema

In brief​

A MAZ file is the wall plan of a dungeon level: a grid of 32 × 32 cells, and for each cell four numbers, one per side, that say which wall stands there. A number is only a reference: the graphics of a wall, whether monsters or projectiles can pass and any special action it has come from the level's INF file, whose wall mappings fill per-level tables indexed by these numbers.

The DOS game has 15 MAZ files, LEVEL1.MAZ to LEVEL15.MAZ. INF files name the map they use, and the numbers do not always match: LEVEL6.INF uses level5.maz, and LEVEL14.INF uses level12.maz. Which level uses which file.

From the file LEVELn.MAZ to the game. The file holds, in order: Header (6 bytes); Cells (1,024 × 4 bytes). The game: Read 6 + 4,096 bytes; Copy the cells into the block table, unless the level has a record. In memory: The wall references of the 1,024 blocks. Used by: Moving, The view, Doors and scripts.
The game turns it into the wall references of the 1,024 blocks.

Organization​

Reading the header as width, height and cell size is inferred.

PartSizeContents
Header6 bytesThree 16-bit numbers: 32, 32 and 4 in every file.
Cells4096 bytes1024 records of four wall references, in row order.

Record i is the cell in column i mod 32, row i div 32; the game's distance calculation uses the same split.1 Below, a cell is written [XX:YY] for column XX and row YY, so record i is cell [XX:YY] with i = YY × 32 + XX.

Row 00 is the northern edge of the level and column 00 its western edge. The four bytes of a record are the cell's faces turned north, east, south and west, in that order (Direction).2

Reading the file​

The game reads a level's map each time it loads the level, from the name that the level's INF file gives. The game's loader reads exactly these 6 + 4096 bytes and copies the 1024 records in order into its block table, so a grid of another size would not fit it. It never checks the header: the six bytes are read into the first block of the table, where the copy of the cells overwrites the first two numbers and the third one stays as that block's state (an anomaly). Nor does it check how many bytes the reads return: with a shorter file, the missing cells would come from what the read buffer last held, on a level load the level's compressed INF file (inferred).3 The first two numbers are overwritten before anything reads them, so nothing in the game depends on them or on the order of width and height: the game always reads a 32 × 32 grid. Only the third number has an effect, as that block's state.

On a level change, the game can keep the current level's state in LEVELS.TMP. If the level being loaded has such a record, the map loader restores the block table from it instead of using the MAZ data; see returning to a level.4

What it becomes in memory​

The cells become the wall references of the 1,024 blocks of the current level, the four bytes of each record in the order of the Direction values. Moving, the dungeon view, doors and scripts read and change them there; a level the party leaves keeps its changed walls in LEVELS.TMP.

In the original files​

A level's INF file names its map, and the numbers do not always match. LEVEL6.MAZ is named by no INF file and by no string of the executable, so the game never loads it. Each file has four references per cell, 4,096 in all.

FileUsed byDifferent referencesNo wall (0)Solid walls (1, 2)Closed doors (3, 8, 13, 18)
LEVEL1.MAZLEVEL1.INF237243,16720
LEVEL2.MAZLEVEL2.INF329602,86940
LEVEL3.MAZLEVEL3.INF291,4782,30644
LEVEL4.MAZLEVEL4.INF73483,7140
LEVEL5.MAZLEVEL5.INF, LEVEL6.INF341,0022,77344
LEVEL6.MAZnone351,1602,56542
LEVEL7.MAZLEVEL7.INF341,1522,53742
LEVEL8.MAZLEVEL8.INF251,2502,68330
LEVEL9.MAZLEVEL9.INF261,2582,35010
LEVEL10.MAZLEVEL10.INF155223,4776
LEVEL11.MAZLEVEL11.INF271,3042,36122
LEVEL12.MAZLEVEL12.INF, LEVEL14.INF331,6461,94848
LEVEL13.MAZLEVEL13.INF201,9261,94926
LEVEL14.MAZLEVEL15.INF239182,92918
LEVEL15.MAZLEVEL16.INF157323,21836

The 15 files hold 61,440 wall references. References 1 and 2, the plain solid walls, account for 20,429 and 20,417 of them; both occur in all 15 files, and no INF wall mapping names either. Of the references of closed doors, 3 and 8 occur in every file except LEVEL4.MAZ, 13 in LEVEL2.MAZ, LEVEL5.MAZ and LEVEL6.MAZ, and 18 in LEVEL2.MAZ and LEVEL6.MAZ.

Example​

The first 18 bytes of LEVEL1.MAZ:

offset bytes meaning
0000 20 00 20 00 04 00 header: 32, 32, 4
0006 01 01 02 02 cell [00:00]: four wall references
000a 02 02 01 01 cell [01:00]
000e 01 01 02 02 cell [02:00]

What 01 and 02 stand for depends on the wall mappings of the INF file that uses this map.

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references (REF-MW-002, REF-SCUMM-004, REF-SCUMM-005). The files are identified in the file inventory.

Footnotes​

  1. Distance between two blocks. ↩

  2. Neighbor routine with its direction steps, visible blocks, compass drawing and view setup. ↩

  3. Map loading, into the level blocks, through the level-data buffer, which the INF loader fills before it. ↩

  4. Map loading, reading a LEVELS.TMP record and restoring the level state and its unpacking half. ↩