Skip to main content

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.

From the file LEVELS.TMP to the game. The file holds, in order: Walls (up to 1,200 bytes); Monsters (900 bytes); Temporary walls (30 bytes); × 17 records (2,130 bytes each). The game: Write a level’s record when the party leaves it; Read it back when the party returns; Copied whole into saved games. In memory: The walls, monster slots and temporary walls of the level. Used by: Level changes, Saved games.
The game turns it into the walls, monster slots and temporary walls of the level.

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:

PartRecord offsetSizeContents
Walls0x000up to 1,200The four wall references of the 1,024 blocks, compressed with the type-4 method of CPS containers.
Monsters0x4b0900The 30 monster slots of the level.
Temporary walls0x83430Five 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.

Sources​

Locations refer to the game executable reference. The reference file is listed in the file inventory.

Footnotes​

  1. Write a level record, read a level record, pack and unpack a level record and the saved-level bits. ↩ ↩2

  2. The program start-up and the saved-level bits; write a level record, save a game and read a saved game, with the file open helper. ↩

  3. Pack and unpack a level record, the level blocks, the monster slots and the temporary-wall slots. ↩