--MutantTeam1 = { "c12" }
--MutantTeam2 = { "c11" }
--MutantTeam3 = { "c9" }
--MutantTeam4 = { "c8" }
--MutantTeam5 = { "c7" }
--MutantTeam6 = { "c6" }
--MutantTeam7 = { "c5" }
--MutantTeam8 = { "c4" }
--MutantTeam9 = { "c3" }
--MutantTeam10 = { "c2" }
--MutantTeam11 = { "c1" }
--MutantTeam12 = { "c10" }

--Wave = 0
--Waves =
--{
--	{ delay = 500, units = { MutantTeam1 } },
--	{ delay = 500, units = { MutantTeam2 } },
--	{ delay = 500, units = { MutantTeam3 } },
--	{ delay = 500, units = { MutantTeam4 } },
--	{ delay = 500, units = { MutantTeam5 } },
--	{ delay = 500, units = { MutantTeam6 } },
--	{ delay = 500, units = { MutantTeam7 } },
--	{ delay = 500, units = { MutantTeam8 } },
--	{ delay = 500, units = { MutantTeam9 } },
--	{ delay = 500, units = { MutantTeam10 } },
--	{ delay = 500, units = { MutantTeam11 } },
--	{ delay = 500, units = { MutantTeam12 } },
--	{ delay = 500, units = { MutantTeam2 } },
--	{ delay = 500, units = { MutantTeam3 } },
--	{ delay = 500, units = { MutantTeam4 } },
--	{ delay = 500, units = { MutantTeam5 } },
--	{ delay = 500, units = { MutantTeam6 } },
--	{ delay = 500, units = { MutantTeam7 } },
--	{ delay = 500, units = { MutantTeam8 } },
--	{ delay = 500, units = { MutantTeam9 } },
--	{ delay = 500, units = { MutantTeam10 } },
--	{ delay = 500, units = { MutantTeam11 } },
--	{ delay = 500, units = { MutantTeam12 } }
--}
--EntryPoints = { EntryPoint, EntryPoint1, EntryPoint2, EntryPoint3, EntryPoint4, EntryPoint5, EntryPoint6, EntryPoint7 }
--MiddlePoints = { MiddlePoint, MiddlePoint1, MiddlePoint2, MiddlePoint3 }

