Lephisto/scripts/ai/pirate.lua
Allanis a89395a54f [Add] We can now have multiple enemies.
[Add] You are able to get other ship's health from AI now.
2013-02-10 05:21:09 +00:00

88 lines
2.0 KiB
Lua

--Required control rate.
control_rate = 2
-- Required "control" function.
function control()
task = taskname()
if task ~= "attack" and task ~= "runaway" then
-- If getenemy() is 0, there is no enemy around.
enemy = getenemy()
if enemy ~= 0 then
-- Taunts.
num = rng(0,4)
if num == 0 then msg "Prepare to be boarded!"
elseif num == 1 then msg = "Whoa! Lookie we I found here!"
elseif num == 2 then msg = "What's a ship like you doing in a place like this?"
end
comm(enemy,msg)
-- Make hostile to the enemy (mainly, player! YOU!).
hostile(enemy)
-- Go ahead and attack.
pushtask(0, "attack", enemy)
else
pushtask(0, "fly")
end
end
end
-- Required "attacked" function
function attacked(attacker)
task = taskname()
if task ~= "attack" and task ~= "runaway" then
taunt()
pushtask(0, "attack", attacker)
elseif task == "attack" then
if gettargetid() ~= attacker then
pushtask(0, "attack", attacker)
end
end
end
function taunt()
num = rng(0,4)
if num == 0 then msg = "How dare you attack me?!"
elseif num == 1 then msg = "Aha! You think you can best ME?!"
elseif num == 2 then msg = "JUST! DIE!"
elseif num == 3 then msg = "Ohh, You're not going to enjoy this!"
end
if msg then comm(attacker, msg) end
end
-- Run away from the target.
function runaway()
target = gettargerid()
dir = face(target, 1)
accel()
end
-- Attack the target.
function attack()
target = gettargetid()
dir = face(target)
dist = getdist(getpos(target))
-- We need to know when to run away.
if parmor() < 70 then
poptask()
pushtask(0, "runaway", target)
-- Try to obliterate the target.
elseif dir < 10 and dist > 300 then
accel()
elseif dir < 10 and dist < 300 then
shoot()
end
end
-- Fly to the player. Pointless until hyperspace is implemented.
function fly()
target = player
dir = face(target)
dist = getdist(getpos(target))
if dir < 10 and dist > 300 then
accel()
end
end