;;-*-Lisp-*-
(in-package goal)
(bundles "ROL.DGO")
(require "engine/common-obs/collectables.gc")

;; DECOMP BEGINS

(deftype race-ring (process-drawable)
  ((rot-y                 float)
   (face-vec              vector :inline)
   (part-track            handle)
   (keep-part-track-alive symbol)
   (timeout               time-frame)
   (alt-actor             entity-actor)
   (alt-task              uint8)
   (cyl                   cylinder-flat :inline)
   (old-hips              vector :inline))
  (:states
   race-ring-active
   race-ring-idle
   race-ring-wait))


(defpartgroup group-rolling-ring
  :id 457
  :linger-duration (seconds 0)
  :bounds (static-bspherem 0 0 0 8)
  :parts
  ((sp-item 1773 :fade-after (meters 100) :falloff-to (meters 100))
   (sp-item 1774 :fade-after (meters 80))
   (sp-item 1775 :flags (is-3d))
   (sp-item 1776 :flags (is-3d))))

(defpart 1773
  :init-specs
  ((:texture (starflash effects))
   (:num 2.0 2.0)
   (:scale-x (meters 1) (meters 1))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 64.0 1 64.0)
   (:g 0.0)
   (:b 64.0 1 64.0)
   (:a 64.0)
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:fade-a -1.4222221)
   (:timer (seconds 0.14))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 4.5))
   (:rotate-y (degrees 0))))

(defpart 1774
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:scale-x (meters 1) (meters 4))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 64.0 1 64.0)
   (:g 0.0)
   (:b 64.0 1 64.0)
   (:a 64.0)
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:fade-a -1.4222221)
   (:timer (seconds 0.14))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 4.5))
   (:rotate-y (degrees 0))))

(defpart 1775
  :init-specs
  ((:texture (water-ring effects))
   (:num 1.0)
   (:scale-x (meters 10))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees -1) (degrees 2))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 128.0 1 127.0)
   (:g 0.0)
   (:b 128.0 1 127.0)
   (:a 96.0 32.0)
   (:fade-a -8.533334)
   (:timer (seconds 0.035))
   (:flags (bit2 bit3))))

(defpart 1776
  :init-specs
  ((:texture (middot effects))
   (:num 1.0)
   (:scale-x (meters 12))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees 0))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 128.0 1 127.0)
   (:g 0.0)
   (:b 128.0 1 127.0)
   (:a 32.0 32.0)
   (:timer (seconds 0.017))
   (:flags (bit2 bit3))))

(defpartgroup group-rolling-spawn-ring
  :id 458
  :duration (seconds 0.017)
  :linger-duration (seconds 0.47)
  :bounds (static-bspherem 0 0 0 8)
  :parts
  ((sp-item 1777 :fade-after (meters 100) :falloff-to (meters 100))
   (sp-item 1778 :flags (is-3d))
   (sp-item 1779 :flags (is-3d))))

(defpart 1777
  :init-specs
  ((:texture (starflash effects))
   (:num 32.0)
   (:scale-x (meters 1) (meters 3))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 64.0 1 64.0)
   (:g 0.0)
   (:b 64.0 1 64.0)
   (:a 0.0 63 1.0)
   (:vel-y (meters 0.03))
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:timer (seconds 0.5))
   (:flags (bit3))
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 1780)
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 0))
   (:rotate-y (degrees 0))))

(defpart 1780
  :init-specs
  ((:r 64.0 1 64.0)
   (:g 0.0)
   (:b 64.0 1 64.0)
   (:a 0.0 63 1.0)
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 1780)))

(defpart 1778
  :init-specs
  ((:texture (water-ring effects))
   (:num 1.0)
   (:scale-x (meters 0))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees -1) (degrees 2))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 128.0 1 127.0)
   (:g 0.0)
   (:b 128.0 1 127.0)
   (:a 96.0 32.0)
   (:scalevel-x (meters 0.06666667))
   (:scalevel-y :copy scalevel-x)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.017))
   (:next-launcher 1781)))

