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 of this format (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, 2 for LZMA, otherwise undefined (maybe LZMA2 for the future?)
          Value of 01 (DEFLATE) is recommended for its faster compression

08        World generator version. If the generator adds new feature (e.g. new ores, new buildings)
09        this number must be incremented by one.

0A        World width
0B        World width
0C        World width
0D        World width

0E        World height
0F        World height
10        World height
11        World height

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
16        Default spawn coord in Absolute Tile Number
17        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 in Uint16
                  Uncompressed size will be 2x of (width * height)

Payload "WALL" -- world walls data in Unit16
                  Uncompressed size will be 2x of (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)

Payload "FlTP" -- world fluid types, array of: (Int48 tileAddress, Signed Int16 type)
                  Uncompressed size will be arbitrary (multiple of eights)

Payload "FlFL" -- world fluid fills, array of: (Int48 tileAddress, Float32 amount)
                  Uncompressed size will be arbitrary (multiple of tens)
                  If the 'amount' < 0.0001f (WorldSimulator.FLUID_MIN_MASS), the entry must be discarded

Payload "WiNt" -- wiring nodes, in JSON format

Payload "CtYP" -- conduit types, array of: (Int48 tileAddress, Uint32 bitarray)
                  can hold 32 different wires simultaneously

Payload "CfL0" -- conduit fills, aka size of liquid/gas packet, array of: (Int48 tileAddress, Float32 fill)
                  CfL0..CfL9, CfLa..CfLf are available to store values for 16 different things.

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"]
