;;-*-Lisp-*-
(in-package goal)

;; name: mh-flyer.gc
;; name in dgo: mh-flyer
;; dgos: DESBATTL

(define-extern *mh-flyer-curve-linear-up-red* curve2d-piecewise)
(define-extern *mh-flyer-trail-color-curve-missile* curve-color-fast)
(define-extern *mh-flyer-curve-missile-linear-trail* curve2d-fast)
(define-extern *mh-flyer-missile-trail* light-trail-composition)

;; DECOMP BEGINS

(defpart 1715
  :init-specs ((:texture (bigpuff level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 3))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 150.0)
    (:b 128.0)
    (:a 64.0)
    (:scalevel-x (meters 0.005))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.32)
    (:timer (seconds 0.667))
    (:flags (sp-cpuinfo-flag-2))
    (:rotate-y (degrees 0))
    )
  )

(when (or (zero? *mh-flyer-curve-linear-up-red*) (!= loading-level global))
  (set! *mh-flyer-curve-linear-up-red* (new 'loading-level 'curve2d-piecewise))
  (allocate! *mh-flyer-curve-linear-up-red* 2 'loading-level #f)
  )

(set! (-> *mh-flyer-curve-linear-up-red* pts data 0 first) 0.0)

(set! (-> *mh-flyer-curve-linear-up-red* pts data 0 second) 0.3)

(set! (-> *mh-flyer-curve-linear-up-red* pts data 1 first) 1.0)

(set! (-> *mh-flyer-curve-linear-up-red* pts data 1 second) 1.0)

(if #t
    (set! *mh-flyer-trail-color-curve-missile* (new 'static 'curve-color-fast
                                                 :xs (new 'static 'vector :y -0.2 :z -1.0 :w -2.0)
                                                 :ys (new 'static 'inline-array vector 4
                                                   (new 'static 'vector :x 1.0 :y 0.5 :w 128.0)
                                                   (new 'static 'vector :x 0.7 :w 128.0)
                                                   (new 'static 'vector :x 0.7 :w 128.0)
                                                   (new 'static 'vector :x 0.7 :w 128.0)
                                                   )
                                                 :one-over-x-deltas (new 'static 'vector :x 5.0 :y 1.25 :z 1.0 :w 1.0)
                                                 )
          )
    )

(if #t
    (set! *mh-flyer-curve-missile-linear-trail* (new 'static 'curve2d-fast
                                                  :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                                  :ys (new 'static 'vector :x 0.3 :y 1.0 :z 2.0 :w 3.0)
                                                  :one-over-x-deltas (new 'static 'vector :x 0.7 :y 1.0 :z 1.0 :w 1.0)
                                                  )
          )
    )

(if (or (zero? *mh-flyer-missile-trail*) (!= loading-level global))
    (set! *mh-flyer-missile-trail* (new 'loading-level 'light-trail-composition))
    )

(set! (-> *mh-flyer-missile-trail* color-mode) (the-as uint 0))

(set! (-> *mh-flyer-missile-trail* color-repeat-dist) 40960.0)

(set! (-> *mh-flyer-missile-trail* alpha-1-mode) (the-as uint 0))

(set! (-> *mh-flyer-missile-trail* alpha-2-mode) (the-as uint 1))

(set! (-> *mh-flyer-missile-trail* base-alpha) 0.5)

(set! (-> *mh-flyer-missile-trail* alpha-repeat-dist) 6144.0)

(set! (-> *mh-flyer-missile-trail* width-mode) (the-as uint 2))

(set! (-> *mh-flyer-missile-trail* base-width) 4096.0)

(set! (-> *mh-flyer-missile-trail* width-repeat-dist) 40960.0)

(set! (-> *mh-flyer-missile-trail* uv-mode) (the-as uint 0))

(set! (-> *mh-flyer-missile-trail* uv-repeat-dist) 16384000.0)

(set! (-> *mh-flyer-missile-trail* lie-mode) (lie-mode appearance0))

(set! (-> *mh-flyer-missile-trail* max-age) (seconds 1))

(if #f
    (set! (-> *mh-flyer-missile-trail* tex-id) (lookup-texture-id-by-name (the-as string #f) (the-as string #f)))
    (set! (-> *mh-flyer-missile-trail* tex-id) (new 'static 'texture-id :index #x3 :page #x1))
    )

(set! (-> *mh-flyer-missile-trail* width-curve)
      (the-as curve2d-piecewise *mh-flyer-curve-missile-linear-trail*)
      )

(set! (-> *mh-flyer-missile-trail* color-curve)
      (the-as curve-color-piecewise *mh-flyer-trail-color-curve-missile*)
      )

(set! (-> *mh-flyer-missile-trail* alpha-curve-1) (the-as curve2d-piecewise *curve-linear-down*))

(set! (-> *mh-flyer-missile-trail* alpha-curve-2) *mh-flyer-curve-linear-up-red*)

(set! (-> *mh-flyer-missile-trail* zbuffer?) #f)

(vector-copy! (-> *mh-flyer-missile-trail* lie-vector) *up-vector*)

(set! (-> *mh-flyer-missile-trail* use-tape-mode?) #f)

(set! (-> *mh-flyer-missile-trail* blend-mode) (the-as uint 1))

(set! (-> *mh-flyer-missile-trail* frame-stagger) (the-as uint 1))

(defskelgroup skel-mh-flyer-missile mh-flyer-missile mh-flyer-missile-lod0-jg mh-flyer-missile-idle-ja
              ((mh-flyer-missile-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 8)
              :origin-joint-index 3
              )

(deftype mh-flyer-shot (projectile)
  ((tail-pos           vector      :inline)
   (hit-pos            vector      :inline)
   (turn-quat          quaternion  :inline)
   (minimap            connection-minimap)
   (hit-actor?         basic)
   (last-hit-time      uint64)
   (snd-whoosh         uint32)
   (muzzle-flash-part  basic)
   (particle-trail     basic)
   )
  )


(defstate impact (mh-flyer-shot)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('touched)
       (send-event
         proc
         'attack
         (-> block param 0)
         (static-attack-info :mask (vehicle-impulse-factor) ((id (-> self attack-id))
                                                             (damage 2.0)
                                                             (vehicle-damage-factor 0.00666)
                                                             (vehicle-impulse-factor 2.5)
                                                             (mode 'explode)
                                                             )
                             )
         )
       #t
       )
      )
    )
  :enter (behavior ()
    (call-parent-state-handler enter)
    (when (-> self minimap)
      (logior! (-> self minimap flags) (minimap-flag fade-out))
      (set! (-> self minimap) #f)
      )
    (let ((gp-0 (new 'stack-no-clear 'explosion-init-params)))
      (vector-copy! (-> gp-0 spawn-point) (-> self root trans))
      (quaternion-identity! (-> gp-0 spawn-quat))
      (set! (-> gp-0 radius) 40960.0)
      (set! (-> gp-0 scale) 1.0)
      (set! (-> gp-0 group) group-grenade-shot-explode)
      (set! (-> gp-0 collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> gp-0 damage) 2.0)
      (set! (-> gp-0 damage-scale) 1.0)
      (set! (-> gp-0 vehicle-damage-factor) 1.0)
      (set! (-> gp-0 vehicle-impulse-factor) 1.0)
      (set! (-> gp-0 ignore-proc) (process->handle #f))
      (explosion-spawn gp-0 (the-as process-drawable *default-pool*))
      )
    (let ((f0-6 (lerp-scale 409.6 0.0 (vector-vector-distance (camera-pos) (-> self root trans)) 40960.0 163840.0)))
      (if (!= f0-6 0.0)
          (activate! *camera-smush-control* f0-6 37 600 1.0 0.1 (-> self clock))
          )
      )
    (logior! (-> self draw status) (draw-control-status no-draw))
    (let ((v1-30 (-> self root root-prim)))
      (set! (-> v1-30 prim-core collide-as) (collide-spec))
      (set! (-> v1-30 prim-core collide-with) (collide-spec))
      )
    0
    )
  :code (behavior ()
    (while (-> self child)
      (suspend)
      )
    )
  )

(defstate dissipate (mh-flyer-shot)
  :virtual #t
  :enter (behavior ()
    (call-parent-state-handler enter)
    (when (-> self minimap)
      (logior! (-> self minimap flags) (minimap-flag fade-out))
      (set! (-> self minimap) #f)
      )
    )
  )

(defmethod projectile-method-24 ((this mh-flyer-shot))
  (draw-beam
    (the-as sparticle-launcher (-> this muzzle-flash-part))
    (-> this tail-pos)
    (-> this starting-dir)
    #f
    )
  0
  (none)
  )

(defmethod projectile-method-25 ((this mh-flyer-shot))
  (transform-post)
  0
  (none)
  )

(defmethod deal-damage! ((this mh-flyer-shot) (arg0 process) (arg1 event-message-block))
  (let ((t9-0 (method-of-type projectile deal-damage!)))
    (when (t9-0 this arg0 arg1)
      (set! (-> this hit-actor?) (the-as basic #t))
      #t
      )
    )
  )

(defmethod projectile-method-26 ((this mh-flyer-shot))
  (let ((v1-8
          (cond
            ((-> this hit-actor?)
             (cond
               ((logtest? (-> group-gun-yellow-shot-hit-object flags) (sp-group-flag sp13))
                (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
                (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-gun-yellow-shot-hit-object)
                )
               (else
                 (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
                 (part-tracker-spawn part-tracker :to *entity-pool* :group group-gun-yellow-shot-hit-object)
                 )
               )
             )
            ((logtest? (-> group-gun-yellow-shot-hit flags) (sp-group-flag sp13))
             (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
             (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-gun-yellow-shot-hit)
             )
            (else
              (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
              (part-tracker-spawn part-tracker :to *entity-pool* :group group-gun-yellow-shot-hit)
              )
            )
          )
        )
    (send-event (ppointer->process v1-8) 'clock this)
    )
  0
  (none)
  )

;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this mh-flyer-shot) (arg0 projectile-options))
  (let ((v1-0 arg0))
    (cond
      ((zero? v1-0)
       (sound-play "flyer-msllaunch")
       )
      ((= v1-0 (projectile-options po0))
       (if (-> this hit-actor?)
           (sound-play "flyer-mslexplod")
           (sound-play "ball-explode")
           )
       )
      ((= v1-0 (projectile-options po0 po1))
       (sound-play-by-name
         (static-sound-name "flyer-mslstreak")
         (-> this sound-id)
         1024
         (the int (* 1524.0 (doppler-pitch-shift (-> this root trans) (-> this root transv))))
         0
         (sound-group)
         #t
         )
       )
      )
    )
  (none)
  )

(defun mh-flyer-shot-move ((arg0 mh-flyer-shot))
  (let ((s5-0 (-> arg0 root)))
    (let ((s2-0 (as-type (handle->process (-> arg0 desired-target)) process-focusable)))
      (if s2-0
          (vector+float*!
            (-> arg0 desired-target-pos)
            (get-trans (the-as process-focusable s2-0) 0)
            (get-transv (the-as process-focusable s2-0))
            (* 3.0 (-> arg0 charge-level))
            )
          )
      )
    (let ((s3-1 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> s5-0 transv) 1.0))
          (s2-2 (vector-! (new 'stack-no-clear 'vector) (-> arg0 desired-target-pos) (-> s5-0 trans)))
          (s4-4 (new 'stack-no-clear 'quaternion))
          (f30-0 (vector-length (-> s5-0 transv)))
          )
      (vector-normalize! s2-2 1.0)
      (quaternion-from-two-vectors-max-angle! s4-4 s3-1 s2-2 (* 29127.111 (seconds-per-frame)))
      (quaternion-slerp! (-> arg0 turn-quat) (-> arg0 turn-quat) s4-4 (* 10.0 (seconds-per-frame)))
      (quaternion*! (-> s5-0 quat) (-> arg0 turn-quat) (-> s5-0 quat))
      (vector-z-quaternion! (-> s5-0 transv) (-> s5-0 quat))
      (vector-normalize! (-> s5-0 transv) f30-0)
      )
    (projectile-move-fill-line-sphere arg0)
    (when (logtest? (-> s5-0 status) (collide-status touch-surface))
      (if (logtest? (-> arg0 root status) (collide-status touch-actor))
          (set! (-> arg0 hit-actor?) (the-as basic #t))
          )
      (let ((v1-23 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> arg0 tail-pos) (-> s5-0 trans)) 2048.0))
            (a1-12 (-> arg0 hit-pos))
            )
        (vector-copy! a1-12 (-> s5-0 trans))
        (vector+! a1-12 a1-12 v1-23)
        (move-to-point! (-> arg0 root) a1-12)
        )
      (go (method-of-object arg0 impact))
      )
    )
  0
  (none)
  )

(defmethod handle-proj-hit! ((this mh-flyer-shot) (arg0 process) (arg1 event-message-block))
  (let ((t9-0 (method-of-type projectile handle-proj-hit!)))
    (when (not (t9-0 this arg0 arg1))
      (if (type? arg0 projectile)
          (go (method-of-object this impact))
          )
      )
    )
  )

(defmethod setup-collision! ((this mh-flyer-shot))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction)
          (the-as (function control-info collide-query vector vector collide-status) cshape-reaction-just-move)
          )
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate jak-yellow-shot))
    (let ((v1-7 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-7 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-7 prim-core collide-with)
            (collide-spec backgnd jak crate civilian enemy vehicle-sphere hit-by-others-list player-list pusher shield)
            )
      (set! (-> v1-7 prim-core action) (collide-action solid))
      (set-vector! (-> v1-7 local-sphere) 0.0 0.0 0.0 12288.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-7)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-10 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-10 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-10 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 1))
    (set! (-> s5-0 event-self) 'touched)
    (set! (-> this root) s5-0)
    )
  (set! (-> this root pat-ignore-mask)
        (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noproj #x1 :noendlessfall #x1 :board #x1)
        )
  0
  (none)
  )

(defmethod relocate ((this mh-flyer-shot) (offset int))
  (if (nonzero? (-> this particle-trail))
      (&+! (-> this particle-trail) offset)
      )
  (call-parent-method this offset)
  )

;; ERROR: Stack slot load at 96 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 112 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 128 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 96 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 112 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 128 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 96 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 112 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 128 mismatch: defined as size 4, got size 16
(defmethod init-proj-settings! ((this mh-flyer-shot))
  (local-vars
    (sv-80 (function float float float float float float))
    (sv-96 float)
    (sv-112 float)
    (sv-128 float)
    )
  (with-pp
    (initialize-skeleton
      this
      (the-as skeleton-group (art-group-get-by-name *level* "skel-mh-flyer-missile" (the-as (pointer level) #f)))
      (the-as pair 0)
      )
    (set! (-> this hit-actor?) #f)
    (vector-copy! (-> this tail-pos) (-> this root trans))
    (cpad-set-buzz! (-> *cpad-list* cpads 0) 1 204 (seconds 0.1))
    (set! (-> this attack-mode) 'eco-yellow)
    (set! (-> this max-speed) 327680.0)
    (set! (-> this move) mh-flyer-shot-move)
    (set! (-> this timeout) (seconds 15))
    (set! (-> this sound-id) (new-sound-id))
    (set! (-> this damage) 2.0)
    (set! (-> this vehicle-damage-factor) 0.333)
    (logior! (-> this options) (projectile-options po13))
    (set! (-> this muzzle-flash-part) (-> *part-id-table* 268))
    pp
    (set! (-> this particle-trail)
          (new 'process 'sparticle-subsampler *sp-particle-system-2d* (-> *part-id-table* 1715) 8.0)
          )
    (set! (-> this desired-target) (-> *vehicle-info* handle-by-vehicle-type 14))
    (let ((s3-0 (as-type (handle->process (-> this desired-target)) process-focusable)))
      (if s3-0
          (vector+float*!
            (-> this desired-target-pos)
            (get-trans (the-as process-focusable s3-0) 0)
            (get-transv (the-as process-focusable s3-0))
            (* 3.0 (-> this charge-level))
            )
          )
      )
    (let ((s5-5 (new 'stack-no-clear 'light-trail-tracker-spawn-params)))
      (set! (-> s5-5 tracked-obj) (process->handle this))
      (set! (-> s5-5 appearance) *mh-flyer-missile-trail*)
      (set! (-> s5-5 max-num-crumbs) (the int (* 0.5 (the float (-> s5-5 appearance max-age)))))
      (set! (-> s5-5 track-immediately?) #t)
      (let* ((v0-8 (estimate-light-trail-mem-usage
                     (the-as uint (-> s5-5 max-num-crumbs))
                     (the-as uint (= (-> s5-5 appearance lie-mode) (lie-mode use-two-strips)))
                     )
                   )
             (s4-2 (get-process *default-dead-pool* light-trail-tracker-projectile (+ v0-8 8192) 1))
             )
        (when s4-2
          (let ((t9-10 (method-of-type process activate)))
            (t9-10 s4-2 *entity-pool* "light-trail" (the-as pointer #x70004000))
            )
          (run-now-in-process s4-2 light-trail-tracker-init-by-other s5-5)
          (-> s4-2 ppointer)
          )
        )
      )
    (set! (-> this minimap) (add-icon! *minimap* this (the-as uint 135) (the-as int #f) (the-as vector #t) 0))
    (quaternion-copy! (-> this turn-quat) *unity-quaternion*)
    (let* ((s5-6 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> this root transv) 1.0))
           (f0-9 (vector-dot s5-6 *y-vector*))
           (s4-3 (new 'stack-no-clear 'vector))
           )
      (let ((s3-1 vector-lerp!)
            (s2-0 s4-3)
            (s1-0 *y-vector*)
            (s0-0 *x-vector*)
            )
        (set! sv-80 lerp-scale)
        (set! sv-96 (the-as float 0.0))
        (set! sv-112 (the-as float 1.0))
        (set! sv-128 f0-9)
        (let ((a3-5 (cos 14563.556))
              (t0-2 0.0)
              )
          (s3-1 s2-0 s1-0 s0-0 (sv-80 sv-96 sv-112 sv-128 a3-5 t0-2))
          )
        )
      (forward-up->quaternion (-> this root quat) s5-6 s4-3)
      )
    (set-vector! (-> this root scale) 2.0 2.0 1.0 1.0)
    0
    (none)
    )
  )

(define *mh-flyer-shadow-control*
  (new 'static 'shadow-control :settings (new 'static 'shadow-settings
                                           :center (new 'static 'vector :w (the-as float #x28))
                                           :shadow-dir (new 'static 'vector :y -1.0 :w 614400.0)
                                           :bot-plane (new 'static 'plane :y 1.0 :w 40960.0)
                                           :top-plane (new 'static 'plane :y 1.0 :w -40960.0)
                                           :fade-dist 1638400.0
                                           )
                               )
  )

(defskelgroup skel-mh-flyer mh-flyer mh-flyer-lod0-jg -1
              ((mh-flyer-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 32)
              :shadow mh-flyer-shadow-mg
              )

(deftype mh-flyer (enemy)
  ((rotation-matrix      matrix       :inline)
   (move-curve           cubic-curve  :inline)
   (init-pos             vector       :inline)
   (move-dest            vector       :inline)
   (target-velocity      vector       :inline)
   (focus-bullseye-pos   vector       :inline)
   (focus-xz-dir         vector       :inline)
   (minimap              connection-minimap)
   (des-path             desbeast-path)
   (manager              handle)
   (path-pos             uint32)
   (bank-angle           float)
   (pitch-angle          float)
   (missiles-fired       int32)
   (last-fire-time       time-frame)
   (last-player-screech  time-frame)
   (jitter               float)
   )
  (:state-methods
    orbiting
    on-path
    )
  (:methods
    (mh-flyer-method-157 (_type_) none)
    (mh-flyer-method-158 (_type_) none)
    )
  )


(define *mh-flyer-enemy-info* (new 'static 'enemy-info
                                :use-die-falling #t
                                :use-victory #f
                                :use-jump-blocked #f
                                :debug-draw-neck #f
                                :jump-debug-draw #f
                                :move-to-ground #f
                                :hover-if-no-ground #t
                                :idle-anim-script #f
                                :idle-anim 5
                                :notice-anim 5
                                :hostile-anim 5
                                :hit-anim 5
                                :knocked-anim 5
                                :knocked-land-anim 5
                                :die-anim 5
                                :die-falling-anim 5
                                :victory-anim -1
                                :jump-wind-up-anim -1
                                :jump-in-air-anim -1
                                :jump-land-anim -1
                                :neck-joint 26
                                :look-at-joint 26
                                :bullseye-joint 18
                                :sound-die (static-sound-name "flyer-death")
                                :notice-distance (meters 180)
                                :notice-distance-delta (meters 10)
                                :proximity-notice-distance (meters 5)
                                :default-hit-points 8.0
                                :gnd-collide-with (collide-spec backgnd)
                                :overlaps-others-collide-with-filter (collide-spec jak bot player-list)
                                :penetrate-knocked (penetrate
                                  touch
                                  generic-attack
                                  lunge
                                  flop
                                  punch
                                  spin
                                  roll
                                  uppercut
                                  bonk
                                  tube
                                  vehicle
                                  flut-attack
                                  board
                                  mech
                                  mech-punch
                                  mech-bonk
                                  dark-skin
                                  dark-punch
                                  dark-bomb
                                  dark-smack
                                  flut
                                  shield
                                  explode
                                  jak-yellow-shot
                                  jak-red-shot
                                  jak-blue-shot
                                  jak-dark-shot
                                  enemy-yellow-shot
                                  enemy-dark-shot
                                  eco-yellow
                                  eco-red
                                  eco-blue
                                  eco-green
                                  knocked
                                  jak-red-shockwave
                                  jak-dark-nuke
                                  jak-dark-blackhole
                                  emp-blast
                                  penetrate38
                                  penetrate39
                                  penetrate40
                                  penetrate41
                                  penetrate42
                                  penetrate43
                                  penetrate44
                                  penetrate45
                                  penetrate46
                                  penetrate47
                                  penetrate48
                                  penetrate49
                                  penetrate50
                                  penetrate51
                                  penetrate52
                                  penetrate53
                                  penetrate54
                                  penetrate55
                                  penetrate56
                                  penetrate57
                                  penetrate58
                                  penetrate59
                                  penetrate60
                                  penetrate61
                                  penetrate64
                                  penetrate63
                                  )
                                :movement-gravity (meters -100)
                                :friction 0.8
                                :attack-shove-back (meters 3)
                                :attack-shove-up (meters 2)
                                :attack-mode 'generic
                                :attack-damage 2
                                :recover-gnd-collide-with (collide-spec backgnd crate obstacle hit-by-others-list pusher)
                                :knocked-can-land-timeout (seconds 0.5)
                                :knocked-recover-timeout (seconds 2)
                                :ragdoll-blend-out-time (seconds 0.25)
                                :ragdoll-rotate-velocity-mult 1.0
                                :jump-height-min (meters 3)
                                :jump-height-factor 0.5
                                :knocked-seek-ry-clamp 364.0889
                                :knocked-soft-vxz-lo (meters 17.6)
                                :knocked-soft-vxz-hi (meters 26.4)
                                :knocked-soft-vy-lo (meters 20)
                                :knocked-soft-vy-hi (meters 30)
                                :knocked-medium-vxz-lo (meters 36)
                                :knocked-medium-vxz-hi (meters 48)
                                :knocked-medium-vy-lo (meters 33)
                                :knocked-medium-vy-hi (meters 37)
                                :knocked-hard-vxz-lo (meters 19.2)
                                :knocked-hard-vxz-hi (meters 28.8)
                                :knocked-hard-vy-lo (meters 44.8)
                                :knocked-hard-vy-hi (meters 51.2)
                                :knocked-huge-vxz-lo (meters 40.2)
                                :knocked-huge-vxz-hi (meters 60.8)
                                :knocked-huge-vy-lo (meters 44.8)
                                :knocked-huge-vy-hi (meters 53.2)
                                :knocked-yellow-vxz-lo (meters 10)
                                :knocked-yellow-vxz-hi (meters 12)
                                :knocked-yellow-vy-lo (meters 14)
                                :knocked-yellow-vy-hi (meters 20)
                                :knocked-red-vxz-lo (meters 6)
                                :knocked-red-vxz-hi (meters 48)
                                :knocked-red-vy-lo (meters 23)
                                :knocked-red-vy-hi (meters 37)
                                :knocked-blue-vxz-lo (meters 10)
                                :knocked-blue-vxz-hi (meters 12)
                                :knocked-blue-vy-lo (meters 6)
                                :knocked-blue-vy-hi (meters 20)
                                :ragdoll-info (new 'static 'ragdoll-setup
                                  :orient-tform (new 'static 'vector :x 0.9952 :y 0.0483 :z -0.0847 :w 19014.305)
                                  :scale (new 'static 'vector :x 1.0 :y 1.0 :z 1.0)
                                  :bg-collide-with (collide-spec backgnd player-list)
                                  :joint-setup (new 'static 'boxed-array :type ragdoll-joint-setup
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 3
                                      :parent-joint -1
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      :hit-sound (static-sound-name "flyer-impacts")
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 4
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -1.0 :w 15000.881)
                                      :geo-tform (new 'static 'vector :x 1.0 :w 12867.685)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 5
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -1.0 :w 612.3975)
                                      :geo-tform (new 'static 'vector :x -1.0 :w 2728.8462)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 6
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -1.0 :w 2728.8462)
                                      :geo-tform (new 'static 'vector :x -1.0 :w 717.6192)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 7
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -1.0 :w 717.601)
                                      :geo-tform (new 'static 'vector :x -1.0 :w 1219.2063)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 8
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -1.0 :w 1219.188)
                                      :geo-tform (new 'static 'vector :x -1.0 :w 1844.1648)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 9
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -1.0 :w 1844.1467)
                                      :geo-tform (new 'static 'vector :x -1.0 :w 807.4945)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 10
                                      :parent-joint 5
                                      :pre-tform (new 'static 'vector :x 0.2346 :z -0.972 :w 16714.355)
                                      :geo-tform (new 'static 'vector :x -0.6784 :y -0.5036 :z 0.5348 :w 18576.945)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 11
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -0.9938 :z 0.1106 :w 15361.675)
                                      :geo-tform (new 'static 'vector :x 0.7739 :y -0.411 :z 0.4817 :w 20593.668)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 12
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 0.4415 :z 0.8972 :w 18033.285)
                                      :geo-tform (new 'static 'vector :x -0.5869 :y -0.7225 :z -0.3653 :w 14834.109)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 13
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -0.4415 :z -0.8972 :w 9765.41)
                                      :geo-tform (new 'static 'vector :x -0.5094 :y -0.6374 :z -0.5779 :w 14238.17)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 14
                                      :parent-joint 5
                                      :pre-tform (new 'static 'vector :x 0.2347 :z 0.972 :w 16714.482)
                                      :geo-tform (new 'static 'vector :x 0.8251 :y -0.426 :z -0.3709 :w 21422.863)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 15
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -0.9817 :z -0.1901 :w 14298.391)
                                      :geo-tform (new 'static 'vector :x -0.8611 :y 0.3294 :z 0.3871 :w 19576.295)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 16
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 0.6637 :z -0.7479 :w 14707.134)
                                      :geo-tform (new 'static 'vector :x 0.871 :y 0.2965 :z -0.3916 :w 20604.574)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 17
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -0.6637 :z 0.7479 :w 13520.04)
                                      :geo-tform (new 'static 'vector :x 0.8988 :y 0.2347 :z -0.3701 :w 29743.805)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 18
                                      :parent-joint 3
                                      :pre-tform (new 'static 'vector :x 1.0 :w 22499.637)
                                      :geo-tform (new 'static 'vector :x 0.9999 :y -0.0007 :z -0.0003 :w 43627.824)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 19
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -0.2432 :z -0.9699 :w 18621.07)
                                      :geo-tform (new 'static 'vector :x -0.0922 :y 0.9892 :z -0.1133 :w 13819.74)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 20
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -0.9735 :z -0.2283 :w 1877.1332)
                                      :geo-tform (new 'static 'vector :x -0.1573 :y 0.9524 :z 0.2609 :w 15864.6455)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 21
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 0.1924 :z 0.9813 :w 4414.25)
                                      :geo-tform (new 'static 'vector :x 0.4704 :y 0.8824 :z -0.0036 :w 17260.018)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 22
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 0.7159 :z -0.6981 :w 7377.5693)
                                      :geo-tform (new 'static 'vector :x 0.3008 :y 0.9433 :z -0.1398 :w 14574.26)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 23
                                      :parent-joint 18
                                      :pre-tform (new 'static 'vector :x -1.0 :z -0.0002 :w 5351.724)
                                      :geo-tform (new 'static 'vector :x 1.0 :y 0.0001 :z 0.0002 :w 6248.257)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 24
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 1.0 :z 0.0001 :w 6248.257)
                                      :geo-tform (new 'static 'vector :x 1.0 :y 0.0004 :w 2265.7434)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 25
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 1.0 :w 2265.7617)
                                      :geo-tform (new 'static 'vector :x -1.0 :y 0.0002 :w 4304.095)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 26
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -1.0 :w 4304.1133)
                                      :geo-tform (new 'static 'vector :x 1.0 :y 0.0001 :w 7142.222)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 27
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 1.0 :w 7142.204)
                                      :geo-tform (new 'static 'vector :x 1.0 :y 0.0001 :w 8916.282)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 28
                                      :parent-joint 18
                                      :pre-tform (new 'static 'vector :x -0.2407 :z 0.9705 :w 18604.36)
                                      :geo-tform (new 'static 'vector :x 0.7906 :y 0.0698 :z 0.6083 :w 31586.479)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 29
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x -0.973 :z 0.2307 :w 1875.604)
                                      :geo-tform (new 'static 'vector :x 0.7297 :y -0.1807 :z 0.6593 :w 30495.795)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 30
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 0.1895 :z -0.9818 :w 4414.25)
                                      :geo-tform (new 'static 'vector :x 0.7224 :y 0.0023 :z 0.6914 :w 40145.39)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    (new 'static 'ragdoll-joint-setup
                                      :joint-index 31
                                      :parent-joint -1
                                      :pre-tform (new 'static 'vector :x 0.718 :z 0.696 :w 7377.5693)
                                      :geo-tform (new 'static 'vector :x 0.7813 :y 0.0914 :z 0.6173 :w 36833.145)
                                      :axial-slop 2001.0144
                                      :max-angle 4713.313
                                      :coll-rad 6787.072
                                      )
                                    )
                                  )
                                :shadow-size (meters 1)
                                :shadow-max-y (meters 1)
                                :shadow-min-y (meters -1)
                                :shadow-locus-dist (meters 150)
                                :gem-joint -1
                                :gem-offset (new 'static 'sphere :r 163840.0)
                                :knocked-off #t
                                )
        )

