// Lifted Tile Handler.
// Worthless Bums 2013.


function createNewLiftedTileArray ()
{//echo("createNewLiftedTileArray()");
	$mazeLiftedTiles[$mazeDimension, $mazeDimension] = 0; 
}
function spawnLiftedFloorTile (%xIndex, %yIndex)
{//echo("spawnLiftedFloorTile()");
	// Create grating tile to fit underneath.
	%liftedTileGrating = new Sprite("lifted tile grating")
	{
		status = 1;
		SceneLayer = $LiftedTileLayer;
		position = getTileShiftedPositionFromIndices(%xIndex, %yIndex);
		scenegraph = levelSceneGraph;
		image = "Sprites:underGrating";
		visible = true;
		size = "4 4";
		xIndex = %xIndex;
		yIndex = %yIndex;
		liftedTile = null;
		shadow = null;
	};
	addObjectToScene(%liftedTileGrating);
	// Create actual lifted floor tile.
	%frame = getRandom(78, 79);
	%liftedTile = new Sprite("lifted tile")
	{
		status = 1;
		SceneLayer = $LiftedTileLayer;
		graph = $LiftedTileGraph;
		position = getLiftedTilePositionFromIndices(%xIndex, %yIndex);
		scenegraph = levelSceneGraph;
		image = getImageFromOverworldLocation();
		frame = %frame;
		visible = true;
		size = "4 4";
		xIndex = %xIndex;
		yIndex = %yIndex;
	};
	addObjectToScene(%liftedTile);
	// Created lifted tile shadow.
	%liftedTileShadow = new Sprite("lifted tile shadow")
	{
		status = 1;
		SceneLayer = $LiftedTileShadowLayer;
		graph = $LiftedTileShadowGroup;
		position = getTileShiftedPositionFromIndices(%xIndex, %yIndex);
		scenegraph = levelSceneGraph;
		imagemap = "Sprites:LiftedTileShadow";
		visible = true;
		size = "9 9";
		xIndex = %xIndex;
		yIndex = %yIndex;
	};
	addObjectToScene(%liftedTileShadow);
	%liftedTileGrating.shadow = %liftedTileShadow;
	%liftedTileGrating.liftedTile = %liftedTile;
	$mazeLiftedTiles[%xIndex, %yIndex] = %liftedTileGrating;
}
function handleLiftedTileMarker (%unit)
{//echo("handleLiftedTileMarker()");
	if (isObject($mazeLiftedTiles[%unit.xIndex, %unit.yIndex]))
	{//echo("on lifted tile!");
		if (isObject(%unit.liftedTileMarker))
		{
			(%unit.liftedTileMarker).safeDelete();
		}
		%liftedTileMarker = createLiftedTileMarkerAnimation(%unit);
		%unit.liftedTileMarker = %liftedTileMarker;
	}
	else
	{//echo("NOT on lifted tile!");
		if (isObject(%unit.liftedTileMarker))
		{//echo("deleting marker!");
			(%unit.liftedTileMarker).safeDelete();
		}
	}
}