includefilename = "asset\\composition\\AIScript\\LordAICommon.lua"
includefilename = SYSTEM.RelativeToAbsolutePath( includefilename )
dofile( includefilename )
includefilename = "asset\\composition\\AIScript\\test_helper.lua"
includefilename = SYSTEM.RelativeToAbsolutePath( includefilename )
dofile( includefilename )
--******************************************************************
-- Normal                                                           
--******************************************************************





function Patrol_Enter_Wander( AILUATable )
	AILUATable.Check = "wander"
	AILUATable.State = "wander"
	AILUATable.RandomTowerIndex = 0
	ARMY.SetBehavior(AILUATable.myArmyID, "Wander")
end

function Patrol_Wander_Update( AILUATable )
	-- check to see if we need to init wander
	if AILUATable.State == "wander"  then
		-- nothing
	else
		Patrol_Enter_Wander( AILUATable )
	end

	-- 
	if AILUATable.RandomTowerIndex < 5  then
		AILUATable.RandomTowerIndex= AILUATable.RandomTowerIndex +1
	else
		AILUATable.RandomTowerIndex = 0
		local EnemyID = ARMY.GetInRangeID( AILUATable.myArmyID, "VISIBLE_ENEMY_ARMY", 1200 )
	
		if (EnemyID == -1)  then
			-- nothing
		else
			-- break out
			 Patrol_Enter_Attack( AILUATable )
		end
	end	

end



function Patrol_Enter_Attack( AILUATable )
	AILUATable.Check = "fight"
	AILUATable.State = "fight"
	AILUATable.RandomTowerIndex = 0
	AttackEnemy( EnemyID, AILUATable )
end


function Patrol_Attack_Update( AILUATable )
	-- check to see if we need to init attack
	if AILUATable.State == "fight" then
		--nothing
	else
		Patrol_Enter_Attack( AILUATable )
	end

	-- 
	if AILUATable.RandomTowerIndex < 5  then
		AILUATable.RandomTowerIndex = AILUATable.RandomTowerIndex +1
	else
		AILUATable.RandomTowerIndex = 0
		local EnemyID = ARMY.GetInRangeID( AILUATable.myArmyID, "VISIBLE_ENEMY_ARMY", 2500 )
	
		if (EnemyID == -1) then
			-- break out
			Patrol_Enter_Wander( AILUATable )
		end
	end

end

--******************************************************************
-- General                                                          
--******************************************************************
function Patrol_AI_Init( AILUATable )
	AILUATable.State = "normal"
	AILUATable.Check = "init"
	AILUATable.RandomTowerIndex = 0
end

function Patrol_AI_Update( AILUATable )
	if( AILUATable.State == "normal" ) then
		local EnemyID = ARMY.GetInRangeID( AILUATable.myArmyID, "VISIBLE_ENEMY_ARMY", 800 )
		
		if EnemyID == -1  then
			Patrol_Wander_Update( AILUATable )
		else	
			Patrol_Attack_Update( AILUATable )
		end
		return
	end		

	if AILUATable.State == "wander" then
		Patrol_Wander_Update( AILUATable )
	elseif  AILUATable.State == "fight" then
		Patrol_Attack_Update( AILUATable )
	end
end