File: runaway.lua

package info (click to toggle)
naev 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 386,084 kB
  • sloc: ansic: 93,149; xml: 87,292; python: 2,347; sh: 904; makefile: 654; lisp: 162; awk: 4
file content (38 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
--[[
-- Pilot runs away, could be at low health, or at signs of fighting
--]]


-- Required "attacked" function
function attacked ( attacker )
   if ai.taskname() ~= "runaway" then
      -- Sir Robin bravely ran away
      ai.pushtask(0, "runaway", attacker)
   else -- run away from the new baddie
      ai.poptask()
      ai.pushtask(0, "runaway", attacker)
   end
end

-- runs away
function runaway ()
   target = ai.targetid()

   if not ai.exists(target) then
      ai.pushtask()
      ai.pushtask(0,"hyperspace")
      return
   end

   dir = ai.face( target, 1 )
   ai.accel()
   if ai.hasturrets() then
      dist = ai.dist( ai.pos(target) )
      if dist < 300 then
         ai.settarget(target)
         ai.shoot()
      end
   end
end