Castle Adventure Data Format
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. The data is long strings of data stored in the standard DOS code page 437. Item and monster positions, as well as the description and location of furniture resides in the EXE.
|char||Map, Description, and Exits.|
|char||High Score Name|
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.
|char||Map (24 × 18)|
|char||Description (25 × 5)|
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. LoadRoom(bRoom) ' Main Loop Do ' Get keyboard input. sKey = Inkey() bChange = 0 Select Case sKey Case Chr(27) ' ESC End 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 LoadRoom(bRoom) EndIf Loop 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 Cls 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!)