Changes between Version 2 and Version 3 of Rmgen_Library


Ignore:
Timestamp:
Jul 9, 2011, 2:18:32 AM (13 years ago)
Author:
historic_bruno
Comment:

add table of contents

Legend:

Unmodified
Added
Removed
Modified
  • Rmgen_Library

    v2 v3  
     1[[TOC]]
    12Rmgen is the name of the default script library included with the random map generator. This document describes how to use it.
    23
    3 = Map Coordinate System =
     4== Map Coordinate System ==
    45
    56The map uses the same x,z coordinate system as in-game, with all units, including those for height, equal to the size of 1 tile (which is actually 4.0 model-space units). This seemed less confusing because most people will think in terms of tiles.
    67
    7 = Terrains =
     8== Terrains ==
    89
    910The concept of terrains in rmgen is more than just textures that are painted onto a tile. As part of the terrain, a tile can also have objects on it that are "attached" to the terrain and hence removed when the tile is painted with a different terrain (for example, if you paint a forest and then paint a patch of desert inside of it, there will be no trees on the desert). Furthermore, API functions that require terrains can also take a number of complex objects that might paint different tiles with different textures but still make up one type of "logical terrain" (for example, something that paints mixed types of dirt for variation). The following ways of specifying a terrain are available:
     
    1516'''TODO:''' Later it should be possible to provide custom JS terrain objects as well.
    1617
    17 = Accessing Map Data Directly =
     18== Accessing Map Data Directly ==
    1819
    1920The lowest-level way to create a map is to set terrain and elevation for each tile specifically and place objects individually. Although this is often not what you'll want to use for ease-of-use reasons, there might be cases (such as non-standard gameplay maps) where you might want to do something not possible with the higher-level API. Thus, the API provides functions that give complete control over the map to allow this:
     
    2425 *
    2526
    26 = Placing Terrain: Areas =
     27== Placing Terrain: Areas ==
    2728
    2829The core concept of terrain placement is that of ''areas''. An area is a set of tiles of related terrain that constitutes a feature of the map, such as a body of water, a forest, etc. Once you have placed areas, you can also refer to them to control placement of other areas or objects; for example, place gold mines only on dirt patch areas, place fish only on water areas, or make forests avoid player base areas.
     
    3738This section will talk about area placers and painters; full information on constraints can be found in the Constraints section below.
    3839
    39 == Creating a single area ==
     40=== Creating a single area ===
    4041
    4142The simplest way to create an area is using the `createArea(placer, painter, constraint)` function. This takes a given placer object and tries to place the area within the given constraint. If it succeeds, it paints the area and returns the area object. If it fails, it returns `undefined` and does not change any terrain. (You can check for failure with `if(createArea(...) === undefined)`).
    4243
    43 == Creating multiple areas at random locations ==
     44=== Creating multiple areas at random locations ===
    4445
    4546For many areas, you do not want to specify an exact location for the area placer, you just want to place it at a random place that satisfies the constraint you provide. You might also want to create several similar areas using the same placer and painter but in different locations within the same constraints. Thus, the most common way to place areas is using the `createAreas(centeredPlacer, painter, constraint, number, retryFactor)` function. This takes 5 parameters:
     
    5152It returns an array of the areas placed (or an empty array if none).
    5253
    53 == Area placers ==
     54=== Area placers ===
    5455
    5556The following area placers are available. Centered placers can be used with `createAreas`. Note that most objects have editable fields of the same names as its constructor parameters after you construct it.
    5657
    57 === Centered placers ===
     58==== Centered placers ====
    5859
    5960 * `ClumpPlacer(size, coherence, smoothness, x, z)`: Places an irregular "clump" or "blob" of terrain at a specified point (or could be placed at a random point with `createAreas`. The parameters mean the following:
     
    6364  * '''x, z''': Optional tile coordinates of placer.
    6465
    65 === Other placers ===
     66==== Other placers ====
    6667
    6768 * `RectPlacer(x1, z1, x2, z2)`: Places a grid-aligned rectangle from (x1,z1) to (x2,z2), where x1 < x2 and z1 < z2. Not usable with `createAreas` since it's not a centered placer.
    6869
    69 == Area painters ==
     70=== Area painters ===
    7071
    7172The following area painters are available. Remember that terrains can be any of the objects in the "A Note on Terrains" section above.
     
    8081  * If the `type` is set to `ELEVATION_MODIFY`, it raises/lowers all tiles in the area by the specified amount (for example, elevation = 2 would increase them by 2 and elevation = -3 would lower them by 3).
    8182
    82 = Placing Units: Object Groups =
     83== Placing Units: Object Groups ==
    8384
    8485An ''object'' or ''entity'' is the game's representation of various units, buildings, and props that occur on a map. You can place objects in a similar way to painting terrains by using ''object groups''. An object group is one or more types of objects which can be placed according to an optional constraint. This process is analogous to creating an area, but it doesn't modify the terrain.
     
    9091 * (Optional) '''minAngle''', '''maxAngle''': The variation in angle of placed objects (to make them all face the same direction, set these equal). Default to 0 and 2*PI, respectively.
    9192
    92 == Creating a single object group ==
     93=== Creating a single object group ===
    9394
    9495To place one object group at a known location, use the function `createObjectGroup(placer, player, constraint)`. Given a placer, player ID, and optional constraint, it will try to create the object group. If successful it will return `true`, or `false` on failure.
    9596
    96 == Creating multiple object groups at random locations ==
     97=== Creating multiple object groups at random locations ===
    9798
    9899Just like `createAreas` for terrains, there is a `createObjectGroups(placer, player, constraint, number, retryFactor)` function for placing multiple object groups at random locations.
    99100
    100 == Object group placers ==
     101=== Object group placers ===
    101102
    102103Currently there is only one object group placer `SimpleGroup(objects, avoidSelf, tileClass, x, z)`:
     
    106107 * (Optional) '''x, z''': Tile coordinates of the center of the placer.
    107108
    108 = Grouping Similar Features: Tile Classes =
     109== Grouping Similar Features: Tile Classes ==
    109110
    110111In random maps, it is often the case that terrain types and objects will be interconnected. Also when creating the map, we want to avoid some features when placing others. One way of achieving this is by using ''tile classes''. Tile classes can be painted like terrains, although they don't affect the appearance by themselves. They are like placeholders that tell the map script where to place or avoid placing other things. An example usage of tile classes could be to define a "base" area at the starting location of each player. Within this area you probably would want to exclude some things: forests, lakes, and opponents. Likewise you'd want to include resources like berry bushes and sheep.
    111112
    112 == Working with tile classes ==
     113=== Working with tile classes ===
    113114
    114115To create a tile class call `createTileClass()` which will return a new integer ID. Store the ID in a variable for future reference. If you want to get the tile class object, call `getTileClass(id)` and it will return the object or `undefined` if the ID was invalid.
     
    116117Points can be added individually to a tile class with `addToClass(x, z, id)`. In practice this would be tedious, and one advantage of areas is they allow a simple representation of points. There is a special area painter just for this purpose, `TileClassPainter(tileClass)`. This could be used directly if you have a tile class object, but more common is using the `paintClass(id)` helper function, which will return a `TileClassPainter` matching the given ID.
    117118
    118 = Controlling Placement: Constraints =
     119== Controlling Placement: Constraints ==
    119120
    120121Both areas and object groups use ''constraints'' to limit their placement to specific parts of the map. This is usually the key to making realistic and fair random maps. For example, on most maps, you want a number of clumps of forest, but you want them to be spread out to make most areas of the map reachable, so you will probably want to use an "avoid forest by X meters" constraint on your forest objects. Similarly, you want iron mines to be spread out fairly, and you also don't want them to be inside forests, or under water. If you're making some kind of "king of the hill" map though, you might want the same mines to be only in some area in the center of the map. The list goes on.
     
    135136 * `avoidClasses(...)`: Avoid all the given tile classes by the minimum distances specified.
    136137
    137 = Map Helpers =
     138== Map Helpers ==
    138139
    139140These functions are for accessing properties of the map settings:
     
    144145 * `isCircularMap()`: Returns true if the map is circular.
    145146
    146 = Environment Helpers =
     147== Environment Helpers ==
    147148
    148149The environment of a map represents sky, lighting, and water settings. For example a tropical island map might have a clear blue sky, bright sun, and light blue water, whereas a temperate map might have muddy water and an overcast sky. The environment doesn't affect gameplay but does provide a more realistic setting. The following are some functions to adjust the environment of a random map.
     
    165166  * `setWaterReflectionTintStrength(s)`
    166167
    167 = Miscellaneous Helpers =
     168== Miscellaneous Helpers ==
    168169
    169170The following utility functions are available to scripts. Especially useful are the randomization functions for when you want parameters like terrains or area sizes to vary.
     
    174175 * `chooseRand(...)`: Returns one of its arguments at random (takes any number of arguments).
    175176
    176 = Script Library =
     177== Script Library ==
    177178
    178179These are the scripts that are part of the rmgen library: