// Movement Grid Handler.
// Worthless Bums 2013.


// Fill an array with the tiles the active character can move to.
function getMoveTiles (%characterIndex)
{//echo("getMoveTiles()");getMoveTiles(3);
	// Get out if the specified character is not valid.
	if (!isObject($playerSquad[%characterIndex]))
	{
		return false;
	}
	
	// Need to clear the array for the max action point size first!
	// Nothing here yet!
	
	// Flag each tile that can be reached from the active character's tile position.
	%size = $playerSquad[%characterIndex].currentActionPoints;
	%xIndex = $playerSquad[%characterIndex].xIndex;
	%yIndex = $playerSquad[%characterIndex].yIndex;
	for (%i = -1 * %size; %i <= %size; %i++)
	{
		for (%j = -1 * %size; %j <= %size; %j++)
		{
			%distance = mRound(mAbs(VectorDist(%xIndex SPC %yIndex, (%xIndex + %i) SPC (%yIndex + %j))));
			if (%distance < mAbs(%size)								&&
				!isObject($mazeRoom[%xIndex + %i, %yIndex + %j])	&&
				$fogOfWar.isClear(%xIndex + %i, %yIndex + %j))
			{
				$MoveTiles[%i + %size, %j + %size] = 1;		// Can move to this tile.
				// Set movable tile indicator at indices (%xIndex + %i) SPC (%yIndex + %j).
				%explosionPosition = getTilePositionFromIndices(%xIndex + %i, %yIndex + %j);
				%moveTileIndicator = new Sprite()
				{
					SceneLayer = 0;
					scenegraph = levelSceneGraph;
					Animation = "Bloat_Death_Explosion_FramesAnimation";
					canSaveDynamicFields = "1";
					position = %explosionPosition;
					size = "10.000 10.000";
				};
				addObjectToScene(%moveTileIndicator);
			}
			else
			{
				$MoveTiles[%i + %size, %j + %size] = 0;		// Can't move to this tile.
			}
		}
	}
	// Add the four cardinal direction points.
	$MoveTiles[%size, 0] = 1;			// North.
	$MoveTiles[%size, 2 * %size] = 1;	// South.
	$MoveTiles[2 * %size, %size ] = 1;	// East.
	$MoveTiles[0, %size] = 1;			// West.
	
	
	// DEBUG: Print the array.
	/*for (%i = -1 * %size; %i <= %size; %i++)
	{
		%row = "";
		for (%j = -1 * %size; %j <= %size; %j++)
		{
			%row = %row @ $MoveTiles[%i + %size, %j + %size];
		}
		echo(%row);
	}*/
	// END DEBUG
}