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

(import "goal_src/jak1/import/snow-bunny-ag.gc")

;; definition of type snow-bunny
(deftype snow-bunny (nav-enemy)
  ((patrol-rand-distraction int32              :offset-assert 400)
   (base-hop-dist           float              :offset-assert 404)
   (halfway-dist            float              :offset-assert 408)
   (retreat-timeout         float              :offset-assert 412)
   (gnd-popup               float              :offset-assert 416)
   (jump-height-min         float              :offset-assert 420)
   (jump-height-factor      float              :offset-assert 424)
   (jump-anim-start-frame   float              :offset-assert 428)
   (defense                 uint64             :offset-assert 432)
   (retreat-timeout-time    time-frame         :offset-assert 440)
   (last-nondangerous-time  time-frame         :offset-assert 448)
   (patrol-hop-failed?      basic              :offset-assert 456)
   (should-retreat?         basic              :offset-assert 460)
   (got-jump-event?         symbol             :offset-assert 464)
   (using-jump-event?       basic              :offset-assert 468)
   (jump-anim               int8               :offset-assert 472)
   (notice-land-anim        int8               :offset-assert 473)
   (attack-anim             int8               :offset-assert 474)
   (final-dest              vector     :inline :offset-assert 480)
   (jump-event-dest         vector     :inline :offset-assert 496)
   )
  :heap-base #x190
  :method-count-assert 77
  :size-assert         #x200
  :flag-assert         #x4d01900200
  (:methods
    (dummy-51 (_type_ vector vector) symbol :replace 51)
    (dummy-52 (_type_) symbol :replace 52)
    (dummy-54 (_type_) symbol :replace 54)
    (dummy-57 (_type_) symbol :replace 57)
    (dummy-60 (_type_) none :replace 60)
    (dummy-76 (_type_ symbol) none 76)
    )
  )

;; definition for method 3 of type snow-bunny
(defmethod inspect snow-bunny ((obj snow-bunny))
  (let ((t9-0 (method-of-type nav-enemy inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tpatrol-rand-distraction: ~D~%" (-> obj patrol-rand-distraction))
  (format #t "~T~Tbase-hop-dist: ~f~%" (-> obj base-hop-dist))
  (format #t "~T~Thalfway-dist: ~f~%" (-> obj halfway-dist))
  (format #t "~T~Tretreat-timeout: ~f~%" (-> obj retreat-timeout))
  (format #t "~T~Tgnd-popup: ~f~%" (-> obj gnd-popup))
  (format #t "~T~Tjump-height-min: ~f~%" (-> obj jump-height-min))
  (format #t "~T~Tjump-height-factor: ~f~%" (-> obj jump-height-factor))
  (format #t "~T~Tjump-anim-start-frame: ~f~%" (-> obj jump-anim-start-frame))
  (format #t "~T~Tdefense: ~D~%" (-> obj defense))
  (format #t "~T~Tretreat-timeout-time: ~D~%" (-> obj retreat-timeout-time))
  (format #t "~T~Tlast-nondangerous-time: ~D~%" (-> obj last-nondangerous-time))
  (format #t "~T~Tpatrol-hop-failed?: ~A~%" (-> obj patrol-hop-failed?))
  (format #t "~T~Tshould-retreat?: ~A~%" (-> obj should-retreat?))
  (format #t "~T~Tgot-jump-event?: ~A~%" (-> obj got-jump-event?))
  (format #t "~T~Tusing-jump-event?: ~A~%" (-> obj using-jump-event?))
  (format #t "~T~Tjump-anim: ~D~%" (-> obj jump-anim))
  (format #t "~T~Tnotice-land-anim: ~D~%" (-> obj notice-land-anim))
  (format #t "~T~Tattack-anim: ~D~%" (-> obj attack-anim))
  (format #t "~T~Tfinal-dest: #<vector @ #x~X>~%" (-> obj final-dest))
  (format #t "~T~Tjump-event-dest: #<vector @ #x~X>~%" (-> obj jump-event-dest))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *snow-bunny-sg* snow-bunny snow-bunny-lod0-jg snow-bunny-idle-ja
              ((snow-bunny-lod0-mg (meters 20)) (snow-bunny-lod1-mg (meters 40)) (snow-bunny-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 0.25 0 2)
              :shadow snow-bunny-shadow-mg
              )

;; definition for symbol *snow-bunny-nav-enemy-info*, type nav-enemy-info
(define *snow-bunny-nav-enemy-info* (new 'static 'nav-enemy-info
                                      :idle-anim 5
                                      :walk-anim 5
                                      :turn-anim 5
                                      :notice-anim 9
                                      :run-anim 5
                                      :jump-anim 7
                                      :jump-land-anim 10
                                      :victory-anim 9
                                      :taunt-anim 9
                                      :die-anim 11
                                      :neck-joint 5
                                      :player-look-at-joint 5
                                      :run-travel-speed (meters 6)
                                      :run-rotate-speed (degrees 2880.0)
                                      :run-acceleration (meters 1)
                                      :run-turn-time (seconds 0.1)
                                      :walk-travel-speed (meters 4)
                                      :walk-rotate-speed (degrees 720.0)
                                      :walk-acceleration (meters 1)
                                      :walk-turn-time (seconds 0.5)
                                      :shadow-size (meters 2)
                                      :notice-nav-radius (meters 1.2)
                                      :nav-nearest-y-threshold (meters 10)
                                      :notice-distance (meters 30)
                                      :stop-chase-distance (meters 40)
                                      :frustration-distance (meters 8)
                                      :frustration-time (seconds 4)
                                      :die-anim-hold-frame 31.0
                                      :jump-anim-start-frame 11.0
                                      :jump-land-anim-end-frame 10000000000.0
                                      :jump-height-min (meters 1)
                                      :jump-height-factor 0.6
                                      :jump-start-anim-speed 1.0
                                      :shadow-max-y (meters 0.25)
                                      :shadow-min-y (meters -4)
                                      :shadow-locus-dist (meters 150)
                                      :use-align #f
                                      :draw-shadow #t
                                      :move-to-ground #t
                                      :hover-if-no-ground #f
                                      :use-momentum #f
                                      :use-flee #f
                                      :use-proximity-notice #f
                                      :use-jump-blocked #f
                                      :use-jump-patrol #f
                                      :gnd-collide-with (collide-kind background)
                                      :debug-draw-neck #f
                                      :debug-draw-jump #f
                                      )
        )

;; definition for function snow-bunny-default-event-handler
;; INFO: Used lq/sq
(defbehavior snow-bunny-default-event-handler snow-bunny ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('attack)
     (nav-enemy-set-hit-from-direction arg0)
     (go-virtual nav-enemy-die)
     )
    (('touch)
     (when (send-event arg0 'attack (-> arg3 param 0) (new 'static 'attack-info))
       (set! (-> self touch-time) (-> *display* base-frame-counter))
       (set-collide-offense (-> self collide-info) 2 (collide-offense no-offense))
       (logior! (-> self nav-enemy-flags) (nav-enemy-flags navenmf8))
       (go-virtual snow-bunny-attack)
       )
     )
    (('jump)
     (let ((v1-16 (the-as object (-> arg3 param 0))))
       (set! (-> self got-jump-event?) #t)
       (let ((v0-1 (the-as object (-> self jump-event-dest))))
         (set! (-> (the-as vector v0-1) quad) (-> (the-as vector v1-16) quad))
         v0-1
         )
       )
     )
    )
  )

;; definition for method 76 of type snow-bunny
;; INFO: Return type mismatch int vs none.
(defmethod dummy-76 snow-bunny ((obj snow-bunny) (arg0 symbol))
  (let ((f0-0 -4096.0))
    (if arg0
        (set! f0-0 -20480.0)
        )
    (let ((v1-3 (-> obj draw shadow-ctrl)))
      (set! (-> v1-3 settings bot-plane w) (- f0-0))
      )
    )
  0
  (none)
  )

;; definition for method 47 of type snow-bunny
;; INFO: Return type mismatch int vs none.
(defmethod initialize-collision snow-bunny ((obj snow-bunny))
  (let ((s5-0 (new 'process 'collide-shape-moving obj (collide-list-enum usually-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)
          )
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 3) 0)))
      (set! (-> s4-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s4-0 collide-with) (collide-kind target))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 3686.4 0.0 5324.8)
      (set-root-prim! s5-0 s4-0)
      (let ((s3-0 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 3))))
        (set! (-> s3-0 prim-core collide-as) (collide-kind enemy))
        (set! (-> s3-0 collide-with) (collide-kind target))
        (set! (-> s3-0 prim-core action) (collide-action solid))
        (set! (-> s3-0 prim-core offense) (collide-offense touch))
        (set-vector! (-> s3-0 local-sphere) 0.0 1638.4 0.0 1843.2)
        (append-prim s4-0 s3-0)
        )
      (let ((s3-1 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 3))))
        (set! (-> s3-1 prim-core collide-as) (collide-kind enemy))
        (set! (-> s3-1 collide-with) (collide-kind target))
        (set! (-> s3-1 prim-core action) (collide-action solid))
        (set! (-> s3-1 prim-core offense) (collide-offense touch))
        (set-vector! (-> s3-1 local-sphere) 0.0 4096.0 0.0 1843.2)
        (append-prim s4-0 s3-1)
        )
      (let ((s3-2 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 1))))
        (set! (-> s3-2 prim-core collide-as) (collide-kind enemy))
        (set! (-> s3-2 collide-with) (collide-kind target))
        (set! (-> s3-2 prim-core offense) (collide-offense normal-attack))
        (set! (-> s3-2 transform-index) 6)
        (set-vector! (-> s3-2 local-sphere) 0.0 0.0 0.0 2457.6)
        (append-prim s4-0 s3-2)
        )
      )
    (set! (-> s5-0 nav-radius) 2048.0)
    (backup-collide-with-as s5-0)
    (set! (-> s5-0 max-iteration-count) (the-as uint 2))
    (set! (-> obj collide-info) s5-0)
    )
  0
  (none)
  )

;; definition for method 60 of type snow-bunny
;; INFO: Return type mismatch int vs none.
(defmethod dummy-60 snow-bunny ((obj snow-bunny))
  (initialize-skeleton obj *snow-bunny-sg* '())
  (set! (-> obj draw origin-joint-index) (the-as uint 3))
  (none)
  )

;; definition for method 48 of type snow-bunny
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-48 snow-bunny ((obj snow-bunny))
  (dummy-60 obj)
  (TODO-RENAME-45 obj *snow-bunny-nav-enemy-info*)
  (logclear! (-> obj draw shadow-ctrl settings flags) (shadow-flags shdf03))
  (cond
    ((zero? (res-lump-value (-> obj entity) 'mode uint128))
     (set! (-> obj defense) (the-as uint 1))
     (set! (-> obj retreat-timeout) 5.0)
     )
    (else
      (set! (-> obj defense) (the-as uint 0))
      (set! (-> obj retreat-timeout) 0.1)
      )
    )
  (set! (-> obj last-nondangerous-time) (-> *display* base-frame-counter))
  (set! (-> obj gnd-popup) 16384.0)
  (set! (-> obj got-jump-event?) #f)
  (set! (-> obj notice-land-anim) 10)
  (set! (-> obj attack-anim) 6)
  (set! (-> obj neck up) (the-as uint 1))
  (set! (-> obj neck nose) (the-as uint 2))
  (set! (-> obj neck ear) (the-as uint 0))
  (set! (-> obj patrol-rand-distraction) (+ (nav-enemy-rnd-int-count 5) 1))
  (set! (-> obj patrol-hop-failed?) #f)
  0
  (none)
  )

;; definition for method 11 of type snow-bunny
(defmethod init-from-entity! snow-bunny ((obj snow-bunny) (arg0 entity-actor))
  (initialize-collision obj)
  (process-drawable-from-entity! obj arg0)
  (TODO-RENAME-48 obj)
  (if (<= (-> obj path curve num-cverts) 0)
      (go process-drawable-art-error "no path")
      )
  (set! *snow-bunny* (the-as (pointer snow-bunny) (process->ppointer obj)))
  (TODO-RENAME-59 obj)
  (none)
  )

;; definition for method 58 of type snow-bunny
;; INFO: Return type mismatch time-frame vs none.
(defmethod dummy-58 snow-bunny ((obj snow-bunny))
  (if (zero? (logand (-> *target* state-flags) (state-flags dangerous)))
      (set! (-> obj last-nondangerous-time) (-> *display* base-frame-counter))
      )
  (none)
  )

;; definition for function snow-bunny-initialize-jump
;; INFO: Return type mismatch int vs none.
(defbehavior snow-bunny-initialize-jump snow-bunny ((arg0 vector))
  (nav-enemy-initialize-custom-jump arg0 #f (-> self jump-height-min) (-> self jump-height-factor) -307200.0)
  (logclear! (-> self nav-enemy-flags) (nav-enemy-flags drop-jump))
  (logior! (-> self nav-enemy-flags) (nav-enemy-flags standing-jump))
  0
  (none)
  )

;; definition for function snow-bunny-execute-jump
;; INFO: Return type mismatch int vs none.
(defbehavior snow-bunny-execute-jump snow-bunny ()
  (nav-enemy-execute-custom-jump (-> self jump-anim) (-> self jump-anim-start-frame) 1.0)
  0
  (none)
  )

;; definition for method 56 of type snow-bunny
;; INFO: Return type mismatch float vs none.
(defmethod set-jump-height-factor! snow-bunny ((obj snow-bunny) (arg0 int))
  (let ((v1-0 arg0))
    (cond
      ((zero? v1-0)
       (set! (-> obj jump-anim) 8)
       (set! (-> obj jump-height-min) 4096.0)
       (set! (-> obj jump-height-factor) 0.6)
       (set! (-> obj jump-anim-start-frame) 4.0)
       )
      ((= v1-0 1)
       (set! (-> obj jump-anim) 7)
       (set! (-> obj jump-height-min) 4096.0)
       (set! (-> obj jump-height-factor) 0.6)
       (set! (-> obj jump-anim-start-frame) 11.0)
       )
      ((= v1-0 2)
       (set! (-> obj jump-anim) 7)
       (set! (-> obj jump-height-min) 4096.0)
       (set! (-> obj jump-height-factor) 0.4)
       (set! (-> obj jump-anim-start-frame) 11.0)
       )
      )
    )
  (none)
  )

;; definition for method 57 of type snow-bunny
(defmethod dummy-57 snow-bunny ((obj snow-bunny))
  (if (or (not *target*) (zero? (logand (-> *target* state-flags) (state-flags dangerous))))
      (return #f)
      )
  (let ((f0-0 (vector-vector-xz-distance (target-pos 0) (-> obj collide-info trans))))
    (if (< 73728.0 f0-0)
        (return #f)
        )
    (let* ((f0-1 (- f0-0 (-> *TARGET-bank* spin-radius)))
           (f0-2 (+ -2457.6 f0-1))
           )
      (if (>= 40.96 f0-2)
          (set! f0-2 40.96)
          )
      (let ((v1-13 (the int (/ f0-2 (* (-> obj nav-info run-travel-speed) (-> *display* seconds-per-frame))))))
        (if (<= (- (- (seconds 0.36) (- (-> *display* base-frame-counter) (-> obj last-nondangerous-time)))
                   (the-as time-frame v1-13)
                   )
                0
                )
            (return #f)
            )
        )
      )
    )
  #t
  )

;; failed to figure out what this is:
(defstate snow-bunny-tune-spheres (snow-bunny)
  :virtual override
  :code (behavior ()
    0
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) transform-post)
  )

;; failed to figure out what this is:
(defstate nav-enemy-idle (snow-bunny)
  :virtual #t
  :enter (behavior ()
    (dummy-76 self #f)
    (let ((t9-1 (-> (method-of-type nav-enemy nav-enemy-idle) enter)))
      (if t9-1
          (t9-1)
          )
      )
    (none)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.1))
    (ja :group! (-> self draw art-group data (-> self nav-info idle-anim))
        :num! (identity (rand-vu-float-range 0.0 (the float (+ (-> (ja-group) data 0 length) -1))))
        )
    (let ((f30-0 (nav-enemy-rnd-float-range 0.75 1.25)))
      (loop
        (suspend)
        (ja :num! (loop! f30-0))
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-patrol (snow-bunny)
  :virtual #t
  :enter (the-as (function none :behavior snow-bunny) #f)
  :trans (the-as (function none :behavior snow-bunny) #f)
  :code (behavior ()
    (go-virtual snow-bunny-nav-resume)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate snow-bunny-nav-resume (snow-bunny)
  :virtual override
  :code (behavior ()
    (cond
      (*target*
        (let ((f0-0 (vector-vector-distance (target-pos 0) (-> self collide-info trans))))
          (cond
            ((>= f0-0 (-> self enemy-info idle-distance))
             (go-virtual nav-enemy-idle)
             )
            ((< (-> self nav-info notice-distance) f0-0)
             (go-virtual snow-bunny-patrol-idle)
             )
            ((TODO-RENAME-46 self (-> self nav-info notice-distance))
             (go-virtual nav-enemy-notice)
             )
            (else
              (go-virtual snow-bunny-patrol-idle)
              )
            )
          )
        )
      (else
        (go-virtual nav-enemy-idle)
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate snow-bunny-patrol-idle (snow-bunny)
  :virtual override
  :event snow-bunny-default-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (dummy-76 self #f)
    (set! (-> self nav flags) (logior (nav-control-flags navcf19) (-> self nav flags)))
    (logclear! (-> self nav-enemy-flags) (nav-enemy-flags navenmf2))
    (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-rotate))
    (set! (-> self state-timeout) (seconds 0.1))
    (none)
    )
  :trans (behavior ()
    (if (dummy-57 self)
        (go-virtual snow-bunny-defend)
        )
    (when (>= (- (-> *display* base-frame-counter) (-> self state-time)) (-> self state-timeout))
      (if (not *target*)
          (go-virtual nav-enemy-idle)
          )
      (cond
        ((>= (vector-vector-distance (target-pos 0) (-> self collide-info trans)) (-> self enemy-info idle-distance))
         (go-virtual nav-enemy-idle)
         )
        ((nav-enemy-notice-player?)
         (go-virtual nav-enemy-notice)
         )
        )
      )
    (dummy-58 self)
    (none)
    )
  :code (behavior ()
    (let ((gp-0 (nav-enemy-rnd-int-count 3)))
      (when (and (not (-> self patrol-hop-failed?)) (zero? gp-0))
        (if (dummy-53 self)
            (go-virtual snow-bunny-patrol-hop)
            )
        )
      (set! (-> self patrol-hop-failed?) #f)
      (let ((gp-2 (min gp-0 (nav-enemy-rnd-int-count 3))))
        (ja-channel-push! 1 (seconds 0.1))
        (ja :group! (-> self draw art-group data (-> self nav-info idle-anim))
            :num! (identity (rand-vu-float-range 0.0 (the float (+ (-> (ja-group) data 0 length) -1))))
            )
        (loop
          (let ((s5-1 (-> *display* base-frame-counter)))
            (until (>= (- (-> *display* base-frame-counter) s5-1) (seconds 2.52))
              (suspend)
              (ja :num! (loop!))
              )
            )
          (cond
            ((zero? gp-2)
             (if (dummy-53 self)
                 (go-virtual snow-bunny-patrol-hop)
                 )
             )
            (else
              (+! gp-2 -1)
              )
            )
          )
        )
      )
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) nav-enemy-simple-post)
  )

;; definition for method 51 of type snow-bunny
;; INFO: Used lq/sq
(defmethod dummy-51 snow-bunny ((obj snow-bunny) (arg0 vector) (arg1 vector))
  (let ((s5-0 (new 'stack-no-clear 'vector)))
    (let* ((s4-0 (new 'stack-no-clear 'collide-tri-result))
           (f0-0 (-> obj gnd-popup))
           (f30-0 (+ f0-0 40960.0))
           )
      (set! (-> s5-0 quad) (-> arg0 quad))
      (+! (-> s5-0 y) f0-0)
      (let ((f0-2 (fill-and-probe-using-y-probe
                    *collide-cache*
                    s5-0
                    f30-0
                    (collide-kind background)
                    (-> obj collide-info process)
                    s4-0
                    (new 'static 'pat-surface :noentity #x1)
                    )
                  )
            )
        (if (or (< f0-2 0.0) (= (incomplete-bitfield-access (-> s4-0 pat)) 8))
            (return #f)
            )
        (set! (-> s5-0 y) (- (-> s5-0 y) (* f0-2 f30-0)))
        )
      )
    (set! (-> arg1 quad) (-> s5-0 quad))
    )
  #t
  )

;; definition for method 53 of type snow-bunny
;; INFO: Used lq/sq
(defmethod dummy-53 snow-bunny ((obj snow-bunny))
  (let* ((s4-0 (-> obj path curve num-cverts))
         (s2-0 (nav-enemy-rnd-int-count s4-0))
         (s5-0 (new 'stack-no-clear 'vector))
         )
    (dotimes (s3-0 s4-0)
      (eval-path-curve-div! (-> obj path) s5-0 (the float s2-0) 'interp)
      (let ((f30-0 (vector-vector-xz-distance s5-0 (-> obj collide-info trans))))
        (when (>= f30-0 6144.0)
          (when (dummy-51 obj s5-0 s5-0)
            (set! (-> obj final-dest quad) (-> s5-0 quad))
            (set! (-> obj halfway-dist) (* 0.5 f30-0))
            (set! (-> obj base-hop-dist) (rand-vu-float-range 6144.0 22118.4))
            (return #t)
            )
          )
        )
      (set! s2-0 (mod (+ s2-0 1) s4-0))
      )
    )
  #f
  )

;; definition for method 54 of type snow-bunny
;; INFO: Used lq/sq
(defmethod dummy-54 snow-bunny ((obj snow-bunny))
  (local-vars (sv-48 (function float float)))
  (set! (-> obj using-jump-event?) #f)
  (let* ((s5-1 (vector-! (new 'stack-no-clear 'vector) (-> obj final-dest) (-> obj collide-info trans)))
         (f30-0 (vector-length s5-1))
         (f1-0 (-> obj halfway-dist))
         (f0-1 (- 1.0 (/ (fabs (- f30-0 f1-0)) (* 2.0 f1-0))))
         )
    (cond
      ((< f0-1 0.3)
       (set! f0-1 0.3)
       )
      ((< 1.0 f0-1)
       (set! f0-1 1.0)
       )
      )
    (let ((f28-0 (* (-> obj base-hop-dist) f0-1)))
      (cond
        ((>= (+ 4096.0 f28-0) f30-0)
         (set! (-> obj nav target-pos quad) (-> obj final-dest quad))
         )
        (else
          (vector-rotate-around-y! s5-1 s5-1 16384.0)
          (vector-normalize! s5-1 (- f30-0 f28-0))
          (let ((s4-0 (new 'stack-no-clear 'vector)))
            (let ((s3-0 vector+*!)
                  (s2-0 s4-0)
                  (s1-0 (-> obj final-dest))
                  (s0-0 s5-1)
                  )
              (set! sv-48 sin)
              (let ((a0-9 (rand-vu-float-range -16384.0 16384.0)))
                (s3-0 s2-0 s1-0 s0-0 (sv-48 a0-9))
                )
              )
            (vector-! s5-1 s4-0 (-> obj collide-info trans))
            (when (< f28-0 (vector-length s5-1))
              (vector-normalize! s5-1 f28-0)
              (vector+! s4-0 (-> obj collide-info trans) s5-1)
              )
            (set! (-> obj nav target-pos quad) (-> s4-0 quad))
            )
          )
        )
      )
    )
  (set! (-> obj got-jump-event?) #f)
  (dummy-11 (-> obj nav) (-> obj nav target-pos))
  (cond
    ((-> obj got-jump-event?)
     (set! (-> obj nav target-pos quad) (-> obj jump-event-dest quad))
     (set! (-> obj using-jump-event?) #t)
     )
    (else
      (let ((s5-2 (-> obj nav travel)))
        (if (< (vector-length s5-2) 0.01)
            (return #f)
            )
        (let ((a2-2 (-> obj nav target-pos)))
          (vector+! a2-2 (-> obj collide-info trans) s5-2)
          (if (not (dummy-51 obj a2-2 a2-2))
              (return #f)
              )
          )
        )
      )
    )
  #t
  )

;; failed to figure out what this is:
(defstate snow-bunny-patrol-hop (snow-bunny)
  :virtual override
  :event snow-bunny-default-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (when (not (dummy-54 self))
      (set! (-> self patrol-hop-failed?) #t)
      (go-virtual snow-bunny-patrol-idle)
      )
    (if (dummy-57 self)
        (go-virtual snow-bunny-defend)
        )
    (set-jump-height-factor! self 0)
    (snow-bunny-initialize-jump (-> self nav target-pos))
    (dummy-76 self #t)
    (set! (-> self rotate-speed) 728177.75)
    (set! (-> self turn-time) (seconds 0.1))
    (none)
    )
  :exit (behavior ()
    (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-rotate enable-travel))
    (logclear! (-> self collide-info nav-flags) (nav-flags navf1))
    (none)
    )
  :trans (behavior ()
    (dummy-58 self)
    (none)
    )
  :code (behavior ()
    (snow-bunny-execute-jump)
    (if (-> self using-jump-event?)
        (set-current-poly! (-> self nav) (dummy-16 (-> self nav) (-> self collide-info trans)))
        )
    (if (or (zero? (nav-enemy-rnd-int-count (-> self patrol-rand-distraction)))
            (>= 40.96 (vector-vector-distance (-> self final-dest) (-> self collide-info trans)))
            )
        (go-virtual snow-bunny-patrol-idle)
        (go-virtual snow-bunny-patrol-hop)
        )
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) nav-enemy-jump-post)
  )

;; failed to figure out what this is:
(defstate nav-enemy-notice (snow-bunny)
  :virtual #t
  :event snow-bunny-default-event-handler
  :enter (behavior ()
    (logior! (-> self nav-enemy-flags) (nav-enemy-flags navenmf2))
    (nav-enemy-neck-control-look-at)
    (if (logtest? (-> self nav-enemy-flags) (nav-enemy-flags navenmf1))
        (go-virtual nav-enemy-chase)
        )
    (logior! (-> self nav-enemy-flags) (nav-enemy-flags navenmf1))
    (dummy-76 self #t)
    (set-vector! (-> self collide-info transv) 0.0 (nav-enemy-rnd-float-range 102400.0 131072.0) 0.0 1.0)
    (none)
    )
  :exit (the-as (function none :behavior snow-bunny) #f)
  :trans (behavior ()
    (dummy-58 self)
    (none)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.075))
    (let ((f30-0 (nav-enemy-rnd-float-range 0.8 1.2)))
      (ja-no-eval :group! (-> self draw art-group data (-> self nav-info notice-anim))
                  :num! (seek! (ja-aframe 8.0 0) f30-0)
                  :frame-num 0.0
                  )
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek! (ja-aframe 8.0 0) f30-0))
        )
      (until (logtest? (-> self collide-info status) (cshape-moving-flags onsurf))
        (ja :num! (seek! max f30-0))
        (+! (-> self collide-info transv y) (* -546119.7 (-> *display* seconds-per-frame)))
        (integrate-for-enemy-with-move-to-ground!
          (-> self collide-info)
          (-> self collide-info transv)
          (collide-kind background)
          12288.0
          #f
          #f
          #f
          )
        (when *target*
          (let ((gp-2 (new 'stack-no-clear 'vector)))
            (vector-! gp-2 (target-pos 0) (-> self collide-info trans))
            (seek-toward-heading-vec! (-> self collide-info) gp-2 524288.0 (seconds 0.1))
            )
          )
        (suspend)
        )
      (ja-channel-push! 1 (seconds 0.075))
      (ja-no-eval :group! (-> self draw art-group data (-> self notice-land-anim))
                  :num! (seek! max f30-0)
                  :frame-num 0.0
                  )
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek! max f30-0))
        )
      )
    (go-virtual nav-enemy-chase)
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) nav-enemy-simple-post)
  )

;; failed to figure out what this is:
(defstate nav-enemy-chase (snow-bunny)
  :virtual #t
  :event (the-as (function process int symbol event-message-block object :behavior snow-bunny) #f)
  :exit (the-as (function none :behavior snow-bunny) #f)
  :trans (the-as (function none :behavior snow-bunny) #f)
  :code (behavior ()
    (go-virtual snow-bunny-chase-hop)
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) #f)
  )

;; definition for method 52 of type snow-bunny
;; INFO: Used lq/sq
(defmethod dummy-52 snow-bunny ((obj snow-bunny))
  (local-vars (sv-48 (function float float)))
  (set! (-> obj using-jump-event?) #f)
  (if (not *target*)
      (return #f)
      )
  (let ((s4-0 (-> obj final-dest)))
    (set! (-> s4-0 quad) (-> (target-pos 0) quad))
    (if (not (dummy-51 obj s4-0 s4-0))
        (return #f)
        )
    (set! (-> obj base-hop-dist) (rand-vu-float-range 18022.4 22118.4))
    (let* ((s5-2 (vector-! (new 'stack-no-clear 'vector) s4-0 (-> obj collide-info trans)))
           (f28-0 (vector-length s5-2))
           (f30-0 (-> obj base-hop-dist))
           )
      (cond
        ((>= (+ 4096.0 f30-0) f28-0)
         (set! (-> obj nav target-pos quad) (-> s4-0 quad))
         )
        (else
          (vector-rotate-around-y! s5-2 s5-2 16384.0)
          (vector-normalize! s5-2 (- f28-0 f30-0))
          (let ((s3-0 (new 'stack-no-clear 'vector)))
            (let ((s2-0 vector+*!)
                  (s1-0 s3-0)
                  (s0-0 s5-2)
                  )
              (set! sv-48 sin)
              (let ((a0-11 (rand-vu-float-range -16384.0 16384.0)))
                (s2-0 s1-0 s4-0 s0-0 (sv-48 a0-11))
                )
              )
            (vector-! s5-2 s3-0 (-> obj collide-info trans))
            (when (< f30-0 (vector-length s5-2))
              (vector-normalize! s5-2 f30-0)
              (vector+! s3-0 (-> obj collide-info trans) s5-2)
              )
            (set! (-> obj nav target-pos quad) (-> s3-0 quad))
            )
          )
        )
      )
    )
  (set! (-> obj got-jump-event?) #f)
  (dummy-11 (-> obj nav) (-> obj nav target-pos))
  (cond
    ((-> obj got-jump-event?)
     (set! (-> obj nav target-pos quad) (-> obj jump-event-dest quad))
     (set! (-> obj using-jump-event?) #t)
     )
    (else
      (let ((s5-3 (-> obj nav travel)))
        (if (< (vector-length s5-3) 0.01)
            (return #f)
            )
        (let ((a2-3 (-> obj nav target-pos)))
          (vector+! a2-3 (-> obj collide-info trans) s5-3)
          (if (not (dummy-51 obj a2-3 a2-3))
              (return #f)
              )
          )
        )
      )
    )
  #t
  )

;; failed to figure out what this is:
(defstate snow-bunny-chase-hop (snow-bunny)
  :virtual override
  :event snow-bunny-default-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set! (-> self should-retreat?) #f)
    (if (or (not *target*) (logtest? (-> *target* state-flags) (state-flags do-not-notice)))
        (go-virtual nav-enemy-patrol)
        )
    (if (not (TODO-RENAME-46 self (-> self nav-info stop-chase-distance)))
        (go-virtual nav-enemy-patrol)
        )
    (if (dummy-57 self)
        (go-virtual snow-bunny-defend)
        )
    (when (not (dummy-52 self))
      (logclear! (-> self nav-enemy-flags) (nav-enemy-flags navenmf1))
      (go-virtual nav-enemy-notice)
      )
    (set-jump-height-factor! self 1)
    (snow-bunny-initialize-jump (-> self nav target-pos))
    (dummy-76 self #t)
    (set! (-> self rotate-speed) 728177.75)
    (set! (-> self turn-time) (seconds 0.1))
    (none)
    )
  :exit (behavior ()
    (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-rotate enable-travel))
    (logclear! (-> self collide-info nav-flags) (nav-flags navf1))
    (none)
    )
  :trans (behavior ()
    (if (dummy-57 self)
        (set! (-> self should-retreat?) #t)
        )
    (dummy-58 self)
    (none)
    )
  :code (behavior ()
    (snow-bunny-execute-jump)
    (if (-> self using-jump-event?)
        (set-current-poly! (-> self nav) (dummy-16 (-> self nav) (-> self collide-info trans)))
        )
    (if (-> self should-retreat?)
        (go-virtual snow-bunny-defend)
        )
    (go-virtual snow-bunny-chase-hop)
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) nav-enemy-jump-post)
  )

;; failed to figure out what this is:
(defstate snow-bunny-defend (snow-bunny)
  :virtual override
  :code (behavior ()
    (if (= (-> self defense) 1)
        (go-virtual snow-bunny-retreat-hop)
        (go-virtual snow-bunny-lunge)
        )
    (none)
    )
  )

;; definition of type snow-bunny-retreat-work
(deftype snow-bunny-retreat-work (structure)
  ((found-best        basic          :offset-assert   0)
   (using-jump-event? basic          :offset-assert   4)
   (best-travel-dist  float          :offset-assert   8)
   (best-dest         vector :inline :offset-assert  16)
   (away-vec          vector :inline :offset-assert  32)
   )
  :method-count-assert 9
  :size-assert         #x30
  :flag-assert         #x900000030
  )

;; definition for method 3 of type snow-bunny-retreat-work
(defmethod inspect snow-bunny-retreat-work ((obj snow-bunny-retreat-work))
  (format #t "[~8x] ~A~%" obj 'snow-bunny-retreat-work)
  (format #t "~Tfound-best: ~A~%" (-> obj found-best))
  (format #t "~Tusing-jump-event?: ~A~%" (-> obj using-jump-event?))
  (format #t "~Tbest-travel-dist: ~f~%" (-> obj best-travel-dist))
  (format #t "~Tbest-dest: #<vector @ #x~X>~%" (-> obj best-dest))
  (format #t "~Taway-vec: #<vector @ #x~X>~%" (-> obj away-vec))
  obj
  )

;; definition for method 55 of type snow-bunny
;; INFO: Used lq/sq
(defmethod dummy-55 snow-bunny ((obj snow-bunny))
  (set! (-> obj using-jump-event?) #f)
  (if (not *target*)
      (return #f)
      )
  (let ((s5-0 (new 'stack-no-clear 'snow-bunny-retreat-work)))
    (set! (-> s5-0 found-best) #f)
    (let ((s4-0 (-> obj nav)))
      (TODO-RENAME-27 s4-0)
      (TODO-RENAME-28 s4-0 (collide-kind
                             background
                             cak-1
                             cak-2
                             cak-3
                             target
                             water
                             powerup
                             crate
                             enemy
                             wall-object
                             projectile
                             ground-object
                             target-attack
                             mother-spider
                             cak-14
                             blue-eco-suck
                             unknown-16
                             unknown-17
                             unknown-18
                             unknown-19
                             unknown-20
                             unknown-21
                             unknown-22
                             unknown-23
                             unknown-24
                             unknown-25
                             unknown-26
                             unknown-27
                             unknown-28
                             unknown-29
                             unknown-30
                             unknown-31
                             unknown-32
                             unknown-33
                             unknown-34
                             unknown-35
                             unknown-36
                             unknown-37
                             unknown-38
                             unknown-39
                             unknown-40
                             unknown-41
                             unknown-42
                             unknown-43
                             unknown-44
                             unknown-45
                             unknown-46
                             unknown-47
                             unknown-48
                             unknown-49
                             unknown-50
                             unknown-51
                             unknown-52
                             unknown-53
                             unknown-54
                             unknown-55
                             unknown-56
                             unknown-57
                             unknown-58
                             unknown-59
                             unknown-60
                             unknown-61
                             unknown-62
                             unknown-63
                             )
                      )
      )
    (let ((s4-1 (target-pos 0)))
      (vector-! (-> s5-0 away-vec) (-> obj collide-info trans) s4-1)
      (set! (-> s5-0 away-vec y) 0.0)
      (vector-normalize! (-> s5-0 away-vec) 86016.0)
      (let* ((s3-0 (quaternion-y-angle (-> *target* control quat)))
             (a0-9 (atan (-> s5-0 away-vec x) (-> s5-0 away-vec z)))
             (s3-1 (deg- a0-9 s3-0))
             )
        (dotimes (s2-0 2)
          (cond
            ((zero? s2-0)
             (let ((f30-0 0.0))
               (if (< (fabs s3-1) 16384.0)
                   (set! f30-0 (if (>= s3-1 0.0)
                                   4551.1113
                                   -4551.1113
                                   )
                         )
                   )
               (let ((f0-7 (+ f30-0 (rand-vu-float-range -6371.5557 6371.5557)))
                     (s1-0 (new 'stack-no-clear 'vector))
                     )
                 (vector-rotate-around-y! s1-0 (-> s5-0 away-vec) f0-7)
                 (vector+! (-> obj final-dest) s4-1 s1-0)
                 )
               )
             )
            ((= s2-0 1)
             (let* ((f30-1 32768.0)
                    (f0-10 (if (>= s3-1 0.0)
                               (- f30-1 (rand-vu-float-range 10012.444 15473.777))
                               (+ f30-1 (rand-vu-float-range 10012.444 15473.777))
                               )
                           )
                    (s1-1 (new 'stack-no-clear 'vector))
                    )
               (vector-rotate-around-y! s1-1 (-> s5-0 away-vec) f0-10)
               (vector+! (-> obj final-dest) s4-1 s1-1)
               )
             )
            )
          (let* ((s1-3 (vector-! (new 'stack-no-clear 'vector) (-> obj final-dest) (-> obj collide-info trans)))
                 (f0-12 (vector-length s1-3))
                 )
            (let ((f1-4 (* 0.000011625744 f0-12)))
              (cond
                ((< 1.0 f1-4)
                 (set! f1-4 1.0)
                 )
                ((< f1-4 0.4)
                 (set! f1-4 0.4)
                 )
                )
              (set! (-> obj base-hop-dist) (+ 16384.0 (* 20480.0 f1-4)))
              )
            (when (< (-> obj base-hop-dist) f0-12)
              (vector-normalize! s1-3 (-> obj base-hop-dist))
              (vector+! (-> obj final-dest) (-> obj collide-info trans) s1-3)
              )
            )
          (set! (-> obj nav target-pos quad) (-> obj final-dest quad))
          (set! (-> obj got-jump-event?) #f)
          (dummy-13 (-> obj nav) (-> obj nav target-pos) (-> obj nav old-travel))
          (when (< (vector-xz-length (-> obj nav travel)) 204.8)
            (let ((s1-4 (new 'stack-no-clear 'nav-gap-info)))
              (when (TODO-RENAME-12 (-> obj nav) s1-4)
                (set! (-> obj got-jump-event?) #t)
                (set! (-> obj jump-event-dest quad) (-> s1-4 dest quad))
                )
              )
            )
          (cond
            ((-> obj got-jump-event?)
             (when (zero? s2-0)
               (set! (-> obj nav target-pos quad) (-> obj jump-event-dest quad))
               (set! (-> obj using-jump-event?) #t)
               (return #t)
               )
             )
            (else
              (let* ((s0-0 (-> obj nav travel))
                     (f30-2 (vector-length s0-0))
                     )
                (when (>= f30-2 409.6)
                  (let ((s1-5 (-> obj nav target-pos)))
                    (vector+! s1-5 (-> obj collide-info trans) s0-0)
                    (when (dummy-51 obj s1-5 s1-5)
                      (if (>= f30-2 (+ -409.6 (-> obj base-hop-dist)))
                          (return #t)
                          )
                      (when (or (not (-> s5-0 found-best)) (< (-> s5-0 best-travel-dist) f30-2))
                        (set! (-> s5-0 found-best) #t)
                        (set! (-> s5-0 best-travel-dist) f30-2)
                        (set! (-> s5-0 best-dest quad) (-> s1-5 quad))
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    (when (-> s5-0 found-best)
      (set! (-> obj nav target-pos quad) (-> s5-0 best-dest quad))
      (vector-! (-> obj nav travel) (-> s5-0 best-dest) (-> obj collide-info trans))
      (return #t)
      )
    )
  #f
  )

;; failed to figure out what this is:
(defstate snow-bunny-retreat-hop (snow-bunny)
  :virtual override
  :event snow-bunny-default-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (if (not *target*)
        (go-virtual nav-enemy-patrol)
        )
    (let ((v1-8 (>= 73728.0 (vector-vector-xz-distance (target-pos 0) (-> self collide-info trans)))))
      (when (or (-> self should-retreat?) (and v1-8 (logtest? (-> *target* state-flags) (state-flags dangerous))))
        (set! (-> self retreat-timeout-time)
              (+ (-> *display* base-frame-counter) (the int (* 300.0 (-> self retreat-timeout))))
              )
        (set! (-> self should-retreat?) #f)
        )
      (when (or (>= (-> *display* base-frame-counter) (-> self retreat-timeout-time)) (not v1-8))
        (if (or (not *target*)
                (logtest? (-> *target* state-flags) (state-flags do-not-notice))
                (not (TODO-RENAME-46 self (-> self nav-info stop-chase-distance)))
                )
            (go-virtual nav-enemy-patrol)
            (go-virtual snow-bunny-chase-hop)
            )
        )
      )
    (when (not (dummy-55 self))
      (set-vector! (-> self nav travel) 0.0 0.0 0.0 1.0)
      (set! (-> self nav target-pos quad) (-> self collide-info trans quad))
      )
    (set-jump-height-factor! self 2)
    (snow-bunny-initialize-jump (-> self nav target-pos))
    (dummy-76 self #t)
    (set! (-> self rotate-speed) 728177.75)
    (set! (-> self turn-time) (seconds 0.1))
    (none)
    )
  :exit (behavior ()
    (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-rotate enable-travel))
    (logclear! (-> self collide-info nav-flags) (nav-flags navf1))
    (none)
    )
  :trans (behavior ()
    (dummy-58 self)
    (none)
    )
  :code (behavior ()
    (snow-bunny-execute-jump)
    (if (-> self using-jump-event?)
        (set-current-poly! (-> self nav) (dummy-16 (-> self nav) (-> self collide-info trans)))
        )
    (go-virtual snow-bunny-retreat-hop)
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) nav-enemy-jump-post)
  )

;; failed to figure out what this is:
(defstate snow-bunny-lunge (snow-bunny)
  :virtual override
  :event snow-bunny-default-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (dummy-76 self #f)
    (none)
    )
  :trans (behavior ()
    (if (not *target*)
        (go-virtual nav-enemy-patrol)
        )
    (dummy-58 self)
    (let ((f0-0 (vector-vector-xz-distance (target-pos 0) (-> self collide-info trans))))
      (if (< 73728.0 f0-0)
          (go-virtual snow-bunny-chase-hop)
          )
      )
    (if (not (logtest? (-> *target* state-flags) (state-flags dangerous)))
        (go-virtual snow-bunny-chase-hop)
        )
    (if (and (logtest? (-> *target* state-flags) (state-flags dangerous))
             (not (TODO-RENAME-46 self (-> self nav-info notice-distance)))
             )
        (go-virtual snow-bunny-retreat-hop)
        )
    (none)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.075))
    (loop
      (ja-no-eval :group! (-> self draw art-group data (-> self nav-info idle-anim)) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) nav-enemy-simple-post)
  )

;; failed to figure out what this is:
(defstate snow-bunny-attack (snow-bunny)
  :virtual override
  :event snow-bunny-default-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (set-vector! (-> self collide-info transv) 0.0 0.0 0.0 1.0)
    (dummy-76 self #t)
    (none)
    )
  :trans (behavior ()
    (when *target*
      (let ((gp-0 (new 'stack-no-clear 'vector)))
        (vector-! gp-0 (target-pos 0) (-> self collide-info trans))
        (seek-toward-heading-vec! (-> self collide-info) gp-0 524288.0 (seconds 0.1))
        )
      )
    (+! (-> self collide-info transv y) (* -546119.7 (-> *display* seconds-per-frame)))
    (integrate-for-enemy-with-move-to-ground!
      (-> self collide-info)
      (-> self collide-info transv)
      (collide-kind background)
      8192.0
      #f
      #f
      #f
      )
    (none)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.075))
    (ja-no-eval :group! (-> self draw art-group data (-> self attack-anim)) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (until (logtest? (-> self collide-info status) (cshape-moving-flags onsurf))
      (suspend)
      )
    (go-virtual snow-bunny-retreat-hop)
    (none)
    )
  :post (the-as (function none :behavior snow-bunny) nav-enemy-simple-post)
  )
