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

;; name: cty-blow-tower.gc
;; name in dgo: cty-blow-tower
;; dgos: LCTYBLOW

(declare-type bt-vehicle process-focusable)
(declare-type bt-hellcat bt-vehicle)

(define-extern *bt-height-adjust* curve2d-piecewise)
(define-extern *bt-clamp-curve-x* curve2d-piecewise)
(define-extern *bt-accel-curve* curve2d-piecewise)

;; DECOMP BEGINS

(define *blow-tower-bombbat-path-cache*
  (new 'static 'boxed-array :type bombbot-path :length 0 :allocated-length 8)
  )

(dotimes (v1-1 8)
  (set! (-> *blow-tower-bombbat-path-cache* v1-1)
        (new 'static 'bombbot-path
          :node-count #x2
          :node (new 'static 'inline-array bombbot-node 2 (new 'static 'bombbot-node) (new 'static 'bombbot-node))
          )
        )
  )

(deftype bombbot-spawn-record (structure)
  ((hand      handle)
   (ent-name  string)
   )
  )


(deftype task-manager-blow-tower (task-manager)
  ((dest-pos                 vector                  :inline)
   (target-handles           handle                  2)
   (hellcat                  handle                  :overlay-at (-> target-handles 0))
   (pickup                   handle                  :overlay-at (-> target-handles 1))
   (hellcat-turret           handle)
   (mission-elapsed-clock    time-frame)
   (debug-lock-viewport?     symbol)
   (debug-run-events?        symbol)
   (script                   (array tower-event-group))
   (script-index             int16)
   (cmd                      blow-tower-cmd          :inline)
   (event-cursor             blow-tower-path-cursor  :inline)
   (last-missile-spawn-time  time-frame)
   (dest-clock-scalar        float)
   (clock-scalar             float)
   (bombbot-path-index       int8)
   (hud-arrows               handle)
   (hud-arrow-state          uint32)
   (left-arrow-last-time     time-frame)
   (right-arrow-last-time    time-frame)
   (show-skill-time          time-frame)
   (bombbot-records          bombbot-spawn-record    3 :inline)
   (bombbot-record-index     int32)
   (last-missile-ent         string)
   (missile-dir-vec          vector                  :inline)
   )
  (:state-methods
    mission-play
    mission-debug
    wait-for-exit
    wait-fail
    wind-down-mission
    )
  (:methods
    (task-manager-blow-tower-method-37 (_type_ symbol) symbol)
    (handle-bt-command (_type_ blow-tower-cmd) object)
    (advance (_type_ time-frame) none)
    )
  )


(deftype bt-gun-manager-target (structure)
  ((hand               handle)
   (transformed-pos    vector4w  :inline)
   (size               float)
   (hit?               symbol)
   (alpha              float)
   (target-pers-index  int32)
   (num-overlap        int32)
   )
  )


(deftype bt-hud-target-pers (structure)
  ((hand             handle)
   (rotate           float)
   (alpha            float)
   (size-scalar      float)
   (outer-alpha      float)
   (outer-rotate     float)
   (hold-start-time  time-frame)
   )
  :allow-misaligned
  )


(deftype bt-gun-manager (process)
  ((root                    collide-shape)
   (parent-vehicle          handle)
   (params                  target-turret-params)
   (roty                    degrees)
   (rotyv                   degrees)
   (rotyvv                  degrees)
   (roty-min                degrees)
   (roty-max                degrees)
   (rotx                    degrees)
   (rotxv                   degrees)
   (rotxvv                  degrees)
   (rotx-min                degrees)
   (rotx-max                degrees)
   (dest-roty               degrees)
   (dest-rotx               degrees)
   (aim-quat                quaternion              :inline)
   (parent-quat             quaternion              :inline)
   (last-parent-xform       matrix                  :inline)
   (hit-pos                 vector                  :inline)
   (aim-dir                 vector                  :inline)
   (found-target?           symbol)
   (target-hand             handle)
   (target-start-find-time  time-frame)
   (hud-aim                 hud-sprite              :inline)
   (hud-target              hud-sprite              :inline)
   (hud-target-inner        hud-sprite              :inline)
   (rot-y-shift             float)
   (dest-rot-y-shift        float)
   (enable-controls?        symbol)
   (lock-control-time       time-frame)
   (fire-index              uint32)
   (last-fire-time          time-frame)
   (can-exit?               symbol)
   (is-snapping?            symbol)
   (onscreen-targets        bt-gun-manager-target   32 :inline)
   (num-onscreen-targets    int32)
   (hud-pers                bt-hud-target-pers      32 :inline)
   (rot-y-seek-rate         float)
   (cam-quat                quaternion              :inline)
   (dest-roty-max           float)
   (dest-roty-min           float)
   (use-roty-min            float)
   (use-roty-max            float)
   (x-boost-scalar          float)
   (y-boost-scalar          float)
   (servo-sound             sound-id)
   (servo-sound-state       uint64)
   (servo-state-time        time-frame)
   (aim-pos                 vector                  :inline)
   (look-cursor             blow-tower-path-cursor  :inline :offset 4288)
   (look-time-offset        time-frame)
   (look-time-scalar        float)
   (look-mode               uint8)
   (look-ent                entity-actor)
   (look-proc               handle)
   (last-beep-time          time-frame)
   )
  (:state-methods
    idle
    setup
    active
    )
  (:methods
    (bt-gun-manager-method-17 (_type_) none)
    (bt-gun-manager-method-18 (_type_ float) none)
    (bt-gun-manager-method-19 (_type_) none)
    (find-target (_type_) object)
    (fire-shot (_type_) none)
    (bt-gun-handler (_type_ process int symbol event-message-block) object)
    (bt-gun-manager-method-23 (_type_) symbol)
    (bt-gun-manager-method-24 (_type_ quaternion) float)
    )
  )


(defmethod relocate ((this bt-gun-manager) (offset int))
  (if (nonzero? (-> this root))
      (&+! (-> this root) offset)
      )
  (call-parent-method this offset)
  )

(deftype bt-obj-init-params (structure)
  ((pos       vector      :inline)
   (quat      quaternion  :inline)
   (path      blow-tower-path)
   (task-man  handle)
   )
  )


(deftype cast-rider-spot (structure)
  ((rider       handle)
   (offset-pos  vector  :inline)
   )
  )


(deftype cast-rider-array (inline-array-class)
  ((data  cast-rider-spot  :inline :dynamic)
   )
  )


(set! (-> cast-rider-array heap-base) (the-as uint 32))

(deftype bt-bouncer (structure)
  ((mag-scalar   float)
   (duration     time-frame)
   (num-bounces  float)
   )
  )


(deftype bt-vehicle-damage-info (structure)
  ((segd           uint64)
   (seg0           uint64)
   (seg1           uint64)
   (hp-threshold0  float)
   (hp-threshold1  float)
   )
  )


(deftype bt-vehicle (process-focusable)
  ((path-cursor               blow-tower-path-cursor  :inline)
   (task-man                  handle)
   (max-hit-points            float)
   (hit-points                float)
   (last-attack-id            uint32)
   (path-height-offset        float)
   (start-path-height-offset  float)
   (dest-path-height-offset   float)
   (path-height-start         uint64)
   (path-height-end           uint64)
   (path-pos                  vector                  :inline)
   (rider-spots               cast-rider-array)
   (hud-health                handle)
   (path-height-vel           float)
   (inited?                   symbol)
   (pre-bounce-pos            vector                  :inline)
   (bouncers                  bt-bouncer              3 :inline)
   (bounce-start-time         time-frame)
   (barrel-roll-amount        float)
   (barrel-roll-quat          quaternion              :inline)
   (barrel-roll-rate-scalar   float)
   (last-speed                float)
   (last-vel                  vector                  :inline)
   (damage-info               (array bt-vehicle-damage-info))
   (damage-state              float                   4)
   (mission-fail?             symbol)
   (whoosh-sound              sound-id)
   (boost-thruster?           symbol)
   (sound-play-end            time-frame)
   )
  (:state-methods
    die
    )
  (:methods
    (bt-vehicle-event-handler (_type_ process int symbol event-message-block) object)
    (init-collision! (_type_) none)
    (bt-vehicle-method-31 (_type_) none)
    (on-attacked (_type_ float attack-info process-focusable) none)
    (bt-vehicle-method-33 (_type_ handle) int)
    (bt-vehicle-method-34 (_type_ handle) symbol)
    (bt-vehicle-method-35 (_type_ int vector quaternion) none)
    (bt-vehicle-method-36 (_type_ int vector quaternion) object)
    (bt-vehicle-method-37 (_type_) symbol)
    (init-params (_type_) none)
    (init-hud (_type_) none)
    (bt-vehicle-method-40 (_type_ int) float)
    (bt-vehicle-method-41 (_type_ vector vector) symbol)
    (bounce (_type_ vector) symbol)
    (draw-thruster (_type_) object)
    )
  )


