// Ship Handler.
// Worthless Bums 2012.


function pushQuickInfoText (%quickInfo, %messageTime)//pushQuickInfoText("TESTING:\nQUICK INFO MESSAGE", 2500);
{//echo("pushQuickInfoText()");
	// Juice the push!
	// Calculate the center of the screen.
	%xSize = getWord($Game::Resolution, 0);
	%ySize = getWord($Game::Resolution, 1);
	%endPosX = 16;
	%endPosY = 16;
	QuickInformationPanel.position = "-200 16";	// Start here.
	QuickInfoText.setVisible(1);
	QuickInfoText.setText(%quickInfo);
	// Tween movement.
	%delay = 8.0;
	%totalSlices = 100;
	for (%i = 1; %i <= %totalSlices; %i++)
	{//echo("%i =" SPC %i);
		%slice = mRound((%xSize + 800) / %totalSlices);
		%position = (%slice * %i - 800) SPC %endPosY;
		schedule(%i * %delay, 0, "setQuickInfoPosition", %position);
		if ((%slice * %i - 800) >= %endPosX)
		{
			%i = %totalSlices + 1;
		}
	}
	schedule(%messageTime, 0, "popQuickInfoText");
}
function popQuickInfoText ()
{//echo("popQuickInfoText()");
	// Juice the pop!
	// Calculate the center of the screen.
	%xSize = getWord($Game::Resolution, 0);
	%ySize = getWord($Game::Resolution, 1);
	%endPosX = -200;
	%endPosY = 16;
	QuickInformationPanel.position = "16 16";	// Start here.
	// Tween movement.
	%delay = 8.0;
	%totalSlices = 100;
	for (%i = 1; %i <= %totalSlices; %i++)
	{//echo("%i =" SPC %i);
		%slice = mRound((%xSize + 800) / %totalSlices);
		%position = (-1 * %slice * %i) SPC %endPosY;
		schedule(%i * %delay, 0, "setQuickInfoPosition", %position);
		if (-1 * %slice * %i <= %endPosX)
		{
			%i = %totalSlices + 1;
		}
	}
}
function setQuickInfoPosition (%position)
{//echo("setQuickInfoPosition()");
	QuickInformationPanel.position = %position;
}

