-- [[ -- Basic tasks for a pilot, no need to reinvent the wheel with these. -- -- The idea is to have it all here and only really work on the "control" -- functions and such for each AI. --]] --[[ -- Attacks the current target, task pops when target is dead. --]] function attack() target = ai.targetid() -- Make sure pilot exists. if not ai.exists(target) then ai.poptask() return end ai.settarget(target) -- Get stats about enemy. dist = ai.dist(ai.pos(target)) -- Get distance. range = ai.getweaprange() -- We first bias towards range. if dist > range then dir = ai.face(target) -- Normal face the target. -- Shoot missiles if in range. if ai.secondary() == "Launcher" and dist < ai.getweaprange(1) and dir < 30 then -- More leniant with aiming. ai.shoot(2) end if dir < 10 then ai.accel() end -- Close enough to melee. else dir = ai.aim(target) -- we aim instead of face. if (dir < 10 or ai.hasturret()) then ai.shoot() end end end --[[ -- Attempts to run from the target. --]] function runaway() target = ai.targetid() if not ai.exists(target) then ai.poptask() return end dir = ai.face(target, 1) ai.accel() if ai.hasturrets() then dist = ai.dist(ai.pos(target)) if dist < ai.getweaprange() then ai.settarget(target) ai.shoot() end end end --[[ -- Start heading away to try to hyperspace. -- -- Will need the following in control() to work: -- -- task = ai.taskname() -- if task == "hyperspace" then -- ai.hyperspace() -- Try to hyperspace. -- end --]] function hyperspace() dir = ai.facr(-1) -- Face away from (0,0). if(dir < 10) then ai.accel() end end