portal.lsp 1.38 KB
1
(let (fail-conditions (lambda (power)
2 3 4 5
                        (cond (> (distance) ship.status.portal_range)
                              "Out of range."
                              (> 0 (- ship.status.battery power))
                              "Insufficient power."))
6
      activate (lambda ()
7
                 (set_beams 0)
8
                 (print "Portal opening.")
9
                 (portal_activate))
10 11
      fail (lambda (message)
             (print message)
12
             (set_beams nil)
13
             (print failure))
14 15 16 17
      init-time (os.time)
      looper (lambda (last-time looper)
               (coroutine.yield)
               (let (time-since (- (os.time) init-time)
18
                     power (* 0.02 (- (os.time) last-time))
19 20 21
                     failure (fail-conditions power))
                 (if failure
                     (fail failure)
22
                   ;; using a lambda here since sandbox interferes with do macro
23 24
                   ((lambda ()
                      (draw_power power)
25
                      (set_beams time-since)
26 27 28
                      (if (> time-since ship.status.portal_time)
                          (activate)
                        (looper (os.time) looper))))))))
29 30
  (if (no_trip_clearance)
      (fail (no_trip_clearance))
31 32 33 34
    ((lambda ()
       (print "Cleared for portal; standby for activation...")
       (disconnect)
       (looper (os.time) looper)))))