// Pushes the DeckStatsText.
function pushDeckStatsText ()
{//echo("pushDeckStatsText()");
	// Juice the push!
	// Calculate the center of the screen.
	%xSize = getWord($Game::Resolution, 0);
	%ySize = getWord($Game::Resolution, 1);
	%endPosX = 16;
	%endPosY = 16;
	DeckInformationPanel.position = "-200 16";	// Start here.
	deckStatsText.setVisible(1);
	// Tween movement.
	%delay = 8.0;
	%totalSlices = 100;
	for (%i = 1; %i <= %totalSlices; %i++)
	{//echo("%i =" SPC %i);
		%slice = mRound((%xSize + 800) / %totalSlices);
		%position = (%slice * %i - 800) SPC %endPosY;
		schedule(%i * %delay, 0, "setDeckStatsPosition", %position);
		if ((%slice * %i - 800) >= %endPosX)
		{
			// UI tween camera shake.
			//schedule(%i * %delay, 0, "uiTweenCameraShake");
			%i = %totalSlices + 1;
		}
	}
	// Sync to music?
	schedule(2500, 0, "popDeckStatsText");
}
// Pops the DeckStatsText GUI.
function popDeckStatsText ()
{//echo("popDeckStatsText()");
	// Juice the pop!
	// Calculate the center of the screen.
	%xSize = getWord($Game::Resolution, 0);
	%ySize = getWord($Game::Resolution, 1);
	%endPosX = -200;
	%endPosY = 16;
	DeckInformationPanel.position = "16 16";	// Start here.
	// Tween movement.
	%delay = 8.0;
	%totalSlices = 100;
	for (%i = 1; %i <= %totalSlices; %i++)
	{//echo("%i =" SPC %i);
		%slice = mRound((%xSize + 800) / %totalSlices);
		%position = (-1 * %slice * %i) SPC %endPosY;
		schedule(%i * %delay, 0, "setDeckStatsPosition", %position);
		if (-1 * %slice * %i <= %endPosX)
		{
			// UI tween camera shake.
			//schedule(%i * %delay, 0, "uiTweenCameraShake");
			%i = %totalSlices + 1;
		}
	}
}
function setDeckStatsPosition (%position)
{//echo("setDeckStatsPosition()");
	DeckInformationPanel.position = %position;
}
function toggleDeckStatsTextVisibility ()
{
	deckStatsText.setVisible(0);
}
// Update Deck Stats text.
function updateDeckStats ()
{//echo("updateDeckStats()");
	deckStatsText.setVisible(0);		// Not ready to show the world yet!
	
	// Set Deck Stats text.
	//%text = "\c2" @ $overworldLocation;// @ ", Level " @ $dungeonLevel;
	%text = $overworldLocation @ ", Level " @ $dungeonLevel;
	deckStatsText.setText(%text);
	return;
	pushDeckStatsText();
	//schedule(9000, 0, "toggleDeckStatsTextVisibility");
	return;
	
	// Original bar width based on resolution!
	%fullBarWidth = mRound(108 * (getWord($Game::Resolution, 0) / 800));
	
	// Dispatch by deck.
	switch$ ($overworldLocation)
	{
		case "Command Deck":
			// Set Hostile Control bar.
			%hostileControlBarHeight = 16;
			%hostileControlBarWidth = $ship.commandDeckHostileControl / 100;
			%hostileControlBarWidth = mFloor(%hostileControlBarWidth * %fullBarWidth);
			HostileControlBar.extent = %hostileControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Hostile Control text.
			//HostileControlText.setText("Hostiles" SPC mFloor($ship.commandDeckHostileControl) @ "%");
			// Set Integrity bar.
			%integrityBarHeight = 16;
			%integrityControlBarWidth = $ship.commandDeckIntegrity / 100;
			%integrityControlBarWidth = mFloor(%integrityControlBarWidth * %fullBarWidth);
			IntegrityBar.extent = %integrityControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Integrity text.
			//IntegrityText.setText("Integrity" SPC mFloor($ship.commandDeckIntegrity) @ "%");
		
		case "Engineering Deck":
			// Set Hostile Control bar.
			%hostileControlBarHeight = 16;
			%hostileControlBarWidth = $ship.engineeringDeckHostileControl / 100;
			%hostileControlBarWidth = mFloor(%hostileControlBarWidth * %fullBarWidth);
			HostileControlBar.extent = %hostileControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Hostile Control text.
			//HostileControlText.setText("Hostiles" SPC mFloor($ship.engineeringDeckHostileControl) @ "%");
			// Set Integrity bar.
			%integrityBarHeight = 16;
			%integrityControlBarWidth = $ship.engineeringDeckIntegrity / 100;
			%integrityControlBarWidth = mFloor(%integrityControlBarWidth * %fullBarWidth);
			IntegrityBar.extent = %integrityControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Integrity text.
			//IntegrityText.setText("Integrity" SPC mFloor($ship.engineeringDeckIntegrity) @ "%");
		
		case "Medical Deck":
			// Set Hostile Control bar.
			%hostileControlBarHeight = 16;
			%hostileControlBarWidth = $ship.medicalDeckHostileControl / 100;
			%hostileControlBarWidth = mFloor(%hostileControlBarWidth * %fullBarWidth);
			HostileControlBar.extent = %hostileControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Hostile Control text.
			//HostileControlText.setText("Hostiles" SPC mFloor($ship.medicalDeckHostileControl) @ "%");
			// Set Integrity bar.
			%integrityBarHeight = 16;
			%integrityControlBarWidth = $ship.medicalDeckIntegrity / 100;
			%integrityControlBarWidth = mFloor(%integrityControlBarWidth * %fullBarWidth);
			IntegrityBar.extent = %integrityControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Integrity text.
			//IntegrityText.setText("Integrity" SPC mFloor($ship.medicalDeckIntegrity) @ "%");
		
		case "Armory Deck":
			// Set Hostile Control bar.
			%hostileControlBarHeight = 16;
			%hostileControlBarWidth = $ship.armoryDeckHostileControl / 100;
			%hostileControlBarWidth = mFloor(%hostileControlBarWidth * %fullBarWidth);
			HostileControlBar.extent = %hostileControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Hostile Control text.
			//HostileControlText.setText("Hostiles" SPC mFloor($ship.armoryDeckHostileControl) @ "%");
			// Set Integrity bar.
			%integrityBarHeight = 16;
			%integrityControlBarWidth = $ship.armoryDeckIntegrity / 100;
			%integrityControlBarWidth = mFloor(%integrityControlBarWidth * %fullBarWidth);
			IntegrityBar.extent = %integrityControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Integrity text.
			//IntegrityText.setText("Integrity" SPC mFloor($ship.armoryDeckIntegrity) @ "%");
		
		case "Bridge Deck":
			// Set Hostile Control bar.
			%hostileControlBarHeight = 16;
			%hostileControlBarWidth = $ship.bridgeDeckHostileControl / 100;
			%hostileControlBarWidth = mFloor(%hostileControlBarWidth * %fullBarWidth);
			HostileControlBar.extent = %hostileControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Hostile Control text.
			//HostileControlText.setText("Hostiles" SPC mFloor($ship.bridgeDeckHostileControl) @ "%");
			// Set Integrity bar.
			%integrityBarHeight = 16;
			%integrityControlBarWidth = $ship.bridgeDeckIntegrity / 100;
			%integrityControlBarWidth = mFloor(%integrityControlBarWidth * %fullBarWidth);
			IntegrityBar.extent = %integrityControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Integrity text.
			//IntegrityText.setText("Integrity" SPC mFloor($ship.bridgeDeckIntegrity) @ "%");
		
		case "Alien Deck":
			// Set Hostile Control bar.
			%hostileControlBarHeight = 16;
			%hostileControlBarWidth = $ship.alienDeckHostileControl / 100;
			%hostileControlBarWidth = mFloor(%hostileControlBarWidth * %fullBarWidth);
			HostileControlBar.extent = %hostileControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Hostile Control text.
			//HostileControlText.setText("Hostiles" SPC mFloor($ship.alienDeckHostileControl) @ "%");
			// Set Integrity bar.
			%integrityBarHeight = 16;
			%integrityControlBarWidth = $ship.alienDeckIntegrity / 100;
			%integrityControlBarWidth = mFloor(%integrityControlBarWidth * %fullBarWidth);
			IntegrityBar.extent = %integrityControlBarWidth SPC getWord(updateDeckStats, 1);
			// Set Integrity text.
			//IntegrityText.setText("Integrity" SPC mFloor($ship.alienDeckIntegrity) @ "%");
	}
}

