
[Add] Bomber attack routines. [Fix] Bug with AI forgetting about you if another enemy attacks.
69 lines
1.4 KiB
Lua
69 lines
1.4 KiB
Lua
--[[
|
|
-- Generic attack functions.
|
|
--]]
|
|
|
|
function attack_think()
|
|
|
|
end
|
|
|
|
--[[
|
|
-- Generic "brute force" attack. Doesn't really do anything interesting.
|
|
--]]
|
|
function attack()
|
|
target = ai.targetid()
|
|
ai.hostile(target) -- Mark as hostile.
|
|
|
|
-- Make sure pilot exists.
|
|
if not ai.exists(target) then
|
|
ai.poptask()
|
|
return
|
|
end
|
|
ai.settarget(target)
|
|
|
|
-- Get stats about enemy.
|
|
dist = ai.dist(ai.pos(target)) -- Get distance.
|
|
range = ai.getweaprange()
|
|
|
|
if dist > range then
|
|
dir = ai.face(target) -- Normal face the target.
|
|
|
|
secondary, special, ammo = ai.secondary("Launcher")
|
|
|
|
-- Shoot missiles if in range.
|
|
if secondary == "Launcher" and
|
|
dist < ai.getweaprange(1) then
|
|
-- More lenient with aiming.
|
|
if special == "Smart" and dir < 30 then
|
|
ai.shoot(2)
|
|
|
|
-- Non-smart miss more.
|
|
elseif dir < 10 then
|
|
ai.shoot(2)
|
|
end
|
|
end
|
|
|
|
-- Approach for melee.
|
|
if dir < 10 then
|
|
ai.accel()
|
|
end
|
|
|
|
-- Close enough to melee.
|
|
else
|
|
secondary, special = ai.secondary("Beam Weapon")
|
|
dir = ai.aim(target) -- We aim instead of face.
|
|
|
|
-- Fire non-smart secondary weapons.
|
|
if(secondary == "Launcher" and special ~= "Smart") or
|
|
secondary == "Beam Weapon" then
|
|
if dir < 10 or special == "Turret" then -- Need good accuracy.
|
|
ai.shoot(2)
|
|
end
|
|
end
|
|
|
|
if dir < 10 or ai.hasturrets() then
|
|
ai.shoot()
|
|
end
|
|
end
|
|
end
|
|
|