Excursion: The Teeworlds map format

In this chapter you will learn how a teeworlds map is structured. This knowledge is not necessary for using tml, but it can be helpfull if you are interested in understanding what is going on under the hood or just want to hack a map yourself.

Item types

After the header the types are stored. For each item type there is a list containing the type, the number of items for this type and which itme is the first for this type. The list is sorted by item type and item id.

Item offsets

Right after the types the item offsets are stored. The first offset is 0. The offset to the next item will be the size of the previous item. The size of each item is as big as defined in mapitems.h (see teeworlds source) plus 2 more integers containing the type, id and the item size.

Data offsets

After the item offsets the data offsets are stored. The first offset is 0. The offset to the next data will be the size of the previous data. The size of each data gets generated when saveing the map.

Uncompressed data sizes

The uncompressed data sizes are stored after the data offsets. The sizes are used to allocate the memory for each data in teeworlds.

Items

Finally the items are stored. Every item will be stored with all its data in this order:

  1. version
  2. info
  3. images
  4. envelops
  5. groups
  6. layers
  7. envpoints

Every item contains the data as defined in mapitems.h (see teeworlds source) plus 2 more integers containing the type, id and the item size. Type and id is within the first integer. To extract the type and id the following formulas are used:

  • type = (type_and_id >> 16) & 0xffff
  • id = type_and_id & 0xffff

Datas

Eventually the datas are stored. The data is compressed using zlib. Each item which requires data has an index which tells the position of the corresponding data. The compressed data part stores image names, tiles, quads and embedded images.

Table Of Contents

Previous topic

Example scripts

This Page