print("\nGameProcess.lua " .. os.date("%H:%M %d %b %Y"))

storyReveal = {}

function doStoryItemReveal(strTarget, storyRevealID)
	local itemName = target[strTarget].storyrevealitem
	local item = scene:child( itemName )
	item:relocateAnchorPoint("bottom")
	item:relocatePivotPoint("bottom")
	
	local imageName = "IMAGE_BOOK_IMAGE_"..storyRevealID
	local journalItem = scene:newChildSprite({x = item:x(), y = item:y(), image = imageName, section = "journal", name = imageName, alpha = 0.0, anchorpoint = "bottom", pivotpoint = "bottom"})

	local smallWidthScale	= item:width() / journalItem:width()
	local smallHeightScale	= item:height() / journalItem:height()
	local smallScale = smallWidthScale
	if smallHeightScale > smallWidthScale then
		smallScale = smallHeightScale
	end
	local largeWidthScale	= 268 / journalItem:width()
	journalItem:setScale( smallScale )

	item:animate(
		{delay = 900},
		{x = 516+30, y = 285+4, scale = 1.8, rotation = -5.15662016, duration = 700 }
	)
	
	item:animate(
		{delay = 900},
		{alpha = 0.0, duration = 500 },
		{visible = false}
	)
	
	journalItem:animate(
		{delay = 900},
		{alpha = 1.0, x = 516+30, y = 285+4, scale = largeWidthScale, rotation = -5.15662016, duration = 700 },
		{alpha = 0.0, duration = 300 },
		{visible = false}
	)
	
	scene:animate(
		{delay = 1400},
		{call = function() scene:onStoryRevealItemFinished() end}
	)
	
	return true
end

tarRemove = {}					-- funtcion to call when specified target is triggered
tarRemoveDelay = {}				-- wait this long before code continues (e.g., data1 & data2 stuff)

-- tarRemove["9drillbit1"] = { {alpha = 1.0}, {scale = 4.0, duration = 600} } -- this was a test (ERF)
tarRemove["17eel1"] = { {play = "SFX_camera_flash:scenelevels"}, {x = 250, duration = 600} }

tarRemove["73solarpanel"] = { call = function()
		scene:newChildSprite({class = "ParticleEffect", x = 534, y = 136, library = "PARTICLE_SPARK", section = "scenegame_9_DOCKS_AMB", name = "spark", play = true})
	end
	}

tarRemove["72exposedwires"] = { call = function()
		local spark = scene:child( "spark" )
		if( spark ~= nil ) then
			spark:stop()
			spark:removeFromParent()
		end
	end
	}

tarRemove["114targetstartbutton"] = { call = function()
		local	greenstartbutton = scene:child("123ambientgreenbutton")	-- get the startbutton sprite from the scene pipeline
		greenstartbutton:setVisible( false )
	end
	}

tarRemove["8throttle"] = { call = function()
		if scene:isTargetTriggered("62boatdashboard") then
			local	greenstartbutton = scene:child("123ambientgreenbutton")	-- get the startbutton sprite from the scene pipeline
			local	redstartbutton = scene:child("124ambientredbutton")		-- get the startbutton sprite from the scene pipeline
			redstartbutton:setVisible( false )
			greenstartbutton:setVisible( true )
			greenstartbutton:doEvery(0, function()		-- # tells animation how long to wait before starting
				greenstartbutton:animate(
					{alpha = 0, duration = 150},
					{delay = 400},
					{alpha = 1, duration = 150}
				)
				return 700	-- this number is delay before repeating; must be larger than duration of stuff we do above
				end
			)
		end
	end
	}

tarRemove["62boatdashboard"] = { call = function()
		if scene:isTargetTriggered("8throttle") then
			local	greenstartbutton = scene:child("123ambientgreenbutton")	-- get the startbutton sprite from the scene pipeline
			local	redstartbutton = scene:child("124ambientredbutton")		-- get the startbutton sprite from the scene pipeline
			redstartbutton:setVisible( false )
			greenstartbutton:setVisible( true )
			greenstartbutton:doEvery(0, function()		-- # tells animation how long to wait before starting
				greenstartbutton:animate(
					{alpha = 0, duration = 150},
					{delay = 400},
					{alpha = 1, duration = 150}
				)
				return 700	-- this number is delay before repeating; must be larger than duration of stuff we do above
				end
			)
		end
	end
	}
	
