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

;; name: pilot-states.gc
;; name in dgo: pilot-states
;; dgos: CWI
(define-extern *pilot-get-on-mods* surface)
(define-extern *pilot-get-off-mods* surface)

;; DECOMP BEGINS

(defstate target-pilot-start (target)
  :event target-pilot-handler
  :exit target-pilot-exit
  :code (behavior ((arg0 handle) (arg1 symbol) (arg2 symbol))
    (target-pilot-init arg0 arg2)
    (suspend)
    (remove-exit)
    (if arg1
        (go target-pilot-stance)
        (go target-pilot-get-on)
        )
    )
  :post target-post
  )

;; WARN: Return type mismatch symbol vs none.
;; WARN: new jak 2 until loop case, check carefully
(defbehavior target-pilot-bike-anim-loop target ()
  (ja-channel-push! 3 (seconds 0.1))
  (ja :group! jakb-pilot-bike-turn-back-ja)
  (ja :chan 1 :group! jakb-pilot-bike-turn-front-ja)
  (ja :chan 2 :group! jakb-pilot-bike-up-down-ja)
  (until #f
    (let ((gp-0 (-> self pilot)))
      (let ((f30-0 (* 5.0 (- 1.0 (-> gp-0 left-right-interp)))))
        (ja :num-func num-func-identity :frame-num (ja-aframe f30-0 0))
        (let ((f0-3 (fmax 0.0 (fmin 1.0 (* 0.5 (+ 1.0 (* 1.42 (+ -0.3 (-> gp-0 front-back-interp)))))))))
          (ja :chan 1
              :frame-interp0 f0-3
              :frame-interp1 f0-3
              :num-func num-func-identity
              :frame-num (ja-aframe f30-0 1)
              )
          )
        )
      (let ((f0-6 (* 5.0 (- 1.0 (-> gp-0 up-down-interp))))
            (s5-2 (-> self skel root-channel 2))
            )
        (let ((f1-7 (fabs (-> gp-0 up-down-interp))))
          (set! (-> s5-2 frame-interp 1) f1-7)
          (set! (-> s5-2 frame-interp 0) f1-7)
          )
        (set! (-> s5-2 num-func) num-func-identity)
        (set! (-> s5-2 frame-num) (ja-aframe f0-6 2))
        )
      )
    (can-play-stance-amibent?)
    (suspend)
    )
  #f
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
;; WARN: new jak 2 until loop case, check carefully
(defbehavior target-pilot-car-anim-loop target ()
  (ja-channel-push! 3 (seconds 0.1))
  (ja :group! jakb-pilot-car-turn-back-ja)
  (ja :chan 1 :group! jakb-pilot-car-turn-front-ja)
  (ja :chan 2 :group! jakb-pilot-car-up-down-ja)
  (until #f
    (let ((gp-0 (-> self pilot)))
      (let ((f30-0 (* 5.0 (+ 1.0 (-> gp-0 left-right-interp)))))
        (ja :num-func num-func-identity :frame-num (ja-aframe f30-0 0))
        (let ((s5-1 (-> self skel root-channel 1)))
          (let ((f0-3 (* 0.5 (+ 1.0 (-> gp-0 front-back-interp)))))
            (set! (-> s5-1 frame-interp 1) f0-3)
            (set! (-> s5-1 frame-interp 0) f0-3)
            )
          (set! (-> s5-1 num-func) num-func-identity)
          (set! (-> s5-1 frame-num) (ja-aframe f30-0 1))
          )
        )
      (let ((f0-6 (* 10.0 (- 1.0 (-> gp-0 up-down-interp))))
            (s5-2 (-> self skel root-channel 2))
            )
        (let ((f1-7 (fabs (-> gp-0 up-down-interp))))
          (set! (-> s5-2 frame-interp 1) f1-7)
          (set! (-> s5-2 frame-interp 0) f1-7)
          )
        (set! (-> s5-2 num-func) num-func-identity)
        (set! (-> s5-2 frame-num) (ja-aframe f0-6 2))
        )
      )
    (suspend)
    )
  #f
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
;; WARN: new jak 2 until loop case, check carefully
(defbehavior target-daxter-pilot-car-anim-loop target ()
  (ja-channel-push! 3 (seconds 0.1))
  (ja :group! (-> self draw art-group data 453))
  (ja :chan 1 :group! (-> self draw art-group data 452))
  (ja :chan 2 :group! (-> self draw art-group data 454))
  (until #f
    (let ((gp-0 (-> self pilot)))
      (let ((f30-0 (* 5.0 (+ 1.0 (-> gp-0 left-right-interp)))))
        (ja :num-func num-func-identity :frame-num (ja-aframe f30-0 0))
        (let ((s5-1 (-> self skel root-channel 1)))
          (let ((f0-3 (* 0.5 (+ 1.0 (-> gp-0 front-back-interp)))))
            (set! (-> s5-1 frame-interp 1) f0-3)
            (set! (-> s5-1 frame-interp 0) f0-3)
            )
          (set! (-> s5-1 num-func) num-func-identity)
          (set! (-> s5-1 frame-num) (ja-aframe f30-0 1))
          )
        )
      (let ((f0-6 (* 10.0 (- 1.0 (-> gp-0 up-down-interp))))
            (s5-2 (-> self skel root-channel 2))
            )
        (let ((f1-7 (fabs (-> gp-0 up-down-interp))))
          (set! (-> s5-2 frame-interp 1) f1-7)
          (set! (-> s5-2 frame-interp 0) f1-7)
          )
        (set! (-> s5-2 num-func) num-func-identity)
        (set! (-> s5-2 frame-num) (ja-aframe f0-6 2))
        )
      )
    (suspend)
    )
  #f
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defbehavior target-pilot-trans target ()
  (let* ((gp-0 (-> self pilot))
         (s5-0 (handle->process (-> gp-0 vehicle)))
         )
    (cond
      ((not s5-0)
       (ja-channel-set! 0)
       (go target-falling #f)
       )
      (#t
        (let ((s4-0 (new 'stack-no-clear 'inline-array 'vector 10)))
          (set! (-> gp-0 accel-array 7 quad) (-> gp-0 accel-array 6 quad))
          (set! (-> gp-0 accel-array 6 quad) (-> gp-0 accel-array 5 quad))
          (set! (-> gp-0 accel-array 5 quad) (-> gp-0 accel-array 4 quad))
          (set! (-> gp-0 accel-array 4 quad) (-> gp-0 accel-array 3 quad))
          (set! (-> gp-0 accel-array 3 quad) (-> gp-0 accel-array 2 quad))
          (set! (-> gp-0 accel-array 2 quad) (-> gp-0 accel-array 1 quad))
          (set! (-> gp-0 accel-array 1 quad) (-> gp-0 accel-array 0 quad))
          (vehicle-method-115 (the-as vehicle s5-0) (the-as vector (-> gp-0 accel-array)))
          (vector-reset! (-> s4-0 0))
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (the-as vector (-> gp-0 accel-array)) 1.0)
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (-> gp-0 accel-array 1) 1.0)
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (-> gp-0 accel-array 2) 1.0)
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (-> gp-0 accel-array 3) 1.0)
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (-> gp-0 accel-array 4) 1.0)
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (-> gp-0 accel-array 5) 1.0)
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (-> gp-0 accel-array 6) 1.0)
          (vector+float*! (-> s4-0 0) (-> s4-0 0) (-> gp-0 accel-array 7) 1.0)
          (vector-float*! (-> s4-0 0) (-> s4-0 0) 0.5)
          (matrix-transpose! (the-as matrix (-> s4-0 1)) (-> self node-list data 0 bone transform))
          (vector-rotate*! (-> gp-0 local-accel) (-> s4-0 0) (the-as matrix (-> s4-0 1)))
          )
        (vehicle-method-116 (the-as vehicle s5-0) (the-as (pointer vehicle-controls) (-> gp-0 controls)))
        (let ((f30-0 (* 182.04445 (* 0.6 (the float (current-time)))))
              (s5-1 (-> gp-0 local-accel))
              )
          (let ((f3-0
                  (+ (-> gp-0 controls steering) (* 0.03 (sin f30-0)) (* -1.0 (-> s5-1 x) (-> gp-0 left-right-accel-factor)))
                  )
                )
            (set! (-> gp-0 left-right-interp)
                  (fmax
                    -1.0
                    (fmin 1.0 (+ (-> gp-0 left-right-interp) (* 8.0 (- f3-0 (-> gp-0 left-right-interp)) (seconds-per-frame))))
                    )
                  )
            )
          (let ((f3-4
                  (+ (-> gp-0 controls lean-z) (* 0.03 (cos f30-0)) (* -1.0 (-> s5-1 z) (-> gp-0 front-back-accel-factor)))
                  )
                )
            (set! (-> gp-0 front-back-interp)
                  (fmax
                    -1.0
                    (fmin 1.0 (+ (-> gp-0 front-back-interp) (* 8.0 (- f3-4 (-> gp-0 front-back-interp)) (seconds-per-frame))))
                    )
                  )
            )
          (let ((f3-8 (+ (* 0.03 (cos f30-0)) (* -1.0 (-> s5-1 y) (-> gp-0 up-down-accel-factor)))))
            (set! (-> gp-0 up-down-interp)
                  (fmax
                    -1.0
                    (fmin 1.0 (+ (-> gp-0 up-down-interp) (* 8.0 (- f3-8 (-> gp-0 up-down-interp)) (seconds-per-frame))))
                    )
                  )
            )
          )
        (when (and (-> self next-state) (= (-> self next-state name) 'target-pilot-stance))
          (let* ((v1-67 (-> gp-0 accel-array))
                 (f0-27 (+ (* (-> v1-67 0 x) (-> v1-67 0 x)) (* (-> v1-67 0 z) (-> v1-67 0 z))))
                 )
            (if (or (and (-> self pilot as-daxter?) (let ((f1-20 1024000.0))
                                                      (< (* f1-20 f1-20) f0-27)
                                                      )
                         )
                    (let ((f1-23 2048000.0))
                      (< (* f1-23 f1-23) f0-27)
                      )
                    )
                (go target-pilot-impact)
                )
            )
          )
        )
      (else
        (go target-pilot-get-off)
        )
      )
    )
  (none)
  )

(defbehavior target-pilot-signal-ready target ()
  (when (not (focus-test? self pilot-riding))
    (logior! (-> self focus-status) (focus-status pilot-riding))
    (send-event (handle->process (-> self pilot vehicle)) 'pilot-on (-> self pilot seat-index))
    )
  )

(defstate target-pilot-stance (target)
  :event target-pilot-handler
  :exit target-pilot-exit
  :trans (behavior ()
    (target-pilot-trans)
    )
  :code (behavior ()
    (target-pilot-signal-ready)
    (logior! (-> self state-flags) (state-flags sf6))
    (set! (-> self control mod-surface) *pilot-mods*)
    (logior! (-> self control status) (collide-status on-surface on-ground))
    (cond
      ((-> self pilot as-daxter?)
       (target-daxter-pilot-car-anim-loop)
       )
      ((zero? (-> self pilot stance))
       (target-pilot-bike-anim-loop)
       )
      (else
        (target-pilot-car-anim-loop)
        )
      )
    )
  :post (behavior ()
    (target-pilot-post)
    )
  )

(defstate target-pilot-impact (target)
  :event target-pilot-handler
  :exit target-pilot-exit
  :trans (behavior ()
    (target-pilot-trans)
    )
  :code (behavior ()
    (local-vars (v1-1 float) (v1-252 int))
    (rlet ((acc :class vf)
           (vf0 :class vf)
           (vf1 :class vf)
           (vf2 :class vf)
           )
      (init-vf0-vector)
      (let ((gp-0 (-> self pilot)))
        (.lvf vf1 (&-> (-> gp-0 local-accel) quad))
        (.add.w.vf.x vf2 vf0 vf0)
        (.mul.vf vf1 vf1 vf1)
        (.mul.x.vf.x acc vf2 vf1)
        (.add.mul.y.vf.x acc vf2 vf1 acc)
        (.add.mul.z.vf.x vf1 vf2 vf1 acc)
        (.mov v1-1 vf1)
        (let ((f0-0 v1-1)
              (v1-2 (new 'stack-no-clear 'vector))
              )
          (set! (-> v1-2 quad) (-> gp-0 local-accel quad))
          (set! (-> v1-2 x) (* 4.0 (-> v1-2 x)))
          (vector-float*! v1-2 v1-2 (/ 1.0 (sqrtf f0-0)))
          (let ((s5-0 (cond
                        ((< 0.707 (-> v1-2 x))
                         5
                         )
                        ((< (-> v1-2 x) -0.707)
                         4
                         )
                        ((< 0.707 (-> v1-2 y))
                         3
                         )
                        ((< (-> v1-2 y) -0.707)
                         2
                         )
                        ((< 0.707 (-> v1-2 z))
                         1
                         )
                        ((< (-> v1-2 z) -0.707)
                         0
                         )
                        (else
                          6
                          )
                        )
                      )
                )
            (cond
              ((-> self pilot as-daxter?)
               (ja-channel-push! 1 (seconds 0.05))
               (cond
                 ((= s5-0 4)
                  (ja-no-eval :group! (-> self draw art-group data 457) :num! (seek!) :frame-num 0.0)
                  (until (ja-done? 0)
                    (suspend)
                    (ja :num! (seek!))
                    )
                  )
                 ((= s5-0 5)
                  (ja-no-eval :group! (-> self draw art-group data 458) :num! (seek!) :frame-num 0.0)
                  (until (ja-done? 0)
                    (suspend)
                    (ja :num! (seek!))
                    )
                  )
                 ((zero? s5-0)
                  (ja-no-eval :group! (-> self draw art-group data 455) :num! (seek!) :frame-num 0.0)
                  (until (ja-done? 0)
                    (suspend)
                    (ja :num! (seek!))
                    )
                  )
                 ((= s5-0 1)
                  (ja-no-eval :group! (-> self draw art-group data 456) :num! (seek!) :frame-num 0.0)
                  (until (ja-done? 0)
                    (suspend)
                    (ja :num! (seek!))
                    )
                  )
                 (else
                   (ja-no-eval :group! (-> self draw art-group data 455) :num! (seek!) :frame-num 0.0)
                   (until (ja-done? 0)
                     (suspend)
                     (ja :num! (seek!))
                     )
                   )
                 )
               )
              ((zero? (-> self pilot stance))
               (ja-channel-push! 1 (seconds 0.05))
               (let ((v1-131 s5-0))
                 (cond
                   ((= v1-131 4)
                    (ja-no-eval :group! jakb-pilot-bike-smack-left-ja :num! (seek!) :frame-num 0.0)
                    (until (ja-done? 0)
                      (suspend)
                      (ja :num! (seek!))
                      )
                    )
                   ((= v1-131 5)
                    (ja-no-eval :group! jakb-pilot-bike-smack-right-ja :num! (seek!) :frame-num 0.0)
                    (until (ja-done? 0)
                      (suspend)
                      (ja :num! (seek!))
                      )
                    )
                   ((zero? v1-131)
                    (ja-no-eval :group! jakb-pilot-bike-smack-front-ja :num! (seek!) :frame-num (ja-aframe 0.0 0))
                    (until (ja-done? 0)
                      (suspend)
                      (ja :num! (seek!))
                      )
                    )
                   ((= v1-131 1)
                    (ja-no-eval :group! jakb-pilot-bike-smack-back-ja :num! (seek!) :frame-num (ja-aframe 0.0 0))
                    (until (ja-done? 0)
                      (suspend)
                      (ja :num! (seek!))
                      )
                    )
                   (else
                     (ja-no-eval :group! jakb-pilot-bike-smack-shock-ja :num! (seek!) :frame-num (ja-aframe 0.0 0))
                     (until (ja-done? 0)
                       (suspend)
                       (ja :num! (seek!))
                       )
                     )
                   )
                 )
               )
              ((begin (ja-channel-push! 1 (seconds 0.05)) (set! v1-252 s5-0) (= v1-252 4))
               (ja-no-eval :group! jakb-pilot-car-smack-left-ja :num! (seek!) :frame-num 0.0)
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               )
              ((= v1-252 5)
               (ja-no-eval :group! jakb-pilot-car-smack-right-ja :num! (seek!) :frame-num 0.0)
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               )
              ((zero? v1-252)
               (ja-no-eval :group! jakb-pilot-car-smack-front-ja :num! (seek! max 1.3) :frame-num (ja-aframe 4.0 0))
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek! max 1.3))
                 )
               )
              ((= v1-252 1)
               (ja-no-eval :group! jakb-pilot-car-smack-back-ja :num! (seek!) :frame-num (ja-aframe 2.0 0))
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               )
              (else
                (ja-no-eval :group! jakb-pilot-car-smack-shock-ja :num! (seek!) :frame-num (ja-aframe 0.0 0))
                (until (ja-done? 0)
                  (suspend)
                  (ja :num! (seek!))
                  )
                )
              )
            )
          )
        ;; og:preserve-this
        (init-vf0-vector)
        (.svf (&-> (-> gp-0 accel-array) 0 quad) vf0)
        )
      (go target-pilot-stance)
      )
    )
  :post (behavior ()
    (target-pilot-post)
    )
  )

