;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/gfx/mood/weather-part.gc")
(require "engine/common-obs/water.gc")
(require "engine/target/target-util.gc")

;; DECOMP BEGINS

(defbehavior cloud-track process ((arg0 process-tree)
              (arg1 process-tree)
              (arg2 (function vector none))
              (arg3 time-frame)
              (arg4 time-frame)
              (arg5 time-frame))
  (change-parent self arg0)
  (let ((s1-1 (process->handle arg0))
        (s2-1 (process->handle arg1)))
    (suspend-for (+ arg3 arg4)
      (let ((v1-8 (or (not (handle->process s1-1)) (not (handle->process s2-1))))) (if v1-8 (deactivate self)))
      (let* ((f0-1 (fmax 0.0 (fmin 1.0 (/ (- (the float (- (current-time) time)) (the float arg3)) (the float arg4)))))
             (a0-18 (process-drawable-pair-random-point! (the-as process-drawable (-> s1-1 process 0))
                                                         (the-as process-drawable (-> s2-1 process 0))
                                                         (new-stack-vector0)
                                                         f0-1)))
        (arg2 a0-18)))
    (cond
      ((zero? arg5) (loop (suspend)))
      (else
       (suspend-for arg5
         (let ((a0-21 (process-drawable-random-point! (the-as process-drawable (-> s2-1 process 0)) (new-stack-vector0))))
           (arg2 a0-21))))))
  (none))

(defpart 255
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 64.0)
   (:g 64.0)
   (:b 192.0)
   (:a 64.0)
   (:fade-a -1.0666667)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 256
  :init-specs
  ((:texture (bigpuff effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 64.0)
   (:g 64.0)
   (:b 192.0)
   (:a 64.0)
   (:fade-a -1.0666667)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 257
  :init-specs
  ((:texture (lightning effects))
   (:num 1.0 3.0)
   (:scale-x (meters 0.5) (meters 1.5))
   (:rot-x 4)
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y (meters 0.2) (meters 0.1))
   (:r 64.0)
   (:g 64.0)
   (:b 128.0)
   (:a 128.0)
   (:fade-a -1.6)
   (:timer (seconds 0.3))
   (:flags (bit2 bit3))
   (:next-time (seconds 0.035))
   (:next-launcher 258)))

(defpart 259
  :init-specs
  ((:texture (lightning effects))
   (:num 0.0 3.0)
   (:scale-x (meters 1.5) (meters 1.5))
   (:rot-x 4)
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y (meters 0.2) (meters 0.1))
   (:r 128.0)
   (:g 128.0)
   (:b 255.0)
   (:a 128.0)
   (:fade-a -1.6)
   (:timer (seconds 0.305))
   (:flags (bit2 bit3))
   (:next-time (seconds 0.035))
   (:next-launcher 258)))

(defpart 258
  :init-specs ((:r 64.0) (:g 64.0) (:fade-r -1.0) (:fade-g -0.4) (:fade-a -2.0)))

(defpart 260
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:scale-x (meters 0.1) (meters 0.15))
   (:scale-y :copy scale-x)
   (:r 32.0)
   (:g 32.0 64.0)
   (:b 192.0 64.0)
   (:a 64.0 128.0)
   (:scalevel-x (meters -0.00033333333))
   (:scalevel-y :copy scalevel-x)
   (:fade-a -0.2)
   (:accel-y (meters -0.000016666667))
   (:timer (seconds 1.5))
   (:flags (bit0 bit2 bit3))))

(defpartgroup group-blue-hit-ground-effect
  :id 70
  :duration (seconds 0.017)
  :linger-duration (seconds 1.5)
  :bounds (static-bspherem 0 0 0 2)
  :parts ((sp-item 261) (sp-item 262) (sp-item 263 :flags (is-3d)) (sp-item 264) (sp-item 265 :flags (is-3d))))

(defpart 264
  :init-specs
  ((:texture (starflash effects))
   (:num 32.0)
   (:y (meters 0.5))
   (:scale-x (meters 1) (meters 3))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 32.0 32.0)
   (:b 192.0 63.0)
   (:a 0.0 63 1.0)
   (:vel-y (meters 0.093333334))
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:timer (seconds 0.5))
   (:flags (bit3))
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 266)
   (:conerot-x (degrees 90))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0))))

(defpart 266
  :init-specs
  ((:r 0.0)
   (:g 32.0 32.0)
   (:b 192.0 63.0)
   (:a 0.0 63 1.0)
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 266)))

(defpart 265
  :init-specs
  ((:texture (water-ring effects))
   (:num 1.0)
   (:y (meters 0.5))
   (:scale-x (meters 0))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 32.0 32.0)
   (:b 192.0 63.0)
   (:a 96.0 32.0)
   (:scalevel-x (meters 0.21333334))
   (:scalevel-y :copy scalevel-x)
   (:timer (seconds 0.4))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.2))
   (:next-launcher 267)))