tarRemove["110clockwithouthands"] = { call = function()
	if scene:isTargetTriggered( "113brokenwires" ) then
		doSCLABBOpenLocker()
	end
end
}

tarRemove["113brokenwires"] = { call = function()
	if scene:isTargetTriggered( "110clockwithouthands" ) then
		doSCLABBOpenLocker()
		doSCLABTurnOffWireSparks()	
	else
		doSCLABTurnOffWireSparks()
	end
end
}	

tarRemoveDelay["80statueheadpiece1"] = 4000	
tarRemove["80statueheadpiece1"] = { call = function()
	doTEMPXUseStatueHeadPiece()
end
}

tarRemoveDelay["79statueheadpiece 2"] = 1000				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["79statueheadpiece 2"] = { call = function()
	doTEMPXJawDrop( true )
	doTEMPXHeadRaise(true)
--	doTEMPXShowStatueMouth(true)
end
}

tarRemoveDelay["78statueheadpiece3"] = 1500				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["78statueheadpiece3"] = { call = function()
	doTEMPXCrushSuitcase()
end
}

tarRemove["49lightswitchoff"] = { call = function()
	doSCLABRedMode(true)
end
}

tarRemove["66h2obeaker"] = { call = function()
	doSCLABRedMode(false)
end
}

tarRemoveDelay["64resourcestand"] = 3000				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["64resourcestand"] = { call = function()
	doRUINSPresentYellowResource(true)
end
}


tarRemove["27pyramidtip"] = { call = function()
	doRUINSRaisePyramid()
end
}

tarRemoveDelay["11middleofpyramid"] = 7500				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["11middleofpyramid"] = { call = function()
	doRUINSPresentGreenResource()
end
}

tarRemoveDelay["100button1"] = 3000				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["100button1"] = { call = function()
	doWTRFLTurnOffWaterfall()
end
}

tarRemoveDelay["89centrifugeopen"] = 5500				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["89centrifugeopen"] = { call = function()
	doSCLABShakeCentrifuge()
end
}

tarRemove["51canistervalveclosed"] = { call = function()
	doSCLABOpenCannisterPart_1()
end
}

tarRemoveDelay["89centrifugeopen"] = 3800				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["50canistervalveopen1"] = { call = function()
	doSCLABOpenCannisterPart_2()
end
}

tarRemove["95faucet"] = { call = function()
	doUNLABTurnOffFaucet()
end
}

tarRemove["30firewoodsoaked"] = { call = function()
	doLIVNGStartFire( false )
end
}

tarRemove["31firewoodlighted"] = { call = function()
	doLIVNGStopFire()
end
}

tarRemove["69rainbarrelup"] = { call = function() 
	doLIVNGDoBarrelWater()
end
}

tarRemoveDelay["74well3"] = 3900				-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["74well3"] = { call = function() 
	doWTRFLGetCannister()
end
}

tarRemoveDelay["111targetwellwater"] = 4000		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["111targetwellwater"] = { call = function() 
	doWTRFLGetWellWater()
end
}

tarRemoveDelay["5pillarswitch"] = 1000		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["5pillarswitch"] = { call = function() 
	doTEMPIRevealWaterPorts()
	doTEMPIWaterPourRightPort(1000, 1500)
	doTEMPIWaterLeakLeftPort(1500)
end
}

tarRemove["30rightwaterport"] = { call = function() 
	doTEMPIAttachLeftSpigot()
end
}

tarRemoveDelay["27leakypipe"] = 2000		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["27leakypipe"] = {call = function() 
	doTEMPITurnOffLeakyPipe(1000, true)
end
}

tarRemove["67potwithsnake"] = {call = function() 
	doTEMPISnakeSlither()
end
}

