--[[
Author: Will Graham (wgraham@digipen.edu)

Copyright 2008-2009 DigiPen (USA) Corp.
]]--

--print("HillLevel_Init.lua")


if GameEngine.FirstRun == true then
	Sound:StopMusic();
	Sound:PlayMusic("IgneousCity");
	
	StartPos = LvlLoader:GetInfo("playerStart01").Pos_
	startCameraPosition01 = LvlLoader:GetInfo("startCameraPosition01").Pos_
	startCameraTarget01 = LvlLoader:GetInfo("startCameraTarget01").Pos_
	--EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPosition(DefaultCameraVec, DefaultCameraSpeed + 0.05, DefaultCameraRelative, DefaultCameraFixed)");
	EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPositionLookat(startCameraPosition01, startCameraTarget01, 1.0)");
	EventManager:AddEvent(false, 0.0, "PlayerData:LockPlayer(Vector3D(0.0, 1.0, 0.0))");
else
	StartPos = LvlLoader:GetInfo("playerStart02").Pos_
	startCameraPosition02 = LvlLoader:GetInfo("startCameraPosition02").Pos_
	startCameraTarget02 = LvlLoader:GetInfo("startCameraTarget02").Pos_
	EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPositionLookat(startCameraPosition02, startCameraTarget02, 1.0)");
	EventManager:AddEvent(false, 0.0, "PlayerData:LockPlayer(Vector3D(0.0, 1.0, 0.0))");
	EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(startFirePosition01.Pos_, startFireTarget01.Pos_, 100.0, 500.0, 600.0, 10, 1, false)");
	EventManager:AddEvent(false, 2.0, "PlayerData:SetCameraPosition(DefaultCameraVec, DefaultCameraSpeed + 0.05, DefaultCameraRelative, DefaultCameraFixed)");
	EventManager:AddEvent(false, 3.5, "PlayerData:UnlockPlayer()");
	EventManager:AddEvent(false, 5.0, "TikiGod:ActivateAI(true)");
end
cameraStartPos = StartPos;



tikiExplosionCameraPosition01 = LvlLoader:GetInfo("tikiExplosionCameraPosition01").Pos_
tikiExplosionCameraTarget01 = LvlLoader:GetInfo("tikiExplosionCameraTarget01").Pos_
--EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPositionLookat(tikiExplosionCameraPosition01, tikiExplosionCameraTarget01, 1.0)");
--EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPosition(tikiExplosionCameraPosition01, 1.0, false, true)");
--EventManager:AddEvent(false, 1.0, "TikiGod:Explode()")

--EventManager:AddEvent(false, 0.1, "PlayerData:SetCameraPosition(DefaultCameraVec, DefaultCameraSpeed + 0.05, DefaultCameraRelative, DefaultCameraFixed)");
--EventManager:AddEvent(false, 0.0, "PlayerData.JumpDuration_ = 0.0");
EventManager:AddEvent(false, 0.0, "PlayerData.JumpSpeed_ = 150.0");
EventManager:AddEvent(false, 0.0, "PlayerData.MoveSpeed_ = 1000.0");
EventManager:AddEvent(false, 0.0, "PlayerData.Acceleration_ = 7.0");

EventManager:AddEvent(false, 0.0, "PlayerData:SetEmissiveColor(Vector3D(1.0, 0.0, 0.0), true)")
EventManager:AddEvent(false, 0.0, "PlayerData:ToggleLight(true)")
EventManager:AddEvent(false, 0.0, "PlayerData:SetRimColor(Vector3D(0.0, 0.3, 1.0), 1.0)")

--155
BlockTowers = {}
for i = 1, 155 do

	local TowerName = "blockTower"

	if i < 10 then
		TowerName = TowerName .. 0 .. i
	else
		TowerName = TowerName .. i
	end
	
	local TowerInfo = LvlLoader:GetInfo(TowerName)
	BlockTowers[i] = SpawnTowerInfo(TowerInfo, false, false)
	
	if i <= 26 then
		BlockTowers[i]:InsertIntoWorld();
	end

end

Buildings = {}
for i = 1, 0 do

	local TowerName = "structures"

	if i < 10 then
		TowerName = TowerName .. 0 .. i
	else
		TowerName = TowerName .. i
	end
	
	local TowerInfo = LvlLoader:GetInfo(TowerName)
	Buildings[i] = SpawnTowerInfo(TowerInfo, false, false)

end

--6
for i = 1, 6 do

	local DeathBoundaryName = "deathBoundary"

	if i < 10 then
		DeathBoundaryName = DeathBoundaryName .. 0 .. i
	else
		DeathBoundaryName = DeathBoundaryName .. i
	end
	
	SpawnDeathBoundaryInfo(LvlLoader:GetInfo(DeathBoundaryName));

end

--96
for i = 1, 96 do

	local PlatformName = "lua"
	
	if i < 10 then
		PlatformName = PlatformName .. 0 .. i
	else
		PlatformName = PlatformName .. i
	end
	
	SpawnPlatformInfo(LvlLoader:GetInfo(PlatformName))

end


SpawnPlatformInfo(LvlLoader:GetInfo("endPlatform01"))
SpawnPlatformInfo(LvlLoader:GetInfo("startPlatform01"))
SpawnTowerInfo(LvlLoader:GetInfo("introPiece01"), true, true)

TikiGodInfo = LvlLoader:GetInfo("tikiGod02")
TikiGod = GlobalSpawnController:SpawnTikiGod(TikiGodInfo.Pos_, TikiGodInfo.Scale_, false, 200.0);

