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

;; name: for-turret-shot.gc
;; name in dgo: for-turret-shot
;; dgos: LFORM

;; DECOMP BEGINS

(defskelgroup skel-for-turret for-turret for-turret-lod0-jg for-turret-idle-ja
              ((for-turret-lod0-mg (meters 20)) (for-turret-lod1-mg (meters 40)) (for-turret-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 1.8 0.7 6)
              :origin-joint-index 4
              :global-effects 32
              )

(defpart 1065
  :init-specs ((:texture (gun-enemy-beam level-default-sprite))
    (:birth-func 'birth-func-set-quat)
    (:num 1.0)
    (:scale-x (meters 1))
    (:scale-y (meters 30))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 32.0 64.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-14 left-multiply-quat))
    )
  )

(defpart 1066
  :init-specs ((:texture (glow-soft level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 2))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 0.0)
    (:b 128.0)
    (:a 64.0)
    (:scalevel-x (meters -0.075))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -1.6)
    (:timer (seconds 0.135))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14))
    )
  )

(defpart 1067
  :init-specs ((:texture (radial-gradient level-default-sprite))
    (:num 16.0)
    (:z (meters 0) (meters -2))
    (:scale-x (meters 0.5) (meters 0.5))
    (:rot-z (degrees 0) (degrees 3600))
    (:scale-y (meters 0.5) (meters 0.5))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 64.0)
    (:fade-g -3.2 -6.4)
    (:fade-a -1.6 -6.4)
    (:accel-y (meters -0.00016666666) (meters -0.00016666666))
    (:timer (seconds 0.267))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:rotate-y (degrees 0))
    )
  )

(defpart 1068
  :init-specs ((:texture (gun-enemy-muzzleflash level-default-sprite))
    (:birth-func 'birth-func-set-quat)
    (:num 1.0)
    (:scale-x (meters 2))
    (:scale-y (meters 4.5))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 128.0)
    (:fade-a -3.6571429)
    (:timer (seconds 0.117))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14 left-multiply-quat))
    )
  )

(defpart 1069
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 2.5))
    (:rot-x (degrees 4.5))
    (:rot-z (degrees 0) (degrees 3600))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 0.0 64.0)
    (:b 128.0)
    (:a 255.0)
    (:omega (degrees 4515.75))
    (:scalevel-x (meters 0.10666667))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -7.285714)
    (:timer (seconds 0.117))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14 glow))
    (:userdata 1024.0)
    )
  )

(defpartgroup group-for-turret-shot-hit
  :id 239
  :duration (seconds 1)
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 1070 :period (seconds 2) :length (seconds 0.017))
    (sp-item 1071 :fade-after (meters 100) :flags (sp6) :period (seconds 2) :length (seconds 0.017))
    (sp-item 1072 :flags (sp6) :period (seconds 2) :length (seconds 0.017))
    (sp-item 1073 :flags (sp6) :period (seconds 2) :length (seconds 0.017))
    (sp-item 1074 :period (seconds 2) :length (seconds 0.017))
    (sp-item 1075 :fade-after (meters 50) :falloff-to (meters 50) :period (seconds 2) :length (seconds 0.017))
    )
  )

(defpart 1073
  :init-specs ((:texture (explosion-nebula level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1))
    (:rot-x (degrees 1.125))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0 128.0)
    (:b 255.0)
    (:a 12.0)
    (:scalevel-x (meters 0.26666668))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.34285715)
    (:timer (seconds 0.135))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 4096.0)
    )
  )

(defpart 1074
  :init-specs ((:texture (bigpuff level-default-sprite))
    (:num 8.0 8.0)
    (:scale-x (meters 1) (meters 0.5))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0 128.0)
    (:g 0.0 64.0)
    (:b 128.0 128.0)
    (:a 16.0 48.0)
    (:vel-y (meters 0.013333334) (meters 0.04))
    (:scalevel-x (meters 0.0016666667) (meters 0.013333334))
    (:rotvel-z (degrees -0.2) (degrees 0.4))
    (:scalevel-y :copy scalevel-x)
    (:fade-r -0.30476192)
    (:fade-g -0.35555556)
    (:fade-b -0.17777778)
    (:fade-a -0.15238096)
    (:accel-y (meters -0.00016666666) (meters -0.00016666666))
    (:friction 0.9)
    (:timer (seconds 1.4))
    (:flags (sp-cpuinfo-flag-2))
    (:conerot-x (degrees 0) (degrees 3600))
    (:conerot-y (degrees 0) (degrees 3600))
    )
  )

