
-- attackers from East

ATTACK_DELAY_TOWER2 = 5

createArmyTower2 = function()

	ArmyTower2 = UnlimitedArmy.New({
					Player = 5,
					Area = 3000,
					AutoDestroyIfEmpty = false,
					TransitAttackMove = true,
					Formation = UnlimitedArmy.Formations.Lines,
					LeaderFormation = 4,
					AIActive = true,
					AutoRotateRange = true,
					DoNotNormalizeSpeed = true,
					})
	attackercontroller2 = 0
	ACTIVETOWER1DELAY1 = ATTACK_DELAY_TOWER2

	--	job		
		
		StartJob("SetupArmyTower2")

	end



	
-----------------------------------------------------------------------------------------------------------------------	
--
--	JOB: "SetupArmyTower2"
--
-----------------------------------------------------------------------------------------------------------------------	
	-------------------------------------------------------------------------------------------------------------------
	Condition_SetupArmyTower2 = function()
	-------------------------------------------------------------------------------------------------------------------
		
		return Counter.Tick2("SetupArmyTower2",10)
		
		end

	-------------------------------------------------------------------------------------------------------------------
	Action_SetupArmyTower2 = function()
	-------------------------------------------------------------------------------------------------------------------
		
		if IsDead("tower2a") and IsDead("tower2b") then
		return true
		end
		
		if	ACTIVETOWER1DELAY1 > 0 then
		
		ACTIVETOWER1DELAY1 = ACTIVETOWER1DELAY1 - 1
		
		return false
		
		end
		
		if ACTIVETOWER1DELAY1 == 0 then
		
			if attackercontroller2 == 0 and ArmyTower2:IsDead() and doorsopen == 0 then
		
				for i=1,3,1 do
				ArmyTower2:CreateLeaderForArmy(Entities.PU_LeaderSword3, 8, GetPosition("spawn2"), 0)
				end
				for i=1,3,1 do
				ArmyTower2:CreateLeaderForArmy(Entities.PU_LeaderBow2, 8, GetPosition("spawn2"), 0)
				end
				for i=1,2,1 do
				ArmyTower2:CreateLeaderForArmy(Entities.PV_Cannon2, 0, GetPosition("spawn2"), 0)
				end
				attackercontroller2 = 1
				
				ArmyTower2:AddCommandMove(GetPosition("HQ_Crawford"))
				ArmyTower2:AddCommandWaitForIdle(false)
				
			elseif attackercontroller2 == 0 and ArmyTower2:IsDead() and doorsopen == 1 then
			
				for i=1,3,1 do
				ArmyTower2:CreateLeaderForArmy(Entities.PU_LeaderSword3, 8, GetPosition("spawn2"), 3)
				end
				for i=1,3,1 do
				ArmyTower2:CreateLeaderForArmy(Entities.PU_LeaderBow3, 8, GetPosition("spawn2"), 3)
				end
				for i=1,2,1 do
				ArmyTower2:CreateLeaderForArmy(Entities.PV_Cannon3, 0, GetPosition("spawn2"), 3)
				end
			
				attackercontroller2 = 1
				
				ArmyTower2:AddCommandMove(GetPosition("HQ_Crawford"))
				ArmyTower2:AddCommandWaitForIdle(false)
				
			elseif attackercontroller2 == 1 and ArmyTower2:IsDead() and doorsopen == 0 then
				
				ArmyTower2:ClearCommandQueue()
				
				ACTIVETOWER1DELAY1 = ATTACK_DELAY_TOWER2		
				attackercontroller2 = 0
				
			elseif attackercontroller2 == 1 and ArmyTower2:IsDead() and doorsopen == 1 then
				
				ArmyTower2:ClearCommandQueue()
				
				ACTIVETOWER1DELAY1 = 3		
				attackercontroller2 = 0
			end
		
		end
		
		return false
	end
	