RPG Map File Format
Chad Austin
10.3.1999


---- 256 byte header ----

byte signature[4];          // Must be ".rmp"
word version;               // Must be 1
byte type;                  // obsolete
byte num_layers;
byte base_layer;            // zero-based
word num_entities;
word startx;                // In pixel coordinates, not tile
word starty;
byte startlayer;
byte startdirection;        // 0 = north, 1 = northeast, 2 = east, etc. (clockwise)
word num_strings;
byte reserved[237];



---- String data ----

There are num_strings strings in the map file:
word string_length;
byte characters[string_length];

Defined strings:
  0 - tileset file
  1 - music file
  2 - script file


If the tileset file string has no length, the tileset is stored appended to the
map file.  See rts.txt for a description of the tileset format.


---- Layer data ----

Each layer has its own 30-byte header that goes like this:
word width;
word height;
word flags;
byte parallax_x_mult;
byte parallax_x_div;
byte parallax_y_mult;
byte parallax_y_div;
byte scrolling_x_mult;
byte scrolling_x_div;
byte scrolling_y_mult;
byte scrolling_y_div;
byte reserved[16];

string name;  // past the layer header is the string, if it exists

Each layer is sequential in the map file.  Each layer is (width * height * 2)
bytes because the actual tile number is a word.  If the high bit of the
scrolling values is set, the number is negative.



---- Entity header ----

Each entity has a 16-byte information block:
word mapx;         // x-coordinate of entity (pixel coordinates)
word mapy;         // y-coordinate of entity (pixel coordinates)
word layer;        // z-coordinate of entity (layer)
word type;         // 0 = Warp, 1 = Person, 2 = Trigger, 3 = Doodad
byte reserved[8];



---- Entity data ----

  -- Warp (0) --
  string destination_map;
  sword  destx;         // pixel coordinates
  sword  desty;         // pixel coordinates
  sword  destlayer;
  word   fade;

  -- Person (1) --
  byte   direction;     // 0 = up, 2 = right, 4 = down, 6 = left
  string spriteset;     // spriteset filename
  byte   dialogue_type; // 0 = embedded, 1 = file
  string dialogue;      // if dialogue_type is 0, this is just the dialogue text
                        // if dialogue_type is 1, this is a filename with the text
  byte   speed;         // speed
  word   num_tiles;     // number of tiles to walk
  word   delay;         // delay between walks
  byte   reserved[32];

  -- Trigger (2) --
  string function;      // function to be called in the map script

  -- Doodad (3) --
  string doodad;          // doodad filename
  string function;        // activation function
  byte obstructive;       // blocks the user
  byte activation_method; // 0 = none, 1 = door, 2 = chest
  byte reserved[14];



---- Appendix ----

strings are not zero-terminated and defined in the following format:
word length;
byte characters[length];

To convert from tile coordinates to pixel coordinates, multiply them by the
tile dimensions.
