// Handles mounting of weapon sprites to character sprites.
// Worthless Bums 2012.


function mountWeaponToCharacter (%weapon, %characterIndex)
{//echo("mountWeaponToCharacter()");
	if (isObject($playerSquad[%characterIndex].weaponSprite))
	{
		($playerSquad[%characterIndex].weaponSprite).safeDelete();
	}
	$playerSquad[%characterIndex].weapon = %weapon;
	%weaponSprite = new Sprite("WeaponSprite")
	{
		SceneLayer = 2;
		group = 2;
		position = "-4000, -4000";
		scenegraph = levelSceneGraph;
		imagemap = ($playerSquad[%characterIndex].weapon).imageMapName;
		visible = false;
		size = "4 4";
	};
	addObjectToScene(%weaponSprite);
	%mountForce = 50;
	//%weaponSprite.mount($playerSquad[%characterIndex], 0.0, 0.0, %mountForce, true, true, true, true);
	$playerSquad[%characterIndex].weaponSprite = %weaponSprite;
	%unit = $playerSquad[%characterIndex];
	switch (%unit.facing)
	{
		case $northDirection:
			//%weaponSprite.dismount();
			%weaponSprite.setFlipX(1);
			%weaponSprite.SceneLayer = 4;
			//%weaponSprite.mount(%unit, 0.0, 0.0, 50.0, true, true, true, false);
			
		case $southDirection:
			//%weaponSprite.dismount();
			%weaponSprite.setFlipX(0);
			%weaponSprite.SceneLayer = 2;
			//%weaponSprite.mount(%unit, 0.0, 0.0, 50.0, true, true, true, false);
			
		case $eastDirection:
			//%weaponSprite.dismount();
			%weaponSprite.setFlipX(0);
			%weaponSprite.SceneLayer = 2;
			//%weaponSprite.mount(%unit, 0.0, 0.0, 50.0, true, true, true, false);
			
		case $westDirection:
			//%weaponSprite.dismount();
			%weaponSprite.setFlipX(1);
			%weaponSprite.SceneLayer = 4;
			//%weaponSprite.mount(%unit, 0.0, 0.0, 50.0, true, true, true, false);
	}
	updateSquadInfoGui();
}
function giveRandomWeapon (%squadMember, %dungeonLevel)
{//echo("giveRandomWeapon()");
	%weaponCode = createRandomWeapon(%squadMember, %dungeonLevel, $weaponProjectileBallisticType);
	%weapon = createNewWeapon(%weaponCode);
	mountWeaponToCharacter(%weapon, %squadMember);
}
function clearSquadWeapons ()
{//echo("clearSquadWeapons()");
	if (isObject($playerSquad[0].weaponSprite))
	{
		$playerSquad[0].weaponSprite.safeDelete();
	}
	if (isObject($playerSquad[1].weaponSprite))
	{
		$playerSquad[1].weaponSprite.safeDelete();
	}
	if (isObject($playerSquad[2].weaponSprite))
	{
		$playerSquad[2].weaponSprite.safeDelete();
	}
	if (isObject($playerSquad[3].weaponSprite))
	{
		$playerSquad[3].weaponSprite.safeDelete();
	}
}