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

;; name: protect-gunship.gc
;; name in dgo: protect-gunship
;; dgos: LCTYPROT

(define-extern *range-ffexplo-dust-color* curve-color-fast)
(define-extern *range-ffexplo-dust-alpha* curve2d-fast)
(define-extern *range-ffexplo-dust-scale-x* curve2d-fast)
(define-extern *range-ffexplo-dust-scale-y* curve2d-fast)
(define-extern *curve-ffexplo-dust-alpha* curve2d-fast)
(define-extern *curve-ffexplo-dust-scale-x* curve2d-fast)
(define-extern *curve-ffexplo-dust-scale-y* curve2d-fast)
(define-extern *range-gunship-explo-color* curve-color-fast)
(define-extern *range-gunship-explo-alpha* curve2d-fast)
(define-extern *range-gunship-explo-scale-x* curve2d-fast)
(define-extern *range-gunship-explo-scale-y* curve2d-fast)
(define-extern *curve-gunship-explo-alpha* curve2d-fast)
(define-extern *curve-gunship-explo-scale-x* curve2d-fast)
(define-extern *curve-gunship-explo-scale-y* curve2d-fast)
(define-extern *gunship-engine-lightning* lightning-appearance)

;; DECOMP BEGINS

(define *gunship-nav-mesh* (the-as actor-id #xe7d4))

(defpart 4752
  :init-specs ((:texture (pal-lightning level-default-sprite))
    (:birth-func 'birth-func-set-quat)
    (:num 1.0)
    (:scale-x (meters 1))
    (:scale-y (meters 1))
    (:r 128.0 64.0)
    (:g 128.0 64.0)
    (:b 128.0 64.0)
    (:a 128.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14 left-multiply-quat))
    )
  )

(defpart 4753
  :init-specs ((:texture (colorflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1) (meters 0.2))
    (:rot-x (degrees 2.25))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 128.0 64.0)
    (:b 128.0 64.0)
    (:a 64.0 64.0)
    (:omega (degrees 4511.25))
    (:rotvel-z (degrees 0.3))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 40.96)
    )
  )

(defpart 4754
  :init-specs ((:texture (rainbow-halo level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1.4) (meters 0.1))
    (:rot-x (degrees 6.7500005))
    (:scale-y :copy scale-x)
    (:r 0.0)
    (:g 0.0 30.0)
    (:b 128.0)
    (:a 128.0 128.0)
    (:omega (degrees 4511.25))
    (:rotvel-z (degrees 0.3))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 409.6)
    )
  )

(defpart 4755
  :init-specs ((:texture (motion-blur-part level-default-sprite))
    (:num 2.0 6.0)
    (:z (meters 0.1))
    (:scale-x (meters 0.1) (meters 0.2))
    (:rot-x 4)
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 32.0 1 128.0)
    (:g :copy r)
    (:b 255.0)
    (:a 255.0)
    (:omega (degrees 0.03375))
    (:vel-y (meters 0.033333335) (meters 0.033333335))
    (:fade-a -2.56 -2.56)
    (:friction 0.9)
    (:timer (seconds 0.167))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 launch-along-z left-multiply-quat))
    (:func 'sparticle-motion-blur)
    (:conerot-x (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 4756
  :init-specs ((:texture (starflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1) (meters 1))
    (:rot-x (degrees 2.25))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 128.0 64.0)
    (:b 128.0 64.0)
    (:a 64.0 64.0)
    (:omega (degrees 4511.25))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 40.96)
    )
  )

(defpartgroup group-gunship-laser-guard-hit
  :id 1450
  :duration (seconds 0.5)
  :linger-duration (seconds 1)
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 15)
  :parts ((sp-item 4757 :period (seconds 5) :length (seconds 0.085) :offset -10)
    (sp-item 4758 :fade-after (meters 60) :period (seconds 5) :length (seconds 0.1))
    (sp-item 4759 :fade-after (meters 60) :falloff-to (meters 60) :period (seconds 5) :length (seconds 0.335))
    (sp-item 4760 :fade-after (meters 200) :falloff-to (meters 200) :period (seconds 5) :length (seconds 0.167))
    (sp-item 4761 :period (seconds 5) :length (seconds 0.017) :offset -10)
    (sp-item 4762 :fade-after (meters 150) :falloff-to (meters 150) :period (seconds 5) :length (seconds 0.167))
    )
  )

(defpartgroup group-gunship-damage
  :id 1451
  :flags (sp0 sp4)
  :bounds (static-bspherem 0 0 0 20)
  :parts ((sp-item 4763 :flags (sp7)) (sp-item 4764 :flags (sp7)))
  )

(defpart 4763
  :init-specs ((:texture (topglow level-default-sprite))
    (:num 0.1)
    (:scale-x (meters 0.6) (meters 1))
    (:rot-z (degrees -20) (degrees 40))
    (:scale-y :copy scale-x)
    (:r 64.0)
    (:g 64.0)
    (:b 64.0)
    (:a 128.0)
    (:vel-y (meters 0.0033333334))
    (:scalevel-x (meters 0.006666667))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.21333334)
    (:accel-y (meters 0.00033333333) (meters 0.00033333333))
    (:friction 0.9)
    (:timer (seconds 2))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:conerot-x (degrees -5) (degrees 10))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 4764
  :init-specs ((:texture (explosion-nebula level-default-sprite))
    (:num 1.0 1.0)
    (:x (meters 0) (meters 0.5))
    (:y (meters 0.5))
    (:scale-x (meters 0.5) (meters 1))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 200.0 30.0)
    (:b 30.0)
    (:a 128.0)
    (:vel-y (meters 0.0033333334))
    (:scalevel-x (meters -0.0033333334) (meters -0.0033333334))
    (:scalevel-y (meters 0.0033333334) (meters 0.0033333334))
    (:fade-g -0.8)
    (:fade-b -0.2)
    (:fade-a -0.2 -0.6666667)
    (:accel-y (meters 0.00033333333) (meters 0.00033333333))
    (:friction 0.99)
    (:timer (seconds 0.5))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:conerot-x (degrees -5) (degrees 10))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpartgroup group-missile-beacon
  :id 1452
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 1)
  :parts ((sp-item 4765 :flags (is-3d sp3 sp7)))
  )

(defpart 4765
  :init-specs ((:texture (kg-rob-target-01 lctyprot-sprite))
    (:num 1.0)
    (:scale-x (meters 4.5))
    (:scale-y :copy scale-x)
    (:r 200.0)
    (:g 0.0 32.0)
    (:b 0.0)
    (:a 0.0)
    (:rotvel-y (degrees 3.6))
    (:fade-a 2.56)
    (:timer (seconds 2.667))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-3 left-multiply-quat))
    (:next-time (seconds 0.085))
    (:next-launcher 4766)
    (:rotate-y (degrees 90))
    )
  )

(defpart 4767
  :init-specs ((:texture (middot level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 2.5))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 0.0)
    (:b 0.0)
    (:a 128.0)
    (:timer (seconds 0.017))
    (:flags ())
    )
  )

(defpart 4766
  :init-specs ((:r 128.0)
    (:g :copy r)
    (:b :copy g)
    (:a 128.0)
    (:rotvel-y (degrees 0))
    (:fade-a 0.0)
    (:next-time (seconds 0.035))
    (:next-launcher 4768)
    )
  )

(defpart 4768
  :init-specs ((:r 128.0)
    (:g 0.0 32.0)
    (:b 0.0)
    (:a 64.0)
    (:scalevel-x (meters -0.04))
    (:rotvel-y (degrees -3.6))
    (:scalevel-y :copy scalevel-x)
    (:next-time (seconds 0.167))
    (:next-launcher 4769)
    )
  )

(defpart 4769
  :init-specs ((:scalevel-x (meters 0)) (:rotvel-y (degrees 0.15)) (:scalevel-y :copy scalevel-x))
  )

(defpart 4770
  :init-specs ((:scale-x (meters 2))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:a 128.0)
    (:scalevel-x (meters -0.001))
    (:rotvel-y (degrees 0.15))
    (:scalevel-y :copy scalevel-x)
    (:next-time (seconds 0.04))
    (:next-launcher 4771)
    )
  )

(defpart 4771
  :init-specs ((:r 128.0)
    (:a 64.0)
    (:scalevel-x (meters -0.001))
    (:rotvel-y (degrees 0.15))
    (:scalevel-y :copy scalevel-x)
    (:next-time (seconds 0.5))
    (:next-launcher 4770)
    )
  )

(defpartgroup group-grp-gunship-explosion
  :id 1453
  :duration (seconds 4)
  :flags (sp0 sp5)
  :bounds (static-bspherem 0 0 0 15)
  :parts ((sp-item 4773 :flags (sp3) :period (seconds 30) :length (seconds 0.017))
    (sp-item 4774 :period (seconds 30) :length (seconds 0.035))
    (sp-item 4775 :flags (sp3) :period (seconds 30) :length (seconds 0.017))
    (sp-item 4776 :period (seconds 30) :length (seconds 0.035))
    (sp-item 4777 :period (seconds 30) :length (seconds 0.035))
    (sp-item 4778 :flags (sp3) :period (seconds 30) :length (seconds 0.017))
    (sp-item 4779 :period (seconds 30) :length (seconds 0.167))
    (sp-item 4780 :period (seconds 30) :length (seconds 0.5))
    (sp-item 4781 :flags (sp3) :binding 4772)
    (sp-item 4781 :flags (sp3) :binding 4772)
    (sp-item 4781 :flags (sp3) :binding 4772)
    (sp-item 4781 :flags (sp3) :binding 4772)
    (sp-item 4781 :flags (sp3) :binding 4772)
    (sp-item 4772 :flags (sp2) :period (seconds 4) :length (seconds 2))
    (sp-item 4772 :flags (sp2) :period (seconds 4) :length (seconds 2))
    (sp-item 4772 :flags (sp2) :period (seconds 4) :length (seconds 2))
    (sp-item 4772 :flags (sp2) :period (seconds 4) :length (seconds 2))
    (sp-item 4772 :flags (sp2) :period (seconds 4) :length (seconds 2))
    )
  )

(defpart 4773
  :init-specs ((:texture (glow-soft level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 40))
    (:rot-x (degrees 225))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 128.0)
    (:b 40.0)
    (:a 64.0)
    (:fade-a -0.21333334)
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 40960.0)
    )
  )

(defpart 4774
  :init-specs ((:texture (hotdot level-default-sprite))
    (:num 10.0 10.0)
    (:scale-x (meters 1) (meters 1.2))
    (:rot-y (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 80.0 20.0)
    (:b 30.0)
    (:a 128.0)
    (:omega (degrees 0.1125))
    (:vel-y (meters 0.5) (meters 0.8333333))
    (:scalevel-x (meters -0.0016666667))
    (:scalevel-y :copy scalevel-x)
    (:fade-g -0.17777778)
    (:fade-b -0.06666667)
    (:fade-a -0.28444445 -0.28444445)
    (:friction 0.9)
    (:timer (seconds 1.5))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-3))
    (:func 'sparticle-motion-blur)
    (:conerot-x (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 4775
  :init-specs ((:texture (explosion-nebula level-default-sprite))
    (:num 30.0)
    (:scale-x (meters 5) (meters 5))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 160.0)
    (:b 40.0)
    (:a 128.0)
    (:vel-y (meters 0) (meters 0.13333334))
    (:scalevel-x (meters 0.016666668))
    (:scalevel-y :copy scalevel-x)
    (:fade-g -0.22857143)
    (:fade-b -0.08571429)
    (:fade-a -0.36571428 -0.36571428)
    (:friction 0.93)
    (:timer (seconds 1.167))
    (:flags (sp-cpuinfo-flag-3))
    (:conerot-x (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 4776
  :init-specs ((:texture (explosion-edge level-default-sprite))
    (:num 5.0)
    (:scale-x (meters 5) (meters 5))
    (:rot-y (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 8.0 8.0)
    (:g :copy r)
    (:b :copy r)
    (:a 64.0)
    (:vel-y (meters 0.6666667) (meters 0.26666668))
    (:scalevel-x (meters 0.06666667))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.10666667 -0.10666667)
    (:friction 0.7)
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:func 'sparticle-2d-spline-align-instant)
    (:conerot-x (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 4777
  :init-specs ((:texture (explosion-nebula level-default-sprite))
    (:birth-func 'birth-func-curve)
    (:num 30.0)
    (:scale-x (meters 1))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 1.0)
    (:g 1.0)
    (:b 128.0)
    (:a 128.0)
    (:vel-y (meters 0.1))
    (:friction 0.97)
    (:timer (seconds 2))
    (:flags (sp-cpuinfo-flag-13))
    (:userdata 0.0)
    (:func 'live-func-curve)
    (:conerot-x (degrees 0) (degrees 360))
    (:conerot-z (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(if #t
    (set! *range-ffexplo-dust-color* (new 'static 'curve-color-fast
                                       :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                       :ys (new 'static 'inline-array vector 4
                                         (new 'static 'vector :x 70.0 :y 70.0 :z 70.0 :w 128.0)
                                         (new 'static 'vector :x 40.0 :y 40.0 :z 40.0 :w 128.0)
                                         (new 'static 'vector :x 40.0 :y 40.0 :z 40.0 :w 128.0)
                                         (new 'static 'vector :x 40.0 :y 40.0 :z 40.0 :w 128.0)
                                         )
                                       :one-over-x-deltas (new 'static 'vector :x 1.0 :y 1.0 :z 1.0 :w 1.0)
                                       )
          )
    )

(if #t
    (set! *range-ffexplo-dust-alpha* (new 'static 'curve2d-fast
                                       :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                       :ys (new 'static 'vector :x 64.0 :y 32.0 :z 33.0 :w 34.0)
                                       :one-over-x-deltas (new 'static 'vector :x -32.0 :y 1.0 :z 1.0 :w 1.0)
                                       )
          )
    )

(if #t
    (set! *range-ffexplo-dust-scale-x* (new 'static 'curve2d-fast
                                         :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                         :ys (new 'static 'vector :x 16.0 :y 40.0 :z 41.0 :w 42.0)
                                         :one-over-x-deltas (new 'static 'vector :x 24.0 :y 1.0 :z 1.0 :w 1.0)
                                         )
          )
    )

(if #t
    (set! *range-ffexplo-dust-scale-y* (new 'static 'curve2d-fast
                                         :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                         :ys (new 'static 'vector :x 16.0 :y 40.0 :z 41.0 :w 42.0)
                                         :one-over-x-deltas (new 'static 'vector :x 24.0 :y 1.0 :z 1.0 :w 1.0)
                                         )
          )
    )

(if #t
    (set! *curve-ffexplo-dust-alpha* (new 'static 'curve2d-fast
                                       :xs (new 'static 'vector :y -0.7 :z -1.0 :w -2.0)
                                       :ys (new 'static 'vector :y 1.0 :w 1.0)
                                       :one-over-x-deltas (new 'static 'vector :x 1.4285715 :y -3.3333333 :z 1.0 :w 1.0)
                                       )
          )
    )

(if #t
    (set! *curve-ffexplo-dust-scale-x* (new 'static 'curve2d-fast
                                         :xs (new 'static 'vector :y -0.5 :z -1.0 :w -2.0)
                                         :ys (new 'static 'vector :x 0.2 :y 0.8 :z 1.2 :w 2.2)
                                         :one-over-x-deltas (new 'static 'vector :x 1.2 :y 0.8000001 :z 1.0 :w 1.0)
                                         )
          )
    )

(if #t
    (set! *curve-ffexplo-dust-scale-y* (new 'static 'curve2d-fast
                                         :xs (new 'static 'vector :y -0.5 :z -1.0 :w -2.0)
                                         :ys (new 'static 'vector :x 0.2 :y 0.8 :z 1.2 :w 2.2)
                                         :one-over-x-deltas (new 'static 'vector :x 1.2 :y 0.8000001 :z 1.0 :w 1.0)
                                         )
          )
    )

(define *part-grp-gunship-explosion-dust-in-curve-settings* (new 'static 'particle-curve-settings
                                                              :lifetime-base (seconds 0.5)
                                                              :lifetime-offset (seconds 1)
                                                              :flags (particle-curve-flags pcf0)
                                                              )
        )

(set! (-> *part-id-table* 4777 init-specs 14 initial-valuef)
      (the-as float *part-grp-gunship-explosion-dust-in-curve-settings*)
      )

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* color-start) *range-ffexplo-dust-color*)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* alpha-start) *range-ffexplo-dust-alpha*)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* scale-x-start) *range-ffexplo-dust-scale-x*)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* scale-y-start) *range-ffexplo-dust-scale-y*)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* r-scalar) #f)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* g-scalar) #f)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* b-scalar) #f)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* a-scalar) *curve-ffexplo-dust-alpha*)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* scale-x-scalar) *curve-ffexplo-dust-scale-x*)

(set! (-> *part-grp-gunship-explosion-dust-in-curve-settings* scale-y-scalar) *curve-ffexplo-dust-scale-y*)

(defpart 4779
  :init-specs ((:texture (explosion-edge level-default-sprite))
    (:num 5.0)
    (:scale-x (meters 6) (meters 3))
    (:rot-y (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 80.0 20.0)
    (:b 30.0)
    (:a 128.0)
    (:vel-y (meters 0.6666667) (meters 0.26666668))
    (:scalevel-x (meters 0.033333335))
    (:scalevel-y :copy scalevel-x)
    (:fade-g -0.17777778)
    (:fade-b -0.06666667)
    (:fade-a -0.28444445 -0.28444445)
    (:friction 0.7)
    (:timer (seconds 1.5))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-3))
    (:func 'sparticle-2d-spline-align-instant)
    (:conerot-x (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 4780
  :init-specs ((:texture (explo-texture level-default-sprite))
    (:birth-func 'birth-func-curve)
    (:num 8.0)
    (:x (meters -1) (meters 2))
    (:y (meters 0) (meters 2))
    (:scale-x (meters 1))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 128.0)
    (:vel-y (meters 0.13333334) (meters 0.06666667))
    (:friction 0.9)
    (:timer (seconds 1))
    (:flags ())
    (:userdata 0.0)
    (:func 'live-func-curve)
    (:conerot-x (degrees 20) (degrees 90))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(if #t
    (set! *range-gunship-explo-color* (new 'static 'curve-color-fast
                                        :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                        :ys (new 'static 'inline-array vector 4
                                          (new 'static 'vector :x 255.0 :y 255.0 :z 255.0 :w 128.0)
                                          (new 'static 'vector :x 255.0 :y 255.0 :z 255.0 :w 128.0)
                                          (new 'static 'vector :x 255.0 :y 255.0 :z 255.0 :w 128.0)
                                          (new 'static 'vector :x 255.0 :y 255.0 :z 255.0 :w 128.0)
                                          )
                                        :one-over-x-deltas (new 'static 'vector :x 1.0 :y 1.0 :z 1.0 :w 1.0)
                                        )
          )
    )

(if #t
    (set! *range-gunship-explo-alpha* (new 'static 'curve2d-fast
                                        :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                        :ys (new 'static 'vector :x 128.0 :y 128.0 :z 129.0 :w 130.0)
                                        :one-over-x-deltas (new 'static 'vector :y 1.0 :z 1.0 :w 1.0)
                                        )
          )
    )

(if #t
    (set! *range-gunship-explo-scale-x* (new 'static 'curve2d-fast
                                          :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                          :ys (new 'static 'vector :x 6.0 :y 10.0 :z 11.0 :w 12.0)
                                          :one-over-x-deltas (new 'static 'vector :x 4.0 :y 1.0 :z 1.0 :w 1.0)
                                          )
          )
    )

(if #t
    (set! *range-gunship-explo-scale-y* (new 'static 'curve2d-fast
                                          :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                          :ys (new 'static 'vector :x 6.0 :y 10.0 :z 11.0 :w 12.0)
                                          :one-over-x-deltas (new 'static 'vector :x 4.0 :y 1.0 :z 1.0 :w 1.0)
                                          )
          )
    )

(if #t
    (set! *curve-gunship-explo-alpha* (new 'static 'curve2d-fast
                                        :xs (new 'static 'vector :y -0.05 :z -0.7 :w -1.0)
                                        :ys (new 'static 'vector :y 1.0 :z 0.8)
                                        :one-over-x-deltas (new 'static 'vector :x 20.0 :y -0.3076923 :z -2.6666665 :w 1.0)
                                        )
          )
    )

(if #t
    (set! *curve-gunship-explo-scale-x* (new 'static 'curve2d-fast
                                          :xs (new 'static 'vector :y -0.8 :z -1.0 :w -2.0)
                                          :ys (new 'static 'vector :y 1.0 :z 1.5 :w 2.5)
                                          :one-over-x-deltas (new 'static 'vector :x 1.25 :y 2.5000002 :z 1.0 :w 1.0)
                                          )
          )
    )

(if #t
    (set! *curve-gunship-explo-scale-y* (new 'static 'curve2d-fast
                                          :xs (new 'static 'vector :y -0.8 :z -1.0 :w -2.0)
                                          :ys (new 'static 'vector :y 1.0 :z 1.5 :w 2.5)
                                          :one-over-x-deltas (new 'static 'vector :x 1.25 :y 2.5000002 :z 1.0 :w 1.0)
                                          )
          )
    )

(define *part-grp-gunship-explosion-texture-curve-settings* (new 'static 'particle-curve-settings
                                                              :lifetime-base (seconds 0.1)
                                                              :lifetime-offset (seconds 0.6)
                                                              :flags (particle-curve-flags pcf0)
                                                              )
        )

(set! (-> *part-id-table* 4780 init-specs 16 initial-valuef)
      (the-as float *part-grp-gunship-explosion-texture-curve-settings*)
      )

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* color-start) *range-gunship-explo-color*)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* alpha-start) *range-gunship-explo-alpha*)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* scale-x-start) *range-gunship-explo-scale-x*)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* scale-y-start) *range-gunship-explo-scale-y*)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* r-scalar) #f)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* g-scalar) #f)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* b-scalar) #f)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* a-scalar) *curve-gunship-explo-alpha*)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* scale-x-scalar) *curve-gunship-explo-scale-x*)

(set! (-> *part-grp-gunship-explosion-texture-curve-settings* scale-y-scalar) *curve-gunship-explo-scale-y*)

(defpart 4778
  :init-specs ((:texture (starflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 40))
    (:rot-x (degrees 2.25))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 80.0)
    (:b 40.0)
    (:a 128.0)
    (:omega (degrees 6767.9995))
    (:scalevel-x (meters -0.33333334))
    (:scalevel-y :copy scalevel-x)
    (:timer (seconds 0.135))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 4096.0)
    )
  )