--SendWave = function()
--	Wave = Wave + 1
--	local wave = Waves[Wave]
--	Trigger.AfterDelay(wave.delay, function()
--		Utils.Do(wave.units, function(units)
--			local entry = Utils.Random(EntryPoints).Location
--			local target = Utils.Random(MiddlePoints).Location
--			SendUnits(entry, units, target)
--		end)
--		if (Wave < #Waves) then
--			local delay = Utils.RandomInteger(DateTime.Seconds(10), DateTime.Seconds(20))
--			Trigger.AfterDelay(delay, SendWave)
--		end
--	end)

--end

--SendUnits = function(entryCell, unitTypes, targetCell)
--	local units = Reinforcements.Reinforce(Mutants, unitTypes, { entryCell }, 40, function(a)
--		if not a.HasProperty("AttackMove") then
--			Trigger.OnIdle(a, function(a)
--				a.Move(targetCell)
--			end)
--			return
--		end

--		Trigger.OnIdle(a, function(a)
--			if a.Location ~= targetCell then
--				a.Move(targetCell)
--			else
--				a.Hunt()
--			end
--		end)
--	end)
--end

--MAXPLAYERCOUNT = 8

--Teams =
--{
--	{ units = { "c1" },			entryCell = Actor147.Location, building = Actor110 },
--	{ units = { "c2" }, 		entryCell = Actor148.Location, building = Actor104 },
--	{ units = { "c3" }, 		entryCell = Actor149.Location, building = Actor112 },
--	{ units = { "c4" }, 		entryCell = Actor154.Location, building = Actor106 },
--	{ units = { "c5" }, 		entryCell = Actor166.Location, building = Actor82 },
--	{ units = { "c6" }, 		entryCell = Actor198.Location, building = Actor136 },
--	{ units = { "c7" },			entryCell = Actor199.Location, building = Actor81 },
--	{ units = { "c8" }, 		entryCell = Actor200.Location, building = Actor111 },
--	{ units = { "c9" },			entryCell = Actor201.Location, building = Actor126 },
--	{ units = { "c11" }, 		entryCell = Actor202.Location, building = Actor87 },
--	{ units = { "c12" }, 		entryCell = Actor203.Location, building = Actor85 },
--	{ units = { "c10" }, 		entryCell = Actor203.Location, building = Actor110 }
--}

--CreateTeam = function(Team)
--	if Team.building.IsDead then
--		return
--	end
--	local units = Reinforcements.Reinforce(Mutants, Team.units, { Team.entryCell }, 25)
--	SendTeam(units)
--	Utils.Do(units, function(actor)
--		if not actor.IsDead then
--			Trigger.OnIdle(actor, actor.Hunt)
--		end
--	end)
--	Trigger.AfterDelay(DateTime.Seconds(delayRepeatTeam), function()
--		CreateTeam(Team)
--	end)
--end

--SendTeam = function(units)
--	local player = Utils.Random(players)
--	local waypoint = Map.NamedActor("SPMulti"..tostring(player.Spawn - 1))	
--	Utils.Do(units, function(unit)
--		if not unit.IsDead then
--			unit.AttackMove(waypoint.Location)
--			unit.Hunt()
--		end
--	end)
--end


--TanyaActor = "e7"
----TanyaVoices = { "laugh", "tuffguy", "bombit" }

--Entry = function()
--	if Map.Difficulty == "1 Player" then
--		Tanya = Actor.Create(TanyaActor, true, { Owner = Multi0, Location = SpawnPoint.Location })
--		Tanya.AttackMove(Waypoint.Location)
--		Trigger.OnKilled(Tanya, MissionFailed)
--		Trigger.AfterDelay(DateTime.Seconds(3), function()
--			MapRoom1Camera = Actor.Create("Camera.MapRoom1", true, { Owner = Multi0, Location = CameraRoom1.Location })
--		end)
--	elseif Map.Difficulty == "2 Players" then
		
--		Tanya = Actor.Create(TanyaActor, true, { Owner = Multi0, Location = SpawnPoint.Location })
--		Tanya.AttackMove(Waypoint.Location)
--		Tanya1 = Actor.Create(TanyaActor, true, { Owner = Multi1, Location = SpawnPoint.Location })
--		Tanya1.AttackMove(Waypoint.Location)
--		if Tanya.IsDead and not Tanya1.IsDead then
--			Trigger.OnKilled(Tanya1, MissionFailed)
--		end
--		if Tanya1.IsDead and not Tanya.IsDead then
--			Trigger.OnKilled(Tanya, MissionFailed)
--		end
--		Trigger.AfterDelay(DateTime.Seconds(3), function()
--			MapRoom1CameraMulti0 = Actor.Create("Camera.MapRoom1", true, { Owner = Multi0, Location = CameraRoom1.Location })
--			MapRoom1CameraMulti1 = Actor.Create("Camera.MapRoom1", true, { Owner = Multi1, Location = CameraRoom1.Location })
--		end)
--	end
--end

--ControlCenterTrigger = { CPos.New(82,36) }
--Trigger.OnEnteredFootprint(ControlCenterTrigger, function(a, id)
--	Trigger.RemoveFootprintTrigger(id)
--	if Map.Difficulty == "1 Player" then
--		if a.Owner == Multi0 then
--			Trigger.RemoveFootprintTrigger(id)
--			Media.PlaySoundNotification(Multi0, "LevelUp")
--			local SectorGroup1 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint1.Location, Waypoint2.Location })
--			Utils.Do(SectorGroup1, function(unit)
--				SendUnits(unit)
--			end)
--			Wall.Kill()
--			Wall1.Kill()
--			Wall2.Kill()
--			local SectorGroup1 = Reinforcements.Reinforce(Soviets, { "e1", "e4", "e1" }, { SpawnPoint3.Location, Waypoint4.Location })
--			Utils.Do(SectorGroup1, function(unit)
--				SendUnits(unit)
--			end)
--			Trigger.AfterDelay(DateTime.Seconds(5), function()
--				local SectorGroup2 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint4.Location, Waypoint5.Location })
--				Utils.Do(SectorGroup2, function(unit)
--					SendUnits(unit)
--				end)
--				local SectorGroup3 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint1.Location, Waypoint2.Location })
--				Utils.Do(SectorGroup3, function(unit)
--					SendUnits(unit)
--				end)
--				Trigger.AfterDelay(DateTime.Seconds(5), function()
--					local SectorGroup4 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1", "e1", "e1"  }, { SpawnPoint2.Location, Waypoint3.Location })
--					Utils.Do(SectorGroup4, function(unit)
--						SendUnits(unit)
--					end)
--					local SectorGroup5 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint3.Location, Waypoint4.Location })
--					Utils.Do(SectorGroup5, function(unit)
--						SendUnits(unit)
--					end)
--				end)
--			end)
--		end
--	elseif Map.Difficulty == "2 Players" then
--		if a.Owner == Multi0 or a.Owner == Multi1 then
--			Trigger.RemoveFootprintTrigger(id)
--			Media.PlaySoundNotification(Multi0, "LevelUp")
--			Media.PlaySoundNotification(Multi1, "LevelUp")
--			local SectorGroup1 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint1.Location, Waypoint2.Location })
--			Utils.Do(SectorGroup1, function(unit)
--				SendUnits(unit)
--			end)
--			Wall.Kill()
--			Wall1.Kill()
--			Wall2.Kill()
--			local SectorGroup1 = Reinforcements.Reinforce(Soviets, { "e1", "e4", "e1" }, { SpawnPoint3.Location, Waypoint4.Location })
--			Utils.Do(SectorGroup1, function(unit)
--				SendUnits(unit)
--			end)
--			Trigger.AfterDelay(DateTime.Seconds(5), function()
--				local SectorGroup2 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint4.Location, Waypoint5.Location })
--				Utils.Do(SectorGroup2, function(unit)
--					SendUnits(unit)
--				end)
--				local SectorGroup3 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint1.Location, Waypoint2.Location })
--				Utils.Do(SectorGroup3, function(unit)
--					SendUnits(unit)
--				end)
--				Trigger.AfterDelay(DateTime.Seconds(5), function()
--					local SectorGroup4 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1", "e1", "e1"  }, { SpawnPoint2.Location, Waypoint3.Location })
--					Utils.Do(SectorGroup4, function(unit)
--						SendUnits(unit)
--					end)
--					local SectorGroup5 = Reinforcements.Reinforce(Soviets, { "e1", "e1", "e1", "e1" }, { SpawnPoint3.Location, Waypoint4.Location })
--					Utils.Do(SectorGroup5, function(unit)
--						SendUnits(unit)
--					end)
--				end)
--			end)
--		end
--	end
--end)

