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

;; name: wcar-projectiles.gc
;; name in dgo: wcar-projectiles
;; dgos: LPATK, LFACCAR, WASALL

;; DECOMP BEGINS

(deftype v-scorp-shot (projectile)
  ((init-pos        vector  :inline)
   (init-dir        vector  :inline)
   (collide-normal  vector  :inline)
   )
  )


(defmethod projectile-method-24 ((this v-scorp-shot))
  0
  (none)
  )

(defmethod projectile-method-26 ((this v-scorp-shot))
  (rlet ((vf0 :class vf)
         (vf4 :class vf)
         (vf5 :class vf)
         (vf6 :class vf)
         )
    (init-vf0-vector)
    (let ((s3-1 (vector-! (new 'stack-no-clear 'vector) (-> this root trans) (-> this init-pos))))
      (draw-beam (-> *part-id-table* 975) (-> this init-pos) s3-1 #t)
      (draw-beam (-> *part-id-table* 978) (-> this init-pos) (-> this starting-dir) #f)
      (when (not (logtest? (projectile-options po20) (-> this options)))
        (let ((s5-0 (-> *part-id-table* 986))
              (s4-0 (-> *part-id-table* 985))
              )
          (new 'stack-no-clear 'vector)
          (let ((s2-0 (vector-reflect! (new 'stack-no-clear 'vector) s3-1 (-> this collide-normal))))
            (vector-normalize! s2-0 1.0)
            (get-field-spec-by-id s5-0 (sp-field-id spt-conerot-x))
            (get-field-spec-by-id s5-0 (sp-field-id spt-conerot-y))
            (get-field-spec-by-id s5-0 (sp-field-id spt-conerot-z))
            (let ((a1-7 (new 'stack-no-clear 'matrix))
                  (s1-0 (new 'stack-no-clear 'vector))
                  (s3-2 (new 'stack-no-clear 'vector))
                  )
              (vector-cross! (-> a1-7 rvec) *y-vector* s2-0)
              (vector-cross! (-> a1-7 uvec) s2-0 (-> a1-7 rvec))
              (vector-copy! (-> a1-7 fvec) s2-0)
              (matrix->eul (the-as euler-angles s1-0) a1-7 21)
              (vector-negate! s3-2 s1-0)
              (let ((a0-15 s3-2))
                (let ((v1-19 s3-2))
                  (let ((a1-10 -3640.889))
                    (.mov vf6 a1-10)
                    )
                  (.lvf vf4 (&-> v1-19 quad))
                  )
                (.add.x.vf.w vf5 vf0 vf0)
                (.add.x.vf.xyz vf5 vf4 vf6)
                (.svf (&-> a0-15 quad) vf5)
                )
              (sparticle-set-conerot s5-0 s3-2)
              (sparticle-set-conerot s4-0 s3-2)
              )
            )
          )
        (cond
          ((logtest? (-> group-gun-scorp-shot-hit flags) (sp-group-flag sp13))
           (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
           (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-gun-scorp-shot-hit)
           )
          (else
            (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
            (part-tracker-spawn part-tracker :to *entity-pool* :group group-gun-scorp-shot-hit)
            )
          )
        )
      )
    0
    (none)
    )
  )

(defmethod projectile-method-27 ((this v-scorp-shot))
  (draw-beam (-> *part-id-table* 975) (-> this init-pos) (-> this init-dir) #f)
  (draw-beam (-> *part-id-table* 978) (-> this init-pos) (-> this starting-dir) #f)
  0
  (none)
  )

;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this v-scorp-shot) (arg0 projectile-options))
  (let ((v1-0 arg0))
    (cond
      ((zero? v1-0)
       (sound-play "scorp-gun-fire")
       )
      ((= v1-0 (projectile-options po0))
       (sound-play "blue-shot-hit")
       )
      )
    )
  (none)
  )

(defun v-scorp-shot-move ((arg0 v-scorp-shot))
  (projectile-move-fill-line-sphere arg0)
  (cond
    ((logtest? (-> arg0 root status) (collide-status touch-actor))
     (projectile-method-26 arg0)
     )
    ((logtest? (-> arg0 root status) (collide-status touch-surface))
     (go (method-of-object arg0 impact))
     )
    )
  0
  (none)
  )

;; WARN: Return type mismatch int vs collide-status.
(defun cshape-reaction-scorp-shot ((arg0 control-info) (arg1 collide-query) (arg2 vector) (arg3 vector))
  (vector-reset! arg2)
  (let ((a1-1 (new 'stack-no-clear 'vector)))
    (vector-float*! a1-1 (-> arg1 move-dist) (-> arg1 best-dist))
    (move-by-vector! arg0 a1-1)
    )
  (vector-copy! (-> (the-as v-scorp-shot (-> arg0 process)) collide-normal) (-> arg1 best-other-tri normal))
  (let ((v1-7 (as-type (-> arg1 best-other-tri collide-ptr) collide-shape-prim))
        (v0-2 4)
        )
    (cond
      (v1-7
        (set! v0-2 32)
        )
      (else
        )
      )
    (logior! (-> arg0 status) v0-2)
    (the-as collide-status v0-2)
    )
  )

(defmethod setup-collision! ((this v-scorp-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) cshape-reaction-scorp-shot)
    (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 bot crate civilian enemy obstacle vehicle-sphere hit-by-others-list pusher shield)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 1228.8)
      (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 obstacle pusher shield))
      (set! (-> v1-13 prim-core action) (collide-action solid))
      (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 bot crate civilian enemy vehicle-sphere hit-by-others-list player-list)
            )
      (set! (-> v1-15 prim-core action) (collide-action solid))
      (set-vector! (-> v1-15 local-sphere) 0.0 0.0 0.0 4096.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)
        )
  0
  (none)
  )

