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

(import "goal_src/jak1/import/whirlpool-ag.gc")

;; definition of type whirlpool
(deftype whirlpool (process-drawable)
  ((root-override    collide-shape            :offset        112)
   (spin-ry          float                    :offset-assert 176)
   (spin-speed-idle  float                    :offset-assert 180)
   (spin-speed-delta float                    :offset-assert 184)
   (sync             sync-info-paused :inline :offset-assert 188)
   )
  :heap-base #x60
  :method-count-assert 21
  :size-assert         #xcc
  :flag-assert         #x15006000cc
  (:methods
    (dummy-20 (_type_ float) cshape-moving-flags 20)
    )
  (:states
    whirlpool-idle
    )
  )

;; definition for method 3 of type whirlpool
(defmethod inspect whirlpool ((obj whirlpool))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tspin-ry: ~f~%" (-> obj spin-ry))
  (format #t "~T~Tspin-speed-idle: ~f~%" (-> obj spin-speed-idle))
  (format #t "~T~Tspin-speed-delta: ~f~%" (-> obj spin-speed-delta))
  (format #t "~T~Tsync: #<sync-info-paused @ #x~X>~%" (-> obj sync))
  obj
  )

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

;; failed to figure out what this is:
(defpartgroup group-whirlpool-swirl
  :id 447
  :flags (use-local-clock)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 1739 :fade-after (meters 60) :falloff-to (meters 60) :binding 1737)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1737 :flags (bit1 start-dead launch-asap) :binding 1738)
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    (sp-item 1738 :flags (bit1 start-dead))
    )
  )

;; failed to figure out what this is:
(defpart 1739
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x9 :page #x2))
    (sp-flt spt-num 1.0)
    (sp-flt spt-y (meters 6.6))
    (sp-flt spt-scale-x (meters 0.2))
    (sp-copy-from-other spt-scale-y -4)
    (sp-flt spt-g 0.0)
    (sp-flt spt-a 128.0)
    (sp-flt spt-accel-y -0.68266666)
    (sp-int spt-timer 510)
    (sp-cpuinfo-flags bit2 bit3)
    )
  )

;; failed to figure out what this is:
(defpart 1737
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :page #x2))
    (sp-flt spt-num 1.0)
    (sp-flt spt-x (meters 0))
    (sp-flt spt-y (meters 0))
    (sp-rnd-flt spt-z (meters 4) (meters 1) 1.0)
    (sp-flt spt-scale-x (meters 3.2))
    (sp-flt spt-scale-y (meters 1))
    (sp-flt spt-r 150.0)
    (sp-flt spt-g 150.0)
    (sp-flt spt-b 255.0)
    (sp-flt spt-a 0.0)
    (sp-rnd-flt spt-omega 0.0 65536.0 1.0)
    (sp-flt spt-vel-x (meters 0.053333335))
    (sp-flt spt-vel-y (meters 0))
    (sp-flt spt-vel-z (meters -0.01))
    (sp-flt spt-scalevel-x (meters -0.004888889))
    (sp-flt spt-fade-a 0.42666668)
    (sp-int spt-timer 450)
    (sp-cpuinfo-flags bit2 bit3 bit7)
    (sp-int-plain-rnd spt-next-time 37 36 1)
    (sp-launcher-by-id spt-next-launcher 1740)
    )
  )

;; failed to figure out what this is:
(defpart 1740
  :init-specs ((sp-flt spt-fade-a 0.0))
  )

;; failed to figure out what this is:
(defpart 1738
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x9 :page #x2))
    (sp-flt spt-num 1.0)
    (sp-rnd-flt spt-scale-x (meters 0.3) (meters 0.1) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-flt spt-r 255.0)
    (sp-flt spt-g 255.0)
    (sp-flt spt-b 255.0)
    (sp-rnd-flt spt-a 32.0 32.0 1.0)
    (sp-flt spt-fade-a -1.8285716)
    (sp-int spt-timer 30)
    (sp-cpuinfo-flags bit2 bit3)
    )
  )

