File: atk_capital.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 (106 lines) | stat: -rw-r--r-- 2,862 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
function atk_capital_init ()
   mem.atk_think  = atk_heuristic_big_game_think
   mem.atk        = atk_capital
end


--[[
-- Main control function for capital ship behavior.
--]]
function atk_capital ()
   local target = _atk_com_think()
   if target == nil then return end

   -- Targeting stuff
   ai.hostile(target) -- Mark as hostile
   ai.settarget(target)

   -- See if the enemy is still seeable
   if not _atk_check_seeable() then return end

   -- Get stats about enemy
   local dist  = ai.dist( target ) -- get distance
   local range = ai.getweaprange(3)

   -- We first bias towards range
   if dist > range * mem.atk_approach then
      _atk_g_ranged( target, dist )
   -- Close enough to melee
   else   
     _atk_g_capital(target, dist)
   end
end


--[[
-- Simplest of all attacks: maintain an intercept course to the target, and shoot when within range
--
--This is designed for capital ships with turrets and guided munitions
--As there is no aiming involved this is a turret/capital ship only attack method
--]]
function _atk_g_capital( target, dist )
   local range = ai.getweaprange(3)
   local dir = 0
   local shoot = false
   ai.weapset( mem.weapset )

   --capital ships tend to require heavier energy reserves and burst output for maximum effectiveness
   if ai.pilot():energy() <= 1 then
      mem.recharge = true
   elseif ai.pilot():energy() > 15 then
      mem.recharge = false
   end

   --if we're far from the target, then turn and approach 
   if dist > range then
      dir = ai.idir(target)
      if dir < 10 and dir > -10 then
         _atk_keep_distance()     
         ai.accel()
      else  
         dir = ai.iface(target)
      end

   --at moderate range from the target, prepare to intercept and engage with turrets
   elseif dist > 0.6* range then
      --drifting away from target, so emphasize intercept 
      --course facing and accelerate to close
      aimdir = ai.aim(target)
      dir    = ai.iface(target)
      if dir < 10 and dir > -10 then
         ai.accel()
      end
      shoot = true

   elseif dist > 0.3*range then
      --capital ship turning is slow
      --emphasize facing for being able to close quickly
      aimdir = ai.aim(target)
      dir    = ai.iface(target)
      -- Only accelerate if the target is getting away.
      if dir < 10 and dir > -10 and ai.relvel(target) > -10 then
         ai.accel()
      end
      -- Shoot if should be shooting.
      shoot = true

   --within close range; aim and blast away with everything
   else
      dir = ai.aim(target)
      -- At point-blank range, we ignore recharge.
      if dir < 10 then
         ai.shoot()
      end
      ai.shoot(true)
   end

   if shoot and not mem.recharge then
      -- test if, by chance, the target can be hit by cannons
      if aimdir < 10 then
         ai.shoot()
      end
      ai.shoot(true)
   end
end