[Add] Now all ai include "ai/include/basic.lua" to share attack and runaway functions.

This commit is contained in:
Allanis 2013-07-01 17:17:14 +01:00
parent 203079bcfa
commit 7a03a6f377
7 changed files with 67 additions and 208 deletions

View File

@ -1,59 +0,0 @@
-- Required control rate.
control_rate = 2
-- Required "control" function.
function control()
if taskname() == "none" then
pushtask(0, "fly")
end
end
-- Required "attacked" function.
function attacked(attacker)
if taskname() ~= "attack" and task ~= "runaway" then
-- Let's have some taunts.
if attacker == player then
local msg = rng(0,4)
if msg == 0 then say("You will never kill me!")
elseif msg == 1 then say("DIE!")
elseif msg == 2 then say("You won't survive!")
elseif msg == 3 then say("I hate you!")
end
end
pushtask(0, "attack", attacker)
end
end
-- Runs away.
function runaway()
local target = gettargetid()
local dir = face(target, 1)
accel()
end
-- Attack
function attack()
local target = gettargetid()
local dir = face(target)
local dist = getdist(getpos(target))
if parmour() < 70 then
poptask()
pushtask(0, "runaway", target)
elseif dir < 10 and dist > 300 then
accel()
elseif dir < 10 and dist < 300 then
shoot()
end
end
-- Fly to the player.
function fly()
local target = 0
local dir = face(target)
local dist = getdist(getpos(target))
if dir < 10 and dist > 300 then
accel()
end
end

View File

@ -1,3 +1,5 @@
include("ai/include/basic.lua"
-- Required control rate.
control_rate = 2
@ -30,28 +32,3 @@ end
function create()
end
function attack()
target = ai.targetid()
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target)
dist = ai.dist(ai.pos(target))
second = ai.secondary()
if ai.secondary() == "Launcher" then
ai.settarget(target)
is.shoot(2)
end
if dir < 10 and dist > 200 then
ai.accel()
elseif dir < 10 and dist < 200 then
ai.shoot()
end
end

View File

@ -1,3 +1,5 @@
include("ai/include/basic.lua")
-- Required control rate
control_rate = 2
@ -52,31 +54,6 @@ function taunt(target)
if msg then ai.comm(attacker, msg) end
end
function attack()
target = ai.targetid()
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target)
dist = ai.dist(ai.pos(target))
second = ai.secondary()
if ai.secondary() == "Launcher" then
ai.settarget(target)
ai.shoot(2)
end
if dir < 10 and dist > 300 then
ai.accel()
elseif(dir < 10 or ai.hasturrets()) and dist < 300 then
ai.shoot()
end
end
function go()
target = ai.target()
dir = ai.face(target)

View File

@ -0,0 +1,57 @@
[[
Basic tasks for a pilot, no need to reinvent the wheel with these.
The idea is to have it all here and only really work on the "control"
functions and such for each AI.
]]
[[
Attacks the current target, task pops when target is dead.
]]
function attack()
target = ai.targetid()
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target)
dist = ai.dist(ai.pos(target))
second = ai.secondary()
if ai.secondary() == "Launcher" then
ai.settarget(target)
ai.shoot(2)
end
if dir < 10 and dist > 300 then
ai.accel()
elseif(dir < 10 or ai.hasturrets()) and dist < 300 then
ai.shoot()
end
end
[[
Attempts to run from the target.
]]
function runaway()
target = ai.targetid()
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target, 1)
ai.accel()
if ai.hasturrets() then
dist = ai.dist(ai.pos(target))
if dist < 300 then
ai.settarget(target)
ai.shoot()
end
end
end

View File

@ -1,3 +1,5 @@
include("ai/include/basic.lua")
-- Required control rate.
control_rate = 2
@ -58,27 +60,6 @@ function create()
ai.setcargo(cargo, rnd.int(0, ai.cargofree()))
end
-- Runs away.
function runaway()
target = ai.targetid()
if not ai.exists(target) then
ai.pushtask()
ai.pushtask(0, "hyperspace")
return
end
dir = ai.face(target, 1)
ai.accel()
if ai.hasturrets() then
dist = ai.dist(ai.pos(target))
if dist < 300 then
ai.settarget(target)
ai.shoot()
end
end
end
-- Fly to the target.
function go()
target = ai.target()

View File

@ -1,3 +1,5 @@
include("ai/include/basic.lua")
-- Required control rate
control_rate = 2
@ -49,46 +51,6 @@ function taunt(target)
if msg then ai.comm(attacker, msg) end
end
function runaway()
target = ai.targetid()
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target, 1)
ai.accel()
end
function attack()
target = ai.targetid()
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target)
dist = ai.dist(ai.pos(target))
second = ai.secondary()
if ai.secondary() == "Launcher" then
ai.settarget(target)
ai.shoot(2)
end
if ai.parmour() < 70 then
ai.poptask()
ai.pushtask(0, "runaway", target)
elseif dir < 10 and dist > 300 then
ai.accel()
elseif dir < 10 and dist < 300 then
ai.shoot()
end
end
function scan()
target = ai.targetid()
if not ai.exists(target) then

View File

@ -1,3 +1,5 @@
include("ai/include/basic.lua")
--Required control rate.
control_rate = 2
@ -72,44 +74,6 @@ function taunt(target)
if msg then ai.comm(target, msg) end
end
-- Run away from the target.
function runaway()
target = ai.targetid()
-- Ensure target exists.
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target, 1)
ai.accel()
end
-- Attack the target.
function attack()
target = ai.targetid()
-- Ensure target exists.
if not ai.exists(target) then
ai.poptask()
return
end
dir = ai.face(target)
dist = ai.dist(ai.pos(target))
-- We need to know when to run away.
if ai.parmour() < 70 then
ai.pushtask(0, "runaway", target)
-- Try to obliterate the target.
elseif dir < 10 and dist > 300 then
ai.accel()
elseif dir < 10 and dist < 300 then
ai.shoot()
end
end
-- Fly to the player. Pointless until hyperspace is implemented.
function fly()
target = player