# Map Generator

Map Generator
Besides simple dynamic maps defined in Scenario.txt there is also a powerful dynamic map generator for highly complex yet fully random maps.
This generator works with nested layers that can be combined using various operators and to which a material value and various attributes can be assigned to describe their resulting shape. The map generator will generate a map using these layers. The map is then later zoomed to the landscape as a static map would be.
The structure of maps, layers, and attributes is stored in the component Landscape.txt in the scenario.
Syntax
The language describing this structure works with objects, attributes, and operators and is case sensitive. Objects are defined as follows:
Object_type [Name] { Attribute };
The name is optional. Current objects types are map, overlay, and point (for the poly algorithm). If an object is known it can later be used for another instance which is defined with:
Name { Attribute };
Here, the previously defined object 'Name' is copied and optionally extended by the given attributes. If no additional attributes are defined, the brackets can be omitted.
General attribute syntax is:
Attribut=Value;
Attributes can be defined in any order within the object. They can optionally have % or px as unit and can be specified as single value or range of values (val1 - val2). In case of a duplicate assignment the last value is evaluated.
In addition to attributes there can be nested sub-objects which can be combined using operators:
Object1 Operator Object2;
Operator statements can have any length and control the combination of layers. Operators are: | (OR), & (AND), ^ (XOR).
You will find several examples in the Dynamic Worlds folder.
Attributes
Layers (overlay)
The following attributes are defined:

Attribute
Type
Description
mat
Material
Material. The material must be defined in the active Material.ocg. Default is Sky.
tex
Texture
Texture. The material-texture combination should be defined in the active TexMap.
x, y, wdt, hgt
Integer
Size of the specified layer as a percentage of the layer above.
algo
Algorithm
Area fill type. For a list of available fill types see fill algorhythms.
zoomX, zoomY
Integer
Specifies the scale applied to the fill pattern. -100 to +99.
ox, oy
Integer
Offset to the fill pattern in percent. You can use this e.g. to shift a sine curve.
a, b
Integer
Additional parameters for the fill pattern.
turbulence
Integer
10 to 10,000; layer deformation
rotate
Integer
-180 to +180; rotation of the layer.
invert
Boolean
0 or 1; if 1 the layer filling is inverted.
seed
Integer
Random seed for layer generation. Each seed will create a unique random layer.
loosebounds
Boolean
Determines whether the area limits are also affected by rotate, turbulence, ox, and oy.
mask
Boolean
0 or 1; if 1 the layer is never drawn. This does not affect sub-layers.
grp
b
0 or 1; if 1 the layer is considered set if the local algorithm or the algorithm of one of the sub-layers returns true. If an operator follows, the layer itself is not drawn.
sub
Boolean
0 or 1; if 1 the material is considered underground (default)
lambda
Integer
0 to 20; additional turbulence iterations

Maps
Maps generally can have the same attributes as layers. However, only mat, tex, and sub are really useful for maps and determine the background filling.
Fill Algorithms
To decide whether a point on a map hits a given layer, it is first transformed (zoom, turbulence, rotate, ox/oy) and then processed in the layer's algorithm. Also it is checked against the mask boundaries (x, y, wdt, hgt). This is usually done before, but with loosebounds after the transformation.

solid
  Default algorithm. Always true.
random
  Random points. The parameter specifies probability. The higher a, the less likely the point is set.
checker
  Alternating boxes of size 10 (at normal zoom).
bozo
  Specks. Parameter a can be used to reduce speck size.
sin
  Horizontal sine curve. In standard zoom the amplitude is 10, the period 20 pixels.
boxes
  Orderly boxes. Parameter a defines block size, b the distance of block centers.
rndchecker
  As checker, but not in alternating but in random order.
lines
  Vertical lines. Parameter a defines line width, b defines distance between lines.
border
  Draws an inner border in the parent layer (or the whole operator chain respectively). a and b are the horizontal and vertical border width. Because the superior layer needs to be accessed for calculation, it cannot be defined as a group (grp).
mandel
  Draws the Mandel fractal into the target area. Parameter a specifies iteration depth (default 1000). With no zoom, the complete "Apfelmännchen" is drawn (corresponding to -2-2i to 2+2i).
rndall
  The complete area is filled, or not filled, with probability a (in percent). Using this algorithm you could for example specify multiple maps as sub maps of a mask=1 layer and one of these maps would be randomly chosen.
script
  This algorithm is defined via a scenario script function of the following form:
  `func ScriptAlgo[Overlay-Name](x, y, alpha, beta)` The script function's return value should be 0 (no material) or 1 (material). x and y are the pixel coordinates for which the function is called. iAlpha and iBeta correspond to parameters a and b. If the layer has no name, the function "ScriptAlgo" is used.
poly
  Returns true for pixels within the specified polygon. Points are specifed using
  `point { x=<X-Coordinate of the vertex><Unit>; y=<Y-Coordinate>><Unit>; };` Example: `overlay { algo=poly; mat=Earth; point { x=10px; y=25%; }; point { x=20px; y=25%; }; point { x=10px; y=75%; }; point { x=20px; y=75%; }; point { x=30px; y=50%; }; };`

Operators
Multiple layers can be combined using operators. This are evaluated from top to bottom and only the bottom most result of the chain is drawn. In a group (grp) the child layers are taken into the calculation but not actually drawn. Operators are | (OR), & (AND), ^ (XOR).
Sven2
2001-07