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

(import "goal_src/jak1/import/generic-button-ag.gc")

;; definition of type basebutton
(deftype basebutton (process-drawable)
  ((root-override     collide-shape-moving         :offset        112)
   (down?             symbol                       :offset-assert 176)
   (spawned-by-other? symbol                       :offset-assert 180)
   (move-to?          symbol                       :offset-assert 184)
   (notify-actor      entity-actor                 :offset-assert 188)
   (timeout           float                        :offset-assert 192)
   (button-id         int32                        :offset-assert 196)
   (event-going-down  symbol                       :offset-assert 200)
   (event-down        symbol                       :offset-assert 204)
   (event-going-up    symbol                       :offset-assert 208)
   (event-up          symbol                       :offset-assert 212)
   (anim-speed        float                        :offset-assert 216)
   (move-to-pos       vector               :inline :offset-assert 224)
   (move-to-quat      quaternion           :inline :offset-assert 240)
   )
  :heap-base #x90
  :method-count-assert 32
  :size-assert         #x100
  :flag-assert         #x2000900100
  (:methods
    (basebutton-down-idle () _type_ :state 20)
    (basebutton-going-down () _type_ :state 21)
    (basebutton-going-up () _type_ :state 22)
    (basebutton-startup () _type_ :state 23)
    (basebutton-up-idle () _type_ :state 24)
    (reset! (_type_) float 25)
    (TODO-RENAME-26 (_type_) none 26)
    (TODO-RENAME-27 (_type_) collide-shape-moving 27)
    (arm-trigger-event! (_type_) symbol 28)
    (TODO-RENAME-29 (_type_ symbol entity) none 29)
    (move-to-vec-or-quat! (_type_ vector quaternion) quaternion 30)
    (press! (_type_ symbol) int 31)
    )
  )

;; definition for method 3 of type basebutton
(defmethod inspect basebutton ((obj basebutton))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tdown?: ~A~%" (-> obj down?))
  (format #t "~T~Tspawned-by-other?: ~A~%" (-> obj spawned-by-other?))
  (format #t "~T~Tmove-to?: ~A~%" (-> obj move-to?))
  (format #t "~T~Tnotify-actor: ~A~%" (-> obj notify-actor))
  (format #t "~T~Ttimeout: ~f~%" (-> obj timeout))
  (format #t "~T~Tbutton-id: ~D~%" (-> obj button-id))
  (format #t "~T~Tevent-going-down: ~A~%" (-> obj event-going-down))
  (format #t "~T~Tevent-down: ~A~%" (-> obj event-down))
  (format #t "~T~Tevent-going-up: ~A~%" (-> obj event-going-up))
  (format #t "~T~Tevent-up: ~A~%" (-> obj event-up))
  (format #t "~T~Tanim-speed: ~f~%" (-> obj anim-speed))
  (format #t "~T~Tmove-to-pos: #<vector @ #x~X>~%" (-> obj move-to-pos))
  (format #t "~T~Tmove-to-quat: #<quaternion @ #x~X>~%" (-> obj move-to-quat))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *generic-button-sg* generic-button generic-button-lod0-jg generic-button-idle-ja
              ((generic-button-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 3)
              )

;; definition for method 30 of type basebutton
;; INFO: Used lq/sq
(defmethod move-to-vec-or-quat! basebutton ((obj basebutton) (arg0 vector) (arg1 quaternion))
  (set! (-> obj move-to?) #t)
  (if arg0
      (set! (-> obj move-to-pos quad) (-> arg0 quad))
      (set! (-> obj move-to-pos quad) (-> obj root-override trans quad))
      )
  (if arg1
      (quaternion-copy! (-> obj move-to-quat) arg1)
      (quaternion-copy! (-> obj move-to-quat) (-> obj root-override quat))
      )
  )

;; failed to figure out what this is:
(defstate basebutton-startup (basebutton)
  :virtual #t
  :code (behavior ()
    (if (-> self down?)
        (go-virtual basebutton-down-idle)
        (go-virtual basebutton-up-idle)
        )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate basebutton-up-idle (basebutton)
  :virtual #t
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('attack)
       (case (-> arg3 param 1)
         (('flop)
          (TODO-RENAME-29 self (-> self event-going-down) (-> self notify-actor))
          (sound-play "silo-button")
          (go-virtual basebutton-going-down)
          )
         )
       )
      (('trigger)
       (sound-play "silo-button")
       (go-virtual basebutton-going-down)
       )
      (('move-to)
       (move-to-vec-or-quat! self (the-as vector (-> arg3 param 0)) (the-as quaternion (-> arg3 param 1)))
       )
      )
    )
  :enter (behavior ()
    (press! self #f)
    (none)
    )
  :trans (behavior ()
    (if (-> self move-to?)
        (rider-trans)
        )
    (none)
    )
  :code (the-as (function none :behavior basebutton) anim-loop)
  :post (behavior ()
    (when (-> self move-to?)
      (set! (-> self move-to?) #f)
      (set! (-> self root-override trans quad) (-> self move-to-pos quad))
      (quaternion-copy! (-> self root-override quat) (-> self move-to-quat))
      (rider-post)
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate basebutton-going-down (basebutton)
  :virtual #t
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('untrigger)
       (sound-play "silo-button")
       (go-virtual basebutton-going-up)
       )
      (('move-to)
       (move-to-vec-or-quat! self (the-as vector (-> arg3 param 0)) (the-as quaternion (-> arg3 param 1)))
       )
      )
    )
  :enter (behavior ()
    (press! self #t)
    (none)
    )
  :trans (the-as (function none :behavior basebutton) rider-trans)
  :code (behavior ()
    (ja-no-eval :num! (seek! max (-> self anim-speed)))
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! max (-> self anim-speed)))
      )
    (TODO-RENAME-29 self (-> self event-down) (-> self notify-actor))
    (go-virtual basebutton-down-idle)
    (none)
    )
  :post (behavior ()
    (when (-> self move-to?)
      (set! (-> self move-to?) #f)
      (set! (-> self root-override trans quad) (-> self move-to-pos quad))
      (quaternion-copy! (-> self root-override quat) (-> self move-to-quat))
      )
    (rider-post)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate basebutton-down-idle (basebutton)
  :virtual #t
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('untrigger)
       (sound-play "silo-button")
       (go-virtual basebutton-going-up)
       )
      (('move-to)
       (move-to-vec-or-quat! self (the-as vector (-> arg3 param 0)) (the-as quaternion (-> arg3 param 1)))
       )
      )
    )
  :enter (behavior ()
    (press! self #t)
    (none)
    )
  :trans (behavior ()
    (if (-> self move-to?)
        (rider-trans)
        )
    (none)
    )
  :code (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (cond
      ((= (-> self timeout) 0.0)
       (anim-loop)
       )
      (else
        (until (>= (- (-> *display* base-frame-counter) (-> self state-time)) (the int (* 300.0 (-> self timeout))))
          (suspend)
          )
        (TODO-RENAME-29 self (-> self event-going-up) (-> self notify-actor))
        (sound-play "silo-button")
        (go-virtual basebutton-going-up)
        )
      )
    (none)
    )
  :post (behavior ()
    (when (-> self move-to?)
      (set! (-> self move-to?) #f)
      (set! (-> self root-override trans quad) (-> self move-to-pos quad))
      (quaternion-copy! (-> self root-override quat) (-> self move-to-quat))
      (rider-post)
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate basebutton-going-up (basebutton)
  :virtual #t
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('move-to)
       (move-to-vec-or-quat! self (the-as vector (-> arg3 param 0)) (the-as quaternion (-> arg3 param 1)))
       )
      (('trigger)
       (sound-play "silo-button")
       (go-virtual basebutton-going-down)
       )
      )
    )
  :enter (behavior ()
    (press! self #f)
    (none)
    )
  :trans (the-as (function none :behavior basebutton) rider-trans)
  :code (behavior ()
    (ja-no-eval :num! (seek! 0.0 (-> self anim-speed)))
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! 0.0 (-> self anim-speed)))
      )
    (TODO-RENAME-29 self (-> self event-up) (-> self notify-actor))
    (go-virtual basebutton-up-idle)
    (none)
    )
  :post (behavior ()
    (when (-> self move-to?)
      (set! (-> self move-to?) #f)
      (set! (-> self root-override trans quad) (-> self move-to-pos quad))
      (quaternion-copy! (-> self root-override quat) (-> self move-to-quat))
      )
    (rider-post)
    (none)
    )
  )

;; definition for method 31 of type basebutton
(defmethod press! basebutton ((obj basebutton) (arg0 symbol))
  (set! (-> obj down?) arg0)
  (cond
    (arg0
      (if (not (-> obj spawned-by-other?))
          (process-entity-status! obj (entity-perm-status complete) #t)
          )
      )
    (else
      (if (not (-> obj spawned-by-other?))
          (process-entity-status! obj (entity-perm-status complete) #f)
          )
      )
    )
  )

;; definition for method 29 of type basebutton
(defmethod TODO-RENAME-29 basebutton ((obj basebutton) (arg0 symbol) (arg1 entity))
  (with-pp
    (when arg0
      (cond
        (arg1
          (let ((v1-0 (new 'stack-no-clear 'event-message-block)))
            (set! (-> v1-0 from) pp)
            (set! (-> v1-0 num-params) 0)
            (set! (-> v1-0 message) arg0)
            (let ((a1-1 arg1))
              (send-event-function
                (if a1-1
                    (-> a1-1 extra process)
                    )
                v1-0
                )
              )
            )
          )
        (else
          (if (nonzero? (-> obj link))
              (send-to-all (-> obj link) arg0)
              )
          )
        )
      )
    (none)
    )
  )

;; definition for method 25 of type basebutton
(defmethod reset! basebutton ((obj basebutton))
  (set! (-> obj down?) #f)
  (set! (-> obj spawned-by-other?) #t)
  (set! (-> obj move-to?) #f)
  (set! (-> obj notify-actor) #f)
  (set! (-> obj timeout) 0.0)
  (set! (-> obj event-going-down) #f)
  (set! (-> obj event-down) #f)
  (set! (-> obj event-going-up) #f)
  (set! (-> obj event-up) #f)
  (let ((f0-1 1.0))
    (set! (-> obj anim-speed) f0-1)
    f0-1
    )
  )

;; definition for method 28 of type basebutton
(defmethod arm-trigger-event! basebutton ((obj basebutton))
  (let ((v0-0 'trigger))
    (set! (-> obj event-going-down) v0-0)
    v0-0
    )
  )

;; definition for method 26 of type basebutton
(defmethod TODO-RENAME-26 basebutton ((obj basebutton))
  (initialize-skeleton obj *generic-button-sg* '())
  (logior! (-> obj skel status) (janim-status inited))
  (ja-channel-set! 1)
  (cond
    ((-> obj down?)
     (let ((s5-0 (-> obj skel root-channel 0)))
       (joint-control-channel-group-eval!
         s5-0
         (the-as art-joint-anim (-> obj draw art-group data 2))
         num-func-identity
         )
       (set! (-> s5-0 frame-num)
             (the float (+ (-> (the-as art-joint-anim (-> obj draw art-group data 2)) data 0 length) -1))
             )
       )
     )
    (else
      (let ((s5-1 (-> obj skel root-channel 0)))
        (joint-control-channel-group-eval!
          s5-1
          (the-as art-joint-anim (-> obj draw art-group data 2))
          num-func-identity
          )
        (set! (-> s5-1 frame-num) 0.0)
        )
      )
    )
  (set! (-> obj anim-speed) 2.0)
  (update-transforms! (-> obj root-override))
  (ja-post)
  (none)
  )

;; definition for method 27 of type basebutton
(defmethod TODO-RENAME-27 basebutton ((obj basebutton))
  (let ((s5-0 (new 'process 'collide-shape-moving obj (collide-list-enum hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) default-collision-reaction)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (alloc-riders s5-0 1)
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
      (set! (-> s4-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s4-0 collide-with) (collide-kind target))
      (set! (-> s4-0 prim-core action) (collide-action solid ca-1))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 12288.0)
      (set-root-prim! s5-0 s4-0)
      (let ((s3-0 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
        (set! (-> s3-0 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s3-0 collide-with) (collide-kind target))
        (set! (-> s3-0 prim-core action) (collide-action solid ca-1))
        (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
        (set! (-> s3-0 transform-index) 4)
        (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 12288.0)
        (append-prim s4-0 s3-0)
        )
      (let ((s3-1 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 1) (the-as uint 0))))
        (set! (-> s3-1 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s3-1 collide-with) (collide-kind target))
        (set! (-> s3-1 prim-core action) (collide-action solid ca-1))
        (set! (-> s3-1 prim-core offense) (collide-offense indestructible))
        (set! (-> s3-1 transform-index) 3)
        (set-vector! (-> s3-1 local-sphere) 0.0 0.0 0.0 12288.0)
        (append-prim s4-0 s3-1)
        )
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (backup-collide-with-as s5-0)
    (set! (-> obj root-override) s5-0)
    s5-0
    )
  )

;; definition for method 11 of type basebutton
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! basebutton ((obj basebutton) (arg0 entity-actor))
  (reset! obj)
  (set! (-> obj spawned-by-other?) #f)
  (set! (-> obj button-id) -1)
  (let ((v1-4 (res-lump-value (-> obj entity) 'extra-id uint128 :default (the-as uint128 -1))))
    (if (>= (the-as int v1-4) 0)
        (set! (-> obj button-id) (the-as int v1-4))
        )
    )
  (when (or (res-lump-struct arg0 'next-actor structure) (res-lump-struct arg0 'prev-actor structure))
    (set! (-> obj link) (new 'process 'actor-link-info obj))
    (if (< (-> obj button-id) 0)
        (set! (-> obj button-id) (actor-count-before (-> obj link)))
        )
    )
  (TODO-RENAME-27 obj)
  (process-drawable-from-entity! obj arg0)
  (let ((v1-16 #f))
    (if (and (-> obj entity) (logtest? (-> obj entity extra perm status) (entity-perm-status complete)))
        (set! v1-16 #t)
        )
    (set! (-> obj down?) v1-16)
    )
  (set! (-> obj notify-actor) (entity-actor-lookup arg0 'alt-actor 0))
  (set! (-> obj timeout) (res-lump-float arg0 'timeout))
  (if (not (-> obj spawned-by-other?))
      (nav-mesh-connect obj (-> obj root-override) (the-as nav-control #f))
      )
  (arm-trigger-event! obj)
  (TODO-RENAME-26 obj)
  (go (method-of-object obj basebutton-startup))
  (none)
  )

;; definition for function basebutton-init-by-other
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defbehavior basebutton-init-by-other basebutton ((arg0 entity-actor) (arg1 vector) (arg2 quaternion) (arg3 entity-actor) (arg4 symbol) (arg5 float))
  (reset! self)
  (set! (-> self spawned-by-other?) #t)
  (set! (-> self button-id) -1)
  (set! (-> self down?) arg4)
  (set! (-> self notify-actor) arg3)
  (set! (-> self timeout) arg5)
  (if arg0
      (set! (-> self entity) arg0)
      )
  (TODO-RENAME-27 self)
  (set! (-> self root-override trans quad) (-> arg1 quad))
  (quaternion-copy! (-> self root-override quat) arg2)
  (set-vector! (-> self root-override scale) 1.0 1.0 1.0 1.0)
  (arm-trigger-event! self)
  (TODO-RENAME-26 self)
  (go-virtual basebutton-startup)
  (none)
  )

;; definition for symbol *warp-info*, type (array string)
(define *warp-info* (the-as (array string) (new 'static 'boxed-array :type string
                                             "training-warp"
                                             "village1-warp"
                                             "village2-warp"
                                             "village3-warp"
                                             "citadel-warp"
                                             )
                                           )
        )

;; definition of type warp-gate
(deftype warp-gate (process-drawable)
  ((level      symbol  :offset-assert 176)
   (level-slot int32   :offset-assert 180)
   (min-slot   int32   :offset-assert 184)
   (max-slot   int32   :offset-assert 188)
   )
  :heap-base #x50
  :method-count-assert 24
  :size-assert         #xc0
  :flag-assert         #x18005000c0
  (:methods
    (idle () _type_ :state 20)
    (active () _type_ :state 21)
    (use (int level) _type_ :state 22)
    (hidden () _type_ :state 23)
    )
  )

;; definition for method 3 of type warp-gate
(defmethod inspect warp-gate ((obj warp-gate))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tlevel: ~A~%" (-> obj level))
  (format #t "~T~Tlevel-slot: ~D~%" (-> obj level-slot))
  (format #t "~T~Tmin-slot: ~D~%" (-> obj min-slot))
  (format #t "~T~Tmax-slot: ~D~%" (-> obj max-slot))
  obj
  )

;; failed to figure out what this is:
(defstate use (warp-gate)
  :virtual #t
  :trans (behavior ()
    (send-event *camera* 'joystick 0.0 0.0)
    (none)
    )
  :code (behavior ((arg0 int) (arg1 level))
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (when (not arg1)
      (process-release? *target*)
      (go-virtual idle)
      )
    (let ((s4-0 (new 'stack-no-clear 'event-message-block)))
      (set! (-> s4-0 from) self)
      (set! (-> s4-0 num-params) 3)
      (set! (-> s4-0 message) 'change-state)
      (set! (-> s4-0 param 0) (the-as uint target-warp-out))
      (let ((v1-9 (new 'static 'vector)))
        (set! (-> v1-9 quad) (-> self root trans quad))
        (set! (-> s4-0 param 1) (the-as uint v1-9))
        )
      (set! (-> s4-0 param 2) (the-as uint (target-pos 0)))
      (send-event-function *target* s4-0)
      )
    (case (-> self level)
      (('citadel 'lavatube)
       (while (and *target* (zero? (logand (-> *target* draw status) (draw-status hidden))))
         (suspend)
         )
       )
      (else
        (load-state-want-levels (-> self level) (-> arg1 load-name))
        (while (or (not (member (level-status *level* (-> arg1 load-name)) '(loaded active)))
                   (< (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 2))
                   )
          (suspend)
          )
        )
      )
    (set-blackout-frames (seconds 0.05))
    (start 'play (get-continue-by-name *game-info* (-> *warp-info* arg0)))
    (logior! (-> self mask) (process-mask sleep))
    (suspend)
    0
    (none)
    )
  )

;; definition for symbol *warp-jump-mods*, type surface
(define *warp-jump-mods* (new 'static 'surface
                           :name 'jump
                           :turnv 273066.66
                           :turnvv 1820444.5
                           :tiltv 32768.0
                           :tiltvv 131072.0
                           :transv-max 65536.0
                           :target-speed 65536.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 always-rotate-toward-transv)
                           )
        )

;; failed to figure out what this is:
(defstate target-warp-out (target)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('death-end)
       (let ((v0-0 (the-as object (logior (-> self draw status) (draw-status hidden)))))
         (set! (-> self draw status) (the-as draw-status v0-0))
         v0-0
         )
       )
      (else
        (target-generic-event-handler arg0 arg1 arg2 arg3)
        )
      )
    )
  :enter (behavior ((arg0 vector) (arg1 vector))
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (logclear! (-> self control status) (cshape-moving-flags onsurf onground tsurf))
    (set! (-> self control unknown-surface00) *warp-jump-mods*)
    (set! (-> self control unknown-vector102 quad) (-> arg0 quad))
    (set! (-> self control unknown-vector103 quad) (-> arg1 quad))
    (set! (-> self control unknown-vector102 y) (+ -4096.0 (-> self control unknown-vector102 y)))
    (set! (-> self control unknown-uint20) (the-as uint #f))
    (vector-reset! (-> self control transv))
    (logior! (-> self state-flags) (state-flags use-alt-cam-pos))
    (set! (-> self alt-cam-pos quad) (-> arg1 quad))
    (none)
    )
  :exit (behavior ()
    (logclear! (-> self state-flags) (state-flags use-alt-cam-pos))
    (none)
    )
  :code (behavior ((arg0 vector) (arg1 vector))
    (send-event *camera* 'change-state cam-fixed 0)
    (ja-channel-push! 1 (seconds 0.2))
    (ja-no-eval :group! eichar-duck-high-jump-ja :num! (seek! (ja-aframe 16.0 0)) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! (ja-aframe 16.0 0)))
      )
    (vector-! (-> self control transv) (-> self control unknown-vector102) (-> self control trans))
    (vector-xz-normalize! (-> self control transv) 32768.0)
    (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-4
               (- (sqrtf
                    (* 2.0
                       (-> self control dynam gravity-length)
                       (vector-dot
                         (-> self control dynam gravity-normal)
                         (vector-! (new 'stack-no-clear 'vector) (-> self control unknown-vector102) (-> self control trans))
                         )
                       )
                    )
                  (* 0.008333334 (- (-> self control dynam gravity-length)))
                  )
               )
             )
        (vector+!
          (-> self control transv)
          (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f2-4)
          (vector-float*! gp-2 gp-2 (/ f0-7 f1-1))
          )
        )
      )
    (clear-collide-with-as (-> self control))
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self trans-hook)
          (lambda :behavior target
            ()
            (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-3 (vector-length gp-0))
                     (f1-0 f0-3)
                     )
                (if (< f30-0 0.0)
                    (set! f30-0 8192.0)
                    )
                (vector+!
                  (-> self control transv)
                  (vector-float*! (-> self control transv) (-> self control dynam gravity-normal) f30-0)
                  (vector-float*! gp-0 gp-0 (/ f0-3 f1-0))
                  )
                )
              )
            (let ((gp-2 (vector-! (new-stack-vector0) (-> self control unknown-vector102) (-> self control trans))))
              (set! (-> gp-2 y) 0.0)
              (send-event *target* 'sidekick #f)
              (when (and (or (< (vector-dot gp-2 (-> self control transv)) 0.0) (-> self control unknown-spoolanim00))
                         (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.05))
                         )
                (vector-seek! (-> self draw color-mult) (new 'static 'vector) (* 2.0 (-> *display* seconds-per-frame)))
                (set! (-> self control transv x) (* 0.95 (-> self control transv x)))
                (set! (-> self control transv z) (* 0.95 (-> self control transv z)))
                (when (not (-> self control unknown-spoolanim00))
                  (send-event self 'do-effect 'death-warp-out -1.0)
                  (let ((v0-2 #t))
                    (set! (-> self control unknown-uint20) (the-as uint v0-2))
                    v0-2
                    )
                  )
                )
              )
            )
          )
    (ja-no-eval :group! eichar-duck-high-jump-ja :num! (seek! (ja-aframe 40.0 0)) :frame-num (ja-aframe 16.0 0))
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! (ja-aframe 40.0 0)))
      )
    (anim-loop)
    (none)
    )
  :post target-no-stick-post
  )