(defpart 1781
  :init-specs ((:r 128.0 1 127.0) (:g 0.0) (:b 128.0 1 127.0) (:a 32.0 32.0) (:next-time (seconds 0.017)) (:next-launcher 1781)))

(defpart 1779
  :init-specs
  ((:texture (middot effects))
   (:num 1.0)
   (:scale-x (meters 0))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees 0))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 128.0 1 127.0)
   (:g 0.0)
   (:b 128.0 1 127.0)
   (:a 32.0 32.0)
   (:scalevel-x (meters 0.08))
   (:scalevel-y :copy scalevel-x)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.017))
   (:next-launcher 1782)))

(defpart 1782
  :init-specs ((:r 128.0 1 127.0) (:g 0.0) (:b 128.0 1 127.0) (:a 32.0 32.0) (:next-time (seconds 0.017)) (:next-launcher 1782)))

(defpartgroup group-rolling-explode-ring
  :id 459
  :duration (seconds 0.017)
  :linger-duration (seconds 0.5)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 1783 :fade-after (meters 100) :falloff-to (meters 100)) (sp-item 1784 :flags (is-3d))))

(defpart 1783
  :init-specs
  ((:texture (starflash effects))
   (:num 64.0)
   (:scale-x (meters 1) (meters 1))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 64.0 1 64.0)
   (:g 0.0)
   (:b 64.0 1 64.0)
   (:a 32.0 96.0)
   (:vel-y (meters 0.1) (meters 0.033333335))
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:fade-a -0.85333335)
   (:friction 0.9)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 4.5))
   (:rotate-y (degrees 0))))

(defpart 1784
  :init-specs
  ((:texture (water-ring effects))
   (:num 2.0)
   (:scale-x (meters 10))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees -1) (degrees 2))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 128.0 1 127.0)
   (:g 0.0)
   (:b 128.0 1 127.0)
   (:a 128.0)
   (:scalevel-x (meters 0.06666667))
   (:scalevel-y :copy scalevel-x)
   (:fade-a -0.85333335)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3))))

(defun race-ring-set-particle-rotation-callback ((arg0 part-tracker))
  (let ((f0-0 (-> (the-as (pointer race-ring) (-> arg0 userdata)) 0 rot-y)))
    (set! (-> *part-id-table* 1773 init-specs 15 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1774 init-specs 15 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1775 init-specs 4 initial-valuef) (+ -182.04445 f0-0))
    (set! (-> *part-id-table* 1776 init-specs 4 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1777 init-specs 17 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1778 init-specs 4 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1779 init-specs 4 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1783 init-specs 17 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1784 init-specs 4 initial-valuef) f0-0))
  0
  (none))

(defpartgroup group-rolling-ring-blue
  :id 460
  :linger-duration (seconds 0)
  :bounds (static-bspherem 0 0 0 8)
  :parts
  ((sp-item 1785 :fade-after (meters 100) :falloff-to (meters 100))
   (sp-item 1786 :fade-after (meters 80))
   (sp-item 1787 :flags (is-3d))
   (sp-item 1788 :flags (is-3d))))

(defpart 1785
  :init-specs
  ((:texture (starflash effects))
   (:num 2.0 2.0)
   (:scale-x (meters 1) (meters 1))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 64.0 1 64.0)
   (:b 64.0 1 64.0)
   (:a 64.0)
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:fade-a -1.4222221)
   (:timer (seconds 0.14))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 4.5))
   (:rotate-y (degrees 0))))

(defpart 1786
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:scale-x (meters 1) (meters 4))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 64.0 1 64.0)
   (:b 64.0 1 64.0)
   (:a 64.0)
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:fade-a -1.4222221)
   (:timer (seconds 0.14))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 4.5))
   (:rotate-y (degrees 0))))

(defpart 1787
  :init-specs
  ((:texture (water-ring effects))
   (:num 1.0)
   (:scale-x (meters 10))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees -1) (degrees 2))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 128.0 1 127.0)
   (:b 128.0 1 127.0)
   (:a 96.0 32.0)
   (:fade-a -8.533334)
   (:timer (seconds 0.035))
   (:flags (bit2 bit3))))

