// Integrity Handler.
// Worthless Bums 2012.


// Test function. Prints invaded decks.
function printInvadedDecks ()
{//echo("printInvadedDecks()");
	if ($ship.commandDeckInvaded)
	{
		echo("$ship.commandDeckInvaded");
	}
	if ($ship.engineeringDeckInvaded)
	{
		echo("$ship.engineeringDeckInvaded");
	}
	if ($ship.medicalDeckInvaded)
	{
		echo("$ship.medicalDeckInvaded");
	}
	if ($ship.armoryDeckInvaded)
	{
		echo("$ship.armoryDeckInvaded");
	}
	if ($ship.bridgeDeckInvaded)
	{
		echo("$ship.bridgeDeckInvaded");
	}
}
// Test function. Sets all decks to invaded.
function invadeAllDecks ()
{//echop("invadeAllDecks()");
	$ship.commandDeckInvaded = true;
	$ship.engineeringDeckInvaded = true;
	$ship.medicalDeckInvaded = true;
	$ship.armoryDeckInvaded = true;
	$ship.bridgeDeckInvaded = true;
}


// Sets random deck invasions.
function setRandomDeckInvasions ()
{//echo("setRandomDeckInvasions()");
	// Reset all deck invasion flags.
	$ship.commandDeckInvaded = false;
	$ship.engineeringDeckInvaded = false;
	$ship.medicalDeckInvaded = false;
	$ship.armoryDeckInvaded = false;
	$ship.bridgeDeckInvaded = false;
	// Don't set invasions on decks that are gone!
	// NOTE: "Gone" means 0 Integrity or max Infection.
	if ($ship.commandDeckIntegrity > 0	&&
		$ship.commandDeckInfection < $ship.commandDeckMaxInfection)
	{
		if (getRandom(1, 100) <= $deckInvasionChance)
		{
			$ship.commandDeckInvaded = true;
		}
	}
	if ($ship.engineeringDeckIntegrity > 0	&&
		$ship.engineeringDeckInfection < $ship.engineeringDeckMaxInfection)
	{
		if (getRandom(1, 100) <= $deckInvasionChance)
		{
			$ship.engineeringDeckInvaded = true;
		}
	}
	if ($ship.medicalDeckIntegrity > 0	&&
		$ship.medicalDeckInfection < $ship.medicalDeckMaxInfection)
	{
		if (getRandom(1, 100) <= $deckInvasionChance)
		{
			$ship.medicalDeckInvaded = true;
		}
	}
	if ($ship.armoryDeckIntegrity > 0	&&
		$ship.armoryDeckInfection < $ship.armoryDeckMaxInfection)
	{
		if (getRandom(1, 100) <= $deckInvasionChance)
		{
			$ship.armoryDeckInvaded = true;
		}
	}
	if ($ship.bridgeDeckIntegrity > 0	&&
		$ship.bridgeDeckInfection < $ship.bridgeDeckMaxInfection)
	{
		if (getRandom(1, 100) <= $deckInvasionChance)
		{
			$ship.bridgeDeckInvaded = true;
		}
	}
	if ($ship.alienDeckIntegrity > 0	&&
		$ship.alienDeckInfection < $ship.alienDeckMaxInfection)
	{
		if (getRandom(1, 100) <= $deckInvasionChance)
		{
			$ship.alienDeckInvaded = true;
		}
	}
}