[Change] Reworked attack system a bit. More versatile.
This commit is contained in:
parent
e8257c2555
commit
19b8f38acf
@ -9,6 +9,7 @@ land_planet = false
|
||||
|
||||
function create()
|
||||
ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
|
||||
attack_choose()
|
||||
end
|
||||
|
||||
function taunt(target, offence)
|
||||
|
@ -6,6 +6,7 @@ aggressive = true
|
||||
|
||||
function create()
|
||||
ai.setcredits(rnd.int(1000, ai.shipprice()/200))
|
||||
attack_choose()
|
||||
end
|
||||
|
||||
function taunt(target, offense)
|
||||
|
@ -10,6 +10,7 @@ function create()
|
||||
if rnd.int(0,2)==0 then
|
||||
ai.broadcast("The Empire is watching")
|
||||
end
|
||||
attack_choose()
|
||||
end
|
||||
|
||||
function taunt(target, offence)
|
||||
|
@ -5,6 +5,7 @@ aggressive = true
|
||||
|
||||
function create()
|
||||
ai.setcredits(rnd.int(300, ai.shipprice()/70))
|
||||
attack_choose()
|
||||
end
|
||||
|
||||
function taunt(target, offense)
|
||||
|
@ -1,68 +1,39 @@
|
||||
--[[
|
||||
-- Generic attack functions.
|
||||
-- Attack wrappers for calling the correct attack functions.
|
||||
--]]
|
||||
|
||||
function attack_think()
|
||||
include("../scripts/ai/include/attack_generic.lua")
|
||||
include("../scripts/ai/include/attack_bomber.lua")
|
||||
|
||||
--[[
|
||||
-- Wrapper for the think functions.
|
||||
--]]
|
||||
function attack_think()
|
||||
if mem.atk_think ~= nil then
|
||||
mem.atk_think()
|
||||
else
|
||||
atk_g_think()
|
||||
end
|
||||
|
||||
--[[
|
||||
-- Generic "brute force" attack. Doesn't really do anything interesting.
|
||||
-- Wrapper for the attack functions.
|
||||
--]]
|
||||
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.
|
||||
if mem.atk ~= nil then
|
||||
mem.atk()
|
||||
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
|
||||
atk_g()
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
-- Generic function to choose what attack functions match the ship best.
|
||||
--]]
|
||||
function attack_choose()
|
||||
class = ai.shipclass()
|
||||
|
||||
if class == "Bomber" then
|
||||
mem.atk_think = atk_b_think
|
||||
mem.atk = atk_b
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
--[[
|
||||
-- Bombers don't really thing, they lock on until target is dead.
|
||||
--]]
|
||||
function attack_think()
|
||||
function atk_b_think()
|
||||
-- No thinking atm.
|
||||
end
|
||||
|
||||
@ -15,7 +15,7 @@ end
|
||||
-- Specialized for bomber type craft. AI will try to shoot missiles and such
|
||||
-- until out and then they will melee.
|
||||
--]]
|
||||
function attack()
|
||||
function atk_b()
|
||||
target = ai.targetid()
|
||||
ai.hostile(target) -- Mark as hostile.
|
||||
|
||||
|
36
scripts/ai/include/attack_generic.lua
Normal file
36
scripts/ai/include/attack_generic.lua
Normal file
@ -0,0 +1,36 @@
|
||||
--[[
|
||||
-- Generic attack functions.
|
||||
--]]
|
||||
|
||||
--[[
|
||||
-- Mainly manages targetting nearest enemy.
|
||||
--]]
|
||||
function atk_g_think()
|
||||
if mem.atk_think ~= nil then
|
||||
mem.atk_think()
|
||||
else
|
||||
atk_g_think()
|
||||
end
|
||||
|
||||
--[[
|
||||
-- Generic "brute force" attack. Doesn't really do anything interesting.
|
||||
--]]
|
||||
function atk_g()
|
||||
if mem.atk ~= nil then
|
||||
mem.atk()
|
||||
else
|
||||
atk_g()
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
-- Generic function to choose what attack functions match the ship best.
|
||||
--]]
|
||||
function attack_choose()
|
||||
class = ai.shipclass()
|
||||
|
||||
if class == "Bomber" then
|
||||
mem.atk_think = atk_b_think
|
||||
mem.atk = atk_b
|
||||
end
|
||||
|
@ -8,6 +8,7 @@ armour_return = 100
|
||||
|
||||
function create()
|
||||
ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
|
||||
attack_choose()
|
||||
end
|
||||
|
||||
function taunt(target, offense)
|
||||
|
@ -91,7 +91,7 @@ function idle()
|
||||
end
|
||||
|
||||
function create()
|
||||
-- Empty stub.
|
||||
attack_choose()
|
||||
end
|
||||
|
||||
function taunt(target, offensive)
|
||||
|
Loading…
Reference in New Issue
Block a user