// Handles Advanced Monster AI.
// Worthless Bums 2012.


/*
	 Origin is now the current square.
	 1: Origin is now the current square.
	 2: select an adjacent square who's still set to 0.
		if there's none, goto 5.
		
	 3: give the selected square a value of the current square +1.
		if the selected square is the target, goto 7
		
	 4: push selected square onto a list of unfinished squares. goto 2.
	 
	 5: shift the first value from the unfinished list, make it the current square.
	 6: goto 2.
	 
	 7: Target is now the current square.
	 8: select an adjacent square.
	 9: if selected square's value is current square -1, set it to the current square.
		if it's not, goto 8.
		
	10: store the position of the current square relative to the selected square
		(Nort, East, South, West etc.)
		if it's the origin, goto 12 after that.
		
	11: goto 8.
	
	12: return list of directions
 */
// Returns Sim Set of direction moves to reach target.
function findEfficientPath (%startX, %startY, %endX, %endY)
{//echo("findEfficientPath()");
	// Fill tile value map.
	%tileValueMap[64, 64] = 0;		// Zero all values.
	
	// Track the current (start) tile.
	%currentX = %startX;
	%currentY = %startY;
	
	// Select a 0 value adjacent tile.
	%foundZeroTile = false;
	// North.
	if (%currentY - 1 >= 0)
	{
		if (%tileValueMap[%currentX, %currentY - 1] == 0)
		{
			// Flag tile as found.
			%foundZeroTile = true;
			// Assign current tile value + 1.
			%tileValueMap[%currentX, %currentY - 1] = %tileValueMap[%currentX, %currentY] + 1;
		}
	}
	// South.
	if (%currentY + 1 >= 0)
	{
		if (%tileValueMap[%currentX, %currentY + 1] == 0)
		{
			// Flag tile as found.
			%foundZeroTile = true;
			// Assign current tile value + 1.
			%tileValueMap[%currentX, %currentY + 1] = %tileValueMap[%currentX, %currentY] + 1;
		}
	}
	// East.
	if (%currentX + 1 < 64)
	{
		if (%tileValueMap[%currentX + 1, %currentY] == 0)
		{
			// Flag tile as found.
			%foundZeroTile = true;
			// Assign current tile value + 1.
			%tileValueMap[%currentX + 1, %currentY] = %tileValueMap[%currentX, %currentY] + 1;
		}
	}
	// West.
	if (%currentX - 1 >= 0)
	{
		if (%tileValueMap[%currentX - 1, %currentY] == 0)
		{
			// Flag tile as found.
			%foundZeroTile = true;
			// Assign current tile value + 1.
			%tileValueMap[%currentX - 1, %currentY] = %tileValueMap[%currentX, %currentY] + 1;
		}
	}
	
	// If we didn't find a zero tile...
	if (!%foundZeroTile)
	{
		// ...
	}
	
}
function getMonsterAtIndices (%xIndex, %yIndex)
{//echo("getMonsterAtIndices()");
	for (%i = 0; %i < $MonsterList.getCount(); %i++)
	{
		%monster = $MonsterList.getObject(%i);
		if (%monster.xIndex == %xIndex	&&
			%monster.yIndex == %yIndex)
		{
			return %monster;
		}
	}
}