// Initializes Ship object.
function initializeShipObject ()
{//echo("initializeShipObject()");
	// Ship object.
	$ship = new ScriptObject (shipObject)
	{
		// The steampunk spaceship has a lot to track!
		
		// Command Deck data.
		commandDeckHostileControl = 100;		// Start off fully enemy controlled.
		commandDeckIntegrity = 5;				// Start off with full hull integrity.
		commandDeckMaxIntegrity = 5;
		commandDeckOxygen = 50;					// Start off with half oxygen supply.
		commandDeckMaxOxygen = 100;
		commandDeckPower = 50;					// Start off with half power.
		commandDeckMaxPower = 100;
		commandDeckInfection = 0;				// Start off with no infection.
		commandDeckMaxInfection = 3;
		commandDeckInvaded = false;				// Decks currently being invaded (by the enemy).
		
		// Engineering Deck data.
		engineeringDeckHostileControl = 100;	// Start off fully enemy controlled.
		engineeringDeckIntegrity = 5;			// Start off with full hull integrity.
		engineeringDeckMaxIntegrity = 5;
		engineeringDeckOxygen = 50;				// Start off with half oxygen supply.
		engineeringDeckMaxOxygen = 100;
		engineeringDeckPower = 50;				// Start off with half power.
		engineeringDeckMaxPower = 100;
		engineeringDeckInfection = 0;			// Start off with no infection.
		engineeringDeckMaxInfection = 3;
		engineeringDeckInvaded = false;			// Decks currently being invaded (by the enemy).
		
		// Medical Deck data.
		medicalDeckHostileControl = 100;		// Start off fully enemy controlled.
		medicalDeckIntegrity = 5;				// Start off with full hull integrity.
		medicalDeckMaxIntegrity = 5;
		medicalDeckOxygen = 50;					// Start off with half oxygen supply.
		medicalDeckMaxOxygen = 100;
		medicalDeckPower = 50;					// Start off with half power.
		medicalDeckMaxPower = 100;
		medicalDeckInfection = 0;				// Start off with no infection.
		medicalDeckMaxInfection = 3;
		medicalDeckInvaded = false;				// Decks currently being invaded (by the enemy).
		
		// Armory Deck data.
		armoryDeckHostileControl = 100;			// Start off fully enemy controlled.
		armoryDeckIntegrity = 5;				// Start off with full hull integrity.
		armoryDeckMaxIntegrity = 5;
		armoryDeckOxygen = 50;					// Start off with half oxygen supply.
		armoryDeckMaxOxygen = 100;
		armoryDeckPower = 50;					// Start off with half power.
		armoryDeckMaxPower = 100;
		armoryDeckInfection = 0;				// Start off with no infection.
		armoryDeckMaxInfection = 3;
		armoryDeckInvaded = false;				// Decks currently being invaded (by the enemy).
		
		// Alien Deck data.
		alienDeckHostileControl = 100;			// Start off fully enemy controlled.
		alienDeckIntegrity = 5;				// Start off with full hull integrity.
		alienDeckMaxIntegrity = 5;
		alienDeckOxygen = 50;					// Start off with half oxygen supply.
		alienDeckMaxOxygen = 100;
		alienDeckPower = 50;					// Start off with half power.
		alienDeckMaxPower = 100;
		alienDeckInfection = 0;				// Start off with no infection.
		alienDeckMaxInfection = 3;
		alienDeckInvaded = false;				// Decks currently being invaded (by the enemy).
	};
}

// Generates a randomized set of decks and levels for the ship.
function generateRandomShip ()
{//echo("generateRandomShip()");
	// Procedure:
	//		1) Randomize number of levels per deck.
	//		2) Randomize A, B, C, D level step connections.
	//		3) 
	
	// 1)
	%commandDeckMaxLevels = 		getRandom(5, 8);
	%engineeringDeckMaxLevels = 	getRandom(6, 9);
	%medicalDeckMaxLevels = 		getRandom(4, 8);
	%armoryDeckMaxLevels = 			getRandom(3, 5);
	%bridgeDeckMaxLevels = 			getRandom(2, 4);
	%alienDeckMaxLevels = 			getRandom(2, 3);
	
	// 2)
	%commandToEngineeringLevel =	getRandom(3, %commandDeckMaxLevels);
	%engineeringToMedicalLevel =	getRandom(3, %commandDeckMaxLevels);
	%commandToEngineeringLevel =	getRandom(3, %commandDeckMaxLevels);
}