include("../scripts/ai/include/basic.lua")

-- Required control rate.
control_rate = 0.5

function control()
  local task = ai.taskname()

  if task == "none" then
    local enemy = ai.getenemy()

  if enemey ~= 0 then
   ai.pushtask(0, "attack", enemy)
  else
    ai.pushtask(0, "hyperspace")
  end
  elseif task == "hyperspace" then
    ai.hyperspace()
  else
    attack_closestenemy()
 end
end

-- Required "attacked" function.
function attacked(attacker)
 task = ai.taskname()
 if task ~= "attack" then
  -- Now pilot fights back.
  ai.pushtask(0, "attack", attacker)
 
 elseif task == "attack" then
  if ai.targetid() ~= attacker then
   ai.pushtask(0, "attack", attacker)
  end
 end
end

function create()
end