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

;; name: templex-obs.gc
;; name in dgo: templex-obs
;; dgos: TEMX

;; DECOMP BEGINS

;; WARN: Return type mismatch float vs none.
(defun spt-birth-func-brightness-part-temple-break-dust ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo))
  (let ((s5-0 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 31) 128))
        (s3-0 (logand 0 (rand-uint31-gen *random-generator*)))
        (s4-0 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 21) 30))
        (v1-6 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 11) 70))
        )
    (set! (-> arg2 rotate-x) (the float (- s5-0 (the-as int s3-0))))
    (set! (-> arg2 rotate-y) (the float (- s5-0 s4-0)))
    (set! (-> arg2 rotate-z) (the float (- s5-0 v1-6)))
    )
  (none)
  )

;; WARN: Return type mismatch float vs none.
(defun spt-birth-func-brightness-part-temple-break-dust-trail ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo))
  (let ((s5-0 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 31) 128))
        (s3-0 (logand 0 (rand-uint31-gen *random-generator*)))
        (s4-0 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 21) 30))
        (v1-6 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 11) 70))
        )
    (set! (-> arg2 rotate-x) (the float (- s5-0 (the-as int s3-0))))
    (set! (-> arg2 rotate-y) (the float (- s5-0 s4-0)))
    (set! (-> arg2 rotate-z) (the float (- s5-0 v1-6)))
    )
  (none)
  )

(defpartgroup group-temple-break-dust
  :id 698
  :flags (sp0 sp4)
  :bounds (static-bspherem 0 0 0 20)
  :parts ((sp-item 2700 :flags (sp7)))
  )

(defpart 2700
  :init-specs ((:texture (dirtpuff01 level-default-sprite))
    (:birth-func 'spt-birth-func-brightness-part-temple-break-dust)
    (:num 1.0)
    (:scale-x (meters 2) (meters 2))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 64.0 64.0)
    (:vel-y (meters 0.01) (meters 0.01))
    (:scalevel-x (meters 0.0033333334) (meters 0.0033333334))
    (:rotvel-z (degrees -0.2) (degrees 0.4))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.21333334)
    (:friction 0.99)
    (:timer (seconds 2))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:conerot-x (degrees -80) (degrees 160))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpartgroup group-temple-break-dust-trail
  :id 699
  :flags (sp0 sp4)
  :bounds (static-bspherem 0 0 0 20)
  :parts ((sp-item 2701 :flags (sp7)))
  )

(defpart 2701
  :init-specs ((:texture (dirtpuff01 level-default-sprite))
    (:birth-func 'spt-birth-func-brightness-part-temple-break-dust-trail)
    (:num 0.3)
    (:scale-x (meters 1) (meters 1))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 64.0 64.0)
    (:scalevel-x (meters 0.0033333334) (meters 0.0033333334))
    (:rotvel-z (degrees -0.2) (degrees 0.4))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.42666668)
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    )
  )

(deftype tpl-stone-break (process-drawable)
  ((root            collide-shape :override)
   (spool-sound-id  sound-id)
   )
  (:state-methods
    idle
    drop
    )
  )


(defskelgroup skel-tpl-stone-break tpl-stone-break tpl-stone-break-lod0-jg tpl-stone-break-idle-ja
              ((tpl-stone-break-lod0-mg (meters 20)) (tpl-stone-break-lod1-mg (meters 999999)))
              :bounds (static-spherem 3.5 0 3.5 6)
              )

(defstate idle (tpl-stone-break)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('ridden)
       (go-virtual drop)
       )
      )
    )
  :enter (behavior ()
    (set! (-> self draw force-lod) 1)
    (ja-no-eval :group! tpl-stone-break-idle-ja :num! zero)
    (logior! (-> self root root-prim prim-core action) (collide-action rideable))
    (transform-post)
    )
  :trans rider-trans
  :code sleep-code
  :post rider-post
  )

