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

;; name: wasstada-obs.gc
;; name in dgo: wasstada-obs
;; dgos: WASSTADA

(define-extern *range-color-lava-flame* curve-color-fast)
(define-extern *range-alpha-lava-flame* curve2d-fast)
(define-extern *range-scale-lava-flame-x* curve2d-fast)
(define-extern *range-scale-lava-flame-y* curve2d-fast)
(define-extern *r-curve-lava-flame* curve2d-fast)
(define-extern *g-curve-lava-flame* curve2d-fast)
(define-extern *b-curve-lava-flame* curve2d-fast)
(define-extern *curve-alpha-lava-flame* curve2d-fast)
(define-extern *curve-scale-lava-flame-x* curve2d-fast)
(define-extern *curve-scale-lava-flame-y* curve2d-fast)

;; +++wstd-arena-plat-flag
(defenum wstd-arena-plat-flag
  :type uint64
  :bitfield #t
  (wap0 0)
  (wap1 1)
  )
;; ---wstd-arena-plat-flag


;; DECOMP BEGINS

(defpartgroup group-wasstada-lava-flame
  :id 486
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 10)
  :parts ((sp-item 1927 :falloff-to (meters 100)))
  )

(defpart 1927
  :init-specs ((:texture (flame01 level-default-sprite))
    (:birth-func 'birth-func-curve)
    (:num 1.0)
    (:scale-x (meters 5))
    (:scale-y :copy scale-x)
    (:r 155.0)
    (:g 164.0)
    (:b 255.0)
    (:a 0.0)
    (:vel-y (meters -0.0033333334) (meters 0.0016666667))
    (:accel-y (meters 0.0033333334))
    (:timer (seconds 2))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14 launch-along-z))
    (:userdata 0.0)
    (:func 'live-func-curve)
    )
  )

(if #t
    (set! *range-color-lava-flame* (new 'static 'curve-color-fast
                                     :xs (new 'static 'vector :y -0.6 :z -0.9 :w -1.0)
                                     :ys (new 'static 'inline-array vector 4
                                       (new 'static 'vector :x 128.0 :y 30.0 :w 128.0)
                                       (new 'static 'vector :x 128.0 :y 120.0 :z 30.0 :w 128.0)
                                       (new 'static 'vector :x 128.0 :y 128.0 :z 80.0 :w 128.0)
                                       (new 'static 'vector :x 255.0 :y 255.0 :z 255.0 :w 128.0)
                                       )
                                     :one-over-x-deltas (new 'static 'vector :x 1.6666666 :y 3.333334 :z 9.999998 :w 1.0)
                                     )
          )
    )

(if #t
    (set! *range-alpha-lava-flame* (new 'static 'curve2d-fast
                                     :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                     :ys (new 'static 'vector :x 128.0 :y 255.0 :z 256.0 :w 257.0)
                                     :one-over-x-deltas (new 'static 'vector :x 127.0 :y 1.0 :z 1.0 :w 1.0)
                                     )
          )
    )

(if #t
    (set! *range-scale-lava-flame-x* (new 'static 'curve2d-fast
                                       :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                       :ys (new 'static 'vector :x 3.0 :y 6.0 :z 7.0 :w 8.0)
                                       :one-over-x-deltas (new 'static 'vector :x 3.0 :y 1.0 :z 1.0 :w 1.0)
                                       )
          )
    )

(if #t
    (set! *range-scale-lava-flame-y* (new 'static 'curve2d-fast
                                       :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                       :ys (new 'static 'vector :x 3.0 :y 6.0 :z 7.0 :w 8.0)
                                       :one-over-x-deltas (new 'static 'vector :x 3.0 :y 1.0 :z 1.0 :w 1.0)
                                       )
          )
    )

(if #t
    (set! *r-curve-lava-flame* (new 'static 'curve2d-fast
                                 :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                 :ys (new 'static 'vector :x 1.0 :y 1.0 :z 2.0 :w 3.0)
                                 :one-over-x-deltas (new 'static 'vector :y 1.0 :z 1.0 :w 1.0)
                                 )
          )
    )

(if #t
    (set! *g-curve-lava-flame* (new 'static 'curve2d-fast
                                 :xs (new 'static 'vector :y -1.0 :z -2.0 :w -3.0)
                                 :ys (new 'static 'vector :x 0.7 :y 0.5 :z 1.5 :w 2.5)
                                 :one-over-x-deltas (new 'static 'vector :x -0.19999999 :y 1.0 :z 1.0 :w 1.0)
                                 )
          )
    )

