Castle Adventure Data Format

From ModdingWiki
Jump to navigation Jump to search
Castle Adventure Data Format
Castle Adventure Data Format.png
Format typeMap/level
Map type2D tile-based
Layer countUnknown

All of the map data is stored in the Castle.ran file, as is the high score.

Each room is 575 bytes, there are 83 rooms. These numbers are constants in the EXE and are not stored in the map file. Each map is a long string of characters using Western DOS code page 437. Item and monster positions, as well as the description and location of furniture resides in the EXE.

Data type Description
char[575] Map, Description, and Exits.
...83 rooms
char[24] High Score Name
char[22] High Score
char[738] Null

Each room consists of 3 parts, the Map, Description, and Exits.

Each map is 432 bytes long and consists of the room's floor plan stored as a 24 × 18 matrix of characters. Each description is 125 bytes long, displayed as a 25 × 5 matrix of characters. Exits are stored as a single string that must be parsed. The string consists of a series of exits. Each exit begins with a letter indicating the direction, and then a number indicating the room number to move to. They have no deliminator and are variable width, so they must be broken up based on when a letter turns to a number. Possible exits include N - North, S - South, E - East, W - West, U - Up, and D - Down. Rooms must be 1-83.

Data type Description
char[432] Map (24 × 18)
char[125] Description (25 × 5)
char[18] Exits

Source Code

Map Viewer

This FreeBASIC program allows you to cycle through the rooms by pressing left and right.

Declare Sub LoadRoom(bRoom As UByte)

' Specifiy the path to the Castle.ran file.
Dim Shared sFile As String
sFile = "E:\Games\Castle Adventure\Castle.ran"

' Set the starting room.
Dim bRoom As UByte
bRoom = 1

' Engine variables.
Dim sKey As String
Dim bChange As UByte

' Load the initial room.

' Main Loop
    ' Get keyboard input.
    sKey = Inkey()
    bChange = 0
    Select Case sKey
    Case Chr(27)              ' ESC
    Case Chr(255) & "M"       ' Right
        If bRoom < 83 Then 
            bRoom = bRoom + 1
            bChange = 1
        End If
    Case Chr(255) & "K"       ' Left
        If bRoom > 1 Then
            bRoom = bRoom - 1
            bChange = 1
        End If
    End Select
    ' If the room changed, redraw the screen with the new room.
    If bChange = 1 Then

Sub LoadRoom(bRoom As UByte)
    ' Create all the necessary buffers.
    Dim sRoom As String * 575
    Dim sMap As String * 432
    Dim sDescription As String * 125
    Dim sExits As String * 18
    Open sFile For Binary As #1

    ' Read ahead to the correct room.
    Dim bSkip As UByte
    For bSkip = 1 To (bRoom - 1)
        Get #1, , sRoom
    Next bSkip

    ' Read the current room data.
    Get #1, , sMap
    Get #1, , sDescription
    Get #1, , sExits

    Close #1

    Dim bRow As UByte, bCol As UByte

    For bRow = 1 To 18
        Locate bRow, 25
        Print Chr(179)
    Next bRow
    For bCol = 1 To 25
        Locate 19, bCol
        Print Chr(196)
    Next bCol
    Locate 19, 25
    Print Chr(217)
    For bRow = 1 To 18
        Locate bRow, 1
        Print Mid(sMap, ((bRow - 1) * 24) + 1, 24);
    Next bRow
    For bRow = 1 To 5
        Locate bRow + 19, 1
        Print Mid(sDescription, ((bRow - 1) * 25) + 1, 25);
    Next bRow
    Locate 1, 27
    Print "Room: " + Str(bRoom)
    Locate 3, 27
    Print "Exits: " + sExits
    Locate 10, 27
    Print "Use the left and right"
    Locate 11, 27
    Print "arrow keys to cycle"
    Locate 12, 27
    Print "through the rooms."
    Locate 13, 27
End Sub


This level format was reverse engineered by TheAlmightyGuru. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)