(defmethod bounce ((this bt-vehicle) (arg0 vector))
  (set-time! (-> this bounce-start-time))
  (dotimes (s4-0 3)
    (let ((s3-0 (-> this bouncers s4-0)))
      (set! (-> s3-0 duration)
            (the-as time-frame (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 61) 120))
            )
      (set! (-> s3-0 mag-scalar) (-> arg0 data s4-0))
      (let* ((f30-0 1.0)
             (f28-0 0.5)
             (v1-12 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-13 (the-as number (logior #x3f800000 v1-12)))
             )
        (set! (-> s3-0 num-bounces) (+ f30-0 (* f28-0 (+ -1.0 (the-as float v1-13)))))
        )
      )
    )
  #f
  )

(defmethod bt-vehicle-method-41 ((this bt-vehicle) (arg0 vector) (arg1 vector))
  (set! (-> arg0 quad) (the-as uint128 0))
  (set! (-> arg1 quad) (the-as uint128 0))
  (dotimes (s3-0 3)
    (let ((v1-4 (-> this bouncers s3-0)))
      (when (not (time-elapsed? (-> this bounce-start-time) (-> v1-4 duration)))
        (let* ((f0-2 (/ (the float (- (current-time) (-> this bounce-start-time))) (the float (-> v1-4 duration))))
               (f30-0 (* 65536.0 f0-2 (-> v1-4 num-bounces)))
               (f28-0 (* (-> v1-4 mag-scalar) (- 1.0 f0-2)))
               )
          (set! (-> arg0 data s3-0) (* f28-0 (sin f30-0)))
          (set! (-> arg1 data s3-0) (* f28-0 (cos f30-0)))
          )
        )
      )
    )
  #f
  )

;; WARN: Return type mismatch int vs object.
(defmethod draw-thruster ((this bt-vehicle))
  (when (-> this boost-thruster?)
    (if (and (> (-> this sound-play-end) 0) (< (-> this sound-play-end) (-> *blow-tower-targets* mission-time)))
        (set! (-> this boost-thruster?) #f)
        )
    )
  (let ((a1-3 0)
        (a2-0 0)
        )
    (dotimes (v1-7 4)
      (cond
        ((>= (-> this damage-state v1-7) (-> this damage-info v1-7 hp-threshold1))
         (set! a1-3 (logior a1-3 (-> this damage-info v1-7 seg1)))
         (set! a2-0 (logior (logior a2-0 (-> this damage-info v1-7 seg0)) (-> this damage-info v1-7 segd)))
         )
        ((>= (-> this damage-state v1-7) (-> this damage-info v1-7 hp-threshold0))
         (set! a1-3 (logior a1-3 (-> this damage-info v1-7 seg0)))
         (set! a2-0 (logior (logior a2-0 (-> this damage-info v1-7 seg1)) (-> this damage-info v1-7 segd)))
         )
        (else
          (set! a1-3 (logior a1-3 (-> this damage-info v1-7 segd)))
          (set! a2-0 (logior (logior a2-0 (-> this damage-info v1-7 seg0)) (-> this damage-info v1-7 seg1)))
          )
        )
      )
    (let ((a2-4 (logclear a2-0 a1-3)))
      (setup-masks (-> this draw) a1-3 a2-4)
      )
    )
  0
  )

(defmethod init-params ((this bt-vehicle))
  (vector-copy! (-> this path-pos) (-> this root trans))
  (quaternion-identity! (-> this barrel-roll-quat))
  (set! (-> this root penetrated-by) (penetrate))
  (set! (-> this mission-fail?) #f)
  0
  (none)
  )

(defmethod relocate ((this bt-vehicle) (offset int))
  (if (nonzero? (-> this rider-spots))
      (&+! (-> this rider-spots) offset)
      )
  (call-parent-method this offset)
  )

(defmethod bt-vehicle-method-37 ((this bt-vehicle))
  (dotimes (s5-0 (-> this rider-spots length))
    (let ((s4-0 (as-type (handle->process (-> this rider-spots data s5-0 rider)) process-focusable)))
      (when s4-0
        (let ((a2-0 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> this root quat)))
              (s3-1 (-> s4-0 root trans))
              )
          (vector-matrix*!
            s3-1
            (the-as vector (+ (the-as uint (-> this rider-spots data 0 offset-pos)) (* s5-0 32)))
            a2-0
            )
          (vector+! s3-1 s3-1 (-> this root trans))
          )
        (quaternion-copy! (-> s4-0 root quat) (-> this root quat))
        )
      )
    )
  #f
  )

(defmethod init-hud ((this bt-vehicle))
  0
  (none)
  )

(defmethod bt-vehicle-method-33 ((this bt-vehicle) (arg0 handle))
  -1
  )

(defmethod bt-vehicle-method-35 ((this bt-vehicle) (arg0 int) (arg1 vector) (arg2 quaternion))
  (vector-copy! arg1 (-> this root trans))
  (quaternion-copy! arg2 (-> this root quat))
  (bt-vehicle-method-36 this arg0 arg1 arg2)
  0
  (none)
  )

;; WARN: Return type mismatch int vs object.
(defmethod bt-vehicle-method-36 ((this bt-vehicle) (arg0 int) (arg1 vector) (arg2 quaternion))
  0
  )

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

(defmethod init-collision! ((this bt-vehicle))
  0
  (none)
  )

(defmethod bt-vehicle-method-31 ((this bt-vehicle))
  (bt-vehicle-method-37 this)
  0
  (none)
  )

(defstate die (bt-vehicle)
  :virtual #t
  :event bt-vehicle-handler
  :enter (behavior ()
    (logior! (-> self draw status) (draw-control-status no-draw))
    (let ((v1-4 (-> self root root-prim)))
      (set! (-> v1-4 prim-core collide-as) (collide-spec))
      (set! (-> v1-4 prim-core collide-with) (collide-spec))
      )
    0
    (sound-play "snd-ship-explod")
    (cond
      ((logtest? (-> group-hijack-kgpickup-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-hijack-kgpickup-explode)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-hijack-kgpickup-explode)
        )
      )
    (send-event (handle->process (-> self task-man)) 'vehicle-explode)
    (dotimes (gp-3 (-> self rider-spots length))
      (let ((a0-26 (as-type (handle->process (-> self rider-spots data gp-3 rider)) process-focusable)))
        (if a0-26
            (send-event a0-26 'die)
            )
        )
      )
    )
  :code sleep-code
  )

(defmethod on-attacked ((this bt-vehicle) (arg0 float) (arg1 attack-info) (arg2 process-focusable))
  (local-vars
    (sv-64 vector)
    (sv-68 vector)
    (sv-72 vector)
    (sv-76 float)
    (sv-80 (pointer float))
    (sv-88 int)
    (sv-96 vector)
    (sv-100 float)
    )
  (set! sv-64 (new 'stack-no-clear 'vector))
  (set! sv-68 (-> this root trans))
  (set! sv-72 (new 'stack-no-clear 'vector))
  (set! sv-76 (the-as float 0.0))
  (set! sv-80 (new 'static 'array float 4 0.0 0.0 0.0 0.0))
  (set! sv-88 0)
  (set! sv-96 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)))
  (set! sv-100 (the-as float 0.0))
  (let ((s2-0 (new 'stack-no-clear 'attack-info)))
    (attack-info-method-9 arg1 s2-0 arg2 this)
    (vector-copy! sv-64 (-> s2-0 intersection))
    )
  (let ((a0-6 (as-type arg2 process-focusable)))
    (if a0-6
        (vector-copy! sv-64 (get-trans a0-6 3))
        )
    )
  (vector-! sv-72 sv-64 sv-68)
  (set! (-> sv-72 y) 0.0)
  (let ((a0-8 sv-96))
    (vector-copy! a0-8 sv-96)
    (set! (-> a0-8 y) 0.0)
    (vector-normalize! a0-8 1.0)
    )
  (set! sv-100 (* 0.6 (-> this root root-prim local-sphere w)))
  (vector-float*! sv-96 sv-96 sv-100)
  (let ((s4-3 (vector-rotate-around-y! (new 'stack-no-clear 'vector) sv-96 8192.0))
        (f30-0 0.0)
        )
    (dotimes (s3-1 4)
      (set! (-> sv-80 s3-1) (/ (vector-vector-distance s4-3 sv-72) sv-100))
      (set! (-> sv-80 s3-1) (fmax 0.0 (fmin 1.0 (-> sv-80 s3-1))))
      (set! (-> sv-80 s3-1) (- 1.0 (-> sv-80 s3-1)))
      (set! (-> sv-80 s3-1) (* (-> sv-80 s3-1) (-> sv-80 s3-1)))
      (+! f30-0 (-> sv-80 s3-1))
      (vector-rotate-around-y! s4-3 s4-3 -16384.0)
      )
    (when (< 0.1 f30-0)
      (dotimes (v1-46 4)
        (set! (-> sv-80 v1-46) (/ (-> sv-80 v1-46) f30-0))
        )
      (dotimes (v1-49 4)
        (+! (-> this damage-state v1-49) (* (-> sv-80 v1-49) arg0))
        )
      )
    )
  0
  (none)
  )

(when (or (zero? *bt-height-adjust*) (!= loading-level global))
  (set! *bt-height-adjust* (new 'loading-level 'curve2d-piecewise))
  (allocate! *bt-height-adjust* 4 'loading-level #t)
  )

(set! (-> *bt-height-adjust* pts data 0 first) 0.0)

(set! (-> *bt-height-adjust* pts data 0 second) 0.0)

(set! (-> *bt-height-adjust* pts data 1 first) 0.7)

(set! (-> *bt-height-adjust* pts data 1 second) 1.0)

(set! (-> *bt-height-adjust* pts data 2 first) 0.8)

(set! (-> *bt-height-adjust* pts data 2 second) 1.07)

(set! (-> *bt-height-adjust* pts data 3 first) 1.0)

(set! (-> *bt-height-adjust* pts data 3 second) 1.0)

(defmethod bt-vehicle-method-40 ((this bt-vehicle) (arg0 int))
  (with-pp
    (let* ((f1-0 (lerp-scale
                   0.0
                   1.0
                   (the float arg0)
                   (the float (-> this path-height-start))
                   (the float (-> this path-height-end))
                   )
                 )
           (f0-7 (fmax 0.0 (fmin 1.0 f1-0)))
           )
      (cond
        ((< (-> this start-path-height-offset) (-> this dest-path-height-offset))
         )
        (else
          (set! f0-7 (* f0-7 f0-7))
          )
        )
      (let* ((f0-8 (evaluate *bt-height-adjust* f0-7 (loop-behavior use-default)))
             (f0-9 (lerp (-> this start-path-height-offset) (-> this dest-path-height-offset) f0-8))
             )
        (set! (-> this path-height-vel) (* (- f0-9 (-> this path-height-offset)) (-> pp clock frames-per-second)))
        (set! (-> this path-height-offset) f0-9)
        f0-9
        )
      )
    )
  )

(defmethod bt-vehicle-event-handler ((this bt-vehicle) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (local-vars (v0-0 object))
  (case arg2
    (('boost-thruster)
     (set! (-> this boost-thruster?) #t)
     (let ((f0-0 (the-as float (-> arg3 param 0))))
       (cond
         ((< 0.0 f0-0)
          (set! v0-0 (+ (-> *blow-tower-targets* mission-time) (the int (* 300.0 f0-0))))
          (set! (-> this sound-play-end) (the-as time-frame v0-0))
          v0-0
          )
         (else
           (set! (-> this sound-play-end) 0)
           0
           )
         )
       )
     )
    (('stop-sound)
     (set! (-> this boost-thruster?) #f)
     (sound-stop (-> this whoosh-sound))
     )
    (('bt-roboguard-attack?)
     #t
     )
    (('mission-fail)
     (set! v0-0 #t)
     (set! (-> this mission-fail?) (the-as symbol v0-0))
     v0-0
     )
    (('exit)
     (go empty-state)
     )
    (('notify-danger)
     (send-event (handle->process (-> this task-man)) 'notify-danger (-> arg3 param 0))
     )
    (('barrel-roll)
     (set! (-> this barrel-roll-amount) (* 182.04445 (the-as float (-> arg3 param 0))))
     (set! (-> this barrel-roll-rate-scalar) (the-as float (-> arg3 param 1)))
     )
    (('get-path)
     (-> this path-cursor path)
     )
    (('bounce)
     (bounce this (the-as vector (-> arg3 param 0)))
     )
    (('rider-predict-transform)
     (bt-vehicle-method-36
       this
       (the-as int (-> arg3 param 0))
       (the-as vector (-> arg3 param 1))
       (the-as quaternion (-> arg3 param 2))
       )
     )
    (('predict-height)
     (-> this dest-path-height-offset)
     )
    (('predict-position)
     (let ((a0-23 (the-as blow-tower-path-cursor (-> arg3 param 0))))
       (set! (-> a0-23 path) (-> this path-cursor path))
       (blow-tower-path-cursor-method-11 a0-23 (the-as vector (-> arg3 param 1)))
       )
     #t
     )
    (('assign-rider)
     (bt-vehicle-method-33 this (the-as handle (-> arg3 param 0)))
     )
    (('kill-rider)
     (bt-vehicle-method-34 this (the-as handle (-> arg3 param 0)))
     )
    (('get-rider-transform)
     (bt-vehicle-method-35
       this
       (the-as int (-> arg3 param 0))
       (the-as vector (-> arg3 param 1))
       (the-as quaternion (-> arg3 param 2))
       )
     #t
     )
    (('set-path-height)
     (set! (-> this dest-path-height-offset) (the-as float (-> arg3 param 0)))
     (set! (-> this start-path-height-offset) (-> this path-height-offset))
     (set! (-> this path-height-start) (the-as uint (-> *blow-tower-targets* mission-time)))
     (set! v0-0 (-> arg3 param 1))
     (set! (-> this path-height-end) (the-as uint v0-0))
     v0-0
     )
    (('attack)
     (let ((s4-0 (the-as object (-> arg3 param 1))))
       (when (!= (-> (the-as attack-info s4-0) id) (-> this last-attack-id))
         (set! (-> this last-attack-id) (-> (the-as attack-info s4-0) id))
         (let ((f30-0 (if (logtest? (attack-mask damage) (-> (the-as attack-info s4-0) mask))
                          (-> (the-as attack-info s4-0) damage)
                          (penetrate-using->damage (-> (the-as attack-info s4-0) penetrate-using))
                          )
                      )
               )
           (if (not (-> *blow-tower-targets* debug?))
               (set! (-> this hit-points) (- (-> this hit-points) (* f30-0 (-> *blow-tower-targets* difficulty-scalar))))
               )
           (when (and (type? arg0 projectile) (= (-> this type) bt-hellcat))
             (if (and (zero? (mod (the-as int (rand-uint31-gen *random-generator*)) 7))
                      (or (not (logtest? (-> *blow-tower-speech* 19 flags) (speech-info-flag si6)))
                          (and (> (-> *blow-tower-speech* 19 play-time) 0)
                               (time-elapsed? (-> *blow-tower-speech* 19 play-time) (seconds 4))
                               )
                          )
                      )
                 (speech-play *blow-tower-speech* 19 *blow-tower-speech-list* (target-pos 0))
                 )
             (set! f30-0 (* 2.0 f30-0))
             )
           (if (>= 0.0 (-> this hit-points))
               (go (method-of-object this die))
               (on-attacked this f30-0 (the-as attack-info s4-0) (the-as process-focusable arg0))
               )
           )
         )
       )
     )
    (else
      #f
      )
    )
  )

(define *bt-pickup-damage-info*
  (new 'static 'boxed-array :type bt-vehicle-damage-info
    (new 'static 'bt-vehicle-damage-info :segd #x20 :seg0 #x2 :seg1 #x2 :hp-threshold0 10.0 :hp-threshold1 10.0)
    (new 'static 'bt-vehicle-damage-info :segd #x80 :seg0 #x8 :seg1 #x8 :hp-threshold0 10.0 :hp-threshold1 10.0)
    (new 'static 'bt-vehicle-damage-info
      :segd #x100
      :seg0 #x10
      :seg1 #x10
      :hp-threshold0 10.0
      :hp-threshold1 10.0
      )
    (new 'static 'bt-vehicle-damage-info :segd #x40 :seg0 #x4 :seg1 #x4 :hp-threshold0 10.0 :hp-threshold1 10.0)
    )
  )

(deftype bt-pickup (bt-vehicle)
  ((spots                    surround-spot  4 :inline)
   (riders                   handle         2)
   (quat-before-roll         quaternion     :inline)
   (start-hit-time           time-frame)
   (roboguard-attackers      handle         2)
   (desired-thruster-length  float)
   (pickup-barrels           handle         2)
   )
  (:state-methods
    wait-for-player
    path-follow
    )
  (:methods
    (retrieve-spot (_type_ int vector quaternion) none)
    (assign-spot (_type_ handle) none)
    (bt-pickup-method-48 (_type_) none)
    (update-barrel-pos (_type_ vector vector quaternion) quaternion)
    (bt-pickup-method-50 (_type_ int vector) vector)
    )
  )


(defmethod update-barrel-pos ((this bt-pickup) (arg0 vector) (arg1 vector) (arg2 quaternion))
  (let ((v1-1 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> this root quat))))
    (vector-copy! arg0 (-> this root trans))
    (vector+float*! arg0 arg0 (-> v1-1 uvec) 819.2)
    (vector+float*! arg0 arg0 (-> v1-1 rvec) 4096.0)
    (cond
      ((zero? arg2)
       (vector+float*! arg0 arg0 (-> v1-1 fvec) -16384.0)
       )
      ((= arg2 1)
       (vector+float*! arg0 arg0 (-> v1-1 fvec) -2048.0)
       )
      )
    )
  (quaternion-copy! (the-as quaternion arg1) (-> this root quat))
  )

(defmethod bt-vehicle-event-handler ((this bt-pickup) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('update-barrel-pos)
     (update-barrel-pos
       this
       (the-as vector (-> arg3 param 0))
       (the-as vector (-> arg3 param 1))
       (the-as quaternion (-> arg3 param 2))
       )
     )
    (('bt-roboguard-release)
     (dotimes (v1-2 2)
       (when (= (handle->process (-> this roboguard-attackers v1-2)) arg0)
         (set! (-> this roboguard-attackers v1-2) (the-as handle #f))
         (return 0)
         )
       )
     #f
     )
    (('bt-roboguard-attack?)
     (dotimes (v1-6 2)
       (when (not (handle->process (-> this roboguard-attackers v1-6)))
         (set! (-> this roboguard-attackers v1-6) (process->handle arg0))
         (return #t)
         )
       )
     #f
     )
    (('get-attack-pos)
     (let ((v0-0 (the-as object (-> arg3 param 0))))
       (set! (-> (the-as vector v0-0) quad) (-> this root trans quad))
       v0-0
       )
     )
    (('assign-spot)
     (assign-spot this (the-as handle (-> arg3 param 0)))
     )
    (('retrieve-spot)
     (retrieve-spot
       this
       (the-as int (-> arg3 param 0))
       (the-as vector (-> arg3 param 1))
       (the-as quaternion (-> arg3 param 2))
       )
     )
    (else
      (call-parent-method this arg0 arg1 arg2 arg3)
      )
    )
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod bt-pickup-method-48 ((this bt-pickup))
  (dotimes (v1-0 4)
    (set! (-> this spots v1-0 owner) (the-as handle #f))
    )
  (dotimes (v1-3 2)
    (set! (-> this riders v1-3) (the-as handle #f))
    )
  (none)
  )

;; WARN: Function (method 47 bt-pickup) has a return type of none, but the expression builder found a return statement.
(defmethod assign-spot ((this bt-pickup) (arg0 handle))
  (let ((a1-1 0))
    (let ((v1-0 4))
      (dotimes (a0-1 4)
        (when (handle->process (-> this spots a0-1 owner))
          (set! a1-1 (logior a1-1 (ash 1 a0-1)))
          (+! v1-0 -1)
          )
        )
      (if (zero? v1-0)
          (return -1)
          )
      )
    (set! (-> this spots (rand-vu-int-count-excluding 4 a1-1) owner) arg0)
    )
  (none)
  )

;; WARN: Return type mismatch vector vs none.
(defmethod retrieve-spot ((this bt-pickup) (arg0 int) (arg1 vector) (arg2 quaternion))
  (quaternion-look-at! arg2 *x-vector* *up-vector*)
  (quaternion-rotate-local-y! arg2 arg2 (* 16384.0 (the float arg0)))
  (quaternion-rotate-local-x! arg2 arg2 -9102.223)
  (set! (-> arg1 quad) (the-as uint128 0))
  (none)
  )

(defmethod bt-vehicle-method-34 ((this bt-pickup) (arg0 handle))
  (dotimes (v1-0 2)
    (if (= arg0 (-> this riders v1-0))
        (set! (-> this riders v1-0) (the-as handle #f))
        )
    )
  #f
  )

(defmethod bt-vehicle-method-33 ((this bt-pickup) (arg0 handle))
  (dotimes (v1-0 2)
    (when (not (handle->process (-> this riders v1-0)))
      (set! (-> this riders v1-0) arg0)
      (return v1-0)
      )
    )
  -1
  )

;; WARN: Return type mismatch structure vs object.
(defmethod bt-vehicle-method-36 ((this bt-pickup) (arg0 int) (arg1 vector) (arg2 quaternion))
  (cond
    ((zero? arg0)
     (+! (-> arg1 y) -2457.6)
     (vector+float*! arg1 arg1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)) 4096.0)
     )
    (else
      (+! (-> arg1 y) -2457.6)
      (vector+float*! arg1 arg1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)) -6963.2)
      (vector+float*! arg1 arg1 (vector-x-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)) -6144.0)
      (quaternion-rotate-local-y! arg2 arg2 -16384.0)
      )
    )
  )

(define *bt-hellcat-gun-nodes* (new 'static 'boxed-array :type int32 9 12 8 11))

(define *bt-hellcat-damage-info*
  (new 'static 'boxed-array :type bt-vehicle-damage-info
    (new 'static 'bt-vehicle-damage-info :segd #x400 :seg0 #x40 :seg1 #x4 :hp-threshold0 5.0 :hp-threshold1 7.5)
    (new 'static 'bt-vehicle-damage-info
      :segd #x1000
      :seg0 #x100
      :seg1 #x10
      :hp-threshold0 5.0
      :hp-threshold1 7.5
      )
    (new 'static 'bt-vehicle-damage-info
      :segd #x2000
      :seg0 #x200
      :seg1 #x20
      :hp-threshold0 5.0
      :hp-threshold1 7.5
      )
    (new 'static 'bt-vehicle-damage-info :segd #x800 :seg0 #x80 :seg1 #x8 :hp-threshold0 5.0 :hp-threshold1 7.5)
    )
  )

(deftype bt-hellcat (bt-vehicle)
  ((jmod-turret-guns       joint-mod-rotate-world  :inline)
   (child-turret           handle)
   (spots                  surround-spot           12 :inline)
   (assigned-spots         handle                  2)
   (grunt-rider            handle)
   (grunt-rider-boarded?   handle)
   (rider-pitch            float)
   (pitch-quat             quaternion              :inline)
   (roll-amount            float)
   (dest-roll-amount       float)
   (roll-amount-seek-rate  float)
   (quat-before-bounce     quaternion              :inline)
   (quat-grunt-tilt        quaternion              :inline)
   (jmod-lgun              joint-mod-rotate-local  :inline)
   (jmod-rgun              joint-mod-rotate-local  :inline)
   (jmod-barrels           joint-mod-add-local     4 :inline)
   (barrel-fire-state      symbol                  4)
   (engine-sound           sound-id)
   (thrust-sound           sound-id)
   (land-grunt-offset      float)
   )
  (:state-methods
    wait-for-player
    player-riding
    )
  (:methods
    (bt-hellcat-method-46 (_type_ vector quaternion) quaternion)
    (bt-hellcat-method-47 (_type_ int vector quaternion symbol) int)
    (bt-hellcat-method-48 (_type_ handle quaternion) none)
    (init-spots (_type_) symbol)
    (bt-hellcat-method-50 (_type_ int quaternion vector vector) int)
    (bt-hellcat-method-51 (_type_) symbol)
    )
  )


(defmethod bt-vehicle-method-34 ((this bt-hellcat) (arg0 handle))
  (when (= arg0 (-> this grunt-rider))
    (set! (-> this grunt-rider) (the-as handle #f))
    (set! (-> this grunt-rider-boarded?) (the-as handle #f))
    #f
    )
  )

(defmethod bt-vehicle-method-33 ((this bt-hellcat) (arg0 handle))
  (when (not (handle->process (-> this grunt-rider)))
    (set! (-> this grunt-rider) arg0)
    (set! (-> this grunt-rider-boarded?) (the-as handle #f))
    (return 0)
    )
  -1
  )

;; ERROR: Stack slot load at 176 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 176 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 176 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 176 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 176 mismatch: defined as size 4, got size 16
;; WARN: Return type mismatch quaternion vs object.
(defmethod bt-vehicle-method-36 ((this bt-hellcat) (arg0 int) (arg1 vector) (arg2 quaternion))
  (local-vars (sv-176 float))
  (let ((s3-0 (quaternion->matrix (new 'stack-no-clear 'matrix) arg2)))
    (quaternion-rotate-local-y! arg2 arg2 32768.0)
    (let ((f30-0 0.7)
          (f28-0 -1.1)
          )
      (let ((v1-2 1))
        (cond
          ((= v1-2 2)
           (set! f30-0 1.1)
           (set! f28-0 -1.57)
           )
          ((zero? v1-2)
           (set! f30-0 1.1)
           (set! f28-0 -1.59)
           )
          ((= v1-2 1)
           (set! f30-0 1.1)
           (set! f28-0 -1.3)
           )
          )
        )
      (let ((v1-13 (new 'stack-no-clear 'vector)))
        (vector-float*! v1-13 (-> s3-0 uvec) (* 4096.0 f30-0))
        (vector+float*! v1-13 v1-13 (-> s3-0 fvec) (* 4096.0 f28-0))
        )
      (when (handle->process (-> this child-turret))
        (let ((s1-0 (new 'stack-no-clear 'vector))
              (s2-0 (new 'stack-no-clear 'vector))
              )
          (let ((s0-0 (new 'stack-no-clear 'vector)))
            (bt-hellcat-method-46 this s1-0 (new 'stack-no-clear 'quaternion))
            (vector-! s1-0 s1-0 (-> this root trans))
            (vector-float*! s0-0 (-> s3-0 uvec) (* 4096.0 f30-0))
            (vector+float*! s0-0 s0-0 (-> s3-0 fvec) (* 4096.0 f28-0))
            (vector-! s2-0 s0-0 s1-0)
            )
          (let ((f30-1 (-> this land-grunt-offset)))
            (let ((s4-1 vector-rotate-around-axis!)
                  (s3-1 s2-0)
                  (s0-1 s2-0)
                  )
              (set! sv-176 f30-1)
              (let ((a3-1 (vector-y-quaternion! (new 'stack-no-clear 'vector) arg2)))
                (s4-1 s3-1 s0-1 sv-176 a3-1)
                )
              )
            (vector+! s2-0 s2-0 s1-0)
            (vector+! arg1 arg1 s2-0)
            (quaternion-rotate-local-y! arg2 arg2 f30-1)
            )
          )
        )
      )
    )
  )

(defmethod on-attacked ((this bt-hellcat) (arg0 float) (arg1 attack-info) (arg2 process-focusable))
  (sound-play "snd-hellcat-hit")
  (cond
    ((logtest? (-> group-bt-dummy flags) (sp-group-flag sp13))
     (vector-copy! (-> *launch-matrix* trans) (-> arg1 intersection))
     (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-bt-dummy)
     )
    (else
      (vector-copy! (-> *launch-matrix* trans) (-> arg1 intersection))
      (part-tracker-spawn part-tracker :to *entity-pool* :group group-bt-dummy)
      )
    )
  (if (logtest? (-> arg1 mask) (attack-mask control))
      (set! arg0 (-> arg1 control))
      )
  (let ((f28-0 (* 409.6 arg0))
        (f30-0 (lerp 0.05 1.0 (/ arg0 5)))
        )
    (activate! *camera-smush-control* f28-0 45 (the int (* 300.0 f30-0)) 1.0 0.9 (-> *display* camera-clock))
    (cpad-set-buzz! (-> *cpad-list* cpads 0) 1 204 (the-as time-frame (the int (* 150.0 f30-0))))
    )
  (call-parent-method this arg0 arg1 arg2)
  0
  (none)
  )

(defmethod bt-hellcat-method-50 ((this bt-hellcat) (arg0 int) (arg1 quaternion) (arg2 vector) (arg3 vector))
  (local-vars (sv-48 vector) (sv-56 int) (sv-64 number) (sv-68 quaternion))
  (set! sv-48 (new 'stack-no-clear 'vector))
  (set! sv-56 -1)
  (set! sv-64 -1.0)
  (set! sv-68 (new 'stack-no-clear 'quaternion))
  (quaternion-copy! sv-68 arg1)
  (let ((v1-5 (the-as bt-gun-manager (handle->process (-> this child-turret)))))
    (quaternion-copy! sv-68 (-> v1-5 cam-quat))
    )
  (vector-z-quaternion! sv-48 sv-68)
  (let ((a0-8 sv-48))
    (vector-copy! a0-8 sv-48)
    (set! (-> a0-8 y) 0.0)
    (vector-normalize! a0-8 1.0)
    )
  (dotimes (s2-0 12)
    (when (= (-> this spots s2-0 rider-index) arg0)
      (let ((a0-9 (new 'stack-no-clear 'vector)))
        (vector-copy! a0-9 (-> this spots s2-0 offset-dir))
        (set! (-> a0-9 y) 0.0)
        (let ((v1-18 (vector-normalize! a0-9 1.0)))
          0.0
          (let ((f0-5 (vector-dot v1-18 sv-48)))
            (when (< (the-as float sv-64) f0-5)
              (set! sv-64 f0-5)
              (set! sv-56 s2-0)
              (if arg3
                  (vector-copy! arg3 v1-18)
                  )
              )
            )
          )
        )
      )
    )
  (if arg2
      (vector-copy! arg2 sv-48)
      )
  sv-56
  )

(defmethod init-spots ((this bt-hellcat))
  (dotimes (v1-0 12)
    (set! (-> this spots v1-0 rider-index) -1)
    )
  (dotimes (v1-3 2)
    (set! (-> this assigned-spots v1-3) (the-as handle #f))
    )
  (let* ((f30-0 5461.3335)
         (s5-0 (the int (/ 65536.0 f30-0)))
         (f28-0 (/ f30-0 2))
         )
    (dotimes (s4-0 s5-0)
      (vector-rotate-around-y!
        (the-as vector (+ (the-as uint (-> this spots 0 offset-dir)) (* s4-0 64)))
        *x-vector*
        f28-0
        )
      (+! f28-0 f30-0)
      (set! (-> this spots s4-0 owner) (the-as handle #f))
      (set! (-> this spots s4-0 rider-index) (logand s4-0 1))
      (let* ((f26-0 364.0889)
             (f24-0 -4915.2)
             (v1-16 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-17 (the-as number (logior #x3f800000 v1-16)))
             )
        (set! (-> this spots s4-0 y-rot) (+ f26-0 (* f24-0 (+ -1.0 (the-as float v1-17)))))
        )
      )
    )
  #f
  )

(defmethod bt-hellcat-method-48 ((this bt-hellcat) (arg0 handle) (arg1 quaternion))
  (local-vars (s3-0 int) (sv-16 int) (sv-24 int) (sv-64 number) (sv-72 int) (sv-80 vector) (sv-84 vector))
  (set! sv-16 0)
  (set! sv-24 2)
  (dotimes (v1-1 2)
    (when (handle->process (-> this assigned-spots v1-1))
      (set! sv-16 (logior sv-16 (ash 1 v1-1)))
      (set! sv-24 (+ sv-24 -1))
      )
    )
  (when (zero? sv-24)
    (set! s3-0 -1)
    (goto cfg-26)
    )
  (set! sv-64 -1.0)
  (set! sv-72 -1)
  (set! sv-80 (new 'stack-no-clear 'vector))
  (set! sv-84 (new 'stack-no-clear 'vector))
  (dotimes (s3-1 2)
    (when (not (logtest? sv-16 (ash 1 s3-1)))
      (bt-hellcat-method-50 this s3-1 arg1 sv-80 sv-84)
      0.0
      (let ((f0-3 (vector-dot sv-80 sv-84)))
        (when (< (the-as float sv-64) f0-3)
          (set! sv-72 s3-1)
          (set! sv-64 f0-3)
          )
        )
      )
    )
  (set! s3-0 sv-72)
  (set! (-> this assigned-spots s3-0) arg0)
  (set! (-> this spots (bt-hellcat-method-50 this s3-0 arg1 (the-as vector #f) (the-as vector #f)) owner) arg0)
  (label cfg-26)
  (none)
  )

;; 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]
(defmethod bt-hellcat-method-47 ((this bt-hellcat) (arg0 int) (arg1 vector) (arg2 quaternion) (arg3 symbol))
  (local-vars
    (f0-4 float)
    (sv-176 symbol)
    (sv-192 int)
    (sv-208 vector)
    (sv-224 quaternion)
    (sv-240 vector)
    (sv-256 matrix)
    )
  (set! sv-176 arg3)
  (set! sv-192 0)
  (while (< sv-192 12)
    (when (and (= arg0 (-> this spots sv-192 rider-index)) (handle->process (-> this spots sv-192 owner)))
      (let ((s0-0 (-> this spots sv-192)))
        (let ((s2-0 (new 'stack-no-clear 'vector)))
          (set! sv-208 (new 'stack-no-clear 'vector))
          (let ((s1-0 (new 'stack-no-clear 'vector)))
            (bt-hellcat-method-46 this s2-0 (the-as quaternion sv-208))
            (when sv-176
              (set! sv-224 (quaternion-copy! (new 'stack-no-clear 'quaternion) (the-as quaternion sv-208)))
              (set! sv-240 (new 'stack-no-clear 'vector))
              (let ((v1-21 (the-as bt-gun-manager (handle->process (-> this child-turret)))))
                (quaternion-copy! sv-224 (-> v1-21 cam-quat))
                )
              (vector-z-quaternion! sv-240 sv-224)
              (let ((a0-14 sv-240))
                (vector-copy! a0-14 sv-240)
                (set! (-> a0-14 y) 0.0)
                (vector-normalize! a0-14 1.0)
                )
              (acos (vector-dot sv-240 (the-as vector (+ (the-as uint (-> this spots 0 offset-dir)) (* sv-192 64)))))
              (let ((f30-0 4551.1113)
                    (t9-6 acos)
                    )
                ;; og:preserve-this
                (let* ((v1-29 (-> this spots sv-192 offset-dir))
                       ; (v1-29 (the-as object (+ (the-as uint (-> this spots 0 offset-dir)) (* sv-192 64))))
                       ; (f0-3 (-> sv-240 x))
                       ; (f1-0 (-> sv-240 y))
                       ; (f2-0 (-> sv-240 z))
                       ; (f3-0 (-> (the-as vector v1-29) x))
                       ; (f4-0 (-> (the-as vector v1-29) y))
                       ; (f5-0 (-> (the-as vector v1-29) z))
                       )
                  ; (.mula.s f0-3 f3-0)
                  ; (.madda.s f1-0 f4-0)
                  ; (.madd.s f0-4 f2-0 f5-0)
                  (set! f0-4 (vector-dot sv-240 v1-29))
                  )
                (when (< f30-0 (t9-6 f0-4))
                  (let ((v1-33 (bt-hellcat-method-50 this arg0 (-> this root quat) (the-as vector #f) (the-as vector #f))))
                    (let ((a0-25 (-> s0-0 owner)))
                      (set! (-> s0-0 owner) (the-as handle #f))
                      (set! (-> this spots v1-33 owner) a0-25)
                      )
                    (set! s0-0 (-> this spots v1-33))
                    )
                  )
                )
              )
            (let ((v1-38 (handle->process (-> this child-turret))))
              (when v1-38
                (let ((s3-1 matrix-u-f-compose))
                  (set! sv-256 (new 'stack-no-clear 'matrix))
                  (let* ((a1-15 (vector-y-quaternion! (new 'stack-no-clear 'vector) (the-as quaternion (&-> v1-38 stack 4064))))
                         (a2-3 (-> s0-0 offset-dir))
                         (a1-16 (s3-1 sv-256 a1-15 a2-3))
                         )
                    (matrix->quaternion arg2 a1-16)
                    )
                  )
                (quaternion-rotate-local-x! arg2 arg2 (/ (-> this roll-amount) 2))
                )
              )
            (vector-! s1-0 s2-0 (-> this root trans))
            (vector+! arg1 arg1 s1-0)
            )
          )
        (quaternion-rotate-local-x! arg2 arg2 (-> s0-0 y-rot))
        )
      (return 0)
      )
    (set! sv-192 (+ sv-192 1))
    )
  0
  )

(define *bt-turret-params* (new 'static 'target-turret-params
                             :fire-interval (seconds 0.1)
                             :max-health 16.0
                             :roty-accel -118328.89
                             :roty-friction 0.8
                             :rotyv-max 98304.0
                             :rotx-accel -81920.0
                             :rotx-friction 0.8
                             :rotxv-max 10922.667
                             :rotx-min -6371.5557
                             :rotx-max 2184.5334
                             )
        )

(defbehavior bt-gun-manager-init-by-other bt-gun-manager ((arg0 target-turret-params))
  (stack-size-set! (-> self main-thread) 256)
  (set! (-> self parent-vehicle) (the-as handle arg0))
  (set! (-> self root) (the-as collide-shape (new 'process 'trsqv)))
  (vector-copy! (-> self root trans) (target-pos 0))
  (quaternion-identity! (-> self root quat))
  (matrix-identity! (-> self last-parent-xform))
  (set! (-> self params) *bt-turret-params*)
  (set! (-> self rotx-min) (-> self params rotx-min))
  (set! (-> self rotx-max) (-> self params rotx-max))
  (set! (-> self dest-roty-min) -20024.889)
  (set! (-> self dest-roty-max) 20024.889)
  (set! (-> self roty-min) (-> self dest-roty-min))
  (set! (-> self roty-max) (-> self dest-roty-max))
  (set! (-> self enable-controls?) #t)
  (set! (-> self can-exit?) #f)
  (set! (-> self target-hand) (the-as handle #f))
  (set! (-> self is-snapping?) #f)
  (set! (-> self servo-sound) (new-sound-id))
  (set! (-> self look-cursor path) (-> *blow-tower-paths* 0))
  (set! (-> self look-time-offset) (seconds 0.5))
  (set! (-> self look-time-scalar) 1.0)
  (set! (-> self rotx) 0.5)
  (set! (-> self roty) 0.5)
  (dotimes (v1-19 32)
    (set! (-> self hud-pers v1-19 hand) (the-as handle #f))
    )
  (go-virtual idle)
  )

(defstate idle (bt-gun-manager)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('pickup)
       (go-virtual setup)
       )
      )
    )
  :code sleep-code
  )

(defbehavior bt-gun-manager-handler bt-gun-manager ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (bt-gun-handler self arg0 arg1 arg2 arg3)
  )

(defmethod bt-gun-handler ((this bt-gun-manager) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (local-vars (v0-0 object))
  (case arg2
    (('turret-type)
     'hellcat
     )
    (('allow-exit)
     (set! v0-0 #t)
     (set! (-> this can-exit?) (the-as symbol v0-0))
     v0-0
     )
    (('trans 'player-pos)
     (let ((v1-1 (new 'stack-no-clear 'vector)))
       (vector-copy! v1-1 (-> this root trans))
       (set! v0-0 (-> arg3 param 0))
       (set! (-> (the-as vector v0-0) quad) (-> v1-1 quad))
       )
     v0-0
     )
    (('snap-forward)
     (set! (-> this roty) 0.0)
     (set! (-> this rotx) 0.0)
     (set! (-> this rotyv) 0.0)
     (set! (-> this rotxv) 0.0)
     )
    (('cam-post-update)
     (when (not (paused?))
       (find-target this)
       (bt-gun-manager-method-19 this)
       (fire-shot this)
       )
     )
    (('look-at-restore)
     (case (-> this look-mode)
       ((2 1)
        (let ((v1-10 (entity-by-name (the-as string (-> this look-ent)))))
          (when v1-10
            (when (and (-> v1-10 extra process) (= (process->handle (-> v1-10 extra process)) (-> arg3 param 0)))
              (set! (-> this look-mode) (the-as uint 0))
              (set! (-> this look-time-scalar) 1.0)
              )
            )
          )
        )
       )
     )
    (('look-at-ent)
     (set! (-> this look-mode) (the-as uint 1))
     (set! (-> this look-ent) (the-as entity-actor (-> arg3 param 0)))
     (set! (-> this look-time-scalar) (the-as float (-> arg3 param 1)))
     )
    (('look-at-track)
     (set! (-> this look-mode) (the-as uint 2))
     (set! (-> this look-ent) (the-as entity-actor (-> arg3 param 0)))
     (set! (-> this look-time-scalar) (the-as float (-> arg3 param 1)))
     )
    (('look-at-proc)
     (set! (-> this look-mode) (the-as uint 3))
     (set! (-> this look-time-scalar) (the-as float (-> arg3 param 1)))
     (set! v0-0 (-> arg3 param 0))
     (set! (-> this look-proc) (the-as handle v0-0))
     v0-0
     )
    (('look-at)
     (set! (-> this look-cursor path) (-> *blow-tower-paths* (-> arg3 param 0)))
     (set! (-> this look-time-offset) (the-as time-frame (-> arg3 param 1)))
     (set! (-> this look-time-scalar) (the-as float (-> arg3 param 2)))
     (set! (-> this look-mode) (the-as uint 0))
     0
     )
    (('aim-quat)
     (quaternion-copy! (the-as quaternion (-> arg3 param 0)) (-> this aim-quat))
     )
    (('hit-pos)
     (set! v0-0 (-> arg3 param 0))
     (set! (-> (the-as vector v0-0) quad) (-> this hit-pos quad))
     v0-0
     )
    (('quat 'player-quat)
     (quaternion-copy! (the-as quaternion (-> arg3 param 0)) (-> this root quat))
     )
    (('exit-valid)
     (set! (-> (the-as vector (-> arg3 param 0)) quad) (-> this root trans quad))
     (-> this can-exit?)
     )
    (('exit)
     #f
     )
    (('use-camera)
     (if (-> arg3 param 0)
         (set-setting! 'mode-name 'cam-bt-gun 0.0 0)
         (remove-setting! 'mode-name)
         )
     )
    (('get-cam-info)
     (set! (-> (the-as vector (-> arg3 param 0)) quad) (-> this root trans quad))
     (quaternion-copy! (the-as quaternion (-> arg3 param 1)) (-> this root quat))
     (add-debug-quaternion #t (bucket-id debug-no-zbuf1) (-> this root trans) (-> this root quat))
     (quaternion-copy! (the-as quaternion (-> arg3 param 1)) (-> this cam-quat))
     #t
     )
    )
  )

(defstate active (bt-gun-manager)
  :virtual #t
  :event bt-gun-manager-handler
  :enter (behavior ()
    (send-event (handle->process (-> self parent-vehicle)) 'player-board)
    (add-connection
      *cam-post-hook-engine*
      self
      (lambda ((arg0 process)) (send-event arg0 'cam-post-update))
      #f
      #f
      #f
      )
    )
  :trans (behavior ()
    (bt-gun-manager-method-17 self)
    (bt-gun-manager-method-18 self 0.33)
    )
  :code sleep-code
  )

(defstate setup (bt-gun-manager)
  :virtual #t
  :event bt-gun-manager-handler
  :code (behavior ()
    (set-blackout-frames (seconds 1))
    (until (and (-> *target* next-state) (= (-> *target* next-state name) 'target-turret-stance))
      (let ((a1-0 (new 'stack-no-clear 'event-message-block)))
        (let ((v1-0 (process->ppointer self)))
          (set! (-> a1-0 from) v1-0)
          )
        (set! (-> a1-0 num-params) 2)
        (set! (-> a1-0 message) 'change-mode)
        (set! (-> a1-0 param 0) (the-as uint 'turret))
        (set! (-> a1-0 param 1) (the-as uint self))
        (send-event-function *target* a1-0)
        )
      (suspend)
      )
    (send-event self 'use-camera #t)
    (set-setting! 'interp-time 'abs 0.0 0)
    (go-virtual active)
    )
  )

(define *fov-to-use* 13653.333)

(defstate cam-bt-gun (camera-slave)
  :event cam-standard-event-handler
  :enter (behavior ()
    (when (not (-> self enter-has-run))
      (vector-copy! (-> self saved-pt) (-> self trans))
      (set! (-> self blend-from-type) (camera-blend-from-type unknown-1))
      (set! (-> self blend-to-type) (camera-blend-to-type unknown-0))
      0
      )
    )
  :trans (behavior ()
    (seek! (-> self fov) *fov-to-use* (* 8192.0 (seconds-per-frame)))
    (if (not (logtest? (-> *camera* master-options) (cam-master-options-u32 HAVE_TARGET)))
        (cam-slave-go cam-free-floating)
        )
    )
  :code (behavior ()
    (until #f
      (when (not (paused?))
        (let ((a0-1 (handle->process (-> *camera* focus handle))))
          (when a0-1
            (let ((a1-1 (new 'stack-no-clear 'event-message-block)))
              (set! (-> a1-1 from) (process->ppointer self))
              (set! (-> a1-1 num-params) 0)
              (set! (-> a1-1 message) 'get-turret)
              (let ((a0-5 (handle->process (send-event-function a0-1 a1-1))))
                (when a0-5
                  (let ((gp-0 (new 'stack-no-clear 'quaternion)))
                    (if (send-event a0-5 'get-cam-info (-> self trans) gp-0)
                        (forward-up->inv-matrix
                          (-> self tracking inv-mat)
                          (vector-z-quaternion! (new 'stack-no-clear 'vector) gp-0)
                          (vector-y-quaternion! (new 'stack-no-clear 'vector) gp-0)
                          )
                        )
                    )
                  )
                )
              )
            )
          )
        )
      (suspend)
      )
    #f
    )
  )

(defmethod bt-gun-manager-method-23 ((this bt-gun-manager))
  (let ((v1-1 (the-as uint #xffffffff)))
    (dotimes (a1-0 (-> this num-onscreen-targets))
      (set! (-> this onscreen-targets a1-0 target-pers-index) -1)
      (let ((a2-3 (-> this onscreen-targets a1-0 hand)))
        (dotimes (a3-2 32)
          (when (logtest? v1-1 (ash 1 a3-2))
            (when (= a2-3 (-> this hud-pers a3-2 hand))
              (set! v1-1 (logclear v1-1 (ash 1 a3-2)))
              (set! (-> this onscreen-targets a1-0 target-pers-index) a3-2)
              )
            )
          )
        )
      )
    (dotimes (a1-3 (-> this num-onscreen-targets))
      (when (= (-> this onscreen-targets a1-3 target-pers-index) -1)
        (dotimes (a2-9 32)
          (when (logtest? v1-1 (ash 1 a2-9))
            (set! (-> this hud-pers a2-9 hand) (-> this onscreen-targets a1-3 hand))
            (set! (-> this hud-pers a2-9 alpha) 0.0)
            (set! (-> this hud-pers a2-9 rotate) 0.0)
            (set! (-> this hud-pers a2-9 size-scalar) 4.0)
            (set! (-> this hud-pers a2-9 outer-rotate) 0.0)
            (set! (-> this hud-pers a2-9 outer-alpha) 0.0)
            (set! (-> this onscreen-targets a1-3 target-pers-index) a2-9)
            (set! v1-1 (logclear v1-1 (ash 1 a2-9)))
            0
            (goto cfg-30)
            )
          )
        )
      (label cfg-30)
      )
    )
  #f
  )

;; WARN: Return type mismatch symbol vs none.
;; ERROR: Function may read a register that is not set: s4
(defmethod bt-gun-manager-method-19 ((this bt-gun-manager))
  (local-vars
    (v1-17 symbol)
    ;; og:preserve-this
    (s4-0 object)
    (f28-0 float)
    (f30-0 float)
    (sv-64 vector)
    (sv-68 bt-hud-target-pers)
    (sv-96 vector)
    (sv-100 vector)
    (sv-112 process)
    (sv-128 vector)
    (sv-144 vector)
    )
  (bt-gun-manager-method-23 this)
  (set! (-> this hud-target tid)
        (the-as
          texture-id
          (lookup-texture-by-name "hud-target-reticle-fancy-01" (the-as string #f) (the-as (pointer texture-page) #f))
          )
        )
  (set! (-> this hud-target-inner tid)
        (the-as
          texture-id
          (lookup-texture-by-name "hud-target-reticle-fancy-02" (the-as string #f) (the-as (pointer texture-page) #f))
          )
        )
  (dotimes (v1-1 (-> this num-onscreen-targets))
    (set! (-> this onscreen-targets v1-1 num-overlap) 0)
    )
  (dotimes (s5-0 (-> this num-onscreen-targets))
    (let ((s3-0 (new 'stack-no-clear 'vector)))
      (transform-point-vector!
        s3-0
        (get-trans
          (the-as process-focusable (as-type (handle->process (-> this onscreen-targets s5-0 hand)) process-focusable))
          3
          )
        )
      (let ((s2-1 (+ s5-0 1))
            (s1-1 (+ (-> this num-onscreen-targets) -1))
            )
        (while (>= s1-1 s2-1)
          (set! sv-128 (new 'stack-no-clear 'vector))
          (let ((s0-1 transform-point-vector!))
            (set! sv-144 sv-128)
            (let ((v1-15 (-> this onscreen-targets s2-1 hand)))
              (set! s4-0 (and (nonzero? (l32-false-check v1-15)) (begin
                                                                   (set! sv-112 (the-as process s4-0))
                                                                   (let ((a0-15 (-> v1-15 process 0)))
                                                                     (set! v1-17 (when (= (-> v1-15 pid) (-> a0-15 pid))
                                                                                   (set! sv-112 (the-as process v1-17))
                                                                                   (set! sv-112 a0-15)
                                                                                   v1-17
                                                                                   )
                                                                           )
                                                                     )
                                                                   sv-112
                                                                   s4-0
                                                                   )
                              )
                    )
              )
            (let ((a1-9 (get-trans
                          (the-as process-focusable (if (type? sv-112 process-focusable)
                                                        (the-as process-focusable sv-112)
                                                        )
                                  )
                          3
                          )
                        )
                  )
              (s0-1 sv-144 a1-9)
              )
            )
          (let ((t9-9 vector-vector-distance)
                (a1-10 s3-0)
                )
            (when (< (t9-9 sv-128 a1-10) (+ (-> this onscreen-targets s5-0 size) (-> this onscreen-targets s2-1 size)))
              (+! (-> this onscreen-targets s5-0 num-overlap) 1)
              (+! (-> this onscreen-targets s2-1 num-overlap) 1)
              )
            )
          (+! s2-1 1)
          )
        )
      )
    )
  (dotimes (s5-1 (-> this num-onscreen-targets))
    (set! sv-64 (new 'stack-no-clear 'vector))
    (set! sv-68 (-> this hud-pers (-> this onscreen-targets s5-1 target-pers-index)))
    (when (and (< (-> this onscreen-targets s5-1 size) 256.0)
               (!= (-> (handle->process (-> this onscreen-targets s5-1 hand)) type) bt-barrel)
               )
      (set! sv-96 (new 'stack-no-clear 'vector))
      (set! sv-100
            (get-trans
              (the-as process-focusable (as-type (handle->process (-> this onscreen-targets s5-1 hand)) process-focusable))
              3
              )
            )
      (transform-point-vector! sv-96 sv-100)
      (+! (-> sv-96 x) -1792.0)
      (+! (-> sv-96 y) -1840.0)
      (when (and (>= (-> sv-96 x) 0.0) (>= 2048.0 (-> sv-96 x)) (>= (-> sv-96 y) 0.0) (>= 2048.0 (-> sv-96 y)))
        (cond
          ((-> this onscreen-targets s5-1 hit?)
           (seek! (-> sv-68 rotate) 16384.0 (* 65536.0 (seconds-per-frame)))
           (seek! (-> sv-68 size-scalar) 1.0 (* 16.0 (seconds-per-frame)))
           (set! (-> sv-68 alpha) 1.0)
           )
          (else
            (seek! (-> sv-68 size-scalar) 4.0 (* 8.0 (seconds-per-frame)))
            (seek! (-> sv-68 rotate) 0.0 (* 65536.0 (seconds-per-frame)))
            (seek! (-> sv-68 alpha) 0.0 (* 3.0 (seconds-per-frame)))
            (set! (-> sv-68 outer-rotate) (- (-> sv-68 outer-rotate) (* 32768.0 (seconds-per-frame))))
            )
          )
        0.0
        0.0
        (set! f28-0 (cond
                      ((-> this onscreen-targets s5-1 hit?)
                       (set! (-> this hud-target color x) 127)
                       (set! (-> this hud-target color y) 75)
                       (set! (-> this hud-target color z) 0)
                       (set! f30-0 (* 80.0 (-> this onscreen-targets s5-1 alpha)))
                       (set! (-> this hud-target-inner color x) 127)
                       (set! (-> this hud-target-inner color y) 40)
                       (set! (-> this hud-target-inner color z) 0)
                       (set! f28-0 (* 80.0 (-> this onscreen-targets s5-1 alpha)))
                       (when (= (current-time) (-> sv-68 hold-start-time))
                         (set! (-> this hud-target color x) 128)
                         (set! (-> this hud-target color y) 128)
                         (set! (-> this hud-target color z) 128)
                         (set! f30-0 64.0)
                         (set! (-> this hud-target-inner color x) 255)
                         (set! (-> this hud-target-inner color y) 0)
                         (set! (-> this hud-target-inner color z) 0)
                         (set! f28-0 64.0)
                         )
                       f28-0
                       )
                      (else
                        (set! (-> this hud-target color x) 127)
                        (set! (-> this hud-target color y) 40)
                        (set! (-> this hud-target color z) 0)
                        (set! f30-0 (* 45.0 (-> this onscreen-targets s5-1 alpha)))
                        (* 80.0 (-> sv-68 alpha) (-> this onscreen-targets s5-1 alpha))
                        )
                      )
              )
        (let ((f0-40 (vector-vector-distance sv-100 (camera-pos))))
          0.0
          (let* ((f0-41 (lerp-scale-clamp 1.0 0.1 f0-40 327680.0 819200.0))
                 (f1-22 (* f30-0 f0-41))
                 (f0-42 (* f28-0 f0-41))
                 )
            (set! (-> this hud-target color w) (the int f1-22))
            (set! (-> this hud-target-inner color w) (the int f0-42))
            )
          )
        (set! (-> this hud-target angle) 0.0)
        (set! (-> this hud-target flags) (hud-sprite-flags hsf3))
        (set! (-> this hud-target-inner flags) (hud-sprite-flags hsf3))
        (let* ((f0-46 (/ (-> this onscreen-targets s5-1 size) 32))
               (f0-48 (fmax 0.4 (fmin 2.0 f0-46)))
               (f0-49 (* 2.0 f0-48))
               )
          (set! (-> this hud-target scale-x) f0-49)
          (set! (-> this hud-target scale-y) f0-49)
          (set! (-> this hud-target-inner scale-x) (* (-> sv-68 size-scalar) f0-49))
          (set! (-> this hud-target-inner scale-y) (* (-> sv-68 size-scalar) f0-49))
          )
        (set! (-> this hud-target pos x) (the int (the float (the int (-> sv-96 x)))))
        (set! (-> this hud-target pos y) (the int (the float (the int (-> sv-96 y)))))
        (set! (-> this hud-target pos z) 0)
        (set! (-> this hud-target-inner pos x) (the int (the float (the int (-> sv-96 x)))))
        (set! (-> this hud-target-inner pos y) (the int (the float (the int (-> sv-96 y)))))
        (set! (-> this hud-target-inner pos z) 0)
        (set! (-> this hud-target-inner angle) (-> sv-68 rotate))
        (set! (-> this hud-target angle) (-> sv-68 outer-rotate))
        (with-dma-buffer-add-bucket ((s3-2 (-> *display* frames (-> *display* on-screen) global-buf))
                                     (bucket-id hud-draw-hud-alpha)
                                     )
          (draw (-> this hud-target) s3-2 (-> *level* level-default) #f)
          )
        (with-dma-buffer-add-bucket ((s3-3 (-> *display* frames (-> *display* on-screen) global-buf))
                                     (bucket-id hud-draw-hud-alpha)
                                     )
          (draw (-> this hud-target-inner) s3-3 (-> *level* level-default) #f)
          )
        )
      )
    )
  (none)
  )

(when (or (zero? *bt-clamp-curve-x*) (!= loading-level global))
  (set! *bt-clamp-curve-x* (new 'loading-level 'curve2d-piecewise))
  (allocate! *bt-clamp-curve-x* 7 'loading-level #t)
  )

(set! (-> *bt-clamp-curve-x* pts data 0 first) 0.0)

(set! (-> *bt-clamp-curve-x* pts data 0 second) -1.0)

(set! (-> *bt-clamp-curve-x* pts data 1 first) 25.0)

(set! (-> *bt-clamp-curve-x* pts data 1 second) -5.5)

(set! (-> *bt-clamp-curve-x* pts data 2 first) 35.0)

(set! (-> *bt-clamp-curve-x* pts data 2 second) -8.5)

(set! (-> *bt-clamp-curve-x* pts data 3 first) 50.0)

(set! (-> *bt-clamp-curve-x* pts data 3 second) -5.0)

(set! (-> *bt-clamp-curve-x* pts data 4 first) 65.0)

(set! (-> *bt-clamp-curve-x* pts data 4 second) -9.0)

(set! (-> *bt-clamp-curve-x* pts data 5 first) 90.0)

(set! (-> *bt-clamp-curve-x* pts data 5 second) -10.0)

(set! (-> *bt-clamp-curve-x* pts data 6 first) 180.0)

(set! (-> *bt-clamp-curve-x* pts data 6 second) -10.0)

(when (or (zero? *bt-accel-curve*) (!= loading-level global))
  (set! *bt-accel-curve* (new 'loading-level 'curve2d-piecewise))
  (allocate! *bt-accel-curve* 4 'loading-level #t)
  )

(set! (-> *bt-accel-curve* pts data 0 first) 0.0)

(set! (-> *bt-accel-curve* pts data 0 second) 1.0)

(set! (-> *bt-accel-curve* pts data 1 first) 1.0)

(set! (-> *bt-accel-curve* pts data 1 second) 1.5)

(set! (-> *bt-accel-curve* pts data 2 first) 1.5)

(set! (-> *bt-accel-curve* pts data 2 second) 1.5)

(set! (-> *bt-accel-curve* pts data 3 first) 2.5)

(set! (-> *bt-accel-curve* pts data 3 second) 2.0)

(defmethod bt-gun-manager-method-17 ((this bt-gun-manager))
  (send-event
    (handle->process (-> this parent-vehicle))
    'get-turret-pos
    (-> this root trans)
    (-> this parent-quat)
    )
  (let ((a0-6 (new 'stack-no-clear 'vector)))
    (transform-point-vector! a0-6 (-> this aim-pos))
    )
  (let ((f30-0 -1.0))
    (if (-> *setting-control* cam-current flip-vertical)
        (set! f30-0 (* -1.0 f30-0))
        )
    (set! (-> this rotyv) (analog-input (the-as int (-> *cpad-list* cpads 0 leftx)) 128.0 32.0 120.0 1.0))
    (set! (-> this rotxv)
          (* f30-0 (analog-input (the-as int (-> *cpad-list* cpads 0 lefty)) 128.0 32.0 120.0 1.0))
          )
    )
  (let ((f0-4 0.6))
    (if (-> this found-target?)
        (set! f0-4 (* 0.7 f0-4))
        )
    (set! (-> this rotyv) (* (-> this rotyv) f0-4))
    (set! (-> this rotxv) (* 1.2307693 f0-4 (-> this rotxv)))
    0.0
    0.0
    (let ((f1-8 (-> this rotyv))
          (f2-1 (-> this rotxv))
          )
      0.0
      (let* ((f1-10 (/ (fabs f1-8) f0-4))
             (f2-3 (/ (fabs f2-1) (* 1.2307693 f0-4)))
             (f0-6 (* f1-10 f1-10))
             (f28-0 (* f2-3 f2-3))
             (f1-11 f28-0)
             (f1-13 (* f1-11 f1-11))
             (f2-4 f0-6)
             (f30-1 (sqrtf (+ f1-13 (* f2-4 f2-4))))
             )
        (let ((f26-0 0.0)
              (f24-0 0.0)
              )
          (cond
            ((or (< 0.9 f0-6) (< 0.95 f30-1))
             (set! f26-0 2.5)
             (set! f24-0 (* 6.0 (seconds-per-frame)))
             )
            (else
              (set! f26-0
                    (cond
                      ((< 0.75 f0-6)
                       (if (-> this found-target?)
                           (seek! (-> this y-boost-scalar) 0.0 (* 6.0 (seconds-per-frame)))
                           )
                       (cond
                         ((and (< 1.0 (-> this y-boost-scalar)) (< f30-1 0.95))
                          (seek! (-> this y-boost-scalar) (fmin 1.0 (-> this y-boost-scalar)) (* 12.0 (seconds-per-frame)))
                          )
                         (else
                           )
                         )
                       f26-0
                       )
                      (else
                        (set! f24-0 (* 60.0 (seconds-per-frame)))
                        0.0
                        )
                      )
                    )
              )
            )
          (seek! (-> this y-boost-scalar) f26-0 f24-0)
          )
        (let ((f26-1 0.0)
              (f24-1 0.0)
              )
          (cond
            ((or (< 0.9 f28-0) (< 0.95 f30-1))
             (set! f26-1 2.5)
             (set! f24-1 (* 6.0 (seconds-per-frame)))
             )
            (else
              (set! f26-1
                    (cond
                      ((< 0.75 f28-0)
                       (if (-> this found-target?)
                           (seek! (-> this x-boost-scalar) 0.0 (* 6.0 (seconds-per-frame)))
                           )
                       (cond
                         ((and (< 1.0 (-> this x-boost-scalar)) (< f30-1 0.95))
                          (seek! (-> this x-boost-scalar) (fmin 1.0 (-> this x-boost-scalar)) (* 12.0 (seconds-per-frame)))
                          )
                         (else
                           )
                         )
                       f26-1
                       )
                      (else
                        (set! f24-1 (* 60.0 (seconds-per-frame)))
                        0.0
                        )
                      )
                    )
              )
            )
          (seek! (-> this x-boost-scalar) f26-1 f24-1)
          )
        )
      )
    )
  (set! (-> this y-boost-scalar) (fmax 0.0 (fmin 2.5 (-> this y-boost-scalar))))
  (set! (-> this x-boost-scalar) (fmax 0.0 (fmin 2.5 (-> this x-boost-scalar))))
  (set! (-> this rotyv)
        (* (-> this rotyv) (evaluate *bt-accel-curve* (-> this y-boost-scalar) (loop-behavior b2)))
        )
  (set! (-> this rotxv)
        (* (-> this rotxv) (evaluate *bt-accel-curve* (-> this x-boost-scalar) (loop-behavior b2)))
        )
  (set! (-> this rotxv) (* 0.8 (-> this rotxv)))
  (+! (-> this roty) (* (-> this rotyv) (seconds-per-frame)))
  (+! (-> this rotx) (* (-> this rotxv) (seconds-per-frame)))
  (set! (-> this roty-min) 0.0)
  (set! (-> this roty-max) 1.0)
  (set! (-> this rotx-min) 0.0)
  (set! (-> this rotx-max) 1.0)
  (when (or (>= (-> this roty-min) (-> this roty)) (>= (-> this roty) (-> this roty-max)))
    (set! (-> this roty) (fmax (fmin (-> this roty) (-> this roty-max)) (-> this roty-min)))
    (set! (-> this rotyv) 0.0)
    )
  (when (or (>= (-> this rotx-min) (-> this rotx)) (>= (-> this rotx) (-> this rotx-max)))
    (set! (-> this rotx) (fmax (fmin (-> this rotx) (-> this rotx-max)) (-> this rotx-min)))
    (set! (-> this rotxv) 0.0)
    )
  (let ((f0-74 (-> this rotyv)))
    (-> this rotxv)
    0.0
    (cond
      ((< 0.5 f0-74)
       (let ((v1-106 (-> this servo-sound-state)))
         (cond
           ((or (zero? v1-106) (= v1-106 2) (= v1-106 4))
            (sound-play "hc-gun-servo" :id (-> this servo-sound) :position (-> this root trans))
            )
           ((or (= v1-106 1) (= v1-106 3))
            (sound-stop (-> this servo-sound))
            (sound-play "hc-gun-servo" :id (-> this servo-sound) :position (-> this root trans))
            )
           )
         )
       (set! (-> this servo-sound-state) (the-as uint 2))
       )
      ((< f0-74 -0.5)
       (let ((v1-116 (-> this servo-sound-state)))
         (cond
           ((or (zero? v1-116) (= v1-116 1) (= v1-116 4))
            (sound-play "hc-gun-servo" :id (-> this servo-sound) :position (-> this root trans))
            )
           ((or (= v1-116 2) (= v1-116 3))
            (sound-stop (-> this servo-sound))
            (sound-play "hc-gun-servo" :id (-> this servo-sound) :position (-> this root trans))
            )
           )
         )
       (set! (-> this servo-sound-state) (the-as uint 1))
       )
      (else
        (case (-> this servo-sound-state)
          ((1 2)
           (set! (-> this servo-sound-state) (the-as uint 3))
           (set-time! (-> this servo-state-time))
           )
          ((3)
           (when (time-elapsed? (-> this servo-state-time) (seconds 0.05))
             (sound-stop (-> this servo-sound))
             (sound-play "hc-servo-end")
             (set! (-> this servo-sound-state) (the-as uint 4))
             )
           )
          )
        )
      )
    )
  (none)
  )

(defmethod bt-gun-manager-method-18 ((this bt-gun-manager) (arg0 float))
  (local-vars (sv-80 vector) (sv-84 vector) (sv-88 vector) (sv-92 vector))
  (let ((s5-0 (new 'stack-no-clear 'vector)))
    (set! (-> s5-0 x) (lerp 0.0 512.0 (-> this roty)))
    (set! (-> s5-0 y) (lerp 0.0 416.0 (-> this rotx)))
    (set! (-> s5-0 z) 0.0)
    (set! (-> s5-0 w) 1.0)
    (set! sv-80 s5-0)
    )
  (set! sv-84 (new 'stack-no-clear 'vector))
  (set! sv-88 (new 'stack-no-clear 'vector))
  (set! sv-92 (new 'stack-no-clear 'vector))
  (set! (-> this hud-aim pos x) (the int (-> sv-80 x)))
  (set! (-> this hud-aim pos y) (the int (-> sv-80 y)))
  (set! (-> this hud-aim pos z) 0)
  (set! (-> this hud-aim flags) (hud-sprite-flags hsf3))
  (set! (-> this hud-aim scale-x) 1.0)
  (set! (-> this hud-aim scale-y) 1.0)
  (let ((v1-9 (-> this hud-aim color-ptr)))
    (set! (-> v1-9 0) 231)
    (set! (-> v1-9 1) 168)
    (set! (-> v1-9 2) 0)
    (set! (-> v1-9 3) 128)
    )
  (set! (-> this hud-aim tid)
        (the-as
          texture-id
          (lookup-texture-by-name "hud-target-reticle" (the-as string #f) (the-as (pointer texture-page) #f))
          )
        )
  (with-dma-buffer-add-bucket ((s4-0 (-> *display* frames (-> *display* on-screen) global-buf))
                               (bucket-id hud-draw-hud-alpha)
                               )
    (draw (-> this hud-aim) s4-0 (-> *level* level-default) #f)
    )
  (send-event (handle->process (-> this parent-vehicle)) 'get-turret-pos sv-88 sv-84)
  (vector+float*! sv-88 (camera-pos) (-> (camera-matrix) fvec) 40960.0)
  (+! (-> sv-80 x) -256.0)
  (+! (-> sv-80 y) -208.0)
  (reverse-transform-point!
    sv-92
    sv-88
    (vector-float*! (new 'stack-no-clear 'vector) (-> (camera-matrix) fvec) 1.0)
    sv-80
    )
  (vector-copy! (-> this aim-pos) sv-92)
  (vector-! (-> this aim-dir) sv-92 (-> this root trans))
  (vector-normalize! (-> this aim-dir) 1.0)
  (quaternion-look-at! (-> this root quat) (-> this aim-dir) *up-vector*)
  (blow-tower-path-cursor-method-9
    (-> this look-cursor)
    (the-as int (+ (-> this look-time-offset) (-> *blow-tower-targets* mission-time)))
    )
  (let ((s5-5 (new 'stack-no-clear 'quaternion)))
    (send-event (handle->process (-> this parent-vehicle)) 'get-turret-pos (new 'stack-no-clear 'vector) s5-5)
    (when (or (= (-> this look-mode) 2) (= (-> this look-mode) 1))
      (let ((v1-64 (entity-by-name (the-as string (-> this look-ent)))))
        (when v1-64
          (cond
            ((= (-> this look-mode) 2)
             (let ((a0-37 (as-type (-> v1-64 extra process) process-focusable)))
               (cond
                 ((and a0-37
                       (not (logtest? (-> (the-as process-focusable a0-37) focus-status) (focus-status disable dead ignore inactive))
                            )
                       )
                  (vector-copy! (-> this look-cursor pos) (get-trans (the-as process-focusable a0-37) 3))
                  )
                 (else
                   (set! (-> this look-mode) (the-as uint 0))
                   (set! (-> this look-time-scalar) 1.0)
                   )
                 )
               )
             )
            (else
              (vector-copy! (-> this look-cursor pos) (-> v1-64 extra trans))
              )
            )
          )
        )
      )
    (when (= (-> this look-mode) 3)
      (let ((a0-43 (as-type (handle->process (-> this look-proc)) process-focusable)))
        (if (and a0-43
                 (not (logtest? (-> (the-as process-focusable a0-43) focus-status) (focus-status disable dead ignore inactive))
                      )
                 )
            (vector-copy! (-> this look-cursor pos) (get-trans (the-as process-focusable a0-43) 3))
            )
        )
      )
    (let ((s4-12 (vector-! (new 'stack-no-clear 'vector) (-> this look-cursor pos) (-> this root trans)))
          (s3-1 (new 'stack-no-clear 'matrix))
          )
      2.0
      0.0
      (let ((s2-2 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this cam-quat))))
        (cond
          ((zero? (-> this look-mode))
           (let ((a0-47 s2-2))
             (vector-copy! a0-47 s2-2)
             (set! (-> a0-47 y) 0.0)
             (vector-normalize! a0-47 1.0)
             )
           (let ((a0-48 s4-12))
             (vector-copy! a0-48 s4-12)
             (set! (-> a0-48 y) 0.0)
             (vector-normalize! a0-48 1.0)
             )
           )
          (else
            (vector-normalize! s4-12 1.0)
            )
          )
        (let* ((f0-24 (vector-dot s4-12 s2-2))
               (f0-25 (+ 1.0 f0-24))
               (f0-26 (/ f0-25 2))
               (f0-27 (* f0-26 f0-26))
               (f0-28 (lerp 0.0 2.0 f0-27))
               (f30-0 (fmax 0.3 (fmin 2.0 f0-28)))
               )
          (let ((s1-0 (the-as bt-hellcat (handle->process (-> this parent-vehicle)))))
            (when s1-0
              (when (handle->process (-> s1-0 grunt-rider-boarded?))
                (let ((s2-3 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> s1-0 root quat))))
                  (let ((a0-59 s2-3))
                    (vector-copy! a0-59 s2-3)
                    (set! (-> a0-59 y) 0.0)
                    (vector-normalize! a0-59 1.0)
                    )
                  (vector-rotate-around-y! s2-3 s2-3 (-> s1-0 land-grunt-offset))
                  (let ((f0-33 (vector-dot s4-12 s2-3)))
                    (when (< 0.2 f0-33)
                      (vector-copy! s4-12 s2-3)
                      (set! f30-0 6.0)
                      )
                    )
                  )
                )
              )
            )
          (let ((f30-1 (* f30-0 (-> this look-time-scalar))))
            (if (zero? (-> this look-mode))
                (matrix-u-f-compose s3-1 (vector-y-quaternion! (new 'stack-no-clear 'vector) s5-5) s4-12)
                (matrix-f-u-compose s3-1 s4-12 (vector-y-quaternion! (new 'stack-no-clear 'vector) s5-5))
                )
            (matrix->quaternion s5-5 s3-1)
            (quaternion-slerp! (-> this cam-quat) (-> this cam-quat) s5-5 (* f30-1 (seconds-per-frame)))
            )
          )
        )
      )
    )
  (quaternion-copy! (-> this aim-quat) (-> this cam-quat))
  (let ((s5-6 (the-as bt-hellcat (handle->process (-> this parent-vehicle)))))
    (if s5-6
        (set! (-> this dest-rot-y-shift)
              (- (vector-y-angle (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this cam-quat)))
                 (vector-y-angle (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> s5-6 root quat)))
                 )
              )
        )
    )
  0
  (none)
  )

(defbehavior bt-hellcat-init-by-other bt-hellcat ((arg0 bt-obj-init-params))
  (init-collision! self)
  (vector-copy! (-> self root trans) (-> arg0 pos))
  (quaternion-copy! (-> self root quat) (-> arg0 quat))
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-bt-hellcat" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (init-fields (-> self path-cursor))
  (set! (-> self path-cursor path) (-> arg0 path))
  (set! (-> self task-man) (-> arg0 task-man))
  (init-params self)
  (go-virtual wait-for-player)
  )

(defmethod bt-hellcat-method-46 ((this bt-hellcat) (arg0 vector) (arg1 quaternion))
  (vector-copy! arg0 (-> this root trans))
  (quaternion-copy! arg1 (-> this root quat))
  (vector<-cspace! arg0 (-> this node-list data 5))
  (vector+float*! arg0 arg0 (-> this node-list data 5 bone transform uvec) 8192.0)
  (matrix->quaternion arg1 (-> this node-list data 5 bone transform))
  )

(defmethod bt-gun-manager-method-24 ((this bt-gun-manager) (arg0 quaternion))
  (let* ((f0-1 (- (vector-y-angle (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this cam-quat)))
                  (vector-y-angle (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0))
                  )
               )
         (f0-2 (/ f0-1 (meters 4)))
         (f0-3 (+ 0.5 f0-2))
         (f0-4 (floor f0-3))
         )
    (* 16384.0 f0-4)
    )
  )

(defmethod bt-vehicle-event-handler ((this bt-hellcat) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('lock-view 'rotate-view 'unlock-view)
     #f
     )
    (('fire)
     (let ((v0-0 (the-as object #t)))
       (set! (-> this barrel-fire-state (-> arg3 param 0)) (the-as symbol v0-0))
       v0-0
       )
     )
    (('grunt-rider-board)
     (set! (-> this grunt-rider-boarded?) (process->handle arg0))
     (let ((a0-11 (handle->process (-> this child-turret))))
       (if a0-11
           (set! (-> this land-grunt-offset)
                 (bt-gun-manager-method-24 (the-as bt-gun-manager a0-11) (-> this root quat))
                 )
           )
       )
     (send-event (handle->process (-> this child-turret)) 'snap-to-center)
     (send-event (handle->process (-> this child-turret)) 'look-at-restore (-> this grunt-rider))
     )
    (('roll-amount)
     (set! (-> this dest-roll-amount) (* 182.04445 (the-as float (-> arg3 param 0))))
     (set! (-> this roll-amount-seek-rate) (* 182.04445 (the-as float (-> arg3 param 1))))
     )
    (('kill-rider)
     (send-event (handle->process (-> this child-turret)) 'look-at-restore (process->handle arg0))
     (call-parent-method this arg0 arg1 arg2 arg3)
     )
    (('unlock-view)
     (send-event (handle->process (-> this child-turret)) 'unlock-view)
     )
    (('get-attack-pos)
     (bt-hellcat-method-46 this (the-as vector (-> arg3 param 0)) (new 'stack-no-clear 'quaternion))
     )
    (('assign-spot)
     (let ((s4-1 (new 'stack-no-clear 'quaternion)))
       (let ((a1-12 (-> arg3 param 1)))
         (if a1-12
             (quaternion-copy! s4-1 (the-as quaternion a1-12))
             )
         )
       (bt-hellcat-method-48 this (the-as handle (-> arg3 param 0)) s4-1)
       )
     )
    (('retrieve-spot)
     (bt-hellcat-method-47
       this
       (the-as int (-> arg3 param 0))
       (the-as vector (-> arg3 param 1))
       (the-as quaternion (-> arg3 param 2))
       (the-as symbol (-> arg3 param 3))
       )
     )
    (('get-turret-pos)
     (bt-hellcat-method-46 this (the-as vector (-> arg3 param 0)) (the-as quaternion (-> arg3 param 1)))
     )
    (else
      (call-parent-method this arg0 arg1 arg2 arg3)
      )
    )
  )

(defstate wait-for-player (bt-hellcat)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('player-board)
       (send-event (handle->process (-> self task-man)) 'player-board)
       (go-virtual player-riding)
       )
      (else
        (bt-vehicle-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set! (-> self child-turret)
          (ppointer->handle (process-spawn bt-gun-manager (process->handle self) :name "bt-gun-manager" :to self))
          )
    )
  :trans (behavior ()
    '()
    )
  :code sleep-code
  :post transform-post
  )

(defmethod bt-hellcat-method-51 ((this bt-hellcat))
  (dotimes (s5-0 4)
    (let ((f30-0 -2048.0))
      (if (= (logand s5-0 1) 1)
          (set! f30-0 (* -1.0 f30-0))
          )
      (cond
        ((-> this barrel-fire-state s5-0)
         (seek! (-> this jmod-barrels s5-0 transform trans z) f30-0 (* 28672.0 (seconds-per-frame)))
         (if (= (-> this jmod-barrels s5-0 transform trans z) f30-0)
             (set! (-> this barrel-fire-state s5-0) #f)
             )
         )
        (else
          (seek! (-> this jmod-barrels s5-0 transform trans z) 0.0 (* 7168.0 (seconds-per-frame)))
          )
        )
      )
    )
  #f
  )

(defstate player-riding (bt-hellcat)
  :virtual #t
  :event bt-vehicle-handler
  :enter (behavior ()
    (set-blackout-frames 0)
    (send-event (handle->process (-> self task-man)) 'set-turret (-> self child-turret))
    (set-time! (-> self state-time))
    )
  :exit (behavior ()
    '()
    )
  :trans (behavior ()
    (let ((gp-0 (if (handle->process (-> self grunt-rider))
                    (-> self grunt-rider)
                    (send-event (handle->process (-> self task-man)) 'get-vehicle 1)
                    )
                )
          )
      (dotimes (s5-0 (-> self rider-spots length))
        (send-event (handle->process (-> self rider-spots data s5-0 rider)) 'set-track gp-0)
        )
      )
    (if (not (-> self mission-fail?))
        (bt-vehicle-method-31 self)
        )
    (bt-hellcat-method-51 self)
    (set! (-> *game-info* health-bar-vehicle) (/ (-> self hit-points) (-> self max-hit-points)))
    )
  :code sleep-code
  :post (behavior ()
    (draw-thruster self)
    (logior! (-> self skel status) (joint-control-status sync-math))
    (transform-post)
    )
  )

(defmethod init-collision! ((this bt-hellcat))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate vehicle))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 7) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 8))
      (set! (-> s4-0 prim-core action) (collide-action solid rideable))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 26624.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-11 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 1))))
      (set! (-> v1-11 prim-core action) (collide-action solid))
      (set! (-> v1-11 transform-index) 0)
      (set-vector! (-> v1-11 local-sphere) 4096.0 1228.8 9011.2 6144.0)
      )
    (let ((v1-13 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 4))))
      (set! (-> v1-13 prim-core action) (collide-action solid))
      (set! (-> v1-13 transform-index) 0)
      (set-vector! (-> v1-13 local-sphere) -4096.0 1228.8 9011.2 6144.0)
      )
    (let ((v1-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-15 prim-core action) (collide-action solid nav-sphere))
      (set! (-> v1-15 transform-index) 0)
      (set-vector! (-> v1-15 local-sphere) 0.0 2048.0 -409.6 6144.0)
      (set! (-> v1-15 nav-radius) 24576.0)
      )
    (let ((v1-17 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 10))))
      (set! (-> v1-17 prim-core action) (collide-action solid))
      (set! (-> v1-17 transform-index) 0)
      (set-vector! (-> v1-17 local-sphere) 0.0 4096.0 -10240.0 8192.0)
      )
    (let ((v1-19 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 2))))
      (set! (-> v1-19 prim-core action) (collide-action solid))
      (set! (-> v1-19 transform-index) 0)
      (set-vector! (-> v1-19 local-sphere) 10240.0 2048.0 -8192.0 6144.0)
      )
    (let ((v1-21 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 8))))
      (set! (-> v1-21 prim-core action) (collide-action solid))
      (set! (-> v1-21 transform-index) 0)
      (set-vector! (-> v1-21 local-sphere) -10240.0 2048.0 -8192.0 6144.0)
      )
    (let ((v1-23 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-23 prim-core action) (collide-action solid rideable))
      (set! (-> v1-23 transform-index) 3)
      (set-vector! (-> v1-23 local-sphere) 0.0 0.0 0.0 26624.0)
      )
    (set! (-> s5-0 nav-radius) 20480.0)
    (let ((v1-25 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-25 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-25 prim-core collide-with))
      )
    (set! (-> s5-0 nav-flags) (nav-flags has-child-spheres))
    (set! (-> this root) s5-0)
    )
  (iterate-prims
    (-> this root)
    (lambda ((arg0 collide-shape-prim))
      (let ((v1-0 (-> arg0 prim-core prim-type)))
        (cond
          ((= v1-0 -1)
           (set! (-> arg0 prim-core collide-with) (collide-spec
                                                    backgnd
                                                    bot
                                                    crate
                                                    civilian
                                                    enemy
                                                    obstacle
                                                    vehicle-sphere
                                                    hit-by-player-list
                                                    hit-by-others-list
                                                    collectable
                                                    pusher
                                                    shield
                                                    vehicle-sphere-no-probe
                                                    )
                 )
           (set! (-> arg0 prim-core collide-as) (collide-spec vehicle-sphere))
           )
          ((= v1-0 1)
           (set! (-> arg0 prim-core collide-with) (collide-spec jak player-list))
           (set! (-> arg0 prim-core collide-as) (collide-spec vehicle-mesh))
           )
          ((zero? v1-0)
           (set! (-> arg0 prim-core collide-with) (collide-spec
                                                    backgnd
                                                    jak
                                                    bot
                                                    crate
                                                    civilian
                                                    enemy
                                                    obstacle
                                                    vehicle-sphere
                                                    hit-by-player-list
                                                    hit-by-others-list
                                                    player-list
                                                    collectable
                                                    pusher
                                                    shield
                                                    vehicle-sphere-no-probe
                                                    )
                 )
           (set! (-> arg0 prim-core collide-as) (collide-spec vehicle-sphere vehicle-mesh))
           )
          )
        )
      (none)
      )
    )
  0
  (none)
  )

(defmethod find-target ((this bt-gun-manager))
  (local-vars
    (sv-16 float)
    (sv-20 process-drawable)
    (sv-24 int)
    (sv-32 process-drawable)
    (sv-80 vector)
    (sv-84 vector)
    (sv-88 float)
    (sv-128 vector)
    (sv-132 vector)
    (sv-136 float)
    (sv-208 vector)
    (sv-212 vector)
    (sv-216 vector)
    (sv-220 vector)
    (sv-224 float)
    (sv-228 bt-gun-manager-target)
    (sv-784 process-drawable)
    (sv-832 vector)
    (sv-836 vector)
    (sv-840 float)
    (sv-880 vector)
    (sv-884 vector)
    (sv-888 float)
    (sv-960 vector)
    (sv-964 vector)
    (sv-968 vector)
    (sv-972 vector)
    (sv-976 float)
    (sv-980 bt-gun-manager-target)
    (sv-1536 process-drawable)
    (sv-1584 vector)
    (sv-1588 vector)
    (sv-1592 float)
    (sv-1632 vector)
    (sv-1636 vector)
    (sv-1640 float)
    (sv-1712 vector)
    (sv-1716 vector)
    (sv-1720 vector)
    (sv-1724 vector)
    (sv-1728 float)
    (sv-1732 bt-gun-manager-target)
    )
  (set! (-> this num-onscreen-targets) 0)
  (set! sv-16 (the-as float 18.0))
  (set! sv-20 (the-as process-drawable #f))
  (set! sv-24 -1)
  (when #f
    (let ((v1-4 (-> *collide-player-list* alive-list next0)))
      *collide-player-list*
      (let ((s5-0 (-> v1-4 next0)))
        (while (!= v1-4 (-> *collide-player-list* alive-list-end))
          (let* ((v1-5 (the-as collide-shape (-> (the-as connection v1-4) param1)))
                 (s4-0 (-> v1-5 root-prim))
                 )
            (when (logtest? (-> s4-0 prim-core collide-as) (collide-spec enemy obstacle hit-by-others-list))
              (set! sv-32 (as-type (-> v1-5 process) process-focusable))
              (when (and sv-32
                         (< (-> this num-onscreen-targets) 32)
                         (not (logtest? (-> (the-as process-focusable sv-32) focus-status) (focus-status disable dead ignore inactive))
                              )
                         )
                (let ((s3-1 (new 'stack-no-clear 'vector)))
                  (vector-copy! s3-1 (get-trans (the-as process-focusable sv-32) 3))
                  (set! sv-80 s3-1)
                  )
                (set! sv-84 (new 'stack-no-clear 'vector))
                (set! sv-88 (the-as float 0.0))
                (set! sv-88 (vector-vector-distance (-> this root trans) sv-80))
                (vector-! sv-84 sv-80 (camera-pos))
                (when (and (< 1.0 (vector-dot sv-84 (-> (camera-matrix) fvec))) (< sv-88 819200.0))
                  (set! sv-128 (new 'stack-no-clear 'vector))
                  (set! sv-132 (vector+float*! (new 'stack-no-clear 'vector) (-> this root trans) (-> this aim-dir) 40960.0))
                  (set! sv-136 (the-as float 0.0))
                  (set-vector! sv-132 (lerp 0.0 512.0 (-> this roty)) (lerp 0.0 416.0 (-> this rotx)) 0.0 1.0)
                  (+! (-> sv-132 x) -256.0)
                  (+! (-> sv-132 y) -208.0)
                  (+! (-> sv-132 x) 2048.0)
                  (+! (-> sv-132 y) 2048.0)
                  (transform-point-vector! sv-128 sv-80)
                  (set! (-> sv-128 z) 0.0)
                  (set! sv-208 (new 'stack-no-clear 'vector))
                  (set! sv-212 (new 'stack-no-clear 'vector))
                  (set! sv-216 (new 'stack-no-clear 'vector))
                  (set! sv-220 (new 'stack-no-clear 'vector))
                  (vector+float*! sv-208 sv-80 (-> (camera-matrix) rvec) (* 0.6 (-> s4-0 prim-core world-sphere w)))
                  (vector+float*! sv-212 sv-80 (-> (camera-matrix) rvec) (* 0.6 (- (-> s4-0 prim-core world-sphere w))))
                  (transform-point-vector! sv-216 sv-208)
                  (transform-point-vector! sv-220 sv-212)
                  (set! (-> sv-216 z) 0.0)
                  (set! (-> sv-220 z) 0.0)
                  (set! sv-224 (* 0.5 (vector-vector-distance sv-216 sv-220)))
                  (set! sv-228 (-> this onscreen-targets (-> this num-onscreen-targets)))
                  (set! sv-136 (vector-vector-distance sv-132 sv-128))
                  (set! sv-136 (- sv-136 sv-224))
                  (let ((a1-11 (new 'stack-no-clear 'collide-query)))
                    (vector-copy! (-> a1-11 start-pos) (-> this root trans))
                    (vector-! (-> a1-11 move-dist) sv-80 (-> a1-11 start-pos))
                    (let ((v1-57 a1-11))
                      (set! (-> v1-57 radius) 40.96)
                      (set! (-> v1-57 collide-with) (collide-spec backgnd))
                      (set! (-> v1-57 ignore-process0) #f)
                      (set! (-> v1-57 ignore-process1) #f)
                      (set! (-> v1-57 ignore-pat)
                            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                            )
                      (set! (-> v1-57 action-mask) (collide-action solid))
                      )
                    (when (< (fill-and-probe-using-line-sphere *collide-cache* a1-11) 0.0)
                      (when (< sv-136 sv-16)
                        (set! sv-20 sv-32)
                        (set! sv-16 sv-136)
                        (vector-copy! (-> this hit-pos) sv-80)
                        (set! sv-24 (-> this num-onscreen-targets))
                        )
                      (transform-point-qword! (-> sv-228 transformed-pos) sv-80)
                      (set! (-> sv-228 hit?) #f)
                      (set! (-> sv-228 hand) (process->handle sv-32))
                      (set! (-> sv-228 size) sv-224)
                      (set! (-> sv-228 alpha) (lerp-scale-clamp 0.0 1.0 sv-88 20480.0 61440.0))
                      (+! (-> this num-onscreen-targets) 1)
                      )
                    )
                  )
                )
              )
            )
          (set! v1-4 s5-0)
          *collide-player-list*
          (set! s5-0 (-> s5-0 next0))
          )
        )
      )
    )
  (when #t
    (when #f
      (let ((v1-80 (-> *collide-hit-by-player-list* alive-list next0)))
        *collide-hit-by-player-list*
        (let ((s5-1 (-> v1-80 next0)))
          (while (!= v1-80 (-> *collide-hit-by-player-list* alive-list-end))
            (let* ((v1-81 (the-as collide-shape (-> (the-as connection v1-80) param1)))
                   (s4-1 (-> v1-81 root-prim))
                   )
              (when (logtest? (-> s4-1 prim-core collide-as) (collide-spec enemy obstacle hit-by-others-list))
                (set! sv-784 (as-type (-> v1-81 process) process-focusable))
                (when (and sv-784
                           (< (-> this num-onscreen-targets) 32)
                           (not (logtest? (-> (the-as process-focusable sv-784) focus-status) (focus-status disable dead ignore inactive))
                                )
                           )
                  (let ((s3-10 (new 'stack-no-clear 'vector)))
                    (vector-copy! s3-10 (get-trans (the-as process-focusable sv-784) 3))
                    (set! sv-832 s3-10)
                    )
                  (set! sv-836 (new 'stack-no-clear 'vector))
                  (set! sv-840 (the-as float 0.0))
                  (set! sv-840 (vector-vector-distance (-> this root trans) sv-832))
                  (vector-! sv-836 sv-832 (camera-pos))
                  (when (and (< 1.0 (vector-dot sv-836 (-> (camera-matrix) fvec))) (< sv-840 819200.0))
                    (set! sv-880 (new 'stack-no-clear 'vector))
                    (set! sv-884 (vector+float*! (new 'stack-no-clear 'vector) (-> this root trans) (-> this aim-dir) 40960.0))
                    (set! sv-888 (the-as float 0.0))
                    (set-vector! sv-884 (lerp 0.0 512.0 (-> this roty)) (lerp 0.0 416.0 (-> this rotx)) 0.0 1.0)
                    (+! (-> sv-884 x) -256.0)
                    (+! (-> sv-884 y) -208.0)
                    (+! (-> sv-884 x) 2048.0)
                    (+! (-> sv-884 y) 2048.0)
                    (transform-point-vector! sv-880 sv-832)
                    (set! (-> sv-880 z) 0.0)
                    (set! sv-960 (new 'stack-no-clear 'vector))
                    (set! sv-964 (new 'stack-no-clear 'vector))
                    (set! sv-968 (new 'stack-no-clear 'vector))
                    (set! sv-972 (new 'stack-no-clear 'vector))
                    (vector+float*! sv-960 sv-832 (-> (camera-matrix) rvec) (* 0.6 (-> s4-1 prim-core world-sphere w)))
                    (vector+float*! sv-964 sv-832 (-> (camera-matrix) rvec) (* 0.6 (- (-> s4-1 prim-core world-sphere w))))
                    (transform-point-vector! sv-968 sv-960)
                    (transform-point-vector! sv-972 sv-964)
                    (set! (-> sv-968 z) 0.0)
                    (set! (-> sv-972 z) 0.0)
                    (set! sv-976 (* 0.5 (vector-vector-distance sv-968 sv-972)))
                    (set! sv-980 (-> this onscreen-targets (-> this num-onscreen-targets)))
                    (set! sv-888 (vector-vector-distance sv-884 sv-880))
                    (set! sv-888 (- sv-888 sv-976))
                    (let ((a1-25 (new 'stack-no-clear 'collide-query)))
                      (vector-copy! (-> a1-25 start-pos) (-> this root trans))
                      (vector-! (-> a1-25 move-dist) sv-832 (-> a1-25 start-pos))
                      (let ((v1-133 a1-25))
                        (set! (-> v1-133 radius) 40.96)
                        (set! (-> v1-133 collide-with) (collide-spec backgnd))
                        (set! (-> v1-133 ignore-process0) #f)
                        (set! (-> v1-133 ignore-process1) #f)
                        (set! (-> v1-133 ignore-pat)
                              (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                              )
                        (set! (-> v1-133 action-mask) (collide-action solid))
                        )
                      (when (< (fill-and-probe-using-line-sphere *collide-cache* a1-25) 0.0)
                        (when (< sv-888 sv-16)
                          (set! sv-20 sv-784)
                          (set! sv-16 sv-888)
                          (vector-copy! (-> this hit-pos) sv-832)
                          (set! sv-24 (-> this num-onscreen-targets))
                          )
                        (transform-point-qword! (-> sv-980 transformed-pos) sv-832)
                        (set! (-> sv-980 hit?) #f)
                        (set! (-> sv-980 hand) (process->handle sv-784))
                        (set! (-> sv-980 size) sv-976)
                        (set! (-> sv-980 alpha) (lerp-scale-clamp 0.0 1.0 sv-840 20480.0 61440.0))
                        (+! (-> this num-onscreen-targets) 1)
                        )
                      )
                    )
                  )
                )
              )
            (set! v1-80 s5-1)
            *collide-hit-by-player-list*
            (set! s5-1 (-> s5-1 next0))
            )
          )
        )
      )
    (when #t
      (let ((v1-155 (-> *collide-hit-by-others-list* alive-list next0)))
        *collide-hit-by-others-list*
        (let ((s5-2 (-> v1-155 next0)))
          (while (!= v1-155 (-> *collide-hit-by-others-list* alive-list-end))
            (let* ((v1-156 (the-as collide-shape (-> (the-as connection v1-155) param1)))
                   (s4-2 (-> v1-156 root-prim))
                   )
              (when (logtest? (-> s4-2 prim-core collide-as) (collide-spec enemy obstacle hit-by-others-list))
                (set! sv-1536 (as-type (-> v1-156 process) process-focusable))
                (when (and sv-1536
                           (< (-> this num-onscreen-targets) 32)
                           (not (logtest? (-> (the-as process-focusable sv-1536) focus-status) (focus-status disable dead ignore inactive))
                                )
                           )
                  (let ((s3-19 (new 'stack-no-clear 'vector)))
                    (vector-copy! s3-19 (get-trans (the-as process-focusable sv-1536) 3))
                    (set! sv-1584 s3-19)
                    )
                  (set! sv-1588 (new 'stack-no-clear 'vector))
                  (set! sv-1592 (the-as float 0.0))
                  (set! sv-1592 (vector-vector-distance (-> this root trans) sv-1584))
                  (vector-! sv-1588 sv-1584 (camera-pos))
                  (when (and (< 1.0 (vector-dot sv-1588 (-> (camera-matrix) fvec))) (< sv-1592 819200.0))
                    (set! sv-1632 (new 'stack-no-clear 'vector))
                    (set! sv-1636 (vector+float*! (new 'stack-no-clear 'vector) (-> this root trans) (-> this aim-dir) 40960.0))
                    (set! sv-1640 (the-as float 0.0))
                    (set-vector! sv-1636 (lerp 0.0 512.0 (-> this roty)) (lerp 0.0 416.0 (-> this rotx)) 0.0 1.0)
                    (+! (-> sv-1636 x) -256.0)
                    (+! (-> sv-1636 y) -208.0)
                    (+! (-> sv-1636 x) 2048.0)
                    (+! (-> sv-1636 y) 2048.0)
                    (transform-point-vector! sv-1632 sv-1584)
                    (set! (-> sv-1632 z) 0.0)
                    (set! sv-1712 (new 'stack-no-clear 'vector))
                    (set! sv-1716 (new 'stack-no-clear 'vector))
                    (set! sv-1720 (new 'stack-no-clear 'vector))
                    (set! sv-1724 (new 'stack-no-clear 'vector))
                    (vector+float*! sv-1712 sv-1584 (-> (camera-matrix) rvec) (* 0.6 (-> s4-2 prim-core world-sphere w)))
                    (vector+float*! sv-1716 sv-1584 (-> (camera-matrix) rvec) (* 0.6 (- (-> s4-2 prim-core world-sphere w))))
                    (transform-point-vector! sv-1720 sv-1712)
                    (transform-point-vector! sv-1724 sv-1716)
                    (set! (-> sv-1720 z) 0.0)
                    (set! (-> sv-1724 z) 0.0)
                    (set! sv-1728 (* 0.5 (vector-vector-distance sv-1720 sv-1724)))
                    (set! sv-1732 (-> this onscreen-targets (-> this num-onscreen-targets)))
                    (set! sv-1640 (vector-vector-distance sv-1636 sv-1632))
                    (set! sv-1640 (- sv-1640 sv-1728))
                    (let ((a1-39 (new 'stack-no-clear 'collide-query)))
                      (vector-copy! (-> a1-39 start-pos) (-> this root trans))
                      (vector-! (-> a1-39 move-dist) sv-1584 (-> a1-39 start-pos))
                      (let ((v1-208 a1-39))
                        (set! (-> v1-208 radius) 40.96)
                        (set! (-> v1-208 collide-with) (collide-spec backgnd))
                        (set! (-> v1-208 ignore-process0) #f)
                        (set! (-> v1-208 ignore-process1) #f)
                        (set! (-> v1-208 ignore-pat)
                              (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                              )
                        (set! (-> v1-208 action-mask) (collide-action solid))
                        )
                      (when (< (fill-and-probe-using-line-sphere *collide-cache* a1-39) 0.0)
                        (when (< sv-1640 sv-16)
                          (set! sv-20 sv-1536)
                          (set! sv-16 sv-1640)
                          (vector-copy! (-> this hit-pos) sv-1584)
                          (set! sv-24 (-> this num-onscreen-targets))
                          )
                        (transform-point-qword! (-> sv-1732 transformed-pos) sv-1584)
                        (set! (-> sv-1732 hit?) #f)
                        (set! (-> sv-1732 hand) (process->handle sv-1536))
                        (set! (-> sv-1732 size) sv-1728)
                        (set! (-> sv-1732 alpha) (lerp-scale-clamp 0.0 1.0 sv-1592 20480.0 61440.0))
                        (+! (-> this num-onscreen-targets) 1)
                        )
                      )
                    )
                  )
                )
              )
            (set! v1-155 s5-2)
            *collide-hit-by-others-list*
            (set! s5-2 (-> s5-2 next0))
            )
          )
        )
      )
    )
  (cond
    (sv-20
      (let ((s5-3 (process->handle sv-20)))
        (when (or (!= (-> this target-hand) s5-3) (not (-> this found-target?)))
          (let ((s4-3 (-> this hud-pers (-> this onscreen-targets sv-24 target-pers-index))))
            (set! (-> s4-3 alpha) 0.0)
            (set! (-> s4-3 rotate) 0.0)
            (when (time-elapsed? (-> this last-beep-time) (seconds 0.1))
              (sound-play "tracking-beep1" :vol 90)
              (set-time! (-> this last-beep-time))
              )
            (set! (-> s4-3 size-scalar) 4.0)
            (set-time! (-> s4-3 hold-start-time))
            )
          )
        (set! (-> this target-hand) (the-as handle s5-3))
        )
      (set! (-> this found-target?) #t)
      (let ((v0-53 (the-as object #t)))
        (set! (-> this onscreen-targets sv-24 hit?) (the-as symbol v0-53))
        v0-53
        )
      )
    (else
      (set! (-> this found-target?) #f)
      (vector+float*! (-> this hit-pos) (-> this root trans) (-> this aim-dir) 327680.0)
      )
    )
  )

;; WARN: Return type mismatch uint vs none.
(defmethod fire-shot ((this bt-gun-manager))
  (when (and (cpad-hold? 0 r1) (time-elapsed? (-> this last-fire-time) (seconds 0.1)))
    (set-time! (-> this last-fire-time))
    (new 'stack 'projectile-init-by-other-params)
    (let ((s5-0 (new 'stack-no-clear 'vector)))
      (vector-copy! s5-0 (-> this root trans))
      (new 'stack-no-clear 'vector)
      491520.0
      (quaternion->matrix (new 'stack-no-clear 'matrix) (-> this root quat))
      (let ((v1-22 (as-type (handle->process (-> this parent-vehicle)) process-focusable)))
        (when v1-22
          (vector<-cspace! s5-0 (-> v1-22 node-list data (-> *bt-hellcat-gun-nodes* (-> this fire-index))))
          (send-event (handle->process (-> this parent-vehicle)) 'fire (-> this fire-index))
          )
        )
      (sound-play "hc-gun-fire" :position (-> this root trans))
      (let ((s4-2 (new 'stack-no-clear 'collide-query)))
        (vector-copy! (-> s4-2 start-pos) (-> this root trans))
        (vector-! (-> s4-2 move-dist) (-> this hit-pos) (-> s4-2 start-pos))
        (let ((v1-35 s4-2))
          (set! (-> v1-35 radius) 1228.8)
          (set! (-> v1-35 collide-with) (collide-spec backgnd civilian enemy obstacle hit-by-others-list))
          (set! (-> v1-35 ignore-process0) (handle->process (-> this parent-vehicle)))
          (set! (-> v1-35 ignore-process1) (handle->process (-> *blow-tower-targets* pickup)))
          (set! (-> v1-35 ignore-pat)
                (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                )
          (set! (-> v1-35 action-mask) (collide-action solid))
          )
        (let ((f0-2 (fill-and-probe-using-line-sphere *collide-cache* s4-2)))
          (when (>= f0-2 0.0)
            (vector-float*! (-> s4-2 move-dist) (-> s4-2 move-dist) f0-2)
            (let ((s3-2 (vector+! (new 'stack-no-clear 'vector) (-> s4-2 start-pos) (-> s4-2 move-dist))))
              (sound-play "hellcat-riccos" :position s3-2)
              (cond
                ((logtest? (-> group-gun-hellcat-shot-hit flags) (sp-group-flag sp13))
                 (vector-copy!
                   (-> *launch-matrix* trans)
                   (vector+!
                     (new 'stack-no-clear 'vector)
                     s3-2
                     (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> s4-2 move-dist) -4096.0)
                     )
                   )
                 (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-gun-hellcat-shot-hit)
                 )
                (else
                  (vector-copy!
                    (-> *launch-matrix* trans)
                    (vector+!
                      (new 'stack-no-clear 'vector)
                      s3-2
                      (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> s4-2 move-dist) -4096.0)
                      )
                    )
                  (part-tracker-spawn part-tracker :to *entity-pool* :group group-gun-hellcat-shot-hit)
                  )
                )
              )
            (when (and (-> s4-2 best-other-tri collide-ptr)
                       (as-type (-> s4-2 best-other-tri collide-ptr) collide-shape-prim-sphere)
                       )
              (let ((a0-50
                      (-> (the-as collide-shape-prim-sphere (as-type (-> s4-2 best-other-tri collide-ptr) collide-shape-prim-sphere))
                          cshape
                          process
                          )
                      )
                    )
                (if a0-50
                    (send-event
                      a0-50
                      '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 'eco-blue)
                         (attacker-velocity (vector-! (new 'stack-no-clear 'vector) (-> this hit-pos) (-> s4-2 start-pos)))
                         )
                        )
                      )
                    )
                )
              )
            )
          )
        (let ((s3-8 (vector-!
                      (new 'stack-no-clear 'vector)
                      (vector+! (new 'stack-no-clear 'vector) (-> s4-2 start-pos) (-> s4-2 move-dist))
                      s5-0
                      )
                    )
              )
          (cpad-set-buzz! (-> *cpad-list* cpads 0) 1 76 (seconds 0.05))
          (draw-beam (-> *part-id-table* 231) s5-0 s3-8 #t)
          (draw-beam (-> *part-id-table* 364) s5-0 s3-8 #f)
          )
        )
      )
    (+! (-> this fire-index) 1)
    (logand! (-> this fire-index) 3)
    )
  (none)
  )

(defun draw-path-blow-curve ((arg0 cubic-curve) (arg1 vector))
  (let ((s4-0 (new 'stack-no-clear 'matrix))
        (s3-0 10)
        )
    (cubic-curve-method-10 arg0 (-> s4-0 uvec) 0.0)
    (add-debug-x #t (bucket-id debug-no-zbuf1) (-> s4-0 uvec) (the-as rgba arg1))
    (dotimes (s2-0 s3-0)
      (vector-copy! (-> s4-0 rvec) (-> s4-0 uvec))
      (let ((f0-2 (/ (+ 1.0 (the float s2-0)) (the float s3-0))))
        (cubic-curve-method-10 arg0 (-> s4-0 uvec) f0-2)
        )
      (add-debug-line
        #t
        (bucket-id debug-no-zbuf1)
        (-> s4-0 rvec)
        (-> s4-0 uvec)
        (the-as rgba arg1)
        #f
        (the-as rgba -1)
        )
      )
    )
  #f
  )

(defmethod bt-vehicle-method-31 ((this bt-hellcat))
  (local-vars (f30-2 float) (sv-256 vector) (sv-260 vector) (sv-264 vector) (sv-268 vector))
  (set-vector! (-> this rider-spots data 0 offset-pos) 0.0 0.0 0.0 1.0)
  (set-vector! (-> this rider-spots data 1 offset-pos) 0.0 0.0 0.0 1.0)
  (let ((s5-0 (new 'stack 'blow-tower-clock)))
    (set! (-> s5-0 debug?) #f)
    (send-event (handle->process (-> this task-man)) 'get-clock s5-0)
    (blow-tower-path-cursor-method-9 (-> this path-cursor) (the-as int (-> s5-0 elapsed-clock-time)))
    (if (-> s5-0 debug-lock-view?)
        (send-event (handle->process (-> this child-turret)) 'snap-forward)
        )
    (let ((f0-9 (* 3.0 (seconds-per-frame))))
      (if (-> s5-0 debug?)
          (set! f0-9 1.0)
          )
      (when (not (-> this inited?))
        (set! (-> this inited?) #t)
        (set! f0-9 1.0)
        )
      (vector-lerp! (-> this path-pos) (-> this path-pos) (-> this path-cursor pos) f0-9)
      )
    (let ((s2-0 (new 'stack-no-clear 'vector)))
      (vector-copy! s2-0 (-> this pre-bounce-pos))
      (let ((s4-0 (new 'stack-no-clear 'vector))
            (s3-0 (new 'stack-no-clear 'vector))
            )
        0.0
        0.0
        (vector-copy! (-> this pre-bounce-pos) (-> this path-pos))
        (bt-vehicle-method-40 this (the-as int (-> s5-0 elapsed-clock-time)))
        (+! (-> this pre-bounce-pos y) (-> this path-height-offset))
        (vector-! s4-0 s2-0 (-> this pre-bounce-pos))
        (let ((f30-0 (/ (vector-length s4-0) (seconds-per-frame))))
          (vector-! s3-0 s4-0 (-> this last-vel))
          (vector-length s3-0)
          (let ((f28-0 (lerp-scale-clamp 0.0 1.0 f30-0 81920.0 163840.0)))
            (sound-play-by-name
              (static-sound-name "hc-engine")
              (-> this engine-sound)
              1024
              (the int (* 1524.0 (lerp 0.0 0.25 f28-0)))
              0
              (sound-group)
              (-> this root trans)
              )
            (sound-play-by-name
              (static-sound-name "hc-thrust")
              (-> this thrust-sound)
              (the int (* 1024.0 (lerp 0.5 1.0 f28-0)))
              0
              0
              (sound-group)
              (-> this root trans)
              )
            )
          (vector-copy! (-> this last-vel) s4-0)
          (set! (-> this last-speed) f30-0)
          )
        )
      )
    (let ((s4-1 (new 'stack-no-clear 'vector)))
      (let ((a2-8 (new 'stack-no-clear 'vector)))
        (bt-vehicle-method-41 this s4-1 a2-8)
        )
      (vector+! (-> this root trans) (-> this pre-bounce-pos) s4-1)
      )
    (let ((v1-58 (new 'stack-no-clear 'vector)))
      (vector-copy! v1-58 (-> this path-cursor norm))
      (set! sv-256 v1-58)
      )
    (set! sv-260 (vector-x-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)))
    (set! sv-264 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)))
    (set! sv-268 (new 'stack-no-clear 'vector))
    (set! (-> sv-260 y) 0.0)
    (vector-normalize! sv-260 1.0)
    (set! (-> sv-264 y) 0.0)
    (vector-normalize! sv-264 1.0)
    (set! (-> sv-256 y) 0.0)
    (vector-normalize! sv-256 1.0)
    (seek!
      (-> this roll-amount)
      (-> this dest-roll-amount)
      (* (-> this roll-amount-seek-rate) (seconds-per-frame))
      )
    (let ((s4-2 (quaternion-look-at! (new 'stack-no-clear 'quaternion) sv-256 *up-vector*))
          (f30-1 (seconds-per-frame))
          )
      0.0
      (let ((v1-68 (the-as bt-gun-manager (handle->process (-> this child-turret))))
            (s3-3 (-> this pitch-quat))
            )
        (let ((f28-1 (-> this roll-amount)))
          (vector-rotate-around-axis! sv-268 sv-260 (-> v1-68 rot-y-shift) *up-vector*)
          (quaternion-vector-angle! s3-3 sv-268 f28-1)
          )
        (quaternion*! s4-2 s3-3 s4-2)
        )
      (let* ((f0-33 (vector-dot sv-256 sv-264))
             (f1-5 (* 2.5 (- 1.0 f0-33)))
             (f0-36 (- 1.0 (* (- 1.0 f1-5) (- 1.0 f1-5))))
             )
        (if (< 0.0 (vector-dot sv-256 sv-260))
            (set! f0-36 (* -1.0 f0-36))
            )
        (quaternion-rotate-local-z! s4-2 s4-2 (* 8192.0 f0-36))
        )
      (if (-> s5-0 debug?)
          (set! f30-1 1.0)
          )
      (let ((f0-38 (-> this path-height-vel)))
        0.0
        (let ((f0-41 (fmax -1.0 (fmin 1.0 (/ f0-38 (meters 10))))))
          (quaternion-rotate-local-x! s4-2 s4-2 (* -4551.1113 f0-41))
          )
        )
      (quaternion-slerp! (-> this quat-before-bounce) (-> this quat-before-bounce) s4-2 f30-1)
      )
    )
  (quaternion-copy! (-> this root quat) (-> this quat-before-bounce))
  (let ((s5-1 (new 'stack-no-clear 'quaternion)))
    1.0
    (set! f30-2 (cond
                  ((handle->process (-> this grunt-rider-boarded?))
                   (quaternion-vector-angle! s5-1 sv-268 1820.4445)
                   5.0
                   )
                  (else
                    (set! f30-2 1.0)
                    (quaternion-identity! s5-1)
                    f30-2
                    )
                  )
          )
    (quaternion-slerp! (-> this quat-grunt-tilt) (-> this quat-grunt-tilt) s5-1 (* f30-2 (seconds-per-frame)))
    )
  (quaternion*! (-> this root quat) (-> this quat-grunt-tilt) (-> this quat-before-bounce))
  (when (time-elapsed? (-> this state-time) (seconds 0.2))
    (let ((s5-2 (new 'stack-no-clear 'quaternion))
          (f30-3 (fmin 1.0 (* 20.0 (seconds-per-frame))))
          )
      (let ((s4-3 (new 'stack-no-clear 'vector)))
        (send-event (handle->process (-> this child-turret)) 'aim-quat s5-2)
        (send-event (handle->process (-> this child-turret)) 'hit-pos s4-3)
        )
      (new 'stack-no-clear 'vector)
      (quaternion-vector-angle! (-> this jmod-rgun rotation) *up-vector* -2730.6667)
      (quaternion-vector-angle! (-> this jmod-lgun rotation) *up-vector* -2730.6667)
      (quaternion-rotate-local-x! (-> this jmod-lgun rotation) (-> this jmod-lgun rotation) -1456.3556)
      (quaternion-rotate-local-x! (-> this jmod-rgun rotation) (-> this jmod-rgun rotation) -1456.3556)
      (let ((v1-129 (the-as bt-gun-manager (handle->process (-> this child-turret)))))
        (when v1-129
          (let* ((f1-16 (-> v1-129 rotx))
                 (f0-47 (-> v1-129 roty))
                 (f1-17 (* 2.0 f1-16))
                 (f0-48 (* 2.0 f0-47))
                 (f26-2 (+ -1.0 f1-17))
                 (f28-2 (+ -1.0 f0-48))
                 )
            (quaternion-rotate-local-x! (-> this jmod-lgun rotation) (-> this jmod-lgun rotation) (* 2730.6667 f26-2))
            (quaternion-rotate-local-x! (-> this jmod-rgun rotation) (-> this jmod-rgun rotation) (* 2730.6667 f26-2))
            (quaternion-rotate-local-y! (-> this jmod-lgun rotation) (-> this jmod-lgun rotation) 546.13336)
            (quaternion-rotate-local-y! (-> this jmod-rgun rotation) (-> this jmod-rgun rotation) 546.13336)
            (quaternion-rotate-local-y! (-> this jmod-lgun rotation) (-> this jmod-lgun rotation) (* -1820.4445 f28-2))
            (quaternion-rotate-local-y! (-> this jmod-rgun rotation) (-> this jmod-rgun rotation) (* 1820.4445 f28-2))
            )
          )
        )
      (logclear! (-> this draw status) (draw-control-status force-fade))
      (set! (-> this draw force-fade) (the-as uint 32))
      (let ((s4-4 (new 'stack-no-clear 'vector)))
        (vector-z-quaternion! s4-4 s5-2)
        (vector-normalize! s4-4 1.0)
        (let ((s5-3 (quaternion-look-at! (new 'stack-no-clear 'quaternion) s4-4 *up-vector*)))
          (let ((s2-3 (vector-y-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)))
                (s3-4 (new 'stack-no-clear 'vector))
                )
            (vector-x-quaternion! s3-4 s5-3)
            (let ((a0-101 s3-4))
              (vector-copy! a0-101 s3-4)
              (set! (-> a0-101 y) 0.0)
              (vector-normalize! a0-101 1.0)
              )
            (let ((f0-59 (vector-dot s3-4 s2-3)))
              (vector+float*! s3-4 s3-4 s2-3 (- f0-59))
              )
            (let* ((f28-3 (atan (-> s3-4 y) 1.0))
                   (f1-19 (atan (-> s4-4 y) 1.0))
                   (f0-65 (lerp f28-3 0.0 (fmax 0.0 (fmin 1.0 (* 0.0002746582 f1-19)))))
                   )
              (quaternion-rotate-local-z! s5-3 s5-3 f0-65)
              )
            )
          (quaternion-slerp! (-> this jmod-turret-guns rotation) (-> this jmod-turret-guns rotation) s5-3 f30-3)
          )
        )
      )
    (when (and (handle->process (-> this grunt-rider)) (handle->process (-> this grunt-rider-boarded?)))
      (let ((a0-118 (the-as bt-gun-manager (handle->process (-> this child-turret)))))
        (when a0-118
          (if (!= (the float (sar (shl (the int (bt-gun-manager-method-24 a0-118 (-> this root quat))) 48) 48))
                  (the float (sar (shl (the int (-> this land-grunt-offset)) 48) 48))
                  )
              (send-event (handle->process (-> this grunt-rider)) 'rider-eject)
              )
          )
        )
      )
    )
  (call-parent-method this)
  (none)
  )

(defbehavior bt-pickup-init-by-other bt-pickup ((arg0 bt-obj-init-params))
  (init-collision! self)
  (set-vector! (-> self root scale) 2.2 2.0 1.75 1.0)
  (vector-copy! (-> self root trans) (-> arg0 pos))
  (quaternion-copy! (-> self root quat) (-> arg0 quat))
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-bt-pickup" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (init-fields (-> self path-cursor))
  (set! (-> self path-cursor path) (-> arg0 path))
  (set! (-> self task-man) (-> arg0 task-man))
  (init-params self)
  (go-virtual wait-for-player)
  )

(defmethod init-collision! ((this bt-pickup))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate vehicle))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 7) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 8))
      (set! (-> s4-0 prim-core collide-as) (collide-spec vehicle-sphere vehicle-mesh))
      (set! (-> s4-0 prim-core action) (collide-action solid rideable))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 34816.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-12 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 1))))
      (set! (-> v1-12 prim-core action) (collide-action solid))
      (set! (-> v1-12 transform-index) 0)
      (set-vector! (-> v1-12 local-sphere) 3686.4 0.0 12288.0 8192.0)
      )
    (let ((v1-14 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 4))))
      (set! (-> v1-14 prim-core action) (collide-action solid))
      (set! (-> v1-14 transform-index) 0)
      (set-vector! (-> v1-14 local-sphere) -3686.4 0.0 12288.0 8192.0)
      )
    (let ((v1-16 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 5))))
      (set! (-> v1-16 prim-core action) (collide-action solid nav-sphere))
      (set! (-> v1-16 transform-index) 0)
      (set-vector! (-> v1-16 local-sphere) 0.0 819.2 5734.4 9830.4)
      (set! (-> v1-16 nav-radius) 14336.0)
      )
    (let ((v1-18 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 144))))
      (set! (-> v1-18 prim-core action) (collide-action solid nav-sphere))
      (set! (-> v1-18 transform-index) 0)
      (set-vector! (-> v1-18 local-sphere) 0.0 2048.0 -4096.0 11468.8)
      (set! (-> v1-18 nav-radius) 14336.0)
      )
    (let ((v1-20 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 2))))
      (set! (-> v1-20 prim-core action) (collide-action solid))
      (set! (-> v1-20 transform-index) 0)
      (set-vector! (-> v1-20 local-sphere) 4915.2 0.0 -11468.8 8192.0)
      )
    (let ((v1-22 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 8))))
      (set! (-> v1-22 prim-core action) (collide-action solid))
      (set! (-> v1-22 transform-index) 0)
      (set-vector! (-> v1-22 local-sphere) -4915.2 0.0 -11468.8 8192.0)
      )
    (let ((v1-24 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-24 prim-core action) (collide-action solid rideable))
      (set! (-> v1-24 transform-index) 3)
      (set-vector! (-> v1-24 local-sphere) 0.0 0.0 0.0 34816.0)
      )
    (set! (-> s5-0 nav-radius) 20480.0)
    (let ((v1-26 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-26 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-26 prim-core collide-with))
      )
    (set! (-> s5-0 nav-flags) (nav-flags has-child-spheres))
    (set! (-> this root) s5-0)
    )
  (iterate-prims
    (-> this root)
    (lambda ((arg0 collide-shape-prim))
      (let ((v1-0 (-> arg0 prim-core prim-type)))
        (cond
          ((= v1-0 -1)
           (set! (-> arg0 prim-core collide-with) (collide-spec
                                                    backgnd
                                                    bot
                                                    crate
                                                    civilian
                                                    enemy
                                                    obstacle
                                                    vehicle-sphere
                                                    hit-by-player-list
                                                    hit-by-others-list
                                                    collectable
                                                    pusher
                                                    shield
                                                    vehicle-sphere-no-probe
                                                    )
                 )
           (set! (-> arg0 prim-core collide-as) (collide-spec vehicle-sphere))
           )
          ((= v1-0 1)
           (set! (-> arg0 prim-core collide-with) (collide-spec jak player-list))
           (set! (-> arg0 prim-core collide-as) (collide-spec vehicle-mesh))
           )
          ((zero? v1-0)
           (set! (-> arg0 prim-core collide-with) (collide-spec
                                                    backgnd
                                                    jak
                                                    bot
                                                    crate
                                                    civilian
                                                    enemy
                                                    obstacle
                                                    vehicle-sphere
                                                    hit-by-player-list
                                                    hit-by-others-list
                                                    player-list
                                                    collectable
                                                    pusher
                                                    shield
                                                    vehicle-sphere-no-probe
                                                    )
                 )
           (set! (-> arg0 prim-core collide-as) (collide-spec vehicle-sphere vehicle-mesh))
           )
          )
        )
      (none)
      )
    )
  0
  (none)
  )

(defstate wait-for-player (bt-pickup)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('player-board)
       (go-virtual path-follow)
       )
      (else
        (bt-vehicle-handler proc argc message block)
        )
      )
    )
  :trans (behavior ()
    '()
    )
  :code sleep-code
  :post transform-post
  )

(defstate path-follow (bt-pickup)
  :virtual #t
  :event bt-vehicle-handler
  :enter (behavior ()
    '()
    )
  :trans (behavior ()
    (set! (-> *game-info* bot-health 0) (* 100.0 (/ (-> self hit-points) (-> self max-hit-points))))
    (bt-vehicle-method-31 self)
    (let ((gp-0 (new 'stack 'blow-tower-path-cursor)))
      (set! (-> gp-0 path) (-> self path-cursor path))
      (blow-tower-path-cursor-method-9 gp-0 (the-as int (+ (-> self path-cursor current-time) (seconds 1.5))))
      (dotimes (s5-0 (-> self rider-spots length))
        (send-event (handle->process (-> self rider-spots data s5-0 rider)) 'set-track-pos (-> gp-0 pos))
        )
      )
    )
  :code sleep-code
  :post (behavior ()
    (draw-thruster self)
    (transform-post)
    )
  )

(defmethod bt-vehicle-method-31 ((this bt-pickup))
  (set-vector! (-> this rider-spots data 0 offset-pos) 0.0 0.0 0.0 1.0)
  (let ((s5-0 (new 'stack 'blow-tower-clock)))
    (set! (-> s5-0 debug?) #f)
    (send-event (handle->process (-> this task-man)) 'get-clock s5-0)
    (blow-tower-path-cursor-method-9 (-> this path-cursor) (the-as int (-> s5-0 elapsed-clock-time)))
    (vector-copy! (-> this root trans) (-> this path-cursor pos))
    (let ((f0-5 (* 4.0 (seconds-per-frame))))
      (if (-> s5-0 debug?)
          (set! f0-5 1.0)
          )
      (when (not (-> this inited?))
        (set! (-> this inited?) #t)
        (set! f0-5 1.0)
        )
      (vector-lerp! (-> this path-pos) (-> this path-pos) (-> this path-cursor pos) f0-5)
      )
    (vector-copy! (-> this pre-bounce-pos) (-> this path-pos))
    (bt-vehicle-method-40 this (the-as int (-> s5-0 elapsed-clock-time)))
    (+! (-> this pre-bounce-pos y) (-> this path-height-offset))
    (let ((s4-0 (new 'stack-no-clear 'vector)))
      (let ((a2-2 (new 'stack-no-clear 'vector)))
        (bt-vehicle-method-41 this s4-0 a2-2)
        )
      (vector+! (-> this root trans) (-> this pre-bounce-pos) s4-0)
      )
    (let ((s3-0 (new 'stack-no-clear 'vector)))
      (vector-copy! s3-0 (-> this path-cursor norm))
      (let ((s2-0 (vector-x-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))))
        (set! (-> s2-0 y) 0.0)
        (vector-normalize! s2-0 1.0)
        (vector-normalize! s3-0 1.0)
        (let ((s4-1 (quaternion-look-at! (new 'stack-no-clear 'quaternion) s3-0 *up-vector*))
              (f30-0 (* 2.0 (seconds-per-frame)))
              )
          0.0
          (let* ((f0-12 (vector-dot s3-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))))
                 (f1-4 (* 2.5 (- 1.0 f0-12)))
                 (f0-15 (- 1.0 (* (- 1.0 f1-4) (- 1.0 f1-4))))
                 )
            (if (< 0.0 (vector-dot s3-0 s2-0))
                (set! f0-15 (* -1.0 f0-15))
                )
            (quaternion-rotate-local-z! s4-1 s4-1 (* 8192.0 f0-15))
            )
          (let ((f0-17 (-> this path-height-vel)))
            0.0
            (let ((f0-20 (fmax -1.0 (fmin 1.0 (/ f0-17 (meters 10))))))
              (quaternion-rotate-local-x! s4-1 s4-1 (* -4551.1113 f0-20))
              )
            )
          (if (-> s5-0 debug?)
              (set! f30-0 1.0)
              )
          (when (< 5461.3335 (-> this barrel-roll-amount))
            (dotimes (s5-1 2)
              (send-event (handle->process (-> this riders s5-1)) 'rider-eject-if-boarded)
              )
            )
          (quaternion-slerp! (-> this quat-before-roll) (-> this quat-before-roll) s4-1 f30-0)
          )
        )
      )
    )
  (let ((a2-9 (quaternion-vector-angle! (new 'stack-no-clear 'quaternion) *z-vector* (-> this barrel-roll-amount))))
    (quaternion-slerp!
      (-> this barrel-roll-quat)
      (-> this barrel-roll-quat)
      a2-9
      (* (-> this barrel-roll-rate-scalar) (seconds-per-frame))
      )
    )
  (quaternion*! (-> this root quat) (-> this quat-before-roll) (-> this barrel-roll-quat))
  (call-parent-method this)
  (none)
  )

(defun bt-force-show-hud ((arg0 symbol))
  (when (and *target* (or (not *progress-process*) (gone? (-> *progress-process* 0))))
    (let ((v1-7 (-> *hud-engine* alive-list next0)))
      *hud-engine*
      (let ((s5-0 (-> v1-7 next0)))
        (while (!= v1-7 (-> *hud-engine* alive-list-end))
          (if (or (not arg0) (= arg0 (-> (the-as connection v1-7) param2)))
              (send-event (the-as process (-> (the-as connection v1-7) param1)) 'force-show)
              )
          (set! v1-7 s5-0)
          *hud-engine*
          (set! s5-0 (-> s5-0 next0))
          )
        )
      )
    )
  0
  (none)
  )

(defmethod taskman-event-handler ((this task-manager-blow-tower) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (local-vars (v0-0 object))
  (case arg2
    (('vehicle-explode)
     (if (= (-> arg0 type) bt-hellcat)
         (go (method-of-object this wait-fail))
         (go (method-of-object this wind-down-mission))
         )
     )
    (('show-skill)
     (bt-force-show-hud 'hud-skill)
     (set! v0-0 (current-time))
     (set! (-> this show-skill-time) (the-as time-frame v0-0))
     v0-0
     )
    (('get-vehicle)
     (-> this target-handles (-> arg3 param 0))
     )
    (('set-turret)
     (set! v0-0 (-> arg3 param 0))
     (set! (-> this hellcat-turret) (the-as handle v0-0))
     v0-0
     )
    (('get-clock)
     (let ((v1-10 (the-as blow-tower-clock (-> arg3 param 0))))
       (set! (-> v1-10 elapsed-clock-time) (-> this mission-elapsed-clock))
       (set! (-> v1-10 debug?)
             (the-as symbol (and (-> this next-state) (= (-> this next-state name) 'mission-debug)))
             )
       (set! (-> v1-10 debug-lock-view?) (and (-> v1-10 debug?) (-> this debug-lock-viewport?)))
       )
     #t
     )
    (else
      (call-parent-method this arg0 arg1 arg2 arg3)
      )
    )
  )

(defstate mission-debug (task-manager-blow-tower)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (set! (-> *blow-tower-targets* debug?) #t)
    )
  :exit (behavior ()
    (set! (-> *blow-tower-targets* debug?) #f)
    (iterate-process-tree
      *active-pool*
      (lambda ((arg0 process)) (send-event arg0 'blow-tower-debug-end) #t)
      *null-kernel-context*
      )
    )
  :trans (behavior ()
    ((-> (method-of-type task-manager active) trans))
    (dotimes (v1-2 2)
      (set! (-> *blow-tower-targets* target-handles v1-2) (-> self target-handles v1-2))
      )
    (set! (-> self script) *blow-tower-script*)
    (format *stdebug* "========= Blow tower - Debug mode =========~%")
    (let ((t9-2 format)
          (a0-4 *stdebug*)
          (a1-3 "Current time (~d:~d) [mission-percentage ~f~%")
          (a2-1 (the int (* 0.00005555556 (the float (-> self mission-elapsed-clock)))))
          (f0-4 (* 0.0033333334 (the float (-> self mission-elapsed-clock))))
          )
      (t9-2 a0-4 a1-3 a2-1 (the int (- f0-4 (* (the float (the int (/ f0-4 60.0))) 60.0))))
      )
    (format
      *stdebug*
      "Current event-id ~d    |   Next event-id ~d~%"
      (-> self event-cursor event-id)
      (-> self event-cursor path node-info (+ (-> self event-cursor current-node-index) 1) event-id)
      )
    (dotimes (gp-0 (-> self script length))
      (when (= (-> self script gp-0 event-id) (-> self event-cursor event-id))
        (let* ((a0-11 (-> self script gp-0 command-list))
               (s5-0 ((method-of-type (rtype-of a0-11) length) a0-11))
               )
          (when (> s5-0 0)
            (format *stdebug* "Commands are: ")
            (dotimes (s4-0 s5-0)
              (let ((a2-3 (ref (-> self script gp-0 command-list) s4-0)))
                (format *stdebug* "~s " a2-3)
                )
              (if (= (logand s4-0 1) 1)
                  (format *stdebug* "~%")
                  )
              )
            (format *stdebug* "~%")
            )
          )
        )
      )
    (format
      *stdebug*
      "Events? ~s  (triangle) |  Lock view? ~s (circle)~%"
      (-> self debug-run-events?)
      (-> self debug-lock-viewport?)
      )
    (if (cpad-pressed? 1 triangle)
        (set! (-> self debug-run-events?) (not (-> self debug-run-events?)))
        )
    (if (cpad-pressed? 1 circle)
        (set! (-> self debug-lock-viewport?) (not (-> self debug-lock-viewport?)))
        )
    (when (cpad-pressed? 1 square)
      (let ((v1-58 (handle->process (-> self hellcat))))
        (if v1-58
            (set! (-> (the-as bt-hellcat v1-58) hit-points) (-> (the-as bt-hellcat v1-58) max-hit-points))
            )
        )
      (let ((v1-61 (the-as bt-pickup (handle->process (-> self pickup)))))
        (if v1-61
            (set! (-> v1-61 hit-points) (-> v1-61 max-hit-points))
            )
        )
      )
    (when (cpad-pressed? 1 r3)
      (send-event (handle->process (-> self hellcat-turret)) 'look-at 0 450 #x41200000)
      (send-event (handle->process (-> self hellcat)) 'set-path-height 0 (-> self mission-elapsed-clock))
      (send-event (handle->process (-> self pickup)) 'set-path-height 0 (-> self mission-elapsed-clock))
      (send-event (handle->process (-> self hellcat)) 'roll-amount 0 #x43b40000)
      (set! (-> self clock-scalar) 1.0)
      (set! (-> self dest-clock-scalar) 1.0)
      )
    (let ((f0-11 (analog-input (the-as int (-> *cpad-list* cpads 1 lefty)) 128.0 48.0 110.0 -1.0)))
      (+! (-> self mission-elapsed-clock) (the int (* 3000.0 f0-11 (seconds-per-frame))))
      (if (< 0.9 f0-11)
          (+! (-> self mission-elapsed-clock) (the int (* 1500.0 (seconds-per-frame))))
          )
      (set! (-> self mission-elapsed-clock)
            (the-as
              time-frame
              (max
                0
                (min
                  (-> self mission-elapsed-clock)
                  (the int
                       (fmax
                         (* (the float (-> *blow-tower-paths* 0 total-time))
                            (-> *blow-tower-paths* 0 node-info (+ (-> *blow-tower-paths* 0 num-nodes) -1) accum-time-percentage)
                            )
                         (* (the float (-> *blow-tower-paths* 1 total-time))
                            (-> *blow-tower-paths* 1 node-info (+ (-> *blow-tower-paths* 1 num-nodes) -1) accum-time-percentage)
                            )
                         )
                       )
                  )
                )
              )
            )
      (set! (-> *blow-tower-targets* mission-time) (-> self mission-elapsed-clock))
      (if (< 0.0 f0-11)
          (task-manager-blow-tower-method-37 self (if (-> self debug-run-events?)
                                                      'all
                                                      'debug
                                                      )
                                             )
          )
      )
    (if (and (time-elapsed? (-> self state-time) (seconds 0.1)) (or (cpad-pressed? 1 start) (cpad-pressed? 1 select)))
        (go-virtual mission-play)
        )
    )
  :code sleep-code
  )

(define *blow-tower-kg-squad-member-settings* (new 'static 'inline-array kg-squad-member-settings 4
                                                (new 'static 'kg-squad-member-settings
                                                  :object-type (traffic-type roboguard)
                                                  :max-target-count #x7f
                                                  :enemy-type (traffic-type guard-a)
                                                  )
                                                (new 'static 'kg-squad-member-settings
                                                  :object-type (traffic-type roboguard)
                                                  :max-target-count #x7f
                                                  :enemy-type (traffic-type guard-b)
                                                  )
                                                (new 'static 'kg-squad-member-settings
                                                  :object-type (traffic-type flying-turret)
                                                  :max-target-count #x7f
                                                  :enemy-type (traffic-type metalhead-grunt)
                                                  )
                                                (new 'static 'kg-squad-member-settings
                                                  :object-type (traffic-type spydroid)
                                                  :max-target-count #x7f
                                                  :target-count 10
                                                  :enemy-type (traffic-type metalhead-flitter)
                                                  )
                                                )
        )

(defstate mission-play (task-manager-blow-tower)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set-blackout-frames 0)
    (speech-play *blow-tower-speech* 10 *blow-tower-speech-list* (target-pos 0))
    (set! (-> self last-missile-spawn-time) 0)
    (set-time! (-> self state-time))
    (set-setting! 'kg-enemy-settings #f 0.0 *blow-tower-kg-squad-member-settings*)
    (set-setting! 'minimap 'clear 0.0 (minimap-flag minimap))
    (talker-spawn-func (-> *talker-speech* 362) *entity-pool* (target-pos 0) (the-as region #f))
    )
  :trans (behavior ()
    ((-> (method-of-type task-manager active) trans))
    (format *stdebug* "Event ID: ~d~%" (-> self event-cursor event-id))
    (when (and (> (-> self show-skill-time) 0) (time-elapsed? (-> self show-skill-time) (seconds 2)))
      (set! (-> self show-skill-time) 0)
      (hide-hud 'hud-skill)
      )
    (set! (-> *ACTOR-bank* birth-max) 1000)
    (seek! (-> self clock-scalar) (-> self dest-clock-scalar) (* 0.5 (seconds-per-frame)))
    (set! (-> *blow-tower-targets* clock-scalar) (-> self clock-scalar))
    (dotimes (v1-13 2)
      (set! (-> *blow-tower-targets* target-handles v1-13) (-> self target-handles v1-13))
      )
    (+! (-> self mission-elapsed-clock)
        (the int (* (the float (- (current-time) (-> self clock old-frame-counter))) (-> self clock-scalar)))
        )
    (set! (-> *blow-tower-targets* mission-time) (-> self mission-elapsed-clock))
    (task-manager-blow-tower-method-37 self 'all)
    )
  :code sleep-code
  )

(defstate wait-for-exit (task-manager-blow-tower)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set-blackout-frames (seconds 1))
    (send-event (handle->process (-> self hellcat-turret)) 'allow-exit)
    (send-event *target* 'end-mode 'turret)
    )
  :trans (behavior ()
    ((-> (method-of-type task-manager active) trans))
    )
  :code (behavior ()
    (while (let ((gp-0 'turret))
             (= (send-event *target* 'query 'mode) gp-0)
             )
      (suspend)
      )
    (send-event (handle->process (-> self hellcat)) 'exit)
    (send-event (handle->process (-> self pickup)) 'exit)
    (send-event self 'complete)
    (sleep-code)
    )
  )

(defmethod task-manager-method-25 ((this task-manager-blow-tower))
  (send-event (ppointer->process *time-of-day*) 'change 'ratio 1.0)
  (call-parent-method this)
  (none)
  )

(defstate active (task-manager-blow-tower)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('player-board)
       (set! (-> self mission-elapsed-clock) 0)
       (send-event (handle->process (-> self pickup)) 'player-board)
       (if (task-node-closed? (game-task-node city-blow-tower-phase-1))
           (advance self (seconds 31.667))
           )
       (go-virtual mission-play)
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (let ((f0-1 (the float (-> *game-info* sub-task-list (game-task-node city-protect-hq-resolution) death-count))))
      (set! (-> *blow-tower-targets* difficulty-scalar) (lerp-scale-clamp 1.0 0.5 f0-1 3.0 10.0))
      )
    (speeches-reset *blow-tower-speech*)
    (set-setting! 'rain 'abs 0.0 0)
    (set-setting! 'disable-parking-spots? #t 0.0 0)
    (set! (-> self dest-clock-scalar) 1.0)
    (set! (-> self clock-scalar) 1.0)
    (set-setting! 'music 'destower 0.0 0)
    (set! (-> self last-missile-ent) "")
    (set-setting! 'lock-sound-camera-to-target #t 0.0 0)
    (set-setting! 'stop-boats? #t 0.0 0)
    (set-setting! 'hide-crates? #t 0.0 0)
    (set! (-> self debug-lock-viewport?) #f)
    (set! (-> self debug-run-events?) #f)
    (send-event (ppointer->process *time-of-day*) 'change 'hour 14)
    (send-event (ppointer->process *time-of-day*) 'change 'ratio 0.1)
    (set-cloud-and-fog-interp! *mood-control* 0.0 0.0 0.0 0.0)
    (set-time-for-random-weather! *mood-control* 100000000.0 100000000.0)
    (set! (-> self script) *blow-tower-script*)
    (set-setting! 'city-sound '(blow1 blow2 blow3h) 0.0 2)
    (dotimes (v1-44 3)
      (set! (-> self bombbot-records v1-44 hand) (the-as handle #f))
      (set! (-> self bombbot-records v1-44 ent-name) "")
      )
    (let ((v1-48 (new 'stack 'blow-tower-path-cursor)))
      60.0
      60.0
      (let ((f0-7 0.75))
        (set! (-> v1-48 path) (-> *blow-tower-paths* 0))
        (let ((f28-0
                (/ (-> *blow-tower-paths* 0 node-info (+ (-> *blow-tower-paths* 0 num-nodes) -2) accum-dist)
                   (* 104448.0 f0-7)
                   )
                )
              (f30-0
                (/ (-> *blow-tower-paths* 1 node-info (+ (-> *blow-tower-paths* 1 num-nodes) -2) accum-dist)
                   (* 104448.0 f0-7)
                   )
                )
              )
          (let ((gp-1
                  (vector-! (new 'stack-no-clear 'vector) (-> *blow-tower-paths* 0 pts 1) (-> *blow-tower-paths* 0 pts 0))
                  )
                )
            (vector-normalize! gp-1 1.0)
            (set! (-> *blow-tower-paths* 0 total-time) (the-as time-frame (the int (* 300.0 f28-0))))
            (set! (-> self event-cursor path) (-> *blow-tower-paths* 0))
            (init-fields (-> self event-cursor))
            (let ((s5-0 (new 'stack 'bt-obj-init-params)))
              (vector-copy! (-> s5-0 pos) (-> *blow-tower-paths* 0 pts 0))
              (quaternion-copy! (-> s5-0 quat) (quaternion-look-at! (new 'stack-no-clear 'quaternion) gp-1 *up-vector*))
              (set! (-> s5-0 path) (-> *blow-tower-paths* 0))
              (set! (-> s5-0 task-man) (process->handle self))
              (set! (-> self hellcat) (ppointer->handle (process-spawn bt-hellcat s5-0 :name "bt-hellcat" :to self)))
              )
            )
          (let ((gp-4
                  (vector-! (new 'stack-no-clear 'vector) (-> *blow-tower-paths* 1 pts 1) (-> *blow-tower-paths* 1 pts 0))
                  )
                )
            (vector-normalize! gp-4 1.0)
            (set! (-> *blow-tower-paths* 1 total-time) (the-as time-frame (the int (* 300.0 f30-0))))
            (let ((s5-1 (new 'stack 'bt-obj-init-params)))
              (vector-copy! (-> s5-1 pos) (-> *blow-tower-paths* 1 pts 0))
              (quaternion-copy! (-> s5-1 quat) (quaternion-look-at! (new 'stack-no-clear 'quaternion) gp-4 *up-vector*))
              (set! (-> s5-1 path) (-> *blow-tower-paths* 1))
              (set! (-> s5-1 task-man) (process->handle self))
              (set! (-> self pickup) (ppointer->handle (process-spawn bt-pickup s5-1 :name "bt-pickup" :to self)))
              )
            )
          )
        )
      )
    (set! (-> self hud-arrows)
          (ppointer->handle
            (process-spawn hud-pickup-arrows :init hud-init-by-other :name "hud-pickup-arrows" :to self)
            )
          )
    (send-event (handle->process (-> self hud-arrows)) 'force-show)
    )
  :trans (behavior ()
    ((-> (method-of-type task-manager active) trans))
    )
  :code sleep-code
  )

(defun clamp-to-ground ((arg0 vector))
  (let ((s5-0 (new 'stack-no-clear 'collide-query)))
    (vector+float*! (-> s5-0 start-pos) arg0 *up-vector* 24576.0)
    (set! (-> s5-0 move-dist quad) (the-as uint128 0))
    (set! (-> s5-0 move-dist y) -81920.0)
    (let ((v1-4 s5-0))
      (set! (-> v1-4 radius) 409.6)
      (set! (-> v1-4 collide-with) (collide-spec backgnd))
      (set! (-> v1-4 ignore-process0) #f)
      (set! (-> v1-4 ignore-process1) #f)
      (set! (-> v1-4 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-4 action-mask) (collide-action solid))
      )
    (if (>= (fill-and-probe-using-line-sphere *collide-cache* s5-0) 0.0)
        (set! (-> arg0 y) (fmax 0.0 (-> s5-0 best-other-tri intersect y)))
        )
    )
  )

(defmethod handle-bt-command ((this task-manager-blow-tower) (arg0 blow-tower-cmd))
  (local-vars (v0-3 object) (s4-8 int))
  (case (-> arg0 cmd-type)
    (((blow-tower-cmd-type spawn))
     (case (-> arg0 spawn-type)
       (((blow-tower-cmd-spawn-type kg-flyer) (blow-tower-cmd-spawn-type kg-flyer-ent))
        (let ((s4-0 (new 'stack 'tower-enemy-init-params)))
          (set! (-> s4-0 target) (-> this target-handles (-> arg0 target)))
          (vector-copy! (-> s4-0 pos) (target-pos 0))
          (set! (-> s4-0 entity-name) (-> arg0 entity-name))
          (set! (-> s4-0 time-offset) (-> arg0 time-offset))
          (if (= (-> s4-0 time-offset) 0.0)
              (set! (-> s4-0 time-offset) 3.0)
              )
          (process-spawn
            kg-flyer
            :init tower-flyer-init-by-other
            s4-0
            :name "kg-flyer"
            :to (handle->process (-> s4-0 target))
            )
          )
        )
       (((blow-tower-cmd-spawn-type mh-flyer) (blow-tower-cmd-spawn-type mh-flyer-ent))
        (let ((s4-1 (new 'stack 'tower-enemy-init-params)))
          (set! (-> s4-1 target) (-> this target-handles (-> arg0 target)))
          (vector-copy! (-> s4-1 pos) (target-pos 0))
          (set! (-> s4-1 entity-name) (-> arg0 entity-name))
          (set! (-> s4-1 time-offset) (-> arg0 time-offset))
          (if (= (-> s4-1 time-offset) 0.0)
              (set! (-> s4-1 time-offset) 3.0)
              )
          (process-spawn
            bt-mh-flyer
            :init tower-flyer-init-by-other
            s4-1
            :name "bt-mh-flyer"
            :to (handle->process (-> s4-1 target))
            )
          )
        )
       (((blow-tower-cmd-spawn-type missiles))
        (let ((s4-2 (new 'stack 'tower-enemy-init-params)))
          (set! (-> s4-2 target) (-> this target-handles (-> arg0 target)))
          (vector-copy! (-> s4-2 pos) (target-pos 0))
          (set! (-> s4-2 entity-name) "")
          (set! (-> s4-2 activate-time)
                (the-as
                  time-frame
                  (max (-> this mission-elapsed-clock) (+ (-> this last-missile-spawn-time)
                                                          (seconds 0.3)
                                                          (mod (the-as int (rand-uint31-gen *random-generator*)) 211)
                                                          )
                       )
                  )
                )
          (set! (-> this last-missile-spawn-time) (-> s4-2 activate-time))
          (set! (-> s4-2 time-offset) (-> arg0 time-offset))
          (set! (-> s4-2 bool-userdata?) #f)
          (process-spawn bt-missile s4-2 :name "bt-missile" :to (handle->process (-> s4-2 target)))
          )
        )
       (((blow-tower-cmd-spawn-type missiles-ent))
        (let ((s4-3 (new 'stack 'tower-enemy-init-params)))
          (set! (-> s4-3 target) (-> this target-handles (-> arg0 target)))
          (let ((a0-30 (entity-by-name (-> arg0 entity-name))))
            (if a0-30
                (vector-copy! (-> s4-3 pos) (-> a0-30 extra trans))
                )
            )
          (set! (-> s4-3 entity-name) "")
          (set! (-> s4-3 activate-time)
                (the-as
                  time-frame
                  (max (-> this mission-elapsed-clock) (+ (-> this last-missile-spawn-time)
                                                          (seconds 0.3)
                                                          (mod (the-as int (rand-uint31-gen *random-generator*)) 211)
                                                          )
                       )
                  )
                )
          (let ((s3-5 (new 'stack 'blow-tower-path-cursor)))
            (when (send-event (handle->process (-> s4-3 target)) 'predict-position s3-5 (new 'stack-no-clear 'vector))
              (blow-tower-path-cursor-method-9 s3-5 (the-as int (-> s4-3 activate-time)))
              (let ((s3-6 (-> s3-5 pos)))
                (cond
                  ((string= (-> this last-missile-ent) (-> arg0 entity-name))
                   (let ((v1-78 (vector-! (new 'stack-no-clear 'vector) s3-6 (-> this missile-dir-vec))))
                     (set! (-> v1-78 y) 0.0)
                     (vector+! (-> s4-3 pos) (-> s4-3 pos) v1-78)
                     )
                   )
                  (else
                    (vector-copy! (-> this missile-dir-vec) s3-6)
                    (set! (-> this last-missile-ent) (-> arg0 entity-name))
                    )
                  )
                )
              )
            )
          (set! (-> this last-missile-spawn-time) (-> s4-3 activate-time))
          (set! (-> s4-3 time-offset) (-> arg0 time-offset))
          (set! (-> s4-3 bool-userdata?) #t)
          (process-spawn bt-missile s4-3 :name "bt-missile" :to (handle->process (-> s4-3 target)))
          )
        )
       (((blow-tower-cmd-spawn-type mh-grunt))
        (let ((s4-4 (new 'stack 'tower-enemy-init-params)))
          (set! (-> s4-4 target) (-> this target-handles (-> arg0 target)))
          (let ((v1-93 (+ (-> this event-cursor current-node-index) 5)))
            (if (> (-> arg0 event-id) 0)
                (set! v1-93 (find-event-id-index (-> this event-cursor) (the-as int (-> arg0 event-id))))
                )
            (vector-copy! (-> s4-4 pos) (-> *blow-tower-paths* 0 pts v1-93))
            )
          (set! (-> s4-4 entity-name) "")
          (set! (-> s4-4 time-offset) (-> arg0 time-offset))
          (process-spawn bt-grunt s4-4 :name "bt-grunt" :to (handle->process (-> s4-4 target)))
          )
        )
       (((blow-tower-cmd-spawn-type kg-bombbot) (blow-tower-cmd-spawn-type kg-bombbot-ent))
        (let ((s4-5 (new 'stack 'bombbot-spawn-params)))
          (let ((s2-2 (new 'stack-no-clear 'vector))
                (s3-7 (new 'stack-no-clear 'vector))
                )
            (let ((s0-0 (entity-by-name (-> arg0 entity-name)))
                  (s1-0 (new 'stack 'blow-tower-path-cursor))
                  )
              (set! (-> s1-0 path) (-> *blow-tower-paths* (-> arg0 target)))
              (cond
                (s0-0
                  (vector-copy! s2-2 (-> s0-0 extra trans))
                  )
                (else
                  (blow-tower-path-cursor-method-9
                    s1-0
                    (the-as int (+ (-> this mission-elapsed-clock) (the int (* 300.0 (-> arg0 time-offset)))))
                    )
                  (vector-copy! s2-2 (-> s1-0 pos))
                  )
                )
              )
            (case (-> arg0 spawn-type)
              (((blow-tower-cmd-spawn-type kg-bombbot))
               (let ((a0-79 (find-path-event-id-index (-> *blow-tower-paths* 0) (the-as int (-> arg0 event-id)))))
                 (if (>= a0-79 0)
                     (vector-copy! s3-7 (-> *blow-tower-paths* (-> arg0 target) pts a0-79))
                     (vector-copy! s3-7 s2-2)
                     )
                 )
               )
              (((blow-tower-cmd-spawn-type kg-bombbot-ent))
               (let ((a0-87 (entity-by-name (-> arg0 entity-name2))))
                 (if a0-87
                     (vector-copy! s3-7 (-> a0-87 extra trans))
                     )
                 )
               )
              )
            (clamp-to-ground s2-2)
            (clamp-to-ground s3-7)
            (set! (-> s4-5 path) (-> *blow-tower-bombbat-path-cache* (-> this bombbot-path-index)))
            (set! (-> this bombbot-path-index) (logand (+ (-> this bombbot-path-index) 1) 7))
            (set! (-> s4-5 first-node) (the-as uint 0))
            (set! (-> s4-5 stop-offset) 36000.0)
            (set! (-> s4-5 path node 0 position quad) (-> s2-2 quad))
            (set! (-> s4-5 path node 1 position quad) (-> s3-7 quad))
            )
          (set! (-> s4-5 path node 0 nav-mesh-id) (the-as uint -1))
          (set! (-> s4-5 path node 1 nav-mesh-id) (the-as uint -1))
          (quaternion-identity! (-> s4-5 quat))
          (let ((s3-8 (get-process *default-dead-pool* kg-bombbot #x4000 1)))
            (set! (-> this bombbot-records (-> this bombbot-record-index) hand)
                  (ppointer->handle
                    (-> (ppointer->handle (when s3-8
                                            (let ((t9-41 (method-of-type kg-bombbot activate)))
                                              (t9-41 (the-as kg-bombbot s3-8) this "kg-bombbot" (the-as pointer #x70004000))
                                              )
                                            (run-now-in-process s3-8 bombbot-init-by-other s4-5)
                                            (-> s3-8 ppointer)
                                            )
                                          )
                        process
                        )
                    )
                  )
            )
          )
        (set! (-> this bombbot-records (-> this bombbot-record-index) ent-name) (-> arg0 entity-name))
        (set! v0-3 (mod (+ (-> this bombbot-record-index) 1) 3))
        (set! (-> this bombbot-record-index) (the-as int v0-3))
        v0-3
        )
       )
     )
    (((blow-tower-cmd-type end))
     (go (method-of-object this wait-for-exit))
     )
    (((blow-tower-cmd-type activate))
     (let ((v1-151 (entity-by-name (-> arg0 entity-name))))
       (if v1-151
           (send-event
             (if v1-151
                 (-> v1-151 extra process)
                 )
             'activate
             (-> this target-handles (-> arg0 target))
             )
           )
       )
     )
    (((blow-tower-cmd-type lock-view))
     (send-event (handle->process (-> this hellcat-turret)) 'lock-view (-> arg0 lock-min) (-> arg0 lock-max))
     (send-event (handle->process (-> this hellcat)) 'lock-view)
     )
    (((blow-tower-cmd-type unlock-view))
     (send-event (handle->process (-> this hellcat-turret)) 'unlock-view)
     (send-event (handle->process (-> this hellcat)) 'unlock-view)
     )
    (((blow-tower-cmd-type constrain-angle))
     (send-event (handle->process (-> this hellcat-turret)) 'constrain-angle (-> arg0 rotate-amount))
     )
    (((blow-tower-cmd-type rotate-view))
     (send-event
       (handle->process (-> this hellcat-turret))
       'rotate-view
       (-> arg0 rotate-amount)
       (-> arg0 snap-view?)
       (* 182.04445 (-> arg0 time-offset))
       )
     (send-event (handle->process (-> this hellcat)) 'rotate-view)
     )
    (((blow-tower-cmd-type roll-amount))
     (send-event
       (handle->process (-> this target-handles (-> arg0 target)))
       'roll-amount
       (-> arg0 path-height)
       (-> arg0 time-offset)
       )
     )
    (((blow-tower-cmd-type barrel-roll))
     (send-event
       (handle->process (-> this target-handles (-> arg0 target)))
       'barrel-roll
       (-> arg0 path-height)
       (-> arg0 time-offset)
       )
     )
    (((blow-tower-cmd-type advance))
     (advance this (the-as time-frame (-> arg0 event-id)))
     )
    (((blow-tower-cmd-type look-at-bombbot))
     (dotimes (s4-6 3)
       (when (and (string= (-> this bombbot-records s4-6 ent-name) (-> arg0 entity-name))
                  (handle->process (-> this bombbot-records s4-6 hand))
                  )
         (send-event
           (handle->process (-> this hellcat-turret))
           'look-at-proc
           (-> this bombbot-records s4-6 hand)
           (-> arg0 path-height)
           )
         (set! v0-3 0)
         (goto cfg-205)
         )
       )
     (set! v0-3 #f)
     (label cfg-205)
     v0-3
     )
    (((blow-tower-cmd-type look-at))
     (send-event
       (handle->process (-> this hellcat-turret))
       'look-at
       (-> arg0 target)
       (the int (* 300.0 (-> arg0 time-offset)))
       (-> arg0 path-height)
       )
     )
    (((blow-tower-cmd-type look-at-ent))
     (send-event
       (handle->process (-> this hellcat-turret))
       'look-at-ent
       (-> arg0 entity-name)
       (-> arg0 path-height)
       )
     )
    (((blow-tower-cmd-type look-at-track))
     (send-event
       (handle->process (-> this hellcat-turret))
       'look-at-track
       (-> arg0 entity-name)
       (-> arg0 path-height)
       )
     )
    (((blow-tower-cmd-type clock-scalar))
     (set! (-> this dest-clock-scalar) (-> arg0 clock-scalar))
     )
    (((blow-tower-cmd-type play-sound))
     (let ((s4-7 (as-type (handle->process (-> this target-handles (-> arg0 target))) process-focusable)))
       (when s4-7
         (send-event (handle->process (-> this target-handles (-> arg0 target))) 'boost-thruster (-> arg0 time-offset))
         (sound-play "hc-whoosh" :position (-> s4-7 root trans))
         )
       )
     )
    (((blow-tower-cmd-type cmd12))
     (send-event (handle->process (-> this target-handles (-> arg0 target))) 'stop-sound)
     )
    (((blow-tower-cmd-type save-progress))
     (task-node-close! (game-task-node city-blow-tower-phase-1) 'event)
     )
    (((blow-tower-cmd-type path-height))
     (let ((v1-299 (find-path-event-id-index (-> *blow-tower-paths* 0) (the-as int (-> arg0 event-id)))))
       0
       (if (>= v1-299 0)
           (set! s4-8 (the int (* (-> *blow-tower-paths* 0 node-info v1-299 accum-time-percentage)
                                  (the float (-> *blow-tower-paths* 0 total-time))
                                  )
                           )
                 )
           (set! s4-8 (the-as int (+ (-> this mission-elapsed-clock) (seconds 2))))
           )
       )
     (case (-> arg0 target)
       ((3)
        (dotimes (s3-10 2)
          (send-event (handle->process (-> this target-handles s3-10)) 'set-path-height (-> arg0 path-height) s4-8)
          )
        #f
        )
       (else
         (send-event
           (handle->process (-> this target-handles (-> arg0 target)))
           'set-path-height
           (-> arg0 path-height)
           s4-8
           )
         )
       )
     )
    )
  )

(defmethod advance ((this task-manager-blow-tower) (arg0 time-frame))
  (let ((v1-1 (find-path-event-id-index (-> *blow-tower-paths* 0) (the-as int arg0))))
    0
    (if (>= v1-1 0)
        (set! (-> this mission-elapsed-clock)
              (the-as time-frame (the int (* (-> *blow-tower-paths* 0 node-info v1-1 accum-time-percentage)
                                             (the float (-> *blow-tower-paths* 0 total-time))
                                             )
                                      )
                      )
              )
        )
    )
  (none)
  )

(defmethod task-manager-blow-tower-method-37 ((this task-manager-blow-tower) (arg0 symbol))
  (let ((s4-0 (-> this event-cursor current-node-index)))
    (blow-tower-path-cursor-method-9 (-> this event-cursor) (the-as int (-> this mission-elapsed-clock)))
    (when (!= s4-0 (-> this event-cursor current-node-index))
      (dotimes (s4-1 (-> this script length))
        (when (= (-> this script s4-1 event-id) (-> this event-cursor event-id))
          (let* ((a0-7 (-> this script s4-1 command-list))
                 (s3-0 ((method-of-type (rtype-of a0-7) length) a0-7))
                 )
            (dotimes (s2-0 s3-0)
              (let ((s1-0 (ref (-> this script s4-1 command-list) s2-0)))
                (parse-blow-tower-command (the-as pair s1-0) (-> this cmd))
                (when (or (= arg0 'all) (or (and (= arg0 'debug) (case (-> this cmd cmd-type)
                                                                   (((blow-tower-cmd-type lock-view)
                                                                     (blow-tower-cmd-type unlock-view)
                                                                     (blow-tower-cmd-type rotate-view)
                                                                     (blow-tower-cmd-type roll-amount)
                                                                     (blow-tower-cmd-type path-height)
                                                                     (blow-tower-cmd-type look-at)
                                                                     )
                                                                    #t
                                                                    )
                                                                   )
                                                 )
                                            (and (= arg0 'fail) (case (-> this cmd cmd-type)
                                                                  (((blow-tower-cmd-type path-height))
                                                                   #t
                                                                   )
                                                                  )
                                                 )
                                            )
                          )
                  (handle-bt-command this (-> this cmd))
                  (format 0 "Command is ~s~%" s1-0)
                  )
                )
              )
            )
          )
        )
      #f
      )
    )
  )

(defmethod get-trans ((this bt-hellcat) (arg0 int))
  "Get the `trans` for this process."
  (case arg0
    ((3)
     (vector<-cspace! (new 'static 'vector) (-> this node-list data 6))
     )
    (else
      (call-parent-method this arg0)
      )
    )
  )

(defpart 4826
  :init-specs ((:texture (gun-blue-beam level-default-sprite))
    (:birth-func 'birth-func-setup-beam)
    (:num 1.0)
    (:scale-x (meters 0.3) (meters 0.1))
    (:scale-y (meters 100) (meters 20))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 16.0)
    (:fade-a 0.8)
    (:timer (seconds 0.5))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-14 left-multiply-quat))
    (:userdata :data (new 'static 'boxed-array :type int32 30 0 0 #x401000 #x401200))
    (:func 'sparticle-texture-animate)
    (:next-time (seconds 0.05))
    (:next-launcher 4827)
    )
  )

(defpart 4827
  :init-specs ((:scalevel-x (meters 0.033333335))
    (:scalevel-y (meters -0.13333334))
    (:fade-r 0.85333335)
    (:fade-g 0.85333335)
    (:fade-b 0.85333335)
    (:fade-a -0.21333334 -0.42666668)
    (:accel-y (meters 0.000033333334))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-13 sp-cpuinfo-flag-14 left-multiply-quat))
    (:next-time (seconds 0.5))
    (:next-launcher 4828)
    )
  )

(defpart 4828
  :init-specs ((:fade-r 0.0) (:fade-g 0.0) (:fade-b 0.0))
  )

;; WARN: Return type mismatch (array bt-vehicle-damage-info) vs none.
(defmethod init-params ((this bt-hellcat))
  (set! (-> this whoosh-sound) (new-sound-id))
  (set! (-> this boost-thruster?) #f)
  (set! (-> this inited?) #f)
  (set! (-> this rider-spots) (new 'process 'cast-rider-array 2))
  (set! (-> this rider-spots data 0 rider)
        (ppointer->handle
          (process-spawn
            cast-rider
            (art-group-get-by-name *level* "skel-bt-jinx" (the-as (pointer level) #f))
            4
            6
            :name "cast-rider"
            :to this
            )
          )
        )
  (set! (-> this rider-spots data 1 rider)
        (ppointer->handle (process-spawn
                            cast-rider
                            (art-group-get-by-name *level* "skel-bt-sig" (the-as (pointer level) #f))
                            7
                            6
                            :name "cast-rider"
                            :to this
                            )
                          )
        )
  (setup-masks (-> this draw) -1 1022)
  (init (-> this jmod-turret-guns) this (the-as uint 6) (joint-mod-base-flags attached))
  (init (-> this jmod-lgun) this (the-as uint 7) (joint-mod-base-flags attached))
  (init (-> this jmod-rgun) this (the-as uint 10) (joint-mod-base-flags attached))
  (dotimes (s5-2 4)
    (init
      (-> this jmod-barrels s5-2)
      this
      (the-as uint (-> *bt-hellcat-gun-nodes* s5-2))
      (joint-mod-base-flags attached trans)
      )
    (set! (-> this barrel-fire-state s5-2) #f)
    )
  (set! (-> this grunt-rider) (the-as handle #f))
  (set! (-> this grunt-rider-boarded?) (the-as handle #f))
  (init-spots this)
  (set! (-> this mission-fail?) #f)
  (set! (-> this max-hit-points) 40.0)
  (set! (-> this hit-points) (-> this max-hit-points))
  (init-hud this)
  (set! (-> this dest-roll-amount) 0.0)
  (quaternion-copy! (-> this quat-before-bounce) (-> this root quat))
  (quaternion-identity! (-> this quat-grunt-tilt))
  (quaternion-identity! (-> this barrel-roll-quat))
  (set! (-> this engine-sound) (new-sound-id))
  (set! (-> this thrust-sound) (new-sound-id))
  (set! (-> this damage-info) *bt-hellcat-damage-info*)
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod init-params ((this bt-pickup))
  (set! (-> this whoosh-sound) (new-sound-id))
  (set! (-> this boost-thruster?) #f)
  (set! (-> this inited?) #f)
  (set! (-> this rider-spots) (new 'process 'cast-rider-array 1))
  (set! (-> this rider-spots data 0 rider)
        (ppointer->handle (process-spawn
                            cast-rider
                            (art-group-get-by-name *level* "skel-bt-torn" (the-as (pointer level) #f))
                            3
                            6
                            :name "cast-rider"
                            :to this
                            )
                          )
        )
  (setup-masks (-> this draw) -1 30)
  (set! (-> this max-hit-points) 75.0)
  (set! (-> this hit-points) (-> this max-hit-points))
  (bt-pickup-method-48 this)
  (init-hud this)
  (quaternion-identity! (-> this barrel-roll-quat))
  (set! (-> this damage-info) *bt-pickup-damage-info*)
  (dotimes (v1-15 2)
    (set! (-> this roboguard-attackers v1-15) (the-as handle #f))
    )
  (dotimes (s5-1 2)
    (set! (-> this pickup-barrels s5-1)
          (ppointer->handle (process-spawn bt-pickup-barrel s5-1 :name "bt-pickup-barrel" :to this))
          )
    )
  (none)
  )

(defmethod init-hud ((this bt-pickup))
  (set! (-> this hud-health)
        (ppointer->handle (process-spawn hud-pickup :init hud-init-by-other :name "hud-pickup" :to this))
        )
  (none)
  )

(defmethod init-hud ((this bt-hellcat))
  (set! (-> this hud-health)
        (ppointer->handle (process-spawn hud-hellcat :init hud-init-by-other :name "hud-hellcat" :to this))
        )
  (none)
  )

(defmethod bounce ((this bt-pickup) (arg0 vector))
  (set! (-> arg0 y) (* 2.0 (-> arg0 y)))
  (vector-float*! arg0 arg0 0.4)
  (call-parent-method this arg0)
  )

(defmethod on-attacked ((this bt-pickup) (arg0 float) (arg1 attack-info) (arg2 process-focusable))
  (send-event (handle->process (-> this hud-health)) 'hit)
  (set-time! (-> this start-hit-time))
  (sound-play "snd-pickup-hit")
  (cond
    ((not (logtest? (-> arg1 mask) (attack-mask control)))
     (let ((s2-1 (new 'stack-no-clear 'attack-info)))
       (attack-info-method-9 arg1 s2-1 arg2 this)
       (let ((a0-11 (as-type arg2 process-focusable)))
         (if a0-11
             (vector-copy! (-> s2-1 intersection) (get-trans a0-11 3))
             )
         )
       (cond
         ((logtest? (-> group-bt-dummy flags) (sp-group-flag sp13))
          (vector-copy! (-> *launch-matrix* trans) (-> s2-1 intersection))
          (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-bt-dummy)
          )
         (else
           (vector-copy! (-> *launch-matrix* trans) (-> s2-1 intersection))
           (part-tracker-spawn part-tracker :to *entity-pool* :group group-bt-dummy)
           )
         )
       (let ((s1-7 (vector-! (new 'stack-no-clear 'vector) (get-trans this 3) (-> s2-1 intersection))))
         (vector-normalize! s1-7 (fmax 5324.8 (fmin 16384.0 (* 4096.0 arg0))))
         (bounce this s1-7)
         )
       )
     )
    ((logtest? (-> group-bt-dummy flags) (sp-group-flag sp13))
     (vector-copy! (-> *launch-matrix* trans) (-> arg1 intersection))
     (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-bt-dummy)
     )
    (else
      (vector-copy! (-> *launch-matrix* trans) (-> arg1 intersection))
      (part-tracker-spawn part-tracker :to *entity-pool* :group group-bt-dummy)
      )
    )
  (call-parent-method this arg0 arg1 arg2)
  (none)
  )

(defstate wind-down-mission (task-manager-blow-tower)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set! (-> self dest-clock-scalar) 0.0)
    (format 0 "Self scalsr ~f~%" (-> self clock-scalar))
    (if *target*
        (logior! (-> *target* draw status) (draw-control-status no-draw))
        )
    )
  :trans (behavior ()
    (seek! (-> self clock-scalar) (-> self dest-clock-scalar) (seconds-per-frame))
    (dotimes (v1-1 2)
      (set! (-> *blow-tower-targets* target-handles v1-1) (-> self target-handles v1-1))
      )
    (+! (-> self mission-elapsed-clock)
        (the int (* (the float (- (current-time) (-> self clock old-frame-counter))) (-> self clock-scalar)))
        )
    (set! (-> *blow-tower-targets* mission-time) (-> self mission-elapsed-clock))
    (task-manager-blow-tower-method-37 self 'fail)
    (if (>= 0.0 (-> self clock-scalar))
        (go-virtual wait-fail)
        )
    )
  :code sleep-code
  )

(defstate wait-fail (task-manager-blow-tower)
  :virtual #t
  :event task-manager-event-handler
  :code (behavior ()
    (dotimes (gp-0 2)
      (send-event (handle->process (-> self target-handles gp-0)) 'mission-fail)
      )
    (if *target*
        (logior! (-> *target* draw status) (draw-control-status no-draw))
        )
    (send-event self 'fail)
    (sleep-code)
    )
  )

(defmethod bt-pickup-method-50 ((this bt-pickup) (arg0 int) (arg1 vector))
  (vector-copy! arg1 (-> this root trans))
  (let ((v1-2 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> this root quat))))
    (vector+float*! arg1 arg1 (-> v1-2 fvec) -21708.8)
    (vector+float*! arg1 arg1 (-> v1-2 uvec) -2457.6)
    (cond
      ((zero? arg0)
       (vector+float*! arg1 arg1 (-> v1-2 rvec) 4096.0)
       )
      ((= arg0 1)
       (vector+float*! arg1 arg1 (-> v1-2 rvec) -4096.0)
       )
      )
    )
  arg1
  )

;; WARN: Return type mismatch symbol vs object.
(defmethod draw-thruster ((this bt-pickup))
  (call-parent-method this)
  (if (-> this boost-thruster?)
      (seek!
        (-> this desired-thruster-length)
        (* 28672.0 (fmax 1.0 (* (-> this path-cursor speed) (-> *blow-tower-targets* clock-scalar))))
        (* 16384.0 (seconds-per-frame))
        )
      (seek!
        (-> this desired-thruster-length)
        (* 16384.0 (-> *blow-tower-targets* clock-scalar) (-> this path-cursor speed))
        (* 16384.0 (seconds-per-frame))
        )
      )
  (dotimes (s5-0 2)
    (let ((s4-0 (bt-pickup-method-50 this s5-0 (new 'stack-no-clear 'vector))))
      (let* ((f30-0 (-> this desired-thruster-length))
             (f28-0 -1228.8)
             (f26-0 2457.6)
             (v1-16 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-17 (the-as number (logior #x3f800000 v1-16)))
             (f0-18 (+ f28-0 (* f26-0 (+ -1.0 (the-as float v1-17))) f30-0))
             )
        (set! (-> *part-id-table* 4825 init-specs 4 initial-valuef) f0-18)
        (set! (-> *part-id-table* 4825 init-specs 3 initial-valuef) (/ f0-18 2))
        )
      (draw-beam
        (-> *part-id-table* 4825)
        s4-0
        (vector-float*!
          (new 'stack-no-clear 'vector)
          (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))
          -20480.0
          )
        #f
        )
      )
    )
  #f
  )

(defstate die (bt-pickup)
  :virtual #t
  :enter (behavior ()
    (call-parent-state-handler enter)
    (dotimes (gp-0 2)
      (send-event (handle->process (-> self pickup-barrels gp-0)) 'die)
      )
    )
  )
