Terrarum Game Map Format

* Endianness: LITTLE

Ord  Hex  Description
00   54   T
01   45   E
02   4D   M
03   7A   z               # 'z' because it's compressed

04   03   Version revision number (unreleased numbers also count)

05   03   Number of layers, NOT the number of payload

06   05   Number of payloads

07   01   Compression algorithm, 0 for none, 1 for DEFLATE, otherwise undefined (maybe LZMA2 for the future?)

08        World width
09        World width
0A        World width
0B        World width

0C        World height
0D        World height
0E        World height
0F        World height

10        Default spawn coord in Absolute Tile Number
11        Default spawn coord in Absolute Tile Number
12        Default spawn coord in Absolute Tile Number
13        Default spawn coord in Absolute Tile Number
14        Default spawn coord in Absolute Tile Number
15        Default spawn coord in Absolute Tile Number

# Payload
#
# Each layer and other information are stored as a "payload"
# A payload is consisted as follows:
#
#   Literal        Description
#   "\0pLd"        Payload header  [00, 70, 4C, 64]
#   [4]            Identifier. 4 lettres ASCII string
#   [6]            Uncompressed size of DEFLATEd binary (max size 256 TB)
#   [..]           DEFLATEd binary (begins with one of these: 0x789C, 0x78DA, 0x7801)
#   "EndPYLd\xFF"  Payload footer  [45, 6E, 64, 50, 59, 4C, 64, FF]


Payload "TERR" -- world terrain data, concatenation of MSB and LSB arrays. In Haskell style: Deflate(MSB ++ LSB)
                  Uncompressed size will be 1.5x of (width * height)

Payload "WALL" -- world walls data, concatenation of MSB and LSB arrays. In Haskell style: Deflate(MSB ++ LSB)
                  Uncompressed size will be 1.5x of (width * height)

Payload "WIRE" -- world wires data
                  Uncompressed size will be as same as (width * height)

Payload "TdMG" -- world terrain damage data, array of: (Int48 tileAddress, Float32 damage)
                  Uncompressed size will be arbitrary (multiple of tens)

Payload "WdMG" -- world walls damage data, array of: (Int48 tileAddress, Float32 damage)
                  Uncompressed size will be arbitrary (multiple of tens)

EOF  45   E
EOF  6E   n
EOF  64   d
EOF  54   T
EOF  45   E
EOF  4D   M
EOF  FF   Byte order mark
EOF  FE   Byte order mark


* To read layers: you'll need to search for specific strings, namely ["TERR", "WALL", "WIRE"]
