
EnemyunitsConditions = function()
	EnemyInfUnit = { "e1", "e3", "dog" }
	InfDelayTimemin = 1
	InfDelayTimemax = 9
	EnemyInfantryIncome()
	Trigger.AfterDelay(DateTime.Minutes(1), function()
		WaveInterrupter()
		EnemyInfUnit = { "e1", "e1", "e2", "e3", "medi", "dog" }
		InfDelayTimemin = 3
		InfDelayTimemax = 6
		if Map.LobbyOption("difficulty") ~= "easy" then
			EnemyMonsterUnit = { "PVICE", "BSPI" }
			MonsterDelayTimemin = 20
			MonsterDelayTimemax = 25
			EnemyMonsterIncome()
		end
	end)
	Trigger.AfterDelay(DateTime.Minutes(2), function()
		EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog" }
		InfDelayTimemin = 3
		InfDelayTimemax = 8
		EnemyVehUnit = { "apc", "1tnk", "jeep", "ftrk" }
		VehDelayTimemin = 10
		VehDelayTimemax = 20
		EnemyVehicleIncome()
		EnemyMonsterUnit = { "PVICE", "IMP", "BSPI" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(3), function()
		EnemyInfUnit = { "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech" }
		InfDelayTimemin = 4
		InfDelayTimemax = 7
		EnemyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk" }
		VehDelayTimemin = 6
		VehDelayTimemax = 12
		MonsterDelayTimemin = 15
		MonsterDelayTimemax = 20
	end)
	Trigger.AfterDelay(DateTime.Minutes(4), function()
		EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI" }
		VehDelayTimemin = 5
		VehDelayTimemax = 11

	end)
	Trigger.AfterDelay(DateTime.Minutes(5), function()
		EnemyTnkUnit = { "2tnk", "3tnk" }
		TnkDelayTimemin = 18
		TnkDelayTimemax = 23
		EnemyTnkIncome()
		EnemyInfUnit = { "e1", "e1", "e1", "e2", "e3", "e4", "e2", "e3", "e4", "medi", "medi", "medi", "dog", "mech", "mech" }
		EnemyArtyUnit = { "v2rl", "arty" }
		ArtyDelayTimemin = 20
		ArtyDelayTimemax = 30
		EnemyArtyIncome()
		EnemyHeliUnit = { "hind", "hind" }
		HeliDelayTimemin = 20
		HeliDelayTimemax = 30
		EnemyHeliIncome()
		if Map.LobbyOption("difficulty") == "hard" then
			EnemyUFOUnit = { "UFO.Beamer", "UFO.Laser" }
			UFODelayTimemin = 20
			UFODelayTimemax = 30
			EnemyUFOIncome()
			HeliDelayTimemin = 15
			HeliDelayTimemax = 25
			MonsterDelayTimemin = 10
			MonsterDelayTimemax = 18
		end
	end)
	Trigger.AfterDelay(DateTime.Minutes(6), function()
		EnemyInfUnit = { "e1", "e1", "e1", "e2", "e3", "e4", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok" }
		EnemyHeliUnit = { "heli", "hind" }

		EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY" }
		TnkDelayTimemin = 12
		TnkDelayTimemax = 20
		ArtyDelayTimemin = 15
		ArtyDelayTimemax = 25
	end)
	Trigger.AfterDelay(DateTime.Minutes(7), function()
		EnemyInfUnit = { "e1", "e1", "e1", "e1", "e2", "e3", "e4", "medi", "medi", "dog", "mech", "mech", "shok" }
		EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "4tnk" }
		EnemyMonsterUnit = { "PVICE", "IMP", "REVE", "BSPI", "PINKY", "MANC" }
		EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "4tnk" }
	end)
	Trigger.AfterDelay(DateTime.Minutes(8), function()
		EnemyInfUnit = { "e1", "e1", "e1", "e1", "e2", "e3", "e2", "e3", "e4", "medi", "medi", "medi", "dog", "mech", "mech", "mech", "shok", "shok", "e7" }
		InfDelayTimemin = 3
		InfDelayTimemax = 6
		EnemyTnkUnit = { "2tnk", "3tnk", "ctnk", "ttnk", "4tnk", "4tnk" }
		if Map.LobbyOption("difficulty") ~= "easy" then
			Demotruckincome()
		end
	end)
	Trigger.AfterDelay(DateTime.Minutes(9), function()
		EnemyVehUnit = { "apc", "1tnk", "1tnk", "jeep", "ftrk", "ftrk", "ftrk", "ftrk" }
		VehDelayTimemin = 4
		VehDelayTimemax = 5
	end)
	Trigger.AfterDelay(DateTime.Minutes(10), function()
	Media.PlayMusic("benzin")
	Demotruckincome()
	end)
