File: land.lua

package info (click to toggle)
naev 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 386,084 kB
  • sloc: ansic: 93,149; xml: 87,292; python: 2,347; sh: 904; makefile: 654; lisp: 162; awk: 4
file content (45 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
--[[
-- example calling
--
--    planet = ai.rndplanet()
--    -- planet must exist
--    if planet == nil then
--       ai.pushtask(0, "hyperspace")
--    else
--       ai.pushtask(0, "goto", planet)
--    end
--]]

-- flies to the target planet
function goto ()
   target = ai.target()
   dir = ai.face(target)
   dist = ai.dist( target )
   bdist = ai.minbrakedist()
   if dir < 10 and dist > bdist then
      ai.accel()
   elseif dir < 10 and dist < bdist then
      ai.poptask()
      ai.pushtask(0,"stop")
   end
end

-- brakes
function land ()
   if ai.isstopped() then
      ai.stop()
      ai.poptask()
      ai.settimer(0, ai.rnd(8000,15000))
      ai.pushtask(0,"landed")
   else
      ai.brake()
   end
end

-- waits
function landed ()
   if ai.timeup(0) then
      -- Run X task (usually hyperspace
      ai.pushtask(0,"hyperspace")
   end
end