File: attacked.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 (60 lines) | stat: -rw-r--r-- 1,323 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--[[
-- Based on when pilot is hit by something, then will attempt to retaliate
--]]

-- triggered when pilot is hit by something
function attacked ( attacker )
   task = ai.taskname()
   if task ~= "attack" and task ~= "runaway" then

      -- some taunting
      taunt( attacker )

      -- 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

-- taunts
function taunt ( target )
   num = ai.rnd(0,4)
   if num == 0 then msg = "You dare attack me!"
   elseif num == 1 then msg = "You are no match for the Empire!"
   elseif num == 2 then msg = "The Empire will have your head!"
   elseif num == 3 then msg = "You'll regret this!"
   end
   if msg then ai.comm(attacker, msg) end
end

-- attacks
function attack ()
   target = ai.targetid()

   -- make sure pilot exists
   if not ai.exists(target) then
      ai.poptask()
      return
   end

   dir = ai.face( target )
   dist = ai.dist( ai.pos(target) )
   second = ai.secondary()

   if ai.secondary() == "Launcher" then
      ai.settarget(target)
      ai.shoot(2)
   end

   if dir < 10 and dist > 300 then
      ai.accel()
   elseif (dir < 10 or ai.hasturrets()) and dist < 300 then
      ai.shoot()
   end
end