createArmyDefendDen = function()
	--UA mit wechselndem Spawn, je nachdem wie weit spieler ist.
	Logic.SetTechnologyState(5,Technologies.T_SuperTechnology,3)
	DarkCastleDefUA = UnlimitedArmy:New({
					Player = 5,
					Area = 5000,
					AutoDestroyIfEmpty = true,
					TransitAttackMove = true,
					Formation = UnlimitedArmy.Formations.Chaotic,
					LeaderFormation = FormationFunktion,
					AIActive = true,
					AutoRotateRange = true,
					DoNotNormalizeSpeed = true,
					})
	local spawnpos = {}
	spawnpos[1] = GetPosition("innerFestungSpawn1")
	spawnpos[1].Generator = "innerFestungSpawnTurm1"
	spawnpos[2] = GetPosition("innerFestungSpawn2")
	spawnpos[2].Generator = "innerFestungSpawnTurm2"
	spawnpos[3] = GetPosition("innerFestungSpawn3")
	spawnpos[3].Generator = "innerFestungSpawnTurm3"
	spawnpos[4] = GetPosition("innerFestungSpawn4")
	spawnpos[4].Generator = "innerFestungSpawnTurm4"
	spawnpos[5] = GetPosition("innerFestungSpawn5")
	spawnpos[5].Generator = "innerFestungSpawnTurm5"
	spawnpos[6] = GetPosition("defend1")
	spawnpos[6].Generator = "lionsDen"
	DarkCastleDefUASpawnGenerator = UnlimitedArmySpawnGenerator:New(DarkCastleDefUA,{
									Position = spawnpos,
									ArmySize = 40,
									SpawnCounter = 20,
									SpawnLeaders = 25,
									LeaderDesc = {
										{LeaderType = Entities.PU_LeaderSword1, SoldierNum = 0, SpawnNum = function(self) for swordsoldierID in DarkCastleDefUA:Iterator(true) do if Logic.GetEntityType(swordsoldierID) == 200 then return 0 end end return 1 end, Looped = true, Experience = 3},
										{LeaderType = Entities.PU_LeaderSword4, SoldierNum = 8, SpawnNum = 4, Looped = true, Experience = 3},
										{LeaderType = Entities.PU_LeaderHeavyCavalry2, SoldierNum = 3, SpawnNum = 4, Looped = true, Experience = 3},
										{LeaderType = Entities.PU_LeaderBow4, SoldierNum = 8, SpawnNum = 6, Looped = true, Experience = 3},
										{LeaderType = Entities.PV_Cannon4, SoldierNum = 0, SpawnNum = 4, Looped = true, Experience = 3},
										{LeaderType = Entities.PU_LeaderPoleArm4, SoldierNum = 8, SpawnNum = 5, Looped = true, Experience = 3},
										{LeaderType = Entities.PU_LeaderCavalry2, SoldierNum = 3, SpawnNum = 5, Looped = true, Experience = 3}
										}
										})
	DarkCastleDefUA.armychecktable = {}
	Trigger.RequestTrigger(Events.LOGIC_EVENT_EVERY_SECOND,nil,"Check_ArmySoldiers",1,nil,{DarkCastleDefUA})
	DarkCastleDefUA.OldSpawnGenerator = DarkCastleDefUASpawnGenerator.Pos[1].Generator
	DarkCastleDefUA:AddCommandLuaFunc(KerberosDefArmyFunc,true)
end

function KerberosDefArmyFunc(self)
	if self.Spawner then
		if self.OldSpawnGenerator ~= self.Spawner.Pos[1].Generator then
			self.OldSpawnGenerator = self.Spawner.Pos[1].Generator
			self.Spawner.CCounter = 1
			return true, UnlimitedArmy.CreateCommandMove(PunktMoveDecider(self))
		end
		if self:GetSize(true,false) == 0 then
			--return true, UnlimitedArmy.CreateCommandMove({X=self.Spawner.Pos[1].X,Y=self.Spawner.Pos[1].Y})
			return true, UnlimitedArmy.CreateCommandMove(PunktMoveDecider(self))
		end
		if self:IsIdle() then
			return true, UnlimitedArmy.CreateCommandMove(PunktMoveDecider(self))	
		end
	end
	return false
end

function PunktMoveDecider(self)
	if self.Spawner.Pos[1].Generator == "innerFestungSpawnTurm1" then
		return GetPosition("defend4")
	elseif self.Spawner.Pos[1].Generator == "innerFestungSpawnTurm2" then
		if self.Area ~= 5000 then
			self.Area = 5000
		end
		return GetPosition("defend5")
	elseif self.Spawner.Pos[1].Generator == "innerFestungSpawnTurm3" then	
		if self.Area ~= 5000 then
			self.Area = 5000
		end
		return GetPosition("defend4")
	elseif self.Spawner.Pos[1].Generator == "innerFestungSpawnTurm4" then
		if self.Area ~= 5000 then
			self.Area = 5000
		end
		return GetPosition("innerFestungSpawn3")
	elseif self.Spawner.Pos[1].Generator == "innerFestungSpawnTurm5" then
		if self.Area ~= 5000 then
			self.Area = 5000
		end
		return GetPosition("defendabc")
	elseif self.Spawner.Pos[1].Generator == "lionsDen" then
		if self.Area ~= 5500 then
			self.Area = 5500
		end
		return GetPosition("defend1")
	end
end