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

;; name: tomb-boulder.gc
;; name in dgo: tomb-boulder
;; dgos: TOE

(declare-type tomb-wing-door com-airlock)

;; DECOMP BEGINS

(defpartgroup group-tomb-boulder-roll :id 739 :bounds (static-bspherem 0 0 0 40) :parts ((sp-item 3282)))

(defpart 3282
  :init-specs ((:texture (new 'static 'texture-id :page #xc))
    (:num 2.0)
    (:scale-x (meters 1) (meters 1))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 96.0 32.0)
    (:b 64.0 32.0)
    (:a 16.0 32.0)
    (:vel-y (meters 0.08) (meters 0.026666667))
    (:scalevel-x (meters 0.0033333334))
    (:rotvel-z (degrees -0.2) (degrees 0.4))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.16)
    (:accel-y (meters -0.00033333333))
    (:friction 0.95)
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-12))
    (:conerot-x (degrees 80) (degrees 10))
    (:conerot-y (degrees 0) (degrees 360))
    )
  )

(defpartgroup group-tomb-boulder-bounce
  :id 740
  :duration (seconds 0.25)
  :bounds (static-bspherem 0 0 0 40)
  :parts ((sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    (sp-item 3282)
    )
  )

(defskelgroup skel-tomb-boulder tomb-boulder tomb-boulder-lod0-jg -1
              ((tomb-boulder-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 7)
              :origin-joint-index 4
              )

(defskelgroup skel-tomb-spider tomb-boulder tomb-boulder-spider-lod0-jg -1
              ((tomb-boulder-spider-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 2 0 50)
              :shadow tomb-boulder-spider-shadow-mg
              :origin-joint-index 3
              :shadow-joint-index 3
              )

(defskelgroup skel-tomb-boulder-explode tomb-boulder tomb-boulder-explode-lod0-jg -1
              ((tomb-boulder-explode-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 200)
              :origin-joint-index 3
              )

(defskelgroup skel-tomb-boulder-stop tomb-boulder tomb-boulder-stop-lod0-jg -1
              ((tomb-boulder-stop-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 200)
              :origin-joint-index 7
              )

(defskelgroup skel-tomb-boulder-pillar tomb-boulder tomb-boulder-pillar-lod0-jg -1
              ((tomb-boulder-pillar-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 15 0 30)
              :origin-joint-index 3
              )

(defskelgroup skel-tomb-boulder-stick tomb-boulder tomb-boulder-stick-lod0-jg tomb-boulder-stick-idle-ja
              ((tomb-boulder-stick-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 3.5)
              :origin-joint-index 3
              )

(defskelgroup skel-tomb-boulder-wing-door tomb-boulder tomb-boulder-wing-door-lod0-jg tomb-boulder-wing-door-idle-ja
              ((tomb-boulder-wing-door-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 -10 0 20)
              :origin-joint-index 3
              )

(deftype tomb-spider (process-drawable)
  ((root  collide-shape-moving :override)
   )
  (:state-methods
    idle
    )
  )


(defstate idle (tomb-spider)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('touch 'attack)
       (send-event
         proc
         'attack
         (-> block param 0)
         (static-attack-info ((id (new-attack-id)) (shove-up (meters 3)) (mode 'tomb-spider)))
         )
       )
      )
    )
  :code (behavior ()
    (until #f
      ;; og:preserve-this manually patched
      (clone-anim-once (ppointer->handle (-> self parent)) #t "spider-")
      (update-transforms (-> self root))
      (suspend)
      )
    #f
    )
  )

;; WARN: Return type mismatch object vs none.
(defbehavior tomb-spider-init tomb-spider ()
  (let ((gp-0 (new 'process 'collide-shape-moving self (collide-list-enum hit-by-player))))
    (set! (-> gp-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> gp-0 reaction) cshape-reaction-default)
    (set! (-> gp-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> gp-0 penetrated-by) (penetrate))
    (let ((s5-0 (new 'process 'collide-shape-prim-group gp-0 (the-as uint 2) 0)))
      (set! (-> gp-0 total-prims) (the-as uint 3))
      (set! (-> s5-0 prim-core collide-as) (collide-spec enemy))
      (set! (-> s5-0 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> s5-0 transform-index) 3)
      (set-vector! (-> s5-0 local-sphere) 0.0 0.0 0.0 61440.0)
      (set! (-> gp-0 root-prim) s5-0)
      )
    (let ((v1-12 (new 'process 'collide-shape-prim-sphere gp-0 (the-as uint 0))))
      (set! (-> v1-12 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-12 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-12 prim-core action) (collide-action solid deadly no-standon))
      (set! (-> v1-12 transform-index) 6)
      (set-vector! (-> v1-12 local-sphere) 0.0 0.0 0.0 20480.0)
      )
    (let ((v1-14 (new 'process 'collide-shape-prim-sphere gp-0 (the-as uint 0))))
      (set! (-> v1-14 prim-core collide-as) (collide-spec enemy pusher))
      (set! (-> v1-14 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-14 prim-core action) (collide-action solid deadly no-standon))
      (set! (-> v1-14 transform-index) 4)
      (set-vector! (-> v1-14 local-sphere) 0.0 0.0 10240.0 6963.2)
      )
    (set! (-> gp-0 nav-radius) (* 0.75 (-> gp-0 root-prim local-sphere w)))
    (let ((v1-17 (-> gp-0 root-prim)))
      (set! (-> gp-0 backup-collide-as) (-> v1-17 prim-core collide-as))
      (set! (-> gp-0 backup-collide-with) (-> v1-17 prim-core collide-with))
      )
    (set! (-> self root) gp-0)
    )
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-tomb-spider" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (logior! (-> self skel status) (joint-control-status sync-math))
  (go-virtual idle)
  (none)
  )

(deftype tomb-boulder-stop (process-drawable)
  ((root    collide-shape-moving :override)
   (prefix  string)
   )
  (:state-methods
    idle
    )
  )


(defstate idle (tomb-boulder-stop)
  :virtual #t
  :code (behavior ()
    (until #f
      ;; og:preserve-this manually patched
      (clone-anim-once (ppointer->handle (-> self parent)) #t (-> self prefix))
      (update-transforms (-> self root))
      (suspend)
      )
    #f
    )
  )

;; WARN: Return type mismatch object vs none.
(defbehavior tomb-boulder-stop-init tomb-boulder-stop ((arg0 string))
  (let ((s5-0 (new 'process 'collide-shape-moving self (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 penetrated-by) (penetrate))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 1) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 2))
      (set! (-> s4-0 prim-core collide-as) (collide-spec enemy pusher))
      (set! (-> s4-0 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> s4-0 transform-index) 7)
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 122880.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (pusher-init s5-0)
    (let ((v1-14 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-14 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-14 prim-core collide-with)
            (collide-spec backgnd jak bot crate obstacle hit-by-others-list player-list)
            )
      (set! (-> v1-14 prim-core action) (collide-action solid no-standon))
      (set! (-> v1-14 transform-index) 7)
      (set-vector! (-> v1-14 local-sphere) 0.0 0.0 0.0 122880.0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-17 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-17 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-17 prim-core collide-with))
      )
    (set! (-> self root) s5-0)
    )
  (set! (-> self prefix) arg0)
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-tomb-boulder-stop" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (logior! (-> self skel status) (joint-control-status sync-math))
  (go-virtual idle)
  (none)
  )

(deftype tomb-boulder-pillar (process-drawable)
  ((root    collide-shape-moving :override)
   (prefix  string)
   )
  (:state-methods
    idle
    )
  )


(defstate idle (tomb-boulder-pillar)
  :virtual #t
  :trans rider-trans
  :code (behavior ()
    (until #f
      ;; og:preserve-this manually patched
      (clone-anim-once (ppointer->handle (-> self parent)) #t (-> self prefix))
      (update-transforms (-> self root))
      (pull-riders! (-> self root))
      (do-push-aways (-> self root))
      (suspend)
      )
    #f
    )
  )

;; WARN: Return type mismatch object vs none.
(defbehavior tomb-boulder-pillar-init tomb-boulder-pillar ((arg0 string))
  (let ((s5-0 (new 'process 'collide-shape-moving self (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)
          )
    (let ((s4-0 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> s4-0 prim-core collide-as) (collide-spec obstacle pusher))
      (set! (-> s4-0 prim-core collide-with) (collide-spec jak bot player-list))
      (set! (-> s4-0 prim-core action) (collide-action solid rideable))
      (set! (-> s4-0 transform-index) 3)
      (set-vector! (-> s4-0 local-sphere) 0.0 36864.0 0.0 32768.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) s4-0)
      )
    (pusher-init s5-0)
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-16 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-16 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-16 prim-core collide-with))
      )
    (set! (-> self root) s5-0)
    )
  (set! (-> self prefix) arg0)
  (initialize-skeleton
    self
    (the-as
      skeleton-group
      (art-group-get-by-name *level* "skel-tomb-boulder-pillar" (the-as (pointer uint32) #f))
      )
    (the-as pair 0)
    )
  (logior! (-> self skel status) (joint-control-status sync-math))
  (go-virtual idle)
  (none)
  )

(deftype tomb-boulder (process-drawable)
  ((root             collide-shape-moving          :override)
   (art-name         string)
   (anim             spool-anim)
   (loop-id          sound-id)
   (spider           (pointer tomb-spider))
   (explode          (pointer process))
   (stick            basic)
   (wing-door        (pointer tomb-wing-door))
   (stop             (pointer tomb-boulder-stop)    2)
   (pillar           (pointer tomb-boulder-pillar)  4)
   (mode             uint32)
   (sub-mode         uint32)
   (gui-id           sound-id)
   (target-pause     symbol)
   (current-pause    symbol)
   (previous-y-vel   float)
   (previous-y       float)
   (target-speed     float)
   (current-speed    float)
   (distance         meters)
   (distance-target  meters)
   (distance-offset  float)
   (speed-time       time-frame)
   (trans            vector                         2 :inline)
   (dir              vector                         :inline)
   (distance-adjust  (array float))
   )
  (:state-methods
    (chase spool-anim)
    idle
    )
  )


(defstate idle (tomb-boulder)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('draw)
       (if (-> block param 0)
           (logclear! (-> self draw status) (draw-control-status no-draw))
           (logior! (-> self draw status) (draw-control-status no-draw))
           )
       (let ((s5-0 (-> self child)))
         (while s5-0
           (send-event (ppointer->process s5-0) 'draw (-> block param 0))
           (set! s5-0 (-> s5-0 0 brother))
           )
         )
       #f
       )
      )
    )
  :exit (behavior ()
    (while (-> self child)
      (deactivate (-> self child 0))
      )
    )
  :trans (behavior ()
    (cond
      ((or (not *target*)
           *scene-player*
           (focus-test? *target* teleporting)
           (task-node-closed? (game-task-node tomb-poles-boulder))
           )
       )
      ((string= (-> *game-info* current-continue name) "tomb-boulder")
       (set! (-> self mode) (the-as uint 0))
       (go-virtual chase (new 'static 'spool-anim
                           :name "tomb-spider-chase-0"
                           :anim-name "tomb-spider-chase-0"
                           :parts 5
                           :command-list '()
                           )
                   )
       )
      ((string= (-> *game-info* current-continue name) "tomb-boulder-explode")
       (set! (-> self mode) (the-as uint 10))
       (go-virtual chase (new 'static 'spool-anim
                           :name "tomb-spider-chase-1"
                           :anim-name "tomb-spider-chase-1"
                           :parts 18
                           :command-list '()
                           )
                   )
       )
      ((string= (-> *game-info* current-continue name) "tomb-boulder-climb")
       (set! (-> self mode) (the-as uint 11))
       (go-virtual chase (new 'static 'spool-anim
                           :name "tomb-spider-chase-2"
                           :anim-name "tomb-spider-chase-2"
                           :parts 9
                           :command-list '()
                           )
                   )
       )
      )
    )
  :code (behavior ()
    (cond
      ((task-node-closed? (game-task-node tomb-poles-boulder))
       (ja-channel-set! 0)
       (transform-post)
       (let ((v1-1 (-> self root root-prim)))
         (set! (-> v1-1 prim-core collide-as) (collide-spec))
         (set! (-> v1-1 prim-core collide-with) (collide-spec))
         )
       0
       )
      (else
        (set! (-> self stick)
              (the-as basic (process-spawn
                              manipy
                              :init manipy-init
                              (-> self root trans)
                              (-> self entity)
                              (art-group-get-by-name *level* "skel-tomb-boulder-stick" (the-as (pointer uint32) #f))
                              #f
                              0
                              :name "tomb-boulder-stick"
                              :to self
                              )
                      )
              )
        (let ((v1-9 (-> self root root-prim)))
          (set! (-> v1-9 prim-core collide-as) (-> self root backup-collide-as))
          (set! (-> v1-9 prim-core collide-with) (-> self root backup-collide-with))
          )
        (ja-channel-set! 1)
        (ja :group! tomb-boulder-idle-ja)
        (transform-post)
        (until #f
          (when (and (not *scene-player*)
                     *target*
                     (and (>= 81920.0 (vector-vector-distance (-> self root trans) (-> *target* control trans)))
                          (not (logtest? (focus-status teleporting) (-> *target* focus-status)))
                          )
                     )
            (let ((gp-2 (ppointer->handle (process-spawn scene-player :init scene-player-init "tomb-boulder-start" #t #f))))
              (while (handle->process (the-as handle gp-2))
                (suspend)
                )
              )
            (sleep-code)
            )
          (suspend)
          )
        #f
        )
      )
    (sleep-code)
    )
  )

(defstate chase (tomb-boulder)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (local-vars (v0-0 object))
    (case message
      (('touch 'attack)
       (if (not (-> self current-pause))
           (send-event
             proc
             'attack
             (-> block param 0)
             (static-attack-info ((id (new-attack-id)) (shove-up (meters 3)) (mode 'smush)))
             )
           )
       )
      (('end-mode 'reset)
       (go-virtual idle)
       )
      (('pause)
       (set! v0-0 (-> block param 0))
       (set! (-> self target-pause) (the-as symbol v0-0))
       v0-0
       )
      (('draw)
       (cond
         ((-> block param 0)
          (set! v0-0 (logclear (-> self draw status) (draw-control-status no-draw)))
          (set! (-> self draw status) (the-as draw-control-status v0-0))
          )
         (else
           (set! v0-0 (logior (-> self draw status) (draw-control-status no-draw)))
           (set! (-> self draw status) (the-as draw-control-status v0-0))
           )
         )
       v0-0
       )
      (('trigger)
       (set! v0-0 1)
       (set! (-> self sub-mode) (the-as uint v0-0))
       v0-0
       )
      (('mode)
       (set! v0-0 (command-get-int (-> block param 0) 0))
       (set! (-> self mode) (the-as uint v0-0))
       v0-0
       )
      )
    )
  :enter (behavior ((arg0 spool-anim))
    (set! (-> self anim) arg0)
    (set! (-> self sub-mode) (the-as uint 0))
    (set! (-> self current-speed) 0.0)
    (set! (-> self previous-y-vel) 0.0)
    (set! (-> self previous-y)
          (-> (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node tomb-boulder-lod0-jg boulderrot)) y)
          )
    (set! (-> self spider) (process-spawn tomb-spider :init tomb-spider-init :to self))
    (set! (-> self explode)
          (process-spawn
            manipy
            :init manipy-init
            (-> self root trans)
            (-> self entity)
            (art-group-get-by-name *level* "skel-tomb-boulder-explode" (the-as (pointer uint32) #f))
            #f
            0
            :name "tomb-boulder-explode"
            :to self
            )
          )
    (send-event (ppointer->process (-> self explode)) 'anim-mode 'clone-anim)
    (send-event (ppointer->process (-> self explode)) 'prefix "explode-")
    (set! (-> self wing-door)
          (the-as
            (pointer tomb-wing-door)
            (process-spawn
              manipy
              :init manipy-init
              (-> self root trans)
              (-> self entity)
              (art-group-get-by-name *level* "skel-tomb-boulder-wing-door" (the-as (pointer uint32) #f))
              #f
              0
              :name "tomb-boulder-wing-door"
              :to self
              )
            )
          )
    (send-event (ppointer->process (-> self wing-door)) 'anim-mode 'clone-anim)
    (send-event (ppointer->process (-> self wing-door)) 'prefix "wing-door-")
    (set! (-> self stop 0) (process-spawn tomb-boulder-stop :init tomb-boulder-stop-init "stop-a-" :to self))
    (set! (-> self stop 1) (process-spawn tomb-boulder-stop :init tomb-boulder-stop-init "stop-b-" :to self))
    (set! (-> self pillar 0)
          (process-spawn tomb-boulder-pillar :init tomb-boulder-pillar-init "pillar-a-" :to self)
          )
    (set! (-> self pillar 1)
          (process-spawn tomb-boulder-pillar :init tomb-boulder-pillar-init "pillar-b-" :to self)
          )
    (set! (-> self pillar 2)
          (process-spawn tomb-boulder-pillar :init tomb-boulder-pillar-init "pillar-c-" :to self)
          )
    (set! (-> self pillar 3)
          (process-spawn tomb-boulder-pillar :init tomb-boulder-pillar-init "pillar-d-" :to self)
          )
    (cond
      ((< (-> self mode) (the-as uint 10))
       (set! (-> self root root-prim prim-core collide-with) (collide-spec jak player-list))
       (set! (-> self distance-adjust) (new 'static 'boxed-array :type float
                                         0.0
                                         15.0
                                         0.25
                                         160.0
                                         15.0
                                         0.25
                                         180.0
                                         25.0
                                         0.25
                                         220.0
                                         25.0
                                         0.25
                                         250.0
                                         10.0
                                         0.25
                                         )
             )
       )
      (else
        (set! (-> self root root-prim prim-core collide-with) (collide-spec))
        (set! (-> self distance-adjust) (new 'static 'boxed-array :type float
                                          0.0
                                          15.0
                                          0.25
                                          300.0
                                          25.0
                                          0.25
                                          340.0
                                          25.0
                                          0.25
                                          355.0
                                          10.0
                                          0.25
                                          365.0
                                          15.0
                                          0.25
                                          430.0
                                          25.0
                                          0.25
                                          460.0
                                          25.0
                                          0.25
                                          475.0
                                          10.0
                                          0.25
                                          480.0
                                          15.0
                                          0.25
                                          550.0
                                          30.0
                                          0.25
                                          580.0
                                          30.0
                                          0.25
                                          615.0
                                          10.0
                                          0.25
                                          620.0
                                          10.0
                                          0.25
                                          640.0
                                          15.0
                                          0.25
                                          840.0
                                          10.0
                                          0.5
                                          900.0
                                          10.0
                                          0.25
                                          950.0
                                          5.0
                                          0.4
                                          1050.0
                                          5.0
                                          0.4
                                          1051.0
                                          15.0
                                          0.25
                                          1150.0
                                          25.0
                                          0.25
                                          1250.0
                                          10.0
                                          0.25
                                          1270.0
                                          10.0
                                          0.25
                                          1290.0
                                          15.0
                                          0.25
                                          )
              )
        )
      )
    (set-setting! 'music 'danger11 0.0 0)
    (process-entity-status! self (entity-perm-status no-kill) #t)
    )
  :exit (behavior ()
    (when (= (-> *setting-control* user-current spooling) (process->ppointer self))
      (ja-abort-spooled-anim (-> self anim) (the-as art-joint-anim #f) -1)
      (ja-channel-set! 0)
      )
    (remove-process *gui-control* self (gui-channel art-load-next))
    (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 loop-id))
      (set! (-> v1-5 params volume) -4)
      (set! (-> v1-5 auto-time) 240)
      (set! (-> v1-5 auto-from) 2)
      (set! (-> v1-5 params mask) (the-as uint 17))
      (-> v1-5 id)
      )
    (while (-> self child)
      (deactivate (-> self child 0))
      )
    (set! (-> self target-pause) #f)
    (set! (-> self current-pause) #f)
    (set! (-> self mode) (the-as uint 0))
    (remove-setting! 'music)
    (persist-with-delay *setting-control* 'music (seconds 1) 'music 'danger11 0.0 0)
    (process-entity-status! self (entity-perm-status no-kill) #f)
    )
  :code (behavior ((arg0 spool-anim))
    (play-clean #f)
    (set! (-> self gui-id)
          (add-process *gui-control* self (gui-channel art-load-next) (gui-action queue) (-> self anim name) -1.0 0)
          )
    (while (!= (get-status *gui-control* (-> self gui-id)) (gui-status ready))
      (set-blackout-frames (seconds 0.1))
      (suspend)
      )
    (let ((v1-7 (lookup-gui-connection
                  *gui-control*
                  self
                  (gui-channel art-load-next)
                  (the-as string #f)
                  (new 'static 'sound-id)
                  )
                )
          )
      (if v1-7
          (set! (-> v1-7 channel) (gui-channel art-load))
          )
      )
    (ja-play-spooled-anim
      (-> self anim)
      (if (string= (the-as string (-> self anim anim-name)) "tomb-spider-chase-0")
          (get-art-by-name (-> self draw art-group) "idle" art-joint-anim)
          (get-art-by-name (-> self draw art-group) "mid" art-joint-anim)
          )
      (if (string= (the-as string (-> self anim anim-name)) "tomb-spider-chase-0")
          (get-art-by-name (-> self draw art-group) "mid" art-joint-anim)
          (get-art-by-name (-> self draw art-group) "end" art-joint-anim)
          )
      (the-as (function process-drawable symbol) false-func)
      )
    (case (-> self mode)
      ((2)
       (set-blackout-frames (seconds 0.1))
       (ja-channel-set! 0)
       (let ((gp-3 (ppointer->handle (process-spawn scene-player :init scene-player-init "tomb-spider-scare" #t #f))))
         (while (handle->process (the-as handle gp-3))
           (suspend)
           )
         )
       )
      ((10 11 12 13 14)
       (remove-setting! 'music)
       (task-node-close! (game-task-node tomb-poles-boulder))
       (auto-save-user)
       (if (and *target* (not (logtest? (-> *target* focus-status) (focus-status dead))))
           (start 'play (get-continue-by-name *game-info* "tomb-boulder-end"))
           )
       (logior! (-> self mask) (process-mask sleep))
       (suspend)
       0
       )
      )
    (sleep-code)
    )
  :post (behavior ()
    (let ((v1-0 (-> self mode)))
      (cond
        ((or (zero? v1-0) (= v1-0 1))
         (when (and (not (-> self target-pause)) (not (-> self current-pause)))
           (let ((gp-0 (new 'stack-no-clear 'collide-query)))
             (vector<-cspace! (-> gp-0 start-pos) (joint-node tomb-boulder-lod0-jg boulderrot))
             (set-vector! (-> gp-0 move-dist) 0.0 -24576.0 0.0 1.0)
             (let ((v1-7 gp-0))
               (set! (-> v1-7 radius) 409.6)
               (set! (-> v1-7 collide-with) (collide-spec backgnd))
               (set! (-> v1-7 ignore-process0) self)
               (set! (-> v1-7 ignore-process1) #f)
               (set! (-> v1-7 ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1))
               (set! (-> v1-7 action-mask) (collide-action solid))
               )
             (let ((f30-0 (- (-> gp-0 start-pos y) (-> self previous-y))))
               (if *debug-segment*
                   (format *stdcon* "yvel ~M pyvel ~M~%" f30-0 (-> self previous-y-vel))
                   )
               (when (< 409.6 (- f30-0 (-> self previous-y-vel)))
                 (let ((s5-0 (get-process *default-dead-pool* part-tracker #x4000)))
                   (when s5-0
                     (let ((t9-3 (method-of-type part-tracker activate)))
                       (t9-3 (the-as part-tracker s5-0) self (symbol->string (-> part-tracker symbol)) (the-as pointer #x70004000))
                       )
                     (let ((t9-4 run-function-in-process)
                           (a0-12 s5-0)
                           (a1-5 part-tracker-init)
                           (a2-5 (-> *part-group-id-table* 740))
                           (a3-2 0)
                           (t0-0 #f)
                           (t1-0 #f)
                           (t2-0 #f)
                           (t3-0 *launch-matrix*)
                           )
                       (set! (-> t3-0 trans quad)
                             (-> (vector+! (new 'stack-no-clear 'vector) (-> gp-0 start-pos) (-> gp-0 move-dist)) quad)
                             )
                       ((the-as (function object object object object object object object object none) t9-4)
                        a0-12
                        a1-5
                        a2-5
                        a3-2
                        t0-0
                        t1-0
                        t2-0
                        t3-0
                        )
                       )
                     (-> s5-0 ppointer)
                     )
                   )
                 )
               (set! (-> self previous-y-vel) f30-0)
               )
             (set! (-> self previous-y) (-> gp-0 start-pos y))
             (let ((f0-9 (fill-and-probe-using-line-sphere *collide-cache* gp-0)))
               (if (< 0.0 f0-9)
                   (spawn
                     (-> self part)
                     (vector+float*! (new 'stack-no-clear 'vector) (-> gp-0 start-pos) (-> gp-0 move-dist) f0-9)
                     )
                   )
               )
             )
           )
         (when (>= (ja-aframe-num 0) 250.0)
           (set! (-> self target-pause) #t)
           (ja :num-func num-func-identity :frame-num (ja-aframe 250.0 0))
           (set! (-> self mode) (the-as uint 1))
           )
         (case (-> self sub-mode)
           ((1)
            (when (send-event *target* 'trip)
              (set! (-> self sub-mode) (the-as uint 2))
              (set! (-> self mode) (the-as uint 2))
              (set! (-> self target-pause) #f)
              (sound-play "spider-wall1" :position (-> self trans))
              )
            )
           )
         )
        ((or (= v1-0 10) (= v1-0 11))
         (when (>= (ja-aframe-num 0) 840.0)
           (set! (-> self target-pause) #t)
           (ja :num-func num-func-identity :frame-num (ja-aframe 840.0 0))
           (if (= (-> self mode) 10)
               (set-continue! *game-info* "tomb-boulder-climb" #f)
               )
           (set! (-> self mode) (the-as uint 11))
           )
         )
        ((= v1-0 12)
         (set-continue! *game-info* "tomb-boulder-climb" #f)
         (set! (-> self target-pause) #f)
         (set! (-> self mode) (the-as uint 13))
         )
        ((= v1-0 13)
         (case (-> self sub-mode)
           ((1)
            (when (send-event *target* 'trip)
              (set! (-> self sub-mode) (the-as uint 2))
              (set! (-> self mode) (the-as uint 14))
              )
            )
           )
         )
        )
      )
    (transform-post)
    (cond
      ((-> self target-pause)
       (set! (-> self current-pause) #t)
       (sound-pause (-> self gui-id))
       )
      ((-> self current-pause)
       (set! (-> self current-pause) #f)
       (sound-continue (-> self gui-id))
       )
      )
    (set! (-> (the-as vector (-> self trans 1)) quad) (-> self trans 0 quad))
    (if (< (-> self mode) (the-as uint 10))
        (vector<-cspace! (the-as vector (-> self trans)) (-> self node-list data (-> self draw origin-joint-index)))
        (vector<-cspace! (the-as vector (-> self trans)) (-> self spider 0 node-list data 3))
        )
    (let ((s4-1 (vector-! (new 'stack-no-clear 'vector) (the-as vector (-> self trans)) (-> self trans 1))))
      (case (-> self mode)
        ((11)
         (vector-normalize-copy! (-> self dir) s4-1 1.0)
         )
        (else
          (let ((f30-1 (deg-seek (vector-y-angle (-> self dir)) (vector-y-angle s4-1) (* 5461.3335 (seconds-per-frame)))))
            (set-vector! (-> self dir) (sin f30-1) 0.0 (cos f30-1) 1.0)
            )
          )
        )
      )
    (let* ((gp-8 (vector-! (new 'stack-no-clear 'vector) (target-pos 0) (the-as vector (-> self trans))))
           (f0-20 (vector-length gp-8))
           )
      (set! (-> self distance) (if (< 81920.0 f0-20)
                                   f0-20
                                   (vector-dot (-> self dir) gp-8)
                                   )
            )
      )
    (when (or (< (-> self distance) -40960.0) (< (-> self target-speed) -5.0))
      (if (< (-> self mode) (the-as uint 10))
          (send-event
            *target*
            'attack
            #f
            (static-attack-info ((id (new-attack-id)) (shove-up (meters 3)) (mode 'smush)))
            )
          (send-event
            *target*
            'attack
            #f
            (static-attack-info ((id (new-attack-id)) (shove-up (meters 3)) (mode 'tomb-spider)))
            )
          )
      )
    (let ((f30-2 0.0)
          (f26-0 0.0)
          (f0-27 (ja-aframe-num 0))
          (v1-116 (-> self distance-adjust))
          (f28-0 0.25)
          )
      (dotimes (t0-2 (/ (the-as int (-> v1-116 length)) 3))
        (set! f28-0 (cond
                      ((>= f0-27 (-> (the-as (array float) (+ (* 12 t0-2) (the-as int v1-116))) 0))
                       (set! f30-2 (-> (the-as (array float) (+ (* 12 t0-2) (the-as int v1-116))) 0))
                       (set! f26-0 (-> (the-as (array float) (+ (* (+ (* 3 t0-2) 1) 4) (the-as int v1-116))) 0))
                       (-> v1-116 (+ (* 3 t0-2) 2))
                       )
                      (else
                        (set! f26-0 (lerp-scale
                                      f26-0
                                      (-> v1-116 (+ (* 3 t0-2) 1))
                                      f0-27
                                      f30-2
                                      (-> (the-as (array float) (+ (* 12 t0-2) (the-as int v1-116))) 0)
                                      )
                              )
                        (goto cfg-76)
                        f28-0
                        )
                      )
              )
        )
      (label cfg-76)
      (set! (-> self distance-target) (* 4096.0 f26-0))
      (set! (-> self distance-offset) f28-0)
      )
    (let ((f30-3 (lerp-scale
                   (- (-> self distance-offset))
                   (-> self distance-offset)
                   (-> self distance)
                   (+ -20480.0 (-> self distance-target))
                   (+ 20480.0 (-> self distance-target))
                   )
                 )
          )
      (if (and *target* (focus-test? *target* dead))
          (set! f30-3 0.5)
          )
      (when (or (< (vector-vector-distance (the-as vector (-> self trans)) (camera-pos)) 36864.0)
                (< (-> self target-speed) -5.0)
                )
        (set! f30-3 -20.0)
        (seek! (-> self target-speed) f30-3 (* 20.0 (seconds-per-frame)))
        )
      (seek! (-> self target-speed) f30-3 (seconds-per-frame))
      (when (or (!= (-> self target-speed) (-> self current-speed)) (time-elapsed? (-> self speed-time) (seconds 0.2)))
        (set! (-> self current-speed) (-> self target-speed))
        (set-time! (-> self speed-time))
        (when *sound-player-enable*
          (let ((v1-151 (the-as sound-rpc-set-param (get-sound-buffer-entry))))
            (set! (-> v1-151 command) (sound-command set-param))
            (set! (-> v1-151 id) (-> self gui-id))
            (set! (-> v1-151 params pitch-mod) (the int (* 1524.0 (-> self current-speed))))
            (set! (-> v1-151 params mask) (the-as uint 2))
            (-> v1-151 id)
            )
          )
        )
      (if *debug-segment*
          (format
            *stdcon*
            "distance ~,,2m ~,,2m  targ ~,,2f  speed ~,,2f~%"
            (-> self distance)
            (-> self distance-target)
            f30-3
            (-> self target-speed)
            )
          )
      )
    )
  )

;; WARN: Return type mismatch object vs none.
(defmethod init-from-entity! ((this tomb-boulder) (arg0 entity-actor))
  "Typically the method that does the initial setup on the process, potentially using the [[entity-actor]] provided as part of that.
This commonly includes things such as:
- stack size
- collision information
- loading the skeleton group / bones
- sounds"
  (stack-size-set! (-> this main-thread) 512)
  (let ((s4-0 (new 'process 'collide-shape-moving this (collide-list-enum 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-sphere s4-0 (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-spec enemy pusher))
      (set! (-> s3-0 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> s3-0 prim-core action) (collide-action solid))
      (set! (-> s3-0 transform-index) 4)
      (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 25395.2)
      (set! (-> s4-0 total-prims) (the-as uint 1))
      (set! (-> s4-0 root-prim) s3-0)
      )
    (pusher-init s4-0)
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-18 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-18 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-18 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (process-drawable-from-entity! this arg0)
  (logclear! (-> this mask) (process-mask actor-pause))
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-tomb-boulder" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (logior! (-> this skel status) (joint-control-status sync-math))
  (set! (-> this art-name) "tomb-boulder")
  (set! (-> this loop-id) (new-sound-id))
  (set! (-> this target-pause) #f)
  (set! (-> this current-pause) #f)
  (set-vector! (-> this dir) 1.0 0.0 0.0 1.0)
  (set! (-> this part) (create-launch-control (-> *part-group-id-table* 739) this))
  (set! (-> this draw light-index) (the-as uint 11))
  (go (method-of-object this idle))
  (none)
  )

(scene-method-16
  (new 'static 'scene
    :name "tomb-boulder-start"
    :extra #f
    :info #f
    :mask-to-clear (process-mask movie enemy platform projectile)
    :entity "scene-stage-46"
    :art-group "scenecamera"
    :anim "tomb-boulder-start"
    :parts 5
    :command-list '((0
        (send-event "tomb-boulder-4" 'draw #f)
        (send-event "jak-highres" 'eval ,(lambda ((arg0 process-drawable)) (let ((v0-0 (-> arg0 root scale)))
                                                                             (set! (-> v0-0 x) 1.4)
                                                                             (set! (-> v0-0 y) 1.4)
                                                                             (set! (-> v0-0 z) 1.4)
                                                                             (set! (-> v0-0 w) 1.0)
                                                                             v0-0
                                                                             )
                                                 )
                    )
        (fadein (frame-time-30 10))
        (setting-reset music mode 'danger11)
        )
      (10000
        (send-event "tomb-boulder-4" 'draw #t)
        (send-event "tomb-boulder-4" 'trigger)
        (task-close! "tomb-poles-poles")
        )
      )
    :cut-list '()
    :wait-ground-time (seconds 1)
    :draw-target #f
    :abort #t
    :actor (new 'static 'boxed-array :type scene-actor
      (new 'static 'scene-actor
        :name "scenecamera"
        :level #f
        :art-group "skel-scenecamera"
        :prefix ""
        :draw-frames '((min max))
        :scissor-frames '()
        :camera 4
        :shadow-flags -1
        :shadow-volume-joint #f
        )
      (new 'static 'scene-actor
        :name "sidekick-highres"
        :level 'tomba
        :art-group "skel-sidekick-highres"
        :prefix ""
        :draw-frames '((min max))
        :scissor-frames '()
        :flags #x1
        :shadow-flags -1
        :shadow-volume-joint #f
        )
      (new 'static 'scene-actor
        :name "jak-highres"
        :level 'tomba
        :art-group "skel-jak-highres"
        :prefix ""
        :draw-frames '((min max))
        :scissor-frames '()
        :flags #x1
        :shadow-flags -1
        :shadow-volume-joint #f
        )
      (new 'static 'scene-actor
        :name "tomb-boulder"
        :level 'tombe
        :art-group "skel-tomb-boulder"
        :prefix ""
        :draw-frames '((min max))
        :scissor-frames '()
        :flags #x1
        :shadow-flags -1
        :shadow-volume-joint #f
        )
      (new 'static 'scene-actor
        :name "tomb-boulder-stick"
        :level 'tombe
        :art-group "skel-tomb-boulder-stick"
        :prefix "stick-"
        :draw-frames '((min max))
        :scissor-frames '()
        :flags #x1
        :shadow-flags -1
        :shadow-volume-joint #f
        )
      )
    :load-point-obj "tomb-boulder"
    :end-point-obj "tomb-boulder"
    :borrow '()
    :sfx-volume -1.0
    :ambient-volume -1.0
    :music-volume -1.0
    :blackout-end #t
    :peaceful #t
    :save #t
    )
  )

(defskelgroup skel-spider-eyes spider-eyes spider-eyes-lod0-jg spider-eyes-idle-ja
              ((spider-eyes-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 5)
              :origin-joint-index 3
              )

(deftype spider-eyes (process-drawable)
  ((root        collide-shape-moving :override)
   (node-index  uint32)
   )
  (:state-methods
    idle
    )
  (:methods
    (spider-eyes-method-21 (_type_) none)
    )
  )


(defmethod spider-eyes-method-21 ((this spider-eyes))
  (rlet ((acc :class vf)
         (vf0 :class vf)
         (vf4 :class vf)
         (vf5 :class vf)
         (vf6 :class vf)
         (vf7 :class vf)
         )
    (init-vf0-vector)
    (let ((s3-0 *camera-other-matrix*)
          (s5-0 (new 'stack-no-clear 'vector))
          (gp-0 (new 'stack-no-clear 'vector))
          )
      (let ((f0-3 (* 0.25 (sin (* 0.5 (-> *camera-other-fov* data))))))
        (set-vector! (-> this root scale) f0-3 f0-3 f0-3 1.0)
        )
      (set! (-> gp-0 quad) (-> *camera-other-trans* quad))
      (vector-normalize-copy! s5-0 (-> s3-0 vector 2) 1.0)
      (matrix->quaternion (-> this root quat) s3-0)
      (let ((v1-8 (-> this root trans)))
        (let ((a0-8 2048.0))
          (.mov vf7 a0-8)
          )
        (.lvf vf5 (&-> s5-0 quad))
        (.lvf vf4 (&-> gp-0 quad))
        (.add.x.vf.w vf6 vf0 vf0)
        (.mul.x.vf.xyz acc vf5 vf7)
        (.add.mul.w.vf.xyz vf6 vf4 vf0 acc)
        (.svf (&-> v1-8 quad) vf6)
        )
      )
    0
    (none)
    )
  )

(defstate idle (spider-eyes)
  :virtual #t
  :code sleep-code
  :post (behavior ()
    (spider-eyes-method-21 self)
    (ja-post)
    )
  )

;; WARN: Return type mismatch object vs none.
(defbehavior spider-eyes-init-by-other spider-eyes ((arg0 entity-actor) (arg1 object) (arg2 uint))
  (process-entity-set! self arg0)
  (set! (-> self node-index) arg2)
  (set! (-> self root) (the-as collide-shape-moving (new 'process 'trsqv)))
  (set! (-> self root trans quad) (-> *null-vector* quad))
  (quaternion-copy! (-> self root quat) *unity-quaternion*)
  (vector-identity! (-> self root scale))
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-spider-eyes" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (go-virtual idle)
  (none)
  )

(scene-method-16 (new 'static 'scene
                   :name "tomb-spider-scare"
                   :extra #f
                   :info #f
                   :mask-to-clear (process-mask movie enemy platform projectile)
                   :entity "scene-stage-46"
                   :art-group "scenecamera"
                   :anim "tomb-spider-scare"
                   :parts 3
                   :command-list '((0 (send-event "tomb-boulder-4" 'draw #f))
                     (115 (part-tracker
                            "group-tomb-spider-chase-explosion-fma"
                            entity
                            "tomb-spider"
                            joint
                            "head"
                            track
                            #t
                            duration
                            (frame-time 1)
                            )
                          )
                     (240 (joint-eval
                            ,(lambda ((arg0 process) (arg1 vector) (arg2 cspace) (arg3 object) (arg4 object))
                               (process-spawn
                                 spider-eyes
                                 (entity-by-type tomb-boulder)
                                 (+ (-> arg2 joint number) 1)
                                 (the-as none arg4)
                                 :to (-> arg0 child 0)
                                 )
                               )
                            entity
                            "scenecamera"
                            joint
                            "camera"
                            )
                          )
                     (10000 (send-event "tomb-boulder-4" 'draw #t) (send-event "tomb-boulder-4" 'trigger))
                     )
                   :cut-list '(240)
                   :wait-ground-time (seconds 1)
                   :draw-target #f
                   :abort #t
                   :actor (new 'static 'boxed-array :type scene-actor
                     (new 'static 'scene-actor
                       :name "scenecamera"
                       :level #f
                       :art-group "skel-scenecamera"
                       :prefix ""
                       :draw-frames '((min max))
                       :scissor-frames '()
                       :camera 4
                       :shadow-flags -1
                       :shadow-volume-joint #f
                       )
                     (new 'static 'scene-actor
                       :name "sidekick-highres"
                       :level 'tomba
                       :art-group "skel-sidekick-highres"
                       :prefix ""
                       :draw-frames '((min max))
                       :scissor-frames '()
                       :flags #x1
                       :shadow-flags -1
                       :shadow-volume-joint #f
                       )
                     (new 'static 'scene-actor
                       :name "tomb-spider"
                       :level 'tombe
                       :art-group "skel-tomb-spider"
                       :prefix "spider-"
                       :draw-frames '((min max))
                       :scissor-frames '()
                       :flags #x1
                       :shadow-flags -1
                       :shadow-volume-joint #f
                       )
                     )
                   :load-point-obj "tomb-boulder-explode"
                   :end-point-obj "tomb-boulder-explode"
                   :borrow '()
                   :sfx-volume 1.0
                   :ambient-volume -1.0
                   :music-volume -1.0
                   :blackout-end #t
                   :peaceful #t
                   :save #f
                   )
                 )