(defpart 267
  :init-specs ((:fade-a -2.1333334)))

(defpart 263
  :init-specs
  ((:texture (middot effects))
   (:num 1.0)
   (:y (meters 0.5))
   (:scale-x (meters 0))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 32.0 32.0)
   (:b 192.0 63.0)
   (:a 32.0 32.0)
   (:scalevel-x (meters 0.22666667))
   (:scalevel-y :copy scalevel-x)
   (:fade-a -0.7111111)
   (:timer (seconds 0.3))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.15))
   (:next-launcher 268)))

(defpart 268
  :init-specs ((:fade-a -1.4222223)))

(defpart 261
  :init-specs
  ((:texture (bigpuff effects))
   (:num 32.0)
   (:scale-x (meters 1) (meters 1))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 32.0 32.0)
   (:b 192.0 63.0)
   (:a 16.0 32.0)
   (:vel-y (meters 0.053333335) (meters 0.026666667))
   (:scalevel-x (meters 0.0033333334))
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:scalevel-y :copy scalevel-x)
   (:fade-a -0.16)
   (:accel-y (meters -0.00033333333))
   (:friction 0.95)
   (:timer (seconds 1))
   (:flags (bit2 bit12))
   (:conerot-x (degrees 60) (degrees 30))
   (:conerot-y (degrees 0) (degrees 360))))

(defpart 262
  :init-specs
  ((:texture (bigpuff effects))
   (:num 12.0)
   (:scale-x (meters 0.5) (meters 0.25))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 32.0 32.0)
   (:b 192.0 63.0)
   (:a 16.0 16.0)
   (:vel-y (meters 0.10666667) (meters 0.053333335))
   (:scalevel-x (meters 0.0016666667))
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:scalevel-y :copy scalevel-x)
   (:fade-a -0.21333334)
   (:accel-y (meters -0.00033333333))
   (:friction 0.95)
   (:timer (seconds 0.5))
   (:flags (bit2 bit12))
   (:conerot-x (degrees 60) (degrees 30))
   (:conerot-y (degrees 0) (degrees 360))))

(defpart 269
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 92.0 32.0)
   (:g 32.0 92.0)
   (:b 0.0)
   (:a 64.0)
   (:fade-a -1.0)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 270
  :init-specs
  ((:texture (bigpuff effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 92.0 32.0)
   (:g 32.0 92.0)
   (:b 0.0)
   (:a 64.0)
   (:fade-a -1.0)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 271
  :init-specs
  ((:texture (hotdot effects))
   (:num 0.5 2.0)
   (:y (meters -0.05))
   (:scale-x (meters 0.2) (meters 0.1))
   (:scale-y :copy scale-x)
   (:r 100.0 28.0)
   (:g 64.0 64.0)
   (:b 0.0)
   (:a 64.0 64.0)
   (:vel-y (meters 0.0023333333) (meters 0.0016666667))
   (:scalevel-x (meters -0.00083333335))
   (:scalevel-y :copy scalevel-x)
   (:fade-g -0.4)
   (:fade-a -0.024242423)
   (:accel-y (meters -0.000100000005) (meters -0.0003))
   (:friction 0.93)
   (:timer (seconds 0.1) (seconds 0.697))
   (:flags (bit2 bit3))
   (:next-time (seconds 0.3))
   (:next-launcher 272)
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.05))))

(defpart 272
  :init-specs ((:fade-r 0.0)))

(defpart 273
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 92.0 32.0)
   (:g 0.0)
   (:b 0.0)
   (:a 64.0)
   (:fade-a -1.0)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 274
  :init-specs
  ((:texture (bigpuff effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 92.0 32.0)
   (:g 0.0)
   (:b 0.0)
   (:a 64.0)
   (:fade-a -1.0)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 275
  :init-specs
  ((:texture (hotdot effects))
   (:num 0.5 2.0)
   (:y (meters -0.05))
   (:scale-x (meters 0.2) (meters 0.1))
   (:scale-y :copy scale-x)
   (:r 100.0 28.0)
   (:g 0.0)
   (:b 0.0)
   (:a 64.0 64.0)
   (:vel-y (meters 0.0023333333) (meters 0.0016666667))
   (:scalevel-x (meters -0.00083333335))
   (:scalevel-y :copy scalevel-x)
   (:fade-g -0.4)
   (:fade-a -0.024242423)
   (:accel-y (meters -0.000100000005) (meters -0.0003))
   (:friction 0.93)
   (:timer (seconds 0.1) (seconds 0.697))
   (:flags (bit2 bit3))
   (:next-time (seconds 0.3))
   (:next-launcher 276)
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.05))))

