dofile("Scripts/mission.lua");
dofile("Scripts/msl.lua");

function PostCreate()
	mission_lua.BasicMissionInitialize()
	AIparts:AddPeriodic("Siegbedingungen", 10, func_Siegbedingungen, 0 + RandomHalf(10))
	AIparts:AddPeriodic("Prolog", 200, func_Prolog, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Dauerwelle1", 1000, func_Dauerwelle1, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Dauerwelle2", 1000, func_Dauerwelle2, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Init", 10, func_Init, 0 + RandomHalf(10))
	AIparts:AddPeriodic("Event", 10, func_Event, 0 + RandomHalf(10))
	AIparts:AddPeriodic("Level", 10, func_Level, 0 + RandomHalf(10))
	AIparts:AddPeriodic("Bomben", 1000, func_Bomben, 0 + RandomHalf(100))
	AIparts:AddPeriodic("RU_Marineangriff", 10, func_RU_Marineangriff, 0 + RandomHalf(10))
	AIparts:AddPeriodic("Def HQ", 5000, func_Def_HQ, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Panzerjäger", 10, func_Panzerj_ger, 0 + RandomHalf(10))
	AIparts:AddPeriodic("Zonenauslöser", 100, func_Zonenausl_ser, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Tiger", 10000, func_Tiger, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Stadtverteidigung", 100, func_Stadtverteidigung, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Flugplatz", 10, func_Flugplatz, 0 + RandomHalf(10))
	AIparts:AddPeriodic("Panzerproduktion", 30000, func_Panzerproduktion, 0 + RandomHalf(100))
	AIparts:AddPeriodic("Bewegung und abladen", 100, func_Bewegung_und_abladen, 0 + RandomHalf(100))
	msd_vars = {
		Angriffswellen = 0,
		Aufmarsch = 0,
		Bauerhof_Start = 0,
		Bombenziele = 0,
		Bomberanzahl = 0,
		Dauerwelle1 = 0,
		Dauerwelle2 = 0,
		Einheimische = 0,
		HQ_Verstaerkung = 0,
		Kamara1 = 0,
		Nachrichtenschlange = 0,
		Prolog = 0,
		Timer = 0,
	}
end

function func_Siegbedingungen()
	-- Gewonnen
	if IsObjectiveCompleted("Bauer1", "Player") and IsObjectiveCompleted("Bauer3", "Player") and IsObjectiveCompleted("Bauer2", "Player") and IsObjectiveCompleted("Hauptstellung", "Player") and IsObjectiveCompleted("Mühle", "Player") and IsObjectiveCompleted("Bahnhof", "Player") and IsObjectiveCompleted("Industrie", "Player") and IsObjectiveCompleted("Flugplatz", "Player") and IsObjectiveCompleted("Stadt", "Player") then
		PlayerWin("Player")
	end
	if IsEventPresent("Stadt") then
		mission.OutScreenMessage(100035, 15, "0xFF00E000")
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 18*10, function()  PlayerWin("Player") end)
		AIparts:RemovePeriodic("Siegbedingungen")
	end
	-- Bauer1
	-- 
	if NumPlayerUnitsInZone("Enemy", "Bauer1") == 0 and NumPlayerUnitsInZone("Player", "Bauer1") > 0 and IsObjectiveActive("Bauer1") then
		SetObjectiveComplete("Bauer1", "Player")
		SetEvent("Bauer eingenommen")
		AcivateObjective("Bauer4")
		AcivateObjective("Brücke unten")
		AcivateObjective("Stellung Brücke unten")
		DisableObjective("Bauer1")
		MoveGroupToZone("Ru_Welle1", "Bauer1", true, true)
	end
	-- Bauer2
	-- 
	if NumPlayerUnitsInZone("Enemy", "Bauer2") == 0 and NumPlayerUnitsInZone("Player", "Bauer2") > 0 and IsObjectiveActive("Bauer2") then
		SetObjectiveComplete("Bauer2", "Player")
		SetEvent("Bauer eingenommen")
		AcivateObjective("Schuppen")
		AcivateObjective("Kirche")
		AcivateObjective("Bauer4")
		DisableObjective("Bauer2")
		MoveGroupToZone("Ru_welle2", "Bauer2", true, true)
		SetEvent("Level")
	end
	-- Bauer3
	if NumPlayerUnitsInZone("Enemy", "Bauer3") == 0 and NumPlayerUnitsInZone("Player", "Bauer3") > 0 and IsObjectiveActive("Bauer3") then
		SetObjectiveComplete("Bauer3", "")
		SetEvent("Bauer eingenommen")
		AcivateObjective("Bauer4")
		DisableObjective("Bauer3")
		MoveGroupToZone("Ru_welle3", "Bauer4", true, true)
	end
	if NumPlayerUnitsInZone("Enemy", "Bauer4") == 0 and NumPlayerUnitsInZone("Player", "Bauer4") > 0 and IsObjectiveActive("Bauer4") then
		SetObjectiveComplete("Bauer4", "Player")
		SetEvent("Bauer eingenommen")
		AcivateObjective("Bauer5")
		AcivateObjective("Bauer6")
		AcivateObjective("Bauer7")
		AcivateObjective("Brücke mitte")
		DisableObjective("Bauer4")
	end
	if NumPlayerUnitsInZone("Enemy", "Bauer5") == 0 and NumPlayerUnitsInZone("Player", "Bauer5") > 0 and IsObjectiveActive("Bauer5") then
		SetObjectiveComplete("Bauer5", "Player")
		SetEvent("Bauer eingenommen")
		DisableObjective("Bauer5")
	end
	if NumPlayerUnitsInZone("Enemy", "Bauer6") == 0 and NumPlayerUnitsInZone("Player", "Bauer6") > 0 and IsObjectiveActive("Bauer6") then
		SetObjectiveComplete("Bauer6", "Player")
		SetEvent("Bauer eingenommen")
		DisableObjective("Bauer6")
	end
	if NumPlayerUnitsInZone("Enemy", "Bauer7") == 0 and NumPlayerUnitsInZone("Player", "Bauer7") > 0 and IsObjectiveActive("Bauer7") then
		SetObjectiveComplete("Bauer7", "Player")
		SetEvent("Bauer eingenommen")
		SpawnAmmoFuel("ammo_4000.dsc", {"3.Strasse", }, false)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 0*10, function()  RunSpawn("Player", {"DE_Mun", }, "Spawn_00", "Start", "", true, true, {}, false, 20) end)
		DisableObjective("Bauer7")
	end
	if NumPlayerUnitsInZone("Enemy", "Kirche") == 0 and NumPlayerUnitsInZone("Player", "Kirche") > 0 and IsObjectiveActive("Kirche") then
		SetObjectiveComplete("Kirche", "Player")
		DisableObjective("Kirche")
	end
	if NumPlayerUnitsInZone("Enemy", "Schuppen") == 0 and NumPlayerUnitsInZone("Player", "Schuppen") > 0 and IsObjectiveActive("Schuppen") then
		SetObjectiveComplete("Schuppen", "Player")
		SetEvent("Schuppen")
		DisableObjective("Schuppen")
	end
	-- Bahnhof_Zentrum
	if NumPlayerUnitsInZone("Enemy", "Bahnhof") == 0 and NumPlayerUnitsInZone("Player", "Bahnhof") > 5 and IsObjectiveActive("Bahnhof") then
		SetObjectiveComplete("Bahnhof", "Player")
		msd_vars.Bombenziele = 4
		SetEvent("Bahnhof")
		SetEvent("Bomber")
		DisableObjective("Bahnhof")
	end
	-- Hauptstellung HQ
	if NumPlayerUnitsInZoneByType("Enemy", "Stellung_HQ", 0) == 0 and NumPlayerUnitsInZone("Player", "Stellung_HQ") > 5 and IsObjectiveActive("Hauptstellung") then
		SetObjectiveComplete("Hauptstellung", "Player")
		msd_vars.Bombenziele = 3
		SetEvent("Stellung eingenommen")
		SetEvent("HQ eingenommen")
		SetEvent("Bomber")
		DisableObjective("Hauptstellung")
	end
	-- Mühle Stellung
	if NumPlayerUnitsInZoneByType("Enemy", "Stellung_Muehle", 0) == 0 and NumPlayerUnitsInZone("Player", "Stellung_Muehle") > 2 and IsObjectiveActive("Mühle") then
		SetObjectiveComplete("Mühle", "")
		msd_vars.Bombenziele = 3
		SetEvent("Mühle")
		SetEvent("Bomber")
		DisableObjective("Mühle")
	end
	-- Industrie
	if NumPlayerUnitsInZoneByType("Enemy", "Industrie", 0) == 0 and NumPlayerUnitsInZone("Player", "Industrie") > 5 and IsObjectiveActive("Industrie") then
		SetObjectiveComplete("Industrie", "Player")
		SetEvent("Industrie")
		DisableObjective("Industrie")
	end
	if NumPlayerUnitsInZone("Player", "Bridge_mitte") > 0 and IsObjectiveActive("Brücke mitte") and NumPlayerUnitsInZone("Enemy", "Bridge_mitte") == 0 then
		SetObjectiveComplete("Brücke mitte", "Player")
		SetEvent("Stellung eingenommen")
		AcivateObjective("Flugplatz")
		AcivateObjective("Hauptstellung")
		AcivateObjective("Industrie")
		AcivateObjective("Bahnhof")
		AcivateObjective("Bahnhof Ende")
		AcivateObjective("Mühle")
		AcivateObjective("Stadt")
		AcivateObjective("Brücke oben (Flugplatz)")
		DisableObjective("Brücke mitte")
	end
	if NumPlayerUnitsInZone("Player", "Bridge_unten") > 0 and IsObjectiveActive("Brücke unten") and NumPlayerUnitsInZone("Enemy", "Bridge_unten") == 0 then
		SetObjectiveComplete("Brücke unten", "Player")
		SetEvent("Stellung eingenommen")
		SetEvent("Panzerproduktion")
		msd_vars.Bombenziele = 1
		SetEvent("Bomber")
		AcivateObjective("Flugplatz")
		AcivateObjective("Hauptstellung")
		AcivateObjective("Industrie")
		AcivateObjective("Bahnhof")
		AcivateObjective("Bahnhof Ende")
		AcivateObjective("Mühle")
		AcivateObjective("Stadt")
		AcivateObjective("Brücke oben (Flugplatz)")
		DisableObjective("Brücke unten")
	end
	if NumPlayerUnitsInZone("Player", "Bridge_oben") > 0 and IsObjectiveActive("Brücke oben (Flugplatz)") and NumPlayerUnitsInZone("Enemy", "Bridge_oben") == 0 then
		SetObjectiveComplete("Brücke oben (Flugplatz)", "Player")
		SetEvent("Stellung eingenommen")
		DisableObjective("Brücke oben (Flugplatz)")
		msd_vars.Bombenziele = 0
		SetEvent("Bomber")
	end
	if NumPlayerUnitsInZoneByType("Enemy", "SIeg", 0) == 0 and NumPlayerUnitsInZone("Player", "SIeg") > 0 and IsObjectiveActive("Stadt") then
		SetObjectiveComplete("Stadt", "Player")
		SetEvent("Stadt")
		DisableObjective("Stadt")
	end
	if NumPlayerUnitsInZoneByType("Enemy", "Flughafen", 0) == 0 and NumPlayerUnitsInZone("Player", "Flughafen") > 4 and IsObjectiveActive("Flugplatz") then
		SetObjectiveComplete("Flugplatz", "Player")
		SetEvent("Flughafen")
		DisableObjective("Flugplatz")
	end
	if NumPlayerUnitsInZone("Enemy", "Bahnhof_ende") == 0 and NumPlayerUnitsInZone("Player", "Bahnhof_ende") > 0 and IsObjectiveActive("Bahnhof Ende") then
		SetObjectiveComplete("Bahnhof Ende", "Player")
		SetEvent("Stellung eingenommen")
		msd_vars.Bombenziele = 5
		SetEvent("Bomber")
		DisableObjective("Bahnhof Ende")
	end
	if NumPlayerUnitsInZone("Enemy", "Stellung_bridge_unten") == 0 and NumPlayerUnitsInZone("Player", "Stellung_bridge_unten") > 0 and IsObjectiveActive("Bahnhof Ende") and IsObjectiveActive("Stellung Brücke unten") then
		SetObjectiveComplete("Stellung Brücke unten", "Player")
		SetEvent("Stellung eingenommen")
		msd_vars.Bombenziele = 2
		SetEvent("Bomber")
		DisableObjective("Stellung Brücke unten")
	end
end

function func_Prolog()
	if GetGameTime() > 10 and msd_vars.Nachrichtenschlange == 0 then
		mission.OutScreenMessage(100005, 19, "0xFF00E000")
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 50*10, function()  mission.OutScreenMessage(100006, 19, "0xFF00E000") end)
		msd_vars.Nachrichtenschlange = msd_vars.Nachrichtenschlange + 1
	end
	if msd_vars.Nachrichtenschlange == 1 then
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 80*10, function()  mission.OutScreenMessage(100017, 19, "0xFF00E000") end)
		msd_vars.Nachrichtenschlange = msd_vars.Nachrichtenschlange + 2
	end
	-- Tiger
	if msd_vars.Nachrichtenschlange == 3 then
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 120*10, function()  mission.OutScreenMessage(100033, 24, "0xFF00E000") end)
		msd_vars.Nachrichtenschlange = msd_vars.Nachrichtenschlange + 1
	end
	if msd_vars.Nachrichtenschlange == 4 then
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 150*10, function()  mission.OutScreenMessage(100034, 24, "0xFF00E000") end)
		SetEvent("Tiger")
		msd_vars.Nachrichtenschlange = msd_vars.Nachrichtenschlange + 1
	end
	if msd_vars.Nachrichtenschlange == 5 then
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 400*10, function()  mission.OutScreenMessage(100020, 24, "0xFF00E000") end)
		msd_vars.Nachrichtenschlange = msd_vars.Nachrichtenschlange + 1
	end
	if NumPlayerUnitsInZone("Player", "Verstaerkung_De") >= 1 and IsEventPresent("Nachub_erster Kontakt_Strasse1") then
		mission.OutMessage(100025)
		RunSpawn("Player", {"DE_Pz_leicht", }, "Spawn_00", "Verstaerkungen_Deu", "", true, true, {}, false, 30)
		RunSpawn("Player", {"DE_Pz_IVd", }, "Spawn_00", "Verstaerkungen_Deu", "", true, true, {}, false, 30)
		ClearEvent("Nachub_erster Kontakt_Strasse1")
	end
