/
attack.lua
106 lines (84 loc) · 2.38 KB
/
attack.lua
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
--[[
Attack wrappers for calling the correct attack functions.
Here we set up the wrappers and determine exactly how the pilot should behave.
The global layout is:
- atk_util.lua : Attack generic utilities.
- atk_target.lua : Targetting utilities.
--]]
-- Utilities
include("ai/include/atk_util.lua")
include("ai/include/atk_target.lua")
-- Attack profiles
include("ai/include/atk_generic.lua")
include("ai/include/atk_fighter.lua")
include("ai/include/atk_bomber.lua")
include("ai/include/atk_corvette.lua")
include("ai/include/atk_capital.lua")
--include("ai/include/atk_cruiser.lua")
--include("ai/include/atk_carrier.lua")
include("ai/include/atk_drone.lua")
-- Set attack variables
mem.atk_changetarget = 2 -- Distance at which target changes
mem.atk_approach = 1.4 -- Distance that marks approach
mem.atk_aim = 1.0 -- Distance that marks aim
mem.atk_board = false -- Whether or not to board the target
mem.atk_kill = true -- Whether or not to finish off the target
mem.aggressive = true --whether to take the more aggressive or more evasive option when given
mem.recharge = false --whether to hold off shooting to avoid running dry of energy
--[[
-- Wrapper for the think functions.
--]]
function attack_think ()
if mem.atk_think ~= nil then
mem.atk_think()
else
atk_generic_think()
end
end
--[[
-- Wrapper for the attack functions.
--]]
function attack ()
if mem.atk ~= nil then
mem.atk()
else
atk_generic()
end
end
--[[
-- Wrapper for the attacked function.
--]]
function attack_attacked( attacker )
if mem.atk_attacked ~= nil then
mem.atk_attacked( attacker )
else
atk_generic_attacked( attacker )
end
end
-- [[
-- Generic function to choose what attack functions match the ship best.
-- ]]
function attack_choose ()
local class = ai.shipclass()
-- Lighter ships
if class == "Bomber" then
atk_bomber_init()
elseif class == "Fighter" then
atk_fighter_init()
elseif class == "Drone" then
atk_drone_init()
-- Medium ships
elseif class == "Corvette" then
atk_corvette_init()
-- Capital ships
elseif class == "Destroyer" then
atk_capital_init()
elseif class == "Cruiser" then
atk_capital_init()
elseif class == "Carrier" then
atk_capital_init()
-- Generic AI
else
atk_generic_init()
end
end