// Generates a random walk dungeon.
// Worthless Bums 2012.


function generateRandomWalkDungeon (%size, %mapType)
{//echo("generateRandomWalkDungeon()");
	destroyMazeRoom();
	$mazeRoom[%size, %size] = 0;
	$mazeDimension = %size;
	$mazeLength = %size * %size;
	$dummyRoom[%size, %size] = 0;
	for (%i = 0; %i < %size; %i++)			// Rows.
	{
		for (%j = 0; %j < %size; %j++)		// Columns.
		{
			// Make every tile a wall
			$dummyRoom[%i, %j] = 0;
		}
	}
	%xIndex = 2;//getRandom(1, $mazeDimension - 2);
	%yIndex = 2;//getRandom(1, $mazeDimension - 2);
	%tilesToWalk = 4096;		// Arbitrary at the moment.
	for (%i = 0; %i < %tilesToWalk; %i++)
	{//echo("%i =" SPC %i);
		%canWalk = false;
		do {
			%direction = getRandom(0, 3);
			switch (%direction)
			{
				case 0:		// North.
					if (%yIndex - 1 > 0)
					{//echo("walking NORTH!");
						%yIndex--;
						%canWalk = true;
					}
				
				case 1:		// South.
					if (%yIndex + 1 < $mazeDimension - 1)
					{//echo("walking SOUTH!");
						%yIndex++;
						%canWalk = true;
					}
				
				case 2:		// East.
					if (%xIndex + 1 < $mazeDimension - 1)
					{//echo("walking EAST!");
						%xIndex++;
						%canWalk = true;
					}
				
				case 3:		// West.
					if (%xIndex - 1 > 0)
					{//echo("walking WEST!");
						%xIndex--;
						%canWalk = true;
					}
			}
		} while (!%canWalk)
		$dummyRoom[%xIndex, %yIndex] = 1;
	}
	$dummyRoom[1, 1] = 1;
	$dummyRoom[2, 2] = 1;
	$dummyRoom[2, 1] = 1;
	$dummyRoom[1, 2] = 1;
	%ratioCeiling = 0.60;
	%ratioFloor = 0.50;
	%floorToWallRatio = getFloorToWallRatio();
	createDungeonType(%mapType);
}
function getFloorToWallRatio ()
{//echo("getFloorToWallRatio()");
	%floors = 0;
	%walls = 0;
	for (%i = 0; %i < $mazeDimension; %i++)
	{
		for (%j = 0; %j < $mazeDimension; %j++)
		{
			if ($dummyRoom[%i, %j] == 0)
			{
				%walls++;
			}
			else
			{
				%floors++;
			}
		}
	}
	return %floors / %walls;
}