tarRemove["96targeteyes"] = {call = function()
	doTEMPIDoLaserEyes()
end
}

tarRemoveDelay["4landline"] = 1500		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["4landline"] = {call = function()
	doCONDOPhone()
end
}

tarRemove["40thermostat"] = {call = function()
	doCONDOFireExtinguisher()
end
}
 
tarRemove["63ammobox"] = {call = function()
	doMPATHFlashNoService()
end
}

tarRemoveDelay["98targetprinter"] = 3000		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["98targetprinter"] = {call = function()
	doOFFICPrintPaper()
end
}

tarRemoveDelay["66stone"] = 800		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["66stone"] = {call = function()
	doMPATHRollRock()
end
}

tarRemoveDelay["76eel1"] = 3000		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["76eel1"] = {call = function()
	doSHPRKFlashCamera()
end
}

tarRemoveDelay["7backpack"] = 500		-- wait this long before code continues (e.g., data1 & data2 stuff)
tarRemove["7backpack"] = {call = function() 
	doBEACHGetBackpack()
end
}

tarRemove["8poweredcomputer"] = {call = function()
	doINVENPowerComputer()
end
}

tarRemove["9computer"] = {call = function()
	doINVENBlueScreen()
end
}

tarRemove["7computerch9"] = {call = function()
	doINVENSerialCableConnected()
end
}

function animateCinematicBorders(aScene, aDuration)
	local UI = scene:child( "GAME_UI_BLUEPRINT" )
	UI:animate(
		{alpha=0.0, duration=300},
		{delay=aDuration+1000},
		{alpha=1.0, duration=300}
	)
	local topBorder = aScene:child("CINEMATICBORDER_TOP")
	local botBorder = aScene:child("CINEMATICBORDER_BOTTOM")
	local botLabel = aScene:child("LABEL_TEXT")
	topBorder:animate(
		{y=topBorder:y()-topBorder:height(), alpha=1.0},
		{y=topBorder:y(), duration=700},
		{delay=aDuration},
		{y=topBorder:y()-topBorder:height(), duration=700},
		{call = function(topBorder) topBorder:setObsolete() end}
	)
	botBorder:animate(
		{y=botBorder:y()+botBorder:height(), alpha=1.0},
		{y=botBorder:y(), duration=700},
		{delay=aDuration},
		{y=botBorder:y()+botBorder:height(), duration=700},
		{call = function(botBorder) botBorder:setObsolete() end}
	)
	botLabel:animate(
		{y=botLabel:y()+botBorder:height(), alpha=1.0},
		{y=botLabel:y(), duration=700},
		{delay=aDuration},
		{y=botLabel:y()+botBorder:height(), duration=700},
		{call = function(botLabel) botLabel:setObsolete() end}
	)
end



tarRemoveDelay["32boomboxeject"] = 18000
tarRemove["32boomboxeject"] = {call = function()

	-- text and voice stuff
	scene:animate(
		{command = "CreateCinematicBorders"},
		{call=function() animateCinematicBorders(scene, 17000) end}
	)
	scene:animate(
		{delay=700},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_SCIENTIST_0_0") end},
		{playAndWait = "VOICE_SCIENTIST_0_0:scenegame_5_BCAVE_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_SCIENTIST_0_1") end},
		{playAndWait = "VOICE_SCIENTIST_0_1:scenegame_5_BCAVE_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end}
	)
	-- text and voice stuff

	local	soundWaves = scene:child("130soundwaves")	-- get the sprite from the scene pipeline
	soundWaves:relocateAnchorPoint("center")
	soundWaves:setVisible(true)
	scene:child("32boomboxeject"):setVisible(false)
	scene:child("127storyboombox"):setVisible(true)
	local	timeElapsed = 0
	soundWaves:doEvery(500, function()					-- # tells animation how long to wait before starting
		soundWaves:animate(
			{scale=1.0, alpha=0.4, duration=1000, style="easeInOut"},
			{scale=1.2, alpha=1.0, duration=1000, style="easeInOut"}
		)
		timeElapsed = timeElapsed + 2000
		if timeElapsed < 17000 then
			return 2000	-- this number is delay before repeating; must be larger than duration of stuff we do above
		else
			scene:child("32boomboxeject"):setX(1000)	-- move offscreen so when data2 code shows soundWaves, they won't show up
			soundWaves:setX(1000)						-- move offscreen so when data2 code shows soundWaves, they won't show up
			return false
		end
	end
	)
end 
}
	
