

EnemyunitsConditions = function()
	InfDelayTimemax = 3
	if Map.LobbyOption("difficulty") == "easy" then
		EnemyInfUnit = { "e1", "e1", "e1", "e3", "dog", "dog", "dog"  }
	end
	if Map.LobbyOption("difficulty") == "normal" then
		EnemyInfUnit = { "e1", "e1", "e1", "e3", "dog", "dog", "dog", "zombie", "ant"  }
	end
	if Map.LobbyOption("difficulty") == "hard" then
		NorthEnemySubIncome()
		SouthEnemySubIncome()
		EnemyInfUnit = { "e1", "e3", "dog", "dog", "dog", "zombie", "ant"  }
	end
	if Map.LobbyOption("difficulty") == "unbelievable" then
		NorthEnemySubIncome()
		SouthEnemySubIncome()
		EnemyInfUnit = { "e1", "e2", "dog", "dog", "dog", "dog", "zombie", "zombie", "ant", "ant", "ant", "ant"  }
	end
	EnemyInfantryIncome()
	Trigger.AfterDelay(DateTime.Minutes(1), function()
		NorthEnemyGunboatIncome()
		SouthEnemyGunboatIncome()
		if Map.LobbyOption("difficulty") == "easy" then
			EnemyInfUnit = { "e1", "e1", "e2", "e3", "medi", "dog" }
			InfDelayTimemin = 2
		end
		if Map.LobbyOption("difficulty") == "normal" then
			NorthEnemyGunboatIncome()
			SouthEnemyGunboatIncome()
			NorthEnemySubIncome()
			SouthEnemySubIncome()
			EnemyInfUnit = { "e1", "e1", "e2", "e3", "medi", "dog", "zombie", "ant", "ant" }
			EnemyMonsterUnit = { "PVICE", "BSPI" }
			EnemyMonsterIncome()
		end
		if Map.LobbyOption("difficulty") == "hard" then
			NorthEnemyGunboatIncome()
			SouthEnemyGunboatIncome()
			EnemyInfUnit = { "e1", "e1", "e2", "e3", "medi", "dog", "zombie", "ant", "ant", "ant" }
			EnemyMonsterUnit = { "PVICE", "BSPI", "BSPI" }
			EnemyMonsterIncome()
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			NorthEnemyGunboatIncome()
			SouthEnemyGunboatIncome()
			AnyinfUnit = { "e1", "e2", "e3", "zombie", "ant"  }
			EnemyInfUnit = { Utils.Random(AnyinfUnit) }
			InfDelayTimemin = 3
			AnyMonsterUnit = { "PVICE", "BSPI" }
			EnemyMonsterUnit = { Utils.Random(AnyMonsterUnit) }
			EnemyMonsterIncome()
		end
	end)
	Trigger.AfterDelay(DateTime.Minutes(2), function()

		if Map.LobbyOption("difficulty") == "easy" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog" }
			EnemyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk" }
		end
		if Map.LobbyOption("difficulty") == "normal" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "zombie", "ant", "ant"  }
			EnemyMonsterUnit = { "PVICE", "IMP", "BSPI" }
			EnemyVehUnit = { "apc", "1tnk", "1tnk", "1tnk", "jeep", "ftrk" }
		end
		if Map.LobbyOption("difficulty") == "hard" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "zombie", "ant", "ant", "ant" }
			EnemyMonsterUnit = { "PVICE", "IMP", "IMP", "BSPI" }
			EnemyVehUnit = { "apc", "1tnk", "1tnk", "1tnk", "1tnk", "jeep", "ftrk" }
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			AnyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk" }
			EnemyVehUnit = { Utils.Random(AnyVehUnit) }
			AnyMonsterUnit = { "PVICE", "IMP", "BSPI" }
			EnemyMonsterUnit = { Utils.Random(AnyMonsterUnit) }
		end
		EnemyVehicleIncome()
	end)
	Trigger.AfterDelay(DateTime.Minutes(3), function()

		InfDelayTimemin = 1
		if Map.LobbyOption("difficulty") == "easy" then
			NorthEnemySubIncome()
			SouthEnemySubIncome()
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech" }
		end
		if Map.LobbyOption("difficulty") == "normal" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "zombie", "ant", "ant" }
		end
		if Map.LobbyOption("difficulty") == "hard" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "zombie", "ant", "ant", "ant" }

			EnemyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk" }
			VehDelayTimemin = 6
			MonsterDelayTimemin = 13
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			AnyinfUnit = { "e1", "e2", "e3", "zombie", "ant"  }
			EnemyInfUnit = { Utils.Random(AnyinfUnit) }
			VehDelayTimemin = 6
			MonsterDelayTimemin = 10
		end
		Trigger.AfterDelay(DateTime.Seconds(15), function()
			Changemusic1()
		end)
	end)
	Trigger.AfterDelay(DateTime.Minutes(4), function()
		NorthEnemyDestroyerIncome()
		SouthEnemyDestroyerIncome()
		if Map.LobbyOption("difficulty") == "easy" then
			EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI" }
			VehDelayTimemin = 7
			EnemyTnkUnit = { "2tnk", "3tnk" }
		end
		if Map.LobbyOption("difficulty") == "normal" then
			EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI" }
			VehDelayTimemin = 6
			EnemyTnkUnit = { "2tnk", "3tnk" }
		end
		if Map.LobbyOption("difficulty") == "hard" then
			EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI" }
			VehDelayTimemin = 5
			EnemyTnkUnit = { "2tnk", "3tnk" }
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			InfDelayTimemin = 2
			AnyTnkUnit = { "2tnk", "3tnk" }
			EnemyTnkUnit = { Utils.Random(AnyTnkUnit) }
			AnyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk" }
			EnemyVehUnit = { Utils.Random(AnyVehUnit) }
			VehDelayTimemin = 5
			AnyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI" }
			EnemyMonsterUnit = { Utils.Random(AnyMonsterUnit) }
		end
		EnemyTnkIncome()
	end)


	Trigger.AfterDelay(DateTime.Minutes(5), function()
		WriteStatisticsTeam1()
		WriteStatisticsTeam2()
		if Map.LobbyOption("difficulty") == "easy" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "medi", "dog", "mech", "mech", "zombie", "ant" }
		end
		if Map.LobbyOption("difficulty") == "normal" then
			NorthEnemyDestroyerIncome()
			SouthEnemyDestroyerIncome()
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "medi", "dog", "mech", "mech", "zombie", "ant", "ant" }
			MonsterDelayTimemin = 11
		end
		if Map.LobbyOption("difficulty") == "hard" then
			NorthEnemyDestroyerIncome()
			SouthEnemyDestroyerIncome()
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "medi", "dog", "mech", "mech", "zombie", "ant", "ant", "ant" }
			EnemyUFOUnit = { "UFO.Beamer", "UFO.Laser" }
			EnemyUFOIncome()
			HeliDelayTimemin = 12
			MonsterDelayTimemin = 10
			SpecialAttack()
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			NorthEnemyDestroyerIncome()
			SouthEnemyDestroyerIncome()
			AnyinfUnit = { "e1", "e2", "e3", "e4", "medi", "dog", "mech", "zombie", "ant" }
			EnemyInfUnit = { Utils.Random(AnyinfUnit) }
			AnyArtyUnit = { "v2rl", "arty" }
			EnemyArtyUnit = { Utils.Random(AnyArtyUnit) }
			AnyHeliUnit = { "hind", "lynx", "cobra", "huey"  }
			EnemyHeliUnit = { Utils.Random(AnyHeliUnit) }
			AnyUFOUnit = { "UFO.Beamer", "UFO.Laser" }
			EnemyUFOUnit = { Utils.Random(AnyUFOUnit) }
			EnemyUFOIncome()
			HeliDelayTimemin = 12
			MonsterDelayTimemin = 9
			SpecialAttack()
		end
		if Map.LobbyOption("difficulty") ~= "unbelievable" then
			NorthEnemyDestroyerIncome()
			SouthEnemyDestroyerIncome()
			EnemyHeliUnit = { "hind", "lynx", "cobra", "huey" }
			EnemyArtyUnit = { "v2rl", "arty" }
		end
		EnemyArtyIncome()
		EnemyHeliIncome()
	end)
	Trigger.AfterDelay(DateTime.Minutes(6), function()

		if Map.LobbyOption("difficulty") == "easy" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "zombie", "ant", "ant" }
			EnemyHeliUnit = { "heli", "hind", "lynx", "cobra", "huey" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "4tnk" }
			TnkDelayTimemin = 12
			ArtyDelayTimemin = 15
		end
		if Map.LobbyOption("difficulty") == "normal" then
			NorthEnemyCruiserIncome()
			SouthEnemyCruiserIncome()
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "zombie", "ant", "ant", "ant" }
			EnemyHeliUnit = { "heli", "heli", "hind", "lynx", "cobra", "huey" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "4tnk" }
			EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY" }
			TnkDelayTimemin = 11
			ArtyDelayTimemin = 14
			SpecialAttack()
		end
		if Map.LobbyOption("difficulty") == "hard" then
			NorthEnemyCruiserIncome()
			SouthEnemyCruiserIncome()
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "shok", "zombie", "ant", "ant", "ant" }
			EnemyHeliUnit = { "heli", "heli", "heli", "hind", "lynx", "cobra", "huey" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "4tnk" }
			EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY" }
			TnkDelayTimemin = 10
			ArtyDelayTimemin = 13
			EnemyUFOIncome()
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			NorthEnemyCruiserIncome()
			SouthEnemyCruiserIncome()
			AnyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk" }
			EnemyVehUnit = { Utils.Random(AnyVehUnit) }
			AnyTnkUnit = { "2tnk", "3tnk", "ctnk", "4tnk", "ttnk" }
			EnemyTnkUnit = { Utils.Random(AnyTnkUnit) }
			AnyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY" }
			EnemyMonsterUnit = { Utils.Random(AnyMonsterUnit) }
			MonsterDelayTimemin = 6
			TnkDelayTimemin = 10
			ArtyDelayTimemin = 13
		end
		Trigger.AfterDelay(DateTime.Seconds(30), function()
			Changemusic2()
		end)
	end)
	Trigger.AfterDelay(DateTime.Minutes(7), function()

		if Map.LobbyOption("difficulty") == "easy" then
			NorthEnemyCruiserIncome()
			SouthEnemyCruiserIncome()
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "shok", "zombie", "ant", "ant" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "4tnk" }
			SpecialAttack()
		end
		if Map.LobbyOption("difficulty") == "normal" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "shok", "zombie", "ant", "ant", "ant" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "4tnk", "4tnk", "3tnk", "ctnk", "ttnk", "4tnk" }
			EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY", "MANC" }
		end
		if Map.LobbyOption("difficulty") == "hard" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "shok", "shok", "zombie", "ant", "ant", "ant" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "4tnk", "4tnk" }
			EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY", "MANC" }
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			AnyinfUnit = { "e1", "e2", "e3", "e4", "mech", "mech", "shok", "zombie", "ant" }
			EnemyInfUnit = { Utils.Random(AnyinfUnit) }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "4tnk" }
			AnyArtyUnit = { "v2rl", "arty" }
			EnemyArtyUnit = { Utils.Random(AnyArtyUnit) }
			AnyHeliUnit = { "hind", "lynx", "cobra", "huey", "heli"  }
			EnemyHeliUnit = { Utils.Random(AnyHeliUnit) }
			AnyUFOUnit = { "UFO.Beamer", "UFO.Laser" }
			EnemyUFOUnit = { Utils.Random(AnyUFOUnit) }
			TnkDelayTimemin = 10
		end
	end)
	Trigger.AfterDelay(DateTime.Minutes(8), function()

		if Map.LobbyOption("difficulty") == "easy" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "shok", "shok", "zombie", "ant", "ant" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ctnk", "ttnk", "ttnk", "ttnk", "4tnk", "4tnk" }
		end
		if Map.LobbyOption("difficulty") == "normal" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "shok", "shok", "zombie", "ant", "ant", "ant" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ctnk", "ttnk", "ttnk", "4tnk", "4tnk" }
		end
		if Map.LobbyOption("difficulty") == "hard" then
			EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok", "shok", "shok", "shok", "zombie", "ant", "ant", "ant" }
			EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "ttnk", "4tnk", "4tnk" }
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			AnyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk" }
			EnemyVehUnit = { Utils.Random(AnyVehUnit) }
			AnyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY", "MANC" }
			EnemyMonsterUnit = { Utils.Random(AnyMonsterUnit) }
			AnyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "4tnk" }
			EnemyTnkUnit = { Utils.Random(AnyTnkUnit) }
			AnyUFOUnit = { "UFO.Beamer", "UFO.Laser" }
			EnemyUFOUnit = { Utils.Random(AnyUFOUnit) }
			TnkDelayTimemin = 8
		end
		InfDelayTimemin = 1
	end)
	Trigger.AfterDelay(DateTime.Minutes(9), function()
		if Map.LobbyOption("difficulty") == "easy" then
			EnemyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk", "ftrk", "ftrk", "ftrk" }
		end
		if Map.LobbyOption("difficulty") == "normal" then
			EnemyVehUnit = { "apc", "1tnk", "1tnk", "1tnk", "jeep", "ftrk", "ftrk", "ftrk", "ftrk" }
			AnySpecialattack = { 1, 2, 3, 4, 1, 2, 1, 2, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11 }
		end
		if Map.LobbyOption("difficulty") == "hard" then
			EnemyVehUnit = { "apc", "1tnk", "1tnk", "1tnk", "jeep", "ftrk", "ftrk", "ftrk", "ftrk", "ftrk" }
			AnySpecialattack = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			AnyinfUnit = { "e1", "e2", "e3", "e4", "dog", "mech", "mech", "shok", "shok", "shok", "zombie", "ant", "ant" }
			EnemyInfUnit = { Utils.Random(AnyinfUnit) }
			AnyArtyUnit = { "v2rl", "arty" }
			EnemyArtyUnit = { Utils.Random(AnyArtyUnit) }
			AnyHeliUnit = { "heli", "heli", "hind", "lynx", "cobra", "huey" }
			EnemyHeliUnit = { Utils.Random(AnyHeliUnit) }
			AnyUFOUnit = { "UFO.Beamer", "UFO.Laser" }
			EnemyUFOUnit = { Utils.Random(AnyUFOUnit) }
			TnkDelayTimemin = 7
			AnySpecialattack = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }
		end
		VehDelayTimemin = 4
	end)
	Trigger.AfterDelay(DateTime.Minutes(10), function()
		WriteStatisticsTeam1()
		WriteStatisticsTeam2()
		TnkDelayTimemin = 7
		ArtyDelayTimemin = 12
		if Map.LobbyOption("difficulty") == "easy" then
			NorthEnemyGunboatIncome()
			SouthEnemyGunboatIncome()
			EnemyHeliUnit = { "heli", "heli", "hind", "lynx", "cobra", "huey" }
			AnySpecialattack = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11 }
		end
		if Map.LobbyOption("difficulty") == "normal" then
			NorthEnemyDestroyerIncome()
			SouthEnemyDestroyerIncome()
			EnemyHeliUnit = { "heli", "heli", "heli", "hind", "lynx", "cobra", "huey" }
		end
		if Map.LobbyOption("difficulty") == "hard" then
			NorthEnemyMsubIncome()
			SouthEnemyMsubIncome()
			Demotruckincome()
			EnemyHeliUnit = { "heli", "heli", "heli", "heli", "hind", "lynx", "cobra", "huey" }
		end
		if Map.LobbyOption("difficulty") == "unbelievable" then
			NorthEnemyMsubIncome()
			SouthEnemyMsubIncome()
			Demotruckincome()
			AnyinfUnit = { "e2", "shok", "ant" }
			EnemyInfUnit = { Utils.Random(AnyinfUnit) }
			AnyVehUnit = { "1tnk", "ftrk" }
			EnemyVehUnit = { Utils.Random(AnyVehUnit) }
			VehDelayTimemin = 2
			AnyArtyUnit = { "v2rl", "arty" }
			EnemyArtyUnit = { Utils.Random(AnyArtyUnit) }
			AnyHeliUnit = { "heli", "cobra" }
			EnemyHeliUnit = { Utils.Random(AnyHeliUnit) }
			AnyTnkUnit = { "2tnk", "3tnk", "ttnk", "4tnk" }
			EnemyTnkUnit = { Utils.Random(AnyTnkUnit) }
			TnkDelayTimemin = 6
			AnyMonsterUnit = { "PINKY", "MANC" }
			EnemyMonsterUnit = { Utils.Random(AnyMonsterUnit) }
			AnyUFOUnit = { "UFO.Beamer", "UFO.Laser" }
			EnemyUFOUnit = { Utils.Random(AnyUFOUnit) }
		end
		Media.PlayMusic("factory")
	end)