(defpart 1075
  :init-specs ((:texture (radial-gradient level-default-sprite))
    (:num 20.0 10.0)
    (:y (meters 0.25))
    (:scale-x (meters 0.075) (meters 0.05))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 0.0 128.0)
    (:b 128.0)
    (:a 64.0 32.0)
    (:omega (degrees 0.0225) (degrees 0.0225))
    (:vel-y (meters 0.033333335) (meters 0.1))
    (:rotvel-z (degrees -2.4) 1 (degrees 4.8))
    (:fade-g -0.85333335)
    (:fade-a 0.0)
    (:accel-y (meters -0.00033333333) (meters -0.0013333333))
    (:friction 0.9 0.02)
    (:timer (seconds 0.5))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:func 'sparticle-motion-blur)
    (:next-time (seconds 0.335))
    (:next-launcher 1076)
    (:conerot-x (degrees 0) (degrees 360))
    (:conerot-y (degrees 0) (degrees 360))
    )
  )

(defpart 1076
  :init-specs ((:fade-a -0.48 -0.48))
  )

(defpart 1071
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 4))
    (:rot-x (degrees 4.5))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 128.0)
    (:b 128.0 128.0)
    (:a 128.0)
    (:rotvel-z (degrees -0.1))
    (:fade-a -1.6)
    (:timer (seconds 0.267))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14 glow))
    (:userdata -4096.0)
    (:next-launcher 1077)
    )
  )

(defpart 1077
  :init-specs ((:scale-x (meters 2) (meters 0.5))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0 64.0)
    (:b 128.0 128.0)
    (:next-time (seconds 0.017))
    (:next-launcher 1077)
    )
  )

(defpart 1072
  :init-specs ((:texture (glow level-default-sprite))
    (:num 2.0)
    (:scale-x (meters 1))
    (:rot-x (degrees 4.5))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0 64.0)
    (:b 128.0 128.0)
    (:a 48.0)
    (:scalevel-x (meters 0.12857144))
    (:rotvel-z (degrees -0.3) (degrees 0.6))
    (:scalevel-y :copy scalevel-x)
    (:fade-g -2.1333334)
    (:fade-b -2.1333334)
    (:timer (seconds 0.267))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 glow))
    (:userdata -4096.0)
    (:next-time (seconds 0.067))
    (:next-launcher 1078)
    )
  )

(defpart 1078
  :init-specs ((:scale-x (meters 4.5))
    (:scale-y :copy scale-x)
    (:scalevel-x (meters -0.06666667))
    (:scalevel-y :copy scalevel-x)
    (:fade-g -0.53333336)
    (:fade-a -0.8)
    )
  )

(defpart 1070
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 255.0)
    (:b 255.0)
    (:a 96.0)
    (:scalevel-x (meters 0.16666667))
    (:rotvel-z (degrees 0.3))
    (:scalevel-y :copy scalevel-x)
    (:timer (seconds 0.185))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:next-time (seconds 0.05))
    (:next-launcher 1079)
    )
  )

(defpart 1079
  :init-specs ((:scale-x (meters 3.5))
    (:scale-y :copy scale-x)
    (:scalevel-x (meters -0.0875))
    (:scalevel-y :copy scalevel-x)
    (:fade-b -6.4)
    )
  )

(defpartgroup group-for-turret-shot-die
  :id 240
  :duration (seconds 0.017)
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 249))
  )

(defpart 1080
  :init-specs ((:texture (glow-soft level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 5))
    (:rot-x (degrees 2.25))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 192.0)
    (:b 64.0)
    (:a 16.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 819.2)
    )
  )

(deftype for-turret-shot (projectile)
  ((tail-pos  vector  :inline)
   )
  )