(defstate drop (tpl-stone-break)
  :virtual #t
  :enter (behavior ()
    (set! (-> self draw force-lod) 0)
    (sound-play "falling-stone")
    (set-time! (-> self state-time))
    (set! (-> self spool-sound-id)
          (add-process *gui-control* self (gui-channel gun) (gui-action queue) "rockfall" -99.0 0)
          )
    )
  :trans (behavior ()
    (let* ((s3-0 (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node tpl-stone-break-lod0-jg f)))
           (f30-1 (lerp-clamp 0.35 0.105 (* 0.0000055486507 (+ -16384.0 (vector-vector-distance s3-0 (target-pos 0))))))
           )
      (when *sound-player-enable*
        (let ((v1-5 (the-as sound-rpc-set-param (get-sound-buffer-entry))))
          (set! (-> v1-5 command) (sound-command set-param))
          (set! (-> v1-5 id) (-> self spool-sound-id))
          (set! (-> v1-5 params volume) (the int (* 1024.0 f30-1)))
          (set! (-> v1-5 params mask) (the-as uint 1))
          (-> v1-5 id)
          )
        )
      )
    (if (time-elapsed? (-> self state-time) (seconds 0.3))
        (logclear! (-> self root root-prim prim-core action) (collide-action rideable))
        )
    (if (time-elapsed? (-> self state-time) (seconds 0.75))
        (set-action!
          *gui-control*
          (gui-action play)
          (-> self spool-sound-id)
          (gui-channel none)
          (gui-action none)
          (the-as string #f)
          (the-as (function gui-connection symbol) #f)
          (the-as process #f)
          )
        )
    (rider-trans)
    )
  :code (behavior ()
    (set! (-> self draw bounds w) 1228800.0)
    (ja-no-eval :group! tpl-stone-break-drop-ja :num! (seek! max 0.5) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! max 0.5))
      )
    (until #f
      (let ((gp-0 (new 'stack 'sphere)))
        (set! (-> gp-0 quad) (-> self root trans quad))
        (set! (-> gp-0 r) 16384.0)
        (if (or (< (- (-> (target-pos 0) y) (-> self root trans y)) -40960.0) (not (sphere-in-view-frustum? gp-0)))
            (go-virtual idle)
            )
        )
      (suspend)
      )
    #f
    )
  :post rider-post
  )

