[Change] Moved hyperspace() to scripts/ai/include/basic.lua

This commit is contained in:
Allanis 2013-08-10 12:18:05 +01:00
parent 79411d240e
commit afa05f0ff8
4 changed files with 29 additions and 18 deletions

View File

@ -84,10 +84,3 @@ function land()
end end
end end
function hyperspace()
dir = ai.face(-1) -- Face away from (0,0)
if(dir < 10) then
ai.accel()
end
end

View File

@ -59,3 +59,20 @@ function runaway()
end end
end end
--[[
-- Start heading away to try to hyperspace.
--
-- Will need the following in control() to work:
--
-- task = ai.taskname()
-- if task == "hyperspace" then
-- ai.hyperspace() -- Try to hyperspace.
-- end
--]]
function hyperspace()
dir = ai.facr(-1) -- Face away from (0,0).
if(dir < 10) then
ai.accel()
end
end

View File

@ -94,11 +94,3 @@ function land()
end end
end end
-- Go to hyperspace YEAAAHHH!!
function hyperspace()
dir = ai.face(-1) -- Face away from (0,0)
if(dir < 10) then
ai.accel()
end
end

View File

@ -7,8 +7,11 @@ control_rate = 2
function control() function control()
task = ai.taskname() task = ai.taskname()
if task == "hyperspace" then
ai.hyperspace() -- Try to hyperspace.
-- Running pilot has healed up some. -- Running pilot has healed up some.
if task == "runaway" then elseif task == "runaway" then
if ai.parmour() == 100 then if ai.parmour() == 100 then
-- "attack" should be called after "runaway". -- "attack" should be called after "runaway".
ai.poptask() ai.poptask()
@ -16,13 +19,19 @@ function control()
ai.hyperspace() ai.hyperspace()
end end
-- Hurt pilot wants to run away.
elseif task == "attack" then
if ai.parmour() < 80 then
ai.pushtask(0, "runaway", ai.targetid())
end
-- Nothing to do. -- Nothing to do.
elseif task ~= "attack" and task ~= "runaway" then elseif task ~= "attack" and task ~= "runaway" then
-- If getenemy() is 0, there is no enemy around. -- If getenemy() is 0, there is no enemy around.
enemy = ai.getenemy() enemy = ai.getenemy()
if ai.parmour() == 100 and enemy ~= 0 then if ai.parmour() == 100 and enemy ~= 0 then
-- Taunts. -- Taunts.
num = rnd.int(0,4) num = rnd.int(0,5)
if num == 0 then msg = "Prepare to be boarded!" if num == 0 then msg = "Prepare to be boarded!"
elseif num == 1 then msg = "Whoa! Lookie what we found here!" elseif num == 1 then msg = "Whoa! Lookie what we found here!"
elseif num == 2 then msg = "What's a ship like you doing in a place like this?" elseif num == 2 then msg = "What's a ship like you doing in a place like this?"
@ -37,7 +46,7 @@ function control()
ai.pushtask(0, "attack", enemy) -- Begin the attack. ai.pushtask(0, "attack", enemy) -- Begin the attack.
-- Nothing to attack. -- Nothing to attack.
else else
ai.pushtask(0, "fly") ai.pushtask(0, "hyperspace")
end end
end end
end end