(defmethod projectile-method-24 ((this for-turret-shot))
  (draw-beam (-> *part-id-table* 1068) (-> this tail-pos) (-> this starting-dir) #f)
  (let* ((a0-3 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> this starting-dir) 2048.0))
         (v1-2 (vector+! (new 'stack-no-clear 'vector) (-> this tail-pos) a0-3))
         (t9-2 sp-launch-particles-var)
         (a0-4 *sp-particle-system-2d*)
         (a1-4 (-> *part-id-table* 1069))
         (a2-2 *launch-matrix*)
         )
    (vector-copy! (-> a2-2 trans) v1-2)
    (t9-2 a0-4 a1-4 a2-2 (the-as sparticle-launch-state #f) (the-as sparticle-launch-control #f) 1.0)
    )
  0
  (none)
  )

(defmethod projectile-method-25 ((this for-turret-shot))
  (let* ((gp-0 (-> this root trans))
         (a1-0 (-> this tail-pos))
         (s5-1 (vector-! (new 'stack-no-clear 'vector) gp-0 a1-0))
         (f30-0 (vector-length s5-1))
         )
    (let ((s4-1 (vector+*! (new 'stack-no-clear 'vector) a1-0 s5-1 0.8)))
      (let ((f28-0 (-> *part-id-table* 1065 init-specs 4 initial-valuef)))
        (set! (-> *part-id-table* 1065 init-specs 4 initial-valuef) (fmin f28-0 (vector-length s5-1)))
        (draw-beam (-> *part-id-table* 1065) a1-0 s5-1 #f)
        (set! (-> *part-id-table* 1065 init-specs 4 initial-valuef) f28-0)
        )
      (vector-normalize! s5-1 1.0)
      (launch-particles (-> *part-id-table* 1066) s4-1)
      )
    (let ((s4-2 (new 'stack-no-clear 'matrix))
          (f26-0 (/ f30-0 (meters 30)))
          (f30-1 (-> *part-id-table* 1067 init-specs 3 initial-valuef))
          (f28-1 (-> *part-id-table* 1067 init-specs 5 initial-valuef))
          )
      (forward-up->inv-matrix s4-2 s5-1 *up-vector*)
      (vector-copy! (-> s4-2 trans) gp-0)
      (set! (-> *part-id-table* 1067 init-specs 3 initial-valuef) (* f26-0 f30-1))
      (set! (-> *part-id-table* 1067 init-specs 5 initial-valuef) (* f26-0 f28-1))
      (launch-particles (-> *part-id-table* 1067) s4-2 :origin-is-matrix #t)
      (set! (-> *part-id-table* 1067 init-specs 3 initial-valuef) f30-1)
      (set! (-> *part-id-table* 1067 init-specs 5 initial-valuef) f28-1)
      )
    )
  0
  (none)
  )

(defmethod projectile-method-26 ((this for-turret-shot))
  (let* ((gp-0 (-> this root))
         (a0-3 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> this tail-pos) (-> gp-0 trans)) 2048.0))
         (v1-2 (new 'stack-no-clear 'vector))
         )
    (vector-copy! v1-2 (-> gp-0 trans))
    (vector+! v1-2 v1-2 a0-3)
    (cond
      ((logtest? (-> *part-group-id-table* 239 flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) v1-2)
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group (-> *part-group-id-table* 239))
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) v1-2)
        (part-tracker-spawn part-tracker :to *entity-pool* :group (-> *part-group-id-table* 239))
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this for-turret-shot) (arg0 projectile-options))
  (with-pp
    (case arg0
      (((projectile-options po0 po1))
       (when (nonzero? (-> this sound-id))
         (when *sound-player-enable*
           (let ((gp-0 (the-as sound-rpc-set-param (get-sound-buffer-entry))))
             (set! (-> gp-0 command) (sound-command set-param))
             (set! (-> gp-0 id) (-> this sound-id))
             (let ((a1-1 (-> this root trans)))
               (let ((s5-1 pp))
                 (when (= a1-1 #t)
                   (if (and s5-1 (type? s5-1 process-drawable) (nonzero? (-> (the-as process-drawable s5-1) root)))
                       (set! a1-1 (-> (the-as process-drawable s5-1) root trans))
                       (set! a1-1 (the-as vector #f))
                       )
                   )
                 )
               (sound-trans-convert (-> gp-0 params trans) a1-1)
               )
             (set! (-> gp-0 params mask) (the-as uint 32))
             (-> gp-0 id)
             )
           )
         )
       )
      )
    (none)
    )
  )

(defun for-turret-shot-move ((arg0 for-turret-shot))
  (projectile-move-fill-line-sphere arg0)
  (let ((s5-0 (-> arg0 root)))
    (let ((s4-0 (new 'stack-no-clear 'vector)))
      (vector-! s4-0 (-> arg0 tail-pos) (-> s5-0 trans))
      (let ((f0-0 (vector-length s4-0)))
        (when (< 122880.0 f0-0)
          (vector-normalize! s4-0 122880.0)
          (vector+! (-> arg0 tail-pos) (-> s5-0 trans) s4-0)
          )
        )
      )
    (if (logtest? (-> s5-0 status) (collide-status touch-surface))
        (go (method-of-object arg0 impact))
        )
    )
  0
  (none)
  )

(defmethod setup-collision! ((this for-turret-shot))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction)
          (the-as (function control-info collide-query vector vector collide-status) cshape-reaction-just-move)
          )
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate enemy-yellow-shot))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 3))
      (set! (-> s4-0 prim-core collide-as) (collide-spec projectile))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec
              backgnd
              jak
              bot
              crate
              civilian
              enemy
              obstacle
              vehicle-sphere
              hit-by-others-list
              player-list
              special-obstacle
              )
            )
      (set! (-> s4-0 prim-core action) (collide-action solid deadly))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 8192.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-13 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-13 prim-core collide-as) (collide-spec projectile))
      (set! (-> v1-13 prim-core collide-with)
            (collide-spec
              backgnd
              jak
              bot
              crate
              civilian
              enemy
              obstacle
              vehicle-sphere
              hit-by-others-list
              player-list
              special-obstacle
              )
            )
      (set! (-> v1-13 prim-core action) (collide-action solid deadly))
      (set-vector! (-> v1-13 local-sphere) 0.0 0.0 0.0 819.2)
      )
    (let ((v1-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-15 prim-core collide-as) (collide-spec projectile))
      (set! (-> v1-15 prim-core collide-with)
            (collide-spec
              jak
              bot
              crate
              civilian
              enemy
              obstacle
              vehicle-sphere
              hit-by-others-list
              player-list
              special-obstacle
              )
            )
      (set! (-> v1-15 prim-core action) (collide-action solid deadly))
      (set-vector! (-> v1-15 local-sphere) 0.0 0.0 0.0 8192.0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-18 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-18 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-18 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 1))
    (set! (-> s5-0 event-self) 'touched)
    (set! (-> this root) s5-0)
    )
  (set! (-> this root pat-ignore-mask)
        (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noproj #x1 :noendlessfall #x1 :board #x1)
        )
  (none)
  )

