// Handles Barrels.
// Worthless Bums 2012.


// Returns true iff the specified indices has a barrel on it.
function hasBarrel (%xIndex, %yIndex)
{//echo("hasBarrel()");
	for (%i = 0; %i < $barrelList.getCount(); %i++)
	{
		%barrelX = ($barrelList.getObject(%i)).xIndex;
		%barrelY = ($barrelList.getObject(%i)).yIndex;
		if (%xIndex == %barrelX	&&
			%yIndex == %barrelY)
		{
			return %i;
		}
	}
	return -1;
}
function smashBarrel (%barrelIndex)
{//echo("smashBarrel()");
	$GlobalStats.totalCratesSmashed++;
	%barrel = $barrelList.getObject(%barrelIndex);
	if (%barrel.imagemap $= "ExplosiveBarrelImageMap")
	{
		handleGrenadierExplosion(%barrel.xIndex, %barrel.yIndex);
		grenadeEmptyAoePathDamage(%barrel.xIndex, %barrel.yIndex, $northDirection);
	}
	else
	{
		playAudio("Audio:barrelSmash", EffectsAudioVolume.value);
		%range = 10.0;
		wakeNearbyMonsters(%barrel.getPosition(), %range);
		spawnRandomItem(%barrel.xIndex, %barrel.yIndex);
	}
	%barrel.safeDelete();
	autoTargetEnemyUnit($autoTargetDelay * 2);
}