[Add] attack_closestenemy to basic.lua. Pushed the land function into basic.lua.
This commit is contained in:
parent
0d569ecc54
commit
56d10e603b
@ -17,7 +17,8 @@ function control()
|
|||||||
if planet == nil then
|
if planet == nil then
|
||||||
ai.pushtask(0, "hyperspace")
|
ai.pushtask(0, "hyperspace")
|
||||||
else
|
else
|
||||||
ai.pushtask(0, "go", planet)
|
ai.pushtask(0, "hyperspace")
|
||||||
|
ai.pushtask(0, "land", planet)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,8 @@ function control()
|
|||||||
if planet == nil then
|
if planet == nil then
|
||||||
ai.pushtask(0, "hyperspace")
|
ai.pushtask(0, "hyperspace")
|
||||||
else
|
else
|
||||||
ai.pushtask(0, "go", planet)
|
ai.pushtask(0, "hyperspace")
|
||||||
|
ai.pushtask(0, "land", planet)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,11 +5,29 @@
|
|||||||
-- functions and such for each AI.
|
-- functions and such for each AI.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
--[[
|
||||||
|
-- Replaces the current target with a closer one if possible.
|
||||||
|
--]]
|
||||||
|
function attack_closestenemy()
|
||||||
|
local task = ai.taskname()
|
||||||
|
|
||||||
|
if task == "attack" then
|
||||||
|
local enemy = ai.getenemy()
|
||||||
|
local target = ai.targetid()
|
||||||
|
|
||||||
|
if enemy ~= target then
|
||||||
|
ai.poptask()
|
||||||
|
ai.pushtask(0, "attack", enemy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
-- Attacks the current target, task pops when target is dead.
|
-- Attacks the current target, task pops when target is dead.
|
||||||
--]]
|
--]]
|
||||||
function attack()
|
function attack_default()
|
||||||
target = ai.targetid()
|
local target = ai.targetid()
|
||||||
|
ai.hostile(target) -- Mark as hostile.
|
||||||
|
|
||||||
-- Make sure pilot exists.
|
-- Make sure pilot exists.
|
||||||
if not ai.exists(target) then
|
if not ai.exists(target) then
|
||||||
@ -20,15 +38,14 @@ function attack()
|
|||||||
ai.settarget(target)
|
ai.settarget(target)
|
||||||
|
|
||||||
-- Get stats about enemy.
|
-- Get stats about enemy.
|
||||||
dist = ai.dist(ai.pos(target)) -- Get distance.
|
local dist = ai.dist(ai.pos(target)) -- Get distance.
|
||||||
|
local range = ai.getweaprange()
|
||||||
range = ai.getweaprange()
|
|
||||||
|
|
||||||
-- We first bias towards range.
|
-- We first bias towards range.
|
||||||
if dist > range then
|
if dist > range then
|
||||||
dir = ai.face(target) -- Normal face the target.
|
local dir = ai.face(target) -- Normal face the target.
|
||||||
|
|
||||||
secondary, special = ai.secondary("Launcher")
|
local secondary, special = ai.secondary("Launcher")
|
||||||
|
|
||||||
-- Shoot missiles if in range.
|
-- Shoot missiles if in range.
|
||||||
if secondary == "Launcher" and
|
if secondary == "Launcher" and
|
||||||
@ -49,13 +66,13 @@ function attack()
|
|||||||
|
|
||||||
-- Close enough to melee.
|
-- Close enough to melee.
|
||||||
else
|
else
|
||||||
secondary, special = ai.secondary("Weapon")
|
local secondary, special = ai.secondary("Weapon")
|
||||||
dir = ai.aim(target) -- we aim instead of face.
|
local dir = ai.aim(target) -- we aim instead of face.
|
||||||
|
|
||||||
-- Fire non-smart secondary weapons.
|
-- Fire non-smart secondary weapons.
|
||||||
if(secondary == "Launcher" and special ~= "Smart") or
|
if(secondary == "Launcher" and special ~= "Smart") or
|
||||||
secondary == "Weapon" then
|
secondary == "Beam Weapon" then
|
||||||
if dir < 10 then -- Need good acuracy.
|
if dir < 10 or special == "Turret" then -- Need good acuracy.
|
||||||
ai.shoot(2)
|
ai.shoot(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -66,19 +83,78 @@ function attack()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
-- Set attack function to be default. If you want to override use:
|
||||||
|
-- attack = attack_<type>
|
||||||
|
-- Right after including this file.
|
||||||
|
--]]
|
||||||
|
attack = attack_default
|
||||||
|
|
||||||
|
--[[
|
||||||
|
-- Attempt to land on a planet.
|
||||||
|
--]]
|
||||||
|
function land()
|
||||||
|
local target = ai.target()
|
||||||
|
local dir = ai.face(target)
|
||||||
|
local dist = ai.dist(target)
|
||||||
|
local bdist = ai.minbrakedist()
|
||||||
|
|
||||||
|
-- Need to get closer.
|
||||||
|
if dir < 10 and dist > bdist then
|
||||||
|
ai.accel()
|
||||||
|
-- Need to start braking.
|
||||||
|
elseif dist < bdist then
|
||||||
|
ai.poptask()
|
||||||
|
ai.pushtask(0, "landstop", target)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function landstop()
|
||||||
|
ai.brake()
|
||||||
|
|
||||||
|
if ai.isstopped() then
|
||||||
|
local target = ai.target()
|
||||||
|
ai.stop() -- Will stop the pilot if below err vel.
|
||||||
|
ai.settime(0, rnd.int(8000, 15000)) -- We wait during a while.
|
||||||
|
ai.poptask()
|
||||||
|
ai.pushtask(0, "landwait", target)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function landwait()
|
||||||
|
local target = ai.target()
|
||||||
|
local dist = ai.dist(target)
|
||||||
|
|
||||||
|
-- In case for some reason landed far away..
|
||||||
|
if dist > 50 then
|
||||||
|
ai.poptask()
|
||||||
|
ai.pushtask(0, "land", target)
|
||||||
|
|
||||||
|
elseif ai.timeup(0) then
|
||||||
|
ai.poptask() -- Ready to do whatever we were doing before.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
-- Attempts to run from the target.
|
-- Attempts to run from the target.
|
||||||
--]]
|
--]]
|
||||||
function runaway()
|
function runaway()
|
||||||
target = ai.targetid()
|
local target = ai.targetid()
|
||||||
|
|
||||||
if not ai.exists(target) then
|
if not ai.exists(target) then
|
||||||
ai.poptask()
|
ai.poptask()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
dir = ai.face(target, 1)
|
local dir = ai.face(target, 1)
|
||||||
ai.accel()
|
ai.accel()
|
||||||
|
|
||||||
|
--[[
|
||||||
|
-- TODO: Afterburner handling.
|
||||||
|
-- if ai.hasafterburner() then
|
||||||
|
-- ai.afterburn(true)
|
||||||
|
-- end
|
||||||
|
--]]
|
||||||
if ai.hasturrets() then
|
if ai.hasturrets() then
|
||||||
dist = ai.dist(ai.pos(target))
|
dist = ai.dist(ai.pos(target))
|
||||||
if dist < ai.getweaprange() then
|
if dist < ai.getweaprange() then
|
||||||
@ -93,13 +169,13 @@ end
|
|||||||
--
|
--
|
||||||
-- Will need the following in control() to work:
|
-- Will need the following in control() to work:
|
||||||
--
|
--
|
||||||
-- task = ai.taskname()
|
-- local task = ai.taskname()
|
||||||
-- if task == "hyperspace" then
|
-- if task == "hyperspace" then
|
||||||
-- ai.hyperspace() -- Try to hyperspace.
|
-- ai.hyperspace() -- Try to hyperspace.
|
||||||
-- end
|
-- end
|
||||||
--]]
|
--]]
|
||||||
function hyperspace()
|
function hyperspace()
|
||||||
dir = ai.facr(-1) -- Face away from (0,0).
|
local dir = ai.face(-1) -- Face away from (0,0).
|
||||||
if(dir < 10) then
|
if(dir < 10) then
|
||||||
ai.accel()
|
ai.accel()
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,8 @@ function control()
|
|||||||
if planet == nil then
|
if planet == nil then
|
||||||
ai.pushtask(0, "hyperspace")
|
ai.pushtask(0, "hyperspace")
|
||||||
else
|
else
|
||||||
ai.pushtask(0, "go", planet)
|
ai.pushtask(0, "hyperspace")
|
||||||
|
ai.pushtask(0, "land", planet)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user