(defmethod init-from-entity! ((this tpl-stone-break) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (let ((s4-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s4-0 reaction) cshape-reaction-default)
    (set! (-> s4-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s4-0 penetrated-by) (penetrate))
    (let ((s3-0 (new 'process 'collide-shape-prim-group s4-0 (the-as uint 20) 0)))
      (set! (-> s4-0 total-prims) (the-as uint 21))
      (set! (-> s3-0 prim-core collide-as) (collide-spec pusher))
      (set! (-> s3-0 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> s3-0 prim-core action) (collide-action solid rideable))
      (set! (-> s3-0 transform-index) 2)
      (set-vector! (-> s3-0 local-sphere) 14336.0 0.0 14336.0 24576.0)
      (set! (-> s4-0 root-prim) s3-0)
      )
    (pusher-init s4-0)
    (let ((v1-15 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-15 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-15 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-15 prim-core action) (collide-action solid rideable))
      (set! (-> v1-15 transform-index) 3)
      (set-vector! (-> v1-15 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-17 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 1) (the-as uint 0))))
      (set! (-> v1-17 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-17 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-17 prim-core action) (collide-action solid rideable))
      (set! (-> v1-17 transform-index) 4)
      (set-vector! (-> v1-17 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-19 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 2) (the-as uint 0))))
      (set! (-> v1-19 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-19 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-19 prim-core action) (collide-action solid rideable))
      (set! (-> v1-19 transform-index) 5)
      (set-vector! (-> v1-19 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-21 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 3) (the-as uint 0))))
      (set! (-> v1-21 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-21 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-21 prim-core action) (collide-action solid rideable))
      (set! (-> v1-21 transform-index) 6)
      (set-vector! (-> v1-21 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-23 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 4) (the-as uint 0))))
      (set! (-> v1-23 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-23 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-23 prim-core action) (collide-action solid rideable))
      (set! (-> v1-23 transform-index) 7)
      (set-vector! (-> v1-23 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-25 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 5) (the-as uint 0))))
      (set! (-> v1-25 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-25 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-25 prim-core action) (collide-action solid rideable))
      (set! (-> v1-25 transform-index) 8)
      (set-vector! (-> v1-25 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-27 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 6) (the-as uint 0))))
      (set! (-> v1-27 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-27 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-27 prim-core action) (collide-action solid rideable))
      (set! (-> v1-27 transform-index) 9)
      (set-vector! (-> v1-27 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-29 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 7) (the-as uint 0))))
      (set! (-> v1-29 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-29 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-29 prim-core action) (collide-action solid rideable))
      (set! (-> v1-29 transform-index) 10)
      (set-vector! (-> v1-29 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-31 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 8) (the-as uint 0))))
      (set! (-> v1-31 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-31 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-31 prim-core action) (collide-action solid rideable))
      (set! (-> v1-31 transform-index) 11)
      (set-vector! (-> v1-31 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-33 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 9) (the-as uint 0))))
      (set! (-> v1-33 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-33 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-33 prim-core action) (collide-action solid rideable))
      (set! (-> v1-33 transform-index) 12)
      (set-vector! (-> v1-33 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-35 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 10) (the-as uint 0))))
      (set! (-> v1-35 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-35 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-35 prim-core action) (collide-action solid rideable))
      (set! (-> v1-35 transform-index) 13)
      (set-vector! (-> v1-35 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-37 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 11) (the-as uint 0))))
      (set! (-> v1-37 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-37 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-37 prim-core action) (collide-action solid rideable))
      (set! (-> v1-37 transform-index) 14)
      (set-vector! (-> v1-37 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-39 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 12) (the-as uint 0))))
      (set! (-> v1-39 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-39 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-39 prim-core action) (collide-action solid rideable))
      (set! (-> v1-39 transform-index) 15)
      (set-vector! (-> v1-39 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-41 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 13) (the-as uint 0))))
      (set! (-> v1-41 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-41 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-41 prim-core action) (collide-action solid rideable))
      (set! (-> v1-41 transform-index) 16)
      (set-vector! (-> v1-41 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-43 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 14) (the-as uint 0))))
      (set! (-> v1-43 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-43 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-43 prim-core action) (collide-action solid rideable))
      (set! (-> v1-43 transform-index) 17)
      (set-vector! (-> v1-43 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-45 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 15) (the-as uint 0))))
      (set! (-> v1-45 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-45 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-45 prim-core action) (collide-action solid rideable))
      (set! (-> v1-45 transform-index) 18)
      (set-vector! (-> v1-45 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-47 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 16) (the-as uint 0))))
      (set! (-> v1-47 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-47 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-47 prim-core action) (collide-action solid rideable))
      (set! (-> v1-47 transform-index) 19)
      (set-vector! (-> v1-47 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-49 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 17) (the-as uint 0))))
      (set! (-> v1-49 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-49 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-49 prim-core action) (collide-action solid rideable))
      (set! (-> v1-49 transform-index) 20)
      (set-vector! (-> v1-49 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-51 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 18) (the-as uint 0))))
      (set! (-> v1-51 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-51 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-51 prim-core action) (collide-action solid rideable))
      (set! (-> v1-51 transform-index) 21)
      (set-vector! (-> v1-51 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (let ((v1-53 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 19) (the-as uint 0))))
      (set! (-> v1-53 prim-core collide-as) (collide-spec pusher))
      (set! (-> v1-53 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-53 prim-core action) (collide-action solid rideable))
      (set! (-> v1-53 transform-index) 22)
      (set-vector! (-> v1-53 local-sphere) 0.0 0.0 0.0 12288.0)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-56 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-56 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-56 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-tpl-stone-break" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (if (task-node-closed? (game-task-node volcano-darkeco-introduction))
      (cleanup-for-death this)
      (go (method-of-object this idle))
      )
  )