TikiGodInfo = LvlLoader:GetInfo("tikiGod02")
--TikiGod2 = GlobalSpawnController:SpawnTikiGod(TikiGodInfo.Pos_, TikiGodInfo.Scale_, false, 200.0);

--Info = LvlLoader:GetInfo("risingLava01");
--GlobalSpawnController:SpawnRisingLava(Info.Pos_, Info.Scale_, Info.Rot_, Vector3D(0.0, 0.0, 40.0), 0)


if GameEngine.FirstRun == true then
	startFirePosition01 = LvlLoader:GetInfo("startFirePosition01")
	startFirePosition02 = LvlLoader:GetInfo("startFirePosition02")
	startFirePosition03 = LvlLoader:GetInfo("startFirePosition03")
	startFirePosition04 = LvlLoader:GetInfo("startFirePosition04")
	startFireTarget01 = LvlLoader:GetInfo("startFireTarget01")
	startFireTarget02 = LvlLoader:GetInfo("startFireTarget02")
	startFireTarget03 = LvlLoader:GetInfo("startFireTarget03")
	startFireTarget04 = LvlLoader:GetInfo("startFireTarget04")
	startCameraPosition02 = LvlLoader:GetInfo("startCameraPosition02").Pos_
	startCameraTarget02 = LvlLoader:GetInfo("startCameraTarget02").Pos_
		--EventManager:AddEvent(false, 0.5, "PlayerData:SetCameraPosition(Vector3D(-300.0, 0.0, 50.0), 0.1, true, true)");
		--EventManager:AddEvent(false, 1.5, "PlayerData:SetCameraPositionLookat(startCameraPosition02, startCameraTarget02, 0.05)");
		--EventManager:AddEvent(false, 1.6, "PlayerData:LockPlayer(Vector3D(0.0, 0.0, 0.0))");
		--EventManager:AddEvent(false, 4.0, "PlayerData:LockPlayer(Vector3D(0.0, 1.0, 0.0))");
		--EventManager:AddEvent(false, 6.0, "PlayerData:SetCameraPosition(Vector3D(0.0, -500.0, 100.0), 1.0, true, true)");
	SpawnTriggerInfo(LvlLoader:GetInfo("startTrigger01"), false, false,
	[[
		EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(startFirePosition01.Pos_, startFireTarget01.Pos_, 100.0, 500.0, 600.0, 10, 1, false)");
		EventManager:AddEvent(false, 0.7, "PlayerData:SetCameraPosition(Vector3D(0.0, -300.0, 50.0), 0.1, true, true)");
		EventManager:AddEvent(false, 1.1, "PlayerData:SetCameraPosition(DefaultCameraVec, DefaultCameraSpeed + 0.05, DefaultCameraRelative, DefaultCameraFixed)");
		EventManager:AddEvent(false, 3.5, "PlayerData:UnlockPlayer()");
		EventManager:AddEvent(false, 5.0, "TikiGod:ActivateAI(true)");
	]])
end

endLockPos01 = LvlLoader:GetInfo("endLockPos01").Pos_

endCameraPosition01 = LvlLoader:GetInfo("endCameraPosition01").Pos_
endCameraTarget01 = LvlLoader:GetInfo("endCameraTarget01").Pos_
	--PlayerData:SetCameraPositionLookat(endCameraPosition01, endCameraTarget01, 0.1)
	
LastTrigger = true
if LastTrigger == true then
	SpawnTriggerInfo(LvlLoader:GetInfo("endTrigger02"), false, false,
	[[
		TikiGod:ActivateAI(false);
		PlayerData:LockPlayer(Vector3D(0.0, 1.0, 0.0));
		EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPositionLookat(tikiExplosionCameraPosition01, tikiExplosionCameraTarget01, 0.006)");
	]])
end

SpawnTriggerInfo(LvlLoader:GetInfo("tikiExplosionTrigger01"), false, false,
[[
	FinalScale = TikiGodInfo.Scale_
	FinalScale.x = FinalScale.x * 4.0;
	FinalScale.y = FinalScale.y * 4.0;
	FinalScale.z = FinalScale.z * 4.0;
	EventManager:AddEvent(false, 0.0, "GameEngine:PlayParticleEvent(\"levelLoader/compositeObjects/finalExplosion.igobj\", TikiGodInfo.Pos_, FinalScale)");
	--EventManager:AddEvent(false, 0.0, "Sound:PlayEvent(\"BridgeExplosion\", tikiExplosionCameraPosition01, Vector3D(0.0, 0.0, 0.0), true, true)");
	EventManager:AddEvent(false, 0.0, "TikiGod:Explode()");
	EventManager:AddEvent(false, 0.0, "PlayerData:LockPlayer(Vector3D(0.0, 0.0, 0.0))");
	--PlayerData.Tiki_:Explode();
	EventManager:AddEvent(false, 0.0, "PlayerData:ShakeCamera(1.0, 3000, 3000)");
	--EventManager:AddEvent(false, 1.0, "PlayerData:SetCameraPosition(Vector3D(0.0, 10.0, -5.0), 0.1, true, true)");
	EventManager:AddEvent(false, 3.0, "GameEngine.CurrentLevelNum_ = 0");
	EventManager:AddEvent(false, 3.0, "GameEngine.GameOver = true");
	EventManager:AddEvent(false, 3.0, "GameEngine.Credits = true");
]])

dofile("Scripts/HillLevel/HillLevel_TowerTriggers.lua")

MinZ = -2000.0
KillsNeeded = 0


if GameEngine.FirstRun == true then
	GameEngine.FirstRun = false
end