(if #t
    (set! *b-curve-lava-flame* (new 'static 'curve2d-fast
                                 :xs (new 'static 'vector :y -0.6 :z -1.0 :w -2.0)
                                 :ys (new 'static 'vector :x 1.0 :w 1.0)
                                 :one-over-x-deltas (new 'static 'vector :x -1.6666666 :z 1.0 :w 1.0)
                                 )
          )
    )

(if #t
    (set! *curve-alpha-lava-flame* (new 'static 'curve2d-fast
                                     :xs (new 'static 'vector :y -0.3 :z -0.5 :w -1.0)
                                     :ys (new 'static 'vector :y 0.5 :z 1.0)
                                     :one-over-x-deltas (new 'static 'vector :x 1.6666666 :y 2.5000002 :z -2.0 :w 1.0)
                                     )
          )
    )

(if #t
    (set! *curve-scale-lava-flame-x* (new 'static 'curve2d-fast
                                       :xs (new 'static 'vector :y -0.5 :z -1.0 :w -2.0)
                                       :ys (new 'static 'vector :x 0.5 :y 1.0 :z 0.3 :w 1.3)
                                       :one-over-x-deltas (new 'static 'vector :x 1.0 :y -1.4 :z 0.99999994 :w 1.0)
                                       )
          )
    )

(if #t
    (set! *curve-scale-lava-flame-y* (new 'static 'curve2d-fast
                                       :xs (new 'static 'vector :y -0.5 :z -1.0 :w -2.0)
                                       :ys (new 'static 'vector :x 0.5 :y 1.0 :z 1.3 :w 2.3)
                                       :one-over-x-deltas (new 'static 'vector :x 1.0 :y 0.5999999 :z 1.0 :w 1.0)
                                       )
          )
    )

(define *part-wasstada-lava-flame-curve-settings* (new 'static 'particle-curve-settings
                                                    :lifetime-base (seconds 0.4)
                                                    :lifetime-offset (seconds 0.2)
                                                    :flags (particle-curve-flags pcf1)
                                                    )
        )

(set! (-> *part-id-table* 1927 init-specs 13 initial-valuef)
      (the-as float *part-wasstada-lava-flame-curve-settings*)
      )

(set! (-> *part-wasstada-lava-flame-curve-settings* color-start) *range-color-lava-flame*)

(set! (-> *part-wasstada-lava-flame-curve-settings* alpha-start) *range-alpha-lava-flame*)

(set! (-> *part-wasstada-lava-flame-curve-settings* scale-x-start) *range-scale-lava-flame-x*)

(set! (-> *part-wasstada-lava-flame-curve-settings* scale-y-start) *range-scale-lava-flame-y*)

(set! (-> *part-wasstada-lava-flame-curve-settings* r-scalar) *r-curve-lava-flame*)

(set! (-> *part-wasstada-lava-flame-curve-settings* g-scalar) *g-curve-lava-flame*)

(set! (-> *part-wasstada-lava-flame-curve-settings* b-scalar) *b-curve-lava-flame*)

(set! (-> *part-wasstada-lava-flame-curve-settings* a-scalar) *curve-alpha-lava-flame*)

(set! (-> *part-wasstada-lava-flame-curve-settings* scale-x-scalar) *curve-scale-lava-flame-x*)

(set! (-> *part-wasstada-lava-flame-curve-settings* scale-y-scalar) *curve-scale-lava-flame-y*)

(defpartgroup group-wasstada-lava-sploop
  :id 487
  :linger-duration (seconds 1)
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 10)
  :parts ((sp-item 1928 :falloff-to (meters 100)))
  )

