// Handles the character readout.
// Worthless Bums 2012.


// Updated character readouts.
function updateReadouts ()
{//echo("updateReadouts()");
	initializeReadout();
}

// Calculates the inner bar's x-position shift when resizing.
function calculateNewInnerBarPosition (%x, %xMax)
{//echo("calculateNewInnerBarPosition()");
	// Esoteric estimation, but it works!
	return (7.0 * (1.0 - %x / %xMax));
}

// Initializes character readout.
// Note readout currently does not "handle" dead squad members!
function initializeReadout ()
{//echo("initializeReadout()");
	// Hooked to Inventory Tab Information.
	updateInventoryTabInformation();
	updateSquadMemberFloatingHealthPoints();
	updateSquadMemberFloatingActionPoints();
}

// Clears all a squad member's health blocks.
function clearSquadMemberHealthBlocks (%characterIndex)
{//echo("clearSquadMemberHealthBlocks()");
	for (%i = 1; %i <= 20; %i++)
	{
		setHealthBlock(%characterIndex, %i, 0, 0);
	}
	switch ($playerSquad[%characterIndex].characterClass)
	{
		case 0:
			leaderHealthLeftBrace.setVisible(0);
			leaderHealthRightBrace.setVisible(0);
		case 1:
			scoutHealthLeftBrace.setVisible(0);
			scoutHealthRightBrace.setVisible(0);
		case 2:
			grenadierHealthLeftBrace.setVisible(0);
			grenadierHealthRightBrace.setVisible(0);
		case 3:
			supportHealthLeftBrace.setVisible(0);
			supportHealthRightBrace.setVisible(0);
		case 4:
			engineerHealthLeftBrace.setVisible(0);
			engineerHealthRightBrace.setVisible(0);
	}
}

// Sets a health block's bitmap.
function setHealthBlockBitmap (%healthBlock, %bit)
{//echo("setHealthBlockBitmap()");
	if (%bit)
	{
		%healthBlock.setBitmap("../../../Sprites/1/assets/images/UI/healthBlock");
	}
	else
	{
		%healthBlock.setBitmap("../../../Sprites/1/assets/images/UI/healthBlockFaded");
	}
}
// Sets an action block's bitmap.
function setActionBlockBitmap (%actionBlock, %bit)
{//echo("setActionBlockBitmap()");
	if (%bit)
	{
		%actionBlock.setBitmap("../../../Sprites/1/assets/images/UI/actionBlock");
	}
	else
	{
		%actionBlock.setBitmap("../../../Sprites/1/assets/images/UI/actionBlockFaded");
	}
}
// Sets a health block on or off given the specified character index and bit.
function setHealthBlock (%characterIndex, %healthBlock, %bit, %fadeTime)
{//echo("setHealthBlock()");
	// 
	switch ($playerSquad[%characterIndex].characterClass)
	{
		case 0:
			// Leader Health Blocks.
			switch (%healthBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock7, %bit);
				case  8:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock8, %bit);
				case  9:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock9, %bit);
				case 10:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock10, %bit);
				case 11:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock11, %bit);
				case 12:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock12, %bit);
				case 13:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock13, %bit);
				case 14:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock14, %bit);
				case 15:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock15, %bit);
				case 16:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock16, %bit);
				case 17:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock17, %bit);
				case 18:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock18, %bit);
				case 19:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock19, %bit);
				case 20:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", leaderHealthBlock20, %bit);
			}
			
		case 1:
			// Scout Health Blocks.
			switch (%healthBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock7, %bit);
				case  8:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock8, %bit);
				case  9:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock9, %bit);
				case 10:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock10, %bit);
				case 11:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock11, %bit);
				case 12:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock12, %bit);
				case 13:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock13, %bit);
				case 14:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock14, %bit);
				case 15:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock15, %bit);
				case 16:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock16, %bit);
				case 17:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock17, %bit);
				case 18:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock18, %bit);
				case 19:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock19, %bit);
				case 20:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", scoutHealthBlock20, %bit);
			}
			
		case 2:
			// Grenadier Health Blocks.
			switch (%healthBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock7, %bit);
				case  8:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock8, %bit);
				case  9:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock9, %bit);
				case 10:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock10, %bit);
				case 11:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock11, %bit);
				case 12:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock12, %bit);
				case 13:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock13, %bit);
				case 14:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock14, %bit);
				case 15:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock15, %bit);
				case 16:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock16, %bit);
				case 17:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock17, %bit);
				case 18:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock18, %bit);
				case 19:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock19, %bit);
				case 20:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", grenadierHealthBlock20, %bit);
			}
			
		case 3:
			// Support Health Blocks.
			switch (%healthBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock7, %bit);
				case  8:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock8, %bit);
				case  9:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock9, %bit);
				case 10:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock10, %bit);
				case 11:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock11, %bit);
				case 12:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock12, %bit);
				case 13:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock13, %bit);
				case 14:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock14, %bit);
				case 15:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock15, %bit);
				case 16:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock16, %bit);
				case 17:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock17, %bit);
				case 18:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock18, %bit);
				case 19:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock19, %bit);
				case 20:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock20, %bit);
			}
			
		case 4:
			// Engineer Health Blocks.
			switch (%healthBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock7, %bit);
				case  8:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock8, %bit);
				case  9:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock9, %bit);
				case 10:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock10, %bit);
				case 11:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock11, %bit);
				case 12:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock12, %bit);
				case 13:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock13, %bit);
				case 14:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock14, %bit);
				case 15:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock15, %bit);
				case 16:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock16, %bit);
				case 17:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock17, %bit);
				case 18:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock18, %bit);
				case 19:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock19, %bit);
				case 20:
					schedule(%fadeTime, 0, "setHealthBlockBitmap", supportHealthBlock20, %bit);
			}
	}
}