(defpart 276
  :init-specs ((:fade-r 0.0)))

(defpart 277
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 92.0 32.0)
   (:b 0.0)
   (:a 64.0)
   (:fade-a -1.0)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 278
  :init-specs
  ((:texture (bigpuff effects))
   (:num 1.0 1.0)
   (:scale-x (meters 1.5) (meters 0.4))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 92.0 32.0)
   (:b 0.0)
   (:a 64.0)
   (:fade-a -1.0)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.5))))

(defpart 279
  :init-specs
  ((:texture (hotdot effects))
   (:num 0.5 2.0)
   (:y (meters -0.05))
   (:scale-x (meters 0.2) (meters 0.1))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 100.0 28.0)
   (:b 0.0)
   (:a 64.0 64.0)
   (:vel-y (meters 0.0023333333) (meters 0.0016666667))
   (:scalevel-x (meters -0.00083333335))
   (:scalevel-y :copy scalevel-x)
   (:fade-g -0.4)
   (:fade-a -0.024242423)
   (:accel-y (meters -0.000100000005) (meters -0.0003))
   (:friction 0.93)
   (:timer (seconds 0.1) (seconds 0.697))
   (:flags (bit2 bit3))
   (:next-time (seconds 0.3))
   (:next-launcher 280)
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0.05))))

(defpart 280
  :init-specs ((:fade-g 0.0)))

(defun eco-blue-glow ((arg0 vector))
  (launch-particles (-> *part-id-table* 255) arg0)
  (if (rand-vu-percent? 0.5) (launch-particles (-> *part-id-table* 257) arg0))
  0
  (none))