(defmethod init-proj-settings! ((this for-turret-shot))
  (vector-copy! (-> this tail-pos) (-> this root trans))
  (set! (-> this attack-mode) 'for-turret-shot)
  (set! (-> this max-speed) 737280.0)
  (set! (-> this move) for-turret-shot-move)
  (set! (-> this timeout) (seconds 1.39))
  (set-gravity-length (-> this root dynam) 573440.0)
  (none)
  )

;; WARN: Return type mismatch (pointer process) vs (pointer for-turret-shot).
(defun spawn-for-turret-projectile ((arg0 target-turret) (arg1 vector) (arg2 vector) (arg3 float))
  (let ((gp-0 (new 'stack-no-clear 'projectile-init-by-other-params)))
    (set! (-> gp-0 ent) (-> arg0 entity))
    (set! (-> gp-0 charge) 1.0)
    (set! (-> gp-0 options) (projectile-options))
    (logclear! (-> gp-0 options) (projectile-options po14 po15 po16))
    (set! (-> gp-0 notify-handle) (process->handle arg0))
    (set! (-> gp-0 owner-handle) (the-as handle #f))
    (set! (-> gp-0 target-handle) (the-as handle #f))
    (set! (-> gp-0 target-pos quad) (the-as uint128 0))
    (set! (-> gp-0 ignore-handle) (process->handle arg0))
    (let* ((v1-11 *game-info*)
           (a0-11 (+ (-> v1-11 attack-id) 1))
           )
      (set! (-> v1-11 attack-id) a0-11)
      (set! (-> gp-0 attack-id) a0-11)
      )
    (set! (-> gp-0 timeout) (seconds 4))
    (vector-copy! (-> gp-0 pos) arg1)
    (vector-normalize-copy! (-> gp-0 vel) arg2 arg3)
    (the-as (pointer for-turret-shot) (spawn-projectile for-turret-shot gp-0 arg0 *default-dead-pool*))
    )
  )