(defpart 4781
  :init-specs ((:texture (hotdot level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 6) (meters 6))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 255.0)
    (:b 200.0)
    (:a 128.0)
    (:vel-y (meters 0.1) (meters 0.1))
    (:scalevel-x (meters -0.033333335) (meters -0.033333335))
    (:scalevel-y :copy scalevel-x)
    (:accel-y (meters -0.00066666666) (meters -0.00066666666))
    (:timer (seconds 2))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-3))
    (:conerot-x (degrees 0) (degrees 170))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 4772
  :init-specs ((:texture (explo-texture level-default-sprite))
    (:birth-func 'birth-func-inherit-size)
    (:num 1.0)
    (:scale-x (meters 0.00024414062) (meters 0.00012207031))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 128.0)
    (:b 32.0)
    (:a 128.0)
    (:fade-a -0.36571428 -0.36571428)
    (:accel-y (meters 0) (meters -0.00033333333))
    (:timer (seconds 1.167))
    (:flags (sp-cpuinfo-flag-3))
    )
  )

(defpartgroup group-protect-gunship-cannon-charge
  :id 1454
  :flags (sp12)
  :bounds (static-bspherem 0 0 0 1)
  :parts ((sp-item 4782 :flags (sp6)) (sp-item 4783 :flags (sp6)) (sp-item 4784))
  )

(defpart 4782
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 4) (meters 0.2))
    (:rot-x (degrees 1.125))
    (:scale-y :copy scale-x)
    (:r 0.0)
    (:g 32.0 8.0)
    (:b 255.0)
    (:a 50.0 10.0)
    (:rotvel-z (degrees 0.3))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 1.0)
    )
  )

(defpart 4783
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1) (meters 0.02))
    (:rot-x (degrees 1.125))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 255.0)
    (:b 255.0)
    (:a 64.0 5.0)
    (:rotvel-z (degrees 0.3))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 glow))
    (:userdata 1.0)
    )
  )

(defpart 4784
  :init-specs ((:texture (laser-hit2 level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 10) (meters 0.2))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 0.0 1 128.0)
    (:g :copy r)
    (:b 255.0)
    (:a 0.0)
    (:scalevel-x (meters -0.06666667))
    (:scalevel-y :copy scalevel-x)
    (:fade-a 0.4)
    (:timer (seconds 0.5))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:userdata 1.0)
    (:func 'spt-func-relative-pos)
    )
  )