end

function func_Dauerwelle1()
	if IsEventPresent("Bauer eingenommen") and msd_vars.Dauerwelle1 < 3 then
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 5*10, function()  RunSpawn("Enemy", {"RU_inf_Marine", }, "Spawn_02", "RU_Dauerwelle1", "", true, true, {}, true, 20) end)
		MoveGroupToZone("RU_Dauerwelle1", "Bauer4", true, false)
		msd_vars.Dauerwelle1 = msd_vars.Dauerwelle1 + 1
	end
	if GroupSeeEnemyNow("RU_Dauerwelle1") then
		GroupSetMicroAIBehaviour("RU_Dauerwelle1", "Cautious")
		SetGroupBehaviour("RU_Dauerwelle1", false, true, true, true, nil, true, true, true, true, nil)
		GroupAttackPlace("RU_Dauerwelle1", "Ende 2. Strasse", 50)
	end
	if NumPlayerUnitsInZone("Player", "Bauer7") > 0 then
		AIparts:RemovePeriodic("Dauerwelle1")
	end
end

function func_Dauerwelle2()
	if IsEventPresent("Schuppen") and msd_vars.Dauerwelle2 < 3 then
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 5*10, function()  RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_02", "RU_Dauerwelle2", "", true, true, {}, true, 20) end)
		MoveGroupToZone("RU_Dauerwelle2", "Bauer1", true, false)
		msd_vars.Dauerwelle2 = msd_vars.Dauerwelle2 + 1
	end
	if GroupSeeEnemyNow("RU_Dauerwelle2") then
		SetGroupBehaviour("RU_Dauerwelle2", false, true, true, true, false, true, true, true, true, false)
		GroupSetMicroAIBehaviour("RU_Dauerwelle2", "Cautious")
		GroupAttackPlace("RU_Dauerwelle2", "Russe_Strasse2", 50)
	end
	if NumPlayerUnitsInZone("Player", "Bauer7") > 0 then
		AIparts:RemovePeriodic("Dauerwelle2")
	end
	
