Version 4 (modified by historic_bruno, 12 years ago) ( diff )

--

There is a random map generator integrated with the engine. Random map scripts (RMS) are implemented in Javascript with a minimal C++ interface, see Random Map Generator Internals.

Playing Random Maps

Random maps can now be played through the game setup, by choosing Random from the Match Type dropdown. See the Gameplay Manual for more details.

Guide to JavaScript

The game supports scripts written in Javascript, which are used for random maps, game logic, and AIs. The engine uses the SpiderMonkey library to implement the language. References for those interested in Javascript programming:

Guide to Random Map Scripting

Basically a random map script is responsible for all the logic of generating a map: modeling terrain, placing units and resources, and then returning the data to the engine. In practice, most of the logic is hidden by APIs also implemented in JavaScript. We have added the concept of libraries for this purpose.

Random map scripts are placed in the maps/random/ directory. In addition to the script itself, there is also an associated JSON data file. This file is loaded by game setup to recognize a new random map, and it includes various settings, see defining the map for details.

Load libraries

A random map script should first load any libraries it will need. Libraries are stored in the game data directories under maps/random/libraryName/. When a library is loaded, all scripts in that directory are parsed and their code made available to the random map script. They are loaded through the function call RMS.LoadLibrary(libraryName). Currently there is only one library available, rmgen - in the future there may be others or you can create your own.

Initialize the library

The next step is to initialize the library. This may vary, but for rmgen, you would call InitMap().

Save the results

The random map script should end with a call to RMS.ExportMap(data), which returns all the map data back to the engine. In rmgen this is abstracted by a call to ExportMap(). For the exact format of the data see Random Map Generator Internals.

Available Libraries

Here's a list of libraries currently included with the map generator:

Note: See TracWiki for help on using the wiki.