// Ammunition Handler.
// Worthless Bums 2012.


function characterHasRequiredAmmo (%characterIndex, %ammoAmount)
{//echo("characterHasRequiredAmmo()");
	if (weaponHasRequiredAmmo(%characterIndex))
	{
		return true;
	}
	return false;
}
function weaponHasRequiredAmmo (%characterIndex)
{//echo("weaponHasRequiredAmmo()");echo("$playerSquad[%characterIndex].weapon).currentAmmo =" SPC ($playerSquad[%characterIndex].weapon).currentAmmo);
	if (($playerSquad[%characterIndex].weapon).currentAmmo > 0)
	{
		return true;
	}
	if (isLargeUnit($playerSquad[%characterIndex]))
	{
		return true;
	}
	return false;
}
function reloadWeapon ()
{//echo("reloadWeapon()");
	if ($generateTutorialLevel)
	{
		if ($tutorialSection == 6)
		{
			tutorialMessage7();
		}
	}
	if ($playerSquad[$activeCharacter].ammo > 0)
	{
		if (($playerSquad[$activeCharacter].weapon).currentAmmo > 0)
		{
			($playerSquad[$activeCharacter].weapon).currentAmmo = ($playerSquad[$activeCharacter].weapon).capacity + 1;
		}
		else
		{
			($playerSquad[$activeCharacter].weapon).currentAmmo = ($playerSquad[$activeCharacter].weapon).capacity;
		}
		
		$playerSquad[$activeCharacter].ammo--;
		if ($playerSquad[$activeCharacter].ammo < 0)
		{
			$playerSquad[$activeCharacter].ammo = 0;
		}
	}
	if (!isLargeUnit($playerSquad[$activeCharacter]))
	{
		playMarineReloadAnimation($activeCharacter);
	}
	($playerSquad[$activeCharacter].weapon).weaponType = setWord(($playerSquad[$activeCharacter].weapon).weaponType, 9, ($playerSquad[$activeCharacter].weapon).currentAmmo);
	playAudio("Audio:weaponSwap", EffectsAudioVolume.value);
	updateInventoryTabInformation();
	updateFirearmReloadReadout();
}
function reloadCharacterWeapon (%characterIndex)
{//echo("reloadCharacterWeapon()");
	if ($playerSquad[%characterIndex].ammo > 0)
	{
		if (($playerSquad[%characterIndex].weapon).currentAmmo > 0)
		{
			($playerSquad[%characterIndex].weapon).currentAmmo = ($playerSquad[%characterIndex].weapon).capacity + 1;
		}
		else
		{
			($playerSquad[%characterIndex].weapon).currentAmmo = ($playerSquad[%characterIndex].weapon).capacity;
		}
		$playerSquad[%characterIndex].ammo--;
		if ($playerSquad[%characterIndex].ammo < 0)
		{
			$playerSquad[%characterIndex].ammo = 0;
		}
	}
	playMarineReloadAnimation(%characterIndex);
	($playerSquad[%characterIndex].weapon).weaponType = setWord(($playerSquad[%characterIndex].weapon).weaponType, 9, ($playerSquad[%characterIndex].weapon).currentAmmo);
	playAudio("Audio:weaponSwap", EffectsAudioVolume.value);
	updateInventoryTabInformation();
}