/**
 * Name: Main isoGame script file.
 * By:   FireFly (firefly.nu).
 * Date: 2009-04-22.
 * 
 * ---[ Log: ]---
 * × 09-04-17: First version, generates an isometric map (the format of a larger isometric tile). Only grass. (Only map.js.)
 * × 09-04-20: Adds water; 100% random maps (each tile has a certain chance of grass/water).
 * × 09-04-22: Moves scripts to js folder, separates styles to an external css file. Places the map generator file in a separate file, updates to better represent continents. (Algorithm: Place a tile, check if enough amount of grass; if not, has a certain chance of repeating the algorithm on nearby cells. This chance decreases further away from starting point.) Starting with water bordering tiles; creates units.js, moves global vars and init to (the new) main.js.
 */

	/*** Global variables ***/
var map, tileTypes; // Arrays.
var elMap; // Elements.

var width, height;

	/*** Debug variables ***/
var debugIndent = 0;

	/*** function: init (start of script) ***/
function init() {
	var gameDiv = document.getElementById('gamefield');
	if (typeof(elMap) != 'undefined')
		gameDiv.removeChild(elMap);
	
		// Create new 'map' div.
	elMap = document.createElement('div');
	elMap.id = 'map';
	gameDiv.appendChild(elMap);
	
		// Setup stuff.
	setupTiles();
	doMapGeneration();
	setupMap();
}

function doMapGeneration() {
	width       = parseInt(document.getElementById('settWidth').value);
	height      = parseInt(document.getElementById('settHeight').value);
	var amount      = parseFloat(document.getElementById('settAmount').value);
	var probability = parseFloat(document.getElementById('settProbability').value);
	var multiplier  = parseFloat(document.getElementById('settMultiplier').value);
	
	debugln("Genererar karta... "); debugIndent++;
	map = generateStandardMap(width, height, tileTypes, probability, amount, multiplier);
	debugIndent--;
	debugln("klar!");
}

function debug(str) {
	for (var i=0; i<debugIndent; i++)
		str = '&nbsp;&nbsp;&nbsp;&nbsp;'+str;
	document.getElementById('debug').innerHTML += str.replace(/\n/, '<br/>');
}
function debugln(str){
	debug(str+'<br/>');
}