// Grating Handler.
// Worthless Bums 2012.


function spawnGrating (%xIndex, %yIndex, %burst)
{//echo("spawnGrating()");
	%frame = 49;
	if (%burst)
	{
		%frame = 50;
	}
	%grating = new Sprite("grating")
	{
		status = 1;
		SceneLayer = $BaseTileLayer;
		position = getTileShiftedPositionFromIndices(%xIndex, %yIndex);
		scenegraph = levelSceneGraph;
		image = getImageFromOverworldLocation();
		frame = %frame;
		visible = true;
		size = "4 4";
		xIndex = %xIndex;
		yIndex = %yIndex;
	};
	addObjectToScene(%grating);
	$gratingList.add(%grating);
	return %grating;
}
function addSteamVentingAnimations ()
{//echo("addSteamVentingAnimations()");
	for (%i = 0; %i < $gratingList.getCount(); %i++)
	{
		createSteamVentingAnimation($gratingList.getObject(%i));
	}
}
function burstTappedWallMonster ()
{//echo("burstTappedWallMonster()");
	if ($TappingWallTileX >= 0	&&
		$TappingWallTileY >= 0)
	{
		// Make sure this is still a wall tile!
		if (isObject($mazeRoom[$TappingWallTileX, $TappingWallTileY]))
		{
			destroyTerrainTile($TappingWallTileX, $TappingWallTileY);
			showAdjacentTileDestruction($TappingWallTileX, $TappingWallTileY);
			playRandomHeavyMetalSfx();
			$fogOfWar.showFogOfWar();
			%monsterSpawn = spawnRandomMonster($TappingWallTileX, $TappingWallTileY);
			$monsterList.add(%monsterSpawn);
			setMonsterFacing(getRandom(1, 4), %monsterSpawn);
		}
		// Reset tapping regardless of wall status!
		$TappingWallTileX = -1;
		$TappingWallTileY = -1;
	}
}