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

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


function InsertObjectRange(Towers, index1, index2)
	for i = index1, index2 do
		Towers[i]:InsertIntoWorld();
	end
end

function LazerHelper(Shooter, LoaderName)
	local FirePosition = LvlLoader:GetInfo(LoaderName).Pos_;
	Shooter:FireMahLazer(FirePosition, Vector3D(0.0, 0.0, 50.0), 100.0, 700.0, 500.0, 4, 2, true);
end

SpawnInsertionTriggers = true
if SpawnInsertionTriggers == true then
	-- Spawn the towers
	
	SpawnTriggerInfo(LvlLoader:GetInfo("tier01FireTrigger01"), false, false, "TikiGod:FireMahLazer(LvlLoader:GetInfo(\"tier01FirePosition01\").Pos_, Vector3D(0.0, 0.0, 0.0), 100.0, 450.0, 250.0, 4, 2, true)");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier01FireTrigger02"), false, false, "TikiGod:FireMahLazer(LvlLoader:GetInfo(\"tier01FirePosition02\").Pos_, Vector3D(0.0, 0.0, 0.0), 100.0, 450.0, 250.0, 4, 2, true)");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier01FireTrigger03"), false, false, "TikiGod:FireMahLazer(LvlLoader:GetInfo(\"tier01FirePosition03\").Pos_, Vector3D(0.0, 0.0, 0.0), 100.0, 450.0, 250.0, 4, 2, true)");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier01FireTrigger04"), false, false, "TikiGod:FireMahLazer(LvlLoader:GetInfo(\"tier01FirePosition04\").Pos_, Vector3D(0.0, 0.0, 0.0), 100.0, 450.0, 250.0, 4, 2, true)");
	
	tier02FirePosition01 = LvlLoader:GetInfo("tier02FirePosition01").Pos_
	tier02FirePosition02 = LvlLoader:GetInfo("tier02FirePosition02").Pos_
	tier02FirePosition03 = LvlLoader:GetInfo("tier02FirePosition03").Pos_
	tier02FirePosition04 = LvlLoader:GetInfo("tier02FirePosition04").Pos_
	tier02FirePosition05 = LvlLoader:GetInfo("tier02FirePosition05").Pos_
	tier02FirePosition06 = LvlLoader:GetInfo("tier02FirePosition06").Pos_
	SpawnTriggerInfo(LvlLoader:GetInfo("tierTrigger02"), false, false,
	[[
		InsertObjectRange(BlockTowers, 27, 38);
		EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(tier02FirePosition01, Vector3D(0.0, 0.0, -100.0), 100.0, 650.0, 500.0, 4, 2, true)");
		EventManager:AddEvent(false, 0.4, "TikiGod:FireMahLazer(tier02FirePosition02, Vector3D(0.0, 0.0, -100.0), 100.0, 650.0, 500.0, 4, 2, true)");
		EventManager:AddEvent(false, 0.6, "TikiGod:FireMahLazer(tier02FirePosition03, Vector3D(0.0, 0.0, -100.0), 100.0, 650.0, 500.0, 4, 2, true)");
		EventManager:AddEvent(false, 0.8, "TikiGod:FireMahLazer(tier02FirePosition04, Vector3D(0.0, 0.0, -100.0), 100.0, 650.0, 500.0, 4, 2, true)");
		EventManager:AddEvent(false, 1.0, "TikiGod:FireMahLazer(tier02FirePosition05, Vector3D(0.0, 0.0, -100.0), 100.0, 650.0, 500.0, 4, 2, true)");
		EventManager:AddEvent(false, 1.2, "TikiGod:FireMahLazer(tier02FirePosition06, Vector3D(0.0, 0.0, -100.0), 100.0, 650.0, 500.0, 4, 2, true)");
	]])
	
	tier03FirePosition01 = LvlLoader:GetInfo("tier03FirePosition01").Pos_
	tier03FirePosition02 = LvlLoader:GetInfo("tier03FirePosition02").Pos_
	tier03FireTarget01 = LvlLoader:GetInfo("tier03FireTarget01").Pos_
	tier03FireTarget02 = LvlLoader:GetInfo("tier03FireTarget02").Pos_
	SpawnTriggerInfo(LvlLoader:GetInfo("tierTrigger03"), false, false,
	[[
		InsertObjectRange(BlockTowers, 39, 70);
		InsertObjectRange(BlockTowers, 71, 102);
		EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(tier03FirePosition01, tier03FireTarget01, 200.0, 500.0, 250.0, 41, 4, false)");
		EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(tier03FirePosition02, tier03FireTarget02, 200.0, 500.0, 250.0, 41, 4, false)");
	]])

	SpawnTriggerInfo(LvlLoader:GetInfo("tierTrigger04"), false, false,
	[[
	]])
	
	tier05FirePosition01 = LvlLoader:GetInfo("tier05FirePosition01").Pos_
	tier05FirePosition02 = LvlLoader:GetInfo("tier05FirePosition02").Pos_
	tier05FireTarget01 = LvlLoader:GetInfo("tier05FireTarget01").Pos_
	tier05FireTarget02 = LvlLoader:GetInfo("tier05FireTarget02").Pos_
	SpawnTriggerInfo(LvlLoader:GetInfo("tierTrigger05"), false, false,
	[[
		InsertObjectRange(BlockTowers, 103, 118);
		InsertObjectRange(BlockTowers, 119, 134);
		EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(tier05FirePosition01, tier05FireTarget01, 200.0, 500.0, 250.0, 49, 4, false)");
		EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(tier05FirePosition02, tier05FireTarget02, 200.0, 500.0, 250.0, 49, 4, false)");
	]])
	
	SpawnTriggerInfo(LvlLoader:GetInfo("tierTrigger06"), false, false,
	[[
		InsertObjectRange(BlockTowers, 135, 155);
	]])
	
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger01"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition01\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger02"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition02\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger03"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition03\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger04"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition04\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger05"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition05\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger06"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition06\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger07"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition07\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger08"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition08\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger09"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition09\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger10"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition10\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger11"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition11\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger12"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition12\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger13"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition13\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger14"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition14\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger15"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition15\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger16"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition16\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger17"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition17\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger18"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition18\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger19"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition19\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger20"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition20\")");
	SpawnTriggerInfo(LvlLoader:GetInfo("tier06FireTrigger21"), false, false, "LazerHelper(TikiGod, \"tier06FirePosition21\")");
end

SpawnDestructionTriggers = true
if SpawnDestructionTriggers == true then
	FrameInterval = 3
	-- Spawn the deletion triggers
	tier01DestuctionPosition01 = LvlLoader:GetInfo("tier01DestructionPosition01")
	tier01DestuctionTarget01 = LvlLoader:GetInfo("tier01DestructionTarget01")
	SpawnTriggerInfo(LvlLoader:GetInfo("tierDestructionTrigger01"), false, false,
	[[
		TikiGod:FireMahLazer(tier01DestuctionPosition01.Pos_, tier01DestuctionTarget01.Pos_, 200.0, 800.0, 300.0, 36, FrameInterval, false, false);
	]])

	tier02DestuctionPosition01 = LvlLoader:GetInfo("tier02DestructionPosition01")
	tier02DestuctionTarget01 = LvlLoader:GetInfo("tier02DestructionTarget01")
	SpawnTriggerInfo(LvlLoader:GetInfo("tierDestructionTrigger02"), false, false,
	[[
		TikiGod:FireMahLazer(tier02DestuctionPosition01.Pos_, tier02DestuctionTarget01.Pos_, 200.0, 2500.0, 300.0, 36, FrameInterval, false, false);
	]])

	tier03DestuctionPosition01 = LvlLoader:GetInfo("tier03DestructionPosition01")
	tier03DestuctionTarget01 = LvlLoader:GetInfo("tier03DestructionTarget01")
	tier03DestuctionPosition02 = LvlLoader:GetInfo("tier03DestructionPosition02")
	tier03DestuctionTarget02 = LvlLoader:GetInfo("tier03DestructionTarget02")
	SpawnTriggerInfo(LvlLoader:GetInfo("tierDestructionTrigger03"), false, false,
	[[
		TikiGod:FireMahLazer(tier03DestuctionPosition01.Pos_, tier03DestuctionTarget01.Pos_, 200.0, 800.0, 300.0, 57, FrameInterval, false, false);
		TikiGod:FireMahLazer(tier03DestuctionPosition02.Pos_, tier03DestuctionTarget02.Pos_, 200.0, 800.0, 300.0, 57, FrameInterval, false, false);
	]])

	tier04DestuctionPosition01 = LvlLoader:GetInfo("tier04DestructionPosition01")
	tier04DestuctionTarget01 = LvlLoader:GetInfo("tier04DestructionTarget01")
	tier04DestuctionPosition02 = LvlLoader:GetInfo("tier04DestructionPosition02")
	tier04DestuctionTarget02 = LvlLoader:GetInfo("tier04DestructionTarget02")
	SpawnTriggerInfo(LvlLoader:GetInfo("tierDestructionTrigger04"), false, false,
	[[
		TikiGod:FireMahLazer(tier04DestuctionPosition01.Pos_, tier04DestuctionTarget01.Pos_, 200.0, 2500.0, 300.0, 36, FrameInterval, false, false);
		TikiGod:FireMahLazer(tier04DestuctionPosition02.Pos_, tier04DestuctionTarget02.Pos_, 200.0, 2500.0, 300.0, 36, FrameInterval, false, false);
	]])

	tier05DestuctionPosition01 = LvlLoader:GetInfo("tier05DestructionPosition01")
	tier05DestuctionTarget01 = LvlLoader:GetInfo("tier05DestructionTarget01")
	tier05DestuctionPosition02 = LvlLoader:GetInfo("tier05DestructionPosition02")
	tier05DestuctionTarget02 = LvlLoader:GetInfo("tier05DestructionTarget02")
	SpawnTriggerInfo(LvlLoader:GetInfo("tierDestructionTrigger05"), false, false,
	[[
		TikiGod:FireMahLazer(tier05DestuctionPosition01.Pos_, tier05DestuctionTarget01.Pos_, 200.0, 1000.0, 300.0, 36, FrameInterval, false, false);
		TikiGod:FireMahLazer(tier05DestuctionPosition02.Pos_, tier05DestuctionTarget02.Pos_, 200.0, 1000.0, 300.0, 36, FrameInterval, false, false);
	]])
end