end

StartingUnitsCheck = function()
	WaveInterval = 0
	Utils.Do(Humans, function(player)
		Dog = player.GetActorsByType("dog")
		for p,doggy in pairs(Dog) do
			if doggy.IsInWorld then
				WaveInterval = 0
				if doggy.Owner == Multi0 then doggy.Move(CPos.New(24,8)) end
				if doggy.Owner == Multi1 then doggy.Move(CPos.New(24,14)) end
				if doggy.Owner == Multi2 then doggy.Move(CPos.New(24,41)) end
				if doggy.Owner == Multi3 then doggy.Move(CPos.New(24,47)) end
			end
		end
		E1 = player.GetActorsByType("e1")
		for p,rifleman in pairs(E1) do
			if rifleman.IsInWorld then
				WaveInterval = 1
				if rifleman.Owner == Multi0 then rifleman.Move(CPos.New(24,8)) end
				if rifleman.Owner == Multi1 then rifleman.Move(CPos.New(24,14)) end
				if rifleman.Owner == Multi2 then rifleman.Move(CPos.New(24,41)) end
				if rifleman.Owner == Multi3 then rifleman.Move(CPos.New(24,47)) end
			end
		end
		E2 = player.GetActorsByType("e2")
		for p,nader in pairs(E2) do
			if nader.IsInWorld then
				WaveInterval = 2
				if nader.Owner == Multi0 then nader.Move(CPos.New(24,8)) end
				if nader.Owner == Multi1 then nader.Move(CPos.New(24,14)) end
				if nader.Owner == Multi2 then nader.Move(CPos.New(24,41)) end
				if nader.Owner == Multi3 then nader.Move(CPos.New(24,47)) end
			end
		end
		E3 = player.GetActorsByType("e3")
		for p,rocketman in pairs(E3) do
			if rocketman.IsInWorld then
				WaveInterval = 3
				if rocketman.Owner == Multi0 then rocketman.Move(CPos.New(24,8)) end
				if rocketman.Owner == Multi1 then rocketman.Move(CPos.New(24,14)) end
				if rocketman.Owner == Multi2 then rocketman.Move(CPos.New(24,41)) end
				if rocketman.Owner == Multi3 then rocketman.Move(CPos.New(24,47)) end
			end
		end
		Medi = player.GetActorsByType("medi")
		for p,medic in pairs(Medi) do
			if medic.IsInWorld then
				WaveInterval = 4
				if medic.Owner == Multi0 then medic.Move(CPos.New(24,8)) end
				if medic.Owner == Multi1 then medic.Move(CPos.New(24,14)) end
				if medic.Owner == Multi2 then medic.Move(CPos.New(24,41)) end
				if medic.Owner == Multi3 then medic.Move(CPos.New(24,47)) end
			end
		end
		Mech = player.GetActorsByType("mech")
		for p,mechanic in pairs(Mech) do
			if mechanic.IsInWorld then
				WaveInterval = 5
				if mechanic.Owner == Multi0 then mechanic.Move(CPos.New(24,8)) end
				if mechanic.Owner == Multi1 then mechanic.Move(CPos.New(24,14)) end
				if mechanic.Owner == Multi2 then mechanic.Move(CPos.New(24,41)) end
				if mechanic.Owner == Multi3 then mechanic.Move(CPos.New(24,47)) end
			end
		end
		E6 = player.GetActorsByType("e6")
		for p,engie in pairs(E6) do
			if engie.IsInWorld then
				WaveInterval = 6
				if engie.Owner == Multi0 then engie.Move(CPos.New(24,8)) end
				if engie.Owner == Multi1 then engie.Move(CPos.New(24,14)) end
				if engie.Owner == Multi2 then engie.Move(CPos.New(24,41)) end
				if engie.Owner == Multi3 then engie.Move(CPos.New(24,47)) end
			end
		end
		UnitPercent = 10 - WaveInterval
	end)