(defmethod init-proj-settings! ((this v-scorp-shot))
  (with-pp
    (vector-copy! (-> this init-pos) (-> this root trans))
    (vector-copy! (-> this init-dir) (-> this starting-dir))
    (vector-normalize-copy! (-> this root transv) (-> this init-dir) (* 491520.0 (-> pp clock frames-per-second)))
    (set! (-> this attack-mode) 'eco-blue)
    (set! (-> this max-speed) (* 491520.0 (-> pp clock frames-per-second)))
    (set! (-> this timeout) 1)
    (set! (-> this move) v-scorp-shot-move)
    (vector-reset! (-> this collide-normal))
    (set! (-> this damage) 4.0)
    (set! (-> this vehicle-impulse-factor) 0.5)
    (logior! (-> this options) (projectile-options po13))
    0
    (none)
    )
  )

(deftype v-snake-shot (v-scorp-shot)
  ()
  )


;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this v-snake-shot) (arg0 projectile-options))
  (let ((v1-0 arg0))
    (cond
      ((zero? v1-0)
       (sound-play "snake-gun-fire")
       )
      ((= v1-0 (projectile-options po0))
       (sound-play "blue-shot-hit")
       )
      )
    )
  (none)
  )

(defmethod deal-damage! ((this v-snake-shot) (arg0 process) (arg1 event-message-block))
  (let ((gp-0 ((method-of-type v-scorp-shot deal-damage!) this arg0 arg1)))
    (when gp-0
      (if (logtest? (process-mask vehicle) (-> arg0 mask))
          (sound-play "snake-riccos")
          )
      )
    gp-0
    )
  )

(deftype v-rhino-shot (guard-shot)
  ()
  )


(defmethod projectile-method-24 ((this v-rhino-shot))
  (draw-beam (-> *part-id-table* 854) (-> 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* 855))
         (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 v-rhino-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)))
      (set! (-> *part-id-table* 980 init-specs 4 initial-valuef) (vector-length s5-1))
      (draw-beam (-> *part-id-table* 980) a1-0 s5-1 #f)
      (vector-normalize! s5-1 1.0)
      (launch-particles (-> *part-id-table* 981) s4-1)
      )
    (let ((s4-2 (new 'stack-no-clear 'matrix))
          (f26-0 (/ f30-0 (meters 30)))
          (f30-1 (-> *part-id-table* 982 init-specs 3 initial-valuef))
          (f28-0 (-> *part-id-table* 982 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* 982 init-specs 3 initial-valuef) (* f26-0 f30-1))
      (set! (-> *part-id-table* 982 init-specs 5 initial-valuef) (* f26-0 f28-0))
      (launch-particles (-> *part-id-table* 982) s4-2 :origin-is-matrix #t)
      (set! (-> *part-id-table* 982 init-specs 3 initial-valuef) f30-1)
      (set! (-> *part-id-table* 982 init-specs 5 initial-valuef) f28-0)
      )
    )
  0
  (none)
  )

