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

;; name: grim.gc
;; name in dgo: grim
;; dgos: SEB, SWB, UNB

;; DECOMP BEGINS

(defmethod init-enemy-collision! ((this grim))
  "Initializes the [[collide-shape-moving]] and any ancillary tasks to make the enemy collide properly"
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum hit-by-others))))
    (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 penetrated-by) (penetrate
                                    generic-attack
                                    lunge
                                    flop
                                    punch
                                    spin
                                    roll
                                    uppercut
                                    bonk
                                    tube
                                    vehicle
                                    flut-attack
                                    board
                                    mech-punch
                                    dark-punch
                                    dark-giant
                                    )
          )
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 3) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 4))
      (set! (-> s4-0 prim-core collide-as) (collide-spec bot bot-targetable))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid can-ride no-standon))
      (set-vector! (-> s4-0 local-sphere) 0.0 5734.4 0.0 7372.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 bot bot-targetable))
      (set! (-> v1-13 prim-core collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> v1-13 prim-core action) (collide-action solid can-ride))
      (set-vector! (-> v1-13 local-sphere) 0.0 3686.4 0.0 3686.4)
      )
    (let ((v1-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-15 prim-core collide-as) (collide-spec bot bot-targetable))
      (set! (-> v1-15 prim-core collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> v1-15 prim-core action) (collide-action solid))
      (set-vector! (-> v1-15 local-sphere) 0.0 5939.2 0.0 3686.4)
      )
    (let ((v1-17 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-17 prim-core collide-as) (collide-spec bot bot-targetable))
      (set! (-> v1-17 prim-core collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> v1-17 prim-core action) (collide-action solid no-standon))
      (set-vector! (-> v1-17 local-sphere) 0.0 8192.0 0.0 3686.4)
      )
    (set! (-> s5-0 nav-radius) 4096.0)
    (let ((v1-19 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-19 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-19 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 3))
    (set! (-> s5-0 event-priority) (the-as uint 6))
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod init-enemy! ((this grim))
  "Common method called to initialize the enemy, typically sets up default field values and calls ancillary helper methods"
  (let ((t9-0 (method-of-type jinx init-enemy!)))
    (t9-0 this)
    )
  (set! (-> this channel) (gui-channel grim))
  (set! (-> this min-speed) 20480.0)
  (set! (-> this max-speed) 40960.0)
  (set! (-> this follow-offset) 12288.0)
  (set! (-> this bot-health-index) 1)
  (set! (-> this spot-color) (the-as uint #x50008f00))
  (setup-masks (-> this draw) 654 #x3fd70)
  (none)
  )

(defmethod ruffian-method-244 ((this grim))
  (with-pp
    (ruffian-method-245 this)
    (let ((f30-0 (-> this nav state speed)))
      (let ((f0-1 (lerp-scale 0.0 1.0 f30-0 12288.0 40960.0)))
        (seek! (-> this travel-anim-interp) f0-1 (* 4.0 (seconds-per-frame)))
        )
      (let ((f28-0 (-> this travel-anim-interp))
            (v1-9 (if (> (-> this skel active-channels) 0)
                      (-> this skel root-channel 0 frame-group)
                      )
                  )
            )
        (cond
          ((and v1-9 (= v1-9 (-> this draw art-group data 34)))
           (let ((v1-14 (-> this skel root-channel 1)))
             (set! (-> v1-14 frame-interp 1) f28-0)
             (set! (-> v1-14 frame-interp 0) f28-0)
             )
           (let* ((f28-1 (current-cycle-distance (-> this skel)))
                  (f0-5 (quaternion-y-angle (-> this root quat)))
                  (f1-2 (deg- f0-5 (-> this travel-prev-ry)))
                  (f0-8 (fmin 40960.0 (* 0.35342914 (-> pp clock frames-per-second) (fabs f1-2))))
                  (f0-11 (/ (* 16.0 (fmax f30-0 f0-8)) (* 15.0 f28-1)))
                  (a0-11 (-> this skel root-channel 0))
                  )
             (set! (-> a0-11 param 0) f0-11)
             (joint-control-channel-group-eval! a0-11 (the-as art-joint-anim #f) num-func-loop!)
             )
           (let ((a0-12 (-> this skel root-channel 1)))
             (set! (-> a0-12 param 0) 0.0)
             (joint-control-channel-group-eval! a0-12 (the-as art-joint-anim #f) num-func-chan)
             )
           )
          (else
            (ja-channel-push! 2 (seconds 0.15))
            (let ((a0-14 (-> this skel root-channel 0)))
              (set! (-> a0-14 dist) 13107.2)
              (set! (-> a0-14 frame-group) (the-as art-joint-anim (-> this draw art-group data 34)))
              (set! (-> a0-14 param 0) 1.0)
              (joint-control-channel-group! a0-14 (the-as art-joint-anim (-> this draw art-group data 34)) num-func-loop!)
              )
            (let ((a0-15 (-> this skel root-channel 1)))
              (set! (-> a0-15 frame-interp 1) f28-0)
              (set! (-> a0-15 frame-interp 0) f28-0)
              (set! (-> a0-15 dist) 21843.969)
              (set! (-> a0-15 frame-group) (the-as art-joint-anim (-> this draw art-group data 35)))
              (set! (-> a0-15 param 0) 0.0)
              (joint-control-channel-group! a0-15 (the-as art-joint-anim (-> this draw art-group data 35)) num-func-chan)
              )
            )
          )
        )
      )
    (none)
    )
  )

(defstate die-falling (grim)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type ruffian die-falling) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (play-death-sound self "hal159")
    )
  )