end

function func_Init()
	if GetGameTime() > 0 then
		SetEvent("Nachub_erster Kontakt_Strasse1")
		SetEvent("Zone_Muehle_1")
		SetEvent("Zone_Muehle_2")
		SetEvent("Zone_Muehle_3")
		AddBonus(1, 2, 4, -1, -1)
		DisableObjective("Bahnhof Ende")
		DisableObjective("Bahnhof")
		DisableObjective("Brücke oben (Flugplatz)")
		DisableObjective("Brücke mitte")
		DisableObjective("Brücke unten")
		DisableObjective("Flugplatz")
		DisableObjective("Hauptstellung")
		DisableObjective("Mühle")
		DisableObjective("Industrie")
		DisableObjective("Stadt")
		DisableObjective("Kirche")
		DisableObjective("Schuppen")
		DisableObjective("Bauer7")
		DisableObjective("Bauer6")
		DisableObjective("Bauer5")
		DisableObjective("Bauer4")
		-- aktiv
		AcivateObjective("Bauer1")
		AcivateObjective("Bauer2")
		AcivateObjective("Bauer3")
		AIparts:RemovePeriodic("Init")
	end
end

function func_Event()
	if GetClearEvent("Bauer eingenommen") then
		RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_inf_leicht", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		mission.OutMessage(100007)
	end
	-- Bahnhof
	if GetClearEvent("Bahnhof") then
		RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Mun", }, "Spawn_02", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Pz_IVd", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Pz_III G", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_leicht", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		mission.OutMessage(100002)
	end
	-- Flugplatz eingenommen
	if GetClearEvent("Flughafen") then
		RunSpawn("Player", {"DE_Mun", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AddBonus(1, 2, 4, 100015, -1)
		mission.OutMessage(100008)
	end
	-- Kirche einheimische
	-- init Marineangriff
	if GetClearEvent("Schuppen") then
		SpawnAmmoFuel("fuel_2200.dsc", {"Schuppen", }, false)
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		RunSpawn("Player", {"DE_Flak", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Mun", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		MoveGroupToZone("Ru_Welle1", "Bauer4", true, false)
	end
	if GetClearEvent("Industrie") then
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, true, 30)
		RunSpawn("Player", {"DE_Flak", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_inf_leicht", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		RunSpawn("Player", {"DE_Pz_leicht", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		RunSpawn("Player", {"DE_Mun", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_leicht", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_leicht", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		ClearEvent("Panzerproduktion")
	end
	if GetClearEvent("Mühle") then
		SpawnAmmoFuel("ammo_4000.dsc", {"Mühle", }, false)
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		RunSpawn("Player", {"DE_Flak", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_inf_leicht", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_88", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		RunSpawn("Player", {"DE_Pz_IVd", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Pz_IVd", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Pz_III G", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
	end
	if GetClearEvent("Stellung eingenommen") then
		RunSpawn("Player", {"DE_Flak", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		RunSpawn("Player", {"DE_inf_leicht", }, "Spawn_00", "Start", "", true, true, {}, true, 5)
		RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 500*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		RunSpawn("Player", {"DE_Pz_III G", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Pz_IVd", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
		RunSpawn("Player", {"DE_Pz_III G", }, "Spawn_00", "Start", "", true, true, {}, false, 5)
	end
	if IsEventPresent("Tiger") then
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 200*10, function()  RunSpawn("Player", {"DE_Tiger", }, "Spawn_00", "DE_Tiger", "", true, true, {}, true, 5) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 300*10, function()  RunSpawn("Player", {"DE_Tiger", }, "Spawn_00", "DE_Tiger", "", true, true, {}, true, 5) end)
		ClearEvent("Tiger")
	end
end

function func_Level()
	if IsDifficultyLevel("easy") and IsEventPresent("Level") then
		RunSpawn("Player", {"DE_Pz_Sturmgeschütz", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Haubitze", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Pz_III J", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Pz_III G", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Pz_IVd", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_88", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_88", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Pz_hummel", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 10*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 20*10, function()  RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:RemovePeriodic("Level")
	end
	if IsDifficultyLevel("regular") and IsEventPresent("Level") then
		RunSpawn("Player", {"DE_Pz_Sturmgeschütz", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Haubitze", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Pz_IVd", }, "Spawn_00", "Start", "", true, true, {}, true, 10)
		RunSpawn("Player", {"DE_88", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 10*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 20*10, function()  RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:RemovePeriodic("Level")
	end
	if IsDifficultyLevel("hardcore") and IsEventPresent("Level") then
		RunSpawn("Player", {"DE_PAK_schwer", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		RunSpawn("Player", {"DE_Mechaniker", }, "Spawn_00", "Start", "", true, true, {}, true, 1)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 10*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:AddOneTime(AIparts:GetUniqueId("TIMER_DO_"), 20*10, function()  RunSpawn("Player", {"DE_inf_Schwer", }, "Spawn_00", "Start", "", true, true, {}, false, 0) end)
		AIparts:RemovePeriodic("Level")
	end
end

function func_Bomben()
	if GetClearEvent("Flughafen") then
		AddBonus(1, 2, 4, 100015, -1)
		mission.OutMessage(100024)
		AIparts:RemovePeriodic("Bomben")
	end
	if IsObjectiveActive("Flugplatz") and IsEventPresent("Bomber") and msd_vars.Bombenziele == 0 then
		SetPlaneDesc("ussr", "bomber", "ussr/tu_2.dsc")
		SetPlaneSide(2, "S")
		SendPlane("Enemy", "DE_Aufmarschgebiet", "bomber", "N", 300, -1, "")
		msd_vars.Bombenziele = 9
		ClearEvent("Bomber")
	end
	if IsObjectiveActive("Flugplatz") and IsEventPresent("Bomber") and msd_vars.Bombenziele == 1 then
		SetPlaneDesc("ussr", "bomber", "ussr/tu_2.dsc")
		SetPlaneSide(2, "S")
		msd_vars.Bombenziele = 9
		SendPlane("Enemy", "Ende 2. Strasse", "bomber", "N", 300, -1, "")
		ClearEvent("Bomber")
	end
	if IsObjectiveActive("Flugplatz") and IsEventPresent("Bomber") and msd_vars.Bombenziele == 2 then
		SetPlaneDesc("ussr", "bomber", "ussr/tu_2.dsc")
		SetPlaneSide(2, "S")
		SendPlane("Enemy", "Mühle_Kreuzung_west", "bomber", "N", 300, -1, "")
		msd_vars.Bombenziele = 9
		SendPlane("Enemy", "Mühle_kreuzung_ost", "bomber", "N", 300, -1, "")
		ClearEvent("Bomber")
	end
	if IsObjectiveActive("Flugplatz") and IsEventPresent("Bomber") and msd_vars.Bombenziele == 3 then
		SetPlaneDesc("ussr", "bomber", "ussr/tu_2.dsc")
		SetPlaneSide(2, "S")
		SendPlane("Enemy", "Brücke unten West_kreuzung", "bomber", "N", 300, -1, "")
		msd_vars.Bombenziele = 9
		SendPlane("Enemy", "Brücke unten Ost_kreuzung", "bomber", "N", 300, -1, "")
		ClearEvent("Bomber")
	end
	if IsObjectiveActive("Flugplatz") and IsEventPresent("Bomber") and msd_vars.Bombenziele == 4 then
		SetPlaneDesc("ussr", "bomber", "ussr/tu_2.dsc")
		SetPlaneSide(2, "S")
		SendPlane("Enemy", "Bahnhof_Stellung_Süd", "bomber", "N", 300, -1, "")
		msd_vars.Bombenziele = 9
		ClearEvent("Bomber")
	end
	if IsObjectiveActive("Flugplatz") and IsEventPresent("Bomber") and msd_vars.Bombenziele == 5 then
		SetPlaneDesc("ussr", "bomber", "ussr/tu_2.dsc")
		SetPlaneSide(2, "S")
		SendPlane("Enemy", "Bombe_vor_stadt", "bomber", "N", 300, -1, "")
		SendPlane("Enemy", "bahnhof_Stellung_west", "bomber", "N", 500, -1, "")
		msd_vars.Bombenziele = 9
		ClearEvent("Bomber")
	end
	if IsObjectiveActive("Flugplatz") and IsEventPresent("Bomber") and msd_vars.Bombenziele == 6 then
		SetPlaneDesc("ussr", "bomber", "ussr/tu_2.dsc")
		SetPlaneSide(2, "S")
		SendPlane("Enemy", "Bombe_vor_stadt", "bomber", "N", 300, -1, "")
		SendPlane("Enemy", "Bombe vor Bahnhof Nord", "bomber", "N", 500, -1, "")
		msd_vars.Bombenziele = 9
		ClearEvent("Bomber")
	end
end

function func_RU_Marineangriff()
	if NumPlayerUnitsInZone("Player", "Bridge_unten") > 0 then
		SetEvent("Brücke_unten_wird_überquert")
	end
	if NumPlayerUnitsInZone("Player", "Bridge_mitte") > 0 then
		SetEvent("Brücke_mitte_wird_überquert")
	end
	if IsEventPresent("Brücke_unten_wird_überquert") and msd_vars.Angriffswellen < 6 then
		RunSpawn("Enemy", {"RU_inf_Marine", }, "Spawn_02", "Ru_Marine_Nachschub_unten", "", true, true, {}, true, 20)
		RunSpawn("Enemy", {"RU_Pz_leicht", }, "Spawn_02", "Ru_Marine_Nachschub_unten", "", true, true, {}, true, 20)
		msd_vars.Angriffswellen = msd_vars.Angriffswellen + 1
		ClearEvent("Brücke_unten_wird_überquert")
		SetGroupBehaviour("RUS_ari_schwer", nil, nil, nil, nil, nil, true, true, true, true, true)
		GroupSetMicroAIBehaviour("RUS_ari_schwer", "Agressive")
	end
	if IsEventPresent("Brücke_mitte_wird_überquert") and msd_vars.Angriffswellen < 10 then
		RunSpawn("Enemy", {"RU_inf_Marine", }, "Spawn_07", "Ru_Marine_Nachschub_mitte", "", true, true, {}, true, 20)
		msd_vars.Angriffswellen = msd_vars.Angriffswellen + 1
		SetGroupBehaviour("RUS_ari_schwer", nil, nil, nil, nil, nil, true, true, true, true, true)
		ClearEvent("Brücke_mitte_wird_überquert")
	end
	if NumGroupUnits("Ru_Marine_Nachschub_unten", 0, true, true, false) > 0 then
		MoveGroupToZone("Ru_Marine_Nachschub_unten", "Bauer1", true, true)
	end
	if NumGroupUnits("Ru_Marine_Nachschub_mitte", 0, true, true, false) > 0 then
		MoveGroupToZone("Ru_Marine_Nachschub_unten", "Bauer7", true, true)
	end
end

function func_Def_HQ()
	if NumPlayerUnitsInZone("Enemy", "HQ_Front") == 0 and IsObjectiveActive("Hauptstellung") and IsObjectiveActive("Bahnhof") then
		RunSpawn("Enemy", {"RU_Pak_leicht", }, "Spawn_03", "Ru_HQ_Nachschub", "", true, true, {}, false, 0)
		msd_vars.HQ_Verstaerkung = msd_vars.HQ_Verstaerkung + 1
	end
	if NumGroupUnits("Ru_HQ_Nachschub", 0, false, false, false) > 0 then
		MoveGroupToZone("Ru_HQ_Nachschub", "HQ_Front", true, false)
	end
	if NumGroupUnitsInZone("Ru_HQ_Nachschub", "Stellung_HQ") > 0 then
		TransferUnits("Ru_HQ_Nachschub", 0, "RU_HQ_Def", 0)
	end
	if GroupSeeEnemyNow("RU_HQ_Def") then
		SetGroupBehaviour("RU_HQ_Def", false, true, true, true, false, false, false, true, nil, nil)
	end
	if msd_vars.HQ_Verstaerkung == 5 then
		AIparts:RemovePeriodic("Def HQ")
	end
end

function func_Panzerj_ger()
	if IsEventPresent("Bauer eingenommen") then
		RunSpawn("Enemy", {"RU_Halftrack", }, "Spawn_02", "Group0", "", true, true, {}, false, 0)
		RunSpawn("Enemy", {"RU_Halftrack", }, "Spawn_00", "Group0", "", true, true, {}, false, 0)
	end
	if NumGroupUnits("Group0", 0, true, true, false) > 0 then
		MoveGroupToZone("Group0", "Verstaerkung_De", true, false)
		SetGroupBehaviour("Group0", false, true, true, true, false, false, false, true, false, false)
	end
	if GroupSeeEnemyNow("Group0") then
		UnloadTransports("Group0")
	end
end

function func_Zonenausl_ser()
	if NumPlayerUnitsInZone("Player", "Muehle_1") > 0 and GetClearEvent("Zone_Muehle_1") then
		RunSpawn("Enemy", {"RU_inf_schwer", }, "Spawn_03", "Russ_Muehle_Neu", "", true, true, {}, false, 0)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_03", "Russ_Muehle_Neu", "", true, true, {}, false, 0)
		MoveGroupToZone("Russ_Muehle_Neu", "RU_verstrkung_muehle", true, false)
	end
	if NumGroupUnits("Russ_Muehle_Neu", 0, false, false, false) > 0 and NumGroupUnitsInZone("Russ_Muehle_Neu", "RU_verstrkung_muehle") > 3 then
		MoveGroupToZone("Russ_Muehle_Neu", "Muehle_1", true, false)
	end
	if NumPlayerUnitsInZone("Enemy", "Muehle_1") > 0 then
		SetEvent("Zone_Muehle_1")
	end
	if NumPlayerUnitsInZone("Player", "Muehle_2") > 0 and GetClearEvent("Zone_Muehle_2") then
		RunSpawn("Enemy", {"RU_inf_schwer", }, "Spawn_03", "Russ_Muehle_Neu2", "", true, true, {}, false, 0)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_03", "Russ_Muehle_Neu2", "", true, true, {}, false, 0)
		RunSpawn("Enemy", {"RU_Pz_schwer", }, "Spawn_03", "Russ_Muehle_Neu2", "", true, true, {}, false, 0)
		MoveGroupToZone("Russ_Muehle_Neu2", "Muehle_2", true, false)
	end
	if NumGroupUnits("Russ_Muehle_Neu2", 0, false, false, false) > 0 and NumGroupUnitsInZone("Russ_Muehle_Neu2", "RU_verstrkung_muehle") > 3 then
		MoveGroupToZone("Russ_Muehle_Neu2", "Muehle_2", true, false)
	end
	if NumPlayerUnitsInZone("Enemy", "Muehle_2") > 0 then
		SetEvent("Zone_Muehle_2")
	end
	if NumPlayerUnitsInZone("Player", "Muehle_3") > 0 and GetClearEvent("Zone_Muehle_3") then
		RunSpawn("Enemy", {"RU_inf_schwer", }, "Spawn_03", "Russ_Muehle_Neu3", "", true, true, {}, false, 0)
		RunSpawn("Enemy", {"RU_Halftrack", }, "Spawn_03", "Russ_Muehle_Neu3", "", true, true, {}, false, 0)
		MoveGroupToZone("Russ_Muehle_Neu3", "RU_verstrkung_muehle", true, false)
	end
	if NumGroupUnits("Russ_Muehle_Neu3", 0, false, false, false) > 0 and NumGroupUnitsInZone("Russ_Muehle_Neu3", "RU_verstrkung_muehle") > 3 then
		MoveGroupToZone("Russ_Muehle_Neu3", "Muehle_3", true, false)
	end
	if NumPlayerUnitsInZone("Enemy", "Muehle_3") > 0 then
		SetEvent("Zone_Muehle_3")
	end
end

function func_Tiger()
	if GetGameTime() < 0 then
		RunSpawn("Player", {"DE_Tiger", }, "Spawn_00", "Start", "", true, true, {}, false, 10)
	end
end

function func_Stadtverteidigung()
	if NumPlayerUnitsInZone("Player", "Bahnhof_ende") > 0 and NumGroupUnits("Stadt_Graben", 0, false, false, false) == 0 and IsObjectiveActive("Flugplatz") then
		RunSpawn("Enemy", {"RU_Pz_schwer", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 10)
		RunSpawn("Enemy", {"RU_Pz_leicht", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 10)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 30)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 40)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 50)
		RunSpawn("Enemy", {"RU_inf_schwer", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 60)
		msd_vars.Bombenziele = 5
		SetEvent("Bomber")
	end
	if NumPlayerUnitsInZone("Player", "Stadt") > 0 and NumGroupUnits("Stadt_Haeuser", 0, false, false, false) == 0 and IsObjectiveActive("Flugplatz") then
		RunSpawn("Enemy", {"RU_Pz_schwer", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 10)
		RunSpawn("Enemy", {"RU_Pz_leicht", }, "Spawn_05", "Stadt_Graben", "", true, true, {}, false, 10)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Haeuser", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Haeuser", "", true, true, {}, false, 30)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Haeuser", "", true, true, {}, false, 40)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_05", "Stadt_Haeuser", "", true, true, {}, false, 50)
		RunSpawn("Enemy", {"RU_inf_schwer", }, "Spawn_05", "Stadt_Haeuser", "", true, true, {}, false, 60)
		msd_vars.Bombenziele = 6
		SetEvent("Bomber")
	end
end

function func_Flugplatz()
	if NumGroupUnits("Rus_Verteidiung_Flugplatz", 0, false, false, false) < 2 then
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_07", "", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_Pz_leicht", }, "Spawn_07", "", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_07", "", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_inf_schwer", }, "Spawn_07", "", "", true, true, {}, false, 20)
	end
end

function func_Panzerproduktion()
	if IsEventPresent("Panzerproduktion") then
		RunSpawn("Enemy", {"RU_Pz_schwer", }, "Spawn_06", "Russ_Panzerproduktion", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_Pz_leicht", }, "Spawn_06", "Russ_Panzerproduktion", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_06", "Russ_Panzerproduktion", "", true, true, {}, false, 20)
		RunSpawn("Enemy", {"RU_inf_leicht", }, "Spawn_06", "Russ_Panzerproduktion", "", true, true, {}, false, 20)
		MoveGroupToZone("Russ_Panzerproduktion", "Bahnhof", true, true)
	end
	if IsEventPresent("Panzerproduktion") and NumGroupUnitsInZone("Russ_Panzerproduktion", "Bahnhof") > 50 then
		TransferUnits("Russ_Panzerproduktion", 0, "RUSS_Panzerproduktion_Bahnhof", 0)
		MoveGroupToZone("RUSS_Panzerproduktion_Bahnhof", "Kirche", true, false)
	end
	if IsEventPresent("Panzerproduktion") and NumGroupUnitsInZone("RUSS_Panzerproduktion_Bahnhof", "Kirche") > 50 then
		TransferUnits("RUSS_Panzerproduktion_Bahnhof", 0, "RUSS_Panzerproduktion_Stadt", 0)
		MoveGroupToZone("RUSS_Panzerproduktion_Stadt", "Verstaerkung_DE_Strasse2", true, true)
	end
end

function func_Bewegung_und_abladen()
	if GroupSeeEnemyNow("Ru_Marine_Nachschub_mitte") then
		UnloadTransports("Ru_Marine_Nachschub_mitte")
	end
	if GroupSeeEnemyNow("Ru_Marine_Nachschub_unten") then
		UnloadTransports("Ru_Marine_Nachschub_unten")
	end
	if NumGroupUnits("Russ_Panzerproduktion", 0, false, false, false) > 0 then
		MoveGroupToZone("Russ_Panzerproduktion", "Schlosserei", true, false)
	end
	if NumGroupUnits("RUSS_Panzerproduktion_Bahnhof", 0, false, false, false) > 0 then
		MoveGroupToZone("RUSS_Panzerproduktion_Bahnhof", "Bahnhof", true, false)
	end
	if NumGroupUnits("RUSS_Panzerproduktion_Stadt", 0, false, false, false) > 0 then
		MoveGroupToZone("RUSS_Panzerproduktion_Stadt", "Stadt", true, false)
	end
end