tarRemoveDelay["1cellphone"] = 23000
tarRemove["1cellphone"] = {call = function()

	doCONDOAnswerPhone()
	
	-- text and voice stuff
	scene:animate(
		{command = "CreateCinematicBorders"},
		{call=function() animateCinematicBorders(scene, 22000) end}
	)
	scene:animate(
		{delay=3500},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_RADIMAR_0_0") end},
		{playAndWait = "VOICE_RADIMAR_0_0:scenegame_16_CONDO_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_RADIMAR_0_1") end},
		{playAndWait = "VOICE_RADIMAR_0_1:scenegame_16_CONDO_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_RADIMAR_0_2") end},
		{playAndWait = "VOICE_RADIMAR_0_2:scenegame_16_CONDO_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_RADIMAR_0_3") end},
		{playAndWait = "VOICE_RADIMAR_0_3:scenegame_16_CONDO_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end}
	)
	-- text and voice stuff

	local	soundWaves = scene:child("51storymessage")	-- get the sprite from the scene pipeline
	soundWaves:relocateAnchorPoint("center")
	soundWaves:setVisible(true)
	local	timeElapsed = 0
	soundWaves:doEvery(1000, function()		-- # tells animation how long to wait before starting
		soundWaves:animate(
			{scale=1.0, alpha=0.4, duration=1000, style="easeInOut"},
			{scale=1.2, alpha=1.0, duration=1000, style="easeInOut"}
		)
		timeElapsed = timeElapsed + 2000
		if timeElapsed < 23000 then
			return 2000	-- this number is delay before repeating; must be larger than duration of stuff we do above
		else
			scene:child("1cellphone"):setX(1000)	-- move offscreen so when data2 code shows cellphone, they won't show up
			scene:child("50layer1"):setX(1000)
			soundWaves:setX(1000)						-- move offscreen so when data2 code shows soundWaves, they won't show up
			return false
		end
	end
	)
end 
}

tarRemoveDelay["5serialcable"] = 14000
tarRemove["5serialcable"] = {call = function()

	local serialCable = scene:child("120serialcableconnected")
	if serialCable ~= nil then
		serialCable:setVisible(false)
	end
	
	-- text and voice stuff
	scene:animate(
		{command = "CreateCinematicBorders"},
		{call=function() animateCinematicBorders(scene, 13000) end}
	)
	scene:animate(
		{delay=1500},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_PILOT_0_0") end},
		{playAndWait = "VOICE_PILOT_0_0:scenegame_11_PLANE_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_PILOT_0_1") end},
		{playAndWait = "VOICE_PILOT_0_1:scenegame_11_PLANE_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end}	
	)
	-- text and voice stuff
	
	local	soundWaves = scene:child("4blackboxmessage")	-- get the sprite from the scene pipeline
	scene:child("3flightrecorder"):setVisible(true)
	soundWaves:relocateAnchorPoint("center")
	soundWaves:setVisible(true)
	local	timeElapsed = 0
	soundWaves:doEvery(100, function()		-- # tells animation how long to wait before starting
		soundWaves:animate(
			{scale=1.0, alpha=0.4, duration=1000, style="easeInOut"},
			{scale=1.2, alpha=1.0, duration=1000, style="easeInOut"}
		)
		timeElapsed = timeElapsed + 2000
		if timeElapsed < 14000 then
			return 2000	-- this number is delay before repeating; must be larger than duration of stuff we do above
		else
			scene:child("5serialcable"):setX(1000)	-- move offscreen so when data2 code shows blackbox, they won't show up
			soundWaves:setX(1000)						-- move offscreen so when data2 code shows soundWaves, they won't show up
			return false
		end
	end
	)
end 
}

tarRemoveDelay["44hamradiowiresstripped"] = 11000
tarRemove["44hamradiowiresstripped"] = {call = function()

	if scene:child("radioWires") ~= nil then
		scene:child("radioWires"):setVisible(false)
	end
	
	-- text and voice stuff
	scene:animate(
		{command = "CreateCinematicBorders"},
		{call=function() animateCinematicBorders(scene, 16000) end}
	)
	scene:animate(
		{delay=700},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_GENERAL_0_0") end},
		{playAndWait = "VOICE_GENERAL_0_0:scenegame_12_TEMPI_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_GENERAL_0_1") end},
		{playAndWait = "VOICE_GENERAL_0_1:scenegame_12_TEMPI_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},	
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_GENERAL_0_2") end},
		{playAndWait = "VOICE_GENERAL_0_2:scenegame_12_TEMPI_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end},
		{delay=200},
		{call=function() startText(scene, "LABEL_TEXT", "TEXT_INSCENE_GENERAL_0_3") end},
		{playAndWait = "VOICE_GENERAL_0_3:scenegame_12_TEMPI_AMB"},	
		{delay=200},
		{call=function() endText(scene, "LABEL_TEXT") end}
		
	)
	-- text and voice stuff
	
	local	soundWaves = scene:child("140pocketsoundwaves")	-- get the sprite from the scene pipeline
	soundWaves:relocateAnchorPoint("center")
	scene:child("45walkietalkie"):setVisible(true)
	soundWaves:setVisible(true)
	local	timeElapsed = 0
	soundWaves:doEvery(1000, function()		-- # tells animation how long to wait before starting
		soundWaves:animate(
			{scale=1.0, alpha=0.4, duration=1000, style="easeInOut"},
			{scale=1.2, alpha=1.0, duration=1000, style="easeInOut"}
		)
		timeElapsed = timeElapsed + 2000
		if timeElapsed < 13000 then
			return 2000	-- this number is delay before repeating; must be larger than duration of stuff we do above
		else
			scene:child("44hamradiowiresstripped"):setX(1000)	-- move offscreen so when data2 code shows blackbox, they won't show up
			soundWaves:setX(1000)						-- move offscreen so when data2 code shows soundWaves, they won't show up
			return false
		end
	end
	)
end 
}

tarRemoveDelay["40openhatch"] = 9000
tarRemove["40openhatch"] = {call = function()
	doBCAVEBeatGameBling()
end
}

tarRemove["83groundvines"] = {call = function()
	doMPATHBatteryAcid()
end
} 

tarRemove["85groundvines1"] = {call = function()
	doMPATHBatteryAcid()
end
} 

tarRemove["43hamradiowires"] = {call = function()
	doTEMPXRadioWires()
end
}

tarRemoveDelay["108targetbatterycharger"] = 3000
tarRemove["108targetbatterycharger"] = {call = function()
	doOFFICChargeBatteries()
end
}

-- Various functions that are used in the game are here

function targetTriggered(strActionItem, strTarget)
	
	-- do we have an animation routine to do here?  Check.
	local tarAnim = tarRemove[strTarget]
	local tarAnimDelay = tarRemoveDelay[strTarget]
	
	local target = scene:child( strTarget )
	--target:bringToFront()	
	
	if tarAnim ~= nil then
--		local newTable = {}  -- = tarAnim
		
--		table.insert( newTable, tarAnim )
			
--		table.insert( newTable, {call = function() scene:onTargetProcessedFinished() end} )		
--		target:animate( newTable )
		local	del = 0
		if tarAnimDelay ~= nil then
			del = tarAnimDelay
		end
		scene:animate(
			{tarAnim},
			{delay = del},
			{call = function() scene:onTargetProcessedFinished() end}
		)
	else
		scene:animate(
			{call = function() scene:onTargetProcessedFinished() end}
		)
	end
	
	return true
end