(defpart 1928
  :init-specs ((:texture (lava-drop-01 wasstada-sprite))
    (:birth-func 'birth-func-texture-group)
    (:num 2.0 10.0)
    (:x (meters 0))
    (:z (meters 0))
    (:scale-x (meters 0.2) (meters 0.8))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 80.0 100.0)
    (:b 0.0)
    (:a 128.0)
    (:vel-y (meters 0.016666668) (meters 0.05))
    (:rotvel-z (degrees -2) (degrees 4))
    (:accel-y (meters -0.0016666667))
    (:timer (seconds 4))
    (:flags (launch-along-z))
    (:userdata :data (new 'static 'boxed-array :type int32 5 1 0 #x24f00000 #x24f00100 #x24f00200 #x24f00300))
    (:func 'check-drop-group-center)
    (:conerot-x (degrees 0) (degrees 15))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpartgroup group-wasstada-lava-sploop-box
  :id 488
  :linger-duration (seconds 1)
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 10)
  :parts ((sp-item 1929 :fade-after (meters 50) :falloff-to (meters 80)))
  )

(defpart 1929
  :init-specs ((:texture (lava-drop-01 wasstada-sprite))
    (:birth-func 'birth-func-texture-group)
    (:num 0.1 0.5)
    (:x (meters 0))
    (:z (meters 0))
    (:scale-x (meters 0.2) (meters 1))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 80.0 100.0)
    (:b 0.0)
    (:a 128.0)
    (:vel-y (meters 0.0016666667) (meters 0.013333334))
    (:rotvel-z (degrees -2) (degrees 4))
    (:accel-y (meters -0.0016666667))
    (:timer (seconds 1))
    (:flags (launch-along-z))
    (:userdata :data (new 'static 'boxed-array :type int32 5 1 0 #x24f00000 #x24f00100 #x24f00200 #x24f00300))
    (:func 'check-drop-group-center)
    (:conerot-x (degrees 0) (degrees 15))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defskelgroup skel-wstd-door wstd-door wstd-door-lod0-jg wstd-door-idle-ja
              ((wstd-door-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 6 0 12)
              :origin-joint-index 3
              )

(deftype wstd-door (com-airlock)
  ()
  )


(defmethod init-from-entity! ((this wstd-door) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (let ((s5-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (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 obstacle))
      (set! (-> s4-0 prim-core collide-with) (collide-spec jak bot player-list))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 24576.0 0.0 49152.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-8 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-8 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-8 prim-core collide-with) (collide-spec jak bot player-list))
      (set! (-> v1-8 prim-core action) (collide-action solid))
      (set! (-> v1-8 transform-index) 3)
      (set-vector! (-> v1-8 local-sphere) 0.0 0.0 0.0 53248.0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-11 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-11 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-11 prim-core collide-with))
      )
    (set! (-> this root) s5-0)
    )
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-wstd-door" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (init-airlock! this)
  (set! (-> this sound-open-loop) (static-sound-spec "ver-open" :group 0))
  (set! (-> this sound-open-stop) (static-sound-spec "ver-open-hit" :group 0))
  (set! (-> this sound-close-loop) (static-sound-spec "ver-open" :group 0))
  (set! (-> this sound-close-stop) (static-sound-spec "air-ver-cls-hit" :group 0))
  (set! (-> this sound-behind?) #t)
  (go (method-of-object this close) #t)
  )

(defskelgroup skel-wstd-arena-plat wstd-arena-plat wstd-arena-plat-lod0-jg wstd-arena-plat-idle-ja
              ((wstd-arena-plat-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 -23 0 26)
              :origin-joint-index 3
              )

(deftype wstd-arena-plat (base-plat)
  ((sync                sync-paused  :inline)
   (flags               wstd-arena-plat-flag)
   (ride-timer          time-frame)
   (current-pos         float)
   (dest-pos            float)
   (speed               float)
   (y-pos               float)
   (ambient-sound-id    sound-id)
   (on-activate         basic)
   (go-pos              float)
   (sound-id            sound-id)
   (sound-running-loop  sound-spec)
   )
  (:state-methods
    plat-base-state
    idle
    active
    wait
    run
    show
    wait-show
    go-down
    )
  (:methods
    (wstd-arena-plat-method-43 (_type_) none)
    (wstd-arena-plat-method-44 (_type_) none)
    )
  )


(defmethod wstd-arena-plat-method-43 ((this wstd-arena-plat))
  (cond
    ((< (-> this current-pos) (-> this dest-pos))
     (+! (-> this current-pos) (* 300.0 (seconds-per-frame) (-> this speed)))
     (if (< (-> this dest-pos) (-> this current-pos))
         (set! (-> this current-pos) (-> this dest-pos))
         )
     (seek! (-> this speed) 1.0 (seconds-per-frame))
     )
    ((< (-> this dest-pos) (-> this current-pos))
     (+! (-> this current-pos) (* 300.0 (seconds-per-frame) (-> this speed)))
     (if (< (-> this current-pos) (-> this dest-pos))
         (set! (-> this current-pos) (-> this dest-pos))
         )
     (seek! (-> this speed) -1.0 (seconds-per-frame))
     )
    (else
      (seek! (-> this speed) 0.0 (seconds-per-frame))
      )
    )
  0
  (none)
  )

(defmethod deactivate ((this wstd-arena-plat))
  "Make a process dead, clean it up, remove it from the active pool, and return to dead pool."
  (sound-stop (-> this ambient-sound-id))
  (call-parent-method this)
  (none)
  )

(defstate plat-base-state (wstd-arena-plat)
  :virtual #t
  :event plat-event
  :trans plat-trans
  :code sleep-code
  :post plat-post
  )

(defmethod wstd-arena-plat-method-44 ((this wstd-arena-plat))
  (cond
    ((!= (-> this current-pos) (-> this dest-pos))
     (if (-> this sound-running-loop)
         (sound-play-by-spec (-> this sound-running-loop) (-> this sound-id) (-> this root trans))
         )
     )
    (else
      (sound-stop (-> this sound-id))
      )
    )
  (when (-> this ambient-sound-id)
    (let ((a0-3 (static-sound-spec "arena-plat" :group 0)))
      (sound-play-by-spec a0-3 (-> this ambient-sound-id) (-> this root trans))
      )
    )
  0
  (none)
  )

(defstate idle (wstd-arena-plat)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trigger)
       (go-virtual active)
       )
      )
    (plat-event proc argc message block)
    )
  :trans plat-trans
  :code sleep-code
  :post plat-post
  )

(defstate active (wstd-arena-plat)
  :virtual #t
  :event plat-event
  :trans (behavior ()
    0.0
    (let ((f0-1 (get-norm! (-> self sync) 0)))
      (get-point-at-percent-along-path! (-> self path) (-> self basetrans) f0-1 'interp)
      )
    (wstd-arena-plat-method-44 self)
    (plat-trans)
    )
  :code (behavior ()
    (until #f
      (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  :post plat-post
  )

(defstate run (wstd-arena-plat)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('ridden)
       (set-time! (-> self ride-timer))
       (plat-event proc argc message block)
       )
      (else
        (plat-event proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set-time! (-> self state-time))
    (set! (-> self dest-pos) (-> self go-pos))
    (set-time! (-> self ride-timer))
    )
  :trans (behavior ()
    (if (time-elapsed? (-> self ride-timer) (seconds 1))
        (go-virtual wait)
        )
    0.0
    (let ((f0-3 (get-norm! (-> self sync) (the int (-> self current-pos)))))
      (get-point-at-percent-along-path! (-> self path) (-> self basetrans) f0-3 'interp)
      )
    (wstd-arena-plat-method-44 self)
    (wstd-arena-plat-method-43 self)
    (plat-trans)
    )
  :code (behavior ()
    (until #f
      (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  :post plat-post
  )

(defstate wait (wstd-arena-plat)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('ridden)
       (logior! (-> self flags) (wstd-arena-plat-flag wap0))
       (plat-event proc argc message block)
       )
      (('go-pos)
       (if (zero? (-> block param 0))
           (set! (-> self go-pos) 1.0)
           (set! (-> self go-pos) (the float (+ (shr (-> self sync period) 1) -1)))
           )
       )
      (('hide)
       (go-virtual go-down)
       )
      (else
        (plat-event proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set-time! (-> self ride-timer))
    (logclear! (-> self flags) (wstd-arena-plat-flag wap0))
    (set-time! (-> self ride-timer))
    )
  :trans (behavior ()
    (let ((s5-0 (new 'stack-no-clear 'vector))
          (gp-0 (new 'stack-no-clear 'vector))
          )
      (get-point-at-percent-along-path! (-> self path) s5-0 0.0 'interp)
      (get-point-at-percent-along-path!
        (-> self path)
        gp-0
        (+ -1.0 (* 0.5 (the float (-> self sync period))))
        'interp
        )
      (if (< (vector-vector-distance s5-0 (target-pos 0)) (vector-vector-distance gp-0 (target-pos 0)))
          (set! (-> self dest-pos) 1.0)
          (set! (-> self dest-pos) (the float (+ (shr (-> self sync period) 1) -1)))
          )
      )
    (if (not (logtest? (-> self flags) (wstd-arena-plat-flag wap0)))
        (set-time! (-> self ride-timer))
        )
    (logclear! (-> self flags) (wstd-arena-plat-flag wap0))
    (if (time-elapsed? (-> self ride-timer) (seconds 1))
        (go-virtual run)
        )
    0.0
    (let ((f0-9 (get-norm! (-> self sync) (the int (-> self current-pos)))))
      (get-point-at-percent-along-path! (-> self path) (-> self basetrans) f0-9 'interp)
      )
    (wstd-arena-plat-method-44 self)
    (wstd-arena-plat-method-43 self)
    (plat-trans)
    )
  :code (behavior ()
    (until #f
      (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  :post (behavior ()
    (debug-draw (-> self path))
    (plat-post)
    )
  )

(defstate go-down (wstd-arena-plat)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('show)
       (set! (-> self go-pos) 1.0)
       (go-virtual show)
       )
      (else
        (plat-event proc argc message block)
        )
      )
    )
  :enter (behavior ()
    '()
    )
  :trans (behavior ()
    (+! (-> self basetrans y) (* -16384.0 (seconds-per-frame)))
    (if (< (-> self basetrans y) 0.0)
        (go-virtual wait-show)
        )
    (plat-trans)
    )
  :code sleep-code
  :post (behavior ()
    (debug-draw (-> self path))
    (plat-post)
    )
  )

(defstate wait-show (wstd-arena-plat)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('show)
       (set! (-> self go-pos) 1.0)
       (go-virtual show)
       )
      (('wait)
       (go-virtual wait)
       )
      )
    )
  :enter (behavior ()
    0.0
    (let ((f0-3 (get-norm! (-> self sync) (the int (-> self current-pos)))))
      (get-point-at-percent-along-path! (-> self path) (-> self basetrans) f0-3 'interp)
      )
    (set! (-> self basetrans y) 0.0)
    (plat-trans)
    (plat-post)
    )
  :code sleep-code
  )

(defstate show (wstd-arena-plat)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (plat-event proc argc message block)
    )
  :enter (behavior ()
    0.0
    (let ((f0-3 (get-norm! (-> self sync) (the int (-> self current-pos)))))
      (get-point-at-percent-along-path! (-> self path) (-> self basetrans) f0-3 'interp)
      )
    (set! (-> self basetrans y) 0.0)
    (set! (-> self y-pos) (-> self basetrans y))
    )
  :trans (behavior ()
    (plat-trans)
    )
  :code (behavior ()
    (until (process-grab? *target* #f)
      (suspend)
      )
    (let ((a3-1 (res-lump-struct (-> self entity) 'camera-name structure)))
      (if a3-1
          (set-setting! 'entity-name a3-1 0.0 0)
          )
      )
    0.0
    0.0
    (let ((f0-4 (get-norm! (-> self sync) (the int (-> self current-pos)))))
      (get-point-at-percent-along-path! (-> self path) (-> self basetrans) f0-4 'interp)
      )
    (let ((f30-0 (-> self basetrans y)))
      (if (< f30-0 81920.0)
          (sound-play "plat-raise")
          )
      (until #f
        (suspend)
        (if (< 81920.0 f30-0)
            (wstd-arena-plat-method-44 self)
            )
        (set! (-> self y-pos)
              (seek-ease-in-out (-> self y-pos) 0.0 f30-0 (* 40960.0 (seconds-per-frame)) 8192.0 8192.0 1.0)
              )
        (when (= (-> self y-pos) (-> self basetrans y))
          (until (process-release? *target*)
            (suspend)
            )
          (remove-setting! 'entity-name)
          (go-virtual wait)
          )
        (set! (-> self basetrans y) (-> self y-pos))
        )
      )
    #f
    )
  :post (behavior ()
    (debug-draw (-> self path))
    (plat-post)
    )
  )

(defmethod update-part-and-sfx! ((this wstd-arena-plat))
  (when (nonzero? (-> this sound))
    (vector-copy! (-> this sound trans) (-> this root trans))
    (update! (-> this sound))
    )
  (none)
  )

(defmethod init-collision! ((this wstd-arena-plat))
  (let ((s5-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (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 camera-blocker pusher))
      (set! (-> s4-0 prim-core collide-with) (collide-spec jak 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 -94208.0 0.0 106496.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-12 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-12 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-12 prim-core collide-with))
      )
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod init-from-entity! ((this wstd-arena-plat) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (local-vars (v1-75 uint128))
  (init-collision! this)
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-wstd-arena-plat" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (init-bounce-params! this)
  (let ((a0-6 (-> this skel root-channel 0)))
    (set! (-> a0-6 frame-group) (if (> (-> this skel active-channels) 0)
                                    (-> this skel root-channel 0 frame-group)
                                    )
          )
    (set! (-> a0-6 param 0) 1.0)
    (set! (-> a0-6 frame-num) 0.0)
    (joint-control-channel-group!
      a0-6
      (if (> (-> this skel active-channels) 0)
          (-> this skel root-channel 0 frame-group)
          )
      num-func-loop!
      )
    )
  (ja-post)
  (let ((a1-5 (new 'stack-no-clear 'sync-info-params)))
    (let ((v1-20 0))
      (if #t
          (set! v1-20 (logior v1-20 1))
          )
      (set! (-> a1-5 sync-type) 'sync-paused)
      (set! (-> a1-5 sync-flags) (the-as sync-flags v1-20))
      )
    (set! (-> a1-5 entity) arg0)
    (set! (-> a1-5 period) (the-as uint 3000))
    (set! (-> a1-5 percent) 0.0)
    (set! (-> a1-5 pause-in) 0.0)
    (set! (-> a1-5 pause-out) 0.0)
    (initialize! (-> this sync) a1-5)
    )
  (set! (-> this path) (new 'process 'path-control this 'path 0.0 arg0 #f))
  (logior! (-> this path flags) (path-control-flag display draw-line draw-point draw-text))
  (logclear! (-> this mask) (process-mask actor-pause))
  (set! (-> this part) (create-launch-control group-wasstada-lava-sploop-box this))
  (set! (-> this dest-pos) (the float (+ (shr (-> this sync period) 1) -1)))
  (set! (-> this current-pos) (-> this dest-pos))
  (set! (-> this speed) 0.0)
  (set! (-> this ambient-sound-id) (new 'static 'sound-id))
  (set! (-> this on-activate) (res-lump-struct (-> this entity) 'on-activate basic))
  (set! (-> this draw light-index) (the-as uint 10))
  (set! (-> this go-pos) 1.0)
  (set! (-> this sound-running-loop) #f)
  (set! (-> this sound-id) (new-sound-id))
  (let ((s5-1 (the-as object #f)))
    (if (-> this on-activate)
        (set! s5-1 (script-eval (the-as pair (-> this on-activate)) :vector (-> this root trans)))
        )
    (when s5-1
      (let ((s3-1 (new 'stack-no-clear 'vector))
            (s4-1 (new 'stack-no-clear 'vector))
            )
        (get-point-at-percent-along-path! (-> this path) s3-1 0.0 'interp)
        (get-point-at-percent-along-path!
          (-> this path)
          s4-1
          (+ -1.0 (* 0.5 (the float (-> this sync period))))
          'interp
          )
        (if (< (vector-vector-distance s3-1 (target-pos 0)) (vector-vector-distance s4-1 (target-pos 0)))
            (set! (-> this dest-pos) 1.0)
            (set! (-> this dest-pos) (the float (+ (shr (-> this sync period) 1) -1)))
            )
        )
      (set! (-> this current-pos) (-> this dest-pos))
      )
    (cond
      ((= s5-1 'wait)
       (set! (-> this go-pos) 1.0)
       (set! (-> this sound-running-loop) (static-sound-spec "plat-raise-loop" :group 0))
       (go (method-of-object this wait))
       )
      ((= s5-1 'wait-end)
       (set! (-> this go-pos) (the float (+ (shr (-> this sync period) 1) -1)))
       (set! (-> this sound-running-loop) (static-sound-spec "plat-raise-loop" :group 0))
       (go (method-of-object this wait))
       )
      ((begin
         (set! v1-75 (res-lump-value (-> this entity) 'extra-id uint128 :time -1000000000.0))
         (logtest? (-> this path flags) (path-control-flag not-found))
         )
       (go (method-of-object this idle))
       )
      ((zero? v1-75)
       (set! (-> this ambient-sound-id) (new-sound-id))
       (go (method-of-object this active))
       )
      ((= (the-as uint v1-75) 1)
       (set! (-> this sound-running-loop) (static-sound-spec "plat-raise-loop" :group 0))
       (go (method-of-object this wait))
       )
      ((= (the-as uint v1-75) 2)
       (set! (-> this sound-running-loop) (static-sound-spec "plat-raise-loop" :group 0))
       (go (method-of-object this wait-show))
       )
      (else
        (go (method-of-object this idle))
        )
      )
    )
  )

(deftype wstd-flag-a (process-drawable)
  ()
  (:state-methods
    idle
    )
  )


(defskelgroup skel-wstd-flag-a wstd-flag-a wstd-flag-a-lod0-jg wstd-flag-a-idle-ja
              ((wstd-flag-a-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 2 0 10)
              )

(defstate idle (wstd-flag-a)
  :virtual #t
  :code (behavior ()
    (until #f
      (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  :post ja-post
  )

(defmethod init-from-entity! ((this wstd-flag-a) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-wstd-flag-a" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (go (method-of-object this idle))
  )

(deftype wstd-blocker (process-drawable)
  ((root  collide-shape :override)
   )
  (:state-methods
    idle
    )
  )


(defskelgroup skel-wstd-blocker wstd-blocker wstd-blocker-lod0-jg wstd-blocker-idle-ja
              ((wstd-blocker-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 2 0 10)
              )

(defstate idle (wstd-blocker)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('on)
       (set! (-> self root root-prim prim-core collide-as) (collide-spec obstacle))
       (set! (-> self root root-prim prim-core collide-with) (collide-spec jak player-list))
       (transform-post)
       )
      (('off)
       (set! (-> self root root-prim prim-core collide-as) (collide-spec))
       (set! (-> self root root-prim prim-core collide-with) (collide-spec))
       (transform-post)
       )
      )
    )
  :code sleep-code
  )

(defmethod init-from-entity! ((this wstd-blocker) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (let ((s4-0 (new 'process 'collide-shape this (collide-list-enum hit-by-others))))
    (let ((v1-2 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-2 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-2 prim-core collide-with) (collide-spec jak player-list))
      (set! (-> v1-2 prim-core action) (collide-action solid))
      (set! (-> v1-2 transform-index) 3)
      (set-vector! (-> v1-2 local-sphere) 0.0 0.0 0.0 106496.0)
      (set! (-> s4-0 total-prims) (the-as uint 1))
      (set! (-> s4-0 root-prim) v1-2)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-5 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-5 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-5 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (set! (-> this root root-prim prim-core collide-as) (collide-spec))
  (set! (-> this root root-prim prim-core collide-with) (collide-spec))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-wstd-blocker" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (transform-post)
  (go (method-of-object this idle))
  )

(deftype crowd-manager (process)
  ((crowd-intensity  float)
   (snd-id-1         sound-id)
   (snd-id-2         sound-id)
   (next-sound       time-frame)
   (channel          uint32)
   (dur-sound        time-frame)
   (volume-1         float)
   (volume-2         float)
   (trans-1          vector  :inline)
   (trans-2          vector  :inline)
   (crowd-int-red    float)
   (trans            vector  :inline)
   (training?        symbol)
   (darkjak?         symbol)
   (sid              sound-id)
   (volume           float)
   (snd-count        uint32)
   (start-sound      sound-spec)
   )
  (:state-methods
    idle
    )
  )


(define *crowd-manager* (the-as (pointer crowd-manager) #f))

(define *crowd-positions* (new 'static 'boxed-array :type vector
                            (new 'static 'vector :x 9874309.0 :y 215203.84 :z -1698734.1 :w 1.0)
                            (new 'static 'vector :x 10038231.0 :y 211107.84 :z -2074583.0 :w 1.0)
                            (new 'static 'vector :x 9032172.0 :y 223191.05 :z -2062295.0 :w 1.0)
                            (new 'static 'vector :x 9173484.0 :y 213934.08 :z -1712046.1 :w 1.0)
                            )
        )

(defstate idle (crowd-manager)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (local-vars (v0-0 symbol))
    (case message
      (('intensity)
       (set! (-> self crowd-intensity) (the-as float (-> block param 0)))
       (+! (-> self volume) 0.3)
       (set! v0-0 #t)
       (set! (-> self start-sound) (the-as sound-spec v0-0))
       v0-0
       )
      (('off)
       #f
       )
      (('darkjak)
       (set! v0-0 #t)
       (set! (-> self darkjak?) v0-0)
       v0-0
       )
      )
    )
  :trans (behavior ()
    (let ((gp-0 (entity-by-name "wstd-door-1"))
          (f30-0 (- (vector-dot *z-vector* (vector-!
                                             (new 'stack-no-clear 'vector)
                                             (target-pos 0)
                                             (new 'static 'vector :x 9656808.0 :y 207810.16 :z -1579811.6 :w 1.0)
                                             )
                                )
                    )
                 )
          )
      (cond
        ((or (movie?) (and (< f30-0 4096.0) gp-0 (not (script-eval (res-lump-struct gp-0 'on-notice pair)))))
         (when (nonzero? (-> self snd-id-1))
           (set-action!
             *gui-control*
             (gui-action stop)
             (-> self snd-id-1)
             (gui-channel none)
             (gui-action none)
             (the-as string #f)
             (the-as (function gui-connection symbol) #f)
             (the-as process #f)
             )
           (set! (-> self snd-id-1) (new 'static 'sound-id))
           0
           )
         (when (nonzero? (-> self snd-id-2))
           (set-action!
             *gui-control*
             (gui-action stop)
             (-> self snd-id-2)
             (gui-channel none)
             (gui-action none)
             (the-as string #f)
             (the-as (function gui-connection symbol) #f)
             (the-as process #f)
             )
           (set! (-> self snd-id-2) (new 'static 'sound-id))
           0
           )
         (sound-stop (-> self sid))
         )
        (else
          32
          (let ((f30-1 (lerp-scale 0.0 1.0 f30-0 -163840.0 -81920.0)))
            (-> *crowd-positions* (rand-vu-int-count 4))
            (sound-play-by-name
              (static-sound-name "crowd-loop")
              (-> self sid)
              (the int (* 1024.0 f30-1))
              0
              0
              (sound-group)
              #t
              )
            )
          (when (and (time-elapsed? (+ (-> self dur-sound) (seconds 1.2)) (-> self next-sound)) (-> self start-sound))
            (set! (-> self snd-id-2) (-> self snd-id-1))
            (set! (-> self volume-2) (-> self volume-1))
            (vector-copy! (-> self trans-2) (-> self trans-1))
            (cond
              ((nonzero? (-> self channel))
               32
               (set! (-> self channel) (the-as uint 0))
               0
               )
              (else
                30
                (set! (-> self channel) (the-as uint 1))
                )
              )
            (cond
              ((-> self darkjak?)
               (set! (-> self snd-id-1) (sound-play "crowd-cheer-dj"))
               (set! (-> self dur-sound) (seconds 4.87))
               (set! (-> self darkjak?) #f)
               )
              ((= (-> self crowd-intensity) 0.0)
               )
              (else
                (set! (-> self volume) 0.5)
                (let ((v1-45 (-> self snd-count)))
                  (cond
                    ((zero? v1-45)
                     (set! (-> self snd-id-1) (sound-play "crowd-cheer-15"))
                     (set! (-> self dur-sound) (seconds 6.8))
                     (+! (-> self snd-count) 1)
                     )
                    ((= v1-45 1)
                     (set! (-> self snd-id-1) (sound-play "crowd-cheer-10"))
                     (set! (-> self dur-sound) (seconds 7.88))
                     (+! (-> self snd-count) 1)
                     )
                    ((= v1-45 2)
                     (set! (-> self snd-id-1) (sound-play "crowd-cheer-5"))
                     (set! (-> self dur-sound) (seconds 6.84))
                     (+! (-> self snd-count) 1)
                     )
                    ((= v1-45 3)
                     (set! (-> self snd-id-1) (sound-play "crowd-cheer-3"))
                     (set! (-> self dur-sound) (seconds 8.34))
                     (+! (-> self snd-count) 1)
                     )
                    ((= v1-45 4)
                     (set! (-> self snd-id-1) (sound-play "crowd-cheer-1"))
                     (set! (-> self dur-sound) (seconds 8.89))
                     (set! (-> self snd-count) (the-as uint 0))
                     0
                     )
                    )
                  )
                )
              )
            (set-time! (-> self next-sound))
            (set! (-> self crowd-int-red) (-> self crowd-intensity))
            )
          (+ 0.5 (* 0.05 (fmax 0.0 (fmin 20.0 (- (-> self crowd-intensity) (-> self crowd-int-red))))))
          (when *sound-player-enable*
            (let ((v1-74 (the-as sound-rpc-set-param (get-sound-buffer-entry))))
              (set! (-> v1-74 command) (sound-command set-param))
              (set! (-> v1-74 id) (-> self snd-id-1))
              (set! (-> v1-74 params volume) (the int (* 1024.0 (fmax 0.0 (fmin 1.0 (-> self volume))))))
              (set! (-> v1-74 params mask) (the-as uint 1))
              (-> v1-74 id)
              )
            )
          )
        )
      )
    (set! (-> self start-sound) #f)
    (seek! (-> self crowd-intensity) 0.0 (seconds-per-frame))
    )
  :code sleep-code
  )

(defmethod deactivate ((this crowd-manager))
  "Make a process dead, clean it up, remove it from the active pool, and return to dead pool."
  (sound-stop (-> this sid))
  (set! *crowd-manager* (the-as (pointer crowd-manager) #f))
  ((method-of-type process deactivate) this)
  (none)
  )

(defmethod init-from-entity! ((this crowd-manager) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (set! *crowd-manager* (the-as (pointer crowd-manager) (process->ppointer this)))
  (set! (-> this snd-count) (the-as uint 0))
  (set! (-> this snd-id-1) (new 'static 'sound-id))
  (set! (-> this snd-id-2) (new 'static 'sound-id))
  (set! (-> this sid) (new-sound-id))
  (set! (-> this crowd-intensity) 0.0)
  (set! (-> this training?) (task-node-open? (game-task-node arena-training-1-collect)))
  (set! (-> this darkjak?) #f)
  (vector-copy! (-> this trans) (-> arg0 trans))
  (go (method-of-object this idle))
  )