(defpart 4785
  :init-specs ((:texture (gun-yellow-muzzleflash level-default-sprite))
    (:birth-func 'birth-func-set-quat)
    (:num 1.0)
    (:scale-x (meters 2))
    (:scale-y (meters 4))
    (:r 128.0 128.0)
    (:g 32.0 96.0)
    (:b :copy g)
    (:a 128.0 64.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(deftype fire-missile-state (structure)
  ((missile-dest-positions   vector  16 :inline)
   (missile-handles          handle  16)
   (beacon-handles           handle  16)
   (last-fire-missile-time   time-frame)
   (last-probe-missile-time  time-frame)
   (launcher-rotate-time     time-frame)
   (num-missiles             int8)
   (missile-launch-index     int8)
   (missile-probe-index      int8)
   (missile-shoot-index      int8)
   (current-probe-angle      float)
   (probe-angle-shift        float)
   (difficulty-scalar        float)
   )
  (:methods
    (init (_type_) none)
    )
  )


(deftype gunship-info (structure)
  ((proc         handle)
   (want-target  uint8)
   (cur-state    symbol)
   (difficulty   float)
   )
  )


(define *active-gunships*
  (new 'static 'inline-array gunship-info 2 (new 'static 'gunship-info) (new 'static 'gunship-info))
  )

(deftype gunship-movement-state (structure)
  ((state-time        time-frame)
   (next-update-time  time-frame)
   (cur-mode          uint8)
   (dest-mode         uint8)
   (dest-pos          vector  :inline)
   (completed?        symbol)
   )
  )


(deftype gunship-spawn-info (structure)
  ((counts           int8  17)
   (next-spawn-time  time-frame)
   )
  :pack-me
  (:methods
    (init (_type_) none)
    )
  )


(defskelgroup skel-protect-gunship kg-robot-transport kg-robot-transport-lod0-jg kg-robot-transport-idle-ja
              ((kg-robot-transport-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 12.5)
              :shadow kg-robot-transport-shadow-mg
              )

(define *gunship-door-joints* (new 'static 'boxed-array :type int32 4 5 6 7))

(define *gunship-engine-segs-undamaged* (new 'static 'boxed-array :type uint64 #x4 #x10 #x100 #x40))

(define *gunship-engine-segs-damaged* (new 'static 'boxed-array :type uint64 #x8 #x20 #x200 #x80))

(deftype protect-gunship (process-focusable)
  ((task-man                    handle)
   (missile-info                fire-missile-state        :inline)
   (stage-index                 int8)
   (num-stages                  int8)
   (hit-points                  float)
   (last-attack-id              uint32)
   (minimap                     connection-minimap)
   (ground-pt                   vector                    :inline)
   (basetrans                   vector                    :inline)
   (move-state                  gunship-movement-state    :inline)
   (reaction-time               time-frame)
   (choose-new-point-time       time-frame)
   (chosen-point                vector                    :inline)
   (last-repo-pos               vector                    :inline)
   (suppress-times              time-frame                8)
   (want                        uint8)
   (target                      uint8)
   (spawn-info                  gunship-spawn-info        :inline)
   (next-fire-missile-time      time-frame)
   (next-spin-laser-time        time-frame)
   (next-spawn-time             time-frame)
   (last-land-time              time-frame)
   (last-thrust-vec             vector                    :inline)
   (roll-quat                   quaternion                :inline)
   (difficulty                  float)
   (base-difficulty             float)
   (land-start-hp               float)
   (jmod-turret-twist           joint-mod-rotate-local    :inline)
   (jmod-turret-pitch           joint-mod-rotate-local    :inline)
   (jmod-doors                  joint-mod-rotate-local    4 :inline)
   (open-doors                  uint8)
   (num-open-doors              uint8)
   (last-door-index             uint8)
   (engines                     handle                    4)
   (rotate-start-time           time-frame)
   (rotate-total-time           time-frame)
   (rotate-rate                 float)
   (laser-rotate-speed          float)
   (current-laser-rotate-speed  float)
   (base-laser-dir              vector                    :inline)
   (next-new-laser-rot-time     time-frame)
   (laser-y                     float)
   (jmod-laser-descend          joint-mod-add-local       :inline)
   (num-hp-per-stage            float)
   (self-index                  int8)
   (other-ship-index            int8)
   (attacker-info               city-attacker-info)
   (difficulty-scalar           float)
   (sound-engine-loop           sound-id)
   (sound-lock-on               sound-id)
   (sound-lock-on-hi            sound-id)
   (alive-engines               uint8)
   (last-engine?                symbol)
   (desired-thruster-length     float)
   (last-thrust                 vector                    :inline)
   (smoke-parts                 sparticle-launch-control  4)
   )
  (:state-methods
    protect-gunship-base-state
    hover
    landed
    raising
    lowering
    enemy-spawning
    spinning-laser
    die
    )
  (:methods
    (spawn-missile (_type_ vector vector vector float int) handle)
    (protect-gunship-method-37 (_type_) int)
    (protect-gunship-method-38 (_type_ int float) none)
    (spawn-enemy (_type_ gunship-cmd-spawn-type) symbol)
    (update-nav-mesh (_type_) none)
    (gunship-post (_type_) none)
    (probe-ground (_type_) none)
    (protect-gunship-method-43 (_type_) none)
    (gunship-init (_type_) object)
    (gunship-handler (_type_ process int symbol event-message-block) object)
    (protect-gunship-method-46 (_type_) symbol)
    (protect-gunship-method-47 (_type_) none)
    (protect-gunship-method-48 (_type_ vector) symbol)
    (protect-gunship-method-49 (_type_) none)
    (protect-gunship-method-50 (_type_) object)
    (protect-gunship-method-51 (_type_) none)
    (protect-gunship-method-52 (_type_) quaternion)
    (open-doors (_type_) int)
    (protect-gunship-method-54 (_type_) float)
    (fire-laser (_type_ vector vector) object)
    (protect-gunship-method-56 (_type_ float) float)
    (protect-gunship-method-57 (_type_ int vector) vector)
    )
  )


(defskelgroup skel-protect-gunship-engine kg-robot-transport-bomb kg-robot-transport-bomb-lod0-jg kg-robot-transport-bomb-idle-ja
              ((kg-robot-transport-bomb-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 3.5)
              )

(deftype gunship-engine (process-focusable)
  ((hit-points      float)
   (child-index     int16)
   (last-attack-id  uint32)
   (attacker-info   city-attacker-info)
   (bolt            lightning-bolt)
   (hit-recently?   symbol)
   (last-hit-time   time-frame)
   )
  (:state-methods
    idle
    explode
    )
  (:methods
    (gunship-engine-method-30 (_type_) none)
    )
  )


(if (or (zero? *gunship-engine-lightning*) (!= loading-level global))
    (set! *gunship-engine-lightning* (new 'loading-level 'lightning-appearance))
    )

(set! (-> *gunship-engine-lightning* base-alpha) 1.0)

(set! (-> *gunship-engine-lightning* tex-id) (the-as uint #x408f00))

(set! (-> *gunship-engine-lightning* blend-mode) (the-as uint 1))

(set! (-> *gunship-engine-lightning* alpha-1-curve) *curve-linear-down*)

(set! (-> *gunship-engine-lightning* alpha-1-mode) (the-as uint 0))

(set! (-> *gunship-engine-lightning* alpha-1-repeat-dist) 262144.0)

(set! (-> *gunship-engine-lightning* alpha-2-curve) #f)

(set! (-> *gunship-engine-lightning* alpha-2-mode) (the-as uint 3))

(set! (-> *gunship-engine-lightning* alpha-2-repeat-dist) 4096.0)

(set! (-> *gunship-engine-lightning* width-curve) *curve-linear-down*)

(set! (-> *gunship-engine-lightning* width-mode) (the-as uint 3))

(set! (-> *gunship-engine-lightning* width-repeat-dist) 4096.0)

(set! (-> *gunship-engine-lightning* uv-repeat-dist) 28672.0)

(set! (-> *gunship-engine-lightning* regenerate-time-start) (seconds 0.167))

(set! (-> *gunship-engine-lightning* regenerate-time-end) (seconds 0.25))

(set! (-> *gunship-engine-lightning* width-range-start) 3072.0)

(set! (-> *gunship-engine-lightning* width-range-end) 3072.0)

(set! (-> *gunship-engine-lightning* fade-time) (seconds 0.1))

(set! (-> *gunship-engine-lightning* uv-shift?) #t)

(set! (-> *gunship-engine-lightning* uv-shift-speed) (seconds -0.5))

(set! (-> *gunship-engine-lightning* use-sprite-bucket?) #t)

(set! (-> *gunship-engine-lightning* use-accurate-interp?) #t)

(defbehavior gunship-engine-init-by-other gunship-engine ((arg0 int) (arg1 float))
  (stack-size-set! (-> self main-thread) 128)
  (logior! (-> self mask) (process-mask enemy))
  (set! (-> self child-index) arg0)
  (let ((s5-1 (new 'process 'collide-shape-moving self (collide-list-enum usually-hit-by-player))))
    (set! (-> s5-1 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-1 reaction) cshape-reaction-default)
    (set! (-> s5-1 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-1 penetrated-by) (penetrate))
    (let ((v1-10 (new 'process 'collide-shape-prim-sphere s5-1 (the-as uint 0))))
      (set! (-> v1-10 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-10 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-10 prim-core action) (collide-action solid))
      (set-vector! (-> v1-10 local-sphere) 0.0 0.0 0.0 6144.0)
      (set! (-> s5-1 total-prims) (the-as uint 1))
      (set! (-> s5-1 root-prim) v1-10)
      )
    (set! (-> s5-1 nav-radius) (* 0.75 (-> s5-1 root-prim local-sphere w)))
    (let ((v1-13 (-> s5-1 root-prim)))
      (set! (-> s5-1 backup-collide-as) (-> v1-13 prim-core collide-as))
      (set! (-> s5-1 backup-collide-with) (-> v1-13 prim-core collide-with))
      )
    (set! (-> self root) s5-1)
    )
  (initialize-skeleton
    self
    (the-as
      skeleton-group
      (art-group-get-by-name *level* "skel-protect-gunship-engine" (the-as (pointer level) #f))
      )
    (the-as pair 0)
    )
  (set! (-> self hit-points) arg1)
  (set! (-> self hit-recently?) #f)
  (set! (-> self attacker-info) (allocate-attacker *cty-attack-controller*))
  (init! (-> self attacker-info) self 13)
  (set! (-> self bolt) (new 'process 'lightning-bolt))
  (init! (-> self bolt) 2 10 *gunship-engine-lightning*)
  (go-virtual idle)
  )

;; WARN: Function (method 30 gunship-engine) has a return type of none, but the expression builder found a return statement.
(defmethod gunship-engine-method-30 ((this gunship-engine))
  (cond
    ((not (logtest? (-> this draw status) (draw-control-status on-screen)))
     (lightning-bolt-method-13 (-> this bolt) 3)
     (lightning-bolt-method-12 (-> this bolt))
     (return 0)
     )
    ((and (-> this next-state) (= (-> this next-state name) 'idle))
     (lightning-bolt-method-13 (-> this bolt) 0)
     )
    )
  (let ((s5-0 (-> this bolt)))
    (set-vector! (-> this draw color-mult) 0.75 0.75 0.75 1.0)
    (cond
      ((-> this hit-recently?)
       (set-vector! (-> this draw color-emissive) 1.0 1.0 1.0 0.0)
       )
      ((zero? (mod (the-as int (rand-uint31-gen *random-generator*)) 6))
       (set-vector! (-> this draw color-emissive) 0.15 0.15 0.3 0.0)
       )
      (else
        (set! (-> this draw color-emissive quad) (the-as uint128 0))
        )
      )
    (set! (-> s5-0 inner-point-travel-time) (seconds 0.417))
    (set! (-> s5-0 snap-inner-points?) #t)
    (set! (-> s5-0 fractal-reduction) 0.3)
    (set! (-> s5-0 generate-mode) (the-as uint 1))
    (set! (-> s5-0 appearance) *gunship-engine-lightning*)
    (set! (-> s5-0 num-active-spans) 1)
    (set! (-> s5-0 spans data 0 random-offset-size-start) 409.6)
    (set! (-> s5-0 spans-internal data 0 num-inner-points) 5)
    (set! (-> s5-0 spans data 0 inner-random-offset-size) 1228.8)
    (when (not (time-elapsed? (-> this last-hit-time) (seconds 0.3)))
      (let* ((f0-16 (* 0.011111111 (the float (- (current-time) (-> this last-hit-time)))))
             (f0-17 (* f0-16 f0-16))
             )
        (set! (-> s5-0 spans data 0 inner-random-offset-size)
              (* (-> s5-0 spans data 0 inner-random-offset-size) (lerp 5.0 1.0 f0-17))
              )
        )
      )
    (vector<-cspace! (-> s5-0 span-pts-start data 0) (-> this node-list data 4))
    (vector+float*!
      (-> s5-0 span-pts-start data 0)
      (-> s5-0 span-pts-start data 0)
      (-> this node-list data 4 bone transform fvec)
      819.2
      )
    (vector<-cspace! (-> s5-0 span-pts-start data 1) (-> this node-list data 5))
    (vector+float*!
      (-> s5-0 span-pts-start data 1)
      (-> s5-0 span-pts-start data 1)
      (-> this node-list data 4 bone transform fvec)
      819.2
      )
    (set! (-> s5-0 spans data 1 random-offset-size-start) 409.6)
    (set! (-> s5-0 spans-internal data 1 num-inner-points) 0)
    (lightning-bolt-method-11 s5-0)
    (lightning-bolt-method-12 s5-0)
    )
  (set! (-> this hit-recently?) #f)
  (none)
  )

(defmethod relocate ((this gunship-engine) (offset int))
  (if (nonzero? (-> this bolt))
      (&+! (-> this bolt) offset)
      )
  (call-parent-method this offset)
  )

(defmethod get-trans ((this gunship-engine) (arg0 int))
  "Get the `trans` for this process."
  (case arg0
    ((3)
     (let ((gp-1 (new 'static 'vector)))
       (vector-copy! gp-1 (-> this root trans))
       (vector+float*! gp-1 gp-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)) 1638.4)
       (vector+float*! gp-1 gp-1 (vector-y-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)) -6144.0)
       (set! (-> gp-1 w) 10240.0)
       gp-1
       )
     )
    (else
      (call-parent-method this arg0)
      )
    )
  )

(defstate explode (gunship-engine)
  :virtual #t
  :enter (behavior ()
    (lightning-bolt-method-13 (-> self bolt) 3)
    (gunship-engine-method-30 self)
    (sound-play "gship-fuel-expl")
    (when (type? (-> self root) collide-shape)
      (let ((v1-8 (-> self root root-prim)))
        (set! (-> v1-8 prim-core collide-as) (collide-spec))
        (set! (-> v1-8 prim-core collide-with) (collide-spec))
        )
      0
      )
    (logior! (-> self draw status) (draw-control-status no-draw))
    (transform-post)
    (logclear! (-> self mask) (process-mask enemy))
    (cond
      ((logtest? (-> group-gunship-target-explode flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-gunship-target-explode)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-gunship-target-explode)
        )
      )
    (cond
      ((logtest? (-> group-guard-shot-hit flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-guard-shot-hit)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-guard-shot-hit)
        )
      )
    (remove-attacker *cty-attack-controller* (-> self attacker-info))
    (send-event (ppointer->process (-> self parent)) 'engine-destroyed (-> self child-index))
    )
  :code sleep-code
  )

(defstate idle (gunship-engine)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (local-vars (v0-0 symbol))
    (case message
      (('attack)
       (let ((v1-1 (the-as attack-info (-> block param 1))))
         (when (!= (-> v1-1 id) (-> self last-attack-id))
           (set! (-> self last-attack-id) (-> v1-1 id))
           (let ((f0-1 (if (logtest? (attack-mask damage) (-> v1-1 mask))
                           (-> v1-1 damage)
                           (penetrate-using->damage (-> v1-1 penetrate-using))
                           )
                       )
                 )
             (if (= (-> proc type) gun-yellow-shot-3)
                 (set! f0-1 0.5)
                 )
             (set! (-> self hit-recently?) #t)
             (set-time! (-> self last-hit-time))
             (let ((f0-2 (fmin 6.0 f0-1)))
               (set! (-> self hit-points) (- (-> self hit-points) f0-2))
               )
             )
           (if (>= 0.0 (-> self hit-points))
               (go-virtual explode)
               )
           (return (the-as object #t))
           v0-0
           )
         )
       )
      )
    )
  :trans (behavior ()
    (send-event
      (ppointer->process (-> self parent))
      'child-engine-update
      (-> self child-index)
      (-> self root trans)
      (-> self root quat)
      )
    )
  :code sleep-code
  :post (behavior ()
    (logior! (-> self skel status) (joint-control-status sync-math))
    (transform-post)
    (gunship-engine-method-30 self)
    )
  )

(defmethod init ((this gunship-spawn-info))
  (dotimes (v1-0 17)
    (set! (-> this counts v1-0) 0)
    )
  (set! (-> this next-spawn-time) 0)
  0
  (none)
  )

(defun find-nearest-nav-mesh-protect ((arg0 vector) (arg1 float))
  (local-vars (sv-64 nav-poly) (sv-68 nav-mesh) (sv-72 float) (sv-76 vector))
  (set! sv-64 (new 'stack-no-clear 'nav-poly))
  (set! sv-68 (the-as nav-mesh #f))
  (set! sv-72 arg1)
  (set! sv-76 arg0)
  (set! (-> sv-64 data 20) (the-as uint 7))
  (dotimes (gp-0 (-> *level* length))
    (let ((v1-5 (-> *level* level gp-0)))
      (when (= (-> v1-5 status) 'active)
        (when (!= (-> v1-5 name) 'lctyprot)
          (let ((s5-0 (-> v1-5 bsp nav-meshes)))
            (when (nonzero? s5-0)
              (dotimes (s4-0 (-> s5-0 length))
                (let ((s3-0 (-> s5-0 s4-0 nav-mesh)))
                  (when s3-0
                    (vector-! (-> sv-64 vertex 0) sv-76 (the-as vector (-> s3-0 bounds)))
                    (let ((f0-1 (vector-length-squared (-> sv-64 vertex 0)))
                          (f1-0 (-> s3-0 bounds r))
                          )
                      (when (< f0-1 (* f1-0 f1-0))
                        (set! (-> sv-64 vertex1 x) (-> s3-0 nearest-y-threshold))
                        (nav-mesh-method-46 s3-0 sv-64)
                        (when (>= sv-72 (-> sv-64 vertex1 w))
                          (set! sv-72 (-> sv-64 vertex1 w))
                          (set! sv-68 s3-0)
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  sv-68
  )

(defbehavior gunship-event-handler protect-gunship ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (gunship-handler self arg0 arg1 arg2 arg3)
  )

(deftype protect-gunship-init-params (structure)
  ((pos                vector      :inline)
   (quat               quaternion  :inline)
   (task-man           handle)
   (script             pair)
   (num-stages         int8)
   (self-index         int8)
   (difficulty         float)
   (difficulty-scalar  float)
   )
  )


(deftype protect-gunship-enemy-spawn-params (structure)
  ((pos         vector      :inline)
   (quat        quaternion  :inline)
   (spawn-type  gunship-cmd-spawn-type)
   (parent      handle)
   )
  )


(define *gunship-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 32768.0)
                                           :top-plane (new 'static 'plane :y 1.0 :w -4096.0)
                                           )
                               )
  )

(defmethod gunship-init ((this protect-gunship))
  (set! (-> this alive-engines) (the-as uint 15))
  (set! (-> this last-engine?) #f)
  (set! (-> this hit-points) (* (the float (-> this num-stages)) (-> this num-hp-per-stage)))
  (set! (-> this minimap) (add-icon! *minimap* this (the-as uint 13) (the-as int #f) (the-as vector #t) 0))
  (probe-ground this)
  (let ((a0-4 (get-nav-mesh *gunship-nav-mesh*)))
    (when a0-4
      (add-process-drawable-to-nav-mesh a0-4 this #t)
      (update-nav-mesh this)
      )
    )
  (set! (-> this sound-engine-loop) (new-sound-id))
  (set! (-> this sound-lock-on) (new-sound-id))
  (set! (-> this sound-lock-on-hi) (new-sound-id))
  (quaternion-copy! (-> this roll-quat) (-> this root quat))
  (set! (-> this move-state cur-mode) (the-as uint 0))
  (set! (-> this move-state dest-mode) (the-as uint 0))
  (set! (-> this move-state completed?) #f)
  (init (-> this jmod-turret-twist) this (the-as uint 8) (joint-mod-base-flags attached))
  (init (-> this jmod-turret-pitch) this (the-as uint 9) (joint-mod-base-flags attached))
  (init (-> this jmod-laser-descend) this (the-as uint 16) (joint-mod-base-flags attached trans quat scale))
  (set! (-> this jmod-laser-descend transform scale y) -0.01)
  (dotimes (s5-0 4)
    (init
      (-> this jmod-doors s5-0)
      this
      (the-as uint (-> *gunship-door-joints* s5-0))
      (joint-mod-base-flags attached)
      )
    (quaternion-identity! (the-as quaternion (+ (the-as uint (-> this jmod-doors 0 rotation)) (* s5-0 32))))
    )
  (set! (-> this suppress-times (log2 16)) (+ (current-time) (seconds 4)))
  (set! (-> this suppress-times (log2 32)) (+ (current-time) (seconds 2)))
  (set! (-> this suppress-times (log2 128)) (+ (current-time) (seconds 10.1)))
  (set! (-> this suppress-times (log2 8)) (+ (current-time) (seconds 5)))
  (when (-> this draw shadow)
    (set! (-> this draw shadow-ctrl)
          (new 'process 'shadow-control -81920.0 81920.0 614400.0 (the-as vector #f) (shadow-flags shdf04) 245760.0)
          )
    (let ((v1-50 (-> this draw shadow-ctrl)))
      (logclear! (-> v1-50 settings flags) (shadow-flags disable-draw))
      )
    0
    (shadow-control-method-14
      (-> this draw shadow-ctrl)
      (-> this root trans)
      (-> this draw shadow-ctrl settings shadow-dir)
      -122880.0
      -40960.0
      40960.0
      )
    )
  (set! (-> this part) (create-launch-control group-protect-gunship-cannon-charge this))
  (let* ((s5-5 (-> this part))
         (s4-0 (method-of-object s5-5 set-local-space-info))
         (s3-0 (add-connection *part-local-space-engine* this local-space-proc-joint 17 0 0))
         )
    (let ((v1-65 (process->handle this)))
      (if (= v1-65 #f)
          (set! v1-65 (process->handle this))
          )
      (set! (-> (the-as particle-local-space-info s3-0) hand) (the-as handle v1-65))
      )
    (matrix-identity! (-> (the-as particle-local-space-info s3-0) mat-new))
    (matrix-identity! (-> (the-as particle-local-space-info s3-0) mat-prev))
    (set! (-> (the-as particle-local-space-info s3-0) flags) (part-local-space-flags))
    (s4-0 s5-5 (the-as particle-local-space-info s3-0))
    )
  (dotimes (s5-6 4)
    (set! (-> this smoke-parts s5-6) (create-launch-control group-gunship-damage this))
    )
  (go (method-of-object this raising))
  )

(defbehavior protect-gunship-init-by-other protect-gunship ((arg0 protect-gunship-init-params))
  (stack-size-set! (-> self main-thread) 256)
  (logclear! (-> self mask) (process-mask actor-pause))
  (set! (-> self level) (level-get *level* 'lctyprot))
  (let ((s5-0 (new 'process 'collide-shape-moving self (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))
    (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 obstacle))
      (set! (-> s4-0 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set! (-> s4-0 transform-index) 3)
      (set-vector! (-> s4-0 local-sphere) 0.0 18432.0 0.0 32768.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-19 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-19 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-19 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-19 prim-core action) (collide-action solid))
      (set! (-> v1-19 transform-index) 9)
      (set-vector! (-> v1-19 local-sphere) 0.0 2048.0 0.0 16384.0)
      )
    (let ((v1-21 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 1) (the-as uint 0))))
      (set! (-> v1-21 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-21 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-21 prim-core action) (collide-action solid))
      (set! (-> v1-21 transform-index) 3)
      (set-vector! (-> v1-21 local-sphere) 0.0 49152.0 0.0 21708.8)
      )
    (let ((v1-23 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 2) (the-as uint 0))))
      (set! (-> v1-23 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-23 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-23 prim-core action) (collide-action solid))
      (set! (-> v1-23 transform-index) 3)
      (set-vector! (-> v1-23 local-sphere) 0.0 18432.0 0.0 32768.0)
      )
    (let ((v1-25 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 3) (the-as uint 0))))
      (set! (-> v1-25 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-25 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-25 prim-core action) (collide-action solid))
      (set! (-> v1-25 transform-index) 3)
      (set-vector! (-> v1-25 local-sphere) 0.0 18432.0 0.0 36864.0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-28 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-28 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-28 prim-core collide-with))
      )
    (set! (-> s5-0 nav-radius) 32768.0)
    (set! (-> self root) s5-0)
    )
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-protect-gunship" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (set! (-> self task-man) (-> arg0 task-man))
  (set! (-> self self-index) (-> arg0 self-index))
  (set! (-> self other-ship-index) (logand (+ (-> self self-index) 1) 1))
  (set! (-> *active-gunships* (-> self self-index) proc) (process->handle self))
  (ja :group! (-> self draw art-group data 3) :num! (identity 1.0))
  (set! (-> self base-difficulty) (-> arg0 difficulty))
  (set! (-> self difficulty-scalar) (-> arg0 difficulty-scalar))
  (init (-> self missile-info))
  (vector-copy! (-> self root trans) (-> arg0 pos))
  (vector-copy! (-> self basetrans) (-> arg0 pos))
  (quaternion-copy! (-> self root quat) (-> arg0 quat))
  (set! (-> self num-stages) 4)
  (set-vector! (-> self root scale) 0.4 0.4 0.4 1.0)
  (set! (-> self num-hp-per-stage) (lerp 22.0 33.0 (-> self base-difficulty)))
  (set! (-> self num-hp-per-stage) (* (-> self num-hp-per-stage) (lerp 0.5 1.0 (-> self difficulty-scalar))))
  (dotimes (gp-1 4)
    (set! (-> self engines gp-1)
          (ppointer->handle
            (process-spawn gunship-engine gp-1 (-> self num-hp-per-stage) :name "gunship-engine" :to self)
            )
          )
    )
  (gunship-init self)
  )

(defmethod relocate ((this protect-gunship) (offset int))
  (dotimes (v1-0 4)
    (if (nonzero? (-> this smoke-parts v1-0))
        (&+! (-> this smoke-parts v1-0) offset)
        )
    )
  (call-parent-method this offset)
  )

(deftype gunship-exploder (process-drawable)
  ()
  (:state-methods
    explode
    )
  )


(defskelgroup skel-gunship-exploder kg-robot-transport-break kg-robot-transport-break-lod0-jg kg-robot-transport-break-idle-ja
              ((kg-robot-transport-break-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 80.5)
              )

(defstate explode (gunship-exploder)
  :virtual #t
  :code (behavior ()
    (ja-no-eval :group! (-> self draw art-group data 3) :num! (seek! max 0.5) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! max 0.5))
      )
    )
  :post ja-post
  )

(defbehavior gunship-exploder-init-by-other gunship-exploder ((arg0 vector) (arg1 quaternion))
  (set! (-> self root) (new 'process 'trsqv))
  (vector-copy! (-> self root trans) arg0)
  (quaternion-copy! (-> self root quat) arg1)
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-gunship-exploder" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (set-vector! (-> self root scale) 0.4 0.4 0.4 1.0)
  (go-virtual explode)
  )

(defstate die (protect-gunship)
  :virtual #t
  :enter (behavior ()
    (sound-stop (-> self sound-engine-loop))
    (kill-callback (-> *minimap* engine) (-> self minimap))
    (set! (-> *active-gunships* (-> self self-index) want-target) (the-as uint 0))
    (set! (-> *active-gunships* (-> self self-index) cur-state) 'die)
    (when (type? (-> self root) collide-shape)
      (let ((v1-9 (-> self root root-prim)))
        (set! (-> v1-9 prim-core collide-as) (collide-spec))
        (set! (-> v1-9 prim-core collide-with) (collide-spec))
        )
      0
      )
    (logior! (-> self draw status) (draw-control-status no-draw))
    (transform-post)
    (sound-play "gship-explode")
    (cond
      ((logtest? (-> group-grp-gunship-explosion flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-grp-gunship-explosion)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-grp-gunship-explosion)
        )
      )
    )
  :code (behavior ()
    (process-spawn gunship-exploder (-> self root trans) (-> self root quat) :name "gunship-exploder" :to self)
    (vector-copy! (-> self root trans) (-> self ground-pt))
    (let ((gp-1 (new 'static 'fact-info)))
      (set! (-> gp-1 process) self)
      (set! (-> gp-1 pickup-type) (pickup-type ammo-random))
      (set! (-> gp-1 pickup-amount) 15.0)
      (dotimes (s5-0 3)
        (set! (-> gp-1 pickup-spawn-amount) (the float (+ (logand (rand-uint31-gen *random-generator*) 1) 1)))
        (drop-pickup gp-1 #t *entity-pool* gp-1 0 #t)
        )
      (set! (-> gp-1 pickup-type) (pickup-type health))
      (set! (-> gp-1 pickup-spawn-amount) 1.0)
      (set! (-> gp-1 pickup-amount) 2.0)
      (drop-pickup gp-1 #t *entity-pool* gp-1 0 #t)
      )
    (suspend-for (seconds 5)
      )
    )
  )

(defmethod gunship-handler ((this protect-gunship) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('engine-destroyed)
     (let ((v0-0 (the-as object (logclear (-> this alive-engines) (ash 1 (the-as int (-> arg3 param 0)))))))
       (set! (-> this alive-engines) (the-as uint v0-0))
       v0-0
       )
     )
    (('child-engine-update)
     (let ((s2-0 (-> arg3 param 0))
           (s3-0 (-> arg3 param 1))
           (s5-0 (-> arg3 param 2))
           (s4-0 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> this root quat)))
           )
       (vector-rotate-around-axis!
         (-> s4-0 fvec)
         (-> s4-0 fvec)
         (+ 8192.0 (* 16384.0 (the float s2-0)))
         (-> s4-0 uvec)
         )
       (vector+float*! (the-as vector s3-0) (-> this root trans) (-> s4-0 fvec) 25804.8)
       (vector+float*! (the-as vector s3-0) (the-as vector s3-0) (-> s4-0 uvec) 8192.0)
       (quaternion-look-at! (the-as quaternion s5-0) (-> s4-0 fvec) *up-vector*)
       )
     #t
     )
    (('missile-die)
     (let ((v1-10 (-> arg3 param 0)))
       (if (and (>= (the-as int v1-10) 0) (< (the-as int v1-10) 16))
           (send-event (handle->process (-> this missile-info beacon-handles v1-10)) 'die)
           )
       )
     #t
     )
    (else
      #f
      )
    )
  )

(deftype gunship-missile (process-focusable)
  ((dest-pos        vector  :inline)
   (launch-dir      vector  :inline)
   (particle-trail  sparticle-subsampler)
   (travel-speed    float)
   (attack-time     float)
   (attack-id       uint32)
   (index           int16)
   (swoosh-sound    sound-id)
   )
  (:state-methods
    launch
    attack-targ
    explode
    )
  (:methods
    (gunship-missile-method-31 (_type_) none)
    (gunship-missile-method-32 (_type_) sound-id)
    )
  )


(defpart 4786
  :init-specs ((:texture (bigpuff level-default-sprite))
    (:birth-func 'birth-func-texture-group)
    (:num 1.0)
    (:scale-x (meters 0.5) (meters 0.5))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 150.0)
    (:g 150.0)
    (:b 150.0)
    (:a 30.0 30.0)
    (:scalevel-x (meters 0.01))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.2 -0.2)
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:userdata :data (new 'static 'boxed-array :type int32 20 1 0 #x400000 #x405c00))
    (:rotate-y (degrees 0))
    )
  )

(defskelgroup skel-gunship-missile cty-homing-missile cty-homing-missile-lod0-jg cty-homing-missile-idle-ja
              ((cty-homing-missile-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 3)
              :origin-joint-index 3
              )

(deftype gunship-missile-init-params (structure)
  ((pos           vector  :inline)
   (dest-pos      vector  :inline)
   (launch-dir    vector  :inline)
   (time-to-targ  float)
   (index         int16)
   )
  )


(defbehavior gunship-missile-init-by-other gunship-missile ((arg0 gunship-missile-init-params))
  (set! (-> self level) (level-get *level* 'lctyprot))
  (stack-size-set! (-> self main-thread) 256)
  (logclear! (-> self mask) (process-mask actor-pause))
  (let ((s5-0 (new 'process 'collide-shape-moving self (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))
    (let ((v1-12 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-12 prim-core collide-with) (collide-spec backgnd obstacle pusher))
      (set-vector! (-> v1-12 local-sphere) 0.0 0.0 0.0 8192.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-12)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-15 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-15 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-15 prim-core collide-with))
      )
    (set! (-> self root) s5-0)
    )
  (set! (-> self swoosh-sound) (new-sound-id))
  (let* ((v1-17 *game-info*)
         (a0-12 (+ (-> v1-17 attack-id) 1))
         )
    (set! (-> v1-17 attack-id) a0-12)
    (set! (-> self attack-id) a0-12)
    )
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-gunship-missile" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (vector-copy! (-> self root trans) (-> arg0 pos))
  (vector-copy! (-> self dest-pos) (-> arg0 dest-pos))
  (vector-copy! (-> self launch-dir) (-> arg0 launch-dir))
  (set! (-> self index) (-> arg0 index))
  (let ((a1-9 (matrix-f-compose (new 'stack-no-clear 'matrix) (-> self launch-dir))))
    (matrix->quaternion (-> self root quat) a1-9)
    )
  (let* ((s5-2 quaternion-rotate-local-z!)
         (s4-1 (-> self root quat))
         (s3-0 (-> self root quat))
         (f30-0 65536.0)
         (v1-31 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
         (v1-32 (the-as number (logior #x3f800000 v1-31)))
         )
    (s5-2 s4-1 s3-0 (* f30-0 (+ -1.0 (the-as float v1-32))))
    )
  (set! (-> self travel-speed)
        (/ (vector-vector-xz-distance (-> self root trans) (-> self dest-pos)) (-> arg0 time-to-targ))
        )
  self
  (set! (-> self particle-trail)
        (new 'process 'sparticle-subsampler *sp-particle-system-2d* (-> *part-id-table* 4786) 4.0)
        )
  (set-vector! (-> self root scale) 0.8 0.8 0.9 1.0)
  (ja-post)
  (go-virtual launch)
  )

(defstate launch (gunship-missile)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('attack-targ)
       (vector-copy! (-> self dest-pos) (the-as vector (-> block param 0)))
       (set! (-> self attack-time) (the float (-> block param 1)))
       (go-virtual attack-targ)
       )
      )
    )
  :trans (behavior ()
    (gunship-missile-method-31 self)
    (gunship-missile-method-32 self)
    )
  :code sleep-code
  :post ja-post
  )

(defstate attack-targ (gunship-missile)
  :virtual #t
  :enter (behavior ()
    (sound-play "gship-incoming")
    (set-time! (-> self state-time))
    (let ((gp-2 (vector-! (new 'stack-no-clear 'vector) (-> self dest-pos) (-> self root trans))))
      0.0
      (set! (-> self travel-speed) (/ (vector-normalize-ret-len! gp-2 1.0) (/ (-> self attack-time) 300)))
      (let ((a1-3 (matrix-f-compose (new 'stack-no-clear 'matrix) gp-2)))
        (matrix->quaternion (-> self root quat) a1-3)
        )
      )
    )
  :trans (behavior ()
    (gunship-missile-method-31 self)
    (gunship-missile-method-32 self)
    (if (time-elapsed? (-> self state-time) (the int (-> self attack-time)))
        (go-virtual explode)
        )
    )
  :code sleep-code
  :post ja-post
  )

(define *rand-missile-sound-list* (new 'static 'boxed-array :type string
                                    "missle-expl-1"
                                    "missle-expl-2"
                                    "missle-expl-3"
                                    "missle-expl-5"
                                    "missle-expl-6"
                                    )
        )

(defstate explode (gunship-missile)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    (sound-play-by-name
      (string->sound-name
        (-> *rand-missile-sound-list*
            (mod (the-as int (rand-uint31-gen *random-generator*)) (-> *rand-missile-sound-list* length))
            )
        )
      (new-sound-id)
      1024
      0
      0
      (sound-group)
      #t
      )
    (sound-stop (-> self swoosh-sound))
    (logior! (-> self draw status) (draw-control-status no-draw))
    (let ((v1-11 (-> self root root-prim)))
      (set! (-> v1-11 prim-core collide-as) (collide-spec))
      (set! (-> v1-11 prim-core collide-with) (collide-spec))
      )
    0
    (transform-post)
    (cond
      ((logtest? (-> group-gun-dark-shot-hit flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) (-> self dest-pos))
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-gun-dark-shot-hit)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self dest-pos))
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-gun-dark-shot-hit)
        )
      )
    (send-event (ppointer->process (-> self parent)) 'missile-die (-> self index))
    )
  :trans (behavior ()
    (if (time-elapsed? (-> self state-time) (seconds 0.35))
        (go empty-state)
        )
    (let ((gp-0 (new 'stack-no-clear 'vector)))
      0.0
      0.0
      (let* ((f1-2 (* 0.00952381 (the float (- (current-time) (-> self state-time)))))
             (f0-4 (fmax 0.0 (fmin 1.0 f1-2)))
             (f30-0 (lerp 10240.0 17920.0 f0-4))
             )
        (vector-copy! gp-0 (-> self dest-pos))
        (set! (-> gp-0 w) (* 2.0 f30-0))
        (let ((s5-0 (new 'stack-no-clear 'array 'collide-shape 384)))
          (countdown (s4-0 (fill-actor-list-for-box *actor-hash* gp-0 s5-0 384))
            (let ((v1-16 (as-type (-> s5-0 s4-0) collide-shape)))
              (when v1-16
                (let ((s3-1 (as-type (-> v1-16 process) process-focusable)))
                  (when s3-1
                    (if (and (logtest? (process-mask target crate enemy guard vehicle civilian) (-> s3-1 mask))
                             (not (focus-test? (the-as process-focusable s3-1) disable dead inactive))
                             (-> (the-as process-focusable s3-1) root root-prim)
                             (let ((f0-7
                                     (vector-vector-distance-squared
                                       (-> self dest-pos)
                                       (-> (the-as process-focusable s3-1) root root-prim prim-core world-sphere)
                                       )
                                     )
                                   (f1-4 f30-0)
                                   )
                               (< f0-7 (* f1-4 f1-4))
                               )
                             )
                        (send-event
                          s3-1
                          'attack
                          #f
                          (static-attack-info :mask (vehicle-impulse-factor) ((id (-> self attack-id))
                                                                              (damage (if (= (-> s3-1 type) target)
                                                                                          1.0
                                                                                          12.0
                                                                                          )
                                                                                      )
                                                                              (vehicle-damage-factor 1.0)
                                                                              (vehicle-impulse-factor 1.0)
                                                                              )
                                              )
                          )
                        )
                    )
                  )
                )
              )
            )
          )
        (let ((s5-1 (the-as target (as-type *target* process-focusable))))
          (when (and s5-1 (< (vector-vector-distance (get-trans s5-1 0) gp-0) (-> gp-0 w)))
            (if (and (logtest? (process-mask target crate enemy guard vehicle civilian) (-> s5-1 mask))
                     (not (focus-test? s5-1 disable dead inactive))
                     (-> s5-1 control root-prim)
                     (< (vector-vector-distance-squared (-> self dest-pos) (-> s5-1 control root-prim prim-core world-sphere))
                        (* f30-0 f30-0)
                        )
                     )
                (send-event
                  s5-1
                  'attack
                  #f
                  (static-attack-info :mask (vehicle-impulse-factor) ((id (-> self attack-id))
                                                                      (damage (if (= (-> s5-1 type) target)
                                                                                  1.0
                                                                                  12.0
                                                                                  )
                                                                              )
                                                                      (vehicle-damage-factor 1.0)
                                                                      (vehicle-impulse-factor 1.0)
                                                                      )
                                      )
                  )
                )
            )
          )
        )
      )
    )
  :code sleep-code
  )

;; WARN: Return type mismatch matrix vs none.
(defmethod gunship-missile-method-31 ((this gunship-missile))
  (let ((gp-0 (new 'stack-no-clear 'matrix)))
    (matrix-f-u-compose gp-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)) *up-vector*)
    (vector-copy! (-> gp-0 trans) (-> this root trans))
    (vector+float*! (-> gp-0 trans) (-> gp-0 trans) (-> gp-0 fvec) -3686.4)
    (vector+float*! (-> gp-0 trans) (-> gp-0 trans) (-> gp-0 fvec) -4096.0)
    (init-with-mat! (-> this particle-trail) gp-0)
    )
  (none)
  )

(defmethod gunship-missile-method-32 ((this gunship-missile))
  (let ((v1-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))))
    (vector+float*! (-> this root trans) (-> this root trans) v1-1 (* (-> this travel-speed) (seconds-per-frame)))
    (sound-play-by-name
      (static-sound-name "gship-mslstreak")
      (-> this swoosh-sound)
      1024
      (the int (* 1524.0 (doppler-pitch-shift
                           (-> this root trans)
                           (vector-float*! (new 'stack-no-clear 'vector) v1-1 (-> this travel-speed))
                           )
                  )
           )
      0
      (sound-group)
      #t
      )
    )
  )

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

;; WARN: Return type mismatch int vs handle.
(defmethod spawn-missile ((this protect-gunship) (arg0 vector) (arg1 vector) (arg2 vector) (arg3 float) (arg4 int))
  (let ((s5-0 (new 'stack-no-clear 'gunship-missile-init-params)))
    (vector-copy! (-> s5-0 pos) arg0)
    (vector-normalize-copy! (-> s5-0 launch-dir) arg1 1.0)
    (vector-copy! (-> s5-0 dest-pos) arg2)
    (set! (-> s5-0 index) arg4)
    (set! (-> s5-0 time-to-targ) arg3)
    (the-as handle (ppointer->handle (process-spawn gunship-missile s5-0 :name "gunship-missile" :to this)))
    )
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod init ((this fire-missile-state))
  (set! (-> this num-missiles) 0)
  (set! (-> this missile-launch-index) 0)
  (set! (-> this missile-probe-index) 0)
  (set! (-> this missile-shoot-index) 0)
  (dotimes (v1-0 16)
    (set! (-> this beacon-handles v1-0) (the-as handle #f))
    (set! (-> this missile-handles v1-0) (the-as handle #f))
    )
  (none)
  )

;; WARN: Return type mismatch time-frame vs none.
(defmethod protect-gunship-method-38 ((this protect-gunship) (arg0 int) (arg1 float))
  (init (-> this missile-info))
  (set! (-> this missile-info num-missiles) arg0)
  (let* ((f30-0 65536.0)
         (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
         (v1-5 (the-as number (logior #x3f800000 v1-4)))
         )
    (set! (-> this missile-info current-probe-angle) (* f30-0 (+ -1.0 (the-as float v1-5))))
    )
  (set! (-> this missile-info probe-angle-shift) (/ 65536.0 (the float arg0)))
  (set! (-> this missile-info difficulty-scalar) arg1)
  (set-time! (-> this missile-info launcher-rotate-time))
  (none)
  )

(define *missile-launch-locations* (new 'static 'boxed-array :type int16 10 11 12 13 14 15))

(defmethod protect-gunship-method-37 ((this protect-gunship))
  (if (zero? (-> this missile-info num-missiles))
      (return 0)
      )
  (when (not (time-elapsed? (-> this missile-info launcher-rotate-time) (seconds 0.5)))
    (let ((v1-7 (target-pos 0))
          (s5-0 (new 'stack-no-clear 'vector))
          )
      (vector-! s5-0 v1-7 (-> this root trans))
      (set! (-> s5-0 y) 0.0)
      (vector-float*! s5-0 s5-0 0.85)
      (set! (-> s5-0 y) 163840.0)
      (vector-normalize! s5-0 1.0)
      (let* ((f0-5 (- 16384.0 (acos (vector-dot s5-0 *up-vector*))))
             (f0-8
               (lerp 0.0 f0-5 (* 0.006666667 (the float (- (current-time) (-> this missile-info launcher-rotate-time)))))
               )
             (f30-1 (fmin 8192.0 f0-8))
             )
        (quaternion-rotate-x!
          (-> this jmod-turret-pitch rotation)
          (quaternion-identity! (new 'stack-no-clear 'quaternion))
          (- f30-1)
          )
        )
      )
    (return 0)
    )
  (when (and (>= (-> this missile-info missile-shoot-index) (-> this missile-info num-missiles))
             (time-elapsed? (-> this missile-info last-fire-missile-time) (seconds 0.6))
             )
    (dotimes (s5-2 (-> this missile-info num-missiles))
      (send-event (handle->process (-> this missile-info beacon-handles s5-2)) 'die)
      )
    (init (-> this missile-info))
    (remove-setting! 'string-min-height)
    (remove-setting! 'string-max-height)
    )
  (when (< (-> this missile-info missile-launch-index) (-> this missile-info num-missiles))
    (if (zero? (-> this missile-info missile-launch-index))
        (sound-play "gship-msllaunch")
        )
    (when (time-elapsed? (-> this missile-info last-fire-missile-time) (seconds 0.03))
      (let ((s3-0 (target-pos 0))
            (s4-1 (new 'stack-no-clear 'vector))
            (s5-4 (new 'stack-no-clear 'vector))
            )
        (vector<-cspace!
          s5-4
          (-> this
              node-list
              data
              (-> *missile-launch-locations*
                  (mod (-> this missile-info missile-launch-index) (-> *missile-launch-locations* length))
                  )
              )
          )
        (vector-! s4-1 s3-0 s5-4)
        (set! (-> s4-1 y) 0.0)
        (vector-float*! s4-1 s4-1 0.85)
        (set! (-> s4-1 y) 163840.0)
        (set! (-> this missile-info missile-handles (-> this missile-info missile-launch-index))
              (spawn-missile
                this
                s5-4
                s4-1
                (target-pos 0)
                (lerp 1.2 0.6 (-> this missile-info difficulty-scalar))
                (-> this missile-info missile-launch-index)
                )
              )
        )
      (set-time! (-> this missile-info last-fire-missile-time))
      (+! (-> this missile-info missile-launch-index) 1)
      )
    (return 0)
    )
  (if (and *target* (focus-test? *target* board))
      (set! (-> this missile-info difficulty-scalar) 1.2)
      )
  (when (and (< (-> this missile-info missile-probe-index) (-> this missile-info num-missiles))
             (time-elapsed? (-> this missile-info last-probe-missile-time) (seconds 0.03))
             )
    (let ((s5-5 (-> this missile-info missile-probe-index)))
      (when (zero? s5-5)
        (let ((v1-86 (the int (* 300.0 (lerp 1.2 0.6 (-> this missile-info difficulty-scalar))))))
          (+! (-> this missile-info last-fire-missile-time) v1-86)
          )
        )
      (let ((s4-3 (min 1 (- (-> this missile-info num-missiles) s5-5))))
        (set-time! (-> this missile-info last-probe-missile-time))
        (dotimes (s3-2 s4-3)
          (when *target*
            (let ((s2-1 (new 'stack-no-clear 'vector)))
              (vector-copy! s2-1 (get-trans *target* 1))
              0.0
              0.75
              (let ((f30-3 (vector-length (get-transv *target*)))
                    (f28-0 (lerp 0.0 0.75 (* 0.0625 (the float (-> this missile-info num-missiles)))))
                    )
                (if (focus-test? *target* board)
                    (set! f28-0 1.2)
                    )
                (let ((f26-0 (* 0.1875 (the float (-> this missile-info num-missiles)))))
                  (vector+float*! s2-1 s2-1 (get-transv *target*) f28-0)
                  (let* ((f28-1 (* f26-0 (-> this missile-info probe-angle-shift) (the float s5-5)))
                         (f26-1 8192.0)
                         (f24-0 8192.0)
                         (v1-115 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                         (v1-116 (the-as number (logior #x3f800000 v1-115)))
                         (f26-2 (+ f26-1 (* f24-0 (+ -1.0 (the-as float v1-116)))))
                         (s1-3 (new 'stack-no-clear 'vector))
                         )
                    (vector-copy! s1-3 *x-vector*)
                    0.0
                    (let* ((v1-121 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                           (v1-122 (the-as number (logior #x3f800000 v1-121)))
                           (f0-35 (- (* (+ -1.0 (the-as float v1-122)) (-> this missile-info probe-angle-shift))))
                           (f24-1 (/ f0-35 4))
                           (f0-38 (floor (the float (/ s5-5 3))))
                           (f2-0 (/ f30-3 (meters 15)))
                           (f1-15 (fmax 0.0 (fmin 1.0 f2-0)))
                           (f1-16 (* f1-15 f1-15))
                           (f0-39 (* f0-38 (- 1.0 f1-16)))
                           (f0-41 (* f26-2 (+ 0.75 f0-39)))
                           (f30-4 (fmin 40960.0 f0-41))
                           )
                      (vector-rotate-around-y! s1-3 s1-3 (+ f28-1 f24-1 (-> this missile-info current-probe-angle)))
                      (vector+float*! (-> this missile-info missile-dest-positions s5-5) s2-1 s1-3 f30-4)
                      )
                    )
                  )
                )
              )
            (let ((v1-138 (new 'stack-no-clear 'vector))
                  (s2-2 (new 'stack-no-clear 'collide-query))
                  )
              (vector-copy! v1-138 (-> this missile-info missile-dest-positions s5-5))
              (vector+float*! (-> s2-2 start-pos) v1-138 *up-vector* 24576.0)
              (set! (-> s2-2 move-dist quad) (the-as uint128 0))
              (set! (-> s2-2 move-dist y) -81920.0)
              (let ((v1-141 s2-2))
                (set! (-> v1-141 radius) 40.96)
                (set! (-> v1-141 collide-with) (collide-spec backgnd))
                (set! (-> v1-141 ignore-process0) #f)
                (set! (-> v1-141 ignore-process1) #f)
                (set! (-> v1-141 ignore-pat)
                      (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                      )
                (set! (-> v1-141 action-mask) (collide-action solid))
                )
              (if (>= (fill-and-probe-using-line-sphere *collide-cache* s2-2) 0.0)
                  (vector-copy! (-> this missile-info missile-dest-positions s5-5) (-> s2-2 best-other-tri intersect))
                  (set! (-> this missile-info missile-dest-positions s5-5 y) 0.0)
                  )
              )
            (sound-play "gship-bombscan")
            (let ((v1-152 (new 'stack-no-clear 'vector)))
              (vector-copy! v1-152 (-> this missile-info missile-dest-positions s5-5))
              (+! (-> v1-152 y) 409.6)
              (set! (-> this missile-info beacon-handles s5-5)
                    (ppointer->handle (cond
                                        ((logtest? (-> group-missile-beacon flags) (sp-group-flag sp13))
                                         (vector-copy! (-> *launch-matrix* trans) v1-152)
                                         (part-tracker-spawn part-tracker-subsampler :to this :group group-missile-beacon)
                                         )
                                        (else
                                          (vector-copy! (-> *launch-matrix* trans) v1-152)
                                          (part-tracker-spawn part-tracker :to this :group group-missile-beacon)
                                          )
                                        )
                                      )
                    )
              )
            (+! (-> this missile-info missile-probe-index) 1)
            (+! s5-5 1)
            )
          )
        )
      )
    )
  (when (and (< (-> this missile-info missile-shoot-index) (-> this missile-info num-missiles))
             (< (-> this missile-info missile-shoot-index) (-> this missile-info missile-probe-index))
             )
    (when (time-elapsed? (-> this missile-info last-fire-missile-time) (seconds 0.05))
      (set-time! (-> this missile-info last-fire-missile-time))
      (sound-stop (-> this sound-lock-on))
      (sound-play "gship-bomblock" :id (-> this sound-lock-on-hi))
      (send-event
        (handle->process (-> this missile-info missile-handles (-> this missile-info missile-shoot-index)))
        'attack-targ
        (-> this missile-info missile-dest-positions (-> this missile-info missile-shoot-index))
        180
        )
      (+! (-> this missile-info missile-shoot-index) 1)
      )
    )
  (cond
    ((or (< (-> this missile-info missile-shoot-index) (-> this missile-info num-missiles))
         (not (time-elapsed? (-> this missile-info last-fire-missile-time) (seconds 0.6)))
         )
     (set-setting! 'string-min-height 'abs (meters 8) 0)
     (set-setting! 'string-max-height 'abs (meters 8) 0)
     (dotimes (v1-221 (-> this missile-info missile-probe-index))
       )
     (the-as int #f)
     )
    (else
      (sound-stop (-> this sound-lock-on-hi))
      )
    )
  )

(defmethod spawn-enemy ((this protect-gunship) (arg0 gunship-cmd-spawn-type))
  (let ((s5-0 (new 'stack-no-clear 'protect-gunship-enemy-spawn-params)))
    (set! (-> s5-0 parent) (process->handle this))
    (case arg0
      (((gunship-cmd-spawn-type turret))
       (let ((v1-4 0))
         (dotimes (a0-6 4)
           (when (and (logtest? (-> this open-doors) (ash 1 a0-6))
                      (or (!= a0-6 (-> this last-door-index)) (>= (the-as uint 1) (-> this num-open-doors)))
                      )
             (set! v1-4 a0-6)
             (set! (-> this last-door-index) (the-as uint a0-6))
             0
             (goto cfg-21)
             )
           )
         (label cfg-21)
         (let ((v1-10
                 (vector<-cspace! (new 'stack-no-clear 'vector) (-> this node-list data (-> *gunship-door-joints* v1-4)))
                 )
               (s3-0 (new 'stack-no-clear 'vector))
               )
           (vector-! s3-0 v1-10 (-> this root trans))
           (set! (-> s3-0 y) 0.0)
           (vector+! (-> s5-0 pos) (-> this root trans) s3-0)
           (+! (-> s5-0 pos y) 12288.0)
           (vector-normalize! s3-0 1.0)
           (quaternion-look-at! (-> s5-0 quat) s3-0 *up-vector*)
           )
         )
       )
      (else
        (vector-copy! (-> s5-0 pos) (-> this root trans))
        (quaternion-copy! (-> s5-0 quat) (-> this root quat))
        )
      )
    (if (not (protect-gunship-method-48 this (-> s5-0 pos)))
        (return #f)
        )
    (set! (-> s5-0 spawn-type) arg0)
    (send-event (handle->process (-> this task-man)) 'gunship-spawn s5-0)
    )
  #t
  )

(defmethod probe-ground ((this protect-gunship))
  (let ((s5-0 (new 'stack-no-clear 'collide-query)))
    (vector-copy! (-> this ground-pt) (-> this basetrans))
    (vector+float*! (-> s5-0 start-pos) (-> this ground-pt) *up-vector* 24576.0)
    (set! (-> s5-0 move-dist quad) (the-as uint128 0))
    (set! (-> s5-0 move-dist y) -81920.0)
    (let ((v1-5 s5-0))
      (set! (-> v1-5 radius) 40.96)
      (set! (-> v1-5 collide-with) (collide-spec backgnd))
      (set! (-> v1-5 ignore-process0) #f)
      (set! (-> v1-5 ignore-process1) #f)
      (set! (-> v1-5 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-5 action-mask) (collide-action solid))
      )
    (if (>= (fill-and-probe-using-line-sphere *collide-cache* s5-0) 0.0)
        (vector-copy! (-> this ground-pt) (-> s5-0 best-other-tri intersect))
        (set! (-> this ground-pt y) 7372.8)
        )
    )
  0
  (none)
  )

(defmethod protect-gunship-method-57 ((this protect-gunship) (arg0 int) (arg1 vector))
  (let ((s5-0 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> this root quat))))
    (vector-rotate-around-axis!
      (-> s5-0 fvec)
      (-> s5-0 fvec)
      (+ 8192.0 (* 16384.0 (the float arg0)))
      (-> s5-0 uvec)
      )
    (vector+float*! arg1 (-> this root trans) (-> s5-0 fvec) 21708.8)
    )
  arg1
  )

(defmethod gunship-post ((this protect-gunship))
  (probe-ground this)
  (sound-play "gship-engn-loop" :id (-> this sound-engine-loop))
  (set-virtual-cur-pos! (-> this nav state) (-> this ground-pt))
  (protect-gunship-method-37 this)
  (set! (-> this want) (the-as uint 0))
  (set! (-> this target) (the-as uint 0))
  (vector-copy! (-> this root trans) (-> this basetrans))
  (let* ((f0-0 0.4)
         (f1-1 (* 0.0033333334 (the float (current-time))))
         (f0-1 (* f0-0 (- f1-1 (* (the float (the int (/ f1-1 2.5))) 2.5))))
         )
    (set! (-> this root trans y) (+ 1228.8 (* 1228.8 (cos (* 65536.0 f0-1))) (-> this basetrans y)))
    )
  (let ((s5-0 (new 'stack-no-clear 'vector)))
    (vector-copy! s5-0 (-> this last-thrust))
    0.0
    0.0
    (vector+! s5-0 s5-0 (-> this root transv))
    (vector-float*! s5-0 s5-0 0.5)
    (set! (-> s5-0 y) 0.0)
    (let* ((f0-11 (vector-normalize-ret-len! s5-0 1.0))
           (f1-6 (/ f0-11 (meters 25)))
           (f0-13 (fmax 0.0 (fmin 1.0 f1-6)))
           (f0-14 (* f0-13 f0-13))
           )
      (vector-cross! (new 'stack-no-clear 'vector) *up-vector* s5-0)
      (let ((f0-15 (* 2730.6667 f0-14))
            (s4-0 (new 'stack-no-clear 'quaternion))
            )
        (quaternion-vector-angle! s4-0 s5-0 f0-15)
        (quaternion-slerp! (-> this roll-quat) (-> this roll-quat) s4-0 (* 2.0 (seconds-per-frame)))
        )
      )
    )
  (let ((s5-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))))
    (set! (-> s5-1 y) 0.0)
    (vector-normalize! s5-1 1.0)
    (quaternion-look-at! (-> this root quat) s5-1 *up-vector*)
    )
  (quaternion*! (-> this root quat) (-> this roll-quat) (-> this root quat))
  (let ((s5-2 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)))
        (s4-2 (vector-! (new 'stack-no-clear 'vector) (-> this root trans) (target-pos 0)))
        )
    0.0
    (set! (-> s5-2 y) 0.0)
    (set! (-> s4-2 y) 0.0)
    (vector-normalize! s5-2 1.0)
    (vector-normalize! s4-2 1.0)
    (vector-float*! s5-2 s5-2 -1.0)
    (let ((a2-6
            (quaternion-rotate-y!
              (new 'stack-no-clear 'quaternion)
              (quaternion-identity! (new 'stack-no-clear 'quaternion))
              (- (vector-y-angle s4-2) (vector-y-angle s5-2))
              )
            )
          )
      (quaternion-slerp!
        (-> this jmod-turret-twist rotation)
        (-> this jmod-turret-twist rotation)
        a2-6
        (* 3.0 (seconds-per-frame))
        )
      )
    )
  (if (zero? (-> this missile-info num-missiles))
      (quaternion-slerp!
        (-> this jmod-turret-pitch rotation)
        (-> this jmod-turret-pitch rotation)
        (quaternion-identity! (new 'stack-no-clear 'quaternion))
        (* 2.0 (seconds-per-frame))
        )
      )
  (when (and (not (and (-> this next-state) (= (-> this next-state name) 'enemy-spawning)))
             (time-elapsed? (-> this spawn-info next-spawn-time) (seconds 1))
             )
    (when (> (-> this num-open-doors) 0)
      (sound-play "gship-doorclose")
      (set! (-> this num-open-doors) (the-as uint 0))
      0
      )
    (dotimes (s5-5 4)
      (quaternion-slerp!
        (the-as quaternion (+ (the-as uint (-> this jmod-doors 0 rotation)) (* s5-5 32)))
        (the-as quaternion (+ (the-as uint (-> this jmod-doors 0 rotation)) (* s5-5 32)))
        (quaternion-identity! (new 'stack-no-clear 'quaternion))
        (* 2.0 (seconds-per-frame))
        )
      )
    )
  (cond
    ((and (-> this next-state) (let ((v1-75 (-> this next-state name)))
                                 (or (= v1-75 'lowering) (= v1-75 'landed))
                                 )
          )
     (seek! (-> this desired-thruster-length) 4096.0 (* 8192.0 (seconds-per-frame)))
     )
    ((and (-> this next-state) (= (-> this next-state name) 'raising))
     (seek! (-> this desired-thruster-length) 22528.0 (* 24576.0 (seconds-per-frame)))
     )
    (else
      (let* ((f0-39 (vector-length (-> this last-thrust)))
             (f0-40 (lerp-scale-clamp 10240.0 16384.0 f0-39 12288.0 81920.0))
             )
        (seek! (-> this desired-thruster-length) f0-40 (* 12288.0 (seconds-per-frame)))
        )
      )
    )
  (set! (-> this hit-points) 0.0)
  (dotimes (s5-6 4)
    (let ((f0-45 (-> (the-as gunship-engine (handle->process (-> this engines s5-6))) hit-points)))
      (+! (-> this hit-points) (fmax 0.0 f0-45))
      (cond
        ((>= 0.0 f0-45)
         (setup-masks
           (-> this draw)
           (the-as int (-> *gunship-engine-segs-damaged* s5-6))
           (the-as int (-> *gunship-engine-segs-undamaged* s5-6))
           )
         (let ((a1-32 (protect-gunship-method-57 this s5-6 (new 'stack-no-clear 'vector))))
           (spawn (-> this smoke-parts s5-6) a1-32)
           )
         )
        (else
          (setup-masks
            (-> this draw)
            (the-as int (-> *gunship-engine-segs-undamaged* s5-6))
            (the-as int (-> *gunship-engine-segs-damaged* s5-6))
            )
          (let ((s4-6 (protect-gunship-method-57 this s5-6 (new 'stack-no-clear 'vector))))
            (let* ((f30-2 (-> this desired-thruster-length))
                   (f28-1 -1228.8)
                   (f26-0 2457.6)
                   (v1-117 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                   (v1-118 (the-as number (logior #x3f800000 v1-117)))
                   (f0-51 (+ f28-1 (* f26-0 (+ -1.0 (the-as float v1-118))) f30-2))
                   )
              (set! (-> *part-id-table* 4785 init-specs 4 initial-valuef) f0-51)
              (set! (-> *part-id-table* 4785 init-specs 3 initial-valuef) (/ f0-51 2))
              )
            (draw-beam
              (-> *part-id-table* 4785)
              s4-6
              (vector-float*!
                (new 'stack-no-clear 'vector)
                (vector-y-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))
                -20480.0
                )
              #f
              )
            )
          )
        )
      )
    )
  (when (>= 0.0 (-> this hit-points))
    (send-event (handle->process (-> this task-man)) 'gunship-destroyed)
    (go (method-of-object this die))
    )
  (set! (-> this stage-index)
        (- (-> this num-stages) (the int (ceil (/ (-> this hit-points) (-> this num-hp-per-stage)))))
        )
  (set! (-> this difficulty)
        (- 1.0 (/ (-> this hit-points) (* (the float (-> this num-stages)) (-> this num-hp-per-stage))))
        )
  (set! (-> this difficulty) (fmax 0.0 (fmin 1.0 (-> this difficulty))))
  (when (>= (-> this base-difficulty) 0.5)
    (set! (-> *active-gunships* (-> this self-index) difficulty) (-> this difficulty))
    (set! (-> this difficulty)
          (* 0.5 (+ (-> this difficulty) (-> *active-gunships* (-> this other-ship-index) difficulty)))
          )
    )
  (set! (-> this difficulty) (* (-> this difficulty) (-> this difficulty-scalar)))
  (if (not (and (-> this next-state) (= (-> this next-state name) 'spinning-laser)))
      (seek! (-> this jmod-laser-descend transform scale y) -0.01 (seconds-per-frame))
      )
  (transform-post)
  (none)
  )

;; WARN: Return type mismatch nav-callback-info vs none.
(defmethod update-nav-mesh ((this protect-gunship))
  (let ((a0-2 (get-nav-mesh *gunship-nav-mesh*)))
    (if (and nav-mesh (!= nav-mesh (-> this nav state mesh)))
        (change-to a0-2 this)
        )
    )
  (let ((a0-3 (-> this nav state))
        (v1-7 (-> this ground-pt))
        )
    (logclear! (-> a0-3 flags) (nav-state-flag directional-mode))
    (logior! (-> a0-3 flags) (nav-state-flag target-poly-dirty))
    (vector-copy! (-> a0-3 target-pos) v1-7)
    )
  0
  (set! (-> this nav flags) (nav-control-flag display-marks))
  (let ((v1-11 (-> this nav)))
    (set! (-> v1-11 sphere-mask) (the-as uint 0))
    )
  0
  (let ((v1-13 (-> this nav)))
    (set! (-> v1-13 target-speed) 4096.0)
    )
  0
  (let ((v1-15 (-> this nav)))
    (set! (-> v1-15 acceleration) 409600000.0)
    )
  0
  (let ((v1-17 (-> this nav)))
    (set! (-> v1-17 turning-acceleration) 40960000.0)
    )
  0
  (let ((v1-19 (-> this nav)))
    (set! (-> v1-19 speed-scale) 1.0)
    )
  0
  (let ((v1-21 (-> this nav)))
    (set! (-> v1-21 max-rotation-rate) 18204444.0)
    )
  0
  (set! (-> this nav callback-info) *default-nav-callback-info*)
  (none)
  )

(defstate protect-gunship-base-state (protect-gunship)
  :virtual #t
  :event gunship-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (set-time! (-> self reaction-time))
    )
  :trans (behavior ()
    (protect-gunship-method-47 self)
    )
  :code sleep-code
  :post (behavior ()
    (gunship-post self)
    )
  )

;; WARN: Return type mismatch time-frame vs none.
(defmethod protect-gunship-method-49 ((this protect-gunship))
  (let* ((f30-0 (lerp 0.25 1.2 (-> this difficulty)))
         (f28-0 10.0)
         (v1-2 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
         (v1-3 (the-as number (logior #x3f800000 v1-2)))
         (s5-0 (the int (+ f28-0 (* (+ -1.0 (the-as float v1-3)) (+ -10.0 (lerp 12.0 16.0 (-> this difficulty)))))))
         (f28-1 (lerp 7.5 5.5 (-> this difficulty)))
         )
    (protect-gunship-method-38 this s5-0 f30-0)
    (if (handle->process (-> *active-gunships* (-> this other-ship-index) proc))
        (set! f28-1 (* 2.0 f28-1))
        )
    (set! (-> this next-fire-missile-time) (+ (current-time) (the int (* 300.0 f28-1))))
    )
  (set! (-> this suppress-times (log2 32)) (+ (current-time) (seconds 2)))
  (set! (-> this suppress-times (log2 8)) (+ (current-time) (seconds 2)))
  (set! (-> this suppress-times (log2 128)) (+ (current-time) (seconds 2.5)))
  (none)
  )

(defmethod protect-gunship-method-50 ((this protect-gunship))
  (when (time-elapsed? (-> this reaction-time) (seconds 0.2))
    (cond
      ((logtest? (-> this target) 32)
       (go (method-of-object this enemy-spawning))
       )
      ((logtest? (-> this target) 64)
       (let ((v1-11 -1)
             (a0-2 0)
             )
         (dotimes (a1-0 4)
           (when (logtest? (-> this alive-engines) (ash 1 a1-0))
             (+! a0-2 1)
             (set! v1-11 a1-0)
             )
           )
         (cond
           ((= a0-2 1)
            (set! (-> this last-engine?) #t)
            (let ((a0-4 (new 'stack-no-clear 'vector))
                  (s5-0 (new 'stack-no-clear 'quaternion))
                  )
              (send-event this 'child-engine-update v1-11 a0-4 s5-0)
              (let ((s5-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) s5-0))
                    (s4-1 (vector-! (new 'stack-no-clear 'vector) (-> this root trans) (target-pos 0)))
                    )
                0.0
                (set! (-> s5-1 y) 0.0)
                (set! (-> s4-1 y) 0.0)
                (vector-normalize! s5-1 1.0)
                (vector-normalize! s4-1 1.0)
                (vector-float*! s5-1 s5-1 -1.0)
                (let ((f30-1 (- (vector-y-angle s4-1) (vector-y-angle s5-1))))
                  (format 0 "Doing inverse rotate~%")
                  (set! (-> this rotate-rate) (/ f30-1 4))
                  )
                )
              )
            (set-time! (-> this rotate-start-time))
            (let ((v0-0 (the-as object 1200)))
              (set! (-> this rotate-total-time) (the-as time-frame v0-0))
              v0-0
              )
            )
           (else
             (let* ((f30-2 5461.3335)
                    (f28-0 2730.6665)
                    (v1-23 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                    (v1-24 (the-as number (logior #x3f800000 v1-23)))
                    )
               (set! (-> this rotate-rate) (+ f30-2 (* f28-0 (+ -1.0 (the-as float v1-24)))))
               )
             (set-time! (-> this rotate-start-time))
             (set! (-> this rotate-total-time)
                   (the-as time-frame (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 1501) 900))
                   )
             (if (not (logtest? (rand-uint31-gen *random-generator*) 1))
                 (set! (-> this rotate-rate) (* -1.0 (-> this rotate-rate)))
                 )
             )
           )
         )
       )
      ((logtest? (-> this target) 128)
       (go (method-of-object this lowering))
       )
      ((logtest? (-> this target) 16)
       (protect-gunship-method-49 this)
       )
      ((logtest? (-> this target) 8)
       (go (method-of-object this spinning-laser))
       )
      )
    )
  )

(defmethod protect-gunship-method-54 ((this protect-gunship))
  (let ((f0-1 (lerp 5.0 8.0 (-> this base-difficulty))))
    (lerp 2.0 f0-1 (-> this difficulty))
    )
  )

;; WARN: Return type mismatch sound-id vs int.
(defmethod open-doors ((this protect-gunship))
  (with-pp
    (init (-> this spawn-info))
    0.0
    (let ((f30-0 (protect-gunship-method-54 this))
          (a1-0 (new 'stack-no-clear 'event-message-block))
          )
      (set! (-> a1-0 from) (process->ppointer pp))
      (set! (-> a1-0 num-params) 0)
      (set! (-> a1-0 message) 'count-active)
      (let* ((f1-0 (/ (the float (send-event-function (handle->process (-> this task-man)) a1-0)) f30-0))
             (f28-0 (fmax 0.0 (fmin 1.0 f1-0)))
             (v1-12 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-13 (the-as number (logior #x3f800000 v1-12)))
             (f26-0 (+ -1.0 (the-as float v1-13)))
             (f24-0 0.5)
             (v1-17 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-18 (the-as number (logior #x3f800000 v1-17)))
             (f24-1 (* f24-0 (+ -1.0 (the-as float v1-18))))
             (f22-0 2.0)
             (v1-22 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-23 (the-as number (logior #x3f800000 v1-22)))
             (f0-12 (* f22-0 (+ -1.0 (the-as float v1-23))))
             )
        0.0
        0.0
        (let* ((f1-8 (+ f26-0 f24-1 f0-12))
               (f22-1 (/ f26-0 f1-8))
               (f24-2 (/ f24-1 f1-8))
               (f26-1 (/ f0-12 f1-8))
               (f0-15 (lerp 1.0 f30-0 (- 1.0 f28-0)))
               )
          (set! (-> this spawn-info counts 9) (the int (the float (the int (+ 0.5 (* f0-15 f22-1))))))
          (set! (-> this spawn-info counts 10) (the int (the float (the int (+ 0.5 (* f0-15 f24-2))))))
          (set! (-> this spawn-info counts 11) (the int (the float (the int (+ 0.5 (* f0-15 f26-1))))))
          )
        )
      )
    (set! (-> this open-doors) (the-as uint 0))
    (set! (-> this num-open-doors) (the-as uint 0))
    (the-as
      int
      (when (> (-> this spawn-info counts 10) 0)
        (let ((f30-1 40960000.0)
              (f28-1 40960000.0)
              (s4-0 -1)
              (s5-0 -1)
              )
          (dotimes (s3-0 4)
            (let ((s2-0
                    (vector<-cspace! (new 'stack-no-clear 'vector) (-> this node-list data (-> *gunship-door-joints* s3-0)))
                    )
                  )
              0.0
              (let ((f0-23 (vector-vector-xz-distance (target-pos 0) s2-0)))
                (cond
                  ((< f0-23 f30-1)
                   (set! f28-1 f30-1)
                   (set! s5-0 s4-0)
                   (set! f30-1 f0-23)
                   (set! s4-0 s3-0)
                   )
                  ((< f0-23 f28-1)
                   (set! f28-1 f0-23)
                   (set! s5-0 s3-0)
                   )
                  )
                )
              )
            )
          (let ((s3-1
                  (vector<-cspace! (new 'stack-no-clear 'vector) (-> this node-list data (-> *gunship-door-joints* s4-0)))
                  )
                )
            (when (protect-gunship-method-48 this s3-1)
              (logior! (-> this open-doors) (ash 1 s4-0))
              (+! (-> this num-open-doors) 1)
              )
            (vector<-cspace! s3-1 (-> this node-list data (-> *gunship-door-joints* s5-0)))
            (when (protect-gunship-method-48 this s3-1)
              (+! (-> this num-open-doors) 1)
              (logior! (-> this open-doors) (ash 1 s5-0))
              )
            )
          )
        (when (and (= (-> this spawn-info counts 10) 1) (< (the-as uint 1) (-> this num-open-doors)))
          (set! (-> this num-open-doors) (the-as uint 1))
          (dotimes (v1-79 4)
            (when (logtest? (-> this open-doors) (ash 1 v1-79))
              (logclear! (-> this open-doors) (ash 1 v1-79))
              0
              (goto cfg-42)
              )
            )
          )
        (label cfg-42)
        (when (zero? (-> this num-open-doors))
          (set! (-> this spawn-info counts 10) 0)
          0
          )
        (if (> (-> this num-open-doors) 0)
            (sound-play "gship-dooropen")
            )
        )
      )
    )
  )

(defstate enemy-spawning (protect-gunship)
  :virtual #t
  :parent (protect-gunship protect-gunship-base-state)
  :enter (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 enter)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    (let ((a0-1 (-> self nav state))
          (v1-5 (-> self basetrans))
          )
      (logclear! (-> a0-1 flags) (nav-state-flag directional-mode))
      (logior! (-> a0-1 flags) (nav-state-flag target-poly-dirty))
      (vector-copy! (-> a0-1 target-pos) v1-5)
      )
    0
    (open-doors self)
    )
  :exit (behavior ()
    (set! (-> self suppress-times (log2 16)) (+ (current-time) (seconds 5)))
    (vector-copy! (-> self last-repo-pos) (-> self basetrans))
    (set! (-> self next-spawn-time) (+ (current-time) (the int (* 300.0 (lerp 7.5 5.0 (-> self difficulty))))))
    )
  :trans (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 trans)))
          (if t9-0
              (t9-0)
              )
          )
        )
      )
    (set! (-> self suppress-times (log2 16)) (+ (current-time) (seconds 5)))
    (cond
      ((and (not (time-elapsed? (-> self state-time) (seconds 0.5))) (> (-> self num-open-doors) 0))
       (dotimes (gp-1 4)
         (if (logtest? (-> self open-doors) (ash 1 gp-1))
             (quaternion-rotate-x!
               (the-as quaternion (+ (the-as uint (-> self jmod-doors 0 rotation)) (* gp-1 32)))
               (quaternion-identity! (new 'stack-no-clear 'quaternion))
               (* 103.158516 (the float (- (current-time) (-> self state-time))))
               )
             )
         )
       )
      (else
        (let ((gp-2 #f))
          (dotimes (s5-1 17)
            (when (> (-> self spawn-info counts s5-1) 0)
              (when (< (-> self spawn-info next-spawn-time) (current-time))
                (cond
                  ((spawn-enemy self (the-as gunship-cmd-spawn-type s5-1))
                   (set! (-> self spawn-info next-spawn-time) (+ (current-time) (seconds 0.5)))
                   (+! (-> self spawn-info counts s5-1) -1)
                   #t
                   )
                  (else
                    (logior! (-> self target) 2)
                    )
                  )
                )
              )
            )
          (dotimes (v1-43 17)
            (if (> (-> self spawn-info counts v1-43) 0)
                (set! gp-2 #t)
                )
            )
          (when (time-elapsed? (-> self spawn-info next-spawn-time) (seconds 1))
            (logior! (-> self target) 2)
            (protect-gunship-method-51 self)
            )
          (if (not gp-2)
              (go-virtual hover)
              )
          )
        )
      )
    )
  :post (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 post)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    (protect-gunship-method-52 self)
    )
  )

(defmethod protect-gunship-method-46 ((this protect-gunship))
  (when (time-elapsed? (-> this reaction-time) (seconds 0.2))
    (let ((f0-0 (vector-vector-xz-distance (-> this basetrans) (target-pos 0))))
      (or (< 327680.0 f0-0) (< f0-0 122880.0))
      )
    )
  )

;; ERROR: Unsupported inline assembly instruction kind - [mula.s f0, f3]
;; ERROR: Unsupported inline assembly instruction kind - [madda.s f1, f4]
;; ERROR: Unsupported inline assembly instruction kind - [madd.s f0, f2, f5]
(defun find-reposition-pt ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 int) (arg4 int) (arg5 float) (arg6 float))
  (local-vars
    (f0-16 float)
    (sv-32 int)
    (sv-40 float)
    (sv-44 float)
    (sv-48 vector)
    (sv-52 symbol)
    (sv-56 float)
    (sv-60 vector)
    (sv-64 float)
    (sv-68 float)
    (sv-72 float)
    (sv-76 float)
    (sv-80 float)
    (sv-144 (function vector vector float))
    (sv-160 vector)
    (sv-176 vector)
    (sv-192 vector)
    )
  (rlet ((vf0 :class vf)
         (vf4 :class vf)
         (vf5 :class vf)
         (vf6 :class vf)
         )
    (init-vf0-vector)
    (set! sv-32 -1)
    (let ((f0-0 409600000.0))
      (set! sv-40 (* f0-0 f0-0))
      )
    (set! sv-44 (the-as float 409600000.0))
    (set! sv-48 (new 'stack-no-clear 'vector))
    (set! sv-52 #t)
    (set! sv-56 (the-as float 0.0))
    (let ((v1-9 (the-as protect-gunship (handle->process (-> *active-gunships* arg4 proc)))))
      (when v1-9
        (vector-! sv-48 (-> v1-9 root trans) arg1)
        (set! (-> sv-48 y) 0.0)
        (set! sv-56 (vector-normalize-ret-len! sv-48 1.0))
        )
      )
    (dotimes (s0-0 (-> *protect-path* length))
      (set! sv-60 (-> *protect-path* s0-0))
      (set! sv-64 (vector-vector-xz-distance-squared arg2 (-> *protect-path* s0-0)))
      (set! sv-68 (vector-vector-xz-distance-squared arg1 (-> *protect-path* s0-0)))
      (set! sv-144 vector-vector-xz-distance-squared)
      (set! sv-160 (-> *protect-path* s0-0))
      (let ((a1-8 (target-pos 0)))
        (set! sv-72 (sv-144 sv-160 a1-8))
        )
      (set! sv-76 (the-as float 0.0))
      (set! sv-80 (the-as float 1.0))
      (set! sv-52 #t)
      (let ((v1-30 (the-as protect-gunship (handle->process (-> *active-gunships* arg4 proc)))))
        (when v1-30
          (set! sv-44 (vector-vector-xz-distance sv-60 (-> v1-30 root trans)))
          (set! sv-176 (new 'stack-no-clear 'vector))
          (let ((v1-34 sv-60)
                (a0-24 arg1)
                )
            (.lvf vf4 (&-> v1-34 quad))
            (.lvf vf5 (&-> a0-24 quad))
            )
          (.mov.vf.w vf6 vf0)
          (.sub.vf.xyz vf6 vf4 vf5)
          (.svf (&-> sv-176 quad) vf6)
          0.0
          (let ((a0-25 sv-176))
            (vector-copy! a0-25 sv-176)
            (set! (-> a0-25 y) 0.0)
            (vector-normalize! a0-25 1.0)
            )
          (let* ((v1-38 sv-48)
                 ; (f0-15 (-> sv-176 x))
                 ; (f1-0 (-> sv-176 y))
                 ; (f2-0 (-> sv-176 z))
                 ; (f3-0 (-> v1-38 x))
                 ; (f4-0 (-> v1-38 y))
                 ; (f5-0 (-> v1-38 z))
                 )
            ;; og:preserve-this
            ; (.mula.s f0-15 f3-0)
            ; (.madda.s f1-0 f4-0)
            ; (.madd.s f0-16 f2-0 f5-0)
            (set! f0-16 (vector-dot sv-176 v1-38))
            )
          (let ((f0-17 f0-16))
            (if (and (< 0.8 f0-17) (< sv-44 sv-56))
                (set! sv-52 (the-as symbol #f))
                )
            )
          )
        )
      (let ((f0-19 143360.0))
        (when (and (< (* f0-19 f0-19) sv-72)
                   (let ((f0-22 sv-72)
                         (f1-4 319488.0)
                         )
                     (< f0-22 (* f1-4 f1-4))
                     )
                   (and (< 102400.0 sv-44) sv-52)
                   )
          (when (or (not (logtest? arg3 2)) (let ((a0-32 (find-nearest-nav-mesh-protect sv-60 (the-as float #x7f800000))))
                                              (when a0-32
                                                (set! sv-192 (new 'stack-no-clear 'vector))
                                                (nav-mesh-method-10 a0-32 sv-192 sv-60 (the-as nav-poly #f))
                                                (let ((t9-9 vector-vector-xz-distance)
                                                      (a1-14 sv-60)
                                                      )
                                                  (< (t9-9 sv-192 a1-14) 4096.0)
                                                  )
                                                )
                                              )
                    )
            (when (or (not (logtest? arg3 6)) (let ((f0-25 arg5))
                                                (< (* f0-25 f0-25) sv-64)
                                                )
                      )
              (when (or (not (logtest? arg3 1)) (let ((f0-28 sv-72)
                                                      (f1-10 286720.0)
                                                      )
                                                  (and (< f0-28 (* f1-10 f1-10)) (let ((f0-29 163840.0))
                                                                                   (< (* f0-29 f0-29) sv-72)
                                                                                   )
                                                       )
                                                  )
                        )
                (let ((f0-32 sv-68)
                      (f1-14 arg6)
                      )
                  (set! sv-76 (fabs (- f0-32 (* f1-14 f1-14))))
                  )
                (let ((a0-35 (new 'stack 'sphere)))
                  (set! (-> a0-35 quad) (-> sv-60 quad))
                  (set! (-> a0-35 r) 20480.0)
                  (if (not (sphere-in-view-frustum? a0-35))
                      (set! sv-76 (* 100.0 sv-76))
                      )
                  )
                (when (< sv-76 sv-40)
                  (set! sv-40 sv-76)
                  (set! sv-32 s0-0)
                  )
                )
              )
            )
          )
        )
      )
    (cond
      ((< -1 sv-32)
       (-> *protect-path* sv-32)
       )
      (else
        (empty)
        arg1
        )
      )
    )
  )

(defmethod protect-gunship-method-51 ((this protect-gunship))
  (when (logtest? (-> this target) 7)
    (let ((v1-2 (find-reposition-pt
                  (new 'stack-no-clear 'vector)
                  (-> this basetrans)
                  (-> this last-repo-pos)
                  (the-as int (-> this target))
                  (-> this other-ship-index)
                  122880.0
                  122880.0
                  )
                )
          (a0-3 (-> this nav state))
          )
      (logclear! (-> a0-3 flags) (nav-state-flag directional-mode))
      (logior! (-> a0-3 flags) (nav-state-flag target-poly-dirty))
      (vector-copy! (-> a0-3 target-pos) v1-2)
      )
    0
    )
  (none)
  )

(defmethod fire-laser ((this protect-gunship) (arg0 vector) (arg1 vector))
  (let ((s5-0 (new 'stack-no-clear 'collide-query)))
    (vector-copy! (-> s5-0 start-pos) arg0)
    (vector-float*! (-> s5-0 move-dist) arg1 491520.0)
    (let ((v1-3 s5-0))
      (set! (-> v1-3 radius) 40.96)
      (set! (-> v1-3 collide-with) (collide-spec backgnd obstacle pusher))
      (set! (-> v1-3 ignore-process0) this)
      (set! (-> v1-3 ignore-process1) #f)
      (set! (-> v1-3 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-3 action-mask) (collide-action solid))
      )
    (let ((f0-2 (fill-and-probe-using-line-sphere *collide-cache* s5-0)))
      (if (>= f0-2 0.0)
          (vector-float*! (-> s5-0 move-dist) (-> s5-0 move-dist) f0-2)
          )
      )
    (set! (-> *part-id-table* 4752 init-specs 4 initial-valuef) (vector-length (-> s5-0 move-dist)))
    (draw-beam (-> *part-id-table* 4752) arg0 (-> s5-0 move-dist) #t)
    (launch-particles
      (-> *part-id-table* 4755)
      (vector+! (new 'stack-no-clear 'vector) (-> s5-0 move-dist) (-> s5-0 start-pos))
      )
    (launch-particles
      (-> *part-id-table* 4756)
      (vector+! (new 'stack-no-clear 'vector) (-> s5-0 move-dist) (-> s5-0 start-pos))
      )
    (let ((v1-19 s5-0))
      (set! (-> v1-19 radius) 40.96)
      (set! (-> v1-19 collide-with) (collide-spec jak civilian enemy hit-by-others-list player-list))
      (set! (-> v1-19 ignore-process0) this)
      (set! (-> v1-19 ignore-process1) #f)
      (set! (-> v1-19 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-19 action-mask) (collide-action solid))
      )
    (let ((f0-5 (fill-and-probe-using-line-sphere *collide-cache* s5-0)))
      (if (>= f0-5 0.0)
          (vector-float*! (-> s5-0 move-dist) (-> s5-0 move-dist) f0-5)
          (set! (-> s5-0 best-other-tri collide-ptr) #f)
          )
      )
    (when (and (-> s5-0 best-other-tri collide-ptr)
               (as-type (-> s5-0 best-other-tri collide-ptr) collide-shape-prim-sphere)
               )
      (let ((s5-2
              (-> (the-as collide-shape-prim-sphere (as-type (-> s5-0 best-other-tri collide-ptr) collide-shape-prim-sphere))
                  cshape
                  process
                  )
              )
            )
        (send-event
          s5-2
          'attack
          #f
          (static-attack-info
            :mask (vehicle-impulse-factor)
            ((id (new-attack-id)) (damage 1.0) (vehicle-damage-factor 1.0) (vehicle-impulse-factor 1.0) (mode 'shock))
            )
          )
        (send-event this 'notify 'attack s5-2)
        )
      )
    )
  )

(defstate spinning-laser (protect-gunship)
  :virtual #t
  :parent (protect-gunship protect-gunship-base-state)
  :enter (behavior ()
    (set! (-> self laser-y) (-> self root trans y))
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 enter)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    (vector-z-quaternion! (-> self base-laser-dir) (-> self root quat))
    (set! (-> self base-laser-dir y) 0.0)
    (vector-normalize! (-> self base-laser-dir) 1.0)
    (set! (-> self current-laser-rotate-speed) 0.0)
    (set! (-> self next-new-laser-rot-time) 0)
    (set! (-> self suppress-times (log2 16)) (+ (current-time) (seconds 3)))
    )
  :exit (behavior ()
    (set! (-> self next-spin-laser-time)
          (the-as time-frame (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 1501) 5250 (current-time)))
          )
    )
  :trans (behavior ()
    (set! (-> self suppress-times (log2 32)) (+ (current-time) (seconds 1)))
    (set! (-> self suppress-times (log2 64)) (+ (current-time) (seconds 1)))
    (set! (-> self suppress-times (log2 128)) (+ (current-time) (seconds 1.2)))
    (if (logtest? (-> self target) 16)
        (protect-gunship-method-49 self)
        )
    (let ((gp-3 #f))
      (let ((t9-4 vector-vector-xz-distance)
            (a0-4 (-> self basetrans))
            (a2-0 (-> self nav state))
            (a1-0 (new 'stack-no-clear 'vector))
            )
        (vector-copy! a1-0 (-> a2-0 target-pos))
        (if (< (t9-4 a0-4 a1-0) 20480.0)
            (vector-copy! (-> self last-repo-pos) (-> self basetrans))
            )
        )
      (when (time-elapsed? (-> self choose-new-point-time) (seconds 3))
        (set-time! (-> self choose-new-point-time))
        (set! gp-3 #t)
        )
      (when gp-3
        (let ((v1-30
                (find-reposition-pt
                  (new 'stack-no-clear 'vector)
                  (-> self basetrans)
                  (-> self last-repo-pos)
                  (the-as int (-> self target))
                  (-> self other-ship-index)
                  122880.0
                  122880.0
                  )
                )
              (a0-10 (-> self nav state))
              )
          (logclear! (-> a0-10 flags) (nav-state-flag directional-mode))
          (logior! (-> a0-10 flags) (nav-state-flag target-poly-dirty))
          (vector-copy! (-> a0-10 target-pos) v1-30)
          )
        0
        )
      )
    (when (< (-> self next-new-laser-rot-time) (current-time))
      (if (not (logtest? (-> self draw status) (draw-control-status on-screen)))
          (go-virtual hover)
          )
      (let* ((f30-0 8192.0)
             (v1-44 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-45 (the-as number (logior #x3f800000 v1-44)))
             )
        (set! (-> self laser-rotate-speed)
              (+ f30-0 (* (+ -1.0 (the-as float v1-45)) (+ -8192.0 (lerp 15473.777 17294.223 (-> self difficulty)))))
              )
        )
      (if (not (logtest? (rand-uint31-gen *random-generator*) 1))
          (set! (-> self laser-rotate-speed) (* -1.0 (-> self laser-rotate-speed)))
          )
      (set! (-> self next-new-laser-rot-time)
            (the-as time-frame (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 901) 900 (current-time)))
            )
      )
    (seek! (-> self current-laser-rotate-speed) (-> self laser-rotate-speed) (* 3640.889 (seconds-per-frame)))
    (vector-rotate-around-axis!
      (-> self base-laser-dir)
      (-> self base-laser-dir)
      (* (-> self current-laser-rotate-speed) (seconds-per-frame))
      *up-vector*
      )
    (quaternion-rotate-y!
      (-> self jmod-laser-descend transform quat)
      (-> self jmod-laser-descend transform quat)
      (* (-> self current-laser-rotate-speed) (seconds-per-frame))
      )
    (let ((gp-4 (new 'stack-no-clear 'vector)))
      (vector-copy! gp-4 (-> self root trans))
      (let ((s5-0 (new 'stack-no-clear 'vector))
            (s4-0 (the int (lerp 2.0 4.5 (-> self difficulty))))
            )
        0.0
        (let ((f30-1 0.0)
              (s3-0 (new 'stack-no-clear 'vector))
              )
          (let ((s2-0 (new 'stack-no-clear 'vector)))
            (let ((s1-0 *target*))
              (when s1-0
                (vector-copy! s2-0 (target-pos 0))
                (vector-copy! s3-0 (get-trans s1-0 3))
                (let ((s0-3 (vector-! (new 'stack-no-clear 'vector) s2-0 (-> self root trans)))
                      (s1-2 (vector-! (new 'stack-no-clear 'vector) s3-0 (-> self root trans)))
                      )
                  0.0
                  (set! (-> s0-3 y) 0.0)
                  (set! (-> s1-2 y) 0.0)
                  (let ((f0-26 (vector-normalize-ret-len! s0-3 1.0)))
                    (vector-float*! s0-3 s0-3 f0-26)
                    )
                  (set! (-> s2-0 x) (+ (-> self root trans x) (-> s0-3 x)))
                  (set! (-> s2-0 z) (+ (-> self root trans z) (-> s0-3 z)))
                  (let* ((f0-31 (vector-normalize-ret-len! s1-2 1.0))
                         (f0-32 (fmin 184320.0 f0-31))
                         )
                    (vector-float*! s1-2 s1-2 f0-32)
                    )
                  (set! (-> s3-0 x) (+ (-> self root trans x) (-> s1-2 x)))
                  (set! (-> s3-0 z) (+ (-> self root trans z) (-> s1-2 z)))
                  )
                )
              )
            (let ((s1-3 (new 'stack-no-clear 'collide-query)))
              (vector+float*! (-> s1-3 start-pos) s2-0 *up-vector* 24576.0)
              (set! (-> s1-3 move-dist quad) (the-as uint128 0))
              (set! (-> s1-3 move-dist y) -81920.0)
              (let ((v1-85 s1-3))
                (set! (-> v1-85 radius) 40.96)
                (set! (-> v1-85 collide-with) (collide-spec backgnd))
                (set! (-> v1-85 ignore-process0) #f)
                (set! (-> v1-85 ignore-process1) #f)
                (set! (-> v1-85 ignore-pat)
                      (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                      )
                (set! (-> v1-85 action-mask) (collide-action solid))
                )
              (if (>= (fill-and-probe-using-line-sphere *collide-cache* s1-3) 0.0)
                  (set! f30-1 (-> s1-3 best-other-tri intersect y))
                  )
              )
            )
          (seek! (-> self jmod-laser-descend transform scale y) 1.9 (seconds-per-frame))
          (vector<-cspace! gp-4 (joint-node kg-robot-transport-lod0-jg laser))
          (let ((f0-44 (vector-vector-xz-distance gp-4 s3-0))
                (f1-13 (- (-> gp-4 y) f30-1))
                )
            (set! (-> self base-laser-dir y)
                  (lerp (-> self base-laser-dir y) (- (/ f1-13 (+ 32768.0 f0-44))) (* 2.0 (seconds-per-frame)))
                  )
            )
          )
        (+! (-> gp-4 y) (* 2048.0 (- (-> self base-laser-dir y))))
        (vector-normalize-copy! s5-0 (-> self base-laser-dir) 1.0)
        (cond
          ((time-elapsed? (-> self state-time) (seconds 3))
           (dotimes (s3-1 s4-0)
             (fire-laser self gp-4 s5-0)
             (vector-rotate-around-axis! s5-0 s5-0 (/ 65536.0 (the float s4-0)) *up-vector*)
             )
           )
          ((time-elapsed? (-> self state-time) (seconds 1.5))
           (spawn-from-mat (-> self part) (-> self node-list data 17 bone transform))
           )
          )
        )
      )
    (if (time-elapsed? (-> self state-time) (seconds 15))
        (go-virtual hover)
        )
    )
  :code sleep-code
  :post (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 post)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    (protect-gunship-method-52 self)
    )
  )

(defmethod protect-gunship-method-52 ((this protect-gunship))
  (let ((a0-1 (-> this nav state))
        (a1-0 (new 'stack-no-clear 'vector))
        )
    (vector-copy! a1-0 (-> a0-1 target-pos))
    0.0
    (let ((a0-4 (-> this nav state))
          (s5-0 (new 'stack-no-clear 'vector))
          )
      (vector-copy! s5-0 (-> a0-4 heading))
      0.0
      (let* ((f0-2 (vector-vector-xz-distance (-> this basetrans) a1-0))
             (f0-3 (fmin 102400.0 f0-2))
             )
        (vector-float*! s5-0 s5-0 f0-3)
        )
      (let ((v1-8 (vector-! (new 'stack-no-clear 'vector) s5-0 (-> this root transv))))
        0.0
        0.0
        (let* ((f0-6 (vector-length v1-8))
               (f0-7 (/ f0-6 (meters 25)))
               (f1-3 (* f0-7 f0-7 (seconds-per-frame)))
               (f0-10 (fmax 0.0 (fmin 1.0 f1-3)))
               )
          (vector+float*! (-> this root transv) (-> this root transv) v1-8 f0-10)
          )
        (vector-float*! (-> this last-thrust) v1-8 1.0)
        )
      )
    )
  (vector+float*! (-> this basetrans) (-> this basetrans) (-> this root transv) (seconds-per-frame))
  (let ((s5-1 (new 'stack-no-clear 'vector)))
    (nav-mesh-method-10 (-> this nav state mesh) s5-1 (-> this basetrans) (the-as nav-poly #f))
    (let ((v1-15 (vector-! (new 'stack-no-clear 'vector) s5-1 (-> this basetrans))))
      0.0
      (set! (-> v1-15 y) 0.0)
      (vector+float*! (-> this root transv) (-> this root transv) v1-15 (* 0.1 (seconds-per-frame)))
      )
    )
  (let ((a0-29 (the-as protect-gunship (handle->process (-> *active-gunships* (-> this other-ship-index) proc)))))
    (when a0-29
      (let ((s5-3 (vector-! (new 'stack-no-clear 'vector) (-> this root trans) (-> a0-29 root trans))))
        0.0
        (set! (-> s5-3 y) 0.0)
        (let ((f1-6 (vector-normalize-ret-len! s5-3 1.0)))
          (when (< f1-6 122880.0)
            (let* ((f0-21 (/ f1-6 (meters 30)))
                   (f0-22 (- 1.0 f0-21))
                   (f0-23 (* f0-22 f0-22))
                   )
              (vector-float*! s5-3 s5-3 (- 122880.0 f1-6))
              (vector+float*! (-> this root transv) (-> this root transv) s5-3 (* 4.0 (seconds-per-frame) f0-23))
              )
            )
          )
        )
      )
    )
  (let* ((f0-25 (vector-normalize-ret-len! (-> this root transv) 1.0))
         (f0-26 (fmin 102400.0 f0-25))
         )
    (vector-float*! (-> this root transv) (-> this root transv) f0-26)
    )
  (if (not (time-elapsed? (-> this rotate-start-time) (-> this rotate-total-time)))
      (quaternion-rotate-local-y!
        (-> this root quat)
        (-> this root quat)
        (* (-> this rotate-rate) (seconds-per-frame))
        )
      )
  )

(defstate hover (protect-gunship)
  :virtual #t
  :parent (protect-gunship protect-gunship-base-state)
  :enter (behavior ()
    (set! (-> self choose-new-point-time) 0)
    (let ((v1-1 (-> self state parent)))
      (when v1-1
        (let ((t9-0 (-> v1-1 enter)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    )
  :trans (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 trans)))
          (if t9-0
              (t9-0)
              )
          )
        )
      )
    (protect-gunship-method-50 self)
    (protect-gunship-method-51 self)
    )
  :post (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 post)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    (protect-gunship-method-52 self)
    )
  )

(defstate landed (protect-gunship)
  :virtual #t
  :parent (protect-gunship protect-gunship-base-state)
  :enter (behavior ()
    (set! (-> self root transv quad) (the-as uint128 0))
    (set! (-> self last-thrust quad) (the-as uint128 0))
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 enter)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    (set! (-> self land-start-hp) (-> self hit-points))
    )
  :exit (behavior ()
    (set-time! (-> self last-land-time))
    (vector-copy! (-> self last-repo-pos) (-> self basetrans))
    )
  :trans (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 trans)))
          (if t9-0
              (t9-0)
              )
          )
        )
      )
    (if (logtest? (-> self target) 16)
        (protect-gunship-method-49 self)
        )
    (if (or (time-elapsed? (-> self state-time) (the int (* 300.0 (lerp 6.0 4.5 (-> self difficulty)))))
            (< 0.2 (/ (- (-> self land-start-hp) (-> self hit-points)) (-> self num-hp-per-stage)))
            (< 348160.0 (vector-vector-xz-distance (-> self basetrans) (target-pos 0)))
            )
        (go-virtual raising)
        )
    )
  )

(defstate raising (protect-gunship)
  :virtual #t
  :parent (protect-gunship protect-gunship-base-state)
  :enter (behavior ()
    (sound-play "gship-thrust")
    (set! (-> self move-state dest-pos y) (+ 22528.0 (-> self ground-pt y)))
    (set! (-> self root nav-radius) 0.0)
    (let ((v1-4 (-> self state parent)))
      (when v1-4
        (let ((t9-2 (-> v1-4 enter)))
          (if t9-2
              ((the-as (function none) t9-2))
              )
          )
        )
      )
    )
  :trans (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 trans)))
          (if t9-0
              (t9-0)
              )
          )
        )
      )
    (seek! (-> self basetrans y) (-> self move-state dest-pos y) (* 20480.0 (seconds-per-frame)))
    (if (= (the int (-> self basetrans y)) (the int (-> self move-state dest-pos y)))
        (go-virtual hover)
        )
    )
  )

(defstate lowering (protect-gunship)
  :virtual #t
  :parent (protect-gunship protect-gunship-base-state)
  :enter (behavior ()
    (set! (-> self root nav-radius) 32768.0)
    (set! (-> self move-state dest-pos y) (+ 6144.0 (-> self ground-pt y)))
    (set! (-> self suppress-times (log2 16)) (+ (current-time) (seconds 5)))
    (let ((v1-8 (-> self state parent)))
      (when v1-8
        (let ((t9-1 (-> v1-8 enter)))
          (if t9-1
              ((the-as (function none) t9-1))
              )
          )
        )
      )
    )
  :trans (behavior ()
    (vector-lerp! (-> self root transv) (-> self root transv) *zero-vector* (* 5.0 (seconds-per-frame)))
    (vector-lerp! (-> self last-thrust) (-> self last-thrust) *zero-vector* (* 5.0 (seconds-per-frame)))
    (let ((a0-2 (-> self state parent)))
      (when a0-2
        (let ((t9-2 (-> a0-2 trans)))
          (if t9-2
              (t9-2)
              )
          )
        )
      )
    (seek! (-> self basetrans y) (-> self move-state dest-pos y) (* 12288.0 (seconds-per-frame)))
    (if (= (the int (-> self basetrans y)) (the int (-> self move-state dest-pos y)))
        (go-virtual landed)
        )
    )
  :post (behavior ()
    (protect-gunship-method-52 self)
    (let ((v1-3 (-> self state parent)))
      (when v1-3
        (let ((t9-1 (-> v1-3 post)))
          (if t9-1
              ((the-as (function none) t9-1))
              )
          )
        )
      )
    )
  )

(defmethod protect-gunship-method-56 ((this protect-gunship) (arg0 float))
  0.0
  (let ((f0-2 (- (-> this root trans y) arg0)))
    (* 0.00012849507 f0-2)
    )
  )

;; WARN: Return type mismatch object vs none.
;; WARN: Function (method 47 protect-gunship) has a return type of none, but the expression builder found a return statement.
(defmethod protect-gunship-method-47 ((this protect-gunship))
  (if (not (time-elapsed? (-> this reaction-time) (seconds 0.2)))
      (return 0)
      )
  (if (protect-gunship-method-46 this)
      (logior! (-> this want) 1)
      )
  (if (and (< (-> this next-fire-missile-time) (current-time))
           (not (and (-> this next-state) (let ((v1-15 (-> this next-state name)))
                                            (or (= v1-15 'raising) (= v1-15 'lowering))
                                            )
                     )
                )
           )
      (logior! (-> this want) 16)
      )
  (if (and (< (-> this next-spin-laser-time) (current-time))
           (and (not (and (-> this next-state) (let ((v1-24 (-> this next-state name)))
                                                 (or (= v1-24 'raising) (= v1-24 'lowering))
                                                 )
                          )
                     )
                (>= (-> this base-difficulty) 0.5)
                (>= (-> this difficulty) 0.3)
                )
           )
      (logior! (-> this want) 8)
      )
  (if (and (< (-> this next-spawn-time) (current-time))
           (not (and (-> this next-state) (let ((v1-36 (-> this next-state name)))
                                            (or (= v1-36 'raising) (= v1-36 'lowering))
                                            )
                     )
                )
           )
      (logior! (-> this want) 32)
      )
  (if (time-elapsed? (-> this last-land-time) (the int (* 300.0 (lerp 10.0 15.0 (-> this difficulty)))))
      (logior! (-> this want) 128)
      )
  (if (and (and (-> this next-state) (= (-> this next-state name) 'hover))
           (or (and (-> this last-engine?) (time-elapsed? (-> this rotate-start-time) (seconds 4)))
               (time-elapsed? (-> this rotate-start-time) (+ (-> this rotate-total-time) (seconds 5)))
               )
           )
      (logior! (-> this want) 64)
      )
  (dotimes (v1-63 8)
    (if (>= (-> this suppress-times v1-63) (current-time))
        (logclear! (-> this want) (ash 1 v1-63))
        )
    )
  (when (and (logtest? (-> this want) 128)
             (< (vector-vector-xz-distance (-> this basetrans) (-> this last-repo-pos)) 81920.0)
             )
    (logior! (-> this want) 4)
    (logand! (-> this want) -129)
    )
  (if (and (logtest? (-> this want) 32)
           (let ((s5-1 (the int (protect-gunship-method-54 this))))
             (< s5-1 (the-as int (send-event (handle->process (-> this task-man)) 'count-active)))
             )
           )
      (logand! (-> this want) -33)
      )
  (when (and (logtest? (-> this want) 32)
             (or (< (vector-vector-xz-distance (-> this basetrans) (-> this last-repo-pos)) 122880.0)
                 (not (protect-gunship-method-48 this (-> this basetrans)))
                 )
             )
    (logior! (-> this want) 2)
    (logand! (-> this want) -33)
    )
  (if (and (logtest? (-> this want) 16)
           (let ((s5-2 (the int (* 2.0 (protect-gunship-method-54 this)))))
             (< s5-2 (the-as int (send-event (handle->process (-> this task-man)) 'count-active)))
             )
           )
      (logand! (-> this want) -17)
      )
  (when (or (logtest? (-> *active-gunships* (-> this other-ship-index) want-target) 8)
            (= (-> *active-gunships* (-> this other-ship-index) cur-state) 'spinning-laser)
            )
    (set! (-> this suppress-times (log2 8)) (+ (current-time) (seconds 5)))
    (set! (-> this suppress-times (log2 128)) (+ (current-time) (seconds 5)))
    )
  (if (logtest? (-> *active-gunships* (-> this other-ship-index) want-target) 16)
      (set! (-> this suppress-times (log2 128)) (+ (current-time) (seconds 5)))
      )
  (if (not (logtest? (-> this draw status) (draw-control-status on-screen)))
      (set! (-> this suppress-times (log2 8)) (+ (current-time) (seconds 2)))
      )
  (dotimes (v1-153 8)
    (if (>= (-> this suppress-times v1-153) (current-time))
        (logclear! (-> this want) (ash 1 v1-153))
        )
    )
  (set! (-> this target) (the-as uint 0))
  (set! (-> this target) (logand (-> this want) 7))
  (cond
    ((logtest? (-> this target) 7)
     (if (logtest? (-> this want) 64)
         (logior! (-> this target) 64)
         )
     (if (and (or (not (logtest? (-> this target) 1))
                  (< 327680.0 (vector-vector-xz-distance (-> this basetrans) (target-pos 0)))
                  )
              (logtest? (-> this want) 16)
              )
         (logior! (-> this target) 16)
         )
     )
    (else
      (dotimes (v1-174 8)
        (when (logtest? (-> this want) (ash 1 v1-174))
          (logior! (-> this target) (ash 1 v1-174))
          0
          (goto cfg-150)
          )
        )
      )
    )
  (label cfg-150)
  (dotimes (v1-181 8)
    (when (logtest? (-> this want) (ash 1 v1-181))
      (cond
        ((logtest? (-> this target) (ash 1 v1-181))
         )
        (else
          )
        )
      )
    )
  (set! (-> *active-gunships* (-> this self-index) want-target) (-> this target))
  (if (-> this next-state)
      (set! (-> *active-gunships* (-> this self-index) cur-state) (-> this next-state name))
      (set! (-> *active-gunships* (-> this self-index) cur-state) #f)
      )
  (none)
  )

(defmethod protect-gunship-method-48 ((this protect-gunship) (arg0 vector))
  (let ((a0-2 (find-nearest-nav-mesh-protect arg0 (the-as float #x7f800000))))
    (when a0-2
      (let ((s5-0 (new 'stack-no-clear 'vector)))
        (nav-mesh-method-10 a0-2 s5-0 arg0 (the-as nav-poly #f))
        (if (< (vector-vector-xz-distance s5-0 arg0) 4096.0)
            (return #t)
            )
        )
      )
    )
  #f
  )

(defmethod deactivate ((this protect-gunship))
  "Make a process dead, clean it up, remove it from the active pool, and return to dead pool."
  (sound-stop (-> this sound-engine-loop))
  (sound-stop (-> this sound-lock-on))
  (sound-stop (-> this sound-lock-on-hi))
  (call-parent-method this)
  (none)
  )