(defpart 1788
  :init-specs
  ((:texture (middot effects))
   (:num 1.0)
   (:scale-x (meters 12))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees 0))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 128.0 1 127.0)
   (:b 128.0 1 127.0)
   (:a 32.0 32.0)
   (:timer (seconds 0.017))
   (:flags (bit2 bit3))))

(defpartgroup group-rolling-spawn-ring-blue
  :id 461
  :duration (seconds 0.017)
  :linger-duration (seconds 0.47)
  :bounds (static-bspherem 0 0 0 8)
  :parts
  ((sp-item 1789 :fade-after (meters 100) :falloff-to (meters 100))
   (sp-item 1790 :flags (is-3d))
   (sp-item 1791 :flags (is-3d))))

(defpart 1789
  :init-specs
  ((:texture (starflash effects))
   (:num 32.0)
   (:scale-x (meters 1) (meters 3))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 64.0 1 64.0)
   (:b 64.0 1 64.0)
   (:a 0.0 63 1.0)
   (:vel-y (meters 0.03))
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:timer (seconds 0.5))
   (:flags (bit3))
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 1792)
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 0))
   (:rotate-y (degrees 0))))

(defpart 1792
  :init-specs
  ((:r 0.0)
   (:g 64.0 1 64.0)
   (:b 64.0 1 64.0)
   (:a 0.0 63 1.0)
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 1792)))

(defpart 1790
  :init-specs
  ((:texture (water-ring effects))
   (:num 1.0)
   (:scale-x (meters 0))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees -1) (degrees 2))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 128.0 1 127.0)
   (:b 128.0 1 127.0)
   (:a 96.0 32.0)
   (:scalevel-x (meters 0.06666667))
   (:scalevel-y :copy scalevel-x)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.017))
   (:next-launcher 1793)))

(defpart 1793
  :init-specs ((:r 0.0) (:g 128.0 1 127.0) (:b 128.0 1 127.0) (:a 32.0 32.0) (:next-time (seconds 0.017)) (:next-launcher 1793)))

(defpart 1791
  :init-specs
  ((:texture (middot effects))
   (:num 1.0)
   (:scale-x (meters 0))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees 0))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 128.0 1 127.0)
   (:b 128.0 1 127.0)
   (:a 32.0 32.0)
   (:scalevel-x (meters 0.08))
   (:scalevel-y :copy scalevel-x)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.017))
   (:next-launcher 1794)))

(defpart 1794
  :init-specs ((:r 0.0) (:g 128.0 1 127.0) (:b 128.0 1 127.0) (:a 32.0 32.0) (:next-time (seconds 0.017)) (:next-launcher 1794)))

(defpartgroup group-rolling-explode-ring-blue
  :id 462
  :duration (seconds 0.017)
  :linger-duration (seconds 0.5)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 1795 :fade-after (meters 100) :falloff-to (meters 100)) (sp-item 1796 :flags (is-3d))))

(defpart 1795
  :init-specs
  ((:texture (starflash effects))
   (:num 64.0)
   (:scale-x (meters 1) (meters 1))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 64.0 1 64.0)
   (:b 64.0 1 64.0)
   (:a 32.0 96.0)
   (:vel-y (meters 0.1) (meters 0.033333335))
   (:rotvel-z (degrees -0.2) (degrees 0.4))
   (:fade-a -0.85333335)
   (:friction 0.9)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 360))
   (:conerot-radius (meters 4.5))
   (:rotate-y (degrees 0))))

(defpart 1796
  :init-specs
  ((:texture (water-ring effects))
   (:num 2.0)
   (:scale-x (meters 10))
   (:rot-x (degrees 0) (degrees 360))
   (:rot-y (degrees -1) (degrees 2))
   (:rot-z (degrees 90))
   (:scale-y :copy scale-x)
   (:r 0.0)
   (:g 128.0 1 127.0)
   (:b 128.0 1 127.0)
   (:a 128.0)
   (:scalevel-x (meters 0.06666667))
   (:scalevel-y :copy scalevel-x)
   (:fade-a -0.85333335)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3))))