(set! (-> *mh-flyer-enemy-info* fact-defaults) *fact-info-enemy-defaults*)

(defbehavior mh-flyer-fly-post mh-flyer ()
  (let ((a1-0 (new 'stack-no-clear 'collide-query)))
    (find-ground-and-set-pat! self a1-0 (collide-spec backgnd) 8192.0 163840.0 4096.0 (the-as process #f))
    )
  (if (!= (-> self root gspot-pos y) -40959590.0)
      (set! (-> self move-dest y) (+ 81920.0 (fmax (-> self move-dest y) (-> self root gspot-pos y))))
      )
  (cubic-curve-method-9
    (-> self move-curve)
    (-> self root trans)
    (-> self root transv)
    (-> self move-dest)
    (-> self target-velocity)
    )
  (let ((s5-0 (new 'stack-no-clear 'vector)))
    (new 'stack-no-clear 'vector)
    (let ((gp-0 (new 'stack-no-clear 'vector)))
      (let ((s4-0 (-> self root transv)))
        (cubic-curve-method-11 (-> self move-curve) s4-0 0.0)
        (vector-length-max! s4-0 245760.0)
        (set! (-> s4-0 y) (fmax -163840.0 (fmin 163840.0 (-> s4-0 y))))
        (vector-v++! (-> self root trans) s4-0)
        (cubic-curve-method-12 (-> self move-curve) s5-0 0.0)
        (vector-length-max! s5-0 655360.0)
        (vector-v++! s4-0 s5-0)
        )
      (let* ((v1-21 (vector-flatten! (new 'stack-no-clear 'vector) s5-0 (-> self rotation-matrix rvec)))
             (f0-6 (lerp-scale 9102.223 -9102.223 (vector-dot (-> self rotation-matrix fvec) v1-21) 245760.0 -245760.0))
             )
        (seek! (-> self pitch-angle) f0-6 (* 32768.0 (seconds-per-frame)))
        )
      (vector-rotate-around-axis! gp-0 *y-vector* (-> self pitch-angle) (-> self rotation-matrix rvec))
      (let* ((v1-25 (vector-flatten! (new 'stack-no-clear 'vector) s5-0 *y-vector*))
             (f0-12 (lerp-scale -15473.777 15473.777 (vector-dot (-> self rotation-matrix rvec) v1-25) 131072.0 -131072.0))
             )
        (seek! (-> self bank-angle) f0-12 (* 10922.667 (seconds-per-frame)))
        )
      (vector-rotate-around-axis! gp-0 gp-0 (-> self bank-angle) (-> self rotation-matrix fvec))
      (let ((s5-1 (new 'stack-no-clear 'inline-array 'vector 2)))
        (vector-copy! (-> s5-1 1) (-> self root transv))
        (vector-normalize! (-> s5-1 1) 1.0)
        (forward-up->quaternion (the-as quaternion (-> s5-1 0)) (-> s5-1 1) gp-0)
        (quaternion-slerp!
          (-> self root quat)
          (-> self root quat)
          (the-as quaternion (-> s5-1 0))
          (* 4.0 (seconds-per-frame))
          )
        )
      )
    )
  (enemy-simple-post)
  (none)
  )

(defun get-interp-mod-time ((arg0 float) (arg1 float))
  (/ (the float (mod (+ (current-time) (the int (* 300.0 arg0 arg1))) (the int (* 300.0 arg0)))) (* 300.0 arg0))
  )

(defstate orbiting (mh-flyer)
  :virtual #t
  :enter (behavior ()
    (set! (-> self bank-angle) 0.0)
    (set! (-> self pitch-angle) 0.0)
    (vector-copy! (-> self init-pos) (-> self root trans))
    (vector-reset! (-> self root transv))
    (let ((f0-3 (* 65536.0 (get-interp-mod-time 10.0 -0.2)))
          (gp-0 (new 'stack-no-clear 'vector))
          )
      (vector-rotate-around-y! gp-0 *z-vector* f0-3)
      (vector+float*! (-> self root trans) (-> self init-pos) gp-0 819200.0)
      (vector-! gp-0 (-> self root trans) (-> self init-pos))
      (vector-normalize! gp-0 -1.0)
      (vector-rotate90-around-y! gp-0 gp-0)
      (forward-up->quaternion (-> self root quat) gp-0 *y-vector*)
      )
    )
  :code (behavior ()
    (ja-channel-push! 1 0)
    (until #f
      (ja-no-eval :group! mh-flyer-fly-fast0-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  :post (behavior ()
    (let ((gp-0 (-> self move-dest))
          (f0-1 (* 65536.0 (get-interp-mod-time 20.0 0.0)))
          (s5-0 (new 'stack-no-clear 'vector))
          )
      (vector-rotate-around-y! s5-0 *z-vector* f0-1)
      (vector+float*! gp-0 (-> self init-pos) s5-0 819200.0)
      )
    (let ((gp-2 (-> self target-velocity)))
      (vector-! gp-2 (-> self init-pos) (-> self move-dest))
      (vector-normalize! gp-2 1.0)
      (vector-cross! gp-2 gp-2 *y-vector*)
      (vector-normalize! gp-2 245760.0)
      )
    (mh-flyer-fly-post)
    )
  )

(defstate on-path (mh-flyer)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set! (-> self path-pos) (the-as uint 0))
    (set! (-> self last-fire-time) 0)
    (set! (-> self missiles-fired) 0)
    (set-time! (-> self state-time))
    (ja-channel-set! 2)
    (ja-no-eval :group! mh-flyer-fly-fast0-ja :num! (loop!))
    (ja-no-eval :chan 1 :group! mh-flyer-fly-fast0-jitter-ja :num! (chan 0) :frame-num 0.0)
    )
  :trans (behavior ()
    (let ((a0-0 (-> self skel root-channel 1)))
      (let ((f0-0 (-> self jitter)))
        (set! (-> a0-0 frame-interp 1) f0-0)
        (set! (-> a0-0 frame-interp 0) f0-0)
        )
      (set! (-> a0-0 frame-group) (the-as art-joint-anim mh-flyer-fly-fast0-jitter-ja))
      (set! (-> a0-0 param 0) 0.0)
      (set! (-> a0-0 frame-num) (-> self skel root-channel 0 frame-num))
      (joint-control-channel-group! a0-0 (the-as art-joint-anim mh-flyer-fly-fast0-jitter-ja) num-func-chan)
      )
    (if (= (-> self hit-points) 0.0)
        (go-virtual die)
        )
    )
  :code sleep-code
  :post (behavior ()
    (ja :num! (loop!))
    (seek! (-> self jitter) 0.0 (* 4.0 (seconds-per-frame)))
    (when (>= (-> self missiles-fired) 3)
      (set! (-> self last-fire-time) (+ (current-time) (seconds 5)))
      (set! (-> self missiles-fired) 0)
      0
      )
    (when (time-elapsed? (-> self state-time) (seconds 2))
      (let ((f0-5 (vector-vector-xz-distance (-> self root trans) (target-pos 0))))
        (when (and (< f0-5 1228800.0)
                   (< 286720.0 f0-5)
                   (and (time-elapsed? (-> self last-fire-time) (seconds 0.6))
                        (< 0.0 (vector-dot (-> self rotation-matrix fvec) (-> self focus-xz-dir)))
                        )
                   )
          (let ((gp-1 (new 'stack-no-clear 'projectile-init-by-other-params)))
            (set! (-> gp-1 ent) (-> self entity))
            (set! (-> gp-1 charge) (lerp-scale 0.0 1.0 (the float (-> self missiles-fired)) 0.0 3.0))
            (set! (-> gp-1 options) (projectile-options))
            (logclear! (-> gp-1 options) (projectile-options po14 po15 po16))
            (vector-copy! (-> gp-1 pos) (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node mh-flyer-lod0-jg jaw)))
            (set! (-> gp-1 notify-handle) (the-as handle #f))
            (set! (-> gp-1 owner-handle) (the-as handle #f))
            (set! (-> gp-1 target-handle) (the-as handle #f))
            (set! (-> gp-1 target-pos quad) (the-as uint128 0))
            (set! (-> gp-1 ignore-handle) (process->handle self))
            (let* ((v1-39 *game-info*)
                   (a0-16 (+ (-> v1-39 attack-id) 1))
                   )
              (set! (-> v1-39 attack-id) a0-16)
              (set! (-> gp-1 attack-id) a0-16)
              )
            (set! (-> gp-1 timeout) (seconds 4))
            (vector-z-quaternion! (-> gp-1 vel) (-> self root quat))
            (vector-normalize! (-> gp-1 vel) 327680.0)
            (set! (-> gp-1 vel y) (+ 81920.0 (* 54613.336 (the float (-> self missiles-fired))) (-> gp-1 vel y)))
            (vector-normalize! (-> gp-1 vel) 327680.0)
            (spawn-projectile mh-flyer-shot gp-1 self *default-dead-pool*)
            )
          (set-time! (-> self last-fire-time))
          (+! (-> self missiles-fired) 1)
          (when (time-elapsed? (-> self last-player-screech) (seconds 6))
            (sound-play "flyer-screech")
            (set-time! (-> self last-player-screech))
            )
          )
        )
      )
    (if (= (-> self path-pos) (+ (-> self des-path node-count) -1))
        (go empty-state)
        )
    (let ((a1-10 (-> self des-path node (-> self path-pos))))
      (vector-copy! (-> self move-dest) (-> a1-10 position))
      (if (< (vector-vector-distance (-> self root trans) (-> a1-10 position)) 327680.0)
          (+! (-> self path-pos) 1)
          )
      )
    (let ((a0-30 (-> self target-velocity)))
      (vector-! a0-30 (-> self move-dest) (-> self root trans))
      (vector-normalize! a0-30 245760.0)
      )
    (mh-flyer-fly-post)
    )
  )

(defstate die (mh-flyer)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (when (-> self minimap)
      (logior! (-> self minimap flags) (minimap-flag fade-out))
      (set! (-> self minimap) #f)
      )
    (send-event (ppointer->process (-> self parent)) 'flyer-died)
    (on-dying self)
    )
  :code (behavior ()
    (local-vars (v1-14 object))
    (let ((gp-0 (-> self root transv)))
      (vector-copy! gp-0 (-> self target-velocity))
      (vector-length-max! gp-0 245760.0)
      (set! (-> gp-0 y) (fmax -163840.0 (fmin 163840.0 (-> gp-0 y))))
      (vector-float*! gp-0 gp-0 0.5)
      )
    (ragdoll-spawn! self #f #t)
    (until v1-14
      (let ((gp-1 (-> self root transv)))
        (vector-v++! (-> self root trans) gp-1)
        (vector-float*! gp-1 gp-1 0.92)
        )
      (enemy-simple-post)
      (suspend)
      (set! v1-14 (or (ragdoll-settled? self) (time-elapsed? (-> self state-time) (seconds 4))))
      )
    (if (-> self skel effect)
        (do-effect (-> self skel effect) "death-default" 0.0 -1)
        )
    (suspend-for (seconds 2)
      )
    (cleanup-for-death self)
    )
  )

;; WARN: Return type mismatch int vs process.
(defmethod update-focus ((this mh-flyer))
  "Potentially update the focus, if there is something better to focus on."
  (let ((t9-0 (method-of-type enemy update-focus)))
    (t9-0 this)
    )
  (let ((s5-0 (the-as target (as-type *target* process-focusable))))
    (when s5-0
      (vector-copy! (-> this focus-bullseye-pos) (get-trans s5-0 3))
      (vector-copy! (-> this focus-pos) (get-trans s5-0 3))
      (vector-! (-> this focus-xz-dir) (-> this focus-pos) (-> this root trans))
      (set! (-> this focus-xz-dir y) 0.0)
      (vector-xz-normalize! (-> this focus-xz-dir) 1.0)
      )
    )
  (the-as process 0)
  )

(defmethod mh-flyer-method-157 ((this mh-flyer))
  (cond
    ((and (-> this draw shadow)
          (zero? (-> this draw cur-lod))
          (logtest? (-> this draw status) (draw-control-status on-screen))
          )
     (new 'stack-no-clear 'vector)
     (new 'stack-no-clear 'vector)
     (let ((s4-0 (new 'stack-no-clear 'collide-query))
           (gp-0 (new 'stack-no-clear 'vector))
           )
       (set! (-> gp-0 x) 0.0)
       (set! (-> gp-0 y) -1.0)
       (set! (-> gp-0 z) 0.0)
       (set! (-> gp-0 w) 0.0)
       (let ((f30-0 163840.0))
         (vector-copy! (-> s4-0 start-pos) (-> this root trans))
         (vector-normalize-copy! (-> s4-0 move-dist) gp-0 f30-0)
         (let ((v1-11 s4-0))
           (set! (-> v1-11 radius) 3276.8)
           (set! (-> v1-11 collide-with) (collide-spec backgnd))
           (set! (-> v1-11 ignore-process0) this)
           (set! (-> v1-11 ignore-process1) #f)
           (set! (-> v1-11 ignore-pat)
                 (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                 )
           (set! (-> v1-11 action-mask) (collide-action solid))
           )
         (let ((f0-5 (fill-and-probe-using-line-sphere *collide-cache* s4-0)))
           (cond
             ((>= f0-5 0.0)
              (let ((v1-15 (-> this draw shadow-ctrl)))
                (logclear! (-> v1-15 settings flags) (shadow-flags disable-draw))
                )
              0
              (-> s4-0 best-other-tri intersect)
              (let ((a1-3 (-> this root trans)))
                (-> a1-3 y)
                (let ((f1-2 (* f0-5 f30-0)))
                  (shadow-control-method-14
                    (-> this draw shadow-ctrl)
                    a1-3
                    gp-0
                    (fmax 163840.0 (* 1638400.0 f0-5))
                    (+ -20480.0 f1-2)
                    (+ 20480.0 f1-2)
                    )
                  )
                )
              )
             (else
               (let ((v1-27 (-> this draw shadow-ctrl)))
                 (logior! (-> v1-27 settings flags) (shadow-flags disable-draw))
                 )
               0
               )
             )
           )
         )
       )
     )
    (else
      (let ((v1-30 (-> this draw shadow-ctrl)))
        (logior! (-> v1-30 settings flags) (shadow-flags disable-draw))
        )
      0
      )
    )
  0
  (none)
  )

(defmethod enemy-common-post ((this mh-flyer))
  "Common implementation of post. Runs ja-post."
  (quaternion->matrix (-> this rotation-matrix) (-> this root quat))
  (mh-flyer-method-157 this)
  ((method-of-type enemy enemy-common-post) this)
  (none)
  )

(defmethod event-handler ((this mh-flyer) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  "Commmon handler for events."
  (case arg2
    (('attack)
     (-> arg3 param 1)
     (seek! (-> this jitter) 1.0 (* 500.0 (seconds-per-frame)))
     (set! (-> this hit-points) (seek (-> this hit-points) 0.0 (* 15.0 (seconds-per-frame))))
     )
    (('death-start 'death-end)
     (call-parent-method this arg0 arg1 arg2 arg3)
     )
    )
  )

(defmethod go-fallback-init ((this mh-flyer))
  "If there's no specific settings for initial state, go to this state after spawning."
  (let ((v1-1 (res-lump-value (-> this entity) 'extra-id uint128 :time -1000000000.0)))
    (cond
      ((zero? v1-1)
       (go (method-of-object this orbiting))
       )
      ((= (the-as uint v1-1) 1)
       (go (method-of-object this on-path))
       )
      )
    )
  )

(defmethod mh-flyer-method-158 ((this mh-flyer))
  (set! (-> this minimap) (add-icon! *minimap* this (the-as uint 13) (the-as int #f) (the-as vector #t) 0))
  0
  (none)
  )

(defmethod init-enemy-collision! ((this mh-flyer))
  "Typical place to construct collision shapes"
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrated-by)
          (penetrate
            generic-attack
            lunge
            flop
            punch
            spin
            roll
            uppercut
            bonk
            tube
            flut-attack
            board
            mech-punch
            dark-punch
            dark-smack
            flut
            )
          )
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 4) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 5))
      (set! (-> s4-0 prim-core collide-as) (collide-spec enemy))
      (set! (-> s4-0 prim-core collide-with) (collide-spec backgnd))
      (set! (-> s4-0 prim-core action) (collide-action solid semi-solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 32768.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-13 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-13 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-13 prim-core action) (collide-action solid))
      (set! (-> v1-13 transform-index) 3)
      (set-vector! (-> v1-13 local-sphere) 0.0 0.0 0.0 16384.0)
      )
    (let ((v1-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-15 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-15 prim-core action) (collide-action solid))
      (set! (-> v1-15 transform-index) 26)
      (set-vector! (-> v1-15 local-sphere) 0.0 0.0 0.0 8192.0)
      )
    (let ((v1-17 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-17 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-17 prim-core action) (collide-action solid))
      (set! (-> v1-17 transform-index) 4)
      (set-vector! (-> v1-17 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (set-vector!
      (-> (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0)) local-sphere)
      0.0
      0.0
      0.0
      24576.0
      )
    (set! (-> s5-0 nav-radius) 8192.0)
    (let ((v1-21 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-21 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-21 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 3))
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod init-enemy! ((this mh-flyer))
  "Typical place for shared init code. Runs from entity or process style init."
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-mh-flyer" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (setup-enemy! this *mh-flyer-enemy-info*)
  (set! (-> this root pause-adjust-distance) 368640.0)
  (logclear! (-> this mask) (process-mask actor-pause))
  (logclear! (-> this enemy-flags) (enemy-flag actor-pause-backup))
  (set! (-> this draw shadow-ctrl) *mh-flyer-shadow-control*)
  (set! (-> this last-player-screech) 0)
  (let ((v1-12 (-> this neck)))
    (set! (-> v1-12 up) (the-as uint 1))
    (set! (-> v1-12 nose) (the-as uint 2))
    (set! (-> v1-12 ear) (the-as uint 0))
    (set-vector! (-> v1-12 twist-max) 11832.889 15473.777 0.0 1.0)
    (set! (-> v1-12 ignore-angle) 30947.555)
    )
  (set-vector! (-> this root scale) 0.75 0.75 0.75 1.0)
  0
  (none)
  )

(defbehavior mh-flyer-init-by-other mh-flyer ((arg0 level) (arg1 entity-actor) (arg2 desbeast-path) (arg3 quaternion) (arg4 handle))
  (set! (-> self level) arg0)
  (set! (-> self entity) arg1)
  (set! (-> self manager) arg4)
  (init-enemy-collision! self)
  (vector-copy! (-> self root trans) (-> arg2 node 0 position))
  (quaternion-copy! (-> self root quat) arg3)
  (set! (-> self des-path) arg2)
  (init-enemy! self)
  (mh-flyer-method-158 self)
  (go-virtual on-path)
  )
