Tutorial: Map Generator - Randomness

This is the third part of the map generator tutorial. The previous part can be found here, and should be completed before trying this part of the tutorial. In the two previous parts you learned how to create overlays and combined them with logical operators, use algorithms and how to transform them. These ingredients do allow you to build some basic maps already, as seen in the previous exercise, but we need one more aspect of the map generator to make landscapes really interesting. That aspect is randomness and is treated in this part of the tutorial. There are two ways randomness is introduced into maps, these are through algorithms that behave randomly and through a single transformation called turbulence.

Turbulent Lines

Straight lines deformed randomly!

So let's start with introducing turbulence. For this purpose a new algorithm is introduced, the lines algorithm. It draws straight vertical lines where the parameter a determines the line width and b the distance between the lines. Therefore b must always be chosen larger than a, otherwise the whole overlay will be filled completely. Furthermore we will introduce two new attributes which together specify the turbulence transformation. First there is the turbulence attribute - which takes the values 10, 100, 1000 and 10000 - specifying the amount of deformation of the layer. Second the lambda attribute can be used to repeat the deformation process up to 20 times. So now let's take a look at this piece of map generator code and the result.

// Straight lines made interesting.
map ExampleTurbulentLines {
	mat=Water; tex=water;
	overlay {
		algo=lines; a=10; b=20;
		mat=Gold; tex=gold;
		turbulence=10; lambda=0;
	};
};

You will have noticed that the straight golden lines of the algorithm are deformed quite smoothly by the applied turbulence. Turbulence uses a sine function to shift randomly shift the points of a layer, which transforms regular shapes into disordered and curved ones. Now try larger values for the turbulence and lambda attributes and observe there effects. Turbulence is a crucial attribute and you will need it in almost any dynamic map you design.

Random Points

Everywhere gold and rock.

Random behaviour in the map generator can also be induced through the use of algorithms, the random algorithm is one of these. It draws random points, the parameter a determines the likelihood a point is being drawn. A point is less likely drawn if a is increased.

// Random gold and rock points.
map ExampleRandomPoints {
	mat=Water; tex=water;
	overlay {
		algo=random; a=10;
		mat=Gold; tex=gold;
	};
	overlay {
		algo=random; a=30;
		mat=Rock; tex=rock;
	};
};

In this example we see that quite a few golden points are drawn in the water. On top of this some rock points are drawn. As expected a lot less rock points were drawn, cause a is higher in that overlay. Note that zoom transformations do not have any effect on the point size of this algorithm. As a side effect the other transformations won't have an effect either because points are the smallest quantity the map generator works on.

Random Boxes

[TODO: Explain rndchecker algorithm]

Exercise

[TODO: Exercise where underground materials must be created.]

Summary

[TODO: Summarize]

The next part of this tutorial about some special features is here.