;; definition for method 20 of type whirlpool
(defmethod dummy-20 whirlpool ((obj whirlpool) (arg0 float))
  (let* ((gp-0 (target-pos 0))
         (f28-0 (vector-vector-xz-distance (-> obj root-override trans) gp-0))
         )
    (when (< f28-0 40960.0)
      (let* ((f0-2 (* 0.000024414063 (- 40960.0 f28-0)))
             (f26-0 (* f0-2 f0-2))
             (f0-7 (atan (- (-> gp-0 x) (-> obj root-override trans x)) (- (-> gp-0 z) (-> obj root-override trans z))))
             (f30-0 (* 0.5 f26-0 arg0 (-> *display* seconds-per-frame)))
             (f24-0 (+ f0-7 f30-0))
             (f28-1 (- f28-0 (fmin f28-0 (* 0.16874999 f26-0 (fabs arg0) (-> *display* seconds-per-frame)))))
             (s4-1 (new 'stack-no-clear 'vector))
             )
        (set-vector! s4-1 (* (sin f24-0) f28-1) 0.0 (* (cos f24-0) f28-1) 1.0)
        (vector+! s4-1 s4-1 (-> obj root-override trans))
        (set! (-> s4-1 x) (* (- (-> s4-1 x) (-> gp-0 x)) (-> *display* frames-per-second)))
        (set! (-> s4-1 y) 0.0)
        (set! (-> s4-1 z) (* (- (-> s4-1 z) (-> gp-0 z)) (-> *display* frames-per-second)))
        (let ((gp-1 (-> *target* control)))
          (send-event (-> gp-1 process) 'rotate-y-angle f30-0)
          (fill-cache-for-shape! gp-1 8192.0 (-> gp-1 root-prim collide-with))
          (let ((s3-0 (-> gp-1 status)))
            (integrate-and-collide! gp-1 s4-1)
            (set! (-> gp-1 status) s3-0)
            s3-0
            )
          )
        )
      )
    )
  )

;; failed to figure out what this is:
(defstate whirlpool-idle (whirlpool)
  :trans (behavior ()
    (let ((f30-0
            (+ (* (get-current-phase-with-mirror (-> self sync)) (-> self spin-speed-delta)) (-> self spin-speed-idle))
            )
          )
      (when (>= (fabs f30-0) 45511.11)
        (let ((a1-0 (new 'stack-no-clear 'vector)))
          (set! (-> a1-0 quad) (-> self root-override trans quad))
          (set! (-> a1-0 y) (+ -8192.0 (-> a1-0 y)))
          (spawn (-> self part) a1-0)
          )
        )
      (+! (-> self spin-ry) (* f30-0 (-> *display* seconds-per-frame)))
      (quaternion-axis-angle! (-> self root-override quat) 0.0 1.0 0.0 (-> self spin-ry))
      (if (and *target* (logtest? (-> *target* water flags) (water-flags wt09)))
          (dummy-20 self f30-0)
          )
      (update! (-> self sound))
      (let ((f0-9 (fmin 1.0 (* 0.000007608261 (fmax 0.0 (+ -28580.979 (fabs f30-0)))))))
        (update-vol! (-> self sound) (the int (* 100.0 f0-9)))
        )
      )
    (none)
    )
  :code (the-as (function none :behavior whirlpool) anim-loop)
  :post (the-as (function none :behavior whirlpool) ja-post)
  )

;; definition for method 10 of type whirlpool
(defmethod deactivate whirlpool ((obj whirlpool))
  (if (nonzero? (-> obj sound))
      (stop! (-> obj sound))
      )
  ((method-of-type process-drawable deactivate) obj)
  (none)
  )

;; definition for method 11 of type whirlpool
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! whirlpool ((obj whirlpool) (arg0 entity-actor))
  (local-vars (sv-16 res-tag))
  (set! (-> obj spin-ry) (rand-vu-float-range 0.0 65536.0))
  (let ((s4-0 (new 'process 'collide-shape obj (collide-list-enum hit-by-player))))
    (let ((s3-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-kind wall-object))
      (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 indestructible))
      (set-vector! (-> s3-0 local-sphere) 0.0 -819.2 0.0 11468.8)
      (set-root-prim! s4-0 s3-0)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> obj root-override) s4-0)
    )
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *whirlpool-sg* '())
  (load-params! (-> obj sync) obj (the-as uint 1500) 0.0 0.15 0.15)
  (let ((f30-0 32768.0)
        (f28-0 145635.56)
        )
    (set! sv-16 (new 'static 'res-tag))
    (let ((v1-17 (res-lump-data arg0 'speed (pointer float) :tag-ptr (& sv-16))))
      (when v1-17
        (set! f30-0 (-> v1-17 0))
        (set! f28-0 (-> v1-17 1))
        )
      )
    (set! (-> obj spin-speed-idle) f30-0)
    (set! (-> obj spin-speed-delta) (- f28-0 f30-0))
    )
  (set! (-> obj part) (create-launch-control (-> *part-group-id-table* 447) obj))
  (set! (-> obj sound)
        (new 'process 'ambient-sound (static-sound-spec "whirlpool" :fo-max 55) (-> obj root-override trans))
        )
  (ja-channel-set! 1)
  (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)
    )
  (ja-post)
  (update-transforms! (-> obj root-override))
  (go whirlpool-idle)
  (none)
  )