end

WaveInterrupter = function()
	PeaceTime = true
	Trigger.AfterDelay(DateTime.Seconds(WaveInterval), function()
		PeaceTime = false
	end)
	Trigger.AfterDelay(DateTime.Seconds(10), function()
		WaveInterrupter()
	end)
end

EnemyInfantryIncome = function()
	if not PeaceTime then
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		RandomPosition = Utils.RandomInteger(0, 20)
		RandomInfUnit = Utils.Random(EnemyInfUnit)
		if RandomInfUnit == "e1" then InfDelayTimemax = 5
		elseif RandomInfUnit == "e2" then InfDelayTimemax = 4
		elseif RandomInfUnit == "e3" then InfDelayTimemax = 6
		elseif RandomInfUnit == "e4" then InfDelayTimemax = 9
		elseif RandomInfUnit == "medi" then InfDelayTimemax = 4
		elseif RandomInfUnit == "mech" then InfDelayTimemax = 6
		elseif RandomInfUnit == "shok" then InfDelayTimemax = 10
		elseif RandomInfUnit == "zombie" then InfDelayTimemax = 5
		elseif RandomInfUnit == "ant" then InfDelayTimemax = 11
		elseif RandomInfUnit == "dog" then InfDelayTimemax = 4	
			AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(26,8) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(26,14) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(4,7) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
			AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(26,41) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(26,47) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(4,48) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		end
		EnemyUnitN = Actor.Create(RandomInfUnit, true, { Location = CPos.New(55,1) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyUnitS = Actor.Create(RandomInfUnit, true, { Location = CPos.New(55,36) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyN = { EnemyUnitN }
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(InfDelayTimemin, InfDelayTimemax)), function()
			EnemyInfantryIncome()
		end)
	end)
end


EnemyVehicleIncome = function()
	if not PeaceTime then
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		RandomPosition = Utils.RandomInteger(0, 20)
		RandomVehUnit = Utils.Random(EnemyVehUnit)
		if RandomVehUnit == "apc" then VehDelayTimemax = 10
		elseif RandomVehUnit == "1tnk" then VehDelayTimemax = 15
		elseif RandomVehUnit == "jeep" then VehDelayTimemax = 8
		elseif RandomVehUnit == "ftrk" then VehDelayTimemax = 9 end
		EnemyUnitN = Actor.Create(RandomVehUnit, true, { Location = CPos.New(55,1) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyUnitS = Actor.Create(RandomVehUnit, true, { Location = CPos.New(55,36) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		if ICTime then EnemyUnitN.GrantCondition("invulnerability", DateTime.Seconds(15)) end
		if ICTime then EnemyUnitS.GrantCondition("invulnerability", DateTime.Seconds(15)) end
		EnemyN = { EnemyUnitN }
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(VehDelayTimemin, VehDelayTimemax)), function()
			EnemyVehicleIncome()
		end)
	end)
end

EnemyTnkIncome = function()
	if not PeaceTime then
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		RandomPosition = Utils.RandomInteger(0, 20)
		RandomTnkUnit = Utils.Random(EnemyTnkUnit)
		if RandomTnkUnit == "2tnk" then TnkDelayTimemax = 18
		elseif RandomTnkUnit == "3tnk" then TnkDelayTimemax = 20
		elseif RandomTnkUnit == "ctnk" then TnkDelayTimemax = 14 
		elseif RandomTnkUnit == "4tnk" then TnkDelayTimemax = 29
		elseif RandomTnkUnit == "ttnk" then TnkDelayTimemax = 16 end
		EnemyUnitN = Actor.Create(RandomTnkUnit, true, { Location = CPos.New(55,1) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyUnitS = Actor.Create(RandomTnkUnit, true, { Location = CPos.New(55,36) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		if ICTime then EnemyUnitN.GrantCondition("invulnerability", DateTime.Seconds(19)) end
		if ICTime then EnemyUnitS.GrantCondition("invulnerability", DateTime.Seconds(19)) end
		EnemyN = { EnemyUnitN }
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(TnkDelayTimemin, TnkDelayTimemax)), function()
			EnemyTnkIncome()
		end)
	end)
end

EnemyArtyIncome = function()
	if not PeaceTime then
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		RandomPosition = Utils.RandomInteger(0, 20)
		RandomArtyUnit = Utils.Random(EnemyArtyUnit)
		if RandomArtyUnit == "arty" then ArtyDelayTimemax = 20 
		elseif RandomArtyUnit == "v2rl" then ArtyDelayTimemax = 25 end
		EnemyUnitN = Actor.Create(RandomArtyUnit, true, { Location = CPos.New(55,1) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyUnitS = Actor.Create(RandomArtyUnit, true, { Location = CPos.New(55,36) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		if ICTime then EnemyUnitN.GrantCondition("invulnerability", DateTime.Seconds(15)) end
		if ICTime then EnemyUnitS.GrantCondition("invulnerability", DateTime.Seconds(15)) end
		EnemyN = { EnemyUnitN }
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(ArtyDelayTimemin, ArtyDelayTimemax)), function()
			EnemyArtyIncome()
		end)
	end)
end

EnemyHeliIncome = function()
	if not PeaceTime then
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		RandomPosition = Utils.RandomInteger(0, 20)
		RandomHeliUnit = Utils.Random(EnemyHeliUnit)
		if RandomHeliUnit == "hind" then HeliDelayTimemax = 18 
		elseif RandomHeliUnit == "huey" then HeliDelayTimemax = 16 
		elseif RandomHeliUnit == "lynx" then HeliDelayTimemax = 18 
		elseif RandomHeliUnit == "cobra" then HeliDelayTimemax = 20 
		elseif RandomHeliUnit == "heli" then HeliDelayTimemax = 25 end
		EnemyUnitN = Actor.Create(RandomHeliUnit, true, { Location = CPos.New(57,0) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyUnitS = Actor.Create(RandomHeliUnit, true, { Location = CPos.New(57,36) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyN = { EnemyUnitN }
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(HeliDelayTimemin, HeliDelayTimemax)), function()
			EnemyHeliIncome()
		end)
	end)
end

EnemyMonsterIncome = function()
	if not PeaceTime then
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		RandomPosition = Utils.RandomInteger(0, 20)
		RandomMonsterUnit = Utils.Random(EnemyMonsterUnit)
		if RandomMonsterUnit == "PVICE" then MonsterDelayTimemax = 13
		elseif RandomMonsterUnit == "IMP" then MonsterDelayTimemax = 28
		elseif RandomMonsterUnit == "REVE" then MonsterDelayTimemax = 30
		elseif RandomMonsterUnit == "BSPI" then MonsterDelayTimemax = 22
		elseif RandomMonsterUnit == "PINKY" then MonsterDelayTimemax = 35
		elseif RandomMonsterUnit == "MANC" then MonsterDelayTimemax = 45 end
		EnemyUnitN = Actor.Create(RandomMonsterUnit, true, { Location = CPos.New(55,1) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyUnitS = Actor.Create(RandomMonsterUnit, true, { Location = CPos.New(55,36) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyN = { EnemyUnitN }
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(MonsterDelayTimemin, MonsterDelayTimemax)), function()
			EnemyMonsterIncome()
		end)
	end)
end

EnemyUFOIncome = function()
	if not PeaceTime then
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		RandomPosition = Utils.RandomInteger(0, 20)

		RandomUfoUnit = Utils.Random(EnemyUFOUnit)
		if RandomUfoUnit == "UFO.Laser" then UFODelayTimemax = 16
		elseif RandomUfoUnit == "UFO.Beamer" then UFODelayTimemax = 19 end
		EnemyUnitN = Actor.Create(RandomUfoUnit, true, { Location = CPos.New(57,1) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyUnitS = Actor.Create(RandomUfoUnit, true, { Location = CPos.New(57,36) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyN = { EnemyUnitN }
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(1, function()
		Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(UFODelayTimemin, UFODelayTimemax)), function()
			EnemyUFOIncome()
		end)
	end)
end

NorthEnemyGunboatIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(GunboatminTime, GunboatmaxTime)), function()
		AttackpathN = { CPos.New(31,27) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,23) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(51,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitN = Actor.Create("pt", true, { Location = CPos.New(55,24) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyN = { EnemyUnitN }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitN,NorthEnemyGunboatIncome)
	end)
end
SouthEnemyGunboatIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(GunboatminTime, GunboatmaxTime)), function()
		AttackpathS = { CPos.New(28,30) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,34) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitS = Actor.Create("pt", true, { Location = CPos.New(55,28) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitS,SouthEnemyGunboatIncome)
	end)
end

NorthEnemySubIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(SubminTime, SubmaxTime)), function()
		AttackpathN = { CPos.New(31,27) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,23) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitN = Actor.Create("ss", true, { Location = CPos.New(55,24) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyN = { EnemyUnitN }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitN,NorthEnemySubIncome)
	end)
end
SouthEnemySubIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(SubminTime, SubmaxTime)), function()
		AttackpathS = { CPos.New(28,30) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,34) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitS = Actor.Create("ss", true, { Location = CPos.New(55,28) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitS,SouthEnemySubIncome)
	end)
end

NorthEnemyDestroyerIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(DestroyerminTime, DestroyermaxTime)), function()
		AttackpathN = { CPos.New(31,27) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,23) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitN = Actor.Create("dd", true, { Location = CPos.New(55,24) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyN = { EnemyUnitN }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitN,NorthEnemyDestroyerIncome)
	end)
end
SouthEnemyDestroyerIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(DestroyerminTime, DestroyermaxTime)), function()
		AttackpathS = { CPos.New(28,30) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,34) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitS = Actor.Create("dd", true, { Location = CPos.New(55,28) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitS,SouthEnemyDestroyerIncome)
	end)
end

NorthEnemyCruiserIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(CruiserminTime, CruisermaxTime)), function()
		AttackpathN = { CPos.New(31,27) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,23) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitN = Actor.Create("ca", true, { Location = CPos.New(55,24) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyN = { EnemyUnitN }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitN,NorthEnemyCruiserIncome)
	end)
end
SouthEnemyCruiserIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(CruiserminTime, CruisermaxTime)), function()
		AttackpathS = { CPos.New(28,30) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,34) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitS = Actor.Create("ca", true, { Location = CPos.New(55,28) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitS,SouthEnemyCruiserIncome)
	end)
end

NorthEnemyMsubIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(MsubminTime, MsubmaxTime)), function()
		AttackpathN = { CPos.New(31,27) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,23) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitN = Actor.Create("msub", true, { Location = CPos.New(55,24) + CVec.New(0, RandomPosition), Owner = EnemysTop })
		EnemyN = { EnemyUnitN }
		GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitN,NorthEnemyMsubIncome)
	end)
