Changes between Version 5 and Version 6 of Random_Map_Generator_Internals
- Timestamp:
- Apr 17, 2011, 12:17:18 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Random_Map_Generator_Internals
v5 v6 5 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 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. 6 6 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 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. 7 == Engine-script interface == 8 9 The CMapGenerator provides a minimal interface to 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 some JavaScript functions: 10 * `RMS.LoadLibrary(name)` - load a library, choosing the API to which a random map script will have access, e.g. "rmgen". 11 * `RMS.ExportMap(data)` - return generated map data from the scripts to the engine. 12 * `RMS.SetProgress(percent)` - set the map generation progress percentage, so the loading screen progress bar can be updated. Percentage must be an integer 1-100. 13 * `RMS.MaybeGC()` - possibly run the garbage collector. 8 14 9 15 == Data format == … … 15 21 "seaLevel": 20.0, 16 22 "textureNames": [ "medit_grass_field_a", ... ] 17 "tileData": [ { " texIdx1" : 0x0001, "texIdx2" : 0xFFFF, "priority" : 0 }, ... ]18 "entities": [ { "id" : 100, "name" : "units/hele_support_female_citizen", "x" : 102.4, " y" : 64.8, "angle" : 0.86, "isActor" : false}, ... ]23 "tileData": [ { "idx" : 0x0001, "priority" : 0 }, ... ] 24 "entities": [ { "id" : 100, "name" : "units/hele_support_female_citizen", "x" : 102.4, "z" : 64.8, "angle" : 0.86}, ... ] 19 25 } 20 26 }}} … … 23 29 * `seaLevel`: Float. This is the height of the sea, the value in the heightmap for which all lower terrain will be under water. 24 30 * `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). 25 * `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.31 * `tileData`: Array of tile descriptor objects. Tile descriptors reference the terrain texture(s) for a given tile. 26 32 * `entities`: Array of entity objects. Entities specify something like a tree, unit, or building in the game. 27 33 28 Tile descriptor format: 34 === Tile descriptor format === 29 35 {{{ 30 36 { 31 "texIdx1" : 8, 32 "texIdx2" : 2, 37 "idx" : 8, 33 38 "priority" : 0 34 39 } 35 40 }}} 36 * `texIdx1`: Integer. Primary texture to be used (value is referenced from `textureNames` array). 37 * `texIdx2`: Integer. Optional secondary texture to be used (value of 0xFFFF for none). 38 * `priority`: Integer. Optional priority for texture blending (value of 0 is default). TODO: Explain how this works. 41 * `idx`: Integer. Texture ID to be used (value is referenced from `textureNames` array). 42 * `priority`: Integer. Optional priority for texture blending (value of 0 is default). Considering adjacent tiles, the texture with higher priority will be blended on top of the tiles with lower priorities. 39 43 40 Entity format: 44 === Entity format === 41 45 {{{ 42 46 "id": 1034, 43 47 "name": "units/hele_support_female_citizen", 44 48 "x": 102.4, 45 "y": 64.8, 46 "angle": 0.86, 47 "isActor": false 49 "z": 64.8, 50 "angle": 0.86 48 51 }}} 49 52 * `id`: Integer. Unique ID of this entity, used by the engine to identify each instance. 50 53 * `name`: String. Template name of the entity, usually specifies faction and unit/building type for players, or special gaia templates. 51 * `x`, `y`: Float. Position of the entity on the map (in tiles). 52 * `angle`: Float. Rotation of the entity about y-axis. 53 * `isActor`: Bool. This flags tells the map reader whether this entity is an actor or not. 54 * `x`, `z`: Float. Position of the entity on the map (in XZ map coordinates; 4.0 map units = 1.0 tile unit). 55 * `angle`: Float. Rotation of the entity about y-axis (vertical), in radians. 54 56 55 57 CMapReader is responsible for parsing this data and creating the map, in a process very similar to that for scenarios.