Merge branch 'master' of git://github.com/BTAxis/naev into testmission
[naev.git] / docs / ai / examples / land.lua
blob1ccd44deaf29c07ffa76cb7c56c81748339bc5c5
1 --[[
2 -- example calling
3 --
4 -- planet = ai.rndplanet()
5 -- -- planet must exist
6 -- if planet == nil then
7 -- ai.pushtask(0, "hyperspace")
8 -- else
9 -- ai.pushtask(0, "goto", planet)
10 -- end
11 --]]
13 -- flies to the target planet
14 function goto ()
15 target = ai.target()
16 dir = ai.face(target)
17 dist = ai.dist( target )
18 bdist = ai.minbrakedist()
19 if dir < 10 and dist > bdist then
20 ai.accel()
21 elseif dir < 10 and dist < bdist then
22 ai.poptask()
23 ai.pushtask(0,"stop")
24 end
25 end
27 -- brakes
28 function land ()
29 if ai.isstopped() then
30 ai.stop()
31 ai.poptask()
32 ai.settimer(0, ai.rnd(8000,15000))
33 ai.pushtask(0,"landed")
34 else
35 ai.brake()
36 end
37 end
39 -- waits
40 function landed ()
41 if ai.timeup(0) then
42 -- Run X task (usually hyperspace
43 ai.pushtask(0,"hyperspace")
44 end
45 end