end

StartingUnitsCheck = function()
	Utils.Do(Humans, function(player)
		Dog = player.GetActorsByType("dog")
		for p,doggy in pairs(Dog) do
			if doggy.IsInWorld then
				WaveInterval = 0
			end
		end
		E1 = player.GetActorsByType("e1")
		for p,rifleman in pairs(E1) do
			if rifleman.IsInWorld then
				WaveInterval = 5
			end
		end
		E2 = player.GetActorsByType("e2")
		for p,nader in pairs(E2) do
			if nader.IsInWorld then
				WaveInterval = 10
			end
		end
		E3 = player.GetActorsByType("e3")
		for p,rocketman in pairs(E3) do
			if rocketman.IsInWorld then
				WaveInterval = 15
			end
		end
		Medi = player.GetActorsByType("medi")
		for p,medic in pairs(Medi) do
			if medic.IsInWorld then
				WaveInterval = 20
			end
		end
		Mech = player.GetActorsByType("mech")
		for p,mechanic in pairs(Mech) do
			if mechanic.IsInWorld then
				WaveInterval = 25
			end
		end
		E6 = player.GetActorsByType("e6")
		for p,engie in pairs(E6) do
			if engie.IsInWorld then
				WaveInterval = 30
			end
		end
	end)
end

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

-- 8,24  8,39  8,50  8,65  8,90

EnemyInfantryIncome = function()
	Attackpath0 = { CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	RandomUnit = Utils.Random(EnemyInfUnit)
	if Multi0 ~= nil and not PeaceTime then
		EnemyUnit0 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,7) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy0 = { EnemyUnit0 }
		GroupPatrol(Enemy0, Attackpath0, DateTime.Seconds(0))
	end
	if Multi1 ~= nil and not PeaceTime then
		EnemyUnit1 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,33) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy1 = { EnemyUnit1 }
		GroupPatrol(Enemy1, Attackpath1, DateTime.Seconds(0))
	end
	if Multi2 ~= nil and not PeaceTime then
		EnemyUnit2 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,44) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy2 = { EnemyUnit2 }
		GroupPatrol(Enemy2, Attackpath2, DateTime.Seconds(0))
	end
	if Multi3 ~= nil and not PeaceTime then
		EnemyUnit3 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,59) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy3 = { EnemyUnit3 }
		GroupPatrol(Enemy3, Attackpath3, DateTime.Seconds(0))
	end
	if Multi4 ~= nil and not PeaceTime then
		EnemyUnit4 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,93) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy4 = { EnemyUnit4 }
		GroupPatrol(Enemy4, Attackpath4, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(InfDelayTimemin, InfDelayTimemax)), function()
		EnemyInfantryIncome()
	end)
end

EnemyVehicleIncome = function()
	Attackpath0 = { CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,91) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,22) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	RandomUnit = Utils.Random(EnemyVehUnit)
	if Multi0 ~= nil and not PeaceTime then
		EnemyUnit0 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,7) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy0 = { EnemyUnit0 }
		GroupPatrol(Enemy0, Attackpath0, DateTime.Seconds(0))
	end
	if Multi1 ~= nil and not PeaceTime then
		EnemyUnit1 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,33) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy1 = { EnemyUnit1 }
		GroupPatrol(Enemy1, Attackpath1, DateTime.Seconds(0))
	end
	if Multi2 ~= nil and not PeaceTime then
		EnemyUnit2 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,44) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy2 = { EnemyUnit2 }
		GroupPatrol(Enemy2, Attackpath2, DateTime.Seconds(0))
	end
	if Multi3 ~= nil and not PeaceTime then
		EnemyUnit3 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,59) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy3 = { EnemyUnit3 }
		GroupPatrol(Enemy3, Attackpath3, DateTime.Seconds(0))
	end
	if Multi4 ~= nil and not PeaceTime then
		EnemyUnit4 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,93) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy4 = { EnemyUnit4 }
		GroupPatrol(Enemy4, Attackpath4, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(VehDelayTimemin, VehDelayTimemax)), function()
		EnemyVehicleIncome()
	end)
