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 tower_crazy_Enter_Normal( AILUATable )
	AILUATable.State = "normal"
end

function tower_crazy_Avoid( AILUATable )
	AILUATable.Check = "tower_crazy"
	local EnemyID = ARMY.GetInRangeID( AILUATable.myArmyID, "VISIBLE_ENEMY_ARMY", 4000 )
	if EnemyID == -1 then
		tower_crazy_Check_Tower( AILUATable )
		return 1
	end
	local EnemyDif = GetEnemyDif( EnemyID, AILUATable )
	local MyShape = GetLordShape( AILUATable.myArmyID )
	local EnemyShape = GetLordShape( EnemyID )
	if EnemyDif < 500 and ( not GAMERULE.IsShapeStronger( MyShape, EnemyShape ) ) and ARMY.IsCanUseSpell( AILUATable.myArmyID ) then
		ARMY.UseSpecialAbility( AILUATable.myArmyID )
	else
		tower_crazy_Check_Tower( AILUATable )
	end
end

function tower_crazy_Check_Tower( AILUATable )
	AILUATable.Check = "tower"
	local TowerID = GetClosestTowerID( AILUATable )
	if TowerID == -1 then
		tower_crazy_Wander( AILUATable )
		return 1
	end
	CaptureTower( TowerID, AILUATable )
end

function tower_crazy_Wander( AILUATable )
	AILUATable.Check = "wander"
	local x, y = MAP.GetRandomPosition( )
	WalkTo( x, y, AILUATable )
end

function tower_crazy_Update_Normal( AILUATable )
	tower_crazy_Avoid( AILUATable )
end
--******************************************************************
-- General                                                          
--******************************************************************
function tower_crazy_AI_Init( AILUATable )
	AILUATable.RandomTowerIndex = 0
	AILUATable.State = "normal"
	AILUATable.Check = "init"
	AILUATable.g_EnemyShape = 0
	AILUATable.g_MyShape = 0
end

function tower_crazy_AI_Update( AILUATable )
	DEBUG.ShowMessage( AILUATable.myArmyID, AILUATable.Check )
	if AILUATable.State == "normal" then
		tower_crazy_Update_Normal( AILUATable )
	end
end