// Clears all a squad member's action blocks.
function clearSquadMemberActionBlocks (%characterIndex)
{//echo("clearSquadMemberActionBlocks()");
	for (%i = 1; %i <= 7; %i++)
	{
		setActionBlock(%characterIndex, %i, 0, 0);
	}
	switch ($playerSquad[%characterIndex].characterClass)
	{
		case 0:
			leaderActionLeftBrace.setVisible(0);
			leaderActionRightBrace.setVisible(0);
		case 1:
			scoutActionLeftBrace.setVisible(0);
			scoutActionRightBrace.setVisible(0);
		case 2:
			grenadierActionLeftBrace.setVisible(0);
			grenadierActionRightBrace.setVisible(0);
		case 3:
			supportActionLeftBrace.setVisible(0);
			supportActionRightBrace.setVisible(0);
		case 4:
			engineerActionLeftBrace.setVisible(0);
			engineerActionRightBrace.setVisible(0);
	}
}

// Sets an action block on or off given the specified character index and bit.
function setActionBlock (%characterIndex, %actionBlock, %bit, %fadeTime)
{//echo("setActionBlock()");
	// 
	switch ($playerSquad[%characterIndex].characterClass)
	{
		case 0:
			// Leader Action Blocks.
			switch (%actionBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setActionBlockBitmap", leaderActionBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setActionBlockBitmap", leaderActionBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setActionBlockBitmap", leaderActionBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setActionBlockBitmap", leaderActionBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setActionBlockBitmap", leaderActionBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setActionBlockBitmap", leaderActionBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setActionBlockBitmap", leaderActionBlock7, %bit);
			}
			
		case 1:
			// Scout Action Blocks.
			switch (%actionBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setActionBlockBitmap", scoutActionBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setActionBlockBitmap", scoutActionBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setActionBlockBitmap", scoutActionBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setActionBlockBitmap", scoutActionBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setActionBlockBitmap", scoutActionBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setActionBlockBitmap", scoutActionBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setActionBlockBitmap", scoutActionBlock7, %bit);
			}
			
		case 2:
			// Grenadier Action Blocks.
			switch (%actionBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setActionBlockBitmap", grenadierActionBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setActionBlockBitmap", grenadierActionBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setActionBlockBitmap", grenadierActionBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setActionBlockBitmap", grenadierActionBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setActionBlockBitmap", grenadierActionBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setActionBlockBitmap", grenadierActionBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setActionBlockBitmap", grenadierActionBlock7, %bit);
			}
			
		case 3:
			// Support Action Blocks.
			switch (%actionBlock)
			{
				case  1:
					schedule(%fadeTime, 0, "setActionBlockBitmap", supportActionBlock1, %bit);
				case  2:
					schedule(%fadeTime, 0, "setActionBlockBitmap", supportActionBlock2, %bit);
				case  3:
					schedule(%fadeTime, 0, "setActionBlockBitmap", supportActionBlock3, %bit);
				case  4:
					schedule(%fadeTime, 0, "setActionBlockBitmap", supportActionBlock4, %bit);
				case  5:
					schedule(%fadeTime, 0, "setActionBlockBitmap", supportActionBlock5, %bit);
				case  6:
					schedule(%fadeTime, 0, "setActionBlockBitmap", supportActionBlock6, %bit);
				case  7:
					schedule(%fadeTime, 0, "setActionBlockBitmap", supportActionBlock7, %bit);
			}
	}
}