Cano Map Format 3 - ZaneDubya/MedievaLandsPublic GitHub Wiki

New map format

Map is organized in cells of 4x4 tiles. A map may be any size, so long as it is in cells.

Cells are read left to right, top to bottom.

In addition to the below, I intend to include:

  • Texture blending maps, up to four layers at 16x16x4bit (128 bytes) or 32x32x4bit (512 bytes)
  • Shadow maps at 16x16x1bit (32 bytes) or 32x32x1bit (128 bytes) or 64x64x1bit (512 bytes)
  • Atmospheres (fog, color, lighting).
  • Doodad representation.

Data types

In addition to typical data types (bytes, shorts, integers, floats, etc), I use "7-bit integer" (7bit or 7b) values to store numbers and "Ascii-prefix" (AP) values to store strings.

A 7-bit integer is a number that ranges from 0-2 billion. Values between 0-127 fit in one byte. 128-16383 fit in 2 bytes. Values less than 2 million fit in 3 bytes. This data type optimizes files size when most of the values are less than 2 million, and is 1/4 the size of a 32bit integer when values are 0-127.

An Ascii-Prefix is a 8bit ascii string (8 bits per character, space character is 0x20), prefixed by a 7-bit integer length. It is not zero-terminated.

Map Data

Map Header:
- 2b     Magic "0xD839"
- 2b     Map Format "2"

Map Data:
- 7bit   Version
- 7bit   Flags
         ...
- 7bx2   Width, Height in Cells
Cell Offsets:
- i32xWH 32bit integer offsets from file start to all cells (count is width x height)
Textures:
- 7bit   Texture count
    For each texture
    - 7bit   Index value (lookup index used by cells)
    - AP7xC  Ascii texture path, prefixed by 7bit count string length
             Textures should be RGBA (path.ext, always .png).
             Second texture (name will be path-x.ext) can be bump(RGB)+specular(A).

Cell Data

Cell Data:
- 7bit    Name (0 = no name)
- 7bit    Default Atmosphere
- 7bx155  Tile Zs. Entire cell is 9x9+8x8 vertexes. Each tile is 16 quads, for a total of 256 or 512 polys.

Tile Data (x16):
Flags:
- 7bit    Flags 
          .000 0001 = Is walkable. If 0, players cannot enter tile by walk movement,
                      regardless of adjacent tile blocking.
          .000 0010 = Has blocking data. If 0, all cardinal directions are walkable.
          .000 0100 = Has atmosphere override If 0, atmosphere is cell's atmosphere.

Blocking Data (if FlagBlockingData = 1):
bits    Default blocking (can be overridden by map script)
        .... 0001 = North is default blocked
        .... 0010 = East is default blocked
        .... 0100 = South is default blocked
        .... 1000 = West is default blocked

Atmosphere Data (if HasAtmosphereOverride = 1):
7bit    Atmosphere type

Decoration (Deco) Data:
7bit    Deco count
        For each deco:
        7bit deco anchor
                  0 = north,
                  1 = east   (models rotate 90), 
                  2 = south  (models rotate 180), 
                  3 = west   (models rotate 270), 
                  4 = center
        7bit deco type
        .... deco data

Event Data:
7bit    Event count
        For each Event:
        7bit event type
        7bit event index (per map)

Decoration Types (hex value):

  • 00 quad with texture 7bit texture index
  • 01 quad with two textures 7bit texture index 0 7bit texture index 1, uses alpha map
  • 02 n wall sprite
  • 03 n wall sprite
  • 04 n wall sprite
  • 05 n wall sprite
  • 7f 3d model sbyte x offset from tile center sbyte y offset from tile center sbyte z offset from tile center sbyte x rotation sbyte y rotation sbyte z rotation 7bit model index

Event Types (hex value):

  • 00 on arrive
  • 01 on depart
  • 10 on face n
  • 11 on face e
  • 12 on face s
  • 13 on face w
  • 20 on move n
  • 21 on move e
  • 22 on move s
  • 23 on move w