(defbehavior target-powerup-process target ()
  (water-control-method-10 (-> self water))
  (when (not *weather-off*)
    (case (-> self current-level name)
      (('swamp) (update-rain self))
      (('snow) (update-snow self))))
  (cond
    ((and (= (-> self control ground-pat material) (pat-material ice))
          (and (>= (-> self control unknown-float01) 204.8)
               (not (time-elapsed? (-> self control unknown-dword11) (seconds 0.05)))))
     (let ((gp-0 (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node eichar-lod0-jg RbigToe))))
       (if (and (< (fabs (vector-dot (-> self control dynam gravity-normal) (vector-! (new 'stack-no-clear 'vector) gp-0 (-> self control trans))))
                   819.2)
                (rand-vu-percent? 0.5))
         (launch-particles :system *sp-particle-system-3d* (-> *part-id-table* 2391) gp-0)))
     (let ((gp-1 (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node eichar-lod0-jg LbigToe))))
       (if (and (< (fabs (vector-dot (-> self control dynam gravity-normal) (vector-! (new 'stack-no-clear 'vector) gp-1 (-> self control trans))))
                   819.2)
                (rand-vu-percent? 0.5))
         (launch-particles :system *sp-particle-system-3d* (-> *part-id-table* 2391) gp-1)))
     ;; og:preserve-this PAL patch here
     (let ((f0-8 (lerp-scale 80.0 100.0 (-> self control unknown-float01) 0.0 81920.0)))
       (if (not (ja-group? eichar-ice-stance-ja)) (set! f0-8 (* 0.8 f0-8)))
       (seek! (-> self control unknown-float141) f0-8 (* 100.0 (seconds-per-frame))))
     (let ((f30-0 (-> self control unknown-float141))
           (f0-13 (lerp-scale -0.3 0.3 (-> self control unknown-float01) 0.0 81920.0)))
       (sound-play "ice-loop"
                   :id (-> self control unknown-soundid00)
                   :vol
                   f30-0
                   :pitch
                   f0-13
                   :position
                   (the-as symbol (-> self control trans)))))
    ((< 0.0 (-> self control unknown-float141))
     (set! (-> self control unknown-float141) 0.0)
     (let ((v1-64 (the-as sound-rpc-set-param (get-sound-buffer-entry))))
       (set! (-> v1-64 command) (sound-command set-param))
       (set! (-> v1-64 id) (-> self control unknown-soundid00))
       (set! (-> v1-64 parms volume) -4)
       (set! (-> v1-64 auto-time) 48)
       (set! (-> v1-64 auto-from) 2)
       (set! (-> v1-64 parms mask) (sound-mask volume time))
       (-> v1-64 id))))
  (let ((v1-67 (-> *time-of-day-context* current-shadow))
        (a0-33 (-> self draw shadow-ctrl)))
    (set! (-> a0-33 settings shadow-dir x) (-> v1-67 x))
    (set! (-> a0-33 settings shadow-dir y) (-> v1-67 y))
    (set! (-> a0-33 settings shadow-dir z) (-> v1-67 z)))
  (when (and (!= (-> self fact eco-level) 0.0)
             (>= (- (-> *display* game-frame-counter) (-> self fact eco-pickup-time)) (the-as time-frame (-> self fact eco-timeout))))
    (set! (-> self fact eco-level) 0.0)
    (set! (-> self fact eco-timeout) 0)
    (logclear! (-> self state-flags) (state-flags invuln-powerup))
    (send-event self 'reset-collide)
    (stop! (-> self sound)))
  (when (and (< 0.0 (-> self fact eco-level))
             (not (logtest? (-> self state-flags) (state-flags first-person-mode)))
             (not (logtest? (-> self draw status) (draw-status hidden no-anim)))
             (not (movie?))
             (rand-vu-percent? (lerp-scale 0.0
                                           1.0
                                           (the float
                                                (- (-> self fact eco-timeout) (the-as uint (- (-> *display* game-frame-counter) (-> self fact eco-pickup-time)))))
                                           0.0
                                           900.0)))
    (case (-> self fact eco-type)
      (((pickup-type eco-yellow))
       (change-sound! (-> self sound) (static-sound-name "yel-eco-jak"))
       (let ((s4-0 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
         (launch-particles (-> *part-id-table* (if (rand-vu-percent? 0.5) 269 270))
                           (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data s4-0))))
       (dotimes (gp-4 2)
         (let ((v1-111 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
           (launch-particles (-> *part-id-table* 271)
                             (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data v1-111))))))
      (((pickup-type eco-red))
       (target-danger-set! (-> self control unknown-symbol30) #t)
       (update-transforms! (-> self control))
       (let ((a1-23 (new 'stack-no-clear 'touching-shapes-entry)))
         (set! (-> a1-23 cshape1) (the-as collide-shape 0))
         (set! (-> a1-23 cshape2) (the-as collide-shape *touching-list*))
         (find-overlapping-shapes (-> self control) (the-as overlaps-others-params a1-23)))
       (target-danger-set! (-> self control unknown-symbol30) #f)
       (update-transforms! (-> self control))
       (change-sound! (-> self sound) (static-sound-name "red-eco-jak"))
       (let ((s4-2 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
         (launch-particles (-> *part-id-table* (if (rand-vu-percent? 0.5) 273 274))
                           (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data s4-2))))
       (dotimes (gp-6 2)
         (let ((v1-139 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
           (launch-particles (-> *part-id-table* 275)
                             (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data v1-139))))))
      (((pickup-type eco-blue))
       (change-sound! (-> self sound) (static-sound-name "blue-eco-jak"))
       (let ((v1-150 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
         (cond
           ((and (logtest? (-> self control unknown-surface00 flags) (surface-flags jump))
                 (not (logtest? (-> self control status) (cshape-moving-flags onsurf))))
            (set! (-> *part-id-table* 259 init-specs 4 initial-valuef) 0.0)
            (set! (-> *part-id-table* 259 init-specs 4 random-rangef) 65536.0))
           (else
            (set! (-> *part-id-table* 259 init-specs 4 initial-valuef) 40960.0)
            (set! (-> *part-id-table* 259 init-specs 4 random-rangef) 16384.0)))
         (launch-particles (-> *part-id-table* 259)
                           (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data v1-150))))
       (let ((gp-8 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
         (launch-particles (-> *part-id-table* (if (rand-vu-percent? 0.5) 255 256))
                           (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data gp-8)))
         (if (rand-vu-percent? 0.5)
           (launch-particles (-> *part-id-table* 257) (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data gp-8)))))
       (let ((v1-168 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
         (launch-particles (-> *part-id-table* 260)
                           (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data v1-168))))
       (cpad-set-buzz! (-> *cpad-list* cpads 0) 0 1 (seconds 0.1)))
      (((pickup-type eco-green))
       (change-sound! (-> self sound) (static-sound-name "green-eco-jak"))
       (let ((s4-8 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
         (launch-particles (-> *part-id-table* (if (rand-vu-percent? 0.5) 277 278))
                           (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data s4-8))))
       (dotimes (gp-11 2)
         (let ((v1-188 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
           (launch-particles (-> *part-id-table* 279)
                             (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data v1-188)))))))
    (update-trans! (-> self sound) (-> self control trans))
    (update! (-> self sound)))
  0
  (none))

(defbehavior target-powerup-effect target ((arg0 symbol))
  (case arg0
    (('eco-blue)
     (let ((v1-4 (rand-vu-int-range 3 (+ (-> self node-list length) -1))))
       (eco-blue-glow (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data v1-4))))))
  0
  (none))
