Changes between Version 3 and Version 4 of Random_Map_Generator_Internals


Ignore:
Timestamp:
Apr 6, 2011, 4:09:39 AM (13 years ago)
Author:
historic_bruno
Comment:

added more detail, corrected typos

Legend:

Unmodified
Added
Removed
Modified
  • Random_Map_Generator_Internals

    v3 v4  
    33= Generating the Map =
    44
    5 When loading a scenario, the CMapReader class simply reads an XML file (with map settings, list of entities, and other textual data) together with a binary file called a PMP (which specifies height map and terrain textures). For a random map, there is obviously no predefined map to read. Instead, the engine uses a new CMapGenerator class. The CMapGenerator needs the name of a random map script and some settings, such as number of players and their civs. These are selected during game setup.
     5When loading a scenario, the CMapReader class simply reads an XML file (with map settings, list of entities, and other textual data) together with a binary file called a PMP (which specifies height map and terrain textures). For a random map, there is obviously no predefined map data to load. Instead, the engine uses a new CMapGenerator class. The CMapGenerator needs the name of a random map script and some settings, such as number of players and their civs. These are selected during game setup.
    66
    7 The CMapGenerator provides a few things for the random map scripts. One is a global variable `g_MapSettings` which specifies all the map settings, these are provided by game setup. CMapGenerator also exposes two JavaScript functions: `RMS.LoadLibrary(name)` and `RMS.ExportMap(data)`. `LoadLibrary` is used for choosing the API to which a random map script will have access. `ExportMap` is used to return generated map data from the scripts to the engine.
     7The CMapGenerator provides a few things for the random map scripts. One is a global variable `g_MapSettings` which specifies all the map settings as created by game setup. CMapGenerator also exposes two JavaScript functions: `RMS.LoadLibrary(name)` and `RMS.ExportMap(data)`. `LoadLibrary` is used for choosing the API to which a random map script will have access. `ExportMap` is used to return generated map data from the scripts to the engine.
    88
    99The data from a random map script must be in an exact format, independent of the methods used to generate it. This format can be specified in JSON as follows:
     
    1818}
    1919}}}
    20  * `size`: Integer. This is the size of the map in tiles (integer).
    21  * `height`: Flat array of 16-bit unsigned integers. This is the height data for each tile of the map.
     20 * `size`: Integer. This is the size of the map in tiles.
     21 * `height`: Array of 16-bit unsigned integers. This is the height data for each tile of the map.
    2222 * `seaLevel`: Float. This is the height of the sea, the value in the heightmap for which all lower terrain will be under water.
    23  * `textureNames`: Flat array of strings. This is the terrain textures used. They must be in the order in which they were defined (as they are referenced by tile data).
    24  * `tileData`: Flat array of tile descriptors. Tile descriptors reference the terrain textures for a given tile and an optional priority for blending. The array must be arranged in patches, there are 16 tiles per patch.
    25  * `entities`: Flat array of entities.
     23 * `textureNames`: Array of strings. This is the terrain textures used. They must be in the order in which they were defined (as they are referenced by tile data).
     24 * `tileData`: Array of tile descriptor objects. Tile descriptors reference the terrain texture(s) for a given tile. The array must be arranged in patches; there are 16 tiles per patch.
     25 * `entities`: Array of entity objects. Entities specify something like a tree, unit, or building in the game.
     26
     27Tile descriptor format:
     28{{{
     29{
     30  "texIdx1" : 8,
     31  "texIdx2" : 2,
     32  "priority" : 0
     33}
     34}}}
     35 * `texIdx1`: Integer. Primary texture to be used (value is referenced from `textureNames` array).
     36 * `texIdx2`: Integer. Optional secondary texture to be used (value of 0xFFFF for none).
     37 * `priority`: Integer. Optional priority for texture blending (value of 0 is default). TODO: Explain how this works.
     38
     39Entity format:
     40{{{
     41  "id": 1034,
     42  "name": "units/hele_support_female_citizen",
     43  "x": 102.4,
     44  "y": 64.8,
     45  "angle": 0.86,
     46  "isActor": false
     47}}}
     48 * `id`: Integer. Unique ID of this entity, used by the engine to identify each instance.
     49 * `name`: String. Template name of the entity, usually specifies faction and unit/building type for players, or special gaia templates.
     50 * `x`, `y`: Float. Position of the entity on the map (in tiles).
     51 * `angle`: Float. Rotation of the entity about y-axis.
     52 * `isActor`: Bool. This flags tells the map reader whether this entity is an actor or not.
    2653
    2754CMapReader is responsible for parsing this data and creating the map, in a process very similar to that for scenarios.