end

EnemyTnkIncome = function()
	Attackpath0 = { CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	RandomUnit = Utils.Random(EnemyTnkUnit)
	if Multi0 ~= nil and not PeaceTime then
		EnemyUnit0 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,7) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy0 = { EnemyUnit0 }
		GroupPatrol(Enemy0, Attackpath0, DateTime.Seconds(0))
	end
	if Multi1 ~= nil and not PeaceTime then
		EnemyUnit1 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,33) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy1 = { EnemyUnit1 }
		GroupPatrol(Enemy1, Attackpath1, DateTime.Seconds(0))
	end
	if Multi2 ~= nil and not PeaceTime then
		EnemyUnit2 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,44) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy2 = { EnemyUnit2 }
		GroupPatrol(Enemy2, Attackpath2, DateTime.Seconds(0))
	end
	if Multi3 ~= nil and not PeaceTime then
		EnemyUnit3 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,59) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy3 = { EnemyUnit3 }
		GroupPatrol(Enemy3, Attackpath3, DateTime.Seconds(0))
	end
	if Multi4 ~= nil and not PeaceTime then
		EnemyUnit4 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,93) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy4 = { EnemyUnit4 }
		GroupPatrol(Enemy4, Attackpath4, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(TnkDelayTimemin, TnkDelayTimemax)), function()
		EnemyTnkIncome()
	end)
end

EnemyArtyIncome = function()
	Attackpath0 = { CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	RandomUnit = Utils.Random(EnemyArtyUnit)
	if Multi0 ~= nil and not PeaceTime then
		EnemyUnit0 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,7) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy0 = { EnemyUnit0 }
		GroupPatrol(Enemy0, Attackpath0, DateTime.Seconds(0))
	end
	if Multi1 ~= nil and not PeaceTime then
		EnemyUnit1 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,33) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy1 = { EnemyUnit1 }
		GroupPatrol(Enemy1, Attackpath1, DateTime.Seconds(0))
	end
	if Multi2 ~= nil and not PeaceTime then
		EnemyUnit2 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,44) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy2 = { EnemyUnit2 }
		GroupPatrol(Enemy2, Attackpath2, DateTime.Seconds(0))
	end
	if Multi3 ~= nil and not PeaceTime then
		EnemyUnit3 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,59) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy3 = { EnemyUnit3 }
		GroupPatrol(Enemy3, Attackpath3, DateTime.Seconds(0))
	end
	if Multi4 ~= nil and not PeaceTime then
		EnemyUnit4 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,93) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy4 = { EnemyUnit4 }
		GroupPatrol(Enemy4, Attackpath4, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(ArtyDelayTimemin, ArtyDelayTimemax)), function()
		EnemyArtyIncome()
	end)
end

EnemyHeliIncome = function()
	Attackpath0 = { CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	RandomUnit = Utils.Random(EnemyHeliUnit)
	if Multi0 ~= nil and not PeaceTime then
		EnemyUnit0 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,7) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy0 = { EnemyUnit0 }
		GroupPatrol(Enemy0, Attackpath0, DateTime.Seconds(0))
	end
	if Multi1 ~= nil and not PeaceTime then
		EnemyUnit1 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,33) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy1 = { EnemyUnit1 }
		GroupPatrol(Enemy1, Attackpath1, DateTime.Seconds(0))
	end
	if Multi2 ~= nil and not PeaceTime then
		EnemyUnit2 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,44) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy2 = { EnemyUnit2 }
		GroupPatrol(Enemy2, Attackpath2, DateTime.Seconds(0))
	end
	if Multi3 ~= nil and not PeaceTime then
		EnemyUnit3 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,59) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy3 = { EnemyUnit3 }
		GroupPatrol(Enemy3, Attackpath3, DateTime.Seconds(0))
	end
	if Multi4 ~= nil and not PeaceTime then
		EnemyUnit4 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,93) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy4 = { EnemyUnit4 }
		GroupPatrol(Enemy4, Attackpath4, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(HeliDelayTimemin, HeliDelayTimemax)), function()
		EnemyHeliIncome()
	end)