(defmethod projectile-method-26 ((this v-rhino-shot))
  (let* ((s5-0 (-> this root))
         (a0-3 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> this tail-pos) (-> s5-0 trans)) 2048.0))
         (v1-1 (new 'stack-no-clear 'vector))
         )
    (vector-copy! v1-1 (-> s5-0 trans))
    (vector+! v1-1 v1-1 a0-3)
    (cond
      ((-> this hit-actor?)
       (cond
         ((logtest? (-> group-guard-shot-hit-object flags) (sp-group-flag sp13))
          (vector-copy! (-> *launch-matrix* trans) v1-1)
          (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-guard-shot-hit-object)
          )
         (else
           (vector-copy! (-> *launch-matrix* trans) v1-1)
           (part-tracker-spawn part-tracker :to *entity-pool* :group group-guard-shot-hit-object)
           )
         )
       )
      ((logtest? (-> group-guard-shot-hit flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) v1-1)
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-guard-shot-hit)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) v1-1)
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-guard-shot-hit)
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this v-rhino-shot) (arg0 projectile-options))
  (let ((v1-0 arg0))
    (cond
      ((zero? v1-0)
       (sound-play "rhino-gun-fire")
       )
      ((= v1-0 (projectile-options po0))
       (sound-play "blue-shot-hit")
       )
      )
    )
  (none)
  )

(defmethod deal-damage! ((this v-rhino-shot) (arg0 process) (arg1 event-message-block))
  (let ((gp-0 ((method-of-type v-scorp-shot deal-damage!) (the-as v-scorp-shot this) arg0 arg1)))
    (when gp-0
      (if (logtest? (process-mask vehicle) (-> arg0 mask))
          (sound-play "rhino-riccos")
          )
      )
    gp-0
    )
  )

;; WARN: Return type mismatch sound-id vs none.
(defmethod init-proj-settings! ((this v-rhino-shot))
  (let ((t9-0 (method-of-type guard-shot init-proj-settings!)))
    (t9-0 this)
    )
  (set! (-> this damage) 6.0)
  (set! (-> this vehicle-damage-factor) 1.0)
  (set! (-> this vehicle-impulse-factor) 0.5)
  (set! (-> this timeout) (seconds 0.5))
  (set! (-> this sound-id) (new-sound-id))
  (none)
  )

(deftype v-toad-shot (projectile)
  ((trail-tracker  handle)
   (blast-radius   float)
   )
  (:methods
    (set-y-vel (_type_) none)
    )
  )


(defskelgroup skel-v-toad-shot gun gun-grenade-lod0-jg gun-grenade-idle-ja
              ((gun-grenade-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 2)
              :texture-level 10
              )

(defmethod play-impact-sound ((this v-toad-shot) (arg0 projectile-options))
  (let ((v1-0 arg0))
    (cond
      ((zero? v1-0)
       )
      ((= v1-0 (projectile-options po0))
       (sound-play "toad-shot-hit")
       )
      )
    )
  0
  (none)
  )

(defmethod set-y-vel ((this v-toad-shot))
  (+! (-> this root transv y) (* -163840.0 (seconds-per-frame)))
  0
  (none)
  )

(defmethod setup-collision! ((this v-toad-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) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate explode))
    (let ((v1-7 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-7 prim-core action) (collide-action solid))
      (set-vector! (-> v1-7 local-sphere) 0.0 0.0 0.0 819.2)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-7)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-10 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-10 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-10 prim-core collide-with))
      )
    (set! (-> s5-0 event-self) 'touched)
    (set! (-> this root) s5-0)
    )
  (set-collide-with!
    (-> this root)
    (collide-spec
      backgnd
      bot
      crate
      civilian
      enemy
      obstacle
      vehicle-sphere
      hit-by-player-list
      hit-by-others-list
      collectable
      pusher
      shield
      vehicle-sphere-no-probe
      )
    )
  (set-collide-as! (-> this root) (collide-spec projectile))
  (set! (-> this root pat-ignore-mask)
        (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noproj #x1 :noendlessfall #x1 :board #x1)
        )
  (none)
  )

(defmethod projectile-method-40 ((this v-toad-shot))
  256
  )