Scorch = function()
	Lighting.Red = 0.9
	Lighting.Green = 0.9
	Lighting.Blue = 1
	--Lighting.Ambient = Light
	--if Light < 1.311 then
	--	if Light < 1.20 then
	--		return
	--	else
	--		Light = Light + 0.1
	--		Trigger.AfterDelay(10, function()
	--			Scorch()
	--		end)
	--	end
	--end
end

LightningFlash = function() 
	local delay = Utils.RandomInteger(20, 10)
	Lighting.Flash("LightningStrike", delay)
	Lighting.Flash("LightningStrike", delay)
	Tick = function()
		if (Utils.RandomInteger(1, 200) == 10) then
			local delay = Utils.RandomInteger(1, 10)
			Lighting.Flash("LightningStrike", delay)
			Trigger.AfterDelay(delay, function()
				Media.PlaySound("thunder" .. Utils.RandomInteger(1,6) .. ".aud")
			end)
		end
		if (Utils.RandomInteger(1, 200) == 10) then
			Media.PlaySound("thunder-ambient.aud")
		end
	end
end

EggSpawn = function()
	Trigger.AfterDelay(DateTime.Seconds(60), function()
		Actor.Create(ZillaEgg, true, { Owner = Neutral, Location = ZillaSpawn2.Location })
		Actor.Create(ZillaEgg, true, { Owner = Neutral, Location = ZillaSpawn5.Location })
		Trigger.AfterDelay(DateTime.Seconds(120), function()
			AliensSpawn()
			Actor.Create(ZillaEgg, true, { Owner = Neutral, Location = ZillaSpawn1.Location })
			Trigger.AfterDelay(DateTime.Seconds(80), function()
				Actor.Create(ZillaEgg, true, { Owner = Neutral, Location = ZillaSpawn4.Location })
				Trigger.AfterDelay(DateTime.Seconds(120), function()
					Actor.Create(ZillaEgg, true, { Owner = Neutral, Location = ZillaSpawn3.Location })
					Trigger.AfterDelay(DateTime.Seconds(180), function()
						Actor.Create(ZillaEgg, true, { Owner = Neutral, Location = ZillaSpawn6.Location })
					end)
				end)
			end)
		end)
	end)
end

Smoke = "flare"
ShipGrounded = "ice01"
Ship = "mothership"
ZillaEgg = "radiotower"
Redeemer = "FIREBALLMECHWARRIOR"
Exciter = "FIREBALLEXCITER"
Reclaimer = "FIREBALLEXOMECH"
Redeemer1 = "fireball.husk"

RedeemerSpawn = function()
	Asteroid = Actor.Create(Redeemer, true, { Owner = Creeps, Location = Waypoint1.Location })
	Asteroid.Move(ZillaSpawn2.Location)
	Asteroid1 = Actor.Create(Redeemer, true, { Owner = Creeps, Location = Waypoint1.Location })
	Asteroid1.Move(ZillaSpawn4.Location)
	Asteroid2 = Actor.Create(Redeemer, true, { Owner = Creeps, Location = Waypoint1.Location })
	Asteroid2.Move(ZillaSpawn5.Location)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Asteroid.Kill()
		Asteroid1.Kill()
		Asteroid2.Kill()

	end)