end

EnemyMonsterIncome = function()
	Attackpath0 = { CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	RandomUnit = Utils.Random(EnemyMonsterUnit)
	if Multi0 ~= nil and not PeaceTime then
		EnemyUnit0 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,7) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy0 = { EnemyUnit0 }
		GroupPatrol(Enemy0, Attackpath0, DateTime.Seconds(0))
	end
	if Multi1 ~= nil and not PeaceTime then
		EnemyUnit1 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,33) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy1 = { EnemyUnit1 }
		GroupPatrol(Enemy1, Attackpath1, DateTime.Seconds(0))
	end
	if Multi2 ~= nil and not PeaceTime then
		EnemyUnit2 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,44) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy2 = { EnemyUnit2 }
		GroupPatrol(Enemy2, Attackpath2, DateTime.Seconds(0))
	end
	if Multi3 ~= nil and not PeaceTime then
		EnemyUnit3 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,59) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy3 = { EnemyUnit3 }
		GroupPatrol(Enemy3, Attackpath3, DateTime.Seconds(0))
	end
	if Multi4 ~= nil and not PeaceTime then
		EnemyUnit4 = Actor.Create(RandomUnit, true, { Location = CPos.New(150,93) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy4 = { EnemyUnit4 }
		GroupPatrol(Enemy4, Attackpath4, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(MonsterDelayTimemin, MonsterDelayTimemax)), function()
		EnemyMonsterIncome()
	end)
end

EnemyUFOIncome = function()
	Attackpath0 = { CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	RandomUnit = Utils.Random(EnemyUFOUnit)
	if Multi0 ~= nil and not PeaceTime then
		EnemyUnit0 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,7) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy0 = { EnemyUnit0 }
		GroupPatrol(Enemy0, Attackpath0, DateTime.Seconds(0))
	end
	if Multi1 ~= nil and not PeaceTime then
		EnemyUnit1 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,33) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy1 = { EnemyUnit1 }
		GroupPatrol(Enemy1, Attackpath1, DateTime.Seconds(0))
	end
	if Multi2 ~= nil and not PeaceTime then
		EnemyUnit2 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,44) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy2 = { EnemyUnit2 }
		GroupPatrol(Enemy2, Attackpath2, DateTime.Seconds(0))
	end
	if Multi3 ~= nil and not PeaceTime then
		EnemyUnit3 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,59) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy3 = { EnemyUnit3 }
		GroupPatrol(Enemy3, Attackpath3, DateTime.Seconds(0))
	end
	if Multi4 ~= nil and not PeaceTime then
		EnemyUnit4 = Actor.Create(RandomUnit, true, { Location = CPos.New(152,93) + CVec.New(0, Utils.RandomInteger(-3, 3)), Owner = Enemys })
		Enemy4 = { EnemyUnit4 }
		GroupPatrol(Enemy4, Attackpath4, DateTime.Seconds(0))
	end
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(UFODelayTimemin, UFODelayTimemax)), function()
		EnemyUFOIncome()
	end)
end

