Level records (LEVELS.TMP)
File formats · Field reference · Schema
In brief
LEVELS.TMP keeps the state of the dungeon levels the party has left: for
each level, its walls, its monsters and its temporary walls. The game writes
a level's record when the party leaves it and reads it back when the party
returns, so that opened doors, changed walls and killed monsters stay as the
party left them. See level records and level changes.
The file is part of every saved game: saving copies it into the saved game, and loading a game writes the saved records back over it.
Organization
The file is 17 records of 2,130 bytes, 36,210 bytes in all. Record n − 1, at offset (n − 1) × 2,130, belongs to level n:
| Part | Record offset | Size | Contents |
|---|---|---|---|
| Walls | 0x000 | up to 1,200 | The four wall references of the 1,024 blocks, compressed with the type-4 method of CPS containers. |
| Monsters | 0x4b0 | 900 | The 30 monster slots of the level. |
| Temporary walls | 0x834 | 30 | Five slots: a block and the time left before the wall disappears. |
The file does not say which records are valid. The game keeps one bit per level for that in its memory, and saves it with the saved game; a record without its bit is ignored and can hold leftover data.1
The decoded walls are the level's wall references as they are, in the order of a MAZ map, not a difference from the map.
Writing and reading the file
When the party leaves a level, the game packs the level and writes its record in place, at (n − 1) × 2,130, then sets the level's bit. When the game loads a level whose bit is set, it reads the record back instead of taking the walls from the level's MAZ map.1
A new game does not create or empty the file. All record bits are clear when the program starts, and a new game can only begin then, so the records left in the file by an earlier game are ignored. Leaving a level opens the file without truncating it, creating it when it does not exist, and writes that level's record in place; loading a saved game replaces the whole file. The file is never deleted. A file can therefore hold records of earlier games next to the current ones; the bits tell them apart, and saving copies both kinds into the saved game. See a new game.2
What it becomes in memory
A record is the moving part of a level, packed. Writing it, the game packs
the four wall bytes of the 1,024 level blocks with the type-4 method, then
copies the 30 monster slots, the
MonsterRuntime entries, and the five
temporary-wall slots, whose deadlines become the ticks left (1 when already
due). Reading it reverses each step: it unpacks the walls into the blocks,
restores the monster slots, adds one to the occupancy count of the block of
each of the 30 slots, then turns the ticks left back into deadlines. The
rest of a block, its state word,
item chain and script reference, is not stored in the record.3
In the original files
The reference file is byte-identical to the level records of the reference
saved game. In the reference file only level 4 has its bit. Its walls decode to the cells
of LEVEL4.MAZ, five of its monster slots are in use, and its five
temporary-wall slots are free. The other 16 records are leftovers: the walls
of 14 of them decode, those of levels 15 and 17 do not.
Related pages
- Saving and restoring: when records are written and restored, and what the rest of a level's state becomes.
- Level maps (MAZ): the walls a level starts with.
Sources
Locations refer to the game executable reference. The reference file is listed in the file inventory.