// Handles Wall Paintings.
// Worthless Bums 2012.


// Returns a random wall light given a wall atlas frame.
function getLightImageFromAtlasFrame (%frame)
{//echo("getLightImageFromAtlasFrame()");
	%lightImage = "";
	%lightVerticalLeftImage  = "Sprites:LightFloorLeft";
	%lightVerticalRightImage = "Sprites:LightFloorRight";
	// Add environment props here.
	switch$ (%frame)
	{
		// Vertical Wall Lights.
		// Left Lights.
		case 16: 	%lightImage = %lightVerticalLeftImage;
		case 19: 	%lightImage = %lightVerticalLeftImage;
		case 35: 	%lightImage = %lightVerticalLeftImage;
		case 36: 	%lightImage = %lightVerticalLeftImage;
		case 68: 	%lightImage = %lightVerticalLeftImage;
		case 71: 	%lightImage = %lightVerticalLeftImage;
		case 75: 	%lightImage = %lightVerticalLeftImage;		// Can be left and/or right!
		case 76: 	%lightImage = %lightVerticalLeftImage;		// Can be left and/or right!
		// Right Lights.
		case 17: 	%lightImage = %lightVerticalRightImage;
		case 20: 	%lightImage = %lightVerticalRightImage;
		case 34: 	%lightImage = %lightVerticalRightImage;
		case 37: 	%lightImage = %lightVerticalRightImage;
		case 67: 	%lightImage = %lightVerticalRightImage;
		case 72: 	%lightImage = %lightVerticalRightImage;
		
		// Horizontal Wall Lights
		case "": 	%lightImage = %lightVerticalImage;			// Null case.
	}
	return %lightImage;
}
// Returns a random wall painting given a wall frame.
function getPaintingImageFromAtlasFrame (%frame)
{//echo("getPaintingImageFromAtlasFrame()");echo("%frame =" SPC %frame);
	%paintingImage = getRandom(0, 2);
	switch (%paintingImage)
	{
		case 0:	%paintingImage = "Sprites:PaintingVoxPickup";
		case 1:	%paintingImage = "Sprites:paintingPirate";
		case 2:	%paintingImage = "Sprites:PaintingFoodPlate";
	}
	switch (%frame)
	{
		case 14:	return %paintingImage;
		case 15:	return %paintingImage;
		case 36:	return %paintingImage;
		case 37:	return %paintingImage;
		case 54:	return %paintingImage;
		case 55:	return %paintingImage;
		case 56:	return %paintingImage;
		case 57:	return %paintingImage;
		case 58:	return %paintingImage;
		case 59:	return %paintingImage;
		case 60:	return %paintingImage;
		case 61:	return %paintingImage;
		case 66:	return %paintingImage;
		case 73:	return %paintingImage;
		case 74:	return %paintingImage;
		case 77:	return %paintingImage;
	}
	return "";
}
// Returns a random wall painting given a wall imagemap.
function getPaintingImageMap (%wallImageMap)
{//echo("getPaintingImageMap()");
	%paintingImageMap = "";
	// Grab random paintings.
	%paintingVerticalImageMap = getRandom(0, 1);
	switch (%paintingVerticalImageMap)
	{
		case 0:	%paintingVerticalImageMap = "Painting1ImageMap";
		case 1:	%paintingVerticalImageMap = "Painting2ImageMap";
	}
	%paintingHorizontalImageMap = getRandom(0, 1);
	switch (%paintingVerticalImageMap)
	{
		case 0:	%paintingHorizontalImageMap = "PaintingHorizontal1ImageMap";
		case 1:	%paintingHorizontalImageMap = "PaintingHorizontal2ImageMap";
	}
	// Add environment props here.
	switch$ (%wallImageMap)
	{
		// Vertical Wall Paintings.
		case "EndThin1ImageMap": 			%paintingImageMap = %paintingVerticalImageMap;
		case "OuterCorner1ImageMap":  		%paintingImageMap = %paintingVerticalImageMap;
		case "OuterCorner2ImageMap":  		%paintingImageMap = %paintingVerticalImageMap;
		case "WallThin2ImageMap": 			%paintingImageMap = %paintingVerticalImageMap;
		case "HardOuterCorner1ImageMap":	%paintingImageMap = %paintingVerticalImageMap;
		case "HardOuterCorner2ImageMap":	%paintingImageMap = %paintingVerticalImageMap;
		case "InnerCorner1ImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "InnerCorner2ImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "InnerCorner3ImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "InnerCorner4ImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "TWallThick2ImageMap":			%paintingImageMap = %paintingVerticalImageMap;
		case "TWallThick3ImageMap":			%paintingImageMap = %paintingVerticalImageMap;
		case "TWallThin2ImageMap":			%paintingImageMap = %paintingVerticalImageMap;
		case "TWallThin3ImageMap":			%paintingImageMap = %paintingVerticalImageMap;
		case "CornerWallSEWImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "CornerWallSWNImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "CornerWallSENImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "CornerWallSWNImageMap":		%paintingImageMap = %paintingVerticalImageMap;
		case "WallThick1ImageMap":			%paintingImageMap = %paintingVerticalImageMap;
		case "WallThick2ImageMap":			%paintingImageMap = %paintingVerticalImageMap;
		case "WallThick3ImageMap":			%paintingImageMap = %paintingVerticalImageMap;
		//case "":		%paintingImageMap = %paintingVerticalImageMap;
		
		// Horizontal Wall Paintings.
		//case "EndThin2ImageMap": 			%paintingImageMap = %paintingHorizontalImageMap;
		//case "EndThin3ImageMap": 			%paintingImageMap = %paintingHorizontalImageMap;
		case "HardOuterCorner3ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "OuterCorner3ImageMap":		%paintingImageMap = %paintingHorizontalImageMap;
		//case "OuterCorner4ImageMap":		%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThick1ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThick2ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThick3ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThick5ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThin1ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThin2ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThin3ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "SpecialWallThin4ImageMap":	%paintingImageMap = %paintingHorizontalImageMap;
		case "TWallThin1ImageMap":			%paintingImageMap = %paintingHorizontalImageMap;
		case "WallThick4ImageMap":			%paintingImageMap = %paintingHorizontalImageMap;
		case "WallThin1ImageMap":			%paintingImageMap = %paintingHorizontalImageMap;
		case "WallThin4ImageMap":			%paintingImageMap = %paintingHorizontalImageMap;
		case "CornerEdgeNWSImageMap":		%paintingImageMap = %paintingHorizontalImageMap;
		case "CornerEdgeNESImageMap":		%paintingImageMap = %paintingHorizontalImageMap;
		//case "":			%paintingImageMap = %paintingHorizontalImageMap;
	}
	
	// Return painting imagemap.
	return %paintingImageMap;
}
// Updates the event log depending on painting imagemap.
function paintingTriggerMessage (%image)
{//echo("paintingTriggerMessage()");
	switch$ (%image)
	{
		case "Sprites:PaintingVoxPickup":
			setIndividualDialoguePopup($playerSquad[$activeCharacter], "A malevolent creator...", "dialogue");
		case "Sprites:paintingPirate":
			setIndividualDialoguePopup($playerSquad[$activeCharacter], "This painting seems to be watching me...", "dialogue");
		case "Sprites:paintingFoodPlate":
			setIndividualDialoguePopup($playerSquad[$activeCharacter], "Looks delicious...", "dialogue");
	}
}
// Returns true iff the specified squad member is standing adjacent to a painting.
function isNextToPainting (%characterIndex)
{//echo("isNextToPainting()");
	// Get character indices.
	%xIndex = $playerSquad[%characterIndex].xIndex;
	%yIndex = $playerSquad[%characterIndex].yIndex;
	
	// Check wall tiles adjacent to the character and check for paintings.
	// North.
	// Bounds check.
	if (%yIndex - 1 >= 0)
	{
		// Check if this tile is an object.
		if (isObject($mazeRoom[%xIndex, %yIndex - 1]))
		{
			// Check if this object has a painting object.
			// NOTE: Only wall objects should have paintings!
			if (isObject($mazeRoom[%xIndex, %yIndex - 1].painting))
			{
				// Dispatch painting message!
				// NOTE: How to determine painting type? By imagemap, most likely.
				%imagemap = ($mazeRoom[%xIndex, %yIndex - 1].painting).image;
				paintingTriggerMessage(%imagemap);
			}
		}
	}
	// South.
	// Bounds check.
	if (%yIndex + 1 < $mazeDimension)
	{
		// Check if this tile is an object.
		if (isObject($mazeRoom[%xIndex, %yIndex + 1]))
		{
			// Check if this object has a painting object.
			// NOTE: Only wall objects should have paintings!
			if (isObject($mazeRoom[%xIndex, %yIndex + 1].painting))
			{
				// Dispatch painting message!
				// NOTE: How to determine painting type? By imagemap, most likely.
				%imagemap = ($mazeRoom[%xIndex, %yIndex + 1].painting).image;
				paintingTriggerMessage(%imagemap);
			}
		}
	}
	// East.
	// Bounds check.
	if (%xIndex + 1 < $mazeDimension)
	{
		// Check if this tile is an object.
		if (isObject($mazeRoom[%xIndex + 1, %yIndex]))
		{
			// Check if this object has a painting object.
			// NOTE: Only wall objects should have paintings!
			if (isObject($mazeRoom[%xIndex + 1, %yIndex].painting))
			{
				// Dispatch painting message!
				// NOTE: How to determine painting type? By imagemap, most likely.
				%imagemap = ($mazeRoom[%xIndex + 1, %yIndex].painting).image;
				paintingTriggerMessage(%imagemap);
			}
		}
	}
	// West.
	// Bounds check.
	if (%xIndex - 1 >= 0)
	{
		// Check if this tile is an object.
		if (isObject($mazeRoom[%xIndex - 1, %yIndex]))
		{
			// Check if this object has a painting object.
			// NOTE: Only wall objects should have paintings!
			if (isObject($mazeRoom[%xIndex - 1, %yIndex].painting))
			{
				// Dispatch painting message!
				// NOTE: How to determine painting type? By imagemap, most likely.
				%imagemap = ($mazeRoom[%xIndex - 1, %yIndex].painting).image;
				paintingTriggerMessage(%imagemap);
			}
		}
	}
}
// Substitute function for spawnItemInPlayerInventory()!
function giveItem (%itemType)
{//echo("giveItem()");
	spawnItemInPlayerInventory(%itemType);
}
// Spawns item in player inventory.
function spawnItemInPlayerInventory (%itemType)
{//echo("spawnItemInPlayerInventory()");
	%itemObject = createRandomItem(%itemType, "-9999 -9999", %xIndex, %yIndex);
	addItemToInventory(%itemObject, %itemType);
	updateInventoryTabInformation();
}