[Change] Reworked attack system a bit. More versatile.

This commit is contained in:
Allanis 2013-12-15 17:16:12 +00:00
parent e8257c2555
commit 19b8f38acf
9 changed files with 70 additions and 58 deletions

View File

@ -9,6 +9,7 @@ land_planet = false
function create() function create()
ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100) ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
attack_choose()
end end
function taunt(target, offence) function taunt(target, offence)

View File

@ -6,6 +6,7 @@ aggressive = true
function create() function create()
ai.setcredits(rnd.int(1000, ai.shipprice()/200)) ai.setcredits(rnd.int(1000, ai.shipprice()/200))
attack_choose()
end end
function taunt(target, offense) function taunt(target, offense)

View File

@ -10,6 +10,7 @@ function create()
if rnd.int(0,2)==0 then if rnd.int(0,2)==0 then
ai.broadcast("The Empire is watching") ai.broadcast("The Empire is watching")
end end
attack_choose()
end end
function taunt(target, offence) function taunt(target, offence)

View File

@ -5,6 +5,7 @@ aggressive = true
function create() function create()
ai.setcredits(rnd.int(300, ai.shipprice()/70)) ai.setcredits(rnd.int(300, ai.shipprice()/70))
attack_choose()
end end
function taunt(target, offense) function taunt(target, offense)

View File

@ -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 end
--[[ --[[
-- Generic "brute force" attack. Doesn't really do anything interesting. -- Wrapper for the attack functions.
--]] --]]
function attack() function attack()
target = ai.targetid() if mem.atk ~= nil then
ai.hostile(target) -- Mark as hostile. mem.atk()
-- 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 else
secondary, special = ai.secondary("Beam Weapon") atk_g()
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
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

View File

@ -5,7 +5,7 @@
--[[ --[[
-- Bombers don't really thing, they lock on until target is dead. -- Bombers don't really thing, they lock on until target is dead.
--]] --]]
function attack_think() function atk_b_think()
-- No thinking atm. -- No thinking atm.
end end
@ -15,7 +15,7 @@ end
-- Specialized for bomber type craft. AI will try to shoot missiles and such -- Specialized for bomber type craft. AI will try to shoot missiles and such
-- until out and then they will melee. -- until out and then they will melee.
--]] --]]
function attack() function atk_b()
target = ai.targetid() target = ai.targetid()
ai.hostile(target) -- Mark as hostile. ai.hostile(target) -- Mark as hostile.

View 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

View File

@ -8,6 +8,7 @@ armour_return = 100
function create() function create()
ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100) ai.setcredits(ai.shipprice()/1000, ai.shipprice()/100)
attack_choose()
end end
function taunt(target, offense) function taunt(target, offense)

View File

@ -91,7 +91,7 @@ function idle()
end end
function create() function create()
-- Empty stub. attack_choose()
end end
function taunt(target, offensive) function taunt(target, offensive)