Demotruckincome = function()
	Attackpath0 = { CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath1 = { CPos.New(8,39) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath2 = { CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath3 = { CPos.New(8,65) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }

	Attackpath4 = { CPos.New(8,90) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,24) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)), CPos.New(8,50) + CVec.New(Utils.RandomInteger(-3, 3), Utils.RandomInteger(-3, 3)) }
	Trigger.AfterDelay(DateTime.Seconds(Utils.RandomInteger(30, 60)), function()
		if Multi0 ~= nil and not PeaceTime then
			Demo0 = Actor.Create("dtrk", true, { Location = CPos.New(150,7), Owner = Enemys })
			Dtruk0 = { Demo0 }
			MovePatrol(Dtruk0, Attackpath0, DateTime.Seconds(0))
		end
		if Multi1 ~= nil and not PeaceTime then
			Demo1 = Actor.Create("dtrk", true, { Location = CPos.New(150,33), Owner = Enemys })
			Dtruk1 = { Demo1 }
			MovePatrol(Dtruk1, Attackpath1, DateTime.Seconds(0))
		end
		if Multi2 ~= nil and not PeaceTime then
			Demo2 = Actor.Create("dtrk", true, { Location = CPos.New(150,44), Owner = Enemys })
			Dtruk2 = { Demo2 }
			MovePatrol(Dtruk2, Attackpath2, DateTime.Seconds(0))
		end
		if Multi3 ~= nil and not PeaceTime then
			Demo3 = Actor.Create("dtrk", true, { Location = CPos.New(150,59), Owner = Enemys })
			Dtruk3 = { Demo3 }
			MovePatrol(Dtruk3, Attackpath3, DateTime.Seconds(0))
		end
		if Multi4 ~= nil and not PeaceTime then
			Demo4 = Actor.Create("dtrk", true, { Location = CPos.New(150,93), Owner = Enemys })
			Dtruk4 = { Demo4 }
			MovePatrol(Dtruk4, Attackpath4, DateTime.Seconds(0))
		end
		Demotruckincome()
	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

EnemyBuildingCounter = 0
DestroyedBuildings = 0
EnemysBaseMaker = function()
	if Multi0 ~= nil then
		newEnemyfact0 = Actor.Create("fact", true, { Location = CPos.New(146,9), Owner = Enemys })
		Trigger.OnKilled(newEnemyfact0, function() DestroyedBuildings = DestroyedBuildings + 1 end)
		newEnemyapwr0 = Actor.Create("much.apwr", true, { Location = CPos.New(146,4), Owner = Enemys })
		Trigger.OnKilled(newEnemyapwr0, function() DestroyedBuildings = DestroyedBuildings + 1 end)		
		newEnemytsla0 = Actor.Create("tsla", true, { Location = CPos.New(143,6), Owner = Enemys })
		newEnemypbox0 = Actor.Create("pbox", true, { Location = CPos.New(148,8), Owner = Enemys })
		EnemyBuildingCounter = EnemyBuildingCounter + 2
	end
	if Multi1 ~= nil then
		newEnemyfact1 = Actor.Create("fact", true, { Location = CPos.New(146,36), Owner = Enemys })
		Trigger.OnKilled(newEnemyfact1, function() DestroyedBuildings = DestroyedBuildings + 1 end)
		newEnemyapwr1 = Actor.Create("much.apwr", true, { Location = CPos.New(146,34), Owner = Enemys })
		Trigger.OnKilled(newEnemyapwr1, function() DestroyedBuildings = DestroyedBuildings + 1 end)	
		newEnemytsla1 = Actor.Create("tsla", true, { Location = CPos.New(143,32), Owner = Enemys })
		newEnemypbox1 = Actor.Create("pbox", true, { Location = CPos.New(148,32), Owner = Enemys })
		EnemyBuildingCounter = EnemyBuildingCounter + 2
	end
	if Multi2 ~= nil then
		newEnemyfact2 = Actor.Create("fact", true, { Location = CPos.New(143,45), Owner = Enemys })
		Trigger.OnKilled(newEnemyfact2, function() DestroyedBuildings = DestroyedBuildings + 1 end)
		newEnemyapwr2 = Actor.Create("much.apwr", true, { Location = CPos.New(146,46), Owner = Enemys })
		Trigger.OnKilled(newEnemyapwr2, function() DestroyedBuildings = DestroyedBuildings + 1 end)	
		newEnemytsla2 = Actor.Create("tsla", true, { Location = CPos.New(142,45), Owner = Enemys })
		newEnemypbox2 = Actor.Create("pbox", true, { Location = CPos.New(144,43), Owner = Enemys })
		EnemyBuildingCounter = EnemyBuildingCounter + 2
	end
	if Multi3 ~= nil then
		newEnemyfact3 = Actor.Create("fact", true, { Location = CPos.New(146,55), Owner = Enemys })
		Trigger.OnKilled(newEnemyfact3, function() DestroyedBuildings = DestroyedBuildings + 1 end)
		newEnemyapwr3 = Actor.Create("much.apwr", true, { Location = CPos.New(146,60), Owner = Enemys })
		Trigger.OnKilled(newEnemyapwr3, function() DestroyedBuildings = DestroyedBuildings + 1 end)	
		newEnemytsla3 = Actor.Create("tsla", true, { Location = CPos.New(143,57), Owner = Enemys })
		newEnemypbox3 = Actor.Create("pbox", true, { Location = CPos.New(148,58), Owner = Enemys })
		EnemyBuildingCounter = EnemyBuildingCounter + 2
	end	
	if Multi4 ~= nil then
		newEnemyfact4 = Actor.Create("fact", true, { Location = CPos.New(145,90), Owner = Enemys })
		Trigger.OnKilled(newEnemyfact4, function() DestroyedBuildings = DestroyedBuildings + 1 end)
		newEnemyapwr4 = Actor.Create("much.apwr", true, { Location = CPos.New(145,94), Owner = Enemys })
		Trigger.OnKilled(newEnemyapwr4, function() DestroyedBuildings = DestroyedBuildings + 1 end)
		newEnemytsla4 = Actor.Create("tsla", true, { Location = CPos.New(143,92), Owner = Enemys })
		newEnemypbox4 = Actor.Create("pbox", true, { Location = CPos.New(144,94), Owner = Enemys })
		EnemyBuildingCounter = EnemyBuildingCounter + 2
	end
	if Map.LobbyOption("difficulty") ~= "easy" then
		if Multi0 ~= nil then
			newEnemyhpad0 = Actor.Create("hpad", true, { Location = CPos.New(142,3), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad0, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(144,8), Owner = Enemys })
			newEnemytsla0 = Actor.Create("tsla", true, { Location = CPos.New(143,10), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1
		end
		if Multi1 ~= nil then
			newEnemyhpad1 = Actor.Create("hpad", true, { Location = CPos.New(142,29), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad1, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(144,35), Owner = Enemys })
			newEnemytsla1 = Actor.Create("tsla", true, { Location = CPos.New(141,30), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1
		end
		if Multi2 ~= nil then
			newEnemyhpad2 = Actor.Create("hpad", true, { Location = CPos.New(142,40), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad2, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(147,45), Owner = Enemys })
			newEnemytsla2 = Actor.Create("tsla", true, { Location = CPos.New(140,42), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1
		end
		if Multi3 ~= nil then
			newEnemyhpad3 = Actor.Create("hpad", true, { Location = CPos.New(142,54), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad3, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(144,61), Owner = Enemys })
			newEnemytsla3 = Actor.Create("tsla", true, { Location = CPos.New(141,57), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1
		end
		if Multi4 ~= nil then
			newEnemyhpad4 = Actor.Create("hpad", true, { Location = CPos.New(142,89), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad4, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(143,94), Owner = Enemys })
			newEnemytsla4 = Actor.Create("tsla", true, { Location = CPos.New(141,92), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1
		end
	end
	if Map.LobbyOption("difficulty") == "hard" then
		if Multi0 ~= nil then
			newEnemyhpad02 = Actor.Create("hpad", true, { Location = CPos.New(142,11), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad02, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("gap", true, { Location = CPos.New(144,9), Owner = Enemys })
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(144,5), Owner = Enemys })
			newEnemy = Actor.Create("hbox", true, { Location = CPos.New(144,6), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1	
		end
		if Multi1 ~= nil then
			newEnemyhpad12 = Actor.Create("hpad", true, { Location = CPos.New(142,34), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad12, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("gap", true, { Location = CPos.New(144,32), Owner = Enemys })
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(146,28), Owner = Enemys })
			newEnemy = Actor.Create("hbox", true, { Location = CPos.New(144,34), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1	
		end
		if Multi2 ~= nil then
			newEnemyhpad22 = Actor.Create("hpad", true, { Location = CPos.New(141,46), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad22, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("gap", true, { Location = CPos.New(143,43), Owner = Enemys })
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(141,42), Owner = Enemys })
			newEnemy = Actor.Create("hbox", true, { Location = CPos.New(148,45), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1	
		end
		if Multi3 ~= nil then
			newEnemyhpad32 = Actor.Create("hpad", true, { Location = CPos.New(143,62), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad32, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("gap", true, { Location = CPos.New(145,60), Owner = Enemys })
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(144,56), Owner = Enemys })
			newEnemy = Actor.Create("hbox", true, { Location = CPos.New(143,60), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1	
		end
		if Multi4 ~= nil then
			newEnemyhpad42 = Actor.Create("hpad", true, { Location = CPos.New(141,95), Owner = Enemys })
			Trigger.OnKilled(newEnemyhpad42, function() DestroyedBuildings = DestroyedBuildings + 1 end)
			newEnemy = Actor.Create("gap", true, { Location = CPos.New(144,91), Owner = Enemys })
			newEnemy = Actor.Create("agun", true, { Location = CPos.New(146,87), Owner = Enemys })
			newEnemy = Actor.Create("hbox", true, { Location = CPos.New(144,92), Owner = Enemys })
			EnemyBuildingCounter = EnemyBuildingCounter + 1	
		end
	end
end

RateOfIncrease = 0.001

turnOn = function()
	Lighting.Ambient = Light
	if Light < BrightestLight then
		Light = Light + RateOfIncrease
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			turnOn()
		end)
	
	else
		NoturnOn = true
		Trigger.AfterDelay(DayDuration, function()
			turnOff()
		end)
	end
end

turnOff = function()
	Lighting.Ambient = Light
	if Light < 0.6 then
		Thunderstorm = true
		Media.PlayMusic("quake")
	end
	if Light > DarkestLight then
		Light = Light - 0.001
		Trigger.AfterDelay(BrightnessChangeSpeed, function()
			turnOff()
		end)	
	
	else
		Trigger.AfterDelay(NightDuration, function()
			NoturnOn = false
			Thunderstorm = false
			Media.PlayMusic("benzin")
			turnOn()
		end)
	end
end

Thiscolor = HSLColor.New(115, 115, 143)

PlayersWin = function()
	Media.PlaySoundNotification( allplayers, "AlertBuzzer")
	RateOfIncrease = 0.1
	BrightnessChangeSpeed = 3
	BrightestLight = 1.1
	if NoturnOn then
		turnOn()
	end
	
	if Map.LobbyOption("difficulty") == "easy" then
		Media.DisplayMessage("Good job guys you made this on Easy with a Wave interruption of " .. WaveInterval .. " seconds, try Normal next time for a bigger challange.", "Materia", Thiscolor)
	end
	if Map.LobbyOption("difficulty") == "normal" then
		Media.DisplayMessage("Wow well done guys you accomplished this on Normal with a Wave interruption of " .. WaveInterval .. " seconds, not bad but are you prepared for Hard ?", "Materia", Thiscolor)
	end
	if Map.LobbyOption("difficulty") == "hard" then
		if WaveInterval ~= 0 then
			Media.DisplayMessage("I'm really impressed, you made this on hard with a Wave interruption of " .. WaveInterval .. " seconds, reduce the Wave interval for a bigger challange.", "Materia", Thiscolor)
		end
		if WaveInterval == 0 then
			Media.DisplayMessage("What the ... , how did you do this ? i have to add a new level of difficulty for you guys, please upload this replay somewhere oO.", "Materia", Thiscolor)
		end
	end
	Trigger.AfterDelay(DateTime.Seconds(4), function()
		if Multi0 ~= nil then
			Multi0.MarkCompletedObjective(KillEnemysBase0)
		end
		if Multi1 ~= nil then
			Multi1.MarkCompletedObjective(KillEnemysBase1)
		end
		if Multi2 ~= nil then
			Multi2.MarkCompletedObjective(KillEnemysBase2)
		end
		if Multi3 ~= nil then
			Multi3.MarkCompletedObjective(KillEnemysBase3)
		end
		if Multi4 ~= nil then
			Multi4.MarkCompletedObjective(KillEnemysBase4)
		end
	end)
end

DifficultiesCondition = function()
	if Map.LobbyOption("difficulty") == "easy" then
		TimerColor = HSLColor.Red
		Media.PlayMusic("quake")
		Light = 1
		Trigger.AfterDelay(DateTime.Seconds(3), function()
			Media.DisplayMessage("Defend our bases and give your best in destroying the enemys strctures", "Materia", HSLColor.LawnGreen)
			Trigger.AfterDelay(DateTime.Seconds(5), function()
				Media.DisplayMessage("You need no engie to capture the oilderricks just get a unit next to the flag", "Materia", HSLColor.LawnGreen)
				Trigger.AfterDelay(DateTime.Seconds(5), function()
					Media.DisplayMessage("You can build buildings at the flags", "Materia", HSLColor.LawnGreen)
					Trigger.AfterDelay(DateTime.Seconds(5), function()
						Media.DisplayMessage("All superweapon and other chargedurations are halfed\nAllies have the Cobra and Soviets a Nukesub as new techunits", "Materia", HSLColor.LawnGreen)
						Trigger.AfterDelay(DateTime.Seconds(5), function()
							Media.DisplayMessage("Helipad and airfield have a new Attacksquadron, available in the upper left corner", "Materia", HSLColor.LawnGreen)
							Trigger.AfterDelay(DateTime.Seconds(5), function()
								Media.DisplayMessage("Good luck and have fun", "Materia", HSLColor.LawnGreen)
							end)
						end)
					end)
				end)
			end)
		end)
	end

	if Map.LobbyOption("difficulty") == "normal" then
		TimerColor = HSLColor.White
		Media.PlayMusic("doomsgate")
		Light = 0.9
		BrightnessChangeSpeed = 8
		BrightestLight = 1.01
		DarkestLight = 0.75
		DayDuration = 8000
		NightDuration = 3000
		turnOn()
		Trigger.AfterDelay(DateTime.Seconds(3), function()
			Media.DisplayMessage("Commanders defend The Mainbases against the enemy forces.\nBuild engouh defenses to save our base", "Materia", HSLColor.Orange)
		end)
	end
	if Map.LobbyOption("difficulty") == "hard" then
		TimerColor = HSLColor.Gray
		Media.PlayMusic("benzin")
		Light = 0.7
		BrightnessChangeSpeed = 5
		BrightestLight = 0.9
		DarkestLight = 0.5
		DayDuration = 5000
		NightDuration = 5000
		turnOn()
		Trigger.AfterDelay(DateTime.Seconds(3), function()
			Media.DisplayMessage("hf gl ;D", "Materia", HSLColor.Red)
		end)
	end
end



PlayerConquestConditions = function()
	if Multi0 ~= nil then
		KillEnemysBase0 = Multi0.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti0fact = Actor.Create("fact", true, { Location = CPos.New(13,24), Owner = Multi0 })
		Trigger.OnKilled(newMulti0fact, function() Multi0.MarkFailedObjective(KillEnemysBase0) end)
	end
	if Multi1 ~= nil then
		KillEnemysBase1 = Multi1.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti1fact = Actor.Create("fact", true, { Location = CPos.New(13,39), Owner = Multi1 })
		Trigger.OnKilled(newMulti1fact, function() Multi1.MarkFailedObjective(KillEnemysBase1) end)
	end
	if Multi2 ~= nil then
		KillEnemysBase2 = Multi2.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti2fact = Actor.Create("fact", true, { Location = CPos.New(13,50), Owner = Multi2 })
		Trigger.OnKilled(newMulti2fact, function() Multi2.MarkFailedObjective(KillEnemysBase2) end)
	end
	if Multi3 ~= nil then
		KillEnemysBase3 = Multi3.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti3fact = Actor.Create("fact", true, { Location = CPos.New(13,66), Owner = Multi3 })
		Trigger.OnKilled(newMulti3fact, function() Multi3.MarkFailedObjective(KillEnemysBase3) end)
	end
	if Multi4 ~= nil then
		KillEnemysBase4 = Multi4.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti4fact = Actor.Create("fact", true, { Location = CPos.New(13,91), Owner = Multi4 })
		Trigger.OnKilled(newMulti4fact, function() Multi4.MarkFailedObjective(KillEnemysBase4) end)
	end
end

SetupPlayers = function()
	Enemys = Player.GetPlayer("Enemys")
	Neutral = Player.GetPlayer("Neutral")
	Multi0 = Player.GetPlayer("Multi0")
	Multi1 = Player.GetPlayer("Multi1")
	Multi2 = Player.GetPlayer("Multi2")
	Multi3 = Player.GetPlayer("Multi3")
	Multi4 = Player.GetPlayer("Multi4")
	Humans = { Multi0, Multi1, Multi2, Multi3, Multi4 }
end

WorldLoaded = function()
	SetupPlayers()
	StartingUnitsCheck()
	PlayerConquestConditions()
	EnemysBaseMaker()
	EnemyunitsConditions()
	GetandsetFlags()
	DifficultiesCondition()
end

Tick = function()
	UserInterface.SetMissionText("" .. (DestroyedBuildings) .. " / " .. (EnemyBuildingCounter) .. " Enemy buildings destroyed", TimerColor)
	if DestroyedBuildings == EnemyBuildingCounter then
		if not Goodwon then
			Goodwon = true
			PlayersWin()
		end
	end
	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