end

ExciterSpawn = function()
	Asteroid = Actor.Create(Exciter, true, { Owner = Creeps, Location = Waypoint1.Location })
	Asteroid.Move(ZillaSpawn3.Location)
	Asteroid1 = Actor.Create(Exciter, true, { Owner = Creeps, Location = Waypoint1.Location })
	Asteroid1.Move(ZillaSpawn1.Location)
	Asteroid2 = Actor.Create(Exciter, true, { Owner = Creeps, Location = Waypoint1.Location })
	Asteroid2.Move(ZillaSpawn6.Location)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Asteroid.Kill()
		Asteroid1.Kill()
		Asteroid2.Kill()
	end)
end

ReclaimerSpawn = function()
	Asteroid = Actor.Create(Reclaimer, true, { Owner = Creeps, Location = Waypoint1.Location })
	Asteroid.Move(ZillaSpawn4.Location)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Asteroid.Kill()
	end)
end

WorldLoaded = function()
	Trigger.AfterDelay(DateTime.Minutes(5), function()
		--Asteroid = Actor.Create(Redeemer, true, { Owner = Creeps, Location = Waypoint1.Location })
		--Asteroid.Move(ZillaSpawn6.Location)
		Media.PlaySound("mothershipdeployed.aud")
		Mothership = Actor.Create(Ship, true, { Owner = Neutral, Location = Spawn.Location })
		Mothership.Move(Waypoint.Location)
		Trigger.AfterDelay(DateTime.Seconds(3), function()
			--Asteroid.Kill()
			AliensSpawn()
			Media.PlaySound("incomming.aud")
			Mothership.Kill()
			Trigger.AfterDelay(DateTime.Seconds(15), function()
				Actor.Create(Smoke, true, { Owner = Neutral, Location = Waypoint1.Location })
				EggSpawn()
			--Trigger.AfterDelay(DateTime.Seconds(15), function()
			--	MothershipHusk = Actor.Create(ShipGrounded, true, { Owner = Neutral, Location = Waypoint1.Location })
			end)
		end)
	end)
	Trigger.OnKilled(BurningBush, Scorch)
	Trigger.OnKilled(BurningBush, LightningFlash)
	Neutral = Player.GetPlayer("Neutral")
	Creeps = Player.GetPlayer("Creeps")
end
	--players = { }
	--for i = 1, MAXPLAYERCOUNT, 1 do
	--	local player = Player.GetPlayer("Multi" ..i-1)
	--	if player ~= nil then
	--		table.insert(players, player)
	--	end
	--end
	--if Map.Difficulty == "Mutants On" then
	--	Media.PlaySound("thunder3.aud")
	--	SendWave()
	--	delayRepeatTeam = 110 * (MAXPLAYERCOUNT + 2 - #players)
AliensSpawn = function()
	Trigger.AfterDelay(DateTime.Minutes(2), function()
		Media.PlaySound("hightoxiclevels.aud")
		Trigger.AfterDelay(DateTime.Seconds(5), function()
			Media.PlaySound("thunder5.aud")
			RedeemerSpawn()
			Trigger.AfterDelay(DateTime.Minutes(2), function()
				Media.PlaySound("hightoxiclevels.aud")
				Trigger.AfterDelay(DateTime.Seconds(5), function()
					Media.PlaySound("thunder5.aud")
					ExciterSpawn()
					Trigger.AfterDelay(DateTime.Minutes(3), function()
						Media.PlaySound("hightoxiclevels.aud")
						Trigger.AfterDelay(DateTime.Seconds(5), function()
							Media.PlaySound("thunder5.aud")
							ReclaimerSpawn()
							Trigger.AfterDelay(DateTime.Minutes(5), function()
								Media.PlaySound("hightoxiclevels.aud")
								Trigger.AfterDelay(DateTime.Seconds(5), function()
									Media.PlaySound("thunder5.aud")
									RedeemerSpawn()
									ExciterSpawn()
									Trigger.AfterDelay(DateTime.Minutes(5), function()
										Media.PlaySound("hightoxiclevels.aud")
										Trigger.AfterDelay(DateTime.Seconds(5), function()
											Media.PlaySound("thunder5.aud")
											RedeemerSpawn()
											ExciterSpawn()
											ReclaimerSpawn()
											Trigger.AfterDelay(DateTime.Minutes(5), function()
												Media.PlaySound("hightoxiclevels.aud")
												Trigger.AfterDelay(DateTime.Seconds(5), function()
													RedeemerSpawn()
													ExciterSpawn()
													ReclaimerSpawn()
												end)
											end)
										end)
									end)
								end)
							end)
						end)
					end)
				end)
			end)
		end)
	end)
end