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

;; name: wasstadb-obs.gc
;; name in dgo: wasstadb-obs
;; dgos: WASSTADB

;; DECOMP BEGINS

(deftype arena-state (structure)
  ((time  time-frame)
   )
  )


(define *arena-state* (new 'static 'arena-state))

(deftype hud-timer-training (hud-timer)
  ()
  )


(defmethod update-values! ((this hud-timer-training))
  (set! (-> this values 0 target) (/ (-> *game-info* timer) #x4650))
  (set! (-> this values 1 target) (/ (mod (-> *game-info* timer) #x4650) 300))
  (let ((v1-8 (abs (- (-> this values 1 target) (-> this values 2 target)))))
    (when (> v1-8 0)
      (set! (-> this values 2 target) (-> this values 1 target))
      (cond
        ((<= (-> this values 3 target) 0)
         (sound-play "timer-beep")
         )
        ((= (-> this values 3 target) 1)
         (sound-play "warn-beep1")
         )
        ((= (-> this values 3 target) 2)
         (sound-play "warn-beep2")
         )
        ((>= (-> this values 3 target) 3)
         (sound-play "warn-beep3")
         )
        )
      )
    )
  (logclear! (-> this flags) (hud-flags disable))
  ((method-of-type hud update-values!) this)
  0
  (none)
  )

(defmethod init-callback ((this hud-timer-training))
  (set! (-> this gui-id)
        (add-process *gui-control* this (gui-channel hud-center-right) (gui-action hidden) (-> this name) 81920.0 0)
        )
  ((method-of-type hud init-callback) this)
  (none)
  )

(deftype hud-arena-final-stats (hud)
  ()
  )


(defmethod draw ((this hud-arena-final-stats))
  30
  0
  (let ((s5-0
          (new 'stack 'font-context *font-default-matrix* 0 0 0.0 (font-color default) (font-flags shadow kerning))
          )
        )
    (set! (-> this strings 0 scale) 0.0)
    (set! (-> s5-0 origin x) 45.0)
    (set! (-> s5-0 origin y) 20.0)
    (set-width! s5-0 422)
    (set-height! s5-0 80)
    (let ((a0-4 s5-0))
      (set! (-> a0-4 color) (font-color red))
      )
    (let ((a0-5 s5-0))
      (set! (-> a0-5 flags) (font-flags kerning middle middle-vert large))
      )
    (set-scale! s5-0 1.0)
    (let ((s4-0 80))
      (set-scale! s5-0 1.6)
      (if (= (-> *setting-control* user-default language) (language-enum german))
          (set-scale! s5-0 1.0)
          )
      (print-game-text
        (lookup-text! *common-text* (text-id text-0076) #f)
        s5-0
        #f
        44
        (bucket-id hud-draw-hud-alpha)
        )
      (set! (-> this strings 1 scale) 0.7)
      (set-hud-piece-position!
        (the-as hud-sprite (-> this strings 1 pos))
        256
        (the int (+ (- 198.0 (the float s4-0)) (* -100.0 (-> this offset))))
        )
      )
    )
  (format (clear (-> this strings 1 text)) (lookup-text! *common-text* (text-id text-0573) #f))
  (set-as-offset-from! (the-as hud-sprite (-> this strings 2 pos)) (-> this strings 1 pos) 0 30)
  (set! (-> this strings 2 scale) 0.7)
  (set! (-> this strings 2 flags) (font-flags kerning middle large))
  (print-time (clear (-> this strings 2 text)) (-> *game-info* timer))
  (set! (-> this strings 3 scale) 0.5)
  (set-as-offset-from! (the-as hud-sprite (-> this strings 3 pos)) (-> this strings 2 pos) 0 60)
  (format (clear (-> this strings 3 text)) (lookup-text! *common-text* (text-id text-0575) #f))
  (let ((s5-4 (get-game-score-ref *game-info* 17))
        (s4-3 4)
        )
    (dotimes (s3-1 3)
      (set! (-> this strings s4-3 scale) 0.5)
      (set! (-> this strings s4-3 flags) (font-flags kerning middle large))
      (set! (-> this strings s4-3 color) (font-color white))
      (set-as-offset-from!
        (the-as hud-sprite (+ (the-as uint (-> this strings 0 pos)) (* s4-3 32)))
        (-> this strings 3 pos)
        0
        (+ (* 26 s3-1) 30)
        )
      (print-time (clear (-> this strings s4-3 text)) (the-as time-frame (the int (-> s5-4 s3-1))))
      (+! s4-3 1)
      )
    )
  ((method-of-type hud draw) this)
  0
  (none)
  )

(defmethod update-values! ((this hud-arena-final-stats))
  (logclear! (-> this flags) (hud-flags disable))
  ((method-of-type hud update-values!) this)
  0
  (none)
  )

(defmethod init-callback ((this hud-arena-final-stats))
  (set! (-> this gui-id)
        (add-process *gui-control* this (gui-channel hud-middle-right) (gui-action hidden) (-> this name) 81920.0 0)
        )
  (logior! (-> this flags) (hud-flags show))
  (dotimes (s5-0 8)
    (alloc-string-if-needed this s5-0)
    )
  (set! (-> this strings 0 flags) (font-flags kerning middle large))
  (set! (-> this strings 0 color) (font-color red))
  (set! (-> this strings 1 flags) (font-flags kerning middle large))
  (set! (-> this strings 1 color) (font-color white))
  (set! (-> this strings 2 flags) (font-flags kerning middle large))
  (set! (-> this strings 2 color) (font-color white))
  (set! (-> this strings 3 flags) (font-flags kerning middle large))
  (set! (-> this strings 3 color) (font-color white))
  0
  (none)
  )

(defmethod draw ((this hud-arena-tokens))
  (set-hud-piece-position! (-> this sprites 0) (the int (+ 462.0 (* 130.0 (-> this offset)))) 180)
  (format (clear (-> this strings 0 text)) "~D" (-> this values 0 current))
  (set-as-offset-from! (the-as hud-sprite (-> this strings 0 pos)) (-> this sprites 0 pos) -14 33)
  ((method-of-type hud draw) this)
  0
  (none)
  )

(defmethod update-values! ((this hud-arena-tokens))
  (set! (-> this values 0 target) (the int (-> *game-info* counter)))
  ((method-of-type hud update-values!) this)
  0
  (none)
  )

(defmethod init-callback ((this hud-arena-tokens))
  (set! (-> this gui-id)
        (add-process *gui-control* this (gui-channel hud-center-right) (gui-action hidden) (-> this name) 81920.0 0)
        )
  (logior! (-> this flags) (hud-flags show))
  (set! (-> this sprites 0 tid) (the-as texture-id (get-texture hud-arena-token wasstadb-minimap)))
  (set! (-> this sprites 0 flags) (hud-sprite-flags hsf2))
  (set! (-> this sprites 0 scale-x) 1.0)
  (set! (-> this sprites 0 scale-y) 1.0)
  (alloc-string-if-needed this 0)
  (set! (-> this strings 0 scale) 1.0)
  (set! (-> this strings 0 flags) (font-flags shadow kerning middle large))
  0
  (none)
  )

(defpartgroup group-arena-token
  :id 499
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 10)
  :parts ((sp-item 1968 :fade-after (meters 100) :period (seconds 0.167) :length (seconds 0.035))
    (sp-item 1969 :fade-after (meters 100) :period (seconds 0.167) :length (seconds 0.035))
    (sp-item 1970 :fade-after (meters 100) :period (seconds 0.167) :length (seconds 0.035))
    )
  )

(defpart 1968
  :init-specs ((:texture (starflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1))
    (:scale-y :copy scale-x)
    (:r 20.0)
    (:g 20.0)
    (:b 128.0)
    (:a 200.0)
    (:rotvel-z (degrees 0.1))
    (:timer (seconds 0.335))
    (:flags (sp-cpuinfo-flag-3))
    (:func 'sparticle-track-root)
    )
  )

(defpart 1969
  :init-specs ((:texture (starflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 1))
    (:scale-y :copy scale-x)
    (:r 20.0)
    (:g 20.0)
    (:b 128.0)
    (:a 200.0)
    (:rotvel-z (degrees -0.1))
    (:timer (seconds 0.335))
    (:flags (sp-cpuinfo-flag-3))
    (:func 'sparticle-track-root)
    )
  )

(defpart 1970
  :init-specs ((:texture (laser-hit level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.5))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 20.0)
    (:g 20.0)
    (:b 255.0)
    (:a 255.0)
    (:scalevel-x (meters 0.01))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -1.275)
    (:timer (seconds 0.667))
    (:flags (sp-cpuinfo-flag-3))
    (:func 'sparticle-track-root)
    )
  )

(defpartgroup group-arena-token-pickup
  :id 500
  :duration (seconds 0.035)
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 10)
  :parts ((sp-item 1971 :fade-after (meters 50) :period (seconds 0.167) :length (seconds 0.035)) (sp-item 1972))
  )

(defpart 1971
  :init-specs ((:texture (starflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 6))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 128.0)
    (:b 180.0)
    (:a 255.0)
    (:scalevel-x (meters -0.06666667))
    (:scalevel-y :copy scalevel-x)
    (:timer (seconds 0.167))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-3))
    (:func 'sparticle-track-root)
    )
  )

(defpart 1972
  :init-specs ((:texture (middot level-default-sprite))
    (:num 10.0)
    (:scale-x (meters 0.15))
    (:rot-x 4)
    (:scale-y :copy scale-x)
    (:r 20.0)
    (:g 20.0)
    (:b 255.0)
    (:a 128.0)
    (:omega (degrees 0.0225))
    (:vel-y (meters 0.06666667) (meters 0.13333334))
    (:accel-y (meters 0))
    (:friction 0.7)
    (:timer (seconds 2))
    (:flags (sp-cpuinfo-flag-3))
    (:func 'sparticle-motion-blur)
    (:next-time (seconds 0.167))
    (:next-launcher 1973)
    (:conerot-x (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 1973
  :init-specs ((:omega (degrees 0.0675)) (:accel-y (meters -0.00033333333) (meters -0.00033333333)) (:friction 0.92 0.07))
  )

(defpartgroup group-arena-token-shadow
  :id 501
  :duration (seconds 0)
  :flags (sp0 sp4)
  :bounds (static-bspherem 0 0 0 1)
  :parts ((sp-item 1974 :flags (is-3d sp3 sp7)))
  )

(defpart 1974
  :init-specs ((:texture (middot level-default-sprite))
    (:num 1.0)
    (:y (meters 0.05))
    (:scale-x (meters 1))
    (:scale-y :copy scale-x)
    (:r 0.0)
    (:g 0.0)
    (:b 0.0)
    (:a 64.0)
    (:timer (seconds -0.005))
    (:flags (sp-cpuinfo-flag-13))
    (:rotate-y (degrees 0))
    )
  )

(defskelgroup skel-arena-token arena-token arena-token-lod0-jg arena-token-idle-ja
              ((arena-token-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 1)
              :shadow arena-token-shadow-mg
              )

(deftype arena-token (process-drawable)
  ((root      collide-shape-moving :override)
   (trans-y   float)
   (offset    float)
   (gspot     vector                :inline)
   (shadow-h  handle)
   )
  (:state-methods
    idle
    die
    hide
    )
  (:methods
    (init-collision! (_type_) none)
    (probe-background (_type_) symbol)
    )
  )


;; WARN: Return type mismatch process-drawable vs arena-token.
(defmethod relocate ((this arena-token) (offset int))
  (the-as arena-token ((method-of-type process-drawable relocate) this offset))
  )

(defmethod init-collision! ((this arena-token))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-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) (the-as penetrate -1))
    (let ((v1-7 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-7 prim-core collide-as) (collide-spec collectable))
      (set! (-> v1-7 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set-vector! (-> v1-7 local-sphere) 0.0 0.0 0.0 6144.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-7)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-10 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-10 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-10 prim-core collide-with))
      )
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defstate idle (arena-token)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('touch 'attack)
       (cond
         ((logtest? (-> *part-group-id-table* 500 flags) (sp-group-flag sp13))
          (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
          (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group (-> *part-group-id-table* 500))
          )
         (else
           (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
           (part-tracker-spawn part-tracker :to *entity-pool* :group (-> *part-group-id-table* 500))
           )
         )
       (sound-play "arena-token")
       (let ((a1-9 (new 'stack-no-clear 'event-message-block)))
         (set! (-> a1-9 from) (process->ppointer self))
         (set! (-> a1-9 num-params) 1)
         (set! (-> a1-9 message) 'pickup)
         (set! (-> a1-9 param 0) (the-as uint (-> self entity)))
         (let ((t9-8 send-event-function)
               (v1-40 (-> *game-info* sub-task-list (game-task-node arena-training-1-collect)))
               )
           (t9-8
             (handle->process (if (-> v1-40 manager)
                                  (-> v1-40 manager manager)
                                  (the-as handle #f)
                                  )
                              )
             a1-9
             )
           )
         )
       (go-virtual hide)
       #f
       )
      (('alive)
       #t
       )
      )
    )
  :enter (behavior ()
    (set! (-> self shadow-h)
          (ppointer->handle
            (cond
              ((logtest? (-> *part-group-id-table* 501 flags) (sp-group-flag sp13))
               (vector-copy! (-> *launch-matrix* trans) (-> self gspot))
               (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group (-> *part-group-id-table* 501))
               )
              (else
                (vector-copy! (-> *launch-matrix* trans) (-> self gspot))
                (part-tracker-spawn part-tracker :to *entity-pool* :group (-> *part-group-id-table* 501))
                )
              )
            )
          )
    )
  :exit (behavior ()
    (send-event (handle->process (-> self shadow-h)) 'die)
    )
  :trans (behavior ()
    (spawn (-> self part) (-> self root trans))
    (let ((f26-0 (+ (-> self offset) (* 0.0033333334 (the float (current-time))))))
      (set! (-> self root trans y)
            (+ (-> self trans-y) (* 819.2 (+ (cos (* 182.04445 (* 120.0 f26-0))) (cos (* 182.04445 (* -87.0 f26-0))))))
            )
      )
    )
  :code (behavior ()
    (ja :num-func num-func-identity :frame-num (the float (rand-vu-int-count (ja-num-frames 0))))
    (until #f
      (ja :num! (loop!))
      (when (ja-done? 0)
        )
      (suspend)
      )
    #f
    )
  :post ja-post
  )

(defstate die (arena-token)
  :virtual #t
  :code (behavior ()
    (logior! (-> self draw status) (draw-control-status no-draw))
    (cleanup-for-death self)
    )
  )

(defstate hide (arena-token)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('show)
       (go-virtual idle)
       )
      )
    )
  :trans (behavior ()
    (when (< (vector-vector-distance (-> self root trans) (target-pos 0)) 32768.0)
      (let ((v1-3 (res-lump-struct (-> self entity) 'continue-name string)))
        (when v1-3
          (let ((a1-2 (new 'stack-no-clear 'event-message-block)))
            (set! (-> a1-2 from) (process->ppointer self))
            (set! (-> a1-2 num-params) 2)
            (set! (-> a1-2 message) 'checkpoint)
            (set! (-> a1-2 param 0) (the-as uint v1-3))
            (set! (-> a1-2 param 1) (the-as uint (-> self entity)))
            (let ((t9-3 send-event-function)
                  (v1-7 (-> *game-info* sub-task-list (game-task-node arena-training-1-collect)))
                  )
              (t9-3
                (handle->process (if (-> v1-7 manager)
                                     (-> v1-7 manager manager)
                                     (the-as handle #f)
                                     )
                                 )
                a1-2
                )
              )
            )
          )
        )
      )
    )
  :code (behavior ()
    (logior! (-> self draw status) (draw-control-status no-draw))
    (suspend)
    (until #f
      (suspend)
      )
    #f
    )
  )

(defmethod probe-background ((this arena-token))
  (let ((s5-0 (new 'stack 'collide-query)))
    (vector-copy! (-> s5-0 start-pos) (-> this root trans))
    (set-vector! (-> s5-0 move-dist) 0.0 -204800.0 0.0 1.0)
    (let ((v1-3 s5-0))
      (set! (-> v1-3 radius) 40.96)
      (set! (-> v1-3 collide-with) (collide-spec backgnd))
      (set! (-> v1-3 ignore-process0) this)
      (set! (-> v1-3 ignore-process1) #f)
      (set! (-> v1-3 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-3 action-mask) (collide-action solid))
      )
    (when (>= (fill-and-probe-using-line-sphere *collide-cache* s5-0) 0.0)
      (vector-copy! (-> this gspot) (-> s5-0 best-other-tri intersect))
      (+! (-> this gspot y) 204.8)
      #t
      )
    )
  )

(defmethod init-from-entity! ((this arena-token) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (logior! (-> this mask) (process-mask collectable))
  (init-collision! this)
  (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-arena-token" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (set! (-> this part) (create-launch-control (-> *part-group-id-table* 499) this))
  (set! (-> this trans-y) (-> this root trans y))
  (set! (-> this offset) (rand-vu-float-range 0.0 4.0))
  (probe-background this)
  (transform-post)
  (go (method-of-object this hide))
  )

(defskelgroup skel-wstd-training-dummy wstd-training-dummy wstd-training-dummy-lod0-jg wstd-training-dummy-idle-ja
              ((wstd-training-dummy-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 2.5 0 2.5)
              )

(defskelgroup skel-wstd-training-dummy-explode wstd-training-dummy wstd-training-dummy-explode-lod0-jg wstd-training-dummy-explode-idle-ja
              ((wstd-training-dummy-explode-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 15)
              )

(define *wstd-training-dummy-exploder-params*
  (new 'static 'joint-exploder-static-params
    :joints (new 'static 'boxed-array :type joint-exploder-static-joint-params
      (new 'static 'joint-exploder-static-joint-params :joint-index 4 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 5 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 6 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 7 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 8 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 9 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 10 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 11 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 12 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 13 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 14 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 15 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 16 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 17 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 18 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 19 :parent-joint-index -1)
      )
    :collide-spec (collide-spec backgnd)
    )
  )

(deftype wstd-training-dummy (process-drawable)
  ((root  collide-shape-moving :override)
   )
  (:state-methods
    idle
    die
    )
  (:methods
    (init-collision! (_type_) none)
    )
  )


(defmethod init-collision! ((this wstd-training-dummy))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-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-group s5-0 (the-as uint 2) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 3))
      (set! (-> s4-0 prim-core collide-as) (collide-spec enemy))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid no-standon))
      (set-vector! (-> s4-0 local-sphere) 0.0 8192.0 0.0 12288.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-12 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-12 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-12 prim-core collide-with)
            (collide-spec backgnd jak crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
            )
      (set! (-> v1-12 prim-core action) (collide-action solid))
      (set-vector! (-> v1-12 local-sphere) 0.0 5324.8 0.0 5324.8)
      )
    (let ((v1-14 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-14 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-14 prim-core collide-with) (collide-spec backgnd jak player-list))
      (set! (-> v1-14 prim-core action) (collide-action solid no-standon))
      (set-vector! (-> v1-14 local-sphere) 0.0 9011.2 0.0 5324.8)
      )
    (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! (-> this root) s5-0)
    )
  0
  (none)
  )

(defstate idle (wstd-training-dummy)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('attack)
       (let ((gp-0 (new 'stack 'joint-exploder-tuning (the-as uint 1))))
         (let ((a0-5 (the-as target (as-type *target* process-focusable))))
           (if a0-5
               (vector-copy! (-> gp-0 fountain-rand-transv-lo) (get-trans a0-5 0))
               )
           )
         (set! (-> gp-0 fountain-rand-transv-hi x) 24576.0)
         (set! (-> gp-0 fountain-rand-transv-hi y) 81920.0)
         (set! (-> gp-0 fountain-rand-transv-hi z) 12288.0)
         (set! (-> gp-0 fountain-rand-transv-hi w) 32768.0)
         (process-spawn
           joint-exploder
           (art-group-get-by-name *level* "skel-wstd-training-dummy-explode" (the-as (pointer level) #f))
           5
           gp-0
           *wstd-training-dummy-exploder-params*
           :name "joint-exploder"
           :to self
           :unk 0
           )
         )
       (go-virtual die)
       #f
       )
      (('alive)
       #t
       )
      )
    )
  :enter (behavior ()
    (logclear! (-> self draw status) (draw-control-status no-draw))
    )
  :trans (behavior ()
    '()
    )
  :code (behavior ()
    (ja :num-func num-func-identity :frame-num (the float (rand-vu-int-count (ja-num-frames 0))))
    (until #f
      (ja :num! (loop!))
      (when (ja-done? 0)
        )
      (suspend)
      )
    #f
    )
  :post ja-post
  )

(defstate die (wstd-training-dummy)
  :virtual #t
  :code (behavior ()
    (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
    (logior! (-> self draw status) (draw-control-status no-draw))
    (suspend)
    (ja-channel-set! 0)
    (sound-play "dummy-hit")
    (while (-> self child)
      (suspend)
      )
    (cleanup-for-death self)
    )
  )

(defmethod init-from-entity! ((this wstd-training-dummy) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (init-collision! this)
  (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-wstd-training-dummy" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (transform-post)
  (go (method-of-object this idle))
  )

(define *arena-trainer-checkpoint-valid* (the-as object #f))

(define *arena-trainer-checkpoint-time* 0.0)

(define *arena-trainer-checkpoint-tokens* (new 'static 'array uint64 2 #xffffffffffffffff #x0))

(deftype task-manager-arena-training (task-manager)
  ((judge-h            handle)
   (arrow-h            handle)
   (hud-stat           handle)
   (check-timer        time-frame)
   (actor-group        (pointer actor-group))
   (actor-group-count  int32)
   (checkpoint-timer   float)
   (checkpoint-tokens  handle)
   (message-id         text-id)
   )
  (:state-methods
    wait-touch
    wait-more
    idle
    done
    )
  (:methods
    (task-manager-arena-training-method-36 (_type_) none)
    (print-text (_type_) none)
    )
  )


(defstate wait-touch (task-manager-arena-training)
  :virtual #t
  :parent (task-manager-arena-training active)
  :enter (behavior ()
    (let ((gp-0 (new 'stack-no-clear 'task-arrow-params)))
      (vector-copy! (-> gp-0 pos) (-> self entity trans))
      (quaternion-identity! (-> gp-0 quat))
      (set! (-> gp-0 flags) (task-arrow-flags taf3))
      (set! (-> gp-0 map-icon) (the-as uint 13))
      (set! (-> self arrow-h) (process->handle (task-arrow-spawn gp-0 self)))
      )
    )
  :trans (behavior ()
    '()
    )
  :code (behavior ()
    (set! (-> self judge-h) (ppointer->handle (judge-spawn self (-> self entity trans) (the-as uint 0) #f)))
    (suspend)
    (suspend)
    (while (send-event (handle->process (-> self judge-h)) 'waiting)
      (suspend)
      )
    (send-event (handle->process (-> self arrow-h)) 'leave)
    (talker-spawn-func (-> *talker-speech* 67) *entity-pool* (target-pos 0) (the-as region #f))
    (go-virtual wait-more)
    )
  )

(defstate wait-more (task-manager-arena-training)
  :virtual #t
  :parent (task-manager-arena-training active)
  :enter (behavior ()
    (dotimes (gp-0 (length (-> self actor-group 0)))
      (let ((v1-2 (-> self actor-group 0 data gp-0)))
        (when (logtest? (-> *arena-trainer-checkpoint-tokens* 0) (ash 1 gp-0))
          (let ((a1-2 (new 'stack-no-clear 'event-message-block)))
            (set! (-> a1-2 from) (process->ppointer self))
            (set! (-> a1-2 num-params) 0)
            (set! (-> a1-2 message) 'show)
            (let ((t9-0 send-event-function)
                  (v1-3 (-> v1-2 actor))
                  )
              (t9-0
                (if v1-3
                    (-> v1-3 extra process)
                    )
                a1-2
                )
              )
            )
          )
        )
      )
    )
  :code (behavior ()
    (set-setting! 'music 'arenafi 0.0 0)
    (set-setting! 'music-volume 'rel 0.65 0)
    (suspend)
    (go-virtual idle)
    )
  )

(define *training-fail*
  (new 'static 'resetter-params
    :flags (resetter-flag auto-reset text-message no-audio no-slow-down)
    :fail (new 'static 'resetter-spec :continue "wasstada-jump-training" :reset-mode 'life :execute #f)
    :retry (new 'static 'resetter-spec :continue #f :reset-mode 'try :execute #f)
    :reset-delay (seconds 1)
    )
  )

(defstate idle (task-manager-arena-training)
  :virtual #t
  :parent (task-manager-arena-training active)
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('target)
       (case (-> block param 0)
         (('die)
          (set! *arena-trainer-checkpoint-valid* #t)
          )
         )
       (task-manager-event-handler proc argc message block)
       )
      (('checkpoint)
       (let ((gp-0 (-> block param 0))
             (s4-0 (the-as object (-> block param 1)))
             (s3-0 0)
             (s5-0 #f)
             )
         (until #f
           (let ((v1-6 (-> self actor-group 0 data s3-0)))
             (when (= (-> (the-as entity-actor s4-0) aid) (-> (the-as entity-actor (-> v1-6 actor)) aid))
               (set! s5-0 #t)
               (goto cfg-17)
               )
             (let ((a1-2 (new 'stack-no-clear 'event-message-block)))
               (set! (-> a1-2 from) (process->ppointer self))
               (set! (-> a1-2 num-params) 0)
               (set! (-> a1-2 message) 'alive)
               (let ((t9-1 send-event-function)
                     (v1-8 (-> v1-6 actor))
                     )
                 (if (t9-1
                       (if v1-8
                           (-> v1-8 extra process)
                           )
                       a1-2
                       )
                     (goto cfg-17)
                     )
                 )
               )
             )
           (+! s3-0 1)
           )
         #f
         (label cfg-17)
         (when s5-0
           (copy-string<-string (-> *training-fail* fail continue) (the-as string gp-0))
           (set-setting! 'death-info *training-fail* 0.0 0)
           )
         )
       (set! *arena-trainer-checkpoint-time* (the float (- (current-time) (-> self state-time))))
       )
      (('pickup)
       (let ((gp-1 (the-as object (-> block param 0))))
         (set! (-> *arena-trainer-checkpoint-tokens* 0) (the-as uint 0))
         (dotimes (s5-1 (length (-> self actor-group 0)))
           (let ((v1-25 (-> self actor-group 0 data s5-1)))
             (if (and (!= (-> (the-as entity-actor gp-1) aid) (-> v1-25 actor aid))
                      (let ((a1-8 (new 'stack-no-clear 'event-message-block)))
                        (set! (-> a1-8 from) (process->ppointer self))
                        (set! (-> a1-8 num-params) 0)
                        (set! (-> a1-8 message) 'alive)
                        (let ((t9-4 send-event-function)
                              (v1-27 (-> v1-25 actor))
                              )
                          (t9-4
                            (if v1-27
                                (-> v1-27 extra process)
                                )
                            a1-8
                            )
                          )
                        )
                      )
                 (logior! (-> *arena-trainer-checkpoint-tokens* 0) (ash 1 s5-1))
                 )
             )
           )
         )
       #f
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set! (-> self state-time) (- (current-time) (the-as time-frame (the int *arena-trainer-checkpoint-time*))))
    (set! (-> self hud-counter)
          (ppointer->handle (process-spawn hud-arena-tokens :init hud-init-by-other :name "hud-arena-tokens" :to self))
          )
    (if (not (handle->process (-> self judge-h)))
        (set! (-> self judge-h) (ppointer->handle (judge-spawn self (target-pos 0) (the-as uint 0) #f)))
        )
    )
  :exit (behavior ()
    '()
    )
  :trans (behavior ()
    (let ((gp-0 0))
      (dotimes (s5-0 (length (-> self actor-group 0)))
        (let ((v1-2 (-> self actor-group 0 data s5-0))
              (a1-0 (new 'stack-no-clear 'event-message-block))
              )
          (set! (-> a1-0 from) (process->ppointer self))
          (set! (-> a1-0 num-params) 0)
          (set! (-> a1-0 message) 'alive)
          (let ((t9-0 send-event-function)
                (v1-3 (-> v1-2 actor))
                )
            (if (t9-0
                  (if v1-3
                      (-> v1-3 extra process)
                      )
                  a1-0
                  )
                (+! gp-0 1)
                )
            )
          )
        )
      (cond
        ((zero? gp-0)
         (go-virtual done)
         )
        (else
          (set! (-> *game-info* counter) (the float gp-0))
          (set! (-> *game-info* timer) (- (current-time) (-> self state-time)))
          )
        )
      )
    )
  :code sleep-code
  )

(defmethod print-text ((this task-manager-arena-training))
  (when (= (get-status *gui-control* (the-as sound-id (-> this message-id))) (gui-status active))
    (let ((gp-1
            (new 'stack 'font-context *font-default-matrix* 70 20 0.0 (font-color orange) (font-flags shadow kerning))
            )
          )
      (set-scale! gp-1 0.7)
      (set-width! gp-1 300)
      (set-height! gp-1 70)
      (set! (-> gp-1 origin x) (the float (- 256 (the int (/ (-> gp-1 width) 2)))))
      (set! (-> gp-1 origin y) 320.0)
      (set! (-> gp-1 flags) (font-flags shadow kerning middle middle-vert large))
      (let ((s5-0 print-game-text))
        (format (clear *temp-string*) (lookup-text! *common-text* (text-id text-007c) #f) 1)
        (s5-0 *temp-string* gp-1 #f 44 (bucket-id hud-draw-hud-alpha))
        )
      )
    )
  0
  (none)
  )

(defstate done (task-manager-arena-training)
  :virtual #t
  :parent (task-manager-arena-training active)
  :enter (behavior ()
    (set! (-> self hud-stat) (the-as handle #f))
    (when (task-node-open? (game-task-node arena-training-1-collect))
      (remove-setting! 'music)
      (remove-setting! 'music-volume)
      (task-node-close! (game-task-node arena-training-1-collect) 'event)
      )
    (let ((gp-0 (-> self actor-group 1)))
      (dotimes (s5-0 (-> gp-0 length))
        (let ((a1-3 (new 'stack-no-clear 'event-message-block)))
          (set! (-> a1-3 from) (process->ppointer self))
          (set! (-> a1-3 num-params) 0)
          (set! (-> a1-3 message) 'show)
          (let ((t9-4 send-event-function)
                (v1-11 (-> gp-0 data s5-0 actor))
                )
            (t9-4
              (if v1-11
                  (-> v1-11 extra process)
                  )
              a1-3
              )
            )
          )
        )
      )
    (when (-> self judge-h)
      (send-event (handle->process (-> self judge-h)) 'die)
      (set! (-> self judge-h) (the-as handle #f))
      )
    (when (-> self hud-counter)
      (send-event (handle->process (-> self hud-counter)) 'hide-and-die)
      (set! (-> self hud-counter) (the-as handle #f))
      )
    (let ((gp-1 (new 'stack-no-clear 'task-arrow-params)))
      (let ((a0-16 (new 'static 'vector :x 9527214.0 :y 196812.8 :z -1693368.4 :w 1.0)))
        (vector-copy! (-> gp-1 pos) a0-16)
        )
      (quaternion-identity! (-> gp-1 quat))
      (set! (-> gp-1 flags) (task-arrow-flags))
      (set! (-> gp-1 map-icon) (the-as uint 13))
      (set! (-> self arrow-h) (process->handle (task-arrow-spawn gp-1 self)))
      )
    )
  :exit (behavior ()
    (when (-> self hud-stat)
      (send-event (handle->process (-> self hud-stat)) 'hide-and-die)
      (set! (-> self hud-stat) (the-as handle #f))
      )
    )
  :trans (behavior ()
    (let ((s5-0 (new 'static 'vector :x 9527214.0 :y 196812.8 :z -1693368.4 :w 1.0)))
      (when (< (vector-vector-distance s5-0 (target-pos 0)) 12288.0)
        (send-event (handle->process (-> self arrow-h)) 'leave)
        (go-virtual complete)
        )
      )
    )
  :code (behavior ()
    (suspend-for (seconds 2)
      )
    (set! *arena-trainer-checkpoint-valid* #t)
    (copy-string<-string (-> *training-fail* fail continue) "wasstada-checkpoint-3")
    (set-setting! 'death-info *training-fail* 0.0 0)
    (until #f
      (suspend)
      )
    #f
    )
  )

(defstate active (task-manager-arena-training)
  :virtual #t
  :enter (behavior ()
    (cond
      ((task-node-closed? (game-task-node arena-training-1-collect))
       (go-virtual done)
       )
      ((= *arena-trainer-checkpoint-time* 0.0)
       (go-virtual wait-touch)
       )
      (else
        (go-virtual wait-more)
        )
      )
    (let ((t9-4 (-> (method-of-type task-manager active) enter)))
      (if t9-4
          (t9-4)
          )
      )
    )
  )

(defmethod task-manager-arena-training-method-36 ((this task-manager-arena-training))
  0
  (none)
  )

;; WARN: Return type mismatch continue-point vs none.
(defmethod task-manager-method-25 ((this task-manager-arena-training))
  (let ((t9-0 (method-of-type task-manager task-manager-method-25)))
    (t9-0 this)
    )
  (when (-> this judge-h)
    (send-event (handle->process (-> this judge-h)) 'die)
    (set! (-> this judge-h) (the-as handle #f))
    )
  (send-event *target* 'reset-pickup 'trick-judge)
  (when (not *arena-trainer-checkpoint-valid*)
    (copy-string<-string (-> *training-fail* fail continue) "wasstada-jump-training")
    (set-continue! *game-info* (-> *training-fail* fail continue) #t)
    )
  (none)
  )

(defmethod init! ((this task-manager-arena-training))
  (let ((t9-0 (method-of-type task-manager init!)))
    (t9-0 this)
    )
  (set! (-> this judge-h) (the-as handle #f))
  0
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defmethod set-time-limit ((this task-manager-arena-training))
  (local-vars (sv-16 res-tag))
  (when (not *arena-trainer-checkpoint-valid*)
    (set! *arena-trainer-checkpoint-time* 0.0)
    (set! (-> *arena-trainer-checkpoint-tokens* 0) (the-as uint -1))
    )
  (set! *arena-trainer-checkpoint-valid* (the-as object #f))
  (set-setting! 'music 'arenafi 0.0 0)
  (set-setting! 'death-info *training-fail* 0.0 0)
  (let ((t9-2 (method-of-type task-manager set-time-limit)))
    (t9-2 this)
    )
  (let ((a0-6 (entity-by-name "arena-trainer-1")))
    (when a0-6
      (set! (-> this entity) (the-as entity-actor a0-6))
      (set! sv-16 (new 'static 'res-tag))
      (let ((v0-5 (res-lump-data a0-6 'actor-groups pointer :tag-ptr (& sv-16))))
        (cond
          ((and v0-5 (nonzero? (-> sv-16 elt-count)))
           (set! (-> this actor-group-count) (the-as int (-> sv-16 elt-count)))
           (set! (-> this actor-group) (the-as (pointer actor-group) v0-5))
           )
          (else
            (format 0 "ERROR: ~s: entity missing actor-group!~%" (game-task->string (-> this node-info task)))
            )
          )
        )
      )
    )
  (none)
  )

(deftype wstd-trapdoor (process-drawable)
  ((root          collide-shape :override)
   (notify-actor  entity-actor)
   )
  (:state-methods
    idle
    die
    )
  )


(defskelgroup skel-wstd-trapdoor wstd-trapdoor wstd-trapdoor-lod0-jg wstd-trapdoor-idle-ja
              ((wstd-trapdoor-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 5)
              )

(defskelgroup skel-wstd-trapdoor-explode wstd-trapdoor wstd-trapdoor-explode-lod0-jg wstd-trapdoor-explode-idle-ja
              ((wstd-trapdoor-explode-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 15)
              )

(define *wstd-trapdoor-exploder-params*
  (new 'static 'joint-exploder-static-params
    :joints (new 'static 'boxed-array :type joint-exploder-static-joint-params
      (new 'static 'joint-exploder-static-joint-params :joint-index 4 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 5 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 6 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 7 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 8 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 9 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 10 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 11 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 12 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 13 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 14 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 15 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 16 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 17 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 18 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 19 :parent-joint-index -1)
      (new 'static 'joint-exploder-static-joint-params :joint-index 20 :parent-joint-index -1)
      )
    :collide-spec (collide-spec backgnd)
    )
  )

(defstate idle (wstd-trapdoor)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('attack)
       (when (logtest? (-> (the-as attack-info (-> block param 1)) penetrate-using) (penetrate flop))
         (go-virtual die)
         #f
         )
       )
      )
    )
  :code sleep-code
  )

(defstate die (wstd-trapdoor)
  :virtual #t
  :enter (behavior ()
    (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
    (sound-play "trapdoor")
    (let ((a1-1 (new 'stack-no-clear 'event-message-block)))
      (set! (-> a1-1 from) (process->ppointer self))
      (set! (-> a1-1 num-params) 0)
      (set! (-> a1-1 message) 'trigger)
      (let ((t9-2 send-event-function)
            (v1-6 (-> self notify-actor))
            )
        (t9-2
          (if v1-6
              (-> v1-6 extra process)
              )
          a1-1
          )
        )
      )
    )
  :code (behavior ()
    ((lambda () (with-pp
                  (sound-play "trap-door")
                  (let ((gp-1 (new 'stack 'joint-exploder-tuning (the-as uint 1))))
                    (let ((a0-4 (the-as target (as-type *target* process-focusable))))
                      (when a0-4
                        (vector-copy! (-> gp-1 fountain-rand-transv-lo) (get-trans a0-4 0))
                        (+! (-> gp-1 fountain-rand-transv-lo y) -16384.0)
                        )
                      )
                    (set! (-> gp-1 fountain-rand-transv-hi x) 24576.0)
                    (set! (-> gp-1 fountain-rand-transv-hi y) 81920.0)
                    (set! (-> gp-1 fountain-rand-transv-hi z) 12288.0)
                    (set! (-> gp-1 fountain-rand-transv-hi w) 32768.0)
                    (process-spawn
                      joint-exploder
                      (art-group-get-by-name *level* "skel-wstd-trapdoor-explode" (the-as (pointer level) #f))
                      5
                      gp-1
                      *wstd-trapdoor-exploder-params*
                      :name "joint-exploder"
                      :to pp
                      :unk 0
                      )
                    )
                  )
             )
     )
    (suspend)
    (ja-channel-set! 0)
    (suspend-for (seconds 1)
      )
    (send-event self 'death-end)
    (while (-> self child)
      (suspend)
      )
    (cleanup-for-death self)
    )
  :post ja-post
  )

(defmethod init-from-entity! ((this wstd-trapdoor) (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 usually-hit-by-player))))
    (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 bot player-list))
      (set! (-> v1-2 prim-core action) (collide-action solid))
      (set! (-> v1-2 transform-index) 0)
      (set-vector! (-> v1-2 local-sphere) 0.0 0.0 0.0 20480.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 penetrated-by) (penetrate flop))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-wstd-trapdoor" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (set! (-> this notify-actor) (entity-actor-lookup arg0 'alt-actor 0))
  (let ((a0-14 (-> this skel root-channel 0)))
    (set! (-> a0-14 frame-group) (the-as art-joint-anim (-> this draw art-group data 2)))
    (set! (-> a0-14 frame-num) 0.0)
    (joint-control-channel-group! a0-14 (the-as art-joint-anim (-> this draw art-group data 2)) num-func-identity)
    )
  (transform-post)
  (go (method-of-object this idle))
  )

(defskelgroup skel-wstd-flag wstd-flag wstd-flag-lod0-jg wstd-flag-idle-ja
              ((wstd-flag-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 6 0 12)
              )

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


(defstate idle (wstd-flag)
  :virtual #t
  :enter (behavior ()
    (ja :num-func num-func-identity :frame-num (the float (rand-vu-int-count (ja-num-frames 0))))
    )
  :trans (behavior ()
    (ja :num! (loop!))
    (if (ja-done? 0)
        (sound-play "flag-flaps")
        )
    )
  :code sleep-code
  :post ja-post
  )

(defmethod init-from-entity! ((this wstd-flag) (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" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (logclear! (-> this mask) (process-mask actor-pause))
  (go (method-of-object this idle))
  )