(let ((v1-9 (copy *empty-mods* 'loading-level)))
  (set! (-> v1-9 flags) (surface-flag))
  (set! *pilot-get-on-mods* v1-9)
  )

(defstate target-pilot-get-on (target)
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('end-mode)
       (cond
         ((focus-test? self pilot-riding)
          (go target-pilot-get-off)
          )
         (else
           (ja-channel-set! 0)
           (go target-falling #f)
           )
         )
       )
      (else
        (target-standard-event-handler proc argc message block)
        )
      )
    )
  :exit target-pilot-exit
  :trans (behavior ()
    (let* ((s5-0 (handle->process (-> self pilot vehicle)))
           (gp-0 (if (type? s5-0 vehicle)
                     s5-0
                     )
                 )
           )
      (cond
        ((not gp-0)
         (ja-channel-set! 0)
         (go target-falling #f)
         )
        ((focus-test? (the-as vehicle gp-0) dead)
         (go target-pilot-get-off)
         )
        (else
          (compute-seat-position (the-as vehicle gp-0) (-> self control unknown-vector38) (-> self pilot seat-index))
          (set! (-> self control unknown-vector40 quad) (-> (the-as vehicle gp-0) root quat quad))
          )
        )
      )
    )
  :code (behavior ()
    (logior! (-> self focus-status) (focus-status pilot))
    (logior! (-> self state-flags) (state-flags sf6))
    (set! (-> self alt-cam-pos quad) (-> self control camera-pos quad))
    (let ((gp-0 (if (zero? (-> self pilot stance))
                    jakb-pilot-bike-get-on-ja
                    jakb-pilot-car-get-on-ja
                    )
                )
          )
      (ja-channel-set! 1)
      (set! (-> self control mod-surface) *pilot-get-on-mods*)
      (send-event (ppointer->process (-> self manipy)) 'draw #t)
      (set! (-> self neck flex-blend) 0.0)
      (set! (-> self control unknown-vector37 quad) (-> self control trans quad))
      (set! (-> self control unknown-vector39 quad) (-> self control quat quad))
      (ja :group! gp-0 :num! (seek!) :frame-num 0.0)
      )
    (until (ja-done? 0)
      (let ((f30-0 (sin (lerp-scale 0.0 16384.0 (ja-aframe-num 0) 0.0 10.0))))
        (let ((f28-0 (lerp-scale 0.0 1.0 (ja-aframe-num 0) 0.0 10.0)))
          (vector-lerp!
            (-> self control trans)
            (-> self control unknown-vector37)
            (-> self control unknown-vector38)
            f30-0
            )
          (set! (-> self control trans y)
                (lerp (-> self control unknown-vector37 y) (-> self control unknown-vector38 y) f28-0)
                )
          )
        (quaternion-slerp!
          (-> self control quat-for-control)
          (the-as quaternion (-> self control unknown-vector39))
          (the-as quaternion (-> self control unknown-vector40))
          f30-0
          )
        )
      (rot->dir-targ! (-> self control))
      (if (>= (ja-aframe-num 0) 20.5)
          (target-pilot-signal-ready)
          )
      (suspend)
      (let ((a1-7 (handle->process (-> self pilot vehicle))))
        (if a1-7
            (set! (-> self alt-cam-pos quad) (-> (the-as vehicle a1-7) rbody state position quad))
            )
        )
      (ja :num! (seek!))
      )
    (go target-pilot-stance)
    )
  :post target-no-move-post
  )

(let ((v1-12 (copy *forward-jump-mods* 'loading-level)))
  (set! (-> v1-12 fric) 0.0)
  (set! (-> v1-12 nonlin-fric-dist) 0.0)
  (set! (-> v1-12 turnv) 0.0)
  (set! (-> v1-12 turnvv) 0.0)
  (set! (-> v1-12 tiltv) 131072.0)
  (set! (-> v1-12 tiltvf) 30.0)
  (set! (-> v1-12 mult-hook)
        (the-as
          (function surface surface surface int none)
          (lambda ((arg0 object) (arg1 object) (arg2 object) (arg3 int))
            (case arg3
              ((1)
               (persist-with-delay *setting-control* 'rapid-tracking (seconds 0.05) 'rapid-tracking #f 0.0 0)
               )
              )
            (none)
            )
          )
        )
  (set! *pilot-get-off-mods* v1-12)
  )

(defstate target-pilot-get-off (target)
  :event target-standard-event-handler
  :exit target-pilot-exit
  :trans (behavior ()
    (let ((gp-0 (handle->process (-> self pilot vehicle))))
      (when (not (if (type? gp-0 vehicle)
                     gp-0
                     )
                 )
        (ja-channel-set! 0)
        (go target-falling #f)
        )
      )
    )
  :code (behavior ()
    (local-vars (f30-0 float))
    (let ((v1-1 (-> self control root-prim)))
      (set! (-> v1-1 prim-core collide-as) (-> self control backup-collide-as))
      (set! (-> v1-1 prim-core collide-with) (-> self control backup-collide-with))
      )
    (logclear! (-> self focus-status) (focus-status pilot-riding))
    (set! (-> self control mod-surface) *pilot-get-off-mods*)
    (rot->dir-targ! (-> self control))
    (send-event *camera* 'set-dist #f #f)
    (set! (-> self neck flex-blend) 0.0)
    0.0
    (let ((gp-0 (cond
                  ((zero? (-> self pilot stance))
                   (set! f30-0 7.2)
                   jakb-pilot-bike-get-off-ja
                   )
                  (else
                    (set! f30-0 15.2)
                    jakb-pilot-car-get-off-ja
                    )
                  )
                )
          )
      (ja-channel-push! 1 (seconds 0.05))
      (ja-no-eval :group! gp-0 :num! (seek! (ja-aframe f30-0 0) 2.0) :frame-num 0.0)
      )
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! (ja-aframe f30-0 0) 2.0))
      )
    (let ((v1-29 (camera-matrix))
          (gp-2 (new 'stack-no-clear 'inline-array 'vector 10))
          )
      (set! (-> gp-2 0 quad) (-> v1-29 vector 0 quad))
      (set! (-> gp-2 1 quad) (-> v1-29 vector 2 quad))
      (set! (-> gp-2 1 y) 0.0)
      (vector-normalize! (-> gp-2 1) 1.0)
      (vector-reset! (-> gp-2 2))
      (vector+float*!
        (-> gp-2 2)
        (-> gp-2 2)
        (-> gp-2 0)
        (* 16384.0 (analog-input (the-as int (-> *cpad-list* cpads 0 leftx)) 128.0 48.0 110.0 -1.0))
        )
      (vector+float*!
        (-> gp-2 2)
        (-> gp-2 2)
        (-> gp-2 1)
        (* 16384.0 (analog-input (the-as int (-> *cpad-list* cpads 0 lefty)) 128.0 48.0 110.0 -1.0))
        )
      (vector+! (-> self control transv) (-> self control transv) (-> gp-2 2))
      )
    (go target-jump 10240.0 10240.0 *pilot-get-off-mods*)
    )
  :post target-pilot-post
  )

(defstate target-pilot-grab (target)
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (cond
      ((and (= message 'query) (= (-> block param 0) 'mode))
       (-> self state name)
       )
      (else
        (case message
          (('end-mode)
           (go target-pilot-stance)
           )
          (('clone-anim)
           (go target-pilot-clone-anim (process->handle (the-as process (-> block param 0))))
           )
          (('vehicle-crash)
           (go target-grab 'stance)
           )
          (else
            (target-generic-event-handler proc argc message block)
            )
          )
        )
      )
    )
  :enter (behavior ()
    (set! (-> self control mod-surface) *grab-mods*)
    (set! (-> self neck flex-blend) 0.0)
    (logior! (-> self state-flags) (state-flags sf2))
    (logior! (-> self focus-status) (focus-status grabbed))
    )
  :exit (behavior ()
    (logclear! (-> self state-flags) (state-flags sf2))
    (logclear! (-> self focus-status) (focus-status grabbed))
    (logclear! (-> self water flags) (water-flags jump-out))
    ((-> target-pilot-start exit))
    )
  :code (behavior ()
    (until #f
      (set-forward-vel 0.0)
      (suspend)
      )
    #f
    )
  :post target-pilot-post
  )

(defstate target-pilot-clone-anim (target)
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (if (and (= message 'trans) (= (-> block param 0) 'restore))
        (set! (-> self control unknown-word04) (the-as uint #f))
        )
    ((-> target-pilot-grab event) proc argc message block)
    )
  :enter (-> target-clone-anim enter)
  :exit (behavior ()
    (set! (-> self control draw-offset y) (the-as float (-> self control unknown-word04)))
    (set! (-> self control cspace-offset y) (-> self control draw-offset y))
    (send-event (ppointer->process (-> self sidekick)) 'matrix #f)
    ((-> target-clone-anim exit))
    ((-> target-pilot-start exit))
    (vector-reset! (-> self control transv))
    )
  :code (behavior ((arg0 handle))
    (set! (-> self control unknown-word04) (the-as uint (-> self control draw-offset y)))
    (set! (-> self control draw-offset y) 0.0)
    (send-event (ppointer->process (-> self sidekick)) 'matrix 'play-anim)
    (clone-anim arg0 #t "")
    (go target-pilot-stance)
    )
  :post (behavior ()
    (vector+! (-> self pilot pilot-trans) (-> self control trans) (-> self control cspace-offset))
    (quaternion-copy! (the-as quaternion (-> self pilot pilot-quat)) (-> self control quat))
    (set! (-> self pilot pilot-scale quad) (-> self control scale quad))
    (target-no-ja-move-post)
    )
  )

(defstate target-pilot-edge-grab (target)
  :event (-> target-edge-grab event)
  :enter (behavior ((arg0 pilot-edge-grab-info))
    (set! (-> self control status) (collide-status))
    (let ((gp-0 *edge-grab-info*))
      (mem-copy! (the-as pointer (-> gp-0 pilot-edge-grab)) (the-as pointer arg0) 40)
      (set! (-> gp-0 pilot-grab-interp) 0.0)
      (set! (-> gp-0 pilot-start-grab-pos quad) (-> self control trans quad))
      (set! (-> gp-0 actor-handle) (-> arg0 handle))
      ((-> target-edge-grab enter))
      (let* ((s5-1 (handle->process (-> gp-0 actor-handle)))
             (a0-9 (if (type? s5-1 process-focusable)
                       s5-1
                       )
                   )
             )
        (set! (-> gp-0 pilot-edge-grab?)
              (if (and a0-9
                       (< 24576.0 (fabs (- (-> (get-trans (the-as process-focusable a0-9) 0) y) (-> self control trans y))))
                       )
                  'target-double-jump
                  'target-jump
                  )
              )
        )
      )
    )
  :exit (-> target-edge-grab exit)
  :trans (-> target-edge-grab trans)
  :code (-> target-edge-grab code)
  :post target-no-move-post
  )

(defstate target-pilot-hit (target)
  :event target-generic-event-handler
  :exit (behavior ()
    (if (not (and (-> self next-state) (= (-> self next-state name) 'target-death)))
        (logclear! (-> self focus-status) (focus-status dead hit))
        )
    ((-> target-pilot-start exit))
    )
  :code (behavior ((arg0 symbol) (arg1 attack-info))
    (local-vars (sv-16 attack-info))
    (set-time! (-> self state-time))
    (set! (-> self neck flex-blend) 0.0)
    (set! sv-16 (-> self attack-info))
    (let ((v1-4 sv-16))
      (set! (-> v1-4 attacker) (the-as handle #f))
      (set! (-> v1-4 mode) 'generic)
      (set! (-> v1-4 shove-back) 6144.0)
      (set! (-> v1-4 shove-up) 4915.2)
      (set! (-> v1-4 angle) #f)
      (set! (-> v1-4 trans quad) (-> self control trans quad))
      (set! (-> v1-4 control) 0.0)
      (set! (-> v1-4 invinc-time) (the-as time-frame (-> *TARGET-bank* hit-invulnerable-timeout)))
      (set! (-> v1-4 damage) (-> *FACT-bank* health-default-inc))
      )
    (combine! sv-16 arg1 self)
    (pickup-collectable! (-> self fact) (pickup-type health) -1000.0 (the-as handle #f))
    (go target-pilot-death (-> sv-16 mode))
    )
  :post target-no-stick-post
  )

(defstate target-pilot-death (target)
  :event (-> target-death event)
  :exit (behavior ()
    ((-> target-pilot-start exit))
    ((-> target-death exit))
    )
  :code (behavior ((arg0 symbol))
    (set! (-> self control unknown-word04) (the-as uint #f))
    (set! (-> self control did-move-to-pole-or-max-jump-height)
          (the-as float (send-event (handle->process (-> self attack-info attacker)) 'target 'die arg0))
          )
    (set! (-> self neck flex-blend) 0.0)
    (target-timed-invulnerable-off self 0)
    (case arg0
      (('bot)
       (set-setting! 'process-mask 'set 0.0 (process-mask platform projectile death))
       )
      (('endlessfall 'instant-death 'lava 'dark-eco-pool 'melt 'explode 'grenade)
       (set-setting! 'process-mask 'set 0.0 (process-mask enemy platform projectile death))
       )
      (else
        (set-setting! 'process-mask 'set 0.0 (process-mask enemy platform projectile death))
        (when (using-gun? self)
          (send-event (ppointer->process (-> self gun gun)) 'die)
          (target-gun-end-mode #f)
          )
        )
      )
    (set-setting! 'mode-name 'cam-fixed 0.0 0)
    (set-setting! 'interp-time 'abs 0.0 0)
    (apply-settings *setting-control*)
    (set! (-> self control transv quad) (the-as uint128 0))
    (logior! (-> self focus-status) (focus-status dead))
    (case arg0
      (('melt 'grenade 'explode)
       (suspend-for (seconds 0.2))
       (case arg0
         (('dark-eco-pool)
          (sound-play "death-darkeco")
          (let ((s5-2 (get-process *default-dead-pool* part-tracker #x4000)))
            (when s5-2
              (let ((t9-14 (method-of-type part-tracker activate)))
                (t9-14
                  (the-as part-tracker s5-2)
                  *entity-pool*
                  (symbol->string (-> part-tracker symbol))
                  (the-as pointer #x70004000)
                  )
                )
              (let ((t9-15 run-function-in-process)
                    (a0-36 s5-2)
                    (a1-19 part-tracker-init)
                    (a2-11 (-> *part-group-id-table* 56))
                    (a3-7 0)
                    (t0-6 #f)
                    (t1-6 #f)
                    (t2-1 #f)
                    (t3-0 *launch-matrix*)
                    )
                (set! (-> t3-0 trans quad) (-> self control trans quad))
                ((the-as (function object object object object object object object object none) t9-15)
                 a0-36
                 a1-19
                 a2-11
                 a3-7
                 t0-6
                 t1-6
                 t2-1
                 t3-0
                 )
                )
              (-> s5-2 ppointer)
              )
            )
          )
         (('grenade 'explode)
          (sound-play "explosion")
          (let ((s5-4 (get-process *default-dead-pool* part-tracker #x4000)))
            (when s5-4
              (let ((t9-19 (method-of-type part-tracker activate)))
                (t9-19
                  (the-as part-tracker s5-4)
                  *entity-pool*
                  (symbol->string (-> part-tracker symbol))
                  (the-as pointer #x70004000)
                  )
                )
              (let ((t9-20 run-function-in-process)
                    (a0-45 s5-4)
                    (a1-24 part-tracker-init)
                    (a2-17 (-> *part-group-id-table* 58))
                    (a3-10 0)
                    (t0-8 #f)
                    (t1-8 #f)
                    (t2-3 #f)
                    (t3-1 *launch-matrix*)
                    )
                (set! (-> t3-1 trans quad) (-> self control trans quad))
                ((the-as (function object object object object object object object object none) t9-20)
                 a0-45
                 a1-24
                 a2-17
                 a3-10
                 t0-8
                 t1-8
                 t2-3
                 t3-1
                 )
                )
              (-> s5-4 ppointer)
              )
            )
          )
         (('lava 'melt)
          (sound-play "death-melt")
          (let ((s5-6 (get-process *default-dead-pool* part-tracker #x4000)))
            (when s5-6
              (let ((t9-24 (method-of-type part-tracker activate)))
                (t9-24
                  (the-as part-tracker s5-6)
                  *entity-pool*
                  (symbol->string (-> part-tracker symbol))
                  (the-as pointer #x70004000)
                  )
                )
              (let ((t9-25 run-function-in-process)
                    (a0-52 s5-6)
                    (a1-29 part-tracker-init)
                    (a2-23 (-> *part-group-id-table* 57))
                    (a3-13 0)
                    (t0-10 #f)
                    (t1-10 #f)
                    (t2-5 #f)
                    (t3-2 *launch-matrix*)
                    )
                (set! (-> t3-2 trans quad) (-> self control trans quad))
                ((the-as (function object object object object object object object object none) t9-25)
                 a0-52
                 a1-29
                 a2-23
                 a3-13
                 t0-10
                 t1-10
                 t2-5
                 t3-2
                 )
                )
              (-> s5-6 ppointer)
              )
            )
          )
         )
       (let ((v1-73 (-> self control root-prim)))
         (set! (-> v1-73 prim-core collide-as) (collide-spec))
         (set! (-> v1-73 prim-core collide-with) (collide-spec))
         )
       0
       (ja-channel-set! 0)
       (suspend-for (seconds 1.8))
       )
      (('endlessfall)
       (sound-play "death-fall")
       (if (not (-> self pilot as-daxter?))
           (set! (-> self control unknown-sound-id00)
                 (add-process *gui-control* *target* (gui-channel daxter) (gui-action play) "jakfall" -99.0 0)
                 )
           )
       (set-falloff! *gui-control* (-> self control unknown-sound-id00) #t -1 100 2)
       (logclear! (-> self water flags) (water-flags swim-ground))
       (let ((f0-2 (fmin -4096.0 (- (-> self control ground-impact-vel)))))
         (set! (-> self control unknown-word04) (the-as uint f0-2))
         (let ((v1-94 (new-stack-vector0)))
           (let ((f1-3 (vector-dot (-> self control dynam gravity-normal) (-> self control transv))))
             0.0
             (vector-! v1-94 (-> self control transv) (vector-float*! v1-94 (-> self control dynam gravity-normal) f1-3))
             )
           (let* ((f1-4 (vector-length v1-94))
                  (f2-1 f1-4)
                  )
             (vector+!
               (-> self control transv)
               (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f0-2)
               (vector-float*! v1-94 v1-94 (/ f1-4 f2-1))
               )
             )
           )
         )
       (suspend-for (seconds 0.5))
       )
      (('bot)
       (set! (-> self trans-hook) #f)
       (while (not (-> self control unknown-spool-anim00))
         (set-forward-vel 0.0)
         (suspend)
         )
       )
      (else
        )
      )
    (target-death-reset arg0 #f)
    )
  :post target-pilot-post
  )
