;;-*-Lisp-*-
(in-package goal)
(bundles "BEA.DGO")
(require "engine/common-obs/process-taskable.gc")
(require "engine/anim/aligner.gc")
(require "engine/geometry/path.gc")

;; DECOMP BEGINS

(deftype pelican-bank (basic)
  ((circle-speed        meters)
   (dive-time           seconds)
   (to-nest0-time       seconds)
   (to-nest1-time       seconds)
   (land-time           seconds)
   (from-nest-time      seconds)
   (spit-time           seconds)
   (pre-spit-wait-time  seconds)
   (post-spit-wait-time seconds)
   (run-away-time       seconds)))

(define *PELICAN-bank*
  (new 'static
       'pelican-bank
       :circle-speed (meters 16)
       :dive-time (seconds 2)
       :to-nest0-time (seconds 4)
       :to-nest1-time (seconds 8)
       :land-time (seconds 2.4)
       :from-nest-time (seconds 20)
       :spit-time (seconds 1)
       :pre-spit-wait-time (seconds 0.5)
       :post-spit-wait-time (seconds 1.5)
       :run-away-time (seconds 10)))

(deftype pelican (process-drawable)
  ((root            collide-shape-moving :override)
   (query           gui-query :inline)
   (fuel-cell       handle)
   (cam-tracker     handle)
   (path-data       curve-control 8)
   (path-circle     curve-control :overlay-at (-> path-data 0))
   (path-dive0      curve-control :overlay-at (-> path-data 1))
   (path-to-nest0   curve-control :overlay-at (-> path-data 2))
   (path-from-nest0 curve-control :overlay-at (-> path-data 3))
   (path-spit0      curve-control :overlay-at (-> path-data 4))
   (path-dive1      curve-control :overlay-at (-> path-data 5))
   (path-to-nest1   curve-control :overlay-at (-> path-data 6))
   (path-to-nest2   curve-control :overlay-at (-> path-data 7))
   (path-cache      curve-control)
   (time-cache      time-frame)
   (path-pos        float)
   (path-speed      float)
   (path-max        float)
   (path-vector     vector :inline)
   (state-vector    vector :inline)
   (state-vector1   vector :inline)
   (state-float     float 2)
   (state-object    symbol)
   (neck            joint-mod))
  (:states
   pelican-circle
   (pelican-dive path-control curve-control time-frame)
   (pelican-explode symbol)
   (pelican-fly-to-end path-control time-frame)
   pelican-from-nest
   pelican-spit
   (pelican-to-nest path-control int)
   (pelican-wait-at-end symbol)
   (pelican-wait-at-nest symbol)))

(defmethod relocate ((this pelican) (arg0 int))
  (countdown (v1-0 8)
    (if (nonzero? (-> this path-data v1-0)) (&+! (-> this path-data v1-0) arg0)))
  (if (nonzero? (-> this path-cache)) (&+! (-> this path-cache) arg0))
  (if (nonzero? (-> this neck)) (&+! (-> this neck) arg0))
  (call-parent-method this arg0))

(defskelgroup *pelican-sg*
  pelican
  pelican-lod0-jg
  pelican-fly-ja
  ((pelican-lod0-mg (meters 20)) (pelican-lod1-mg (meters 40)) (pelican-lod2-mg (meters 999999)))
  :bounds (static-spherem 0 3 0 5)
  :shadow pelican-shadow-mg)

(defbehavior pelican-path-update pelican ((arg0 float) (arg1 int) (arg2 float) (arg3 float) (arg4 symbol))
  (compute-alignment! (-> self align))
  (let ((s3-0 (new 'stack-no-clear 'vector)))
    (let* ((f0-1 (+ (-> self path-pos) (* (-> self align align trans z) arg3)))
           (f1-2 (-> self path-max))
           (f30-0 (- f0-1 (* (the float (the int (/ f0-1 f1-2))) f1-2))))
      (eval-path-curve-div! (-> self path) s3-0 f30-0 'interp)
      (+! (-> s3-0 y) (-> self align align trans y))
      (move-to-point! (-> self root) s3-0)
      (path-control-method-12 (-> self path) s3-0 f30-0))
    (if arg4
      (set-heading-vec-clear-roll-pitch! (-> self root) s3-0)
      (seek-toward-heading-vec! (-> self root) s3-0 arg0 (the-as time-frame arg1)))))

(defbehavior pelican-fly pelican ((arg0 (function pelican int)) (arg1 (function pelican int)))
  (loop
    (cond
      ((ja-group? pelican-fly-ja) (ja-no-eval :num! (seek!)) (while (not (ja-done? 0)) (suspend) (ja-eval)))
      (else (ja-channel-push! 1 (seconds 0.25))))
    (let ((s4-0 (arg0 self)))
      (dotimes (s3-0 s4-0)
        (ja-no-eval :group! pelican-fly-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (ja-blend-eval)
          (suspend)
          (ja :num! (seek!)))))
    (let ((s4-1 (arg1 self)))
      (when (> s4-1 0)
        (ja-no-eval :group! pelican-fly-ja :num! (seek! (ja-aframe 12.0 0)) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek! (ja-aframe 12.0 0))))
        (ja-no-eval :num! (loop! 0.25))
        (ja-channel-push! 1 (seconds 1))
        (dotimes (s3-3 s4-1)
          (ja-no-eval :group! pelican-glide-ja :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (ja-blend-eval)
            (suspend)
            (ja :num! (seek!))))
        (ja-no-eval :num! (loop!)))))
  (none))

(defbehavior pelican-post pelican ()
  (ja-post)
  (none))

(defstate pelican-circle (pelican)
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('dive) (let ((v0-0 (the-as structure #t))) (set! (-> self state-object) (the-as symbol v0-0)) v0-0))
        (('fuel-cell) (handle->process (-> self fuel-cell)))
        (('position)
         (set! (-> self path-pos) (the-as float (-> block param 0)))
         (let ((a1-3 (path-control-method-12 (-> self path) (new 'stack-no-clear 'vector) (-> self path-pos))))
           (set-heading-vec! (-> self root) a1-3)))))
  :enter
    (behavior ()
      (while (-> self child)
        (deactivate (-> self child 0)))
      (set! (-> self state-object) #f)
      (let ((gp-0 (-> self path-vector)))
        (eval-path-curve-div! (-> self path-dive0) gp-0 4.5 'interp)
        (+! (-> gp-0 y) -4505.6)
        (let ((v1-8 (manipy-spawn gp-0 (-> self entity) *fuel-cell-sg* (new 'static 'vector :w 4915.2) :to self)))
          (set! (-> self fuel-cell) (ppointer->handle v1-8))
          (if v1-8
            (send-event (ppointer->process v1-8)
                        'eval
                        (lambda :behavior pelican ()
                          (let ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self))) (set! (-> self part) v0-0) v0-0))))))
      (set! (-> self path) (-> self path-circle))
      (set! (-> self path-pos) 0.0)
      (set! (-> self path-max) (the float (+ (-> self path curve num-cverts) -1)))
      (set! (-> self path-speed) (/ (* (-> *PELICAN-bank* circle-speed) (-> self path-max)) (path-distance (-> self path))))
      (set-roll-to-grav-2! (-> self root) -2730.6667))
  :trans
    (behavior ()
      (pelican-path-update 728177.75 30 1.0 (/ (-> self path-max) (path-distance (-> self path))) #f)
      (let ((f0-3 (+ (-> self path-pos) (* (-> self path-speed) (seconds-per-frame))))
            (f1-2 (-> self path-max)))
        (set! (-> self path-pos) (- f0-3 (* (the float (the int (/ f0-3 f1-2))) f1-2))))
      (when (and (and *target* (>= 81920.0 (vector-vector-xz-distance (-> self path-vector) (-> *target* control trans))))
                 (not (handle->process (-> self cam-tracker))))
        (set! (-> self cam-tracker)
              (ppointer->handle (process-spawn camera-tracker
                                               :init
                                               camera-tracker-init
                                               (lambda :behavior camera-tracker ()
                                                 (local-vars (a0-6 process-tree) (a1-5 event-message-block) (t9-6 (function process-tree event-message-block object)))
                                                 (while (not (process-grab? *target*))
                                                   (suspend))
                                                 (send-event (ppointer->process (-> self parent)) 'position 4.0)
                                                 (send-event (ppointer->process (-> self parent)) 'dive)
                                                 (suspend)
                                                 (suspend)
                                                 (send-event *camera* 'blend-from-as-fixed)
                                                 (camera-look-at (the-as pair (ppointer->process (-> self parent))) (the-as uint 0))
                                                 (camera-change-to "camera-215" 0 #f)
                                                 (until (t9-6 a0-6 a1-5)
                                                   (suspend)
                                                   (set! a1-5 (new 'stack-no-clear 'event-message-block))
                                                   (set! (-> a1-5 from) self)
                                                   (set! (-> a1-5 num-params) 0)
                                                   (set! (-> a1-5 message) 'got-cell?)
                                                   (set! t9-6 send-event-function)
                                                   (set! a0-6 (ppointer->process (-> self parent))))
                                                 (send-event *camera* 'point-of-interest #f)
                                                 (while (!= (-> self message) 'release)
                                                   (suspend))
                                                 (set! (-> self message) #f)
                                                 (while (not (process-release? (handle->process (-> self grab-target))))
                                                   (suspend))
                                                 (send-event *camera* 'blend-from-as-fixed)
                                                 (camera-look-at (the-as pair *target*) (the-as uint 0))
                                                 (camera-change-to (the-as string 'base) 150 #f)
                                                 (none))
                                               :to
                                               self)))
        (set! (-> self draw force-lod) 0)
        0)
      (when (and (-> self state-object) (>= (-> self path-pos) 6.0) (< (-> self path-pos) 7.0))
        (let ((v1-24 (-> self entity extra perm)))
          (logior! (-> v1-24 status) (entity-perm-status user-set-from-cstage))
          (set! (-> v1-24 user-int8 0) 2))
        (go pelican-dive (-> self path-dive0) (-> self path-to-nest0) (-> *PELICAN-bank* to-nest0-time))))
  :code
    (behavior ()
      (suspend)
      (send-event (-> self fuel-cell process 0) 'trans-hook fuel-cell-animate)
      (pelican-fly (the-as (function pelican int) (lambda () (rand-vu-int-range 2 4)))
                   (the-as (function pelican int) (lambda () (rand-vu-int-range 3 5)))))
  :post pelican-post)

(defstate pelican-dive (pelican)
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('got-cell?) (-> self state-object))
        (('fuel-cell) (handle->process (-> self fuel-cell)))))
  :enter
    (behavior ((arg0 path-control) (arg1 curve-control) (arg2 time-frame))
      (init! (-> self query) (the-as string #f) 40 150 25 #t (the-as string #f))
      (set! (-> self state-object) #f)
      (set-time! (-> self state-time))
      (set-roll-to-grav-2! (-> self root) 0.0)
      (let ((a0-4 (handle->process (-> self fuel-cell))))
        (cond
          (a0-4 (send-event a0-4 'trans-hook fuel-cell-animate))
          (else)))
      (set! (-> self path-cache) arg1)
      (set! (-> self time-cache) arg2)
      (set! (-> self path) arg0)
      (set! (-> self path-pos) 0.0)
      (set! (-> self path-max) (the float (+ (-> self path curve num-cverts) -1)))
      (set! (-> self path-speed) (/ (* 300.0 (-> self path-max)) (the float (-> *PELICAN-bank* dive-time))))
      (let ((gp-1 (new 'stack-no-clear 'vector)))
        (path-control-method-12 (-> self path) gp-1 (-> self path-pos))
        (set-heading-vec! (-> self root) gp-1))
      (set! (-> self draw force-lod) 0)
      0)
  :exit
    (behavior ()
      (set! (-> self draw force-lod) -1))
  :trans
    (behavior ()
      (if (not (handle->process (-> self fuel-cell)))
        (go pelican-fly-to-end (-> self path-to-nest2) (-> *PELICAN-bank* run-away-time)))
      (pelican-path-update 364088.88 30 0.0 0.0 #t)
      (seek! (-> self path-pos) (-> self path-max) (* (-> self path-speed) (seconds-per-frame)))
      (if (= (-> self path-pos) (-> self path-max)) (go pelican-to-nest (-> self path-cache) (the-as int (-> self time-cache)))))
  :code
    (behavior ((arg0 path-control) (arg1 curve-control) (arg2 time-frame))
      (ja-channel-push! 1 (seconds 0.2))
      (ja-no-eval :group! pelican-swoop-ja :num! (seek! (ja-aframe 48.0 0) 0.5) :frame-num 0.0)
      (until (ja-done? 0)
        (ja-blend-eval)
        (let ((gp-1 (handle->process (-> self fuel-cell))))
          (when (and gp-1 (>= (-> self path-pos) 3.8) (not (send-event gp-1 'query 'grab)))
            (level-hint-spawn (text-id zero) (the-as string #f) (-> self entity) *entity-pool* (game-task none))
            (send-event gp-1 'grab self)
            (send-event gp-1 'draw #f)
            (send-event gp-1 'event-hook #f)
            (set! (-> self state-object) #t)))
        (suspend)
        (ja :num! (seek! (ja-aframe 48.0 0) 0.5)))
      (ja-no-eval :num! (seek!))
      (ja-channel-push! 1 (seconds 0.2))
      (ja-no-eval :group! pelican-fly-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!)))
      (anim-loop))
  :post pelican-post)

(defstate pelican-to-nest (pelican)
  :enter
    (behavior ((arg0 path-control) (arg1 int))
      (set! (-> self path) arg0)
      (set! (-> self path-pos) 0.0)
      (set! (-> self path-max) (the float (+ (-> self path curve num-cverts) -1)))
      (set! (-> self path-speed) (/ (* 300.0 (-> self path-max)) (the float arg1))))
  :trans
    (behavior ()
      (pelican-path-update 546133.3 30 0.0 0.0 #f)
      (seek! (-> self path-pos) (-> self path-max) (* (-> self path-speed) (seconds-per-frame)))
      (if (= (-> self path-pos) (-> self path-max)) (go pelican-wait-at-nest #f)))
  :code
    (behavior ((arg0 path-control) (arg1 int))
      (pelican-fly (the-as (function pelican int) (lambda () 1))
                   (lambda ((arg0 pelican))
                     (if (and (>= (-> arg0 path-pos) 4.0) (>= 6.0 (-> arg0 path-pos))) 1 0))))
  :post pelican-post)

(defstate pelican-wait-at-nest (pelican)
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('attack)
         (case (-> block param 1)
           (('explode)
            (let ((a0-2 (handle->process (-> self fuel-cell)))) (if a0-2 (send-event a0-2 'trans (-> self root trans))))
            (go pelican-explode #f)
            #f)
           (else
            (let* ((gp-0 proc)
                   (v1-13 (if (and (nonzero? gp-0) (type-type? (-> gp-0 type) process-drawable)) gp-0))
                   (f30-0 8192.0)
                   (gp-1 (-> self root))
                   (s4-0 (-> (the-as process-drawable v1-13) root trans)))
              (if (< f30-0 (fabs (deg-diff (y-angle gp-1) (vector-y-angle (vector-! (new 'stack-no-clear 'vector) s4-0 (-> gp-1 trans))))))
                (go pelican-spit))))))
        (('touch) (send-shove-back (-> self root) proc (the-as touching-shapes-entry (-> block param 0)) 0.7 6144.0 16384.0))))
  :enter
    (behavior ((arg0 symbol))
      (set! (-> self path) (-> self path-from-nest0))
      (set! (-> self path-pos) 0.0)
      (set! (-> self path-max) (the float (+ (-> self path curve num-cverts) -1)))
      (set! (-> self path-speed) (/ (* 300.0 (-> self path-max)) (the float (-> *PELICAN-bank* from-nest-time))))
      (let ((s5-0 (-> self state-vector)))
        (eval-path-curve-div! (-> self path) s5-0 (-> self path-pos) 'interp)
        (set! (-> self state-float 0)
              (/ (* 300.0 (vector-vector-distance (-> self root trans) s5-0)) (the float (-> *PELICAN-bank* land-time)))))
      (path-control-method-12 (-> self path) (-> self path-vector) (-> self path-pos))
      (when arg0
        (move-to-point! (-> self root) (-> self state-vector))
        (set-heading-vec! (-> self root) (-> self path-vector))
        (let ((a0-7 (handle->process (-> self fuel-cell)))) (if a0-7 (send-event a0-7 'draw #f)))
        (let ((a0-10 (-> self entity extra perm))) (if (< 2 (-> a0-10 user-int8 0)) (go pelican-explode #t))))
      (if (nonzero? (-> self neck)) (set-mode! (-> self neck) (joint-mod-handler-mode look-at))))
  :exit
    (behavior ()
      (if (nonzero? (-> self neck)) (set-mode! (-> self neck) (joint-mod-handler-mode flex-blend))))
  :trans
    (behavior ()
      (let ((a1-0 (-> self state-vector))
            (gp-0 (new 'stack-no-clear 'vector)))
        (set! (-> gp-0 quad) (-> self root trans quad))
        (vector-seek! gp-0 a1-0 (* (-> self state-float 0) (seconds-per-frame)))
        (move-to-point! (-> self root) gp-0))
      (do-push-aways! (-> self root))
      (seek-toward-heading-vec! (-> self root) (-> self path-vector) 131072.0 (seconds 1))
      (spool-push *art-control* "pelican-spit-ext" 0 self -99.0))
  :code
    (behavior ((arg0 symbol))
      (cond
        (arg0 (ja-channel-set! 1))
        (else
         (ja-no-eval :num! (loop! 0.25))
         (ja-channel-push! 1 (seconds 0.25))
         (ja-no-eval :group! pelican-fly-down-ja :num! (seek!) :frame-num 0.0)
         (until (ja-done? 0)
           (ja-blend-eval)
           (suspend)
           (ja :num! (seek!)))
         (until (vector= (-> self root trans) (-> self state-vector))
           (suspend)
           (ja :num! (loop!)))
         (ja-no-eval :num! (loop!))
         (set! (-> self state-float 0) (* 4.0 (-> self state-float 0)))
         (ja-channel-push! 1 (seconds 0.05))
         (ja-no-eval :group! pelican-land-ja :num! (seek!) :frame-num 0.0)
         (until (ja-done? 0)
           (ja-blend-eval)
           (suspend)
           (ja :num! (seek!)))
         (ja-channel-push! 1 (seconds 0.5))))
      (send-event (handle->process (-> self cam-tracker)) 'message 'release)
      (loop
        (ja-no-eval :group! pelican-sleep-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post
    (behavior ()
      (when *target*
        (if *target* (look-at-enemy! (-> *target* neck) (the-as vector (-> self root root-prim prim-core)) 'nothing self))
        (if (nonzero? (-> self neck)) (set-target! (-> self neck) (target-pos 5))))
      (pelican-post)))

(defstate pelican-spit (pelican)
  :event
    (-> pelican-circle
        event)
  :code
    (behavior ()
      (local-vars (v1-21 symbol) (v1-31 symbol))
      (let ((gp-1 (ppointer->handle (manipy-spawn (-> self entity extra trans) (-> self entity) *beachcam-sg* #f :to self))))
        (let ((s5-0 (get-process *default-dead-pool* othercam #x4000)))
          (ppointer->handle (when s5-0
                              (let ((t9-4 (method-of-type othercam activate)))
                                (t9-4 (the-as othercam s5-0) (-> gp-1 process 0) 'othercam (the-as pointer #x70004000)))
                              (run-now-in-process s5-0 othercam-init-by-other (-> gp-1 process 0) 4 #f #t)
                              (-> s5-0 ppointer))))
        (let ((s4-0 (ppointer->handle (process-spawn fuel-cell :init fuel-cell-init-as-clone (process->handle self) 0 :to self)))
              (s5-2 (new 'stack-no-clear 'quaternion)))
          (quaternion-copy! s5-2 (-> self root quat))
          (until v1-21
            (suspend)
            (set! v1-21 (or (not *target*) (process-grab? *target*))))
          (send-event (-> gp-1 process 0) 'anim-mode 'clone-anim)
          (ja-play-spooled-anim (new 'static
                                     'spool-anim
                                     :name "pelican-spit-ext"
                                     :index 11
                                     :parts 2
                                     :command-list
                                     '((10 send-event camera 'teleport-to-vector-start-string (static-vectorm -179 16 -421))))
                                (the-as art-joint-anim pelican-sleep-ja)
                                (the-as art-joint-anim #f)
                                (the-as (function process-drawable symbol) false-func))
          (until v1-31
            (suspend)
            (set! v1-31 (or (not *target*) (process-release? *target*))))
          (if (handle->process gp-1) (deactivate (-> gp-1 process 0)))
          (if (handle->process s4-0) (deactivate (-> s4-0 process 0)))
          (quaternion-copy! (-> self root quat) s5-2)))
      (process-spawn-function process
        (lambda :behavior pelican ()
          (while (or (-> *setting-control* current ambient) (-> *setting-control* current movie) (-> *setting-control* current hint))
            (suspend))
          (level-hint-spawn (text-id beach-pelican-quick-get-cell) "sksp0027" (the-as entity #f) *entity-pool* (game-task none))
          (none))
        :to
        self)
      (let ((gp-3 (handle->process (-> self fuel-cell))))
        (when gp-3
          (send-event gp-3 'release)
          (set! (-> self path-cache) (-> self path-spit0))
          (let ((s5-3 (new 'stack-no-clear 'vector)))
            (eval-path-curve-div! (-> self path-cache) s5-3 (the float (+ (-> self path-cache curve num-cverts) -1)) 'interp)
            (send-event gp-3 'trans s5-3))
          (send-event gp-3 'draw #t)
          (send-event gp-3
                      'event-hook
                      (lambda :behavior pelican ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
                        (when (or (= arg2 'touch) (= arg2 'attack))
                          (let ((v1-7 (birth-pickup-at-point (-> self root trans)
                                                             (pickup-type fuel-cell)
                                                             (the float (-> self entity extra perm task))
                                                             #f
                                                             *entity-pool*
                                                             (the-as fact-info #f))))
                            (when v1-7
                              (set! (-> (the-as collectable (-> v1-7 0)) collect-timeout) 0)
                              0))
                          (deactivate self))))))
      (go pelican-from-nest))
  :post
    (behavior ()
      (if (not (ja-group? pelican-sleep-ja)) (quaternion-identity! (-> self root quat)))
      (pelican-post)))

(defstate pelican-from-nest (pelican)
  :enter
    (behavior ()
      (set! (-> self path-pos) 1.5))
  :trans
    (behavior ()
      (pelican-path-update 131072.0 150 0.0 0.0 #f)
      (seek! (-> self path-pos) (-> self path-max) (* (-> self path-speed) (seconds-per-frame)))
      (if (= (-> self path-pos) (-> self path-max))
        (go pelican-dive (-> self path-dive1) (-> self path-to-nest1) (-> *PELICAN-bank* to-nest1-time))))
  :code
    (behavior ()
      (pelican-fly (the-as (function pelican int) (lambda () (rand-vu-int-range 2 4)))
                   (the-as (function pelican int) zero-func)))
  :post pelican-post)

(defstate pelican-fly-to-end (pelican)
  :enter
    (behavior ((arg0 path-control) (arg1 time-frame))
      (process-entity-status! self (entity-perm-status complete) #t)
      (let ((v1-2 (-> self entity extra perm)))
        (logior! (-> v1-2 status) (entity-perm-status user-set-from-cstage))
        (set! (-> v1-2 user-int8 0) 10))
      (set-time! (-> self state-time))
      (set! (-> self path) arg0)
      (set! (-> self path-pos) 0.0)
      (set! (-> self path-max) (the float (+ (-> self path curve num-cverts) -1)))
      (set! (-> self path-speed) (/ (* 300.0 (-> self path-max)) (the float arg1)))
      (set! (-> self state-vector quad) (-> self root trans quad))
      (set! (-> self state-float 0) 0.0)
      (let ((gp-1 (new 'stack-no-clear 'vector)))
        (eval-path-curve-div! (-> self path) gp-1 0.0 'interp)
        (set! (-> self state-float 1) (* 0.0073242188 (vector-vector-distance (-> self root trans) gp-1)))))
  :trans
    (behavior ()
      (pelican-path-update 546133.3 30 0.0 0.0 #f)
      (seek! (-> self path-pos) (-> self path-max) (* (-> self path-speed) (seconds-per-frame)))
      (if (= (-> self path-pos) (-> self path-max)) (go pelican-wait-at-end #f))
      (when (not (time-elapsed? (-> self state-time) (the int (-> self state-float 1))))
        (set! (-> self state-float 0) (/ (the float (- (current-time) (-> self state-time))) (-> self state-float 1)))
        (vector-lerp! (-> self root trans) (-> self state-vector) (-> self root trans) (-> self state-float 0))))
  :code
    (behavior ((arg0 path-control) (arg1 time-frame))
      (pelican-fly (the-as (function pelican int) (lambda () 1))
                   (lambda ((arg0 pelican))
                     (if (and (>= (-> arg0 path-pos) 4.0) (>= 6.0 (-> arg0 path-pos))) 1 0))))
  :post pelican-post)

(defstate pelican-wait-at-end (pelican)
  :code
    (behavior ((arg0 symbol))
      (cleanup-for-death self)))

(defstate pelican-explode (pelican)
  :code
    (behavior ((arg0 symbol))
      (let ((v1-2 (-> self entity extra perm)))
        (logior! (-> v1-2 status) (entity-perm-status user-set-from-cstage))
        (set! (-> v1-2 user-int8 0) 5))
      (when (not arg0)
        (sound-play "scrate-break")
        (process-spawn part-tracker
                       :init
                       part-tracker-init
                       (-> *part-group-id-table* 71)
                       -1
                       #f
                       #f
                       #f
                       (-> self root trans)
                       :to
                       *entity-pool*))
      (let ((gp-2 (new-stack-vector0)))
        (set! (-> gp-2 quad) (-> self root trans quad))
        (let ((a0-7 (handle->process (-> self fuel-cell))))
          (when a0-7
            (set! (-> gp-2 quad) (-> (the-as process-drawable a0-7) root trans quad))
            (+! (-> gp-2 y) 8192.0)
            (deactivate a0-7)))
        (when (not (task-complete? *game-info* (-> self entity extra perm task)))
          (let ((v1-29 (birth-pickup-at-point gp-2
                                              (pickup-type fuel-cell)
                                              (the float (-> self entity extra perm task))
                                              #f
                                              self
                                              (the-as fact-info #f))))
            (send-event (ppointer->process v1-29) 'movie-pos 1))))
      (clear-collide-with-as (-> self root))
      (ja-channel-set! 0)
      (anim-loop))
  :post ja-post)

(defmethod init-from-entity! ((this pelican) (arg0 entity-actor))
  (stack-size-set! (-> this main-thread) 512)
  (let ((s4-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s4-0 reaction) default-collision-reaction)
    (set! (-> s4-0 no-reaction) (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing))
    (let ((s3-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set-vector! (-> s3-0 local-sphere) 0.0 12288.0 0.0 12288.0)
      (set-root-prim! s4-0 s3-0))
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> this root) s4-0))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *pelican-sg* '())
  (set! (-> this draw shadow-ctrl) (new 'process 'shadow-control -81920.0 4096.0 614400.0 (the-as float 25) 409600.0))
  (logclear! (-> this mask) (process-mask actor-pause))
  (set! (-> this align) (new 'process 'align-control this))
  (dotimes (s5-1 8)
    (let ((v1-27 (new 'process 'curve-control this 'path (the float (+ s5-1 1)))))
      (set! (-> this path-data s5-1) v1-27)
      (logior! (-> v1-27 flags) (path-control-flag display draw-line draw-point draw-text))))
  (set! (-> this fuel-cell) (the-as handle #f))
  (set! (-> this cam-tracker) (the-as handle #f))
  (set! (-> this neck) (new 'process 'joint-mod (joint-mod-handler-mode flex-blend) this 9))
  (set-vector! (-> this neck twist-max) 2730.6667 2730.6667 0.0 1.0)
  (set! (-> this neck up) (the-as uint 1))
  (set! (-> this neck nose) (the-as uint 2))
  (set! (-> this neck ear) (the-as uint 0))
  (set! (-> this neck max-dist) 61440.0)
  (set! (-> this neck ignore-angle) 16384.0)
  (case (-> this entity extra perm user-int8 0)
    ((10) (go pelican-wait-at-end #t))
    ((5) (go pelican-wait-at-nest #t))
    ((2)
     (let ((s5-2 (manipy-spawn (-> this root trans) (-> this entity) *fuel-cell-sg* (new 'static 'vector :w 4915.2) :to this)))
       (set! (-> this fuel-cell) (if s5-2 (ppointer->handle s5-2) (the-as handle #f)))
       (when s5-2
         (send-event (ppointer->process s5-2)
                     'eval
                     (lambda :behavior pelican ()
                       (let ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self))) (set! (-> self part) v0-0) v0-0)))
         (send-event (ppointer->process s5-2) 'trans-hook fuel-cell-animate)))
     (go pelican-wait-at-nest #t))
    (else (go pelican-circle)))
  (none))
