Version 3 (modified by historic_bruno, 13 years ago) ( diff )

--

For Alpha 5, there will be a random map generator integrated with the engine. This document describes the interaction between the engine and the random map scripts.

Generating the Map

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.

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.

The 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:

{
  "size": 128,
  "height": [ 1000, ... ]
  "seaLevel": 20.0,
  "textureNames": [ "medit_grass_field_a", ... ]
  "tileData": [ { "texIdx1" : 0x0001, "texIdx2" : 0xFFFF, "priority" : 0 }, ... ]
  "entities": [ { "id" : 100, "name" : "units/hele_support_female_citizen", "x" : 102.4, "y" : 64.8, "angle" : 0.86, "isActor" : false}, ... ]
}
  • size: Integer. This is the size of the map in tiles (integer).
  • height: Flat array of 16-bit unsigned integers. This is the height data for each tile of the map.
  • seaLevel: Float. This is the height of the sea, the value in the heightmap for which all lower terrain will be under water.
  • 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).
  • 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.
  • entities: Flat array of entities.

CMapReader is responsible for parsing this data and creating the map, in a process very similar to that for scenarios.

Note: See TracWiki for help on using the wiki.