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

;; name: jinx-bomb.gc
;; name in dgo: jinx-bomb
;; dgos: SEB, SWB, UNB

;; (define-extern jinx-bomb-init-by-other (function vector quaternion none :behavior jinx-bomb))

;; DECOMP BEGINS

(deftype jinx-bomb (process-focusable)
  ((fuse-delay     uint32)
   (attack-id      uint32)
   (shake-screen?  symbol)
   (explode-func   (function jinx-bomb none))
   )
  (:state-methods
    idle
    explode
    )
  )


(defskelgroup skel-jinx-bomb jinx-bomb jinx-bomb-lod0-jg -1
              ((jinx-bomb-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0.2 0 0.4)
              )

(defstate idle (jinx-bomb)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trigger)
       (go-virtual explode)
       )
      (('die-fast)
       (go empty-state)
       )
      )
    )
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (if (and (nonzero? (-> self fuse-delay))
             (time-elapsed? (-> self state-time) (the-as time-frame (-> self fuse-delay)))
             )
        (go-virtual explode)
        )
    )
  :code (behavior ()
    (let ((v1-1 (-> self root root-prim)))
      (set! (-> v1-1 prim-core collide-as) (-> self root backup-collide-as))
      (set! (-> v1-1 prim-core collide-with) (-> self root backup-collide-with))
      )
    (sleep-code)
    )
  :post ja-post
  )

(defstate explode (jinx-bomb)
  :virtual #t
  :code (behavior ()
    (set-time! (-> self state-time))
    (logior! (-> self draw status) (draw-control-status no-draw))
    (let ((v1-6 (-> self root root-prim)))
      (set! (-> v1-6 prim-core collide-as) (collide-spec))
      (set! (-> v1-6 prim-core collide-with) (collide-spec))
      )
    0
    (let ((gp-0 (new 'stack-no-clear 'explosion-init-params)))
      (set! (-> gp-0 spawn-point quad) (-> self root trans quad))
      (quaternion-copy! (-> gp-0 spawn-quat) (-> self root quat))
      (set! (-> gp-0 radius) 40960.0)
      (set! (-> gp-0 group) group-sewer-explode0)
      (set! (-> gp-0 collide-with) (collide-spec jak bot player-list))
      (set! (-> gp-0 penetrate-using) (penetrate explode))
      (explosion-spawn self explosion gp-0)
      )
    (if (-> self shake-screen?)
        (activate! *camera-smush-control* 4096.0 37 510 1.0 0.8 (-> self clock))
        )
    (let ((t9-3 (-> self explode-func)))
      (if t9-3
          (t9-3 self)
          )
      )
    (while (-> self child)
      (suspend)
      )
    (deactivate self)
    )
  )

;; WARN: Return type mismatch object vs none.
(defbehavior jinx-bomb-init-by-other jinx-bomb ((arg0 vector) (arg1 quaternion) (arg2 level) (arg3 uint) (arg4 (function jinx-bomb none)) (arg5 symbol))
  (set! (-> self level) arg2)
  (set! (-> self fuse-delay) arg3)
  (set! (-> self explode-func) arg4)
  (set! (-> self shake-screen?) arg5)
  (let* ((v1-0 *game-info*)
         (a0-2 (+ (-> v1-0 attack-id) 1))
         )
    (set! (-> v1-0 attack-id) a0-2)
    (set! (-> self attack-id) a0-2)
    )
  (let ((s4-0 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
    (let ((v1-3 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> v1-3 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-3 prim-core collide-with) (collide-spec jak bot player-list))
      (set! (-> v1-3 prim-core action) (collide-action solid))
      (set-vector! (-> v1-3 local-sphere) 0.0 819.2 0.0 1228.8)
      (set! (-> s4-0 total-prims) (the-as uint 1))
      (set! (-> s4-0 root-prim) v1-3)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-6 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-6 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-6 prim-core collide-with))
      )
    (set! (-> s4-0 event-self) 'touched)
    (set! (-> self root) s4-0)
    )
  (let ((v1-9 (-> self root)))
    (let ((a0-11 (-> v1-9 root-prim)))
      (set! (-> v1-9 backup-collide-as) (-> a0-11 prim-core collide-as))
      (set! (-> v1-9 backup-collide-with) (-> a0-11 prim-core collide-with))
      )
    (let ((v1-10 (-> v1-9 root-prim)))
      (set! (-> v1-10 prim-core collide-as) (collide-spec))
      (set! (-> v1-10 prim-core collide-with) (collide-spec))
      )
    )
  0
  (set! (-> self root trans quad) (-> arg0 quad))
  (quaternion-copy! (-> self root quat) arg1)
  (vector-identity! (-> self root scale))
  (vector-reset! (-> self root transv))
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-jinx-bomb" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (ja-channel-push! 1 0)
  (ja :group! jinx-bomb-idle-ja :num! min)
  (transform-post)
  (go-virtual idle)
  (none)
  )
