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

;; failed to figure out what this is:
(defstate target-load-wait (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('loading)
       (set! (-> self state-time) (-> *display* base-frame-counter))
       #f
       )
      (else
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :exit target-exit
  :code (behavior ()
    (set! (-> self control unknown-surface00) *walk-no-turn-mods*)
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (while (< (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.05))
      (ja-channel-push! 1 (seconds 0.1))
      (ja-no-eval :group! eichar-trip-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (compute-alignment! (-> self align))
        (align! (-> self align) (align-opts adjust-xz-vel) (the-as float 1.0) (the-as float 1.0) (the-as float 1.0))
        (send-event *camera* 'joystick 0.0 0.0)
        (suspend)
        (ja :num! (seek!))
        )
      (let ((gp-0 (-> *display* base-frame-counter)))
        (until (>= (- (-> *display* base-frame-counter) gp-0) (seconds 0.3))
          (suspend)
          (ja :num! (seek! (ja-aframe (the-as float 19.0) 0) 0.05))
          (suspend)
          )
        )
      (ja-channel-push! 1 (seconds 0.3))
      (ja-no-eval :group! eichar-painful-land-ja :num! (seek!) :frame-num (ja-aframe (the-as float 40.0) 0))
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      (ja-no-eval :group! eichar-painful-land-end-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (go target-stance)
    (none)
    )
  :post target-no-stick-post
  )

;; failed to figure out what this is:
(defstate target-stance-ambient (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('movie)
       (go target-stance)
       )
      (else
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :enter (behavior ()
    (set! (-> self neck flex-blend) 0.0)
    ((-> target-stance enter))
    (let ((v1-2 (rand-vu-int-count 4)))
      (cond
        ((zero? v1-2)
         (set! (-> self control unknown-uint20)
               (the-as uint (new 'static 'spool-anim :name "eichar-ambient-1" :index #xe7 :parts 1 :command-list '()))
               )
         )
        ((= v1-2 1)
         (set! (-> self control unknown-uint20)
               (the-as uint (new 'static 'spool-anim :name "eichar-ambient-2" :index #xe8 :parts 1 :command-list '()))
               )
         )
        ((= v1-2 2)
         (set! (-> self control unknown-uint20)
               (the-as uint (new 'static 'spool-anim :name "eichar-ambient-3" :index #xe9 :parts 1 :command-list '()))
               )
         )
        (else
          (set! (-> self control unknown-uint20)
                (the-as uint (new 'static 'spool-anim :name "eichar-ambient-4" :index #xea :parts 1 :command-list '()))
                )
          )
        )
      )
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (none)
    )
  :exit (behavior ()
    (let ((a0-0 (-> self control unknown-spoolanim00)))
      (when a0-0
        (ja-abort-spooled-anim a0-0 (the-as art-joint-anim #f) -1)
        (ja-channel-set! 1)
        (ja :group! eichar-stance-loop-ja :num! min)
        )
      )
    ((-> target-stance exit))
    (target-exit)
    (none)
    )
  :trans (behavior ()
    (spool-push *art-control* (-> self control unknown-spoolanim00 name) 0 self (the-as float -99.0))
    (if (or (cpad-hold? (-> self control unknown-cpad-info00 number) start l1 r1 triangle circle x square)
            *progress-process*
            )
        (go target-stance)
        )
    (none)
    )
  :code (behavior ()
    (while (let ((v1-13 (file-status *art-control* (-> self control unknown-spoolanim00 name) 0)))
             (not (or (= v1-13 'locked) (= v1-13 'active)))
             )
      (suspend)
      (ja :num! (loop!))
      (ja :chan 1 :num! (chan 0))
      (ja :chan 2 :num! (chan 0))
      )
    (ja-play-spooled-anim
      (-> self control unknown-spoolanim00)
      (the-as art-joint-anim eichar-stance-loop-ja)
      (the-as art-joint-anim eichar-stance-loop-ja)
      (the-as (function process-drawable symbol) (lambda () (!= (-> *cpad-list* cpads 0 stick0-speed) 0.0)))
      )
    (set! (-> self control unknown-uint20) (the-as uint #f))
    (go target-stance)
    (none)
    )
  :post target-post
  )

;; definition of type first-person-hud
(deftype first-person-hud (process)
  ((max-nb-of-particles int32          :offset-assert 112)
   (nb-of-particles     int32          :offset-assert 116)
   (particles           hud-particle 3 :offset-assert 120)
   (in-out-position     int32          :offset-assert 132)
   (sides-x-scale       float          :offset-assert 136)
   (sides-y-scale       float          :offset-assert 140)
   (x-offset            int32          :offset-assert 144)
   )
  :heap-base #x30
  :method-count-assert 15
  :size-assert         #x94
  :flag-assert         #xf00300094
  (:methods
    (dumb-15 (_type_) none 14)
    )
  (:states
    hud-coming-in
    hud-going-out
    hud-normal
    hud-waiting
    )
  )

;; definition for method 3 of type first-person-hud
(defmethod inspect first-person-hud ((obj first-person-hud))
  (let ((t9-0 (method-of-type process inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tmax-nb-of-particles: ~D~%" (-> obj max-nb-of-particles))
  (format #t "~T~Tnb-of-particles: ~D~%" (-> obj nb-of-particles))
  (format #t "~T~Tparticles[3] @ #x~X~%" (-> obj particles))
  (format #t "~T~Tin-out-position: ~D~%" (-> obj in-out-position))
  (format #t "~T~Tsides-x-scale: ~f~%" (-> obj sides-x-scale))
  (format #t "~T~Tsides-y-scale: ~f~%" (-> obj sides-y-scale))
  (format #t "~T~Tx-offset: ~D~%" (-> obj x-offset))
  obj
  )

;; definition for symbol *fp-hud-stack*, type pointer
(define *fp-hud-stack* (malloc 'global #x3800))

;; definition for method 10 of type first-person-hud
(defmethod deactivate first-person-hud ((obj first-person-hud))
  (dotimes (s5-0 (-> obj nb-of-particles))
    (kill-and-free-particles (-> obj particles s5-0 part))
    (set! (-> obj particles s5-0 part matrix) -1)
    )
  (enable-hud)
  (set! (-> *target* fp-hud) (the-as handle #f))
  ((the-as (function process none) (find-parent-method first-person-hud 10)) obj)
  (none)
  )

;; definition for function first-person-hud-init-by-other
;; INFO: Return type mismatch object vs none.
(defbehavior first-person-hud-init-by-other first-person-hud ()
  (logclear! (-> self mask) (process-mask pause))
  (set! (-> self nb-of-particles) 0)
  (set! (-> self max-nb-of-particles) 3)
  (set! (-> self in-out-position) 4096)
  (when (< (-> self nb-of-particles) (-> self max-nb-of-particles))
    (let ((gp-0 (-> self nb-of-particles)))
      (set! (-> self particles gp-0) (new 'static 'hud-particle))
      (set! (-> self particles gp-0 part) (create-launch-control (-> *part-group-id-table* 611) self))
      (set! (-> self particles gp-0 init-pos x) -320.0)
      (set! (-> self particles gp-0 init-pos y) 254.0)
      (set! (-> self particles gp-0 init-pos z) 15.0)
      (set! (-> self particles gp-0 part matrix) -1)
      )
    (+! (-> self nb-of-particles) 1)
    )
  (when (< (-> self nb-of-particles) (-> self max-nb-of-particles))
    (let ((gp-1 (-> self nb-of-particles)))
      (set! (-> self particles gp-1) (new 'static 'hud-particle))
      (set! (-> self particles gp-1 part) (create-launch-control (-> *part-group-id-table* 612) self))
      (set! (-> self particles gp-1 init-pos x) -320.0)
      (set! (-> self particles gp-1 init-pos y) 192.0)
      (set! (-> self particles gp-1 init-pos z) 15.0)
      (set! (-> self particles gp-1 part matrix) -1)
      )
    (+! (-> self nb-of-particles) 1)
    )
  (when (< (-> self nb-of-particles) (-> self max-nb-of-particles))
    (let ((gp-2 (-> self nb-of-particles)))
      (set! (-> self particles gp-2) (new 'static 'hud-particle))
      (set! (-> self particles gp-2 part) (create-launch-control (-> *part-group-id-table* 613) self))
      (set! (-> self particles gp-2 init-pos x) 256.0)
      (set! (-> self particles gp-2 init-pos y) 244.0)
      (set! (-> self particles gp-2 init-pos z) 15.0)
      (set! (-> self particles gp-2 part matrix) -1)
      )
    (+! (-> self nb-of-particles) 1)
    )
  (case (get-aspect-ratio)
    (('aspect4x3)
     (set! (-> self sides-x-scale) 3.5)
     (set! (-> self sides-y-scale) 13.0)
     (set! (-> self x-offset) 0)
     0
     )
    (('aspect16x9)
     (set! (-> self sides-x-scale) 2.8)
     (set! (-> self sides-y-scale) 9.75)
     (set! (-> self x-offset) 12)
     )
    )
  (set! (-> self event-hook) (-> hud-waiting event))
  (go hud-waiting)
  (none)
  )

;; definition for method 7 of type first-person-hud
;; INFO: Return type mismatch process vs first-person-hud.
(defmethod relocate first-person-hud ((obj first-person-hud) (arg0 int))
  (dotimes (v1-0 (-> obj nb-of-particles))
    (when (-> obj particles v1-0 part)
      (if (nonzero? (-> obj particles v1-0 part))
          (&+! (-> obj particles v1-0 part) arg0)
          )
      )
    )
  (the-as first-person-hud ((method-of-type process relocate) obj arg0))
  )

;; definition for method 14 of type first-person-hud
;; INFO: Return type mismatch int vs none.
(defmethod dumb-15 first-person-hud ((obj first-person-hud))
  (dotimes (s5-0 (-> obj nb-of-particles))
    (set! (-> obj particles s5-0 pos x) (+ -256.0 (-> obj particles s5-0 init-pos x)))
    (set! (-> obj particles s5-0 pos y)
          (* 0.5 (- (* (-> obj particles s5-0 init-pos y) (-> *video-parms* relative-y-scale))
                    (the float (-> *video-parms* screen-sy))
                    )
             )
          )
    (set! (-> obj particles s5-0 pos z) (-> obj particles s5-0 init-pos z))
    (if (> (-> obj particles s5-0 part matrix) 0)
        (set-vector!
          (sprite-get-user-hvdf (-> obj particles s5-0 part matrix))
          (the float (+ (the int (-> obj particles s5-0 pos x)) 2048))
          (the float (+ (the int (-> obj particles s5-0 pos y)) 2048))
          (- (-> *math-camera* hvdf-off z) (* 1024.0 (-> obj particles s5-0 pos z)))
          (-> *math-camera* hvdf-off w)
          )
        )
    (spawn (-> obj particles s5-0 part) *null-vector*)
    )
  0
  (none)
  )

;; failed to figure out what this is:
(defstate hud-waiting (first-person-hud)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('go-away)
       (go hud-going-out)
       )
      )
    )
  :enter (behavior ()
    (disable-hud (the-as int (-> *hud-parts* power)))
    (none)
    )
  :code (behavior ()
    (loop
      (dotimes (gp-0 (-> self nb-of-particles))
        (if (= (-> self particles gp-0 part matrix) -1)
            (set! (-> self particles gp-0 part matrix) (sprite-allocate-user-hvdf))
            )
        )
      (set-setting! 'common-page 'set 0.0 1)
      (suspend)
      (go hud-coming-in)
      (suspend)
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate hud-coming-in (first-person-hud)
  :event (-> hud-waiting event)
  :code (behavior ()
    (loop
      (seekl! (-> self in-out-position) 0 (the int (* 350.0 (-> *display* time-adjust-ratio))))
      (if (zero? (-> self in-out-position))
          (go hud-normal)
          )
      (suspend)
      )
    (none)
    )
  :post (behavior ()
    (dumb-15 self)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate hud-normal (first-person-hud)
  :event (-> hud-waiting event)
  :code (behavior ()
    (loop
      (if (or (not *progress-process*)
              (= (-> *progress-process* 0 next-state name) 'progress-going-out)
              (= (-> *progress-process* 0 next-state name) 'progress-gone)
              )
          (seekl! (-> self in-out-position) 0 (the int (* 150.0 (-> *display* time-adjust-ratio))))
          (seekl! (-> self in-out-position) 4096 (the int (* 200.0 (-> *display* time-adjust-ratio))))
          )
      (suspend)
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate hud-going-out (first-person-hud)
  :code (behavior ()
    (loop
      (seekl! (-> self in-out-position) 4096 (the int (* 350.0 (-> *display* time-adjust-ratio))))
      (if (= (-> self in-out-position) 4096)
          (deactivate self)
          )
      (suspend)
      )
    (none)
    )
  :post (behavior ()
    (dumb-15 self)
    (none)
    )
  )

;; definition for function part-first-person-hud-left-func
;; INFO: Return type mismatch int vs none.
(defun part-first-person-hud-left-func ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 matrix))
  (let ((s5-0 (handle->process (-> *target* fp-hud))))
    (when s5-0
      (let ((f30-0 (* 0.00024414062 (the float (-> (the-as first-person-hud s5-0) in-out-position)))))
        (if (or (-> *setting-control* current movie) (movie?))
            (set! f30-0 1.0)
            )
        (if (< 0.25 f30-0)
            (set! f30-0 1.0)
            (* 4.0 f30-0)
            )
        (set! (-> (the-as first-person-hud s5-0) particles 0 init-pos x)
              (the float (- 59 (-> (the-as first-person-hud s5-0) x-offset)))
              )
        (set! (-> arg2 vector 0 w) (* 4096.0 (+ (-> (the-as first-person-hud s5-0) sides-x-scale) (* 10.0 f30-0))))
        (set! (-> arg2 vector 1 w) (* 4096.0 (+ (-> (the-as first-person-hud s5-0) sides-y-scale) (* 10.0 f30-0))))
        )
      )
    )
  0
  (none)
  )

;; definition for function part-first-person-hud-right-func
;; INFO: Return type mismatch int vs none.
(defun part-first-person-hud-right-func ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 matrix))
  (let ((s5-0 (handle->process (-> *target* fp-hud))))
    (when s5-0
      (let ((f30-0 (* 0.00024414062 (the float (-> (the-as first-person-hud s5-0) in-out-position)))))
        (if (or (-> *setting-control* current movie) (movie?))
            (set! f30-0 1.0)
            )
        (if (< 0.25 f30-0)
            (set! f30-0 1.0)
            (* 4.0 f30-0)
            )
        (set! (-> (the-as first-person-hud s5-0) particles 1 init-pos x)
              (the float (+ (-> (the-as first-person-hud s5-0) x-offset) 452))
              )
        (set! (-> arg2 vector 0 w) (* 4096.0 (+ (-> (the-as first-person-hud s5-0) sides-x-scale) (* 10.0 f30-0))))
        (set! (-> arg2 vector 1 w) (* 4096.0 (+ (-> (the-as first-person-hud s5-0) sides-y-scale) (* 10.0 f30-0))))
        )
      )
    )
  0
  (none)
  )

;; definition for function part-first-person-hud-selector-func
;; INFO: Return type mismatch int vs none.
(defun part-first-person-hud-selector-func ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 matrix))
  (let ((v1-2 (handle->process (-> *target* fp-hud))))
    (when v1-2
      (let ((f30-0 (* 0.00024414062 (the float (-> (the-as first-person-hud v1-2) in-out-position)))))
        (if (or (-> *setting-control* current movie) (movie?))
            (set! f30-0 1.0)
            )
        (if (< 0.5 f30-0)
            (set! f30-0 1.0)
            (* 2.0 f30-0)
            )
        (set! (-> arg2 vector 2 w) (- 64.0 (* 64.0 f30-0)))
        )
      )
    )
  0
  (none)
  )

;; definition for function look-for-points-of-interest
;; ERROR: function was not converted to expressions. Cannot decompile.

;; failed to figure out what this is:
(defstate target-stance-look-around (target)
  :event target-standard-event-handler
  :enter (-> target-stance enter)
  :exit (-> target-stance exit)
  :trans (-> target-stance trans)
  :code (behavior ()
    (while (let ((a1-0 (new 'stack-no-clear 'event-message-block)))
             (set! (-> a1-0 from) self)
             (set! (-> a1-0 num-params) 0)
             (set! (-> a1-0 message) 'dist-from-interp-src)
             (and (< (send-event-function *camera* a1-0) 4915.2)
                  (< (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.07))
                  (zero? (ja-group-size))
                  )
             )
      (suspend)
      )
    (let ((v1-8 target-stance))
      (set! (-> self next-state) v1-8)
      (set! (-> self state) v1-8)
      )
    ((the-as (function none :behavior target) (-> target-stance code)))
    (none)
    )
  :post target-post
  )

;; failed to figure out what this is:
(defstate target-look-around (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (cond
      ((and (= arg2 'query) (= (-> arg3 param 0) 'mode))
       (-> self state name)
       )
      ((let ((v1-4 arg2))
         (= v1-4 'end-mode)
         )
       (go target-stance-look-around)
       )
      ((-> self control unknown-symbol30)
       (target-dangerous-event-handler arg0 arg1 arg2 arg3)
       )
      (else
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :enter (behavior ()
    (set! (-> self cam-user-mode) 'look-around)
    (set! (-> self control unknown-surface00) *duck-mods*)
    (logior! (-> self state-flags) (state-flags first-person-mode))
    (send-event *camera* 'blend-from-as-fixed)
    (send-event *camera* 'no-intro)
    (camera-change-to (the-as string 'cam-eye) 60 #f)
    (let ((a0-5 (handle->process (-> self fp-hud))))
      (if a0-5
          (deactivate a0-5)
          )
      )
    (set! (-> self fp-hud)
          (ppointer->handle (process-spawn first-person-hud :to *dproc* :stack (&+ *fp-hud-stack* #x3800)))
          )
    (none)
    )
  :exit (behavior ()
    (let ((a0-1 (handle->process (-> self fp-hud))))
      (if a0-1
          (send-event a0-1 'go-away)
          )
      )
    (set! (-> self cam-user-mode) 'normal)
    (target-exit)
    (when (send-event *camera* 'query-state cam-eye)
      (send-event *camera* 'no-intro)
      (send-event *camera* 'force-blend (seconds 0.2))
      (send-event *camera* 'clear-entity)
      (camera-change-to (the-as string 'base) 60 #f)
      )
    (none)
    )
  :trans (behavior ()
    (local-vars (sv-48 vector))
    (rlet ((vf0 :class vf)
           (vf4 :class vf)
           (vf5 :class vf)
           (vf6 :class vf)
           )
      (init-vf0-vector)
      (when (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                           (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                           )
                                   (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                                   )
                           (pad-buttons r2 circle square)
                           )
                 (and (= (-> self fact-info-target eco-type) (pickup-type eco-yellow))
                      (>= (-> self fact-info-target eco-level) 1.0)
                      )
                 (>= (- (-> *display* base-frame-counter) (-> self control unknown-dword82)) (seconds 0.5))
                 (not *pause-lock*)
                 )
        (let ((gp-1 (vector-float*!
                      (new-stack-vector0)
                      (-> *math-camera* inv-camera-rot vector 2)
                      (the-as float (-> *TARGET-bank* yellow-projectile-speed))
                      )
                    )
              (s5-1 (vector-float*! (new-stack-vector0) (-> *math-camera* inv-camera-rot vector 2) 8192.0))
              )
          (vector+float*! s5-1 s5-1 (-> *math-camera* inv-camera-rot vector 1) (the-as float -2048.0))
          (let ((s4-0 (get-process *default-dead-pool* projectile-yellow #x4000)))
            (when s4-0
              (let ((t9-2 (method-of-type projectile-yellow activate)))
                (t9-2 (the-as projectile-yellow s4-0) self 'projectile-yellow (the-as pointer #x70004000))
                )
              (let ((s3-0 run-function-in-process)
                    (s2-0 s4-0)
                    (s1-0 projectile-init-by-other)
                    (s0-0 (-> self entity))
                    )
                (set! sv-48 s5-1)
                (let ((v0-3 (camera-pos)))
                  (.mov.vf vf6 vf0 :mask #b1000)
                  (.lvf vf4 (&-> v0-3 quad))
                  )
                (.lvf vf5 (&-> s5-1 quad))
                (.add.vf vf6 vf4 vf5 :mask #b111)
                (.svf (&-> sv-48 quad) vf6)
                (let ((t1-0 (if (>= (-> self fact-info-target eco-level) (-> *FACT-bank* eco-level-max))
                                56
                                40
                                )
                            )
                      (t2-0 #f)
                      )
                  ((the-as (function object object object object object object object none) s3-0)
                   s2-0
                   s1-0
                   s0-0
                   sv-48
                   gp-1
                   t1-0
                   t2-0
                   )
                  )
                )
              (-> s4-0 ppointer)
              )
            )
          )
        (set! (-> self control unknown-dword82) (-> *display* base-frame-counter))
        )
      (when (cpad-pressed? (-> self control unknown-cpad-info00 number) triangle)
        (logclear!
          (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-abs 0)
          (pad-buttons triangle)
          )
        (logclear!
          (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
          (pad-buttons triangle)
          )
        (set! (-> self cam-user-mode) 'normal)
        )
      (none)
      )
    )
  :code (behavior ()
    (while (let ((f30-0 8192.0))
             (< f30-0 (send-event *camera* 'dist-from-interp-dest))
             )
      (if (!= (-> self cam-user-mode) 'look-around)
          (go target-stance)
          )
      (suspend)
      )
    (ja-channel-set! 0)
    (set! (-> self control transv quad) (the-as uint128 0))
    (loop
      (if (!= (-> self cam-user-mode) 'look-around)
          (go target-stance-look-around)
          )
      (suspend)
      )
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-billy-game (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (cond
      ((and (= arg2 'query) (= (-> arg3 param 0) 'mode))
       (-> self state name)
       )
      ((let ((v1-4 arg2))
         (= v1-4 'end-mode)
         )
       (go target-stance)
       )
      (else
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :enter (behavior ()
    (set! (-> self neck flex-blend) 0.0)
    (set! (-> self control unknown-surface00) *duck-mods*)
    (logior! (-> self state-flags) (state-flags first-person-mode))
    (send-event *camera* 'blend-from-as-fixed)
    (send-event *camera* 'clear-entity)
    (send-event *camera* 'no-intro)
    (camera-change-to (the-as string 'cam-billy) 0 #f)
    (let ((a0-6 (handle->process (-> self fp-hud))))
      (if a0-6
          (deactivate a0-6)
          )
      )
    (set! (-> self fp-hud)
          (ppointer->handle (process-spawn first-person-hud :to *dproc* :stack (&+ *fp-hud-stack* #x3800)))
          )
    (none)
    )
  :exit (behavior ()
    (let ((a0-1 (handle->process (-> self fp-hud))))
      (if a0-1
          (send-event a0-1 'go-away)
          )
      )
    (when (send-event *camera* 'query-state cam-billy)
      (send-event *camera* 'no-intro)
      (send-event *camera* 'force-blend 0)
      (camera-change-to (the-as string 'base) 0 #f)
      )
    (target-exit)
    (none)
    )
  :trans (behavior ()
    (local-vars (sv-48 vector))
    (rlet ((vf0 :class vf)
           (vf4 :class vf)
           (vf5 :class vf)
           (vf6 :class vf)
           )
      (init-vf0-vector)
      (when (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                           (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                           )
                                   (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                                   )
                           (pad-buttons r2 circle square)
                           )
                 (>= (- (-> *display* base-frame-counter) (-> self control unknown-dword82)) (seconds 0.45))
                 (and (= (-> self fact-info-target eco-type) (pickup-type eco-yellow))
                      (>= (-> self fact-info-target eco-level) 1.0)
                      )
                 (not *pause-lock*)
                 )
        (let ((gp-1 (vector-float*!
                      (new-stack-vector0)
                      (-> *math-camera* inv-camera-rot vector 2)
                      (the-as float (-> *TARGET-bank* yellow-projectile-speed))
                      )
                    )
              (s5-1 (vector-float*! (new-stack-vector0) (-> *math-camera* inv-camera-rot vector 2) 8192.0))
              )
          (vector+float*! s5-1 s5-1 (-> *math-camera* inv-camera-rot vector 1) (the-as float -2048.0))
          (let ((s4-0 (get-process *default-dead-pool* projectile-yellow #x4000)))
            (when s4-0
              (let ((t9-2 (method-of-type projectile-yellow activate)))
                (t9-2 (the-as projectile-yellow s4-0) self 'projectile-yellow (the-as pointer #x70004000))
                )
              (let ((s3-0 run-function-in-process)
                    (s2-0 s4-0)
                    (s1-0 projectile-init-by-other)
                    (s0-0 (-> self entity))
                    )
                (set! sv-48 s5-1)
                (let ((v0-4 (camera-pos)))
                  (.mov.vf vf6 vf0 :mask #b1000)
                  (.lvf vf4 (&-> v0-4 quad))
                  )
                (.lvf vf5 (&-> s5-1 quad))
                (.add.vf vf6 vf4 vf5 :mask #b111)
                (.svf (&-> sv-48 quad) vf6)
                (let ((t1-0 (if (>= (-> self fact-info-target eco-level) (-> *FACT-bank* eco-level-max))
                                120
                                104
                                )
                            )
                      (t2-0 #f)
                      )
                  ((the-as (function object object object object object object object none) s3-0)
                   s2-0
                   s1-0
                   s0-0
                   sv-48
                   gp-1
                   t1-0
                   t2-0
                   )
                  )
                )
              (-> s4-0 ppointer)
              )
            )
          )
        (set! (-> self control unknown-dword82) (-> *display* base-frame-counter))
        )
      (none)
      )
    )
  :code (behavior ()
    (ja-channel-set! 0)
    (set! (-> self control transv quad) (the-as uint128 0))
    (anim-loop)
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-grab (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (cond
      ((and (= arg2 'query) (= (-> arg3 param 0) 'mode))
       (-> self state name)
       )
      (else
        (case arg2
          (('end-mode)
           (go target-stance)
           )
          (('play-anim)
           (let ((v0-0 (the-as object (-> arg3 param 0))))
             (set! (-> self control unknown-uint20) (the-as uint v0-0))
             v0-0
             )
           )
          (('clone-anim)
           (go target-clone-anim (process->handle (the-as process (-> arg3 param 0))))
           )
          (('change-mode)
           (case (-> arg3 param 0)
             (('final-door)
              (go
                target-final-door
                (the-as basic (process->handle (the-as process (-> arg3 param 1))))
                (process->handle (the-as process (-> arg3 param 2)))
                )
              )
             )
           )
          (else
            (target-generic-event-handler arg0 arg1 arg2 arg3)
            )
          )
        )
      )
    )
  :enter (behavior ()
    (set! (-> self control unknown-surface00) *grab-mods*)
    (set! (-> self neck flex-blend) 0.0)
    (logior! (-> self state-flags) (state-flags invulnerable grabbed))
    (set! (-> self control unknown-uint20) (the-as uint 'stance))
    (none)
    )
  :exit (behavior ()
    (logclear! (-> self state-flags) (state-flags invulnerable))
    (target-exit)
    (none)
    )
  :code (behavior ()
    (set-forward-vel (the-as float 0.0))
    (let ((gp-0 0))
      (while (zero? (logand (-> self control status) (cshape-moving-flags onsurf)))
        (target-falling-anim-trans)
        (+! gp-0 (- (-> *display* base-frame-counter) (-> *display* old-base-frame-counter)))
        (suspend)
        )
      (if (or (> gp-0 0) (let ((v1-11 (ja-group)))
                           (or (= v1-11 eichar-jump-ja)
                               (= v1-11 eichar-jump-loop-ja)
                               (= v1-11 eichar-launch-jump-ja)
                               (= v1-11 eichar-launch-jump-loop-ja)
                               (= v1-11 eichar-duck-high-jump-ja)
                               )
                           )
              )
          (target-hit-ground-anim #f)
          )
      )
    (-> self control unknown-spoolanim00)
    (loop
      (let ((gp-1 (-> self control unknown-spoolanim00)))
        (case gp-1
          (('stance)
           (cond
             ((or (and (ja-group? eichar-walk-ja) (< 0.5 (-> self skel root-channel 6 frame-interp)))
                  (let ((v1-32 (ja-group)))
                    (or (= v1-32 eichar-run-squash-ja)
                        (= v1-32 eichar-run-squash-weak-ja)
                        (= v1-32 eichar-attack-from-stance-run-end-ja)
                        (= v1-32 eichar-attack-from-stance-run-alt-end-ja)
                        )
                    )
                  )
              (ja-channel-push! 1 (seconds 0.15))
              (ja-no-eval :group! eichar-run-to-stance-loop-ja :num! (seek!) :frame-num 0.0)
              (until (ja-done? 0)
                (suspend)
                (ja :num! (seek!))
                )
              (ja-no-eval :group! eichar-run-to-stance-ja :num! (seek!) :frame-num 0.0)
              (until (ja-done? 0)
                (suspend)
                (ja :num! (seek!))
                )
              (ja-channel-push! 1 (seconds 0.15))
              )
             ((let ((v1-87 (ja-group)))
                (and (or (= v1-87 eichar-jump-short-land-ja) (= v1-87 eichar-jump-land-ja)) (not (ja-max? 0)))
                )
              (ja-no-eval :num! (seek!))
              (while (not (ja-done? 0))
                (suspend)
                (ja-eval)
                )
              (ja-channel-push! 1 (seconds 0.075))
              )
             ((not (and (ja-group? eichar-stance-loop-ja) (= (ja-group-size) 1)))
              (ja-channel-push! 1 (seconds 0.075))
              )
             )
           (loop
             (ja-no-eval :group! eichar-stance-loop-ja :num! (seek!) :frame-num 0.0)
             (until (ja-done? 0)
               (if (!= gp-1 (-> self control unknown-spoolanim00))
                   (goto cfg-94)
                   )
               (suspend)
               (ja :num! (seek!))
               )
             )
           )
          (('shock-in)
           (ja-channel-push! 1 (seconds 0.2))
           (ja-no-eval :group! eichar-shocked-ja :num! (seek! (ja-aframe (the-as float 18.0) 0)) :frame-num 0.0)
           (until (ja-done? 0)
             (if (!= gp-1 (-> self control unknown-spoolanim00))
                 (goto cfg-94)
                 )
             (suspend)
             (ja :num! (seek! (ja-aframe (the-as float 18.0) 0)))
             )
           (loop
             (if (!= gp-1 (-> self control unknown-spoolanim00))
                 (goto cfg-94)
                 )
             (suspend)
             )
           )
          (('shock-out)
           (if (not (ja-group? eichar-shocked-ja))
               (ja-channel-push! 1 (seconds 0.2))
               )
           (ja-no-eval :group! eichar-shocked-ja :num! (seek!) :frame-num (ja-aframe (the-as float 18.0) 0))
           (until (ja-done? 0)
             (if (!= gp-1 (-> self control unknown-spoolanim00))
                 (goto cfg-94)
                 )
             (suspend)
             (ja :num! (seek!))
             )
           (set! (-> self control unknown-uint20) (the-as uint 'stance))
           )
          )
        )
      (label cfg-94)
      )
    (none)
    )
  :post (behavior ()
    (if (logtest? (-> self control status) (cshape-moving-flags onsurf))
        (set! (-> self control transv quad) (the-as uint128 0))
        )
    (target-no-stick-post)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate target-pole-cycle (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (if (and (= arg2 'query) (= (-> arg3 param 0) 'mode))
        (-> self state name)
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
    )
  :enter (behavior ((arg0 handle))
    (set! (-> self control unknown-handle10) arg0)
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self control unknown-surface00) *pole-mods*)
    (logior! (-> self control root-prim prim-core action) (collide-action ca-8))
    (target-collide-set! 'pole (the-as float 0.0))
    (set! (-> self control unknown-vector102 quad) (-> self control transv quad))
    (set! (-> self control transv quad) (the-as uint128 0))
    (send-event *camera* 'ease-in)
    (set! (-> self control unknown-int21) (the-as int #f))
    (none)
    )
  :exit (behavior ()
    (target-collide-set! 'normal (the-as float 0.0))
    (logclear! (-> self control root-prim prim-core action) (collide-action ca-8))
    (set! (-> self control unknown-handle10) (the-as handle #f))
    (none)
    )
  :trans (behavior ()
    (when (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                         (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                         )
                                 (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                                 )
                         (pad-buttons x)
                         )
               (zero? (logand (-> self state-flags) (state-flags prevent-jump)))
               (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.1))
               )
      (set! (-> self control transv quad) (the-as uint128 0))
      (cond
        ((< 44.0 (ja-aframe-num 0))
         (set-forward-vel (the-as float -49152.0))
         (let ((gp-0 (new-stack-vector0)))
           (let ((f0-2 (vector-dot (-> self control dynam gravity-normal) (-> self control transv))))
             0.0
             (vector-! gp-0 (-> self control transv) (vector-float*! gp-0 (-> self control dynam gravity-normal) f0-2))
             )
           (let* ((f0-3 (vector-length gp-0))
                  (f1-1 f0-3)
                  (f2-0 -81920.0)
                  )
             (vector+!
               (-> self control transv)
               (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f2-0)
               (vector-float*! gp-0 gp-0 (/ f0-3 f1-1))
               )
             )
           )
         (logclear! (-> self control status) (cshape-moving-flags onsurf onground tsurf))
         (go target-falling 'target-pole-cycle)
         )
        ((>= (ja-aframe-num 0) 14.0)
         (remove-exit)
         (go target-pole-flip-up 28672.0 28672.0 (* 1024.0 (- 26.0 (ja-aframe-num 0))))
         )
        (else
          (remove-exit)
          (go target-pole-flip-forward (the-as float 14336.0) (the-as float 14336.0) (the-as float 57344.0))
          )
        )
      )
    (none)
    )
  :code (behavior ((arg0 handle))
    (target-compute-pole)
    (set! (-> self control unknown-uint20)
          (the-as uint (vector-dot
                         (-> self control unknown-vector100)
                         (vector-normalize! (-> self control unknown-vector102) (the-as float 1.0))
                         )
                  )
          )
    (cond
      ((ja-group? (-> self draw art-group data 83))
       (while (not (-> self control unknown-int21))
         (ja :num! (seek!))
         (suspend)
         )
       (ja :num-func num-func-identity :frame-num (ja-aframe (the-as float 37.0) 0))
       )
      (else
        (while (not (-> self control unknown-int21))
          (suspend)
          )
        (suspend)
        (ja-channel-push! 1 (seconds 0.15))
        )
      )
    (ja-no-eval :group! (-> self draw art-group data 80) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (loop
      (set! (-> self anim-seed) (the-as uint (if (rand-vu-percent? (the-as float 0.1))
                                                 0
                                                 1
                                                 )
                                        )
            )
      (ja-no-eval :group! (-> self draw art-group data 80) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-pole-flip-up (target)
  :event target-standard-event-handler
  :exit (-> target-pole-cycle exit)
  :code (behavior ((arg0 object) (arg1 object) (arg2 float))
    (ja-no-eval :group! (-> self draw art-group data 81)
                :num! (seek!)
                :frame-num (ja-aframe (+ 1.0 (fmin 17.0 (ja-aframe-num 0))) 0)
                )
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (set-forward-vel arg2)
    (go target-pole-flip-up-jump (the-as float arg0) (the-as float arg1))
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-pole-flip-up-jump (target)
  :event target-standard-event-handler
  :enter (-> target-jump-forward enter)
  :exit target-exit
  :trans (behavior ()
    ((-> target-jump-forward trans))
    (vector-flatten! (-> self control transv) (-> self control transv) (-> self control unknown-vector100))
    (none)
    )
  :code (behavior ((arg0 float) (arg1 float))
    (sound-play "jump")
    (send-event *camera* 'damp-up)
    (ja :group! (-> self draw art-group data 83) :num! min)
    (let ((f0-1 (target-height-above-ground))
          (f1-1 (vector-dot (-> self control dynam gravity-normal) (-> self control transv)))
          )
      (while (not (and (< (fabs (/ f0-1 (* 0.0033333334 f1-1))) 40.0) (and (< f1-1 0.0) (ja-min? 0))))
        (suspend)
        (ja :num! (loop!))
        (set! f0-1 (target-height-above-ground))
        (set! f1-1 (vector-dot (-> self control dynam gravity-normal) (-> self control transv)))
        )
      )
    (ja-channel-push! 1 (seconds 0.25))
    (ja-no-eval :group! eichar-jump-loop-ja :num! (loop!) :frame-num 0.0)
    (loop
      (suspend)
      (ja :group! eichar-jump-loop-ja :num! (loop!))
      )
    (none)
    )
  :post target-post
  )

;; failed to figure out what this is:
(defstate target-pole-flip-forward (target)
  :event target-standard-event-handler
  :exit (-> target-pole-cycle exit)
  :code (behavior ((arg0 float) (arg1 float) (arg2 float))
    (ja-no-eval :group! (-> self draw art-group data 82)
                :num! (seek! (ja-aframe (the-as float 16.0) 0))
                :frame-num (ja-aframe (+ 1.0 (ja-aframe-num 0)) 0)
                )
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! (ja-aframe (the-as float 16.0) 0)))
      )
    (set-forward-vel arg2)
    (go target-pole-flip-forward-jump arg0 arg1)
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-pole-flip-forward-jump (target)
  :event target-standard-event-handler
  :enter (behavior ((arg0 float) (arg1 float))
    ((-> target-jump enter) arg0 arg1 (the-as surface #f))
    (set! (-> self control unknown-surface00) *forward-pole-jump-mods*)
    (none)
    )
  :exit target-exit
  :trans (behavior ()
    ((-> target-jump-forward trans))
    (vector-flatten! (-> self control transv) (-> self control transv) (-> self control unknown-vector100))
    (none)
    )
  :code (behavior ((arg0 float) (arg1 float))
    (sound-play "jump")
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    ((the-as (function none :behavior target) (-> target-pole-flip-up-jump code)))
    (none)
    )
  :post target-post
  )

;; failed to figure out what this is:
(defstate target-edge-grab (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('end-mode)
       (go target-falling 'target-edge-grab)
       )
      (else
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self control unknown-surface00) *edge-grab-mods*)
    (set! (-> self control unknown-dword41) (-> *display* base-frame-counter))
    (logior! (-> self control root-prim prim-core action) (collide-action ca-3 ca-7))
    (set! (-> self control unknown-vector102 quad) (-> self control transv quad))
    (set! (-> self control transv quad) (the-as uint128 0))
    (send-event *camera* 'ease-in)
    (none)
    )
  :exit (behavior ()
    (when (logtest? (-> self control root-prim prim-core action) (collide-action ca-7))
      (logclear! (-> self control root-prim prim-core action) (collide-action ca-3 ca-7))
      (send-event *camera* 'damp-up)
      )
    (none)
    )
  :trans (behavior ()
    (when (and (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.2))
               (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                         (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                         )
                                 (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                                 )
                         (pad-buttons x)
                         )
               (zero? (logand (-> self state-flags) (state-flags prevent-jump)))
               )
      (cond
        ((or (< -0.2 (local-pad-angle))
             (= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
             )
         (let ((a1-2 (new 'stack-no-clear 'collide-using-spheres-params)))
           (set! (-> a1-2 spheres) (-> *collide-edge-work* world-player-leap-up-spheres))
           (set! (-> a1-2 num-spheres) (the-as uint 6))
           (set! (-> a1-2 collide-with) (-> self control root-prim collide-with))
           (set! (-> a1-2 proc) #f)
           (set! (-> a1-2 ignore-pat) (new 'static 'pat-surface :noentity #x1))
           (set! (-> a1-2 solid-only) #t)
           (when (not (fill-and-probe-using-spheres *collide-cache* a1-2))
             (remove-exit)
             (go
               target-edge-grab-jump
               (-> *TARGET-bank* edge-grab-jump-height-min)
               (-> *TARGET-bank* edge-grab-jump-height-max)
               )
             )
           )
         )
        (else
          (remove-exit)
          (go target-edge-grab-off)
          )
        )
      )
    (none)
    )
  :code (behavior ()
    (target-compute-edge)
    (set! (-> self control unknown-uint20)
          (the-as uint (vector-dot
                         (-> self control unknown-vector100)
                         (vector-normalize! (-> self control unknown-vector102) (the-as float 1.0))
                         )
                  )
          )
    (while (< 0.0 (-> self control unknown-float110))
      (when (not (ja-group? eichar-jump-loop-ja))
        (ja-channel-push! 1 (seconds 0.15))
        (ja :group! eichar-jump-loop-ja :num! min)
        )
      (suspend)
      )
    (ja-channel-push! 1 (seconds 0.15))
    (cond
      ((< (the-as float (-> self control unknown-uint20)) -0.3)
       (ja :group! eichar-edge-grab-swing-right-ja :num! min)
       )
      ((< 0.3 (the-as float (-> self control unknown-uint20)))
       (ja :group! eichar-edge-grab-swing-left-ja :num! min)
       )
      (else
        (ja :group! eichar-falling-to-edge-grab-ja :num! min)
        )
      )
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (ja-channel-set! 1)
    (loop
      (ja-no-eval :group! eichar-edge-grab-stance0-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      (+! (-> self anim-seed) 1)
      (ja-no-eval :group! eichar-edge-grab-stance1-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-edge-grab-jump (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('end-mode)
       (go target-falling 'target-edge-grab)
       )
      (else
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :exit (-> target-edge-grab exit)
  :code (behavior ((arg0 float) (arg1 float))
    (ja-channel-set! 1)
    (set-quaternion! (-> self control) (-> self control dir-targ))
    (logclear! (-> self control root-prim prim-core action) (collide-action ca-3 ca-7))
    (set! (-> self control transv quad) (the-as uint128 0))
    (let ((s4-0 (new 'stack-no-clear 'vector)))
      (ja-no-eval :group! eichar-edge-grab-to-jump-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (target-compute-edge-rider)
        (compute-alignment! (-> self align))
        (when (zero? (logand (-> self align flags) (align-flags disabled)))
          (vector-matrix*! s4-0 (the-as vector (-> self align delta)) (-> self control unknown-matrix01))
          (move-by-vector! (-> self control) s4-0)
          )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (set! (-> self control transv quad) (the-as uint128 0))
    (set! (-> self control unknown-dword70) 0)
    (set-forward-vel (the-as float 16384.0))
    (send-event *camera* 'damp-up)
    (go target-jump-forward arg0 arg1)
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-edge-grab-off (target)
  :event target-standard-event-handler
  :exit (-> target-edge-grab exit)
  :code (behavior ()
    (ja-channel-set! 1)
    (set-quaternion! (-> self control) (-> self control dir-targ))
    (send-event *camera* 'damp-up)
    (let ((gp-0 (new 'stack-no-clear 'vector)))
      (ja-no-eval :group! eichar-edge-grab-off-ja :num! (seek! (ja-aframe (the-as float 191.0) 0)) :frame-num 0.0)
      (until (ja-done? 0)
        (compute-alignment! (-> self align))
        (when (zero? (logand (-> self align flags) (align-flags disabled)))
          (vector-matrix*! gp-0 (the-as vector (-> self align delta)) (-> self control unknown-matrix01))
          (move-by-vector! (-> self control) gp-0)
          )
        (suspend)
        (ja :num! (seek! (ja-aframe (the-as float 191.0) 0)))
        )
      )
    (set! (-> self control transv quad) (the-as uint128 0))
    (logclear! (-> self control root-prim prim-core action) (collide-action ca-3 ca-7))
    (vector-float*! (-> self control transv) (-> self control unknown-vector101) -40960.0)
    (when (and (< (- (-> *display* base-frame-counter) (-> self control rider-time)) (seconds 0.2))
               (or (logtest? (-> self control unknown-surface01 flags) (surface-flags moving-ground))
                   (= (-> self control poly-pat material) (pat-material rotate))
                   )
               )
      (+! (-> self control transv x) (-> self control rider-last-move x))
      (+! (-> self control transv z) (-> self control rider-last-move z))
      )
    (go target-falling 'target-edge-grab)
    (none)
    )
  :post target-no-move-post
  )

;; failed to figure out what this is:
(defstate target-yellow-blast (target)
  :event (-> target-running-attack event)
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self control unknown-surface00) *run-attack-mods*)
    (set! (-> *run-attack-mods* turnv) 655360.0)
    (set! (-> *run-attack-mods* turnvv) 655360.0)
    (target-start-attack)
    (target-danger-set! 'spin #f)
    (set! (-> self control unknown-uint20) (the-as uint 0))
    (set! (-> self control unknown-int21) 0)
    (set! (-> self control unknown-uint31) (the-as uint 0))
    (let ((gp-0 (new-stack-vector0))
          (f30-0 (vector-dot (-> self control dynam gravity-normal) (-> self control transv)))
          )
      0.0
      (vector-! gp-0 (-> self control transv) (vector-float*! gp-0 (-> self control dynam gravity-normal) f30-0))
      (let* ((f0-5 (vector-length gp-0))
             (f1-0 f0-5)
             )
        (if (< 0.0 f30-0)
            (set! f30-0 0.0)
            )
        (vector+!
          (-> self control transv)
          (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f30-0)
          (vector-float*! gp-0 gp-0 (/ f0-5 f1-0))
          )
        )
      )
    (none)
    )
  :exit (behavior ()
    (set! (-> *run-attack-mods* turnv) 0.0)
    (set! (-> *run-attack-mods* turnvv) 0.0)
    (set! (-> self control unknown-dword31) (-> *display* base-frame-counter))
    (target-exit)
    (none)
    )
  :code (behavior ()
    (let ((gp-0 (the-as handle #f)))
      (ja-channel-push! 1 (seconds 0.075))
      (level-hint-spawn
        (game-text-id swamp-eco-yellow-first-use)
        "sksp0145"
        (the-as entity #f)
        *entity-pool*
        (game-task none)
        )
      (case (-> (level-get-target-inside *level*) name)
        (('maincave)
         (level-hint-spawn
           (game-text-id cave-gnawers-look-around)
           "sksp0328"
           (the-as entity #f)
           *entity-pool*
           (game-task none)
           )
         )
        )
      (ja-no-eval :group! eichar-yellow-running-blast-ja
                  :num! (seek! (ja-aframe (the-as float 9.0) 0))
                  :frame-num 0.0
                  )
      (until (ja-done? 0)
        (if (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.1))
            (set! (-> *run-attack-mods* turnvv) 0.0)
            )
        (suspend)
        (ja :num! (seek! (ja-aframe (the-as float 9.0) 0)))
        )
      (let ((s5-2 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self control quat))))
        (set! (-> s5-2 y) 0.0)
        (vector-normalize! s5-2 (-> *TARGET-bank* yellow-projectile-speed))
        (when (and (= (-> self fact-info-target eco-type) (pickup-type eco-yellow))
                   (>= (-> self fact-info-target eco-level) 1.0)
                   )
          (let ((gp-1 (get-process *default-dead-pool* projectile-yellow #x4000)))
            (set! gp-0 (ppointer->handle
                         (when gp-1
                           (let ((t9-12 (method-of-type projectile-yellow activate)))
                             (t9-12 (the-as projectile-yellow gp-1) self 'projectile-yellow (the-as pointer #x70004000))
                             )
                           (run-now-in-process
                             gp-1
                             projectile-init-by-other
                             (-> self entity)
                             (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data 23))
                             s5-2
                             (if (>= (-> self fact-info-target eco-level) (-> *FACT-bank* eco-level-max))
                                 25
                                 9
                                 )
                             #f
                             )
                           (-> gp-1 ppointer)
                           )
                         )
                  )
            )
          (set! (-> self control unknown-dword82) (-> *display* base-frame-counter))
          )
        )
      (ja-no-eval :group! eichar-yellow-running-blast-ja :num! (seek!) :frame-num (ja-aframe (the-as float 9.0) 0))
      (until (ja-done? 0)
        (if (or (< (the-as uint (- (-> *display* base-frame-counter) (the-as int (-> self control unknown-uint30))))
                   (the-as uint 30)
                   )
                (= (-> self control unknown-uint31) 1)
                )
            (send-event (handle->process gp-0) 'die)
            )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (if (logtest? (-> self control status) (cshape-moving-flags onsurf))
        (go target-stance)
        (go target-falling #f)
        )
    (none)
    )
  :post target-post
  )

;; definition for symbol *yellow-jump-mods*, type surface
(define *yellow-jump-mods* (new 'static 'surface
                             :name 'run
                             :tiltv 65536.0
                             :tiltvv 131072.0
                             :transv-max 40960.0
                             :target-speed 40960.0
                             :fric 0.1
                             :nonlin-fric-dist 1.0
                             :slip-factor 1.0
                             :slide-factor 1.0
                             :slope-up-factor 1.0
                             :slope-down-factor 1.0
                             :slope-slip-angle 1.0
                             :impact-fric 1.0
                             :bend-factor 1.0
                             :bend-speed 1.0
                             :alignv 1.0
                             :slope-up-traction 1.0
                             :align-speed 1.0
                             :mode 'air
                             :flags (surface-flags jump)
                             )
        )

;; failed to figure out what this is:
(defstate target-yellow-jump-blast (target)
  :event target-standard-event-handler
  :enter (behavior ()
    (set! (-> self control unknown-surface00) *yellow-jump-mods*)
    (let ((gp-0 (new-stack-vector0)))
      (let ((f0-1 (vector-dot (-> self control dynam gravity-normal) (-> self control transv))))
        0.0
        (vector-! gp-0 (-> self control transv) (vector-float*! gp-0 (-> self control dynam gravity-normal) f0-1))
        )
      (let* ((f0-2 (vector-length gp-0))
             (f1-1 f0-2)
             (f2-0 46917.434)
             )
        (vector+!
          (-> self control transv)
          (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f2-0)
          (vector-float*! gp-0 gp-0 (/ f0-2 f1-1))
          )
        )
      )
    (none)
    )
  :exit (behavior ()
    (rot->dir-targ! (-> self control))
    (set! (-> self control unknown-dword31) (-> *display* base-frame-counter))
    (target-exit)
    (none)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.075))
    (ja-no-eval :group! eichar-yellow-jumping-blast-ja
                :num! (seek! (ja-aframe (the-as float 15.0) 0))
                :frame-num 0.0
                )
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! (ja-aframe (the-as float 15.0) 0)))
      )
    (suspend)
    (let ((gp-2 (new-stack-vector0)))
      (let ((f0-6 (vector-dot (-> self control dynam gravity-normal) (-> self control transv))))
        0.0
        (vector-! gp-2 (-> self control transv) (vector-float*! gp-2 (-> self control dynam gravity-normal) f0-6))
        )
      (let* ((f0-7 (vector-length gp-2))
             (f1-1 f0-7)
             (f2-0 46917.434)
             )
        (vector+!
          (-> self control transv)
          (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f2-0)
          (vector-float*! gp-2 gp-2 (/ f0-7 f1-1))
          )
        )
      )
    (ja :num! (seek!))
    (process-spawn
      projectile-yellow
      :init projectile-init-by-other
      (-> self entity)
      (-> self control unknown-vector90)
      (vector-float*!
        (new 'stack-no-clear 'vector)
        (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self control quat))
        (the-as float (-> *TARGET-bank* yellow-projectile-speed))
        )
      (if (>= (-> self fact-info-target eco-level) (-> *FACT-bank* eco-level-max))
          16
          0
          )
      #f
      :to self
      )
    (set! (-> self control unknown-dword82) (-> *display* base-frame-counter))
    (let ((gp-4 (-> *display* base-frame-counter)))
      (until (>= (- (-> *display* base-frame-counter) gp-4) (seconds 0.1))
        (suspend)
        )
      )
    (ja-no-eval :group! eichar-yellow-jumping-blast-ja :num! (seek!) :frame-num (ja-frame-num 0))
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (if (logtest? (-> self control status) (cshape-moving-flags onsurf))
        (go target-stance)
        (go target-falling #f)
        )
    (none)
    )
  :post target-no-stick-post
  )

;; failed to figure out what this is:
(defstate target-eco-powerup (target)
  :event target-standard-event-handler
  :exit target-exit
  :trans (behavior ()
    (slide-down-test)
    (none)
    )
  :code (behavior ((arg0 object) (arg1 float))
    (set! (-> self neck flex-blend) 0.0)
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (if (= arg1 (-> *FACT-bank* eco-full-inc))
        (set! (-> self control unknown-surface00) *double-jump-mods*)
        (set! (-> self control unknown-surface00) *walk-mods*)
        )
    (ja-channel-push! 1 (seconds 0.05))
    (ja-no-eval :group! eichar-powerup-ja
                :num! (seek! max (the-as float (if (= arg1 (-> *FACT-bank* eco-full-inc))
                                             2.0
                                             3.0
                                             )
                                   )
                       )
                :frame-num (ja-aframe
                  (the-as float (if (= arg1 (-> *FACT-bank* eco-full-inc))
                                    0.0
                                    6.0
                                    )
                          )
                  0
                  )
                )
    (until (ja-done? 0)
      (if (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                         (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                         )
                                 (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                                 )
                         (pad-buttons x)
                         )
               (zero? (logand (-> self water flags) (water-flags wt09)))
               (zero? (logand (-> self state-flags) (state-flags prevent-jump)))
               )
          (go target-jump (-> *TARGET-bank* jump-height-min) (-> *TARGET-bank* jump-height-max) (the-as surface #f))
          )
      (if (and (cpad-pressed? (-> self control unknown-cpad-info00 number) circle) (can-feet?))
          (go target-attack-air #f)
          )
      (when (can-hands? #f)
        (if (and (= (-> self fact-info-target eco-type) (pickup-type eco-yellow))
                 (>= (-> self fact-info-target eco-level) 1.0)
                 )
            (go target-yellow-jump-blast)
            (go target-running-attack)
            )
        )
      (compute-alignment! (-> self align))
      (align!
        (-> self align)
        (align-opts adjust-y-vel)
        (the-as float 1.0)
        (the-as float (if (= arg1 (-> *FACT-bank* eco-full-inc))
                          2.0
                          1.0
                          )
                )
        (the-as float 1.0)
        )
      (suspend)
      (ja :num! (seek! max (the-as float (if (= arg1 (-> *FACT-bank* eco-full-inc))
                                             2.0
                                             3.0
                                             )
                                   )
                       )
          )
      )
    (go target-falling 'target-eco-powerup)
    (none)
    )
  :post target-post
  )

;; failed to figure out what this is:
(defstate target-wade-stance (target)
  :event target-standard-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self control unknown-surface00) *wade-mods*)
    (set-zero! (-> self water bob))
    (none)
    )
  :exit (behavior ()
    (target-state-hook-exit)
    (target-exit)
    (let ((v1-1 (-> self skel effect)))
      (set! (-> v1-1 channel-offset) 0)
      )
    0
    (none)
    )
  :trans (behavior ()
    ((-> self state-hook))
    (when (and (zero? (logand (-> self water flags) (water-flags wt10)))
               (>= (- (-> *display* base-frame-counter) (-> self water wade-time)) (seconds 0.05))
               )
      (if (logtest? (-> self water flags) (water-flags wt11))
          (go target-swim-stance)
          (go target-stance)
          )
      )
    (if (and (cpad-hold? (-> self control unknown-cpad-info00 number) l1 r1) (can-duck?))
        (go target-duck-stance)
        )
    (if (!= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
        (go target-wade-walk)
        )
    (if (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                       (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                       )
                               (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                               )
                       (pad-buttons x)
                       )
             (can-jump? #f)
             )
        (go target-jump (-> *TARGET-bank* jump-height-min) (-> *TARGET-bank* jump-height-max) (the-as surface #f))
        )
    (when (and (cpad-pressed? (-> self control unknown-cpad-info00 number) circle) (can-feet?))
      (sound-play "swim-stroke")
      (dummy-13 (-> self water) (the-as float 1.4) (-> self control trans) 0 (-> self control transv))
      (go target-attack)
      )
    (if (can-hands? #t)
        (go target-running-attack)
        )
    (none)
    )
  :code (-> target-stance code)
  :post target-post
  )

;; failed to figure out what this is:
(defstate target-wade-walk (target)
  :event target-standard-event-handler
  :enter (-> target-wade-stance enter)
  :exit (-> target-wade-stance exit)
  :trans (behavior ()
    ((-> self state-hook))
    (when (and (zero? (logand (-> self water flags) (water-flags wt10)))
               (>= (- (-> *display* base-frame-counter) (-> self water wade-time)) (seconds 0.1))
               )
      (if (logtest? (-> self water flags) (water-flags wt11))
          (go target-swim-stance)
          (go target-stance)
          )
      )
    (if (= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
        (go target-wade-stance)
        )
    (if (and (cpad-hold? (-> self control unknown-cpad-info00 number) l1 r1) (can-duck?))
        (go target-duck-walk)
        )
    (if (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                       (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                       )
                               (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                               )
                       (pad-buttons x)
                       )
             (can-jump? #f)
             )
        (go target-jump (-> *TARGET-bank* jump-height-min) (-> *TARGET-bank* jump-height-max) (the-as surface #f))
        )
    (when (and (cpad-pressed? (-> self control unknown-cpad-info00 number) circle) (can-feet?))
      (sound-play "swim-stroke")
      (dummy-13 (-> self water) (the-as float 1.4) (-> self control trans) 0 (-> self control transv))
      (go target-attack)
      )
    (if (can-hands? #t)
        (go target-running-attack)
        )
    (none)
    )
  :code (behavior ()
    (let ((gp-0 105)
          (f30-0 0.0)
          )
      (let ((v1-2 (ja-group)))
        (cond
          ((or (= v1-2 eichar-walk-ja) (= v1-2 eichar-run-ja))
           (set! gp-0 15)
           (set! f30-0 (ja-frame-num 0))
           )
          ((let ((v1-9 (ja-group)))
             (or (= v1-9 eichar-jump-ja) (= v1-9 eichar-jump-loop-ja))
             )
           (set! gp-0 30)
           )
          ((ja-group? eichar-swim-walk-ja)
           (set! gp-0 120)
           )
          )
        )
      (cond
        ((and (= (ja-group-size) 6) (ja-group? eichar-wade-shallow-walk-ja))
         )
        (else
          (ja-channel-push! 6 (the-as time-frame gp-0))
          (ja :group! eichar-wade-shallow-walk-ja
              :num! (identity f30-0)
              :dist (-> *TARGET-bank* wade-shallow-walk-cycle-dist)
              )
          (ja :chan 1
              :group! eichar-wade-deep-walk-ja
              :num! (identity f30-0)
              :dist (-> *TARGET-bank* wade-deep-walk-cycle-dist)
              )
          (ja :chan 2
              :group! eichar-walk-ja
              :num! (identity f30-0)
              :frame-interp 0.0
              :dist (-> *TARGET-bank* walk-cycle-dist)
              )
          (ja :chan 3
              :group! eichar-walk-down-ja
              :num! (identity f30-0)
              :frame-interp 0.0
              :dist (-> *TARGET-bank* walk-down-cycle-dist)
              )
          (ja :chan 4
              :group! eichar-walk-left-ja
              :num! (identity f30-0)
              :frame-interp 0.0
              :dist (-> *TARGET-bank* walk-side-cycle-dist)
              )
          )
        )
      )
    (set! (-> self skel root-channel 2 command) 'push)
    (set! (-> self skel root-channel 5 command) 'stack)
    (let ((f30-1 0.0)
          (f28-0 0.0)
          (f26-0 (lerp-scale
                   (the-as float 1.0)
                   (the-as float 0.0)
                   (-> self control unknown-float01)
                   (the-as float 16384.0)
                   (the-as float 32768.0)
                   )
                 )
          (gp-6 0)
          )
      (loop
        (let ((f0-10 (fmax -1.0 (fmin 1.0 (* 2.0 (-> self control unknown-float61)))))
              (f24-0 (fmax -1.0 (fmin 1.0 (* 1.6 (-> self control unknown-float62)))))
              )
          (let ((f1-4 (fabs (- f0-10 f30-1))))
            (set! f30-1 (seek f30-1 f0-10 (fmax 0.05 (fmin 0.2 (* 0.25 f1-4)))))
            )
          (let ((f0-14 (fabs (- f24-0 f28-0))))
            (set! f28-0 (seek f28-0 f24-0 (fmax 0.05 (fmin 0.2 (* 0.25 f0-14)))))
            )
          )
        (ja :chan 3 :group! eichar-walk-down-ja :dist (-> *TARGET-bank* walk-down-cycle-dist))
        (if (>= f30-1 0.0)
            (ja :chan 3 :group! eichar-walk-up-ja :frame-interp (fabs f30-1) :dist (-> *TARGET-bank* walk-up-cycle-dist))
            (ja :chan 3
                :group! eichar-walk-down-ja
                :frame-interp (fabs f30-1)
                :dist (-> *TARGET-bank* walk-down-cycle-dist)
                )
            )
        (if (>= f28-0 0.0)
            (ja :chan 4
                :group! eichar-walk-right-ja
                :frame-interp (fabs f28-0)
                :dist (-> *TARGET-bank* walk-side-cycle-dist)
                )
            (ja :chan 4
                :group! eichar-walk-left-ja
                :frame-interp (fabs f28-0)
                :dist (-> *TARGET-bank* walk-side-cycle-dist)
                )
            )
        (let* ((f0-30 (- (-> self water height) (-> self control trans y)))
               (f24-1 (lerp-scale
                        (the-as float 0.0)
                        (the-as float 1.0)
                        f0-30
                        (lerp (-> self water wade-height) (-> self water swim-height) (the-as float 0.25))
                        (lerp (-> self water wade-height) (-> self water swim-height) (the-as float 0.75))
                        )
                      )
               )
          (let ((v1-108 (-> self skel effect)))
            (set! (-> v1-108 channel-offset) (if (< 0.5 f24-1)
                                                 1
                                                 0
                                                 )
                  )
            )
          0
          (set! f26-0 (seek
                        f26-0
                        (lerp-scale
                          (the-as float 1.0)
                          (the-as float 0.0)
                          (-> self control unknown-float01)
                          (the-as float 16384.0)
                          (the-as float 32768.0)
                          )
                        (* 4.0 (-> *display* seconds-per-frame))
                        )
                )
          (set! (-> self skel root-channel 1 frame-interp) f24-1)
          (ja :num! (loop! (/ (-> self control unknown-float01)
                              (* 60.0 (/ (current-cycle-distance (-> self skel)) (-> *TARGET-bank* run-cycle-length)))
                              )
                           )
              )
          (ja :chan 5 :frame-interp (lerp f26-0 (the-as float 0.0) f24-1))
          )
        (ja :chan 1 :num! (chan 0))
        (ja :chan 2 :num! (chan 0))
        (ja :chan 3 :num! (chan 0))
        (ja :chan 4 :num! (chan 0))
        (when (and (>= (- (-> *display* base-frame-counter) (the-as time-frame gp-6)) (seconds 0.2))
                   (< (- (-> self water height) (-> self control trans y)) 4096.0)
                   )
          (case (the int (ja-aframe-num 0))
            ((15 16 17 18)
             (dummy-13
               (-> self water)
               (the-as float 0.2)
               (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data 75))
               0
               (vector-float*! (new 'stack-no-clear 'vector) (-> self control transv) 2.5)
               )
             (set! gp-6 (the-as int (-> *display* base-frame-counter)))
             )
            ((46 47 48 49)
             (dummy-13
               (-> self water)
               (the-as float 0.2)
               (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data 71))
               0
               (vector-float*! (new 'stack-no-clear 'vector) (-> self control transv) 2.5)
               )
             (set! gp-6 (the-as int (-> *display* base-frame-counter)))
             )
            )
          )
        (suspend)
        )
      )
    (none)
    )
  :post target-post
  )

;; definition for function target-swim-tilt
(defbehavior target-swim-tilt target ((arg0 float) (arg1 float) (arg2 float) (arg3 float))
  (let ((gp-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self control unknown-quaternion00))))
    (let ((v1-2 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self control dir-targ)))
          (f0-1
            (fmin 1.0 (* arg0 (/ (-> self control unknown-float01) (-> self control unknown-surface01 target-speed))))
            )
          )
      (seek!
        (-> self control unknown-float130)
        (fmax (fmin (* (+ f0-1 arg2) (fmax 0.5 (+ 0.5 (vector-dot gp-0 v1-2)))) arg3) (- arg3))
        (* arg1 (-> *display* seconds-per-frame))
        )
      )
    (let ((a2-2 (vector-y-quaternion! (new 'stack-no-clear 'vector) (-> self control unknown-quaternion00))))
      (forward-up-nopitch->quaternion (-> self control unknown-quaternion01) gp-0 a2-2)
      )
    )
  (quaternion-rotate-x!
    (-> self control unknown-quaternion01)
    (-> self control unknown-quaternion01)
    (the-as float (if (>= (-> self control unknown-float130) 0.0)
                      16384.0
                      -16384.0
                      )
            )
    )
  (set! (-> self control unknown-float00) (fabs (-> self control unknown-float130)))
  (if (= (-> self next-state name) 'target-swim-down)
      (seek! (-> self control unknown-float131) (the-as float -6144.0) (* 4096.0 (-> *display* seconds-per-frame)))
      (seek! (-> self control unknown-float131) (the-as float 0.0) (* 2048.0 (-> *display* seconds-per-frame)))
      )
  (let ((f0-20 (-> self control unknown-float131)))
    (set! (-> self control unknown-vector11 y) f0-20)
    f0-20
    )
  )

;; failed to figure out what this is:
(defstate target-swim-stance (target)
  :event target-standard-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self control unknown-surface00) *swim-mods*)
    (logior! (-> self water flags) (water-flags wt04))
    (none)
    )
  :exit (behavior ()
    (target-state-hook-exit)
    (set! (-> self control unknown-surface00 target-speed) 28672.0)
    (target-exit)
    (when (not (or (= (-> self next-state name) 'target-swim-stance)
                   (= (-> self next-state name) 'target-swim-walk)
                   (= (-> self next-state name) 'target-swim-down)
                   (= (-> self next-state name) 'target-swim-up)
                   )
               )
      (quaternion-identity! (-> self control unknown-quaternion01))
      (set! (-> self control unknown-float00) 0.0)
      )
    (none)
    )
  :trans (behavior ()
    ((-> self state-hook))
    (if (and (logtest? (-> self control status) (cshape-moving-flags onsurf))
             (zero? (logand (-> self control status) (cshape-moving-flags on-water)))
             )
        (set-zero! (-> self water bob))
        )
    (when (and (zero? (logand (-> self water flags) (water-flags wt11)))
               (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.1))
               )
      (if (logtest? (-> self water flags) (water-flags wt10))
          (go target-wade-stance)
          (go target-stance)
          )
      )
    (if (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                       (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                       )
                               (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                               )
                       (pad-buttons x)
                       )
             (can-jump? #f)
             (>= (- (-> *display* base-frame-counter) (-> self water enter-swim-time)) (seconds 0.1))
             )
        (go target-swim-jump (-> *TARGET-bank* swim-jump-height-min) (-> *TARGET-bank* swim-jump-height-max))
        )
    (if (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                       (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                       )
                               (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                               )
                       (pad-buttons square)
                       )
             (< (-> *TARGET-bank* min-dive-depth) (target-height-above-ground))
             )
        (go target-swim-down)
        )
    (if (and (!= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
             (let ((gp-0 (ja-group)))
               (ja-aframe-num 0)
               (if (or (and (= gp-0 eichar-swim-up-ja) #t) (and (= gp-0 eichar-swim-down-to-up-ja) #t))
                   #f
                   #t
                   )
               )
             )
        (go target-swim-walk)
        )
    (target-swim-tilt (the-as float 0.0) (the-as float 2.0) (the-as float 0.0) (the-as float 1.0))
    (none)
    )
  :code (behavior ()
    (let ((v1-2 (ja-group)))
      (cond
        ((or (= v1-2 eichar-swim-up-ja) (= v1-2 eichar-swim-down-to-up-ja))
         (ja-channel-push! 1 (seconds 0.075))
         (ja-no-eval :group! eichar-swim-up-to-stance-ja
                     :num! (seek!
                       max
                       (the-as float (if (= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
                                         1.0
                                         2.0
                                         )
                               )
                       )
                     :frame-num 0.0
                     )
         (until (ja-done? 0)
           (suspend)
           (let ((a0-9 (-> self skel root-channel 0)))
             (set! (-> a0-9 param 0) (the float (+ (-> a0-9 frame-group data 0 length) -1)))
             (let ((v1-41 (if (= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
                              1.0
                              2.0
                              )
                          )
                   )
               (set! (-> a0-9 param 1) (the-as float v1-41))
               )
             (joint-control-channel-group-eval! a0-9 (the-as art-joint-anim #f) num-func-seek!)
             )
           )
         )
        ((ja-group? eichar-swim-walk-ja)
         (ja-channel-push! 1 (seconds 0.83))
         )
        (else
          (ja-channel-push! 1 (seconds 0.15))
          )
        )
      )
    (loop
      (ja :group! eichar-swim-stance-ja :num! min)
      (until (and (ja-done? 0) (= (-> self skel root-channel 0) (-> self skel channel)))
        (suspend)
        (if (= (-> self skel root-channel 0) (-> self skel channel))
            (ja :num! (seek!))
            )
        )
      )
    (none)
    )
  :post target-swim-post
  )

;; failed to figure out what this is:
(defstate target-swim-walk (target)
  :event target-standard-event-handler
  :enter (behavior ()
    ((-> target-swim-stance enter))
    (die-on-next-update! (-> self water bob))
    (set! (-> self control unknown-uint20) (the-as uint (-> *display* base-frame-counter)))
    (none)
    )
  :exit (-> target-swim-stance exit)
  :trans (behavior ()
    ((-> self state-hook))
    (if (and (logtest? (-> self control status) (cshape-moving-flags onsurf))
             (zero? (logand (-> self control status) (cshape-moving-flags on-water)))
             )
        (set-zero! (-> self water bob))
        )
    (when (and (zero? (logand (-> self water flags) (water-flags wt11)))
               (>= (- (-> *display* base-frame-counter) (-> self water swim-time)) (seconds 0.1))
               )
      (if (logtest? (-> self water flags) (water-flags wt10))
          (go target-wade-stance)
          (go target-stance)
          )
      )
    (if (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                       (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                       )
                               (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                               )
                       (pad-buttons x)
                       )
             (can-jump? #f)
             (>= (- (-> *display* base-frame-counter) (-> self water enter-swim-time)) (seconds 0.1))
             )
        (go target-swim-jump (-> *TARGET-bank* swim-jump-height-min) (-> *TARGET-bank* swim-jump-height-max))
        )
    (if (and (logtest? (logior (logior (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 0)
                                       (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 1)
                                       )
                               (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-rel 2)
                               )
                       (pad-buttons square)
                       )
             (< (-> *TARGET-bank* min-dive-depth) (target-height-above-ground))
             )
        (go target-swim-down)
        )
    (cond
      ((= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
       (if (>= (the-as uint (- (-> *display* base-frame-counter) (the-as int (-> self control unknown-uint20))))
               (the-as uint 15)
               )
           (go target-swim-stance)
           )
       )
      (else
        (set! (-> self control unknown-uint20) (the-as uint (-> *display* base-frame-counter)))
        )
      )
    (target-swim-tilt (the-as float 0.0) (the-as float 2.0) (the-as float 0.0) (the-as float 1.0))
    (none)
    )
  :code (behavior ()
    (let ((v1-2 (ja-group)))
      (cond
        ((or (= v1-2 eichar-swim-up-ja) (= v1-2 eichar-swim-down-to-up-ja) (= v1-2 eichar-swim-up-to-stance-ja))
         (ja-channel-push! 1 (seconds 0.3))
         )
        ((ja-group? eichar-swim-up-to-stance-ja)
         (ja-channel-push! 1 (seconds 0.15))
         (ja-no-eval :group! eichar-swim-walk-ja :num! (seek!) :frame-num (ja-aframe (the-as float 19.0) 0))
         (until (ja-done? 0)
           (compute-alignment! (-> self align))
           (if (zero? (logand (-> self align flags) (align-flags disabled)))
               (set! (-> self control unknown-surface00 target-speed)
                     (* (-> self align delta trans z) (-> self control unknown-surface01 alignv) (-> *display* frames-per-second))
                     )
               )
           (suspend)
           (ja :num! (seek!))
           )
         )
        (else
          (ja-channel-push! 1 (seconds 0.15))
          )
        )
      )
    (loop
      (ja-no-eval :group! eichar-swim-walk-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (compute-alignment! (-> self align))
        (if (zero? (logand (-> self align flags) (align-flags disabled)))
            (set! (-> self control unknown-surface00 target-speed)
                  (* (-> self align delta trans z) (-> self control unknown-surface01 alignv) (-> *display* frames-per-second))
                  )
            )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (none)
    )
  :post target-swim-post
  )

;; failed to figure out what this is:
(defstate target-swim-down (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('attack 'attack-invinc)
       (let ((v1-2 (the-as attack-info (-> arg3 param 1))))
         (when (or (zero? (logand (-> v1-2 mask) (attack-mask mode))) (= (-> v1-2 mode) 'generic) (= (-> v1-2 mode) 'drown))
           (set! (-> v1-2 mode) 'damage)
           (if (and (= (-> self game mode) 'play) (>= 1.0 (-> self fact-info-target health)))
               (set! (-> v1-2 mode) 'drown-death)
               )
           (logior! (-> v1-2 mask) (attack-mask mode))
           (set! (-> self control unknown-uint20) (the-as uint #t))
           )
         )
       )
      )
    (target-standard-event-handler arg0 arg1 arg2 arg3)
    )
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (logclear! (-> self water flags) (water-flags wt04))
    (set! (-> self control unknown-surface00) *dive-mods*)
    (set! (-> self control dynam gravity-max) 16384.0)
    (set! (-> self control dynam gravity-length) 16384.0)
    (set! (-> self water swim-time) (-> *display* base-frame-counter))
    (set! (-> self control unknown-uint20) (the-as uint #f))
    (if (= (-> self next-state name) 'target-swim-down)
        (set! (-> self control unknown-float130) 0.0)
        )
    (none)
    )
  :exit (behavior ()
    (set! (-> self control dynam gravity-max) (-> self control unknown-dynamics00 gravity-max))
    (set! (-> self control dynam gravity-length) (-> self control unknown-dynamics00 gravity-length))
    (target-exit)
    (when (not (or (= (-> self next-state name) 'target-swim-stance)
                   (= (-> self next-state name) 'target-swim-walk)
                   (= (-> self next-state name) 'target-swim-down)
                   (= (-> self next-state name) 'target-swim-up)
                   )
               )
      (quaternion-identity! (-> self control unknown-quaternion01))
      (set! (-> self control unknown-float00) 0.0)
      )
    (none)
    )
  :trans (behavior ()
    (if (>= (- (-> *display* base-frame-counter) (-> self water swim-time)) (seconds 0.5))
        (go target-stance)
        )
    (cond
      ((>= (- (-> *display* base-frame-counter) (-> self control unknown-dword11)) (seconds 0.1))
       (set! (-> self control unknown-surface00) *dive-mods*)
       (if (= (-> self next-state name) 'target-swim-down)
           (target-swim-tilt (the-as float -0.9) (the-as float 1.0) (the-as float 0.0) (the-as float 0.5))
           )
       )
      (else
        (set! (-> self control unknown-surface00) *dive-bottom-mods*)
        (if (or (= (-> self next-state name) 'target-swim-down) (= (-> self next-state name) 'target-swim-stance))
            (target-swim-tilt (the-as float 0.0) (the-as float 2.0) (the-as float -1.0) (the-as float 1.0))
            )
        )
      )
    (none)
    )
  :code (behavior ()
    (let ((gp-0 60)
          (s5-0 3000)
          (f30-0 0.0)
          )
      (let ((v1-2 (ja-group)))
        (set! f30-0
              (cond
                ((or (= v1-2 eichar-swim-stance-ja)
                     (= v1-2 eichar-swim-walk-ja)
                     (= v1-2 eichar-swim-up-to-stance-ja)
                     (= v1-2 eichar-swim-up-ja)
                     (= v1-2 eichar-swim-down-to-up-ja)
                     )
                 (ja-channel-push! 1 (seconds 0.075))
                 (ja-no-eval :group! eichar-swim-walk-to-down-ja :num! (seek!) :frame-num 0.0)
                 (until (ja-done? 0)
                   (compute-alignment! (-> self align))
                   (align!
                     (-> self align)
                     (align-opts adjust-y-vel adjust-xz-vel)
                     (the-as float 1.0)
                     (the-as float 1.0)
                     (the-as float 1.0)
                     )
                   (if (= (ja-aframe-num 0) 73.0)
                       (dummy-13 (-> self water) (the-as float 0.7) (-> self control trans) 1 *null-vector*)
                       )
                   (suspend)
                   (ja :num! (seek!))
                   )
                 (ja :group! eichar-swim-down-ja :num! min)
                 f30-0
                 )
                (else
                  (case (ja-group)
                    ((eichar-flop-down-ja eichar-moving-flop-down-ja eichar-flop-down-loop-ja eichar-moving-flop-down-loop-ja)
                     (ja-channel-push! 1 (seconds 0.075))
                     (set! gp-0 120)
                     (ja :group! eichar-swim-down-ja :num! (identity (ja-aframe (the-as float 124.0) 0)))
                     -16384.0
                     )
                    (else
                      (ja-channel-push! 1 (seconds 0.075))
                      (ja :group! eichar-swim-down-ja :num! min)
                      f30-0
                      )
                    )
                  )
                )
              )
        )
      (loop
        (if (and (or (zero? (logand (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) button0-abs 0)
                                    (pad-buttons square)
                                    )
                            )
                     (-> self control unknown-spoolanim00)
                     )
                 (>= (- (-> *display* base-frame-counter) (-> self state-time)) gp-0)
                 )
            (go target-swim-up)
            )
        (if (or (>= (- (-> *display* base-frame-counter) (-> self state-time)) s5-0)
                (and (logtest? (-> self control status) (cshape-moving-flags onsurf))
                     (and (< (-> self water swim-depth) 8192.0)
                          (>= (- (-> *display* base-frame-counter) (-> self state-time)) gp-0)
                          )
                     )
                )
            (go target-swim-up)
            )
        (let ((s4-3 (new-stack-vector0))
              (f24-0 (vector-dot (-> self control dynam gravity-normal) (-> self control transv)))
              )
          0.0
          (vector-! s4-3 (-> self control transv) (vector-float*! s4-3 (-> self control dynam gravity-normal) f24-0))
          (let* ((f28-0 (vector-length s4-3))
                 (f26-0 f28-0)
                 (f24-1 (+ f24-0 f30-0))
                 )
            (set! f30-0 (seek f30-0 (the-as float 0.0) (* 32768.0 (-> *display* seconds-per-frame))))
            (vector+!
              (-> self control transv)
              (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f24-1)
              (vector-float*! s4-3 s4-3 (/ f28-0 f26-0))
              )
            )
          )
        (suspend)
        (ja :num! (loop! (lerp-scale
                           (the-as float 0.4)
                           (the-as float 1.0)
                           (vector-length (-> self control transv))
                           (the-as float 0.0)
                           (the-as float 16384.0)
                           )
                         )
            )
        )
      )
    (none)
    )
  :post target-swim-post
  )

;; failed to figure out what this is:
(defstate target-swim-up (target)
  :event (-> target-swim-down event)
  :enter (-> target-swim-down enter)
  :exit (-> target-swim-down exit)
  :trans (behavior ()
    (if (and (cpad-pressed? (-> self control unknown-cpad-info00 number) x)
             (zero? (logand (-> self state-flags) (state-flags prevent-jump)))
             (zero? (logand (-> self water flags) (water-flags wt13 wt14)))
             )
        (go
          target-swim-jump-jump
          (-> *TARGET-bank* swim-jump-height-min)
          (-> *TARGET-bank* swim-jump-height-max)
          (the-as surface #f)
          )
        )
    (if (and (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 10))
             (< (target-move-dist (-> *TARGET-bank* stuck-time)) (-> *TARGET-bank* stuck-distance))
             )
        (send-event self 'attack #f (static-attack-info ((mode 'drown-death))))
        )
    ((-> target-swim-down trans))
    (none)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.1))
    (let ((f30-0 1.0))
      (let ((gp-0 #t))
        (ja-no-eval :group! eichar-swim-down-to-up-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (target-swim-tilt
            (the-as float (if (< 8192.0 (-> self water swim-depth))
                              0.5
                              0.0
                              )
                    )
            (the-as float 1.0)
            (the-as float 0.0)
            (the-as float 0.1)
            )
          (if (and (zero? (logand (-> self water flags) (water-flags wt12)))
                   (or (>= (ja-aframe-num 0) 222.0)
                       (and (!= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0)
                            (>= (ja-aframe-num 0) 200.0)
                            )
                       )
                   )
              (goto cfg-37)
              )
          (compute-alignment! (-> self align))
          (when (zero? (logand (-> self water flags) (water-flags wt12)))
            (logior! (-> self water flags) (water-flags wt04))
            (set! gp-0 #f)
            )
          (if gp-0
              (align! (-> self align) (align-opts adjust-y-vel) (the-as float 1.0) (the-as float 1.0) (the-as float 1.0))
              )
          (suspend)
          (ja :num! (seek!))
          )
        )
      (ja :group! eichar-swim-up-ja :num! min)
      (loop
        (target-swim-tilt
          (the-as float (if (< 8192.0 (-> self water swim-depth))
                            0.3
                            0.0
                            )
                  )
          (the-as float 1.0)
          (the-as float 0.0)
          (the-as float 0.1)
          )
        (if (zero? (logand (-> self water flags) (water-flags wt12)))
            (goto cfg-37)
            )
        (if (cpad-pressed? (-> self control unknown-cpad-info00 number) x)
            (set! f30-0 2.0)
            )
        (compute-alignment! (-> self align))
        (when (logtest? (-> self water flags) (water-flags wt12))
          (align! (-> self align) (align-opts adjust-y-vel) (the-as float 1.0) (the-as float 1.0) (the-as float 1.0))
          (set! (-> self control transv y) (+ 8192.0 (* 8192.0 f30-0)))
          )
        (suspend)
        (ja :num! (loop! f30-0))
        (set! f30-0 (seek f30-0 (the-as float 1.0) (-> *display* seconds-per-frame)))
        )
      )
    (label cfg-37)
    (logior! (-> self water flags) (water-flags wt04))
    (set! (-> self water swim-time) (-> *display* base-frame-counter))
    (start-bobbing! (-> self water) (the-as float -4096.0) 600 1500)
    (set! (-> self water bob start-time) (+ (-> *display* base-frame-counter) (seconds -0.05)))
    (go target-swim-stance)
    (none)
    )
  :post target-swim-post
  )

;; failed to figure out what this is:
(defstate target-swim-jump-jump (target)
  :event (-> target-jump event)
  :enter (-> target-jump enter)
  :exit target-exit
  :trans (behavior ()
    (cond
      ((< (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.5))
       (set! (-> self water flags) (logior (water-flags wt16) (-> self water flags)))
       (logclear! (-> self control status) (cshape-moving-flags onsurf onground tsurf))
       )
      (else
        (set! (-> self trans-hook) (-> target-jump trans))
        )
      )
    ((-> target-jump trans))
    (none)
    )
  :code (-> target-jump code)
  :post target-post
  )

;; failed to figure out what this is:
(defstate target-swim-jump (target)
  :event target-standard-event-handler
  :enter (-> target-swim-stance enter)
  :exit (behavior ()
    ((-> target-swim-stance exit))
    (die-on-next-update! (-> self water bob))
    (set! (-> self water align-offset) 0.0)
    (set! (-> self water flags) (logior (water-flags wt16) (-> self water flags)))
    (none)
    )
  :code (behavior ((arg0 float) (arg1 float))
    (die-on-next-update! (-> self water bob))
    (ja-channel-push! 1 (seconds 0.05))
    (ja :group! eichar-swim-jump-ja :num! min)
    (until (and (ja-done? 0) (= (-> self skel root-channel 0) (-> self skel channel)))
      (compute-alignment! (-> self align))
      (if (zero? (logand (-> self align flags) (align-flags disabled)))
          (+! (-> self water align-offset) (* 0.6 (-> self align delta trans y)))
          )
      (suspend)
      (if (= (-> self skel root-channel 0) (-> self skel channel))
          (ja :num! (seek! max 2.0))
          )
      )
    (let ((f30-0 (fmax 0.0 (- (-> self water bob-offset)))))
      (let ((s4-1 (new-stack-vector0)))
        (let ((f0-8 (vector-dot (-> self control dynam gravity-normal) (-> self control transv))))
          0.0
          (vector-! s4-1 (-> self control transv) (vector-float*! s4-1 (-> self control dynam gravity-normal) f0-8))
          )
        (let* ((f0-9 (vector-length s4-1))
               (f1-5 f0-9)
               (f2-1 0.4096)
               )
          (vector+!
            (-> self control transv)
            (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f2-1)
            (vector-float*! s4-1 s4-1 (/ f0-9 f1-5))
            )
          )
        )
      (go target-swim-jump-jump (+ f30-0 arg0) (+ f30-0 arg1) (the-as surface #f))
      )
    (none)
    )
  :post target-swim-post
  )

;; failed to figure out what this is:
(defstate target-hit-ground-hard (target)
  :event target-standard-event-handler
  :enter (behavior ((arg0 float))
    (set! (-> self control unknown-dword31) 0)
    (set! (-> self control unknown-dword33) 0)
    (set-forward-vel (the-as float 0.0))
    (set! (-> self control unknown-surface00) *walk-mods*)
    (none)
    )
  :code (behavior ((arg0 float))
    (when (!= arg0 0.0)
      (let ((f0-5 (the float (the int (+ 1.0 (/ (- arg0 (-> *TARGET-bank* fall-far)) (-> *TARGET-bank* fall-far-inc))))))
            )
        (pickup-collectable!
          (-> self fact-info-target)
          (pickup-type eco-green)
          (* (-> *FACT-bank* health-single-inc) (- (fmax 0.0 f0-5)))
          (the-as handle #f)
          )
        )
      (if (zero? (logand (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons l3)))
          (target-timed-invulnerable (-> *TARGET-bank* hit-invulnerable-timeout) self)
          )
      )
    (cond
      ((and (= (-> self game mode) 'play) (>= 0.0 (-> self fact-info-target health)))
       (set! (-> self attack-info attacker) (the-as handle #f))
       (go target-death 'target-hit-ground-hard)
       )
      (else
        (cpad-set-buzz! (-> *cpad-list* cpads 0) 1 255 (seconds 0.1))
        (ja-channel-push! 1 1)
        (ja :group! eichar-painful-land-ja :num! min)
        (until (and (ja-done? 0) (= (-> self skel root-channel 0) (-> self skel channel)))
          (suspend)
          (if (= (-> self skel root-channel 0) (-> self skel channel))
              (ja :num! (seek!))
              )
          )
        (ja :group! eichar-painful-land-end-ja :num! min)
        (until (and (ja-done? 0) (= (-> self skel root-channel 0) (-> self skel channel)))
          (suspend)
          (if (= (-> self skel root-channel 0) (-> self skel channel))
              (ja :num! (seek!))
              )
          )
        (go target-stance)
        )
      )
    (none)
    )
  :post target-no-stick-post
  )

;; failed to figure out what this is:
(defstate target-launch (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (if (and (= arg2 'query) (= (-> arg3 param 0) 'mode))
        'target-launch
        (target-standard-event-handler arg0 arg1 arg2 arg3)
        )
    )
  :code (behavior ((arg0 float) (arg1 symbol) (arg2 vector) (arg3 int))
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self control unknown-surface00) *turn-around-mods*)
    (ja-channel-push! 1 (seconds 0.15))
    (set-forward-vel (the-as float 0.0))
    (ja-no-eval :group! eichar-duck-stance-ja :num! (seek! (ja-aframe (the-as float 15.0) 0) 3.0) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! (ja-aframe (the-as float 15.0) 0) 3.0))
      )
    (if arg1
        (send-event *camera* 'change-state arg1 (seconds 0.6))
        )
    (if (nonzero? arg3)
        (process-spawn-function
          process
          (lambda :behavior process
            ((arg0 vector) (arg1 time-frame) (arg2 float))
            (local-vars (sv-32 time-frame) (sv-40 vector) (sv-44 symbol))
            (set! sv-32 (-> *display* base-frame-counter))
            (let ((v1-2 (new-stack-vector0)))
              (set! (-> v1-2 quad) (-> arg0 quad))
              (set! sv-40 v1-2)
              )
            (set! sv-44 #t)
            (until (>= (- (-> *display* base-frame-counter) sv-32) arg1)
              (let ((s4-0 (ppointer->process (-> self parent))))
                (cond
                  ((and sv-44
                        (< (- (-> (the-as target s4-0) control trans y) (-> (the-as target s4-0) control unknown-vector52 y)) arg2)
                        )
                   (vector-xz-normalize! (-> (the-as target s4-0) control transv) (the-as float 0.0))
                   (case (-> (the-as target s4-0) current-level name)
                     (('jungleb)
                      (let ((v1-16 (vector-! (new-stack-vector0) (-> (the-as target s4-0) control trans) sv-40)))
                        (set! (-> (the-as target s4-0) control trans x) (+ (-> sv-40 x) (fmax -4096.0 (fmin 4096.0 (-> v1-16 x)))))
                        (set! (-> (the-as target s4-0) control trans z) (+ (-> sv-40 z) (fmax -4096.0 (fmin 4096.0 (-> v1-16 z)))))
                        )
                      )
                     )
                   )
                  (else
                    (if sv-44
                        (set! sv-32 (-> *display* base-frame-counter))
                        )
                    (set! sv-44 (the-as symbol #f))
                    (when (or (= (-> (the-as target s4-0) next-state name) 'target-duck-high-jump-jump)
                              (= (-> (the-as target s4-0) next-state name) 'target-falling)
                              )
                      (let ((v1-30 (-> (the-as target s4-0) control trans))
                            (s3-0 (-> (the-as target s4-0) control transv))
                            )
                        (set! (-> s3-0 x) (- (-> sv-40 x) (-> v1-30 x)))
                        (set! (-> s3-0 z) (- (-> sv-40 z) (-> v1-30 z)))
                        (let ((f30-0 (vector-xz-length s3-0)))
                          (if (< 122880.0 f30-0)
                              (vector-xz-normalize! s3-0 (the-as float 122880.0))
                              )
                          (if (< 4096.0 f30-0)
                              (forward-up-nopitch->quaternion
                                (-> (the-as target s4-0) control dir-targ)
                                (vector-normalize-copy! (new 'stack-no-clear 'vector) s3-0 (the-as float 1.0))
                                (vector-y-quaternion! (new 'stack-no-clear 'vector) (-> (the-as target s4-0) control quat))
                                )
                              )
                          )
                        )
                      )
                    )
                  )
                )
              (suspend)
              0
              )
            #f
            )
          arg2
          arg3
          143360.0
          :to self
          )
        )
    (sound-play "launch-fire")
    (go target-high-jump arg0 arg0 'launch)
    (none)
    )
  :post target-no-stick-post
  )

;; failed to figure out what this is:
(defstate target-periscope (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('change-mode)
       #f
       )
      (('end-mode)
       (when (-> self control unknown-spoolanim00)
         (set! (-> self control unknown-uint20) (the-as uint #f))
         #t
         )
       )
      (else
        (target-generic-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :exit (behavior ()
    (target-exit)
    (set! (-> self cam-user-mode) 'normal)
    (logior! (-> self state-flags) (state-flags grabbed))
    (logclear! (-> self state-flags) (state-flags invulnerable))
    (none)
    )
  :code (behavior ((arg0 handle))
    (set! (-> self neck flex-blend) 0.0)
    (target-exit)
    (logior! (-> self state-flags) (state-flags invulnerable do-not-notice))
    (let ((v1-4 (handle->process arg0)))
      (if v1-4
          (quaterion<-rotate-y-vector (-> self control dir-targ) (vector-!
                                                                   (new 'stack-no-clear 'vector)
                                                                   (-> (the-as process-drawable v1-4) root trans)
                                                                   (-> self control trans)
                                                                   )
                                      )
          )
      )
    (set! (-> self control unknown-uint20) (the-as uint #t))
    (ja-channel-push! 1 (seconds 0.1))
    (ja-no-eval :group! eichar-periscope-grab-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (send-event (handle->process arg0) 'change-mode)
    (while (-> self control unknown-spoolanim00)
      (suspend)
      )
    (ja-no-eval :group! eichar-periscope-grab-ja :num! (seek! 0.0 2.0) :frame-num max)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! 0.0 2.0))
      )
    (go target-stance)
    (none)
    )
  :post target-no-stick-post
  )

;; failed to figure out what this is:
(defstate target-play-anim (target)
  :event target-generic-event-handler
  :enter (behavior ((arg0 string) (arg1 handle))
    (set! (-> self control unknown-handle10) arg1)
    (move-to-ground
      (-> self control)
      (the-as float 40960.0)
      (the-as float 40960.0)
      #f
      (-> self control root-prim collide-with)
      )
    (logior! (-> self state-flags) (state-flags grabbed))
    (set! (-> self neck flex-blend) 0.0)
    (none)
    )
  :exit (behavior ()
    (send-event (handle->process (-> self control unknown-handle10)) 'end-mode)
    (target-exit)
    (none)
    )
  :code (behavior ((arg0 string) (arg1 handle))
    (let ((gp-0 (the-as art-joint-anim (lookup-art (-> self draw art-group) arg0 art-joint-anim))))
      (when gp-0
        (send-event (ppointer->process (-> self sidekick)) 'matrix 'play-anim)
        (ja-channel-set! 1)
        (ja-no-eval :group! gp-0 :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))
          )
        (send-event (ppointer->process (-> self sidekick)) 'matrix 'normal)
        )
      )
    (go target-stance)
    (none)
    )
  :post target-no-stick-post
  )

;; failed to figure out what this is:
(defstate target-clone-anim (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (if (and (= arg2 'trans) (= (-> arg3 param 0) 'restore))
        (set! (-> self control unknown-uint20) (the-as uint #f))
        )
    ((-> target-grab event) arg0 arg1 arg2 arg3)
    )
  :enter (behavior ((arg0 handle))
    (set! (-> self control unknown-handle10) arg0)
    (set! (-> self control unknown-vector102 quad) (-> self control trans quad))
    (set! (-> self control unknown-uint20) (the-as uint #t))
    (quaternion-copy! (the-as quaternion (-> self control unknown-vector103)) (-> self control quat))
    (logior! (-> self state-flags) (state-flags grabbed))
    (vector-reset! (-> self control transv))
    (set! (-> self neck flex-blend) 0.0)
    (send-event (ppointer->process (-> self sidekick)) 'shadow #t)
    (none)
    )
  :exit (behavior ()
    (send-event (ppointer->process (-> self sidekick)) 'matrix 'normal)
    (send-event (ppointer->process (-> self sidekick)) 'shadow #t)
    (let ((gp-0 (-> self node-list data 3))
          (a1-2 (&-> (-> self control) unknown-qword00))
          )
      (cond
        ((not (-> self control unknown-spoolanim00))
         )
        ((zero? (logand (-> self draw status) (draw-status hidden)))
         (move-to-point! (-> self control) (the-as vector a1-2))
         (matrix->quaternion (-> self control unknown-quaternion00) (-> gp-0 bone transform))
         (quaternion-copy! (-> self control quat) (-> self control unknown-quaternion00))
         (move-to-ground
           (-> self control)
           (the-as float 4096.0)
           (the-as float 40960.0)
           #t
           (-> self control root-prim collide-with)
           )
         (when (logtest? (-> self control status) (cshape-moving-flags on-water))
           (let ((a1-6 (new-stack-vector0)))
             (set! (-> a1-6 x) (-> self control trans x))
             (set! (-> a1-6 y) (-> self water height))
             (set! (-> a1-6 z) (-> self control trans z))
             (set! (-> a1-6 w) 1.0)
             (move-to-point! (-> self control) a1-6)
             )
           )
         )
        (else
          (format 0 "ERROR: <ASG>: camera used backup position~%")
          (move-to-point! (-> self control) (-> self control unknown-vector102))
          (quaternion-copy! (-> self control quat) (the-as quaternion (-> self control unknown-vector103)))
          )
        )
      )
    (rot->dir-targ! (-> self control))
    (logior! (-> self control status) (cshape-moving-flags onsurf onground tsurf))
    (set! (-> self control unknown-dword11) (-> *display* base-frame-counter))
    (ja-channel-set! 0)
    (ja-post)
    (target-exit)
    (none)
    )
  :code (behavior ((arg0 handle))
    (clone-anim arg0 (the-as int (-> self draw origin-joint-index)) #t "")
    (go target-stance)
    (none)
    )
  :post target-no-ja-move-post
  )