(defun race-ring-blue-set-particle-rotation-callback ((arg0 part-tracker))
  (let ((f0-0 (-> (the-as (pointer race-ring) (-> arg0 userdata)) 0 rot-y)))
    (set! (-> *part-id-table* 1785 init-specs 15 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1786 init-specs 15 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1787 init-specs 4 initial-valuef) (+ -182.04445 f0-0))
    (set! (-> *part-id-table* 1788 init-specs 4 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1789 init-specs 17 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1790 init-specs 4 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1791 init-specs 4 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1795 init-specs 17 initial-valuef) f0-0)
    (set! (-> *part-id-table* 1796 init-specs 4 initial-valuef) f0-0))
  0
  (none))

(defskelgroup *race-ring-sg*
  race-ring
  race-ring-lod0-jg
  race-ring-race-ring-idle-ja
  ((race-ring-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 0 0 4))

(defun first-ring? ((arg0 race-ring))
  (not (-> arg0 alt-actor)))

(defun last-ring? ((arg0 race-ring))
  (not (-> arg0 link next)))

(defstate race-ring-active (race-ring)
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (local-vars (v0-0 symbol))
      (case message
        (('notify)
         (when (and (= (-> block param 0) 'die) (= proc (-> self part-track process 0)))
           (cond
             ((= (-> self entity extra perm task) (game-task rolling-ring-chase-2))
              (set! (-> self part-track)
                    (ppointer->handle (process-spawn part-tracker
                                                     :init
                                                     part-tracker-init
                                                     (-> *part-group-id-table* 460)
                                                     -1
                                                     race-ring-blue-set-particle-rotation-callback
                                                     (-> self ppointer)
                                                     #f
                                                     (-> self root trans)
                                                     :to
                                                     self)))
              (set! v0-0 #t)
              (set! (-> self keep-part-track-alive) v0-0))
             (else
              (set! (-> self part-track)
                    (ppointer->handle (process-spawn part-tracker
                                                     :init
                                                     part-tracker-init
                                                     (-> *part-group-id-table* 457)
                                                     -1
                                                     race-ring-set-particle-rotation-callback
                                                     (-> self ppointer)
                                                     #f
                                                     (-> self root trans)
                                                     :to
                                                     self)))
              (set! v0-0 #t)
              (set! (-> self keep-part-track-alive) v0-0)))
           v0-0))))
  :enter
    (behavior ()
      (cond
        ((first-ring? self)
         (logior! (-> self mask) (process-mask actor-pause))
         (process-entity-status! self (entity-perm-status bit-3) #f))
        (else (logclear! (-> self mask) (process-mask actor-pause)) (process-entity-status! self (entity-perm-status bit-3) #t)))
      (set! (-> self keep-part-track-alive) #f)
      (if (= (-> self entity extra perm task) (game-task rolling-ring-chase-2))
        (set! (-> self part-track)
              (ppointer->handle (process-spawn part-tracker
                                               :init
                                               part-tracker-init
                                               (-> *part-group-id-table* 461)
                                               -1
                                               race-ring-blue-set-particle-rotation-callback
                                               (-> self ppointer)
                                               #f
                                               (-> self root trans)
                                               :to
                                               self)))
        (set! (-> self part-track)
              (ppointer->handle (process-spawn part-tracker
                                               :init
                                               part-tracker-init
                                               (-> *part-group-id-table* 458)
                                               -1
                                               race-ring-set-particle-rotation-callback
                                               (-> self ppointer)
                                               #f
                                               (-> self root trans)
                                               :to
                                               self))))
      (set! (-> self old-hips quad) (-> (target-pos 26) quad))
      (+! (-> self old-hips x) 1.0)
      (set! (-> self state-time) (-> *display* game-frame-counter)))
  :exit
    (behavior ()
      (sound-play "close-racering")
      (let ((a0-3 (handle->process (-> self part-track)))) (if a0-3 (deactivate a0-3)))
      (if (= (-> self entity extra perm task) (game-task rolling-ring-chase-2))
        (set! (-> self part-track)
              (ppointer->handle (process-spawn part-tracker
                                               :init
                                               part-tracker-init
                                               (-> *part-group-id-table* 462)
                                               -1
                                               race-ring-blue-set-particle-rotation-callback
                                               (-> self ppointer)
                                               #f
                                               (-> self root trans)
                                               :to
                                               self)))
        (set! (-> self part-track)
              (ppointer->handle (process-spawn part-tracker
                                               :init
                                               part-tracker-init
                                               (-> *part-group-id-table* 459)
                                               -1
                                               race-ring-set-particle-rotation-callback
                                               (-> self ppointer)
                                               #f
                                               (-> self root trans)
                                               :to
                                               self))))
      (cond
        ((first-ring? self)
         (logclear! (-> self mask) (process-mask actor-pause))
         (process-entity-status! self (entity-perm-status bit-3) #t))
        (else (logior! (-> self mask) (process-mask actor-pause)) (process-entity-status! self (entity-perm-status bit-3) #f))))
  :trans
    (behavior ()
      (if (nonzero? (-> self sound)) (update! (-> self sound)))
      (cond
        ((handle->process (-> self part-track))
         (if (-> self keep-part-track-alive) (set-time! (-> (the-as part-tracker (-> self part-track process 0)) start-time))))
        ((= (-> self entity extra perm task) (game-task rolling-ring-chase-2))
         (set! (-> self part-track)
               (ppointer->handle (process-spawn part-tracker
                                                :init
                                                part-tracker-init
                                                (-> *part-group-id-table* 460)
                                                -1
                                                race-ring-blue-set-particle-rotation-callback
                                                (-> self ppointer)
                                                #f
                                                (-> self root trans)
                                                :to
                                                self)))
         (set! (-> self keep-part-track-alive) #t))
        (else
         (set! (-> self part-track)
               (ppointer->handle (process-spawn part-tracker
                                                :init
                                                part-tracker-init
                                                (-> *part-group-id-table* 457)
                                                -1
                                                race-ring-set-particle-rotation-callback
                                                (-> self ppointer)
                                                #f
                                                (-> self root trans)
                                                :to
                                                self)))
         (set! (-> self keep-part-track-alive) #t)))
      (cond
        ((not (last-ring? self)))
        ((= (-> self entity extra perm task) (game-task rolling-ring-chase-2))
         (spool-push *art-control* "race-ring-second-anim" 0 self -99.0))
        (else (spool-push *art-control* "race-ring-anim" 0 self -99.0))))
  :code
    (behavior ()
      (loop
        (suspend)
        (cond
          ((first-ring? self))
          ((>= (- (-> *display* game-frame-counter) (-> self state-time)) (-> self timeout))
           (level-hint-spawn (text-id rolling-ring-chase-fail) "sksp0121" (the-as entity #f) *entity-pool* (game-task none))
           (ambient-hint-spawn "st-lose" (the-as vector #f) *entity-pool* 'stinger)
           (let ((a1-2 (new 'stack-no-clear 'event-message-block)))
             (set! (-> a1-2 from) self)
             (set! (-> a1-2 num-params) 0)
             (set! (-> a1-2 message) 'activate)
             (let ((t9-3 send-event-function)
                   (v1-7 (-> self alt-actor)))
               (t9-3 (if v1-7 (-> v1-7 extra process)) a1-2)))
           (go race-ring-idle)))
        (when *target*
          (let ((gp-0 (new 'stack-no-clear 'vector)))
            (set! (-> gp-0 quad) (-> self old-hips quad))
            (set! (-> self old-hips quad) (-> (target-pos 26) quad))
            (vector-! gp-0 gp-0 (-> self old-hips))
            (when (>= (ray-flat-cyl-intersect (-> self cyl) (-> self old-hips) gp-0) 0.0)
              (level-hint-spawn (text-id rolling-ring-chase-1-hint) "sksp0119" (the-as entity #f) *entity-pool* (game-task none))
              (if (= (-> self entity extra perm task) (game-task rolling-ring-chase-2))
                (level-hint-spawn (text-id rolling-ring-chase-2-hint) "sksp0120" (the-as entity #f) *entity-pool* (game-task none)))
              (cond
                ((first-ring? self)
                 (close-specific-task! (-> self entity extra perm task) (task-status need-hint))
                 (entity-birth-no-kill (-> self link next))
                 (let ((a1-9 (new 'stack-no-clear 'event-message-block)))
                   (set! (-> a1-9 from) self)
                   (set! (-> a1-9 num-params) 0)
                   (set! (-> a1-9 message) 'activate)
                   (let ((t9-12 send-event-function)
                         (v1-30 (-> self link next)))
                     (t9-12 (if v1-30 (-> v1-30 extra process)) a1-9))))
                ((last-ring? self)
                 (let ((gp-2 (ppointer->handle (process-spawn othercam self 4 #f #t :to self)))
                       (s5-2 (ppointer->handle (process-spawn fuel-cell :init fuel-cell-init-as-clone (process->handle self) (-> self entity extra perm task) :to self))))
                   (if *target* (logior! (-> *target* mask) (process-mask sleep)))
                   (close-specific-task! (-> self entity extra perm task) (task-status need-reminder))
                   (logclear! (-> self draw status) (draw-status hidden))
                   (logior! (-> self draw status) (draw-status skip-bones))
                   (if (= (-> self entity extra perm task) (game-task rolling-ring-chase-2))
                     (ja-play-spooled-anim (new 'static 'spool-anim :name "race-ring-second-anim" :index 4 :parts 2 :command-list '())
                                           (the-as art-joint-anim #f)
                                           (the-as art-joint-anim #f)
                                           (the-as (function process-drawable symbol) false-func))
                     (ja-play-spooled-anim (new 'static 'spool-anim :name "race-ring-anim" :index 3 :parts 2 :command-list '())
                                           (the-as art-joint-anim #f)
                                           (the-as art-joint-anim #f)
                                           (the-as (function process-drawable symbol) false-func)))
                   (logclear! (-> self draw status) (draw-status skip-bones))
                   (logior! (-> self draw status) (draw-status hidden))
                   (cond
                     ((handle->process (the-as int gp-2)) (deactivate (-> gp-2 process 0)))
                     (else))
                   (if *target* (logclear! (-> *target* mask) (process-mask sleep)))
                   (let ((a0-54 (handle->process s5-2))) (if a0-54 (send-event a0-54 'stop-cloning)))))
                (else
                 (entity-birth-no-kill (-> self link next))
                 (let ((a1-22 (new 'stack-no-clear 'event-message-block)))
                   (set! (-> a1-22 from) self)
                   (set! (-> a1-22 num-params) 0)
                   (set! (-> a1-22 message) 'activate)
                   (let ((t9-26 send-event-function)
                         (v1-86 (-> self link next)))
                     (t9-26 (if v1-86 (-> v1-86 extra process)) a1-22)))))
              (go race-ring-idle))))))
  :post ja-post)

(defstate race-ring-wait (race-ring)
  :code
    (behavior ()
      (if (nonzero? (-> self sound)) (stop! (-> self sound)))
      (loop
        (suspend)
        (when (= (get-task-status (the-as game-task (-> self alt-task))) (task-status invalid))
          (close-specific-task! (-> self entity extra perm task) (task-status need-hint))
          (logclear! (-> self mask) (process-mask actor-pause))
          (go race-ring-active)))))

(defstate race-ring-idle (race-ring)
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('activate) (logclear! (-> self mask) (process-mask actor-pause)) (go race-ring-active))))
  :code
    (behavior ()
      (if (nonzero? (-> self sound)) (stop! (-> self sound)))
      (loop
        (suspend))))

(defmethod init-from-entity! ((this race-ring) (arg0 entity-actor))
  (let ((a0-1 arg0)) (if (not (entity-actor-lookup a0-1 'next-actor 0)) (stack-size-set! (-> this main-thread) 512)))
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *race-ring-sg* '())
  (set! (-> this root pause-adjust-distance) 122880.0)
  (set! (-> this link) (new 'process 'actor-link-info this))
  (set! (-> this part-track) (the-as handle #f))
  (set! (-> this alt-actor) (entity-actor-lookup arg0 'alt-actor 0))
  (logior! (-> this draw status) (draw-status hidden))
  (set! (-> this sound) (new 'process 'ambient-sound (static-sound-spec "loop-racering" :fo-max 40) (-> this root trans)))
  (let ((f0-1 (res-lump-float arg0 'timeout))) (set! (-> this timeout) (the-as time-frame (the int (* 300.0 f0-1)))))
  (let ((s4-0 (new 'stack-no-clear 'vector)))
    (cond
      ((-> this link next) (vector-! (-> this face-vec) (-> this link next extra trans) (-> this root trans)))
      ((-> this link prev) (vector-! (-> this face-vec) (-> this root trans) (-> this link prev extra trans))))
    (vector-flatten! (-> this face-vec) (-> this face-vec) (new 'static 'vector :y 1.0))
    (vector-normalize! (-> this face-vec) 1.0)
    (cond
      ((and (-> this link next) (-> this link prev))
       (vector-! s4-0 (-> this link prev extra trans) (-> this root trans))
       (vector-flatten! s4-0 s4-0 (new 'static 'vector :y 1.0))
       (vector-normalize! s4-0 1.0)
       (vector+! s4-0 s4-0 (-> this face-vec))
       (vector-normalize! s4-0 1.0)
       (set! (-> this rot-y) (acos (vector-dot s4-0 (new 'static 'vector :z 1.0))))
       (if (< (vector-dot s4-0 (new 'static 'vector :x 1.0)) 0.0) (set! (-> this rot-y) (- (-> this rot-y)))))
      (else
       (set! (-> this rot-y) (acos (vector-dot (-> this face-vec) (new 'static 'vector :z 1.0))))
       (if (< (vector-dot (-> this face-vec) (new 'static 'vector :x 1.0)) 0.0) (set! (-> this rot-y) (- (-> this rot-y))))
       (+! (-> this rot-y) 16384.0))))
  (+! (-> this rot-y) (res-lump-float arg0 'rotoffset))
  (set-vector! (-> this cyl axis) (cos (-> this rot-y)) 0.0 (- (sin (-> this rot-y))) 1.0)
  (vector+float*! (the-as vector (-> this cyl)) (-> this root trans) (-> this cyl axis) -2048.0)
  (set! (-> this cyl radius) 24576.0)
  (set! (-> this cyl length) 4096.0)
  (cond
    ((and (first-ring? this)
          (!= (get-task-status (-> this entity extra perm task)) (task-status invalid))
          (!= (get-task-status (-> this entity extra perm task)) 7))
     (set! (-> this alt-task) (res-lump-value (-> this entity) 'alt-task uint))
     (if (or (= (-> this alt-task) 0) (= (get-task-status (the-as game-task (-> this alt-task))) (task-status invalid)))
       (go race-ring-active)
       (go race-ring-wait)))
    ((and (last-ring? this) (= (get-task-status (-> this entity extra perm task)) (task-status need-resolution)))
     (let ((s5-2 (new 'stack-no-clear 'vector)))
       (logclear! (-> this draw status) (draw-status hidden))
       (ja-post)
       (vector<-cspace! s5-2 (-> this node-list data 5))
       (logior! (-> this draw status) (draw-status hidden))
       (birth-pickup-at-point s5-2
                              (pickup-type fuel-cell)
                              (the float (-> this entity extra perm task))
                              #f
                              this
                              (the-as fact-info #f))))
    ((and (last-ring? this) (!= (get-task-status (-> this entity extra perm task)) (task-status invalid)))))
  (set! (-> this event-hook) (-> race-ring-idle event))
  (go race-ring-idle)
  (none))
