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, -1 = none specified
  sword  desty;           // pixel coordinates, -1 = none specified
  sword  destlayer;       // -1 = none specified
  word   fade;


  -- Person (1) --
  string spriteset;       // spriteset filename
  byte   movement;        // 0 = random, 1 = script
  
  // random movement
  byte   direction;       // 0 = up, 1 = right, 2 = down, 3 = left
  byte   walk_speed;      // speed
  word   walk_duration;   // number of tiles to walk
  word   delay;           // delay between walks

  // scripted movement
  string movement_script; // movement script - format defined later

  // dialog
  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 reserved[16];


  -- 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.


Person entity movement scripts:
A movement script is a string consisting of a series of codes.  Each code begins with
a single letter and is followed by a series of digits.  Scripts are repeated when they
are completed.

U# - Move north # tiles
R# - Move east # tiles
D# - Move south # tiles
L# - Move west # tiles
W# - Stop moving for # frames
S# - Set speed to #