end
SouthEnemyMsubIncome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(MsubminTime, MsubmaxTime)), function()
		AttackpathS = { CPos.New(28,30) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(43,34) + CVec.New(Utils.RandomInteger(-1, 1), Utils.RandomInteger(-1, 1)), CPos.New(53,28) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
		RandomPosition = Utils.RandomInteger(0, 4)
		EnemyUnitS = Actor.Create("msub", true, { Location = CPos.New(55,28) + CVec.New(0, RandomPosition), Owner = EnemysBottom })
		EnemyS = { EnemyUnitS }
		GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
		Trigger.OnKilled(EnemyUnitS,SouthEnemyMsubIncome)
	end)
end

SpecialAttack = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(SpecialminTime, SpecialmaxTime)), function()
		EnemySpecialattack =  Utils.Random(AnySpecialattack)
		if EnemySpecialattack == 1 and TopTeamWon == false and BottomTeamWon == false then
			SendParabombs()
		end
		if EnemySpecialattack == 2 and TopTeamWon == false and BottomTeamWon == false then
			SendAirstrike()
		end
		if EnemySpecialattack == 3 and TopTeamWon == false and BottomTeamWon == false then
			SendParatroopers()
		end
		if EnemySpecialattack == 4 and TopTeamWon == false and BottomTeamWon == false then
			SendParaparazombies()
		end
		if EnemySpecialattack == 5 and TopTeamWon == false and BottomTeamWon == false then
			Demotruckincome()
		end
		if EnemySpecialattack == 6 and TopTeamWon == false and BottomTeamWon == false then
			SneakHeils()
		end
		if EnemySpecialattack == 7 and TopTeamWon == false and BottomTeamWon == false then
			SneakApcs()
		end
		if EnemySpecialattack == 8 and TopTeamWon == false and BottomTeamWon == false then
			SneakTship()
		end
		if EnemySpecialattack == 9 and TopTeamWon == false and BottomTeamWon == false then
			IronCurtain()
		end
		if EnemySpecialattack == 10 and TopTeamWon == false and BottomTeamWon == false then
			StealthTanya()
		end
		if EnemySpecialattack == 11 and TopTeamWon == false and BottomTeamWon == false then
			Chronotanks()
		end
		SpecialAttack()
	end)
end

SendParabombs = function()
	DetonationPoint1 = Actor.Create("waypoint", true, { Location = CPos.New(6,6) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 11)), Owner = Neutral })
	DetonationPoint2 = Actor.Create("waypoint", true, { Location = CPos.New(6,39) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 11)), Owner = Neutral })
	ParaProxy1 = Actor.Create("powerproxy.parabombs", false, { Owner = EnemysTop })
	ParaProxy2 = Actor.Create("powerproxy.parabombs", false, { Owner = EnemysBottom })
	units1 = ParaProxy1.SendAirstrike(DetonationPoint1.CenterPosition)
	units2 = ParaProxy2.SendAirstrike(DetonationPoint2.CenterPosition)
end
SendAirstrike = function()
	DetonationPoint1 = Actor.Create("waypoint", true, { Location = CPos.New(6,6) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 11)), Owner = Neutral })
	DetonationPoint2 = Actor.Create("waypoint", true, { Location = CPos.New(6,39) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 11)), Owner = Neutral })
	ParaProxy1 = Actor.Create("powerproxy.parayaks", false, { Owner = EnemysTop })
	ParaProxy2 = Actor.Create("powerproxy.parayaks", false, { Owner = EnemysBottom })
	units1 = ParaProxy1.SendAirstrike(DetonationPoint1.CenterPosition)
	units2 = ParaProxy2.SendAirstrike(DetonationPoint2.CenterPosition)
end
SendParatroopers = function()
	DetonationPoint1 = Actor.Create("waypoint", true, { Location = CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 4)), Owner = Neutral })
	DetonationPoint2 = Actor.Create("waypoint", true, { Location = CPos.New(3,48) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 4)), Owner = Neutral })
	ParaProxy1 = Actor.Create("powerproxy.paratroopers", false, { Owner = EnemysTop })
	ParaProxy2 = Actor.Create("powerproxy.paratroopers", false, { Owner = EnemysBottom })
	units1 = ParaProxy1.SendParatroopers(DetonationPoint1.CenterPosition)
	units2 = ParaProxy2.SendParatroopers(DetonationPoint2.CenterPosition)
end
SendParaparazombies = function()
	DetonationPoint1 = Actor.Create("waypoint", true, { Location = CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 11)), Owner = Neutral })
	DetonationPoint2 = Actor.Create("waypoint", true, { Location = CPos.New(3,42) + CVec.New(Utils.RandomInteger(0, 25), Utils.RandomInteger(0, 11)), Owner = Neutral })
	ParaProxy1 = Actor.Create("powerproxy.parazombies", false, { Owner = EnemysTop })
	ParaProxy2 = Actor.Create("powerproxy.parazombies", false, { Owner = EnemysBottom })
	units1 = ParaProxy1.SendParatroopers(DetonationPoint1.CenterPosition)
	units2 = ParaProxy2.SendParatroopers(DetonationPoint2.CenterPosition)
end
Demotruckincome = function()
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(20, 30)), function()
		AttackpathN = { CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,3) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		AttackpathS = { CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)), CPos.New(3,40) + CVec.New(Utils.RandomInteger(0, 4), Utils.RandomInteger(0, 15)) }
		DemoN = Actor.Create("dtrk", true, { Location = CPos.New(55,5), Owner = EnemysTop })
		DemoS = Actor.Create("dtrk", true, { Location = CPos.New(55,50), Owner = EnemysBottom })
		DtrukN = { DemoN }
		DtrukS = { DemoS }
		MovePatrol(DtrukN, AttackpathN, DateTime.Seconds(3))
		MovePatrol(DtrukS, AttackpathS, DateTime.Seconds(3))
	end)
end
HeliReinforcements = { "e1", "e3", "e2", "e1", "e1", "e1", "e4" }
ApcReinforcements = { "e3", "e2", "e1", "e1", "e4" }
TshipReinforcements = { "e3", "e2", "e4", "e4", "e4" }
Tanya = { "e7", "medi", "medi", "medi" }

SneakHeils = function()
	Topsneakheliunits = Reinforcements.ReinforceWithTransport(EnemysTop, "tran", HeliReinforcements, { CPos.New(20,55) + CVec.New(Utils.RandomInteger(-5, 5), 0), CPos.New(9,10) + CVec.New(Utils.RandomInteger(-1, 1), 0) }, { CPos.New(55,10) + CVec.New(0, Utils.RandomInteger(-8, 8)) })
	Bottomsneakheliunits = Reinforcements.ReinforceWithTransport(EnemysBottom, "tran", HeliReinforcements, { CPos.New(20,1) + CVec.New(Utils.RandomInteger(-5, 5), 0), CPos.New(9,43) + CVec.New(Utils.RandomInteger(-1, 1), 0) }, { CPos.New(55,45) + CVec.New(0, Utils.RandomInteger(-8, 8)) })
end


