Troll Bridge: File Formats

The file formats are not considered final at this time. Every effort will be made to inform developers of changes to the file formats and if possible tools will be provided to aid in the conversion. Unless otherwise specified variables are unsigned.

File Format: .pal
The ".pal" files store a 256 color palette.

Main
palette: array[256] of rgb info Definition for each color

Rgb Info
red: byte Red value of the color
green: byte Green value of the color
blue: byte Blue value of the color

File Format: .spr
The ".spr" files store collections of sprites.

Main
spritenum: short Number of sprites
sprites: array[spritenum] of sprite info Definition of the sprites

Sprite Info
xsize: short X size of the picture
ysize: short Y size of the picture
facings: short Number of facings
frames: short Number of frames
picsize: array[facings * frames] of short Sizes of each individual picture
This is followed by the pictures compressed using a variation of run-length encoding. Each picture has ysize number of segments. Each segment starts with a byte telling the size of the segment followed by that many bytes. If the byte has the highest bit set and the byte is not 255 then the next byte is repeated a number of times equal to the byte without the highest bit set plus one. Otherwise the byte is just the pixel value. The color 255 is transparent.

File Format: .trb
The ".trb" files are the map files for Troll Bridge.

Main
startscreen: array[2] of short X and Y location of the starting screen
startlocation: array[2] of short X and Y location on the starting screen
map: array[TROLL_LEVEL_X][TROLL_LEVEL_Y] of byte Colors for each map square
screens: array[TROLL_LEVEL_X][TROLL_LEVEL_Y][2] of long File offset and the size of each screen info
This is followed by the definitions of the screens (see the screen info structure). The screens may not be inorder and should be referenced by their file offset. Also the file may have extra space that is unused. This is so that map editors can change screens in the middle of the file without moving all the screens to fill all available space.

Screen Info
backgroundpics: array[TROLL_SCREEN_X][TROLL_SCREEN_Y] of short Number of the background pictures for each square
backgroundshift: array[TROLL_SCREEN_X][TROLL_SCREEN_Y] of byte Color shift value for each square
passability: array[TROLL_SCREEN_X][TROLL_SCREEN_Y] of short Passability of each square
exitsnum: short Number of exits from the screen
exits: array[exitsnum] of exit info Definitions of exits
permmonsnum: short Number of permanent monsters
permmons: array[permmonsnum] of short Permanent monster types
respawnmonsnum: short Number of respawning monsters
respawnmons: array[respawnmonsnum] of short Respawning monster types
secretsnum: short Number of secrets
secrets: array[secretsnum] of secret info Definitions of secrets

Exit Info
location: array[2] of short X and Y location of the exit
newlevel: string Filename of the new level (including .trb)
newscreen: array[2] of short X and Y location of the new screen
newlocation: array[2] of short X and Y location on the new screen

Secret Info
secretnum: short Number in the secret array
unsetscriptsize: short Size of the unset script
unsetscript: array[unsetscriptsize] of byte Sequence of secret commands run when the secret is unset
setscriptsize: short Size of the set script
setscript: array[setscriptsize] of byte Sequence of secret commands run when the secret is set

Secret Scripts
Currently secret scripts are very limited. Many more commands are planned. Commands are variable length. The first byte identifies the function and is followed by a variable number of arguments. The commands currently implemented are:

Code: 00
Function Name: (None. Automatically added to the end of secrets.)
Arguments: None
Description: Terminates the secret script.
 
Code: 01
Function Name: CreateMonster
Arguments: monsterType: short
secretNum: short
Description: Creates a monster.
 
Code: 02
Function Name: CreateItem
Arguments: itemType: short
x: signed short
y: signed short
secretNum: short
Description: Create an item.
 
Code: 03
Function Name: SetBackground
Arguments: x: short (in squares)
y: short (in squares)
sprite: short
shift: byte
passability: short
Description: Sets a background square.
 
Code: 04
Function Name: CreateExit
Arguments: x: short
y: short
levelName: string (including .trb)
mapX: short
mapY: short
screenX: short
screenY: short
Description: Create an exit.
 
Code: 05
Function Name: SetText
Arguments: message1: string (max 27 characters)
message2: string (max 27 characters)
Description: Sets the messages to display.
 
Code: 06
Function Name: CreateMonsterXY
Arguments: monsterType: short
x: signed short
y: signed short
secretNum: short
Description: Creates a monster.

File Format: .trs
The ".trs" files saves the characters data. Filenames have a maximum of 8 characters plus the extension.

Main
thp: short Total number of hit points
shift: short Color shift of hero
gold: short Gold coins
secrets: array[TROLL_SECRETS_SIZE] of byte Secret bits
itemsNum: short Number of items
items: array[itemsNum] of item info Items
mapNum: short Number of maps
maps: array[mapNum] of map info Maps

Item Info
itemNum: short Item number
Items can also save extra data. For example the key saves the current number of keys. There is nothing that lists the size of this data or what it contains.

Map Info
levelName: string Name of the level file (including .trb)
map: array[TROLL_LEVEL_X][TROLL_LEVEL_Y] of byte Colors for each map square

File Format: .def
The current world definition file is a simple text file. Each item is on a seperate line. The file defines the shared library, pallete file, sprite file, starting trb file, and title screen. Expect this format to change in future version.

File Format: .pcx
Identical Software's Graphics Library supports the ".pcx" format but it can only read and write 256 color images. Much of the pcx header information is disregarded.

Main
manufacturer: byte Manufacturer (must be 0x0A)
version: byte Version (must be 0x05)
encoding: byte Encoding (must be 0x01)
bpp: byte Bits per pixel (must be 0x08)
ignored: array[4] of byte Ignored (set to 0x00)
xsize: short X size of the picture - 1
ysize: short Y size of the picture - 1
hdpi: short Horizontal DPI (ignored, set to 72)
vdpi: short Vertical DPI (ignored, set to 72)
ignored: array[49] of byte Ignored (set to 0x00)
planes: byte Number of color planes (must be 0x01)
bpl: short Bytes per line (must be even, equals xsize or xsize + 1)
ignored: array[60] of byte Ignored (set to 0x00)
This is followed by the pictures compressed using a variation of run-length encoding. There should be (ysize + 1) number of "lines." Each line is composed of a number of bytes specified by bpl. However, the bytes are compressed so the line may take up more or less space. If the highest two bits are set the next byte is repeated a number of times equal to the byte without the highest two bits set plus one. Otherwise the byte is just the pixel value.
identifier: byte Identifier (0xC0) before 256-color palette (not checked for by loading routine, pallete assumed to be last 768 bytes)
palette: array[256] of rgb info Definition for each color

Rgb Info
red: byte Red value of the color
green: byte Green value of the color
blue: byte Blue value of the color