// Corpse Handler.
// Worthless Bums 2012.


function spawnCrewCorpses ()
{//echo("spawnCrewCorpses()");
	for (%i = 0; %i < $mazeDimension; %i++)
	{
		for (%j = 0; %j < $mazeDimension; %j++)
		{
			if (!isObject($mazeRoom[%i, %j])	&&	// Floor tiles don't actually exist individually except lifted tiles!
				!isSpaceTile(%i, %j))
			{
				if (getRandom(1, 100) <= $crewCorpseChance)
				{//echo("corpse spawning at: " SPC %i SPC %j);
					spawnCorpse(%i, %j, 3);
				}
			}
		}
	}
}
function spawnFloorMarkings ()
{//echo("spawnFloorMarkings()");
	for (%i = 0; %i < $mazeDimension; %i++)
	{
		for (%j = 0; %j < $mazeDimension; %j++)
		{
			if (!isObject($mazeRoom[%i, %j])	&&	// Floor tiles don't actually exist individually except lifted tiles!
				!isSpaceTile(%i, %j))
			{
				if (getRandom(1, 100) <= $floorMarkingsChance)
				{//echo("corpse spawning at: " SPC %i SPC %j);
					spawnCorpse(%i, %j, 4);
				}
			}
		}
	}
}
function spawnCorpse (%xIndex, %yIndex, %corpseType)
{//echo("spawnCorpse()");echo("%corpseType =" SPC %corpseType);
	%corpseImage = "";
	%corpseLayer = $CorpseLayer;
	switch (%corpseType)
	{
		case 0:	// Marine corpses.
			%corpseRoll = getRandom(0, 1);
			switch (%corpseRoll)
			{
				case 0:	%corpseImage = "Sprites:decalcorpse";
				case 1:	%corpseImage = "Sprites:decalcorpsealt";
			}
			
		case 1:	// Robot corpses.
			%corpseRoll = getRandom(0, 1);
			switch (%corpseRoll)
			{
				case 0:	%corpseImage = "Sprites:robotCorpse1";
				case 1:	%corpseImage = "Sprites:robotCorpse2";
			}
			
		case 2:	// Alien corpses.
			%corpseRoll = getRandom(0, 2);
			switch (%corpseRoll)
			{
				case 0:	%corpseImage = "Sprites:alienCorpse1";
				case 1:	%corpseImage = "Sprites:alienCorpse2";
				case 2:	%corpseImage = "Sprites:alienCorpse3";
			}
			
		case 3:	// Crew corpses.
			%corpseRoll = getRandom(0, 3);
			switch (%corpseRoll)
			{
				case 0:	%corpseImage = "Sprites:CrewCorpseNorth";
				case 1:	%corpseImage = "Sprites:CrewCorpseSouth";
				case 2:	%corpseImage = "Sprites:CrewCorpseEast";
				case 3:	%corpseImage = "Sprites:CrewCorpseWest";
			}
			
		case 4:	// Floor markings.
			%corpseRoll = getRandom(0, 3);
			switch (%corpseRoll)
			{
				case 0:	%corpseImage = "Sprites:BloodPoolFloor";%corpseLayer++;
				case 1:	%corpseImage = "Sprites:BloodSplatterFloor";%corpseLayer++;
				case 2:	%corpseImage = "Sprites:BulletHolesFloor";%corpseLayer++;
				case 3:	%corpseImage = "Sprites:ClawMarksFloor";%corpseLayer++;
			}
	}
	%corpseSprite = new Sprite("corpse")
	{
		SceneLayer = %corpseLayer;
		graph = $CorpseGraph;
		position = getTilePositionFromIndices(%xIndex, %yIndex);
		scenegraph = levelSceneGraph;
		image = %corpseImage;
		visible = true;
		size = "4 4";
		xIndex = %xIndex;
		yIndex = %yIndex;
	};
	addObjectToScene(%corpseSprite);
	$CorpseList.add(%corpseSprite);
}