SneakApcs = function()
	Topsneakapcunits = Reinforcements.ReinforceWithTransport(EnemysTop, "apc", ApcReinforcements, { CPos.New(25,1) + CVec.New(Utils.RandomInteger(-1, 1), 0), CPos.New(9,18) + CVec.New(Utils.RandomInteger(-1, 1), 0) }, { CPos.New(55,10) + CVec.New(0, Utils.RandomInteger(-5, 5)) })[2]
	Bottomsneakapcunits = Reinforcements.ReinforceWithTransport(EnemysBottom, "apc", ApcReinforcements, { CPos.New(25,55) + CVec.New(Utils.RandomInteger(-1, 1), 0), CPos.New(9,51) + CVec.New(Utils.RandomInteger(-1, 1), 0) }, { CPos.New(55,45) + CVec.New(0, Utils.RandomInteger(-5, 5)) })[2]
end
			
SneakTship = function()
	local TopTshipunits = Reinforcements.ReinforceWithTransport(EnemysTop, "lst", TshipReinforcements, { CPos.New(55,24) + CVec.New(0, Utils.RandomInteger(0, 4)), CPos.New(30,26) }, { CPos.New(55,24) + CVec.New(0, Utils.RandomInteger(0, 4)) })[2]
	Utils.Do(TopTshipunits, function(a)
		Trigger.OnAddedToWorld(a, function()
			 if not a.IsDead and a.IsInWorld then a.AttackMove(CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18))) end
		end)
	end)
	local BottomTshipunits = Reinforcements.ReinforceWithTransport(EnemysBottom, "lst", TshipReinforcements, { CPos.New(55,28) + CVec.New(0, Utils.RandomInteger(0, 4)), CPos.New(29,32) }, { CPos.New(55,28) + CVec.New(0, Utils.RandomInteger(0, 4)) })[2]
	Utils.Do(BottomTshipunits, function(unit)
		Trigger.OnAddedToWorld(unit, function()
			if not unit.IsDead and unit.IsInWorld then unit.AttackMove(CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18))) end
		end)
	end)
end

ICTime = false
IronCurtain = function()
	ICTime = true
	Media.PlaySound("ironcur9.aud")
	Trigger.AfterDelay(DateTime.Seconds(12), function()
		ICTime = false
	end)
end

StealthTanya = function()
	local TopTanya = Reinforcements.ReinforceWithTransport(EnemysTop, "stnk", Tanya, { CPos.New(23,1) + CVec.New(Utils.RandomInteger(-1, 1), 0), CPos.New(9,18) + CVec.New(Utils.RandomInteger(-1, 1), 0) }, { CPos.New(55,10) + CVec.New(0, Utils.RandomInteger(-5, 5)) })[2]
	Utils.Do(TopTanya, function(a)
		Trigger.OnAddedToWorld(a, function()
			AttackpathN = { CPos.New(26,8) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(26,14) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(4,7) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)) }
			EnemyN = { a }
			GroupPatrol(EnemyN, AttackpathN, DateTime.Seconds(0))
		end)
	end)
	local BottomTanya = Reinforcements.ReinforceWithTransport(EnemysBottom, "stnk", Tanya, { CPos.New(23,55) + CVec.New(Utils.RandomInteger(-1, 1), 0), CPos.New(9,51) + CVec.New(Utils.RandomInteger(-1, 1), 0) }, { CPos.New(55,45) + CVec.New(0, Utils.RandomInteger(-5, 5)) })[2]
	Utils.Do(BottomTanya, function(unit)
		Trigger.OnAddedToWorld(unit, function()
			AttackpathS = { CPos.New(26,41) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(26,47) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(4,48) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18))  }
			EnemyS = { unit }
			GroupPatrol(EnemyS, AttackpathS, DateTime.Seconds(0))
		end)
	end)
end


Chronotanks = function()
		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank2 = Actor.Create("CTNK", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysTop })
			Chronotank2.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)
		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank3 = Actor.Create("CTNK", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysTop })
			Chronotank3.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)
		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank4 = Actor.Create("CTNK", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysTop })
			Chronotank4.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)
		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank5 = Actor.Create("CTNK", true, { Location = CPos.New(1,1) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysTop })
			Chronotank5.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)

		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank7 = Actor.Create("CTNK", true, { Location = CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysBottom })
			Chronotank7.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)
		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank8 = Actor.Create("CTNK", true, { Location = CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysBottom })
			Chronotank8.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)
		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank9 = Actor.Create("CTNK", true, { Location = CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysBottom })
			Chronotank9.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)
		Trigger.AfterDelay(Utils.RandomInteger(0, 88), function()
			Chronotank10 = Actor.Create("CTNK", true, { Location = CPos.New(1,37) + CVec.New(Utils.RandomInteger(0, 5), Utils.RandomInteger(0, 18)), Owner = EnemysBottom })
			Chronotank10.Scatter()
			Media.PlaySound("chrotnk1.aud")
		end)
		Trigger.AfterDelay(Utils.RandomInteger(88, 105), function()
			Media.PlaySpeechNotification( allplayers, "ChronosphereTestSuccessful")
		end)
--	end
end


GroupPatrol = function(units, waypoints, delay) 
	local i = 1
	local stop = false
	Utils.Do(units, function(unit)
		Trigger.OnIdle(unit, function()
			if stop then
				return
			end
			if unit.Location == waypoints[i] then
				local bool = Utils.All(units, function(actor) return actor.IsIdle end)
				if bool then
					stop = true
					i = i + 1
					if i > #waypoints then
						i = 1
					end
					Trigger.AfterDelay(delay, function() stop = false end)
				end
			else
				unit.AttackMove(waypoints[i])
			end
		end)
	end)
end

MovePatrol = function(units, waypoints, delay) 
	local i = 1
	local stop = false
	Utils.Do(units, function(unit)
		Trigger.OnIdle(unit, function()
			if stop then
				return
			end
			if unit.Location == waypoints[i] then
				local bool = Utils.All(units, function(actor) return actor.IsIdle end)
				if bool then
					stop = true
					i = i + 1
					if i > #waypoints then
						i = 1
					end
					Trigger.AfterDelay(delay, function() stop = false end)
				end
			else
				unit.Move(waypoints[i])
			end
		end)
	end)
end

DestroyedBuildings1 = 0
DestroyedBuildings2 = 0

MCVincome = function()
	newmcv0 = Actor.Create("fact", true, { Location = CPos.New(8,7), Owner = Multi0 })
--	Trigger.OnKilledOrCaptured(newmcv0, function() Multi0.MarkFailedObjective(KillbaseP1) end)
	newmcv1 = Actor.Create("fact", true, { Location = CPos.New(8,15), Owner = Multi1 }) 
--	Trigger.OnKilledOrCaptured(newmcv1, function() Multi1.MarkFailedObjective(KillbaseP2) end)
	newmcv2 = Actor.Create("fact", true, { Location = CPos.New(8,40), Owner = Multi2 })
--	Trigger.OnKilledOrCaptured(newmcv2, function() Multi2.MarkFailedObjective(KillbaseP3) end)
	newmcv3 = Actor.Create("fact", true, { Location = CPos.New(8,48), Owner = Multi3 })
--	Trigger.OnKilledOrCaptured(newmcv3, function() Multi3.MarkFailedObjective(KillbaseP4) end)
	Team1Mainbases = { newmcv0, newmcv1 }
	Team2Mainbases = { newmcv2, newmcv3 }
	Trigger.OnAllKilledOrCaptured(Team1Mainbases, Team2Won)
	Trigger.OnAllKilledOrCaptured(Team2Mainbases, Team1Won)

	newEnemymcv0 = Actor.Create("fact.enemy", true, { Location = CPos.New(51,7), Owner = EnemysTop })
	newEnemymcv1 = Actor.Create("fact.enemy", true, { Location = CPos.New(51,15), Owner = EnemysTop }) 
	newEnemymcv2 = Actor.Create("fact.enemy", true, { Location = CPos.New(51,40), Owner = EnemysBottom })
	newEnemymcv3 = Actor.Create("fact.enemy", true, { Location = CPos.New(51,48), Owner = EnemysBottom })
	newEnemyhpad0 = Actor.Create("hpad", true, { Location = CPos.New(47,7), Owner = EnemysTop })
	newEnemyhpad1 = Actor.Create("hpad", true, { Location = CPos.New(47,15), Owner = EnemysTop }) 
	newEnemyhpad2 = Actor.Create("hpad", true, { Location = CPos.New(47,40), Owner = EnemysBottom })
	newEnemyhpad3 = Actor.Create("hpad", true, { Location = CPos.New(47,48), Owner = EnemysBottom })
	newEnemyapwr1 = Actor.Create("much.apwr", true, { Location = CPos.New(50,11), Owner = EnemysTop })
	newEnemyapwr2 = Actor.Create("much.apwr", true, { Location = CPos.New(50,44), Owner = EnemysBottom })

	newEnemyship1 = Actor.Create("syrd", true, { Location = CPos.New(46,25), Owner = EnemysTop }) 
	newEnemyship2 = Actor.Create("syrd", true, { Location = CPos.New(47,32), Owner = EnemysBottom })
	newEnemyspen1 = Actor.Create("spen", true, { Location = CPos.New(39,24), Owner = EnemysTop }) 
	newEnemyspen2 = Actor.Create("spen", true, { Location = CPos.New(39,30), Owner = EnemysBottom })


	Trigger.OnDamaged(newEnemymcv0, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemymcv1, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemymcv2, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemymcv3, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)

	Trigger.OnDamaged(newEnemyhpad0, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyhpad1, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyhpad2, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyhpad3, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)

	Trigger.OnDamaged(newEnemyapwr1, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyapwr2, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyship1, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyship2, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyspen1, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemyspen2, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)

	Trigger.OnKilled(newEnemymcv0, function() DestroyedBuildings1 = DestroyedBuildings1 + 1 end)
	Trigger.OnKilled(newEnemymcv1, function() DestroyedBuildings1 = DestroyedBuildings1 + 1 end)
	Trigger.OnKilled(newEnemymcv2, function() DestroyedBuildings2 = DestroyedBuildings2 + 1 end)
	Trigger.OnKilled(newEnemymcv3, function() DestroyedBuildings2 = DestroyedBuildings2 + 1 end)

	Trigger.OnKilled(newEnemyhpad0, function() DestroyedBuildings1 = DestroyedBuildings1 + 1 end)
	Trigger.OnKilled(newEnemyhpad1, function() DestroyedBuildings1 = DestroyedBuildings1 + 1 end)
	Trigger.OnKilled(newEnemyhpad2, function() DestroyedBuildings2 = DestroyedBuildings2 + 1 end)
	Trigger.OnKilled(newEnemyhpad3, function() DestroyedBuildings2 = DestroyedBuildings2 + 1 end)

	Trigger.OnKilled(newEnemyapwr1, function() DestroyedBuildings1 = DestroyedBuildings1 + 1 end)
	Trigger.OnKilled(newEnemyapwr2, function() DestroyedBuildings2 = DestroyedBuildings2 + 1 end)

	Trigger.OnKilled(newEnemyship1, function() DestroyedBuildings1 = DestroyedBuildings1 + 1 end)
	Trigger.OnKilled(newEnemyship2, function() DestroyedBuildings2 = DestroyedBuildings2 + 1 end)
	Trigger.OnKilled(newEnemyspen1, function() DestroyedBuildings1 = DestroyedBuildings1 + 1 end)
	Trigger.OnKilled(newEnemyspen2, function() DestroyedBuildings2 = DestroyedBuildings2 + 1 end)
	Team1Enemybases = { newEnemymcv0, newEnemymcv1, newEnemyhpad0, newEnemyhpad1, newEnemyapwr1, newEnemyship1, newEnemyspen1 }
	Team2Enemybases = { newEnemymcv2, newEnemymcv3, newEnemyhpad2, newEnemyhpad3, newEnemyapwr2, newEnemyship2, newEnemyspen2 }
	Trigger.OnAllKilledOrCaptured(Team1Enemybases, Team1Won)
	Trigger.OnAllKilledOrCaptured(Team2Enemybases, Team2Won)
	newEnemytsla0 = Actor.Create("tsla", true, { Location = CPos.New(45,8) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysTop })
	newEnemytsla1 = Actor.Create("tsla", true, { Location = CPos.New(45,16) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysTop }) 
	newEnemytsla2 = Actor.Create("tsla", true, { Location = CPos.New(45,41) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysBottom })
	newEnemytsla3 = Actor.Create("tsla", true, { Location = CPos.New(45,49) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysBottom })
	Trigger.OnDamaged(newEnemytsla0, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemytsla1, function(building)
		if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemytsla2, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	Trigger.OnDamaged(newEnemytsla3, function(building)
		if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
			building.StartBuildingRepairs()
		end
	end)
	newEnemypbox0 = Actor.Create("hbox", true, { Location = CPos.New(50,10), Owner = EnemysTop })
	newEnemypbox1 = Actor.Create("hbox", true, { Location = CPos.New(50,18), Owner = EnemysTop }) 
	newEnemypbox2 = Actor.Create("hbox", true, { Location = CPos.New(50,43), Owner = EnemysBottom })
	newEnemypbox3 = Actor.Create("hbox", true, { Location = CPos.New(50,51), Owner = EnemysBottom })
	if Map.LobbyOption("difficulty") ~= "easy" then
		newEnemyaa0 = Actor.Create("agun", true, { Location = CPos.New(49,7), Owner = EnemysTop })
		newEnemyaa1 = Actor.Create("agun", true, { Location = CPos.New(49,15), Owner = EnemysTop }) 
		newEnemyaa2 = Actor.Create("agun", true, { Location = CPos.New(49,40), Owner = EnemysBottom })
		newEnemyaa3 = Actor.Create("agun", true, { Location = CPos.New(49,48), Owner = EnemysBottom })
		newEnemypbox4 = Actor.Create("hbox", true, { Location = CPos.New(48,10), Owner = EnemysTop })
		newEnemypbox5 = Actor.Create("hbox", true, { Location = CPos.New(48,18), Owner = EnemysTop }) 
		newEnemypbox6 = Actor.Create("hbox", true, { Location = CPos.New(48,43), Owner = EnemysBottom })
		newEnemypbox7 = Actor.Create("hbox", true, { Location = CPos.New(48,51), Owner = EnemysBottom })
		Trigger.OnDamaged(newEnemyaa0, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemyaa1, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemyaa2, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemyaa3, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		newEnemytsla4 = Actor.Create("tsla", true, { Location = CPos.New(46,8) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysTop })
		newEnemytsla5 = Actor.Create("tsla", true, { Location = CPos.New(46,16) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysTop }) 
		newEnemytsla6 = Actor.Create("tsla", true, { Location = CPos.New(46,41) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysBottom })
		newEnemytsla7 = Actor.Create("tsla", true, { Location = CPos.New(46,49) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysBottom })
		Trigger.OnDamaged(newEnemytsla4, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemytsla5, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemytsla6, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemytsla7, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
	end
	if Map.LobbyOption("difficulty") == "hard" or Map.LobbyOption("difficulty") == "unbelievable" then
		newEnemypbox8 = Actor.Create("hbox", true, { Location = CPos.New(50,8), Owner = EnemysTop })
		newEnemypbox9 = Actor.Create("hbox", true, { Location = CPos.New(50,16), Owner = EnemysTop }) 
		newEnemypbox10 = Actor.Create("hbox", true, { Location = CPos.New(50,41), Owner = EnemysBottom })
		newEnemypbox11 = Actor.Create("hbox", true, { Location = CPos.New(50,49), Owner = EnemysBottom })
		newEnemyaa4 = Actor.Create("agun", true, { Location = CPos.New(53,6), Owner = EnemysTop })
		newEnemyaa5 = Actor.Create("agun", true, { Location = CPos.New(53,14), Owner = EnemysTop }) 
		newEnemyaa6 = Actor.Create("agun", true, { Location = CPos.New(53,39), Owner = EnemysBottom })
		newEnemyaa7 = Actor.Create("agun", true, { Location = CPos.New(53,47), Owner = EnemysBottom })
		Trigger.OnDamaged(newEnemyaa4, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemyaa5, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemyaa6, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemyaa7, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		newEnemygap1 = Actor.Create("gap", true, { Location = CPos.New(48,11), Owner = EnemysTop })
		newEnemygap2 = Actor.Create("gap", true, { Location = CPos.New(48,44), Owner = EnemysBottom })
		Trigger.OnDamaged(newEnemygap1, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemygap2, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		newEnemytsla8 = Actor.Create("tsla", true, { Location = CPos.New(44,8) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysTop })
		newEnemytsla9 = Actor.Create("tsla", true, { Location = CPos.New(44,16) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysTop }) 
		newEnemytsla10 = Actor.Create("tsla", true, { Location = CPos.New(44,41) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysBottom })
		newEnemytsla11 = Actor.Create("tsla", true, { Location = CPos.New(44,49) + CVec.New(0, Utils.RandomInteger(-1, 1)), Owner = EnemysBottom })
		Trigger.OnDamaged(newEnemytsla8, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemytsla9, function(building)
			if building.Owner == EnemysTop and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemytsla10, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
		Trigger.OnDamaged(newEnemytsla11, function(building)
			if building.Owner == EnemysBottom and building.Health < building.MaxHealth * 3/4 then
				building.StartBuildingRepairs()
			end
		end)
	end
end


SetupPlayers = function()
	EnemysTop = Player.GetPlayer("EnemysTop")
	EnemysBottom = Player.GetPlayer("EnemysBottom")
	France = Player.GetPlayer("france")
	Neutral = Player.GetPlayer("Neutral")
	Multi0 = Player.GetPlayer("Multi0")
	if Multi0 == nil then
		Multi0 = Player.GetPlayer("Multi1")
		if Multi0 == nil then
			Multi0 = Player.GetPlayer("Creeps")
		end
	end
	Multi1 = Player.GetPlayer("Multi1")
	if Multi1 == nil then
		Multi1 = Player.GetPlayer("Multi0")
		if Multi1 == nil then
			Multi1 = Player.GetPlayer("Creeps")
		end
	end
	Multi2 = Player.GetPlayer("Multi2")
	if Multi2 == nil then
		Multi2 = Player.GetPlayer("Multi3")
		if Multi2 == nil then
			Multi2 = Player.GetPlayer("Creeps")
		end
	end
	Multi3 = Player.GetPlayer("Multi3")
	if Multi3 == nil then
		Multi3 = Player.GetPlayer("Multi2")
		if Multi3 == nil then
			Multi3 = Player.GetPlayer("Creeps")
		end
	end
	Humans = { Multi0, Multi1, Multi2, Multi3 }
end
TopTeamWon = false
BottomTeamWon = false

WriteStatisticsTeam1 = function()

	Utils.Do(Humans, function(player)
--		Player1Name = Multi0.Name
		Player1Color = Multi0.Color
		Player1Faction = Multi0.Faction
		Player1Kills = Multi0.UnitsKilled
		Player1Looses = Multi0.UnitsLost
		Player1KillsCost = Multi0.KillsCost
		Player1DeathsCost = Multi0.DeathsCost
		Player1Experience = Multi0.Experience

--		Player2Name = Multi1.Name
--		Player2Color = Multi1.Color
		Player2Faction = Multi1.Faction
		Player2Kills = Multi1.UnitsKilled
		Player2Looses = Multi1.UnitsLost
		Player2KillsCost = Multi1.KillsCost
		Player2DeathsCost = Multi1.DeathsCost
		Player2Experience = Multi1.Experience

		Team1Kills = Player1Kills + Player2Kills
		Team1Looses = Player1Looses + Player2Looses
		Team1KillsCost = Player1KillsCost + Player2KillsCost
		Team1DeathsCost = Player1DeathsCost + Player2DeathsCost
		Team1Experience = Player1Experience + Player2Experience
	end)
	Media.DisplayMessage("" .. Player1Faction .. " + " .. Player2Faction .. "\nKilled/Lost " .. Team1Kills .. " / " .. Team1Looses .. " Units\nDestroyed " .. Team1KillsCost .. " $ and wasted " .. Team1DeathsCost .. " $\nScore : " .. Team1Experience .. "", "Team 1", Player1Color)

end

WriteStatisticsTeam2 = function()

	Utils.Do(Humans, function(player)
--		Player3Name = Multi2.Name
		Player3Color = Multi2.Color
		Player3Faction = Multi2.Faction
		Player3Kills = Multi2.UnitsKilled
		Player3Looses = Multi2.UnitsLost
		Player3KillsCost = Multi2.KillsCost
		Player3DeathsCost = Multi2.DeathsCost
		Player3Experience = Multi2.Experience

--		Player4Name = Multi3.Name
--		Player4Color = Multi3.Color
		Player4Faction = Multi3.Faction
		Player4Kills = Multi3.UnitsKilled
		Player4Looses = Multi3.UnitsLost
		Player4KillsCost = Multi3.KillsCost
		Player4DeathsCost = Multi3.DeathsCost
		Player4Experience = Multi3.Experience

		Team2Kills = Player3Kills + Player4Kills
		Team2Looses = Player3Looses + Player4Looses
		Team2KillsCost = Player3KillsCost + Player4KillsCost
		Team2DeathsCost = Player3DeathsCost + Player4DeathsCost
		Team2Experience = Player3Experience + Player4Experience

	end)
	Media.DisplayMessage("" .. Player3Faction .. " + " .. Player4Faction .. "\nKilled/Lost " .. Team2Kills .. " / " .. Team2Looses .. " Units\nDestroyed " .. Team2KillsCost .. " $ and wasted " .. Team2DeathsCost .. " $\nScore : " .. Team2Experience .. "", "Team 2", Player3Color)

end

Team1Won = function()
	TopTeamWon = true
	if BottomTeamWon == false then
		Media.PlayMusic("radio")
		BrightnessChangeSpeed = 1
		BrightestLight = 1.1
		DarkestLight = 0.01
		RateOfIncrease = 0.008
		turnOff()
		Media.PlaySoundNotification( allplayers, "AlertBuzzer")
		Media.DisplayMessage("Congratulations Team 1 wins the Game!", "Materia", TimerColor)

		Trigger.AfterDelay(DateTime.Seconds(5), function()
			Media.DisplayMessage("Team 1", "Materia", TimerColor)
			WriteStatisticsTeam1()
			if Multi0 ~= Multi1 then Playername = Actor.Create("nix01pname", true, { Location = CPos.New(27,25), Owner = Multi0 }) end
			if Multi0 ~= Multi1 then And = Actor.Create("nix01and", true, { Location = CPos.New(28,27), Owner = Multi0 }) end
			Playername = Actor.Create("nix01pname", true, { Location = CPos.New(27,31), Owner = Multi1 })
			Wins = Actor.Create("nix01wins", true, { Location = CPos.New(24,34), Owner = Multi1 })
			Trigger.AfterDelay(DateTime.Seconds(7), function()
				WriteStatisticsTeam2()
			end)
		end)
	end
	Trigger.AfterDelay(DateTime.Seconds(25), function()
		EndLight = 1.05
		Lighting.Ambient = EndLight
		Multi0.MarkCompletedObjective(KillbaseP1) 
		Multi1.MarkCompletedObjective(KillbaseP2)
		Multi2.MarkFailedObjective(KillbaseP3)
		Multi3.MarkFailedObjective(KillbaseP4)
	end)
end
Team2Won = function()
	BottomTeamWon = true
	if TopTeamWon == false then
		Media.PlayMusic("radio")
		BrightnessChangeSpeed = 1
		BrightestLight = 1.1
		DarkestLight = 0.01
		RateOfIncrease = 0.008
		turnOff()
		Media.PlaySoundNotification( allplayers, "AlertBuzzer")
		Media.DisplayMessage("Congratulations Team 2 wins the Game!", "Materia", TimerColor)
		Trigger.AfterDelay(DateTime.Seconds(5), function()
			WriteStatisticsTeam2()
			if Multi2 ~= Multi3 then Playername = Actor.Create("nix01pname", true, { Location = CPos.New(27,25), Owner = Multi2 }) end
			if Multi2 ~= Multi3 then And = Actor.Create("nix01and", true, { Location = CPos.New(28,27), Owner = Multi2 }) end
			Playername = Actor.Create("nix01pname", true, { Location = CPos.New(27,31), Owner = Multi3 })
			Wins = Actor.Create("nix01wins", true, { Location = CPos.New(24,34), Owner = Multi3 })
			Trigger.AfterDelay(DateTime.Seconds(7), function()
				WriteStatisticsTeam1()
			end)
		end)
	end
	Trigger.AfterDelay(DateTime.Seconds(25), function()
		EndLight = 1.05
		Lighting.Ambient = EndLight
		Multi2.MarkCompletedObjective(KillbaseP3) 
		Multi3.MarkCompletedObjective(KillbaseP4)
		Multi0.MarkFailedObjective(KillbaseP1)
		Multi1.MarkFailedObjective(KillbaseP2)
	end)
end
SetCamera = function(Multi)
	local mainbase = Multi.GetActorsByType("fact")[1]
	Camera.Position = mainbase.CenterPosition
end


RateOfIncrease = 0.001

turnOn = function()
	Lighting.Ambient = Light
	if Light < BrightestLight and TopTeamWon == false and BottomTeamWon == false then
		Light = Light + RateOfIncrease
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			turnOn()
		end)
	
	elseif TopTeamWon == false and BottomTeamWon == false then
		Trigger.AfterDelay(DayDuration, function()
			turnOff()
		end)
	end
end

turnOff = function()
	Lighting.Ambient = Light
	if Light < 0.6 and TopTeamWon == false and BottomTeamWon == false then
		Thunderstorm = true
		Media.PlayMusic("rain")
	end
	if Light > DarkestLight then
		Light = Light - RateOfIncrease
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			turnOff()
		end)	
	elseif TopTeamWon == false and BottomTeamWon == false then
		Trigger.AfterDelay(NightDuration, function()
			Thunderstorm = false
			HardMusic = Utils.Random(RandomHardSound)
			Media.PlayMusic(HardMusic)
			turnOn()
		end)
	end
end

UnbelievableturnOn = function()
	Lighting.Ambient = Light
	if Light > 0.6 and TopTeamWon == false and BottomTeamWon == false then
		BrightnessChangeSpeed = 4
		RateOfIncrease = 0.001
	end
	if Light < BrightestLight and TopTeamWon == false and BottomTeamWon == false then
		Light = Light + RateOfIncrease
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			UnbelievableturnOn()
		end)
	
	elseif TopTeamWon == false and BottomTeamWon == false then
		Trigger.AfterDelay(DayDuration, function()
			UnbelievableturnOff()
		end)
	end
end

UnbelievableturnOff = function()
	Lighting.Ambient = Light
	if Light < 0.7 and TopTeamWon == false and BottomTeamWon == false then
		Thunderstorm = true
		Media.PlayMusic("rain")
	end
	if Light < 0.5 and TopTeamWon == false and BottomTeamWon == false then
		BrightnessChangeSpeed = 1
		RateOfIncrease = 0.0025
	end

	if Light > DarkestLight and TopTeamWon == false and BottomTeamWon == false then
		Light = Light - RateOfIncrease
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			UnbelievableturnOff()
		end)	
	
	else
		Trigger.AfterDelay(NightDuration, function()
			Thunderstorm = false
			HardMusic = Utils.Random(RandomHardSound)
			Media.PlayMusic(HardMusic)
			UnbelievableturnOn()
		end)
	end
end

GiveMoney = function()
	if not newmcv0.IsDead and Multi0.Experience>0 and TopTeamWon == false and BottomTeamWon == false then
		Multi0.Cash = Multi0.Cash + Multi0.Experience
		Media.FloatingText("" .. (Multi0.Experience) .. " $ Scorebonus", newmcv0.CenterPosition, 30, Multi0.Color)
	end
	if not newmcv1.IsDead and Multi1.Experience>0 and TopTeamWon == false and BottomTeamWon == false then
		Multi1.Cash = Multi1.Cash + Multi1.Experience
		Media.FloatingText("" .. (Multi1.Experience) .. " $ Scorebonus", newmcv1.CenterPosition, 30, Multi1.Color)
	end
	if not newmcv2.IsDead and Multi2.Experience>0 and TopTeamWon == false and BottomTeamWon == false then
		Multi2.Cash = Multi2.Cash + Multi2.Experience
		Media.FloatingText("" .. (Multi2.Experience) .. " $ Scorebonus", newmcv2.CenterPosition, 30, Multi2.Color)
	end
	if not newmcv3.IsDead and Multi3.Experience>0 and TopTeamWon == false and BottomTeamWon == false then
		Multi3.Cash = Multi3.Cash + Multi3.Experience
		Media.FloatingText("" .. (Multi3.Experience) .. " $ Scorebonus", newmcv3.CenterPosition, 30, Multi3.Color)
	end
	Trigger.AfterDelay(DateTime.Seconds(4), function()
		GiveMoney()
	end)
end

RandomEasySound = { "radio", "workmen", "hell" }
RandomMediumSound = { "hell", "workmen", "factory" }
RandomHardSound = { "radio", "workmen", "hell", "factory" }

Changemusic1 = function()
	if Map.LobbyOption("difficulty") == "easy" then
		LightMusic2 = Utils.Random(RandomEasySound)
		if LightMusic1 ~= LightMusic2 then
			Media.PlayMusic(LightMusic2)
		else
			Changemusic1()
		end
	end
	if Map.LobbyOption("difficulty") == "normal" then
		MediumMusic2 = Utils.Random(RandomMediumSound)
		if MediumMusic1 ~= MediumMusic2 then
			Media.PlayMusic(MediumMusic2)
		else
			Changemusic1()
		end
	end
end
Changemusic2 = function()
	if Map.LobbyOption("difficulty") == "easy" then
		LightMusic3 = Utils.Random(RandomEasySound)
		if LightMusic1 ~= LightMusic3 and LightMusic2 ~= LightMusic3 then
			Media.PlayMusic(LightMusic3)
		else
			Changemusic2()
		end
	end
	if Map.LobbyOption("difficulty") == "normal" then
		MediumMusic3 = Utils.Random(RandomMediumSound)
		if MediumMusic1 ~= MediumMusic3 and MediumMusic2 ~= MediumMusic3 then
			Media.PlayMusic(MediumMusic3)
		else
			Changemusic2()
		end
	end
end

DifficultiesCondition = function()
	if Map.LobbyOption("difficulty") == "easy" then
		StartingMessages()
		InfDelayTimemin = 3
		VehDelayTimemin = 10
		TnkDelayTimemin = 14
		ArtyDelayTimemin = 17
		HeliDelayTimemin = 15
		GunboatminTime = 25
		GunboatmaxTime = 60
		SubminTime = 30
		SubmaxTime = 60
		DestroyerminTime = 45
		DestroyermaxTime = 65
		CruiserminTime = 40
		CruisermaxTime = 75
		MsubminTime = 40
		MsubmaxTime = 75
		AnySpecialattack = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11 }
		SpecialminTime = 40
		SpecialmaxTime = 60
		EnemyunitsConditions()
		TimerColor = HSLColor.LawnGreen
		LightMusic1 = Utils.Random(RandomEasySound)
		Media.PlayMusic(LightMusic1)
		Light = 1
		Media.DisplayMessage("Difficulty: Easy\n" .. UnitPercent .. "0% Enemy units income.\n\n\n\n\nHF newbie\nYou can adjust the enemys strength in the lobby settings\n40% is easier and 100% the full enemy strength.", "Materia", TimerColor)
	end
	if Map.LobbyOption("difficulty") == "normal" then
		StartingMessages()
		InfDelayTimemin = 2
		VehDelayTimemin = 9
		MonsterDelayTimemin = 8
		TnkDelayTimemin = 13
		ArtyDelayTimemin = 16
		HeliDelayTimemin = 14
		GunboatminTime = 25
		GunboatmaxTime = 60
		SubminTime = 25
		SubmaxTime = 65
		DestroyerminTime = 40
		DestroyermaxTime = 60
		CruiserminTime = 35
		CruisermaxTime = 70
		MsubminTime = 35
		MsubmaxTime = 70
		AnySpecialattack = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 1, 2, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11 }
		SpecialminTime = 30
		SpecialmaxTime = 60
		EnemyunitsConditions()
		TimerColor = HSLColor.Orange
		MediumMusic1 = Utils.Random(RandomMediumSound)
		Media.PlayMusic(MediumMusic1)
		Light = 0.9
		BrightnessChangeSpeed = 8
		BrightestLight = 1.05
		DarkestLight = 0.75
		DayDuration = 8000
		NightDuration = 3000
		turnOn()
		Media.DisplayMessage("Difficulty: Medium\n" .. UnitPercent .. "0% Enemy units income.\n\n\n\n\nGL\nHF", "Materia", TimerColor)
	end
	if Map.LobbyOption("difficulty") == "hard" then
		InfDelayTimemin = 1
		VehDelayTimemin = 8
		MonsterDelayTimemin = 8
		TnkDelayTimemin = 12
		ArtyDelayTimemin = 15
		HeliDelayTimemin = 14
		UFODelayTimemin = 12
		GunboatminTime = 15
		GunboatmaxTime = 55
		SubminTime = 10
		SubmaxTime = 30
		DestroyerminTime = 35
		DestroyermaxTime = 55
		CruiserminTime = 30
		CruisermaxTime = 65
		MsubminTime = 30
		MsubmaxTime = 65
		AnySpecialattack = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 1, 2, 1, 2, 1, 2, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11 }
		SpecialminTime = 20
		SpecialmaxTime = 50
		EnemyunitsConditions()
		TimerColor = HSLColor.Red
		HardMusic = Utils.Random(RandomHardSound)
		Media.PlayMusic(HardMusic)
		Light = 0.7
		BrightnessChangeSpeed = 5
		BrightestLight = 1
		DarkestLight = 0.5
		DayDuration = 5000
		NightDuration = 5000
		turnOn()
		Media.DisplayMessage("Difficulty: Hard\n" .. UnitPercent .. "0% Enemy units income.\n\n\n\n\nGL\nHF", "Materia", TimerColor)
	end
	if Map.LobbyOption("difficulty") == "unbelievable" then
		InfDelayTimemin = 1
		VehDelayTimemin = 8
		MonsterDelayTimemin = 8
		TnkDelayTimemin = 12
		ArtyDelayTimemin = 15
		HeliDelayTimemin = 14
		UFODelayTimemin = 13
		GunboatminTime = 1
		GunboatmaxTime = 60
		SubminTime = 5
		SubmaxTime = 75
		DestroyerminTime = 5
		DestroyermaxTime = 85
		CruiserminTime = 10
		CruisermaxTime = 85
		MsubminTime = 10
		MsubmaxTime = 85
		AnySpecialattack = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 1, 2, 1, 2, 1, 2, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11 }
		SpecialminTime = 5
		SpecialmaxTime = 65
		EnemyunitsConditions()
		TimerColor = Multi0.Color
		HardMusic = Utils.Random(RandomHardSound)
		Media.PlayMusic(HardMusic)
		Light = 0.8
		BrightnessChangeSpeed = 4
		BrightestLight = 1.1
		DarkestLight = 0.01
		DayDuration = 4500
		NightDuration = 30
		UnbelievableturnOn()
		Media.DisplayMessage("Difficulty: Unbelievable\n" .. UnitPercent .. "0% Enemy units income.\n\n\n\n\n\nEverything that can happen!", "Materia", TimerColor)
	end
