/**
 * Name: Standard map script.
 * By:   FireFly (firefly.nu).
 * Date: 2009-04-22.
 */
function generateStandardMap(width, height, types, probability, amount, multiplier) {
	var landTiles = 0;
	var map = new Array(width);
	var setGrass = function(x, y, prob) {
		if (x<0 || y<0 || x>=width || y>=height || map[x][y].type == types[0] || landTiles/(1.0*width*height)>=amount ||  Math.random()>prob)
			return;
		map[x][y] = new MapTile(x, y, types[0]);
		landTiles++;

		for (var i=-1; i<2; i++)
			for (var j=-1; j<2; j++)
				setGrass(x-i, y-j, prob*multiplier);
	}
	
		// Fyll med vatten.
	for (var x=0; x<map.length; x++) {
		map[x] = new Array(height);
		for (var y=0; y<map[x].length; y++)
			map[x][y] = new MapTile(x, y, types[1]);
	}
	
	var x, y;
	while (landTiles/(1.0*width*height) < amount) {
		x = Math.floor(Math.random()*width);
		y = Math.floor(Math.random()*height);
		setGrass(x, y, probability);
	}
	
	
	debugln("Karta: "+Math.round(landTiles/(width*height)*100)+"% land ("+width+"x"+height+").");
	debugln(" -- Karta genererad!");
	return map;
}