
function InitGlobalVariables()
	done = 0
	stage = 0
	cur_timer = 0
	wait_timer = 10
	stage_init = true
end

function OnEnter()

	InitGlobalVariables()
	LG_GameController("LoadLevel","data\\levels\\test2.txt")
	
	
end

function DoStop()
	done = 0

end

function OnExit()
	
--	LG_GameUI("ScreenFadeOut", 1, 1, 1, 2)
--	LG_GameController("RunScript","data\\scripts\\test.lua")
end

OnEnter()

---------------------- Cutscene Initial -----------------------------


while (done < 1) do

if (stage == 0) then

		LG_GameUI("ScreenFadeIn", 1, 1, 1, 2)

		LG_GameController("SetView","FPS")
		LG_GameController("EnableAI","true");	
		
		local x
		local y
		local z

		x,y,z = LG_Camera("GetPosition")
		y = y - 1000

		LG_Camera("SetTarget",x, y, z, "true")

	--	LG_GameController("LoadDialog","data\\dialogue\\dialogue01.txt");
		
		done = done + 1
	end

	LG_Script("Yield")

--[[
	local time = LG_GameController("GetTime")

	if (stage == 0) then

		stage = stage + 1
	
	elseif (stage == 1) then

		LG_GameUI("ScreenFadeIn", 1, 1, 1, 2)

		LG_GameController("EnableAI","true");	
		
		LG_Player("EnablePlayer","false")
		LG_Camera("EnableCutSceneCam","true")

		LG_Camera("SetPosition",-139.83, 2.09, 65.66, "true")
		LG_Camera("SetTarget",-7.52, 1.96, 1.33, "true")
		LG_Camera("SetRotSpeed",1)
		LG_Camera("EnableCamRot","true")
		
	--	done = done + 1
		stage = stage + 1

		LG_Misc("SetWait",2)


	elseif (stage == 2) then

		local ret = LG_Misc("CheckWait", time)
		if(ret > 0) then
			stage = stage + 1
		end

	elseif (stage == 3) then

		LG_Camera("SetPosition",79.25, -166.20, 96.89, "true")
		LG_Camera("SetTarget",8.41, 9.51, 1.33, "true")
		LG_Camera("SetRotSpeed",-1)
		LG_Misc("SetWait",2)
		stage = stage + 1

	elseif (stage == 4) then

		local ret = LG_Misc("CheckWait", time)
		if(ret > 0) then
			stage = stage + 1
		end

	elseif (stage == 5) then


		LG_Camera("SetPosition",-171.14, 100.64, 65.69, "true")
		LG_Camera("SetTarget",-2.81, 1.77, 1.33, "true")
		LG_Camera("SetRotSpeed",1)
		LG_Misc("SetWait",2)
		stage = stage + 1

	end





	LG_Debug("SetWindowText",2,stage)

	LG_Script("Yield")
]]

end
---------------------- Objective Find Bombs ------------------------

local mx
local my
local mz

while (done < 2) do

	local time = LG_GameController("GetTime")

	if (stage == 0) then
		--LG_Misc("SetWait",2)
		--stage = stage + 1
		
	elseif (stage == 1) then

		local ret = LG_Misc("CheckWait", time)
		if(ret > 0) then
			LG_GameController("EnableDialog","true")
			LG_GameController("AddDialog","Press 'w', 'A', 'S', or 'D' to move around",9999)
			stage = stage + 1

			stage_init = true
		end

	elseif (stage==2) then
	
		if (stage_init) then
			mx,my,mz = LG_Player("GetPosition")
			stage_init = false
		
		else
			local nx
			local ny
			local nz

			nx,ny,nz = LG_Player("GetPosition")

			local dist = LG_Math("Distance",mx,my,mz,nx,ny,nz)
			if (dist > .1) then
				LG_GameController("AddDialog","Press / Hold L Mouse Button to fire weapon",9999)
		
				LG_GameUI("SkipDialog",3)
				stage = stage + 1

			end
		end

	elseif (stage==3) then

		local ret = LG_Misc("IsLButtonDown")

		if(ret == 1) then
			
			LG_GameUI("SkipDialog",3)
			stage = stage + 1
		end

	elseif (stage==4) then
		
		local reached = LG_Player("HasReached",70.88, 98.99, -5.67, 6)
		if(reached == 1) then
			done = done + 1	
		end

	end


--	LG_Debug("SetWindowText",2,stage,done)
	

	LG_Script("Yield")
end

---------------------- Cutscene Bomb Found -----------------------------

stage = 0

while (done < 3) do

	local time = LG_GameController("GetTime")

	if (stage==0) then

		LG_Player("EnablePlayer","false")
		LG_GameController("EnableAI","false")

		
		LG_Camera("EnableCutSceneCam","true")
		LG_Camera("SetPosition",62.28, 119.31, -1.27, "true")
		LG_Camera("SetTarget",-5.75, 190.58, -18.37, "true")

		local fx
		local fy
		local fz

		fx,fy,fz = LG_Camera("GetForward")
		fx,fy,fz = LG_Math("MultiplyVec3",fx,fy,fz,2)

		LG_Camera("SetVelocity",fx,fy,fz,"true","true")
		

		local wait_time = 4
		LG_Misc("SetWait", wait_time)

		LG_GameUI("ScreenFadeIn",0,0,0, 1)

		LG_GameController("AddDialog","There it is...",5)
		LG_GameController("AddDialog","Bombs...",5)
		
		
		stage = stage + 1
	
	elseif (stage==1) then
		
		local ret = LG_Misc("CheckWait", time)
		if(ret > 0) then
				
		--	LG_Camera("SetPosition",37.88, 138.79, -2.37, "true")
		--	LG_Camera("SetTarget",-30.15, 210.05, -19.47, "true")

		--	LG_Camera("SetVelocity", 0, 0, 0,"true","true")
			--LG_Camera("EnablePlayerCam","true")
			--LG_GameUI("ScreenFadeIn",0,0,0, 1)

			stage = stage + 1

			LG_Misc("SetWait", 4)
		
		end

	elseif (stage ==2) then
	
		local ret = LG_Misc("CheckWait", time)
		if(ret > 0) then

			LG_Camera("SetVelocity", 0, 0, 0,"true","true")

			local fx
			local fy
			local fz

			fx,fy,fz = LG_Camera("GetForward")

			LG_Player("SetPosition",62.26, 116.59, -5.21)
			LG_Player("SetFacing",fx,fy,fz)

			LG_Camera("EnableCutSceneCam","false")
			LG_Player("EnablePlayer","true")
			LG_GameController("EnableAI","true")

			LG_Camera("SetPosition",66.97, 111.78, -1.60, "true")
			LG_Camera("SetTarget",-2.72, 180.79, -21.09, "true")

			
			LG_GameUI("ScreenFadeIn",0,0,0, 1)

			stage = stage + 1
			done = done + 1
		end

	end

	--LG_Debug("SetWindowText",3,stage,LG_Misc("GetWait"),done)
	
	LG_Script("Yield")
end

------------------- GamePlay Ambush -----------------------

stage = 0

while (done < 4) do

	if(stage == 0) then
	
		local reached = LG_Player("HasReached",34.85, 141.84, -5.50, 10)
		if(reached == 1) then
		
			LG_GameController("AddSoldier","Flame Thrower",1,27.83, 149.90, 10.50)
			LG_GameController("AddSoldier","Flame Thrower",1,28.83, 149.90, 10.50)
		

			done = done + 1	
		end
	end
	
	LG_Script("Yield")


end

LG_Script("Stop")

OnExit()