(defmethod init-proj-settings! ((this v-toad-shot))
  (set! (-> this attack-mode) 'explode)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-toad-shot" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (let ((t9-2 (method-of-type projectile init-proj-settings!)))
    (t9-2 this)
    )
  (set! (-> this part) (create-launch-control group-guard-grenade this))
  (set! (-> this blast-radius) 102400.0)
  (set! (-> this max-speed) 90112.0)
  (set! (-> this timeout) (seconds 4))
  (set! (-> this update-velocity) (method-of-object this set-y-vel))
  (set! (-> this damage) 0.0)
  (let ((v1-13 (new 'stack-no-clear 'vector)))
    (set! (-> v1-13 x) 2.0)
    (set! (-> v1-13 y) 2.0)
    (set! (-> v1-13 z) 2.0)
    (set! (-> v1-13 w) 1.0)
    (vector-copy! (-> this root scale) v1-13)
    )
  (let ((s5-1 (new 'stack-no-clear 'light-trail-tracker-spawn-params)))
    (set! (-> s5-1 tracked-obj) (process->handle this))
    (set! (-> s5-1 appearance) *toad-grenade-trail*)
    (set! (-> s5-1 max-num-crumbs) (the int (* 0.5 (the float (-> s5-1 appearance max-age)))))
    (set! (-> s5-1 track-immediately?) #t)
    (let* ((v1-26
             (estimate-light-trail-mem-usage
               (the-as uint (-> s5-1 max-num-crumbs))
               (the-as uint (= (-> s5-1 appearance lie-mode) (lie-mode use-two-strips)))
               )
             )
           (s4-1 (get-process *default-dead-pool* light-trail-tracker-projectile (+ v1-26 8192) 1))
           )
      (set! (-> this trail-tracker)
            (ppointer->handle (when s4-1
                                (let ((t9-6 (method-of-type process activate)))
                                  (t9-6 s4-1 this "light-trail" (the-as pointer #x70004000))
                                  )
                                (run-now-in-process s4-1 light-trail-tracker-init-by-other s5-1)
                                (-> s4-1 ppointer)
                                )
                              )
            )
      )
    )
  0
  (none)
  )

(defmethod projectile-method-24 ((this v-toad-shot))
  (draw-beam (-> *part-id-table* 979) (-> this root trans) (-> this starting-dir) #f)
  (none)
  )

(defmethod projectile-method-25 ((this v-toad-shot))
  (spawn (-> this part) (-> this root trans))
  (ja-post)
  0
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defmethod projectile-method-39 ((this v-toad-shot))
  (if (logtest? (-> this root status) (collide-status impact-surface))
      (go (method-of-object this impact))
      )
  (none)
  )

(defstate impact (v-toad-shot)
  :virtual #t
  :code (behavior ()
    (let ((gp-0 (new 'stack-no-clear 'explosion-init-params)))
      (vector-copy! (-> gp-0 spawn-point) (-> self root trans))
      (quaternion-identity! (-> gp-0 spawn-quat))
      (set! (-> gp-0 radius) (-> self blast-radius))
      (set! (-> gp-0 scale) 2.0)
      (set! (-> gp-0 group) group-toad-grenade-shot-explode)
      (set! (-> gp-0 collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> gp-0 damage) 20.0)
      (set! (-> gp-0 damage-scale) 3.0)
      (set! (-> gp-0 vehicle-damage-factor) 1.0)
      (set! (-> gp-0 vehicle-impulse-factor) 1.0)
      (set! (-> gp-0 ignore-proc) (process->handle (handle->process (-> self ignore-handle))))
      (explosion-spawn gp-0 self)
      )
    (logior! (-> self draw status) (draw-control-status no-draw))
    (let ((v1-20 (-> self root root-prim)))
      (set! (-> v1-20 prim-core collide-as) (collide-spec))
      (set! (-> v1-20 prim-core collide-with) (collide-spec))
      )
    0
    (send-event (handle->process (-> self trail-tracker)) 'notice 'die)
    (while (-> self child)
      (suspend)
      )
    (deactivate self)
    )
  )

(deftype v-marauder-shot (guard-shot)
  ()
  )


;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this v-marauder-shot) (arg0 projectile-options))
  (let ((v1-0 arg0))
    (cond
      ((zero? v1-0)
       (sound-play "inter-gun-fire")
       )
      ((= v1-0 (projectile-options po0 po1))
       (let ((f0-0 (doppler-pitch-shift (-> this root trans) (-> this root transv)))
             (a0-7 (static-sound-spec "inter-doppler" :group 0 :volume 0.0 :mask (pitch reg0)))
             )
         (set! (-> a0-7 volume) 1024)
         (set! (-> a0-7 pitch-mod) (the int (* 1524.0 f0-0)))
         (sound-play-by-spec a0-7 (-> this sound-id) (-> this root trans))
         )
       )
      ((= v1-0 (projectile-options po0))
       (sound-play "guard-shot-hit")
       )
      )
    )
  (none)
  )

;; WARN: Return type mismatch sound-id vs none.
(defmethod init-proj-settings! ((this v-marauder-shot))
  (let ((t9-0 (method-of-type guard-shot init-proj-settings!)))
    (t9-0 this)
    )
  (set! (-> this vehicle-damage-factor) 0.333)
  (set! (-> this vehicle-impulse-factor) 0.25)
  (set! (-> this timeout) (seconds 1.25))
  (set! (-> this sound-id) (new-sound-id))
  (none)
  )

(defmethod deal-damage! ((this v-marauder-shot) (arg0 process) (arg1 event-message-block))
  (when ((method-of-type guard-shot deal-damage!) this arg0 arg1)
    (if (logtest? (process-mask vehicle) (-> arg0 mask))
        (sound-play "inter-riccos")
        )
    #t
    )
  )