end

PlayerObjectives = function()
	KillbaseP1 = Multi0.AddPrimaryObjective("Kill the top enemys Mainbase")
	KillbaseP2 = Multi1.AddPrimaryObjective("Kill the top enemys Mainbase")
	KillbaseP3 = Multi2.AddPrimaryObjective("Kill the bottom enemys Mainbase")
	KillbaseP4 = Multi3.AddPrimaryObjective("Kill the bottom enemys Mainbase")
end
SetStartingCamera = function()
	Trigger.AfterDelay(1, function()
		Protectorsign = Actor.Create("nix01pr", true, { Location = CPos.New(5,27), Owner = Multi0 })
		if Multi0.IsLocalPlayer then
			SetCamera(Multi0)
		elseif Multi1.IsLocalPlayer then
			SetCamera(Multi1)
		elseif Multi2.IsLocalPlayer then
			SetCamera(Multi2)
		elseif Multi3.IsLocalPlayer then
			SetCamera(Multi3)
		end
	end)
end
StartingMessages = function()
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Media.DisplayMessage("Defend your bases against the incoming forces.", "Materia", TimerColor)	
	end)
	Trigger.AfterDelay(DateTime.Seconds(8), function()
		Media.DisplayMessage("Try to destroy the enemys base in front of you.", "Materia", TimerColor)
	end)
	Trigger.AfterDelay(DateTime.Seconds(12), function()
		Media.DisplayMessage("You can capture Oilderricks by moving any unit close to it.", "Materia", TimerColor)
		Media.PlaySoundNotification( allplayers, "Beacon")
		Beacon.New(Multi0, Actor37.CenterPosition, 1000, true)
		Beacon.New(Multi0, Actor38.CenterPosition, 1000, true)
		Beacon.New(Multi1, Actor39.CenterPosition, 1000, true)
		Beacon.New(Multi1, Actor40.CenterPosition, 1000, true)
		Beacon.New(Multi2, Actor41.CenterPosition, 1000, true)
		Beacon.New(Multi2, Actor42.CenterPosition, 1000, true)
		Beacon.New(Multi3, Actor43.CenterPosition, 1000, true)
		Beacon.New(Multi3, Actor44.CenterPosition, 1000, true)

	end)
	Trigger.AfterDelay(DateTime.Seconds(16), function()
		Media.DisplayMessage("Oilderricks give you buildarea.", "Materia", TimerColor)
	end)
	Trigger.AfterDelay(DateTime.Seconds(21), function()
		Media.DisplayMessage("All chargetimes are halfed.", "Materia", TimerColor)
	end)
end


function WorldLoaded()
	SetupPlayers()
	StartingUnitsCheck()
	WaveInterrupter()
	DifficultiesCondition()
	MCVincome()
	GetandsetFlags()
	GiveMoney()
	PlayerObjectives()
	SetStartingCamera()
end

Tick = function()
	if DestroyedBuildings1 > 4 or DestroyedBuildings2 > 4 and not TimerRed then
		TimerColor = HSLColor.Red
		TimerRed = true
	end
	UserInterface.SetMissionText("Team 1   " .. (DestroyedBuildings1) .. " / 7 destroyed Enemy buildings                                   Team 2   " .. (DestroyedBuildings2) .. " / 7 destroyed Enemy buildings" , TimerColor)
	if Thunderstorm then
		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



