File: attack_bomber.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 (135 lines) | stat: -rw-r--r-- 2,712 bytes parent folder | download | duplicates (2)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
--[[
--    Attack functions for bombers
--]]


--[[
-- Bombers don't really think, they lock on until target is dead.
--]]
function atk_b_think ()
   -- No thinking atm
end



--[[
-- Attacks the current target, task pops when target is dead.
--
-- Specialized for bomber type craft.  AI will try to shoot missiles and such
--  until out and then will melee.
--]]
function atk_b ()
   target = ai.target()
   ai.hostile(target) -- Mark as hostile

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

   -- Get stats about enemy
   dist = ai.dist( target ) -- get distance

   -- Get bombing tool
   secondary, special = ai.secondary("ranged")
   if secondary ~= "Launcher" or special == "Unguided" then -- No launcher, must melee
      atk_b_melee( target, dist, secondary, special )
   end

   atk_b_ranged( target, dist )
end


--[[
--   Melee combat.
--]]
function atk_b_melee( target, dist, secondary, special )
   range = ai.getweaprange()

   -- Must approach
   if dist > range then
      dir = ai.face(target)
      if dir < 10 then
         ai.accel()
      end

   -- Time to shoot
   else
      dir = ai.aim(target) -- We aim instead of face
      
      -- Fire secondary
      if dir < 10 or special == "Turret" then
         ai.shoot(true)
      end

      -- Fire primary
      if dir < 10 then
         ai.shoot(false)
      elseif ai.hasturrets() then
         ai.shoot(false, 1)
      end
   end
end


--[[
--   The heart and soul of the bomber.
--]]
function atk_b_ranged( target, dist )

   -- Get ranges relative to bombing weapon of choice
   bombrange = ai.getweaprange(true)
   backoff = bombrange / 4

   -- Must get closer to be able to bomb
   if dist > bombrange then
      dir = ai.face(target)
      if dir < 10 then
         ai.accel()
      end

   -- In bombing range
   elseif dist > backoff then
      dir = ai.face(target)

      -- Shoot missiles if in range
      if secondary == "Launcher" and
            dist < bombrange then

         -- More lenient with aiming
         if special == "Smart" and dir < 30 then
            ai.shoot(true)

         -- Non-smart miss more
         elseif dir < 10 then
            ai.shoot(true)
         end
      end

      -- We don't approach, we try to stay away from melee

   -- Time to break attack and get back to bomb
   else
      ai.pushtask( "atk_b_backoff" )
   end
end


--[[
--   Back off and come back when ready to kill
--]]
function atk_b_backoff ()
   range = ai.getweaprange()

   -- Flee
   ai.face(target, true)
   ai.accel()

   -- Fire turret if being chased
   if dist < range and ai.hasturrets() then
      ai.shoot(false, 1)
   end
end