includefilename = "asset\\composition\\AIScript\\LordAICommon.lua" 
includefilename = SYSTEM.RelativeToAbsolutePath(includefilename)
dofile(includefilename)

function Watch_Then_Fight_AI_Init ()
--WANDER.AddGoalPoint(myArmyID, 1000, 1000, 0)
--WANDER.AddGoalPoint(myArmyID, 1000, -1000, 0)
--WANDER.AddGoalPoint(myArmyID, -1000, -1000, 0)
--WANDER.AddGoalPoint(myArmyID, -1000, 1000, 0)
  startWatching_MoveTowardsArmyRange = 1600
  stopWatching_MoveTowardsArmyRange = 1500
  
  Watch_Then_Fight_Enter_Watch()
end


--------------------------------------------------------------------------------------
------------------------------ start Watch state ------------------------------------
--------------------------------------------------------------------------------------

function Watch_Then_Fight_Enter_Watch ()
  STATE = "Watch"
  
  local EnemyID = ARMY.GetInRangeID(myArmyID, "VISIBLE_CAN_ATTACK_ARMY", 100000)
  Watch_Army = EnemyID
  hasStoppedApproachingEnemy = false
  
  ARMY.SetBehavior(myArmyID, "WalkTo")
end

function Watch_Then_Fight_Update_Watch ()
  local Enemy_PositionX, Enemy_PositionY = ARMY.GetPosition(Watch_Army)
  local Now_PositionX, Now_PositionY = ARMY.GetPosition(myArmyID)
  local DistanceFromOrigin = MAP.GetDistanceBetweenTwoPosition(Enemy_PositionX, Enemy_PositionY, Now_PositionX, Now_PositionY)
      
  if DistanceFromOrigin < stopWatching_MoveTowardsArmyRange then
    if not hasStoppedApproaching then
      --already very close, stop approaching
      ARMY.SetGoalPosition(myArmyID, Now_PositionX, Now_PositionY)
      hasStoppedApproaching = true
    end
  elseif DistanceFromOrigin > startWatching_MoveTowardsArmyRange then
      --keep approaching
      ARMY.SetGoalPosition(myArmyID, Enemy_PositionX, Enemy_PositionY)
      hasStoppedApproaching = false
  end
end

function Watch_Then_Fight_Exit_Watch ()

end

--------------------------------------------------------------------------------------
-------------------------------- end Watch state ------------------------------------
--------------------------------------------------------------------------------------

function Watch_Then_Fight_AI_Update ()
  if STATE == "Watch" then
    Watch_Then_Fight_Update_Watch()
  end
end
