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

;; name: des-bush.gc
;; name in dgo: des-bush
;; dgos: LBBSDRP1, LBBRING3, LBBRING4, LBBSDRP2, LBBRING2, LBBSPIRT, LBBSPID, LBBRING5, LBBSPRT3, LBBSPRT2, LBBRING1, LBBRING6, LBBSDRP3

(declare-type desert-chase-ring process)

;; +++bb-score-type
(defenum bb-score-type
  :type uint8
  (small)
  (medium)
  (large)
  )
;; ---bb-score-type


;; DECOMP BEGINS

(define *tex-level-list*
  (new 'static 'boxed-array :type symbol 'lbbring1 'lbbring2 'lbbring3 'lbbring4 'lbbring5 'lbbring6)
  )

(defpartgroup group-desert-ring
  :id 1547
  :duration (seconds 218.45)
  :linger-duration (seconds 0)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 5143 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5143 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5143 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5143 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5143 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5143 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5144 :flags (is-3d sp7))
    (sp-item 5144 :flags (is-3d sp7))
    )
  )

(defpart 5143
  :init-specs ((:texture (racegate lbbring6-sprite))
    (:num 1.0)
    (:scale-x (meters 12))
    (:scale-y :copy scale-x)
    (:r 40.0)
    (:g 80.0)
    (:b 255.0)
    (:a 64.0)
    (:rotvel-y (degrees 0.026666665) (degrees 0.033333335))
    (:timer (seconds -0.005))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14))
    (:rotate-x (degrees -90) 1 (degrees 180))
    (:rotate-z (degrees -90) (degrees 180))
    )
  )

(defpart 5144
  :init-specs ((:texture (splash-foam level-default-sprite))
    (:num 0.0 0.5)
    (:scale-x (meters 12) (meters 1))
    (:scale-y :copy scale-x)
    (:r 10.0)
    (:g 0.0 64.0)
    (:b 255.0)
    (:a 0.0)
    (:scalevel-x (meters -0.093333334))
    (:scalevel-y :copy scalevel-x)
    (:fade-a 6.4)
    (:timer (seconds 0.5))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14 left-multiply-quat))
    (:next-time (seconds 0.067))
    (:next-launcher 5145)
    (:rotate-x (degrees -90))
    (:rotate-z (degrees -90) (degrees 180))
    )
  )

(defpart 5145
  :init-specs ((:fade-a -1.28))
  )

(defpartgroup group-desert-ring-final
  :id 1548
  :duration (seconds 218.45)
  :linger-duration (seconds 0)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 5146 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5146 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5146 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5146 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5146 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5146 :flags (is-3d sp3 sp6 sp7))
    (sp-item 5147 :flags (is-3d sp7))
    (sp-item 5147 :flags (is-3d sp7))
    )
  )

(defpart 5146
  :init-specs ((:texture (racegate lbbring6-sprite))
    (:num 1.0)
    (:scale-x (meters 12))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 80.0)
    (:b 40.0)
    (:a 64.0)
    (:rotvel-y (degrees 0.026666665) (degrees 0.033333335))
    (:timer (seconds -0.005))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14))
    (:rotate-x (degrees -90) 1 (degrees 180))
    (:rotate-z (degrees -90) (degrees 180))
    )
  )

(defpart 5147
  :init-specs ((:texture (splash-foam level-default-sprite))
    (:num 0.0 0.5)
    (:scale-x (meters 12) (meters 1))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0 64.0)
    (:b 10.0)
    (:a 0.0)
    (:scalevel-x (meters -0.093333334))
    (:scalevel-y :copy scalevel-x)
    (:fade-a 6.4)
    (:timer (seconds 0.5))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 sp-cpuinfo-flag-14 left-multiply-quat))
    (:next-time (seconds 0.067))
    (:next-launcher 5148)
    (:rotate-x (degrees -90))
    (:rotate-z (degrees -90) (degrees 180))
    )
  )

(defpart 5148
  :init-specs ((:fade-a -1.28))
  )

(defpartgroup group-desert-ring-explode
  :id 1549
  :duration (seconds 0.067)
  :linger-duration (seconds 0.5)
  :flags (sp0 sp4)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 5149 :flags (sp3 sp7)) (sp-item 5150 :flags (sp6 sp7)))
  )

(defpart 5149
  :init-specs ((:texture (middot level-default-sprite))
    (:num 200.0)
    (:x (meters 5.8))
    (:scale-x (meters 0.3))
    (:scale-y :copy scale-x)
    (:r 40.0)
    (:g 80.0)
    (:b 255.0)
    (:a 64.0)
    (:omega (degrees 0.225))
    (:vel-x (meters 0.06666667) (meters 0.06666667))
    (:friction 0.9)
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:func 'sparticle-motion-blur)
    (:rotate-y (degrees 0))
    (:rotate-z (degrees 0) (degrees 3600))
    )
  )

(defpart 5150
  :init-specs ((:texture (glow-soft level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 36))
    (:scale-y :copy scale-x)
    (:r 120.0)
    (:g 120.0)
    (:b 120.0)
    (:a 20.0)
    (:fade-r -17.0)
    (:fade-g -8.5)
    (:fade-b 0.0)
    (:fade-a -0.6666667)
    (:timer (seconds 0.1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 0.0)
    (:rotate-x (degrees -90))
    )
  )

(defpartgroup group-desert-ring-explode-final
  :id 1550
  :duration (seconds 0.067)
  :linger-duration (seconds 0.5)
  :flags (sp0 sp4)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 5151 :flags (sp3 sp7)) (sp-item 5152 :flags (sp6 sp7)))
  )

(defpart 5151
  :init-specs ((:texture (middot level-default-sprite))
    (:num 200.0)
    (:x (meters 5.8))
    (:scale-x (meters 0.3))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 80.0)
    (:b 40.0)
    (:a 64.0)
    (:omega (degrees 0.225))
    (:vel-x (meters 0.06666667) (meters 0.06666667))
    (:friction 0.9)
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:func 'sparticle-motion-blur)
    (:rotate-y (degrees 0))
    (:rotate-z (degrees 0) (degrees 3600))
    )
  )

(defpart 5152
  :init-specs ((:texture (glow-soft level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 36))
    (:scale-y :copy scale-x)
    (:r 120.0)
    (:g 120.0)
    (:b 120.0)
    (:a 20.0)
    (:fade-r -17.0)
    (:fade-g -8.5)
    (:fade-b 0.0)
    (:fade-a -0.6666667)
    (:timer (seconds 0.1))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 0.0)
    (:rotate-x (degrees -90))
    )
  )

(defpartgroup group-desert-ring-birth
  :id 1551
  :duration (seconds 0.067)
  :linger-duration (seconds 0.5)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 5153 :flags (is-3d sp3 sp6 sp7)) (sp-item 5150 :flags (sp6 sp7)))
  )

(defpart 5153
  :init-specs ((:texture (racegate lbbring6-sprite))
    (:num 1.0)
    (:r 40.0)
    (:g 80.0)
    (:b 255.0)
    (:a 64.0)
    (:scalevel-x (meters 0.1))
    (:rotvel-y (degrees 0.026666665) (degrees 0.033333335))
    (:scalevel-y :copy scalevel-x)
    (:fade-a 0.53333336)
    (:timer (seconds 0.4))
    (:flags (sp-cpuinfo-flag-3 sp-cpuinfo-flag-14))
    (:rotate-x (degrees -90))
    (:rotate-z (degrees -90) (degrees 180))
    )
  )

(defpartgroup group-desert-ring-birth-final
  :id 1552
  :duration (seconds 0.067)
  :linger-duration (seconds 0.5)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 5154 :flags (is-3d sp3 sp6 sp7)) (sp-item 5152 :flags (sp6 sp7)))
  )

(defpart 5154
  :init-specs ((:texture (racegate lbbring6-sprite))
    (:num 1.0)
    (:r 255.0)
    (:g 80.0)
    (:b 40.0)
    (:a 64.0)
    (:scalevel-x (meters 0.1))
    (:rotvel-y (degrees 0.026666665) (degrees 0.033333335))
    (:scalevel-y :copy scalevel-x)
    (:fade-a 0.53333336)
    (:timer (seconds 0.4))
    (:flags (sp-cpuinfo-flag-3 sp-cpuinfo-flag-14))
    (:rotate-x (degrees -90))
    (:rotate-z (degrees -90) (degrees 180))
    )
  )

(defun find-level-name ()
  (dotimes (gp-0 (-> *tex-level-list* length))
    (let ((v1-3 (level-get *level* (-> *tex-level-list* gp-0))))
      (if v1-3
          (return v1-3)
          )
      )
    )
  (the-as level #f)
  )

;; WARN: Return type mismatch texture-id vs none.
(defun set-ring-particle-texture ()
  (let ((gp-0 (find-level-name)))
    (when gp-0
      (set! (-> *part-id-table* 5143 init-specs 0 initial-valuef)
            (the-as float (lookup-level-texture-id-by-name "racegate" gp-0 7))
            )
      (set! (-> *part-id-table* 5146 init-specs 0 initial-valuef)
            (the-as float (lookup-level-texture-id-by-name "racegate" gp-0 7))
            )
      (set! (-> *part-id-table* 5153 init-specs 0 initial-valuef)
            (the-as float (lookup-level-texture-id-by-name "racegate" gp-0 7))
            )
      (set! (-> *part-id-table* 5154 init-specs 0 initial-valuef)
            (the-as float (lookup-level-texture-id-by-name "racegate" gp-0 7))
            )
      )
    )
  (none)
  )

(define *des-ring-times*
  (the-as (array (array float))
    (new 'static 'boxed-array :type array
      (new 'static 'boxed-array :type float
        11.0
        9.0
        9.0
        8.0
        7.0
        11.0
        8.0
        8.0
        10.0
        8.0
        12.0
        9.0
        10.0
        9.0
        10.0
        13.0
        11.0
        12.0
        10.0
        10.0
        10.0
        10.0
        8.0
        9.0
        13.0
        10.0
        12.0
        10.0
        6.0
        8.0
        9.0
        11.0
        10.0
        11.0
        10.0
        11.0
        15.0
        14.0
        9.0
        15.0
        10.0
        13.0
        9.0
        13.0
        8.0
        7.0
        )
      (new 'static 'boxed-array :type float
        11.0
        5.2133
        5.2066
        5.8266
        5.0
        5.0
        5.0
        5.0
        8.0
        5.0
        5.0
        7.0
        9.0
        8.0
        4.0
        4.0
        5.0
        10.0
        11.0
        10.0
        )
      (new 'static 'boxed-array :type float
        11.0
        4.0
        4.0
        3.0
        3.0
        6.0
        3.0
        4.0
        5.0
        7.0
        5.0
        4.0
        6.0
        6.0
        3.0
        4.0
        6.0
        3.0
        5.0
        4.0
        4.0
        9.0
        5.0
        9.0
        )
      (new 'static 'boxed-array :type float 11.0 6.0 7.0 8.0 5.0 5.0 7.0 6.0 5.0 5.0 5.0 6.0 8.0 7.0 6.0 6.0 8.0)
      (new 'static 'boxed-array :type float
        11.0
        5.0
        4.0
        5.0
        5.0
        5.0
        5.0
        6.0
        6.0
        6.0
        5.0
        6.0
        6.0
        5.0
        6.0
        6.0
        6.0
        4.0
        6.0
        7.0
        5.0
        5.0
        7.0
        6.0
        6.0
        5.0
        5.0
        4.0
        )
      (new 'static 'boxed-array :type float
        11.0
        6.0
        5.0
        7.0
        8.0
        4.0
        3.0
        4.0
        5.0
        5.0
        5.0
        5.0
        5.0
        6.0
        5.0
        7.0
        7.0
        4.0
        5.0
        5.0
        6.0
        7.0
        4.0
        4.0
        7.0
        5.0
        5.0
        5.0
        4.0
        4.0
        7.0
        5.0
        7.0
        7.0
        7.0
        7.0
        4.0
        7.0
        )
      )
    )
  )

(deftype task-manager-desert-bbush-ring (task-manager)
  ((actor-group        (pointer actor-group))
   (actor-group-count  int32)
   (current-ring       int32)
   )
  (:methods
    (get-mgr-name (_type_) string)
    (task-manager-desert-bbush-ring-method-33 (_type_) none)
    )
  )


(defstate resolution (task-manager-desert-bbush-ring)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :code (behavior ()
    (local-vars (v1-34 object))
    (when (logtest? (-> self info mask) (task-manager-mask resolution-scene))
      (let ((gp-1 (ppointer->handle (process-spawn
                                      scene-player
                                      :init scene-player-init
                                      (-> self info resolution-scene)
                                      #t
                                      (-> self info resolution-scene-continue)
                                      :name "scene-player"
                                      )
                                    )
                  )
            )
        (while (handle->process (the-as handle gp-1))
          (suspend)
          )
        )
      )
    (task-manager-method-27 self)
    (give *game-info* 'skill (the float (-> self info user-count)) (the-as handle #f))
    (until (< (* 45 (-> self info user-count)) (- (current-time) (-> self state-time)))
      (suspend)
      )
    (let ((gp-2 (-> self info on-complete)))
      (if gp-2
          (script-eval gp-2)
          )
      )
    (task-node-close! (-> self info final-node) 'event)
    (remove-setting! 'allow-progress)
    (while (begin
             (set! v1-34 (or (handle->process (-> self arrow)) (begin
                                                                 (countdown (v1-35 4)
                                                                   (when (handle->process (-> self hud v1-35))
                                                                     (set! v1-34 #t)
                                                                     (goto cfg-41)
                                                                     )
                                                                   )
                                                                 #f
                                                                 )
                             )
                   )
             (label cfg-41)
             v1-34
             )
      (suspend)
      )
    )
  )

(defmethod get-mgr-name ((this task-manager-desert-bbush-ring))
  "t-manager-1"
  )

(defmethod task-manager-desert-bbush-ring-method-33 ((this task-manager-desert-bbush-ring))
  (cond
    ((= (level-status? *level* 'waswide #f) 'active)
     (set-setting! 'extra-bank '((wascity3 bbush1)) 0.0 0)
     (set-setting! 'music 'wasring 0.0 0)
     )
    (else
      (set-setting! 'extra-bank '((desert2 bbush1) (nest2 bbush1)) 0.0 0)
      (set-setting! 'music 'desring 0.0 0)
      )
    )
  0
  (none)
  )

(define *bb-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)
    )
  )

(defmethod set-time-limit ((this task-manager-desert-bbush-ring))
  (local-vars (sv-16 res-tag))
  (let ((t9-0 (method-of-type task-manager set-time-limit)))
    (t9-0 this)
    )
  (set-setting! 'airlock #f 0.0 0)
  (format 0 "actor-group-count: ~d~%" (-> this actor-group-count))
  (set! (-> this current-ring) 0)
  (task-manager-desert-bbush-ring-method-33 this)
  (logclear! (-> this mask) (process-mask actor-pause))
  (let ((a0-8 (entity-by-name (get-mgr-name this))))
    (when a0-8
      (set! (-> this entity) (the-as entity-actor a0-8))
      (set! sv-16 (new 'static 'res-tag))
      (let ((s5-2 (res-lump-data a0-8 'actor-groups pointer :tag-ptr (& sv-16))))
        (format 0 "elt-count: ~d" (-> sv-16 elt-count))
        (cond
          ((and s5-2 (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) s5-2))
           )
          (else
            (format 0 "ERROR: ~s: entity missing actor-group!~%" (game-task->string (-> this node-info task)))
            )
          )
        )
      )
    )
  0
  (none)
  )

(defmethod hud-timer-handler ((this task-manager-desert-bbush-ring))
  (with-pp
    (cond
      ((and *target* (= (level-status? *level* 'desert #f) 'active) (focus-test? *target* pilot-riding))
       (when (nonzero? (-> this start-time))
         (let ((v1-8 (handle->process (-> this hud-timer))))
           (if (and *target* (not v1-8))
               (set! (-> this hud-timer)
                     (ppointer->handle (process-spawn hud-timer :init hud-init-by-other :name "hud-timer" :to *target*))
                     )
               )
           )
         (let ((v1-18 (- (-> this time-limit) (- (current-time) (-> this start-time)))))
           (let ((a0-21 *game-info*))
             (set! (-> a0-21 timer) v1-18)
             (set! (-> a0-21 timer-flash) (< v1-18 (seconds 10)))
             )
           (cond
             ((< v1-18 0)
              (format #t "speed: ~f~%" (* 0.00024414062 (vector-length (-> *target* control transv))))
              (cond
                ((< (vector-length (-> *target* control transv)) 1966.08)
                 (process-release? *target*)
                 (if *debug-segment*
                     (format #t "task failed:  ran out of time~%")
                     )
                 (send-event (handle->process (-> this hud-timer)) 'hide-and-die)
                 (let ((v1-41 (-> this actor-group 0 data (-> this current-ring))))
                   (when v1-41
                     (let ((a1-9 (new 'stack-no-clear 'event-message-block)))
                       (set! (-> a1-9 from) (process->ppointer pp))
                       (set! (-> a1-9 num-params) 0)
                       (set! (-> a1-9 message) 'fail)
                       (let ((t9-8 send-event-function)
                             (v1-42 (-> v1-41 actor))
                             )
                         (t9-8
                           (if v1-42
                               (-> v1-42 extra process)
                               )
                           a1-9
                           )
                         )
                       )
                     )
                   )
                 (go (method-of-object this fail) (on-fail this 'fail))
                 )
                (else
                  (set! (-> this time-limit) (- (current-time) (-> this start-time)))
                  (process-grab? *target* #f)
                  )
                )
              )
             (else
               (process-release? *target*)
               )
             )
           )
         )
       )
      (else
        (call-parent-method this)
        )
      )
    0
    (none)
    )
  )

(defstate active (task-manager-desert-bbush-ring)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('goal)
       (send-event self 'complete)
       )
      (('ring-hit)
       (+! (-> self current-ring) 1)
       (cond
         ((< (-> self current-ring) (length (-> self actor-group 0)))
          (let ((gp-1 (-> self actor-group 0 data (-> self current-ring))))
            (when gp-1
              (cond
                ((= (+ (length (-> self actor-group 0)) -1) (-> self current-ring))
                 (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) 'trigger-final)
                   (let ((t9-3 send-event-function)
                         (v1-17 (-> gp-1 actor))
                         )
                     (t9-3
                       (if v1-17
                           (-> v1-17 extra process)
                           )
                       a1-2
                       )
                     )
                   )
                 )
                (else
                  (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) 'trigger)
                    (let ((t9-4 send-event-function)
                          (v1-23 (-> gp-1 actor))
                          )
                      (t9-4
                        (if v1-23
                            (-> v1-23 extra process)
                            )
                        a1-3
                        )
                      )
                    )
                  )
                )
              (set-time! (-> self start-time))
              (set! (-> self time-limit)
                    (the-as time-frame (the int (* 300.0 (-> *des-ring-times* (-> self info index) (-> self current-ring)))))
                    )
              0
              )
            )
          )
         (else
           (send-event self 'complete)
           )
         )
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set-time! (-> self start-time))
    (set! (-> self time-limit)
          (the-as time-frame (the int (* 300.0 (-> *des-ring-times* (-> self info index) 0))))
          )
    )
  :exit (behavior ()
    (process-release? *target*)
    (let ((t9-2 (-> (find-parent-state) exit)))
      (if t9-2
          (t9-2)
          )
      )
    0
    )
  :trans (behavior ()
    (call-parent-state-handler trans)
    (hud-timer-handler self)
    )
  :code (behavior ()
    (suspend)
    (when (nonzero? (-> self actor-group-count))
      (let ((v1-4 (-> self actor-group 0 data)))
        (when v1-4
          (let ((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) 'trigger)
            (let ((t9-0 send-event-function)
                  (v1-5 (-> v1-4 0 actor))
                  )
              (t9-0
                (if v1-5
                    (-> v1-5 extra process)
                    )
                a1-0
                )
              )
            )
          0
          )
        )
      )
    (until #f
      (suspend)
      )
    #f
    )
  )

(defstate fail (task-manager-desert-bbush-ring)
  :virtual #t
  :enter (behavior ((arg0 resetter-params))
    (kill-by-type desert-chase-ring *active-pool*)
    )
  )

(deftype task-manager-desert-bbush-ring-2 (task-manager-desert-bbush-ring)
  ()
  )


(defmethod get-mgr-name ((this task-manager-desert-bbush-ring-2))
  "t-manager-10"
  )

(defmethod task-manager-desert-bbush-ring-method-33 ((this task-manager-desert-bbush-ring-2))
  (set-setting! 'extra-bank '((desert2 bbush1)) 0.0 0)
  (set-setting! 'music 'desring 0.0 0)
  0
  (none)
  )

(deftype task-manager-desert-bbush-ring-3 (task-manager-desert-bbush-ring)
  ()
  )


(defmethod get-mgr-name ((this task-manager-desert-bbush-ring-3))
  (format 0 "tag1~%")
  "t-manager-2"
  )

(deftype task-manager-desert-bbush-ring-4 (task-manager-desert-bbush-ring)
  ()
  )


(defmethod get-mgr-name ((this task-manager-desert-bbush-ring-4))
  (format 0 "tag1~%")
  "t-manager-6"
  )

(deftype task-manager-desert-bbush-ring-5 (task-manager-desert-bbush-ring)
  ()
  )


(defmethod init! ((this task-manager-desert-bbush-ring-5))
  (set-setting! 'use-alternate-bouncer? #t 0.0 0)
  (call-parent-method this)
  (none)
  )

(defmethod get-mgr-name ((this task-manager-desert-bbush-ring-5))
  (format 0 "tag1~%")
  "t-manager-7"
  )

(defmethod task-manager-desert-bbush-ring-method-33 ((this task-manager-desert-bbush-ring-5))
  (set-setting! 'city-sound '(citybb1) 0.0 2)
  (set-setting! 'music 'cityring 0.0 0)
  0
  (none)
  )

(deftype task-manager-desert-bbush-ring-6 (task-manager-desert-bbush-ring)
  ()
  )


(defmethod task-manager-desert-bbush-ring-method-33 ((this task-manager-desert-bbush-ring-6))
  (set-setting! 'city-sound '(citybb1) 0.0 2)
  (set-setting! 'music 'cityring 0.0 0)
  0
  (none)
  )

(defmethod init! ((this task-manager-desert-bbush-ring-6))
  (set-setting! 'use-alternate-bouncer? #t 0.0 0)
  (call-parent-method this)
  (none)
  )

(define *bbush-ring-6-kg-squad-member-settings* (new 'static 'squad-unit-settings
                                                  :target-count 14
                                                  :shot-count #x7f
                                                  :inaccuracy (the-as float #x6)
                                                  :rand-shot-delay (seconds 108.42)
                                                  )
        )

(defmethod set-time-limit ((this task-manager-desert-bbush-ring-6))
  (set-setting! 'kg-enemy-settings #f 0.0 *bbush-ring-6-kg-squad-member-settings*)
  (call-parent-method this)
  (none)
  )

(defmethod get-mgr-name ((this task-manager-desert-bbush-ring-6))
  (format 0 "tag1~%")
  "t-manager-8"
  )

(deftype desert-chase-ring (process-drawable)
  ((mat           matrix  :inline)
   (taskman       handle)
   (turbo-handle  handle)
   (alt-actor     entity-actor)
   (ring-radius   float)
   (minimap       connection-minimap)
   (is-final?     symbol)
   (part-final    sparticle-launch-control)
   )
  (:state-methods
    dormant
    idle
    die
    )
  (:methods
    (alloc-trsqv! (_type_) none)
    )
  )


(defun desert-chase-ring-cleared? ((arg0 vector) (arg1 vector) (arg2 desert-chase-ring))
  (let ((s5-0 (new 'stack-no-clear 'vector)))
    (and (< (fabs (vector-dot (vector-x-quaternion! s5-0 (the-as quaternion arg0)) arg1)) (-> arg2 ring-radius))
         (< (fabs (vector-dot (vector-y-quaternion! s5-0 (the-as quaternion arg0)) arg1)) (-> arg2 ring-radius))
         (< (fabs (vector-dot (vector-z-quaternion! s5-0 (the-as quaternion arg0)) arg1)) 4096.0)
         )
    )
  )

(defmethod run-logic? ((this desert-chase-ring))
  "Should this process be run? Checked by execute-process-tree."
  #t
  )

(defstate dormant (desert-chase-ring)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trigger)
       (if (type? proc task-manager-desert-bbush-ring)
           (set! (-> self taskman) (process->handle proc))
           )
       (go-virtual idle)
       )
      (('trigger-final)
       (when (type? proc task-manager-desert-bbush-ring)
         (set! (-> self is-final?) #t)
         (set! (-> self taskman) (process->handle proc))
         )
       (go-virtual idle)
       )
      )
    )
  :trans (behavior ()
    0
    )
  :code sleep-code
  :post (behavior ()
    0
    )
  )

(defstate idle (desert-chase-ring)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('fail)
       (if (nonzero? (-> self part))
           (kill-particles (-> self part))
           )
       (go-virtual die)
       )
      )
    )
  :enter (behavior ()
    (cond
      ((-> self is-final?)
       (if (logtest? (-> *part-group-id-table* 1552 flags) (sp-group-flag sp13))
           (part-tracker-spawn
             part-tracker-subsampler
             :to self
             :group (-> *part-group-id-table* 1552)
             :mat-joint (-> self mat)
             )
           (part-tracker-spawn part-tracker :to self :group (-> *part-group-id-table* 1552) :mat-joint (-> self mat))
           )
       )
      ((logtest? (-> *part-group-id-table* 1551 flags) (sp-group-flag sp13))
       (part-tracker-spawn
         part-tracker-subsampler
         :to self
         :group (-> *part-group-id-table* 1551)
         :mat-joint (-> self mat)
         )
       )
      (else
        (part-tracker-spawn part-tracker :to self :group (-> *part-group-id-table* 1551) :mat-joint (-> self mat))
        )
      )
    (sound-play "ring-create")
    (set-time! (-> self state-time))
    (set! (-> self minimap) (add-icon! *minimap* self (the-as uint 13) (the-as int #f) (the-as vector #t) 0))
    (when (-> self alt-actor)
      (format 0 "setting-up turbo~%")
      (turbo-pickup-spawn (-> self alt-actor extra trans))
      )
    )
  :trans (behavior ()
    (let ((v1-0 *target*)
          (a1-0 (new 'stack-no-clear 'vector))
          )
      (when v1-0
        (cond
          ((focus-test? v1-0 pilot)
           (let ((a2-1 (handle->process (-> v1-0 pilot vehicle))))
             (vector-copy! a1-0 (-> (the-as vehicle a2-1) root root-prim prim-core world-sphere))
             )
           )
          (else
            (vector-copy! a1-0 (-> v1-0 control trans))
            (+! (-> a1-0 y) 12288.0)
            )
          )
        (vector-! a1-0 a1-0 (-> self root trans))
        (let ((a0-12 (-> self root quat)))
          (when (desert-chase-ring-cleared? (-> a0-12 vec) a1-0 self)
            (if (-> self is-final?)
                (sound-play "ring-final")
                (sound-play "ring-pass")
                )
            (send-event (handle->process (-> self taskman)) 'ring-hit)
            (if (nonzero? (-> self part))
                (kill-particles (-> self part))
                )
            (cond
              ((-> self is-final?)
               (if (logtest? (-> *part-group-id-table* 1550 flags) (sp-group-flag sp13))
                   (part-tracker-spawn
                     part-tracker-subsampler
                     :to self
                     :group (-> *part-group-id-table* 1550)
                     :mat-joint (-> self mat)
                     )
                   (part-tracker-spawn part-tracker :to self :group (-> *part-group-id-table* 1550) :mat-joint (-> self mat))
                   )
               )
              ((logtest? (-> *part-group-id-table* 1549 flags) (sp-group-flag sp13))
               (part-tracker-spawn
                 part-tracker-subsampler
                 :to self
                 :group (-> *part-group-id-table* 1549)
                 :mat-joint (-> self mat)
                 )
               )
              (else
                (part-tracker-spawn part-tracker :to self :group (-> *part-group-id-table* 1549) :mat-joint (-> self mat))
                )
              )
            (go-virtual die)
            )
          )
        )
      )
    )
  :code sleep-code
  :post (behavior ()
    (when (time-elapsed? (-> self state-time) (seconds 0.4))
      (cond
        ((-> self is-final?)
         (if (nonzero? (-> self part-final))
             (spawn-from-mat (-> self part-final) (-> self mat))
             )
         )
        (else
          (if (nonzero? (-> self part))
              (spawn-from-mat (-> self part) (-> self mat))
              )
          )
        )
      )
    )
  )

(defstate die (desert-chase-ring)
  :virtual #t
  :code (behavior ()
    (kill-callback (-> *minimap* engine) (-> self minimap))
    (while (-> self child)
      (suspend)
      )
    (go-virtual dormant)
    )
  )

;; og:preserve-this duplicate
; (defmethod run-logic? ((this desert-chase-ring))
;   "Should this process be run? Checked by execute-process-tree."
;   #t
;   )

(defmethod alloc-trsqv! ((this desert-chase-ring))
  (set! (-> this root) (new 'process 'trsqv))
  0
  (none)
  )

(defmethod relocate ((this desert-chase-ring) (offset int))
  (if (nonzero? (-> this part-final))
      (&+! (-> this part-final) offset)
      )
  (call-parent-method this offset)
  )

(defmethod deactivate ((this desert-chase-ring))
  "Make a process dead, clean it up, remove it from the active pool, and return to dead pool."
  (if (nonzero? (-> this part-final))
      (kill-particles (-> this part-final))
      )
  (call-parent-method this)
  (none)
  )

(defmethod init-from-entity! ((this desert-chase-ring) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (set-ring-particle-texture)
  (alloc-trsqv! this)
  (process-drawable-from-entity! this arg0)
  (set! (-> this ring-radius) (res-lump-float arg0 'ring-radius :default 24576.0))
  (quaternion->matrix (-> this mat) (-> this root quat))
  (vector-copy! (-> this mat trans) (-> this root trans))
  (set! (-> this part) (create-launch-control (-> *part-group-id-table* 1547) this))
  (set! (-> this part-final) (create-launch-control (-> *part-group-id-table* 1548) this))
  (logclear! (-> this mask) (process-mask actor-pause))
  (set! (-> this alt-actor) (entity-actor-lookup (-> this entity) 'alt-actor 0))
  (set! (-> this is-final?) #f)
  (go (method-of-object this dormant))
  )

(deftype spirit (process-drawable)
  ((part-subsampler   sparticle-subsampler)
   (sound-id          sound-id)
   (sound-id-2        sound-id)
   (play-pixie?       symbol)
   (goal-part         sparticle-launch-control)
   (draw-start-goal?  symbol)
   )
  (:state-methods
    idle
    dormant
    explode
    )
  )


(defstate explode (spirit)
  :virtual #t
  :enter (behavior ()
    (cond
      ((logtest? (-> *part-group-id-table* 1546 flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
       (part-tracker-spawn part-tracker-subsampler :to self :group (-> *part-group-id-table* 1546))
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker :to self :group (-> *part-group-id-table* 1546))
        )
      )
    )
  :code sleep-code
  )

(defstate dormant (spirit)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trans)
       (let ((v1-1 (the-as object (-> block param 0)))
             (v0-0 (the-as object (-> self root trans)))
             )
         (set! (-> (the-as vector v0-0) quad) (-> (the-as vector v1-1) quad))
         v0-0
         )
       )
      (('play-pixie)
       (go-virtual idle)
       )
      (('goal)
       (go-virtual explode)
       )
      )
    )
  :trans (behavior ()
    (sound-play "magic-trail" :id (-> self sound-id-2))
    (spawn (-> self goal-part) (-> self root trans))
    )
  :code sleep-code
  )

(defstate idle (spirit)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trans)
       (let ((v1-1 (the-as object (-> block param 0)))
             (v0-0 (the-as object (-> self root trans)))
             )
         (set! (-> (the-as vector v0-0) quad) (-> (the-as vector v1-1) quad))
         v0-0
         )
       )
      (('play-pixie)
       (set! (-> self play-pixie?) #t)
       (set! (-> self draw-start-goal?) #f)
       #f
       )
      (('goal-state)
       (set! (-> self draw-start-goal?) #t)
       (go-virtual dormant)
       )
      )
    )
  :trans (behavior ()
    (spawn (-> self part) (-> self root trans))
    (init-with-vec! (-> self part-subsampler) (-> self root trans))
    (sound-play "magic-trail" :id (-> self sound-id-2))
    (sound-play-by-name
      (static-sound-name "flying-pixie")
      (-> self sound-id)
      1024
      (the int (* 1524.0 (doppler-pitch-shift (-> self root trans) (-> self root transv))))
      0
      (sound-group)
      #t
      )
    )
  :code sleep-code
  )

;; WARN: Return type mismatch process-drawable vs spirit.
(defmethod relocate ((this spirit) (offset int))
  (if (nonzero? (-> this part-subsampler))
      (&+! (-> this part-subsampler) offset)
      )
  (if (nonzero? (-> this goal-part))
      (&+! (-> this goal-part) offset)
      )
  (the-as spirit ((method-of-type process-drawable relocate) this offset))
  )

(defmethod deactivate ((this spirit))
  "Make a process dead, clean it up, remove it from the active pool, and return to dead pool."
  (if (nonzero? (-> this goal-part))
      (kill-particles (-> this goal-part))
      )
  ((method-of-type process-drawable deactivate) this)
  (none)
  )

(defbehavior spirit-init-by-other spirit ((arg0 vector))
  (set! (-> self play-pixie?) #f)
  (set! (-> self root) (new 'process 'trsqv))
  (vector-copy! (-> self root trans) arg0)
  (set! (-> self sound-id) (new-sound-id))
  (set! (-> self sound-id-2) (new-sound-id))
  (set! (-> self part) (create-launch-control (-> *part-group-id-table* 1541) self))
  self
  (set! (-> self part-subsampler)
        (new 'process 'sparticle-subsampler *sp-particle-system-2d* (-> *part-id-table* 5117) 3.0)
        )
  (set! (-> self goal-part) (create-launch-control (-> *part-group-id-table* 1540) self))
  (set! (-> self draw-start-goal?) #t)
  (go-virtual dormant)
  )

(deftype hud-spider-killed (hud-goal)
  ()
  )


(defmethod draw ((this hud-spider-killed))
  (set-hud-piece-position! (-> this sprites 0) 65 125)
  (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) 0 -8)
  (set-as-offset-from! (the-as hud-sprite (-> this strings 1 pos)) (-> this sprites 0 pos) 0 -40)
  ((method-of-type hud draw) this)
  0
  (none)
  )

(defmethod update-values! ((this hud-spider-killed))
  (set! (-> this values 0 target) (the int (-> *game-info* score)))
  ((method-of-type hud update-values!) this)
  0
  (none)
  )

(defmethod init-callback ((this hud-spider-killed))
  (set! (-> this gui-id)
        (add-process *gui-control* this (gui-channel hud-upper-center-2) (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-scoreboard-01 level-default-minimap)))
  (set! (-> this sprites 0 scale-x) 1.2)
  (set! (-> this sprites 0 flags) (hud-sprite-flags hsf3))
  (alloc-string-if-needed this 0)
  (set! (-> this strings 0 scale) 0.5)
  (set! (-> this strings 0 flags) (font-flags kerning middle large))
  (set! (-> this strings 0 color) (font-color red))
  (alloc-string-if-needed this 1)
  (set! (-> this strings 1 scale) 0.75)
  (set! (-> this strings 1 flags) (font-flags kerning middle large))
  (set! (-> this strings 1 color) (font-color red))
  (let ((s5-0 format)
        (gp-1 (clear (-> this strings 1 text)))
        (s4-0 "~S")
        )
    (format (clear *temp-string*) (lookup-text! *common-text* (text-id kills) #f))
    (s5-0 gp-1 s4-0 *temp-string*)
    )
  0
  (none)
  )

(deftype task-manager-bbush-egg-spider (task-manager)
  ((actor-group        (pointer actor-group))
   (actor-group-count  int32)
   (goal-score         uint32)
   (hud-score          handle)
   (hud-goal           handle)
   )
  (:methods
    (task-manager-bbush-egg-spider-method-32 (_type_) none)
    )
  )


(defstate resolution (task-manager-bbush-egg-spider)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :code (behavior ()
    (local-vars (v1-34 object))
    (when (logtest? (-> self info mask) (task-manager-mask resolution-scene))
      (let ((gp-1 (ppointer->handle (process-spawn
                                      scene-player
                                      :init scene-player-init
                                      (-> self info resolution-scene)
                                      #t
                                      (-> self info resolution-scene-continue)
                                      :name "scene-player"
                                      )
                                    )
                  )
            )
        (while (handle->process (the-as handle gp-1))
          (suspend)
          )
        )
      )
    (task-manager-method-27 self)
    (give *game-info* 'skill (the float (-> self info user-count)) (the-as handle #f))
    (until (< (* 45 (-> self info user-count)) (- (current-time) (-> self state-time)))
      (suspend)
      )
    (let ((gp-2 (-> self info on-complete)))
      (if gp-2
          (script-eval gp-2)
          )
      )
    (task-node-close! (-> self info final-node) 'event)
    (remove-setting! 'allow-progress)
    (while (begin
             (set! v1-34 (or (handle->process (-> self arrow)) (begin
                                                                 (countdown (v1-35 4)
                                                                   (when (handle->process (-> self hud v1-35))
                                                                     (set! v1-34 #t)
                                                                     (goto cfg-41)
                                                                     )
                                                                   )
                                                                 #f
                                                                 )
                             )
                   )
             (label cfg-41)
             v1-34
             )
      (suspend)
      )
    )
  )

(defmethod task-manager-method-25 ((this task-manager-bbush-egg-spider))
  (dotimes (s5-0 44)
    (let ((s4-0 (-> *vehicle-info* handle-by-vehicle-type s5-0)))
      (when (handle->process s4-0)
        (send-event (handle->process s4-0) 'ignore-damage #f)
        (send-event (handle->process s4-0) 'ignore-impulse #f)
        )
      )
    )
  ((method-of-type task-manager task-manager-method-25) this)
  (none)
  )

(defmethod task-manager-bbush-egg-spider-method-32 ((this task-manager-bbush-egg-spider))
  (set-setting! 'extra-bank '((desert2 bbush2)) 0.0 0)
  (set-setting! 'music 'despider 0.0 0)
  0
  (none)
  )

;; WARN: Return type mismatch float vs none.
(defmethod set-time-limit ((this task-manager-bbush-egg-spider))
  (local-vars (sv-16 res-tag))
  (let ((t9-0 (method-of-type task-manager set-time-limit)))
    (t9-0 this)
    )
  (set-setting! 'airlock #f 0.0 0)
  (set-setting! 'string-max-height 'abs (meters 8) 0)
  (set-setting! 'string-max-length 'abs (meters 24) 0)
  (set-setting! 'string-min-height 'abs (meters 6) 0)
  (set-setting! 'string-min-length 'abs (meters 20) 0)
  (adjust-player-ammo 5000.0 (pickup-type ammo-yellow))
  (adjust-player-ammo 5000.0 (pickup-type ammo-red))
  (adjust-player-ammo 5000.0 (pickup-type ammo-blue))
  (adjust-player-ammo 5000.0 (pickup-type ammo-dark))
  (set-setting! 'pilot #f 0.0 0)
  (set-setting! 'gun-special-mode #t 0.0 0)
  (task-manager-bbush-egg-spider-method-32 this)
  (let ((s5-0 (entity-by-name "tmanager-4")))
    (when s5-0
      (set! (-> this entity) (the-as entity-actor s5-0))
      (set! (-> this goal-score)
            (res-lump-value s5-0 'goal-score uint :default (the-as uint128 80) :time -1000000000.0)
            )
      (set! sv-16 (new 'static 'res-tag))
      (let ((v1-20 (res-lump-data s5-0 'actor-groups pointer :tag-ptr (& sv-16))))
        (cond
          ((and v1-20 (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) v1-20))
           )
          (else
            (format 0 "ERROR: ~s: entity missing actor-group!~%" (game-task->string (-> this node-info task)))
            )
          )
        )
      )
    )
  (set! (-> this hud-score)
        (ppointer->handle
          (process-spawn hud-spider-killed :init hud-init-by-other :name "hud-spider-killed" :to this)
          )
        )
  (set! (-> this hud-goal)
        (ppointer->handle (process-spawn hud-goal :init hud-init-by-other :name "hud-goal" :to this))
        )
  (set! (-> *game-info* goal) (the float (-> this goal-score)))
  (set! (-> *game-info* score) 0.0)
  (none)
  )

(defstate active (task-manager-bbush-egg-spider)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('goal)
       (send-event self 'complete)
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set-time! (-> self start-time))
    (set! (-> self time-limit) (seconds 60))
    )
  :trans (behavior ()
    (let ((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) 'count-death)
      (let* ((t9-0 send-event-function)
             (v1-5 (-> self actor-group 0 data 0 actor))
             (v1-7 (t9-0
                     (if v1-5
                         (-> v1-5 extra process)
                         )
                     a1-0
                     )
                   )
             )
        ;; og:preserve-this fix hud kill counter
        (set! (-> *game-info* score) (the float (the int v1-7)))
        ;; og:preserve-this fix original game bug
        (if (>= v1-7 (-> self goal-score))
            (send-event self 'complete)
            )
        )
      )
    (hud-timer-handler self)
    )
  :code (behavior ()
    (set-setting! 'minimap 'clear 0.0 (minimap-flag minimap))
    (until #f
      (dotimes (v1-2 44)
        (let ((gp-0 (-> *vehicle-info* handle-by-vehicle-type v1-2)))
          (when (handle->process gp-0)
            (send-event (handle->process gp-0) 'ignore-damage #t)
            (send-event (handle->process gp-0) 'ignore-impulse #t)
            (goto cfg-27)
            )
          )
        )
      (suspend)
      )
    #f
    (until #f
      (label cfg-27)
      (suspend)
      )
    #f
    )
  )

(deftype task-manager-bbush-spirit-chase (task-manager)
  ((actor-group             (pointer actor-group))
   (actor-group-count       int32)
   (path-pos                float)
   (trans                   vector  :inline)
   (touched                 symbol)
   (spirit                  handle)
   (current-curve-distance  float)
   (current-curve-length    float)
   (min-spirit-vel          float)
   (current-spirit-vel      float)
   (high-spirit-vel         float)
   (fail-radius             float)
   (chase-distance          float)
   (start-offset-vel        float)
   (sound-id                sound-id)
   )
  (:methods
    (get-entity-name (_type_) string)
    (task-manager-bbush-spirit-chase-method-33 (_type_) float)
    (task-manager-bbush-spirit-chase-method-34 (_type_) float)
    (set-sbanks (_type_) none)
    )
  )


(defstate resolution (task-manager-bbush-spirit-chase)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :code (behavior ()
    (local-vars (v1-38 object))
    (when (logtest? (-> self info mask) (task-manager-mask resolution-scene))
      (let ((gp-1
              (ppointer->handle
                (process-spawn
                  scene-player
                  :init scene-player-init
                  (-> self info resolution-scene)
                  #t
                  (-> self info resolution-scene-continue)
                  :name "scene-player"
                  )
                )
              )
            )
        (while (handle->process (the-as handle gp-1))
          (suspend)
          )
        )
      )
    (task-manager-method-27 self)
    (set-time! (-> self state-time))
    (give *game-info* 'skill (the float (-> self info user-count)) (the-as handle #f))
    (set-action!
      *gui-control*
      (gui-action play)
      (-> self sound-id)
      (gui-channel none)
      (gui-action none)
      (the-as string #f)
      (the-as (function gui-connection symbol) #f)
      (the-as process #f)
      )
    (until (< (* 45 (-> self info user-count)) (- (current-time) (-> self state-time)))
      (suspend)
      )
    (let ((gp-2 (-> self info on-complete)))
      (if gp-2
          (script-eval gp-2)
          )
      )
    (task-node-close! (-> self info final-node) 'event)
    (remove-setting! 'allow-progress)
    (while (begin
             (set! v1-38 (or (handle->process (-> self arrow)) (begin
                                                                 (countdown (v1-39 4)
                                                                   (when (handle->process (-> self hud v1-39))
                                                                     (set! v1-38 #t)
                                                                     (goto cfg-41)
                                                                     )
                                                                   )
                                                                 #f
                                                                 )
                             )
                   )
             (label cfg-41)
             v1-38
             )
      (suspend)
      )
    )
  )

(defmethod set-sbanks ((this task-manager-bbush-spirit-chase))
  (cond
    ((= (level-status? *level* 'waswide #f) 'active)
     (set-setting! 'extra-bank '((wascity3 bbush1)) 0.0 0)
     (set-setting! 'music 'waspirit 0.0 0)
     )
    (else
      (set-setting! 'extra-bank '((desert2 bbush1)) 0.0 0)
      (set-setting! 'music 'despirit 0.0 0)
      )
    )
  0
  (none)
  )

(defmethod get-entity-name ((this task-manager-bbush-spirit-chase))
  "tmanager-5"
  )

(defmethod task-manager-bbush-spirit-chase-method-33 ((this task-manager-bbush-spirit-chase))
  4096.0
  )

(defmethod task-manager-bbush-spirit-chase-method-34 ((this task-manager-bbush-spirit-chase))
  655360.0
  )

;; WARN: Return type mismatch object vs none.
(defmethod set-time-limit ((this task-manager-bbush-spirit-chase))
  (local-vars (sv-16 res-tag))
  (let ((t9-0 (method-of-type task-manager set-time-limit)))
    (t9-0 this)
    )
  (set-setting! 'airlock #f 0.0 0)
  (set! (-> this path-pos) 0.0)
  (set! (-> this touched) #f)
  (set! (-> this spirit) (ppointer->handle (process-spawn spirit *null-vector* :name "spirit" :to this)))
  (logclear! (-> this mask) (process-mask actor-pause))
  (let ((s5-2 (entity-by-name (get-entity-name this))))
    (when s5-2
      (set! (-> this min-spirit-vel) (res-lump-float s5-2 'min-spirit-vel :default 163840.0))
      (set! (-> this high-spirit-vel) (res-lump-float s5-2 'high-spirit-vel :default 163840.0))
      (set! (-> this fail-radius) (res-lump-float s5-2 'fail-radius :default 655360.0))
      (set! (-> this chase-distance) (res-lump-float s5-2 'chase-distance :default 102400.0))
      (set! (-> this start-offset-vel) (res-lump-float s5-2 'start-offset-vel :default 20480.0))
      (format #t "new-vel: ~f~%" (/ (-> this start-offset-vel) METER_LENGTH))
      (set! (-> this entity) (the-as entity-actor s5-2))
      (set! sv-16 (new 'static 'res-tag))
      (let ((v1-19 (res-lump-data s5-2 'actor-groups pointer :tag-ptr (& sv-16))))
        (cond
          ((and v1-19 (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) v1-19))
           )
          (else
            (format 0 "ERROR: ~s: entity missing actor-group!~%" (game-task->string (-> this node-info task)))
            )
          )
        )
      )
    )
  (set-sbanks this)
  (set! (-> this sound-id) (new 'static 'sound-id))
  (set! (-> this current-spirit-vel) (-> this min-spirit-vel))
  (format #t "min-spirit-vel: ~f~%" (/ (-> this min-spirit-vel) METER_LENGTH))
  (none)
  )

(defstate active (task-manager-bbush-spirit-chase)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('goal)
       (send-event self 'complete)
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set-time! (-> self start-time))
    (set! (-> self time-limit) (seconds 60))
    (set! (-> self current-curve-distance) 1.0)
    (set! (-> self current-curve-distance) 0.0)
    )
  :trans (behavior ()
    (local-vars (sv-240 vector) (sv-256 vector) (sv-272 vector))
    (rlet ((vf0 :class vf)
           (vf1 :class vf)
           (vf2 :class vf)
           )
      (init-vf0-vector)
      (when (nonzero? (-> self actor-group))
        (dotimes (gp-0 (+ (length (-> self actor-group 0)) -1))
          (cond
            ((and (>= (-> self path-pos) (the float gp-0)) (>= (the float (+ gp-0 1)) (-> self path-pos)))
             (let ((v1-7 (-> self actor-group 0 data gp-0))
                   (a1-2 (-> self actor-group 0 data (+ gp-0 1)))
                   )
               (when (and v1-7 a1-2)
                 (let ((s3-0 (-> v1-7 actor))
                       (s5-0 (-> a1-2 actor))
                       (s4-0 (new 'stack 'cubic-curve))
                       )
                   (new 'stack-no-clear 'vector)
                   (when (and s3-0 s5-0)
                     (let ((s2-0 s4-0)
                           (s1-0 (method-of-type cubic-curve cubic-curve-method-9))
                           (s0-0 (-> s3-0 trans))
                           )
                       (set! sv-240 (new 'stack-no-clear 'vector))
                       (let ((v0-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> s3-0 quat)))
                             (f0-3 204800.0)
                             )
                         (.lvf vf1 (&-> v0-1 quad))
                         (let ((v1-14 f0-3))
                           (.mov vf2 v1-14)
                           )
                         )
                       (.add.x.vf.w vf1 vf0 vf0)
                       (.mul.x.vf.xyz vf1 vf1 vf2)
                       (.svf (&-> sv-240 quad) vf1)
                       (set! sv-256 (-> s5-0 trans))
                       (set! sv-272 (new 'stack-no-clear 'vector))
                       (let ((v0-2 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> s5-0 quat)))
                             (f0-4 204800.0)
                             )
                         (.lvf vf1 (&-> v0-2 quad))
                         (let ((v1-19 f0-4))
                           (.mov vf2 v1-19)
                           )
                         )
                       (.add.x.vf.w vf1 vf0 vf0)
                       (.mul.x.vf.xyz vf1 vf1 vf2)
                       (.svf (&-> sv-272 quad) vf1)
                       (s1-0 s2-0 s0-0 sv-240 sv-256 sv-272)
                       )
                     (set! (-> self current-curve-length) (vector-vector-distance (-> s3-0 trans) (-> s5-0 trans)))
                     (cubic-curve-method-10 s4-0 (-> self trans) (- (-> self path-pos) (the float gp-0)))
                     (cond
                       ((not (time-elapsed? (-> self state-time) (seconds 4)))
                        (let ((f0-9 (+ (vector-length (-> *target* control transv)) (-> self start-offset-vel))))
                          (seek! (-> self current-spirit-vel) f0-9 (* 0.5 (seconds-per-frame) (-> self high-spirit-vel)))
                          )
                        )
                       ((< (vector-vector-distance (target-pos 0) (-> s5-0 trans))
                           (+ (vector-vector-distance (-> self trans) (-> s5-0 trans)) (-> self chase-distance))
                           )
                        (let ((f0-17 (fmax (vector-length (-> *target* control transv)) (-> self high-spirit-vel))))
                          (seek! (-> self current-spirit-vel) (-> self high-spirit-vel) (* 0.5 (seconds-per-frame) f0-17))
                          )
                        )
                       (else
                         (seek!
                           (-> self current-spirit-vel)
                           (-> self min-spirit-vel)
                           (* 0.5 (seconds-per-frame) (-> self high-spirit-vel))
                           )
                         )
                       )
                     )
                   )
                 )
               )
             )
            (else
              (set! (-> self current-curve-distance) 0.0)
              )
            )
          )
        )
      (send-event (handle->process (-> self spirit)) 'trans (-> self trans))
      (cond
        ((-> self touched)
         (+! (-> self current-curve-distance) (* (-> self current-spirit-vel) (seconds-per-frame)))
         (+! (-> self path-pos) (/ (-> self current-curve-distance) (-> self current-curve-length)))
         (when (< (the float (+ (length (-> self actor-group 0)) -1)) (-> self path-pos))
           (set! (-> self path-pos) (the float (+ (length (-> self actor-group 0)) -1)))
           (send-event (handle->process (-> self spirit)) 'goal-state)
           (set! (-> self sound-id)
                 (add-process *gui-control* self (gui-channel bbush) (gui-action queue) "miss001" -99.0 0)
                 )
           (when (< (vector-vector-distance (target-pos 0) (-> self trans)) 20480.0)
             (send-event (handle->process (-> self spirit)) 'goal)
             (send-event self 'complete)
             )
           )
         (let ((f0-36 (-> self fail-radius)))
           (if (< (* f0-36 f0-36) (vector-vector-distance-squared (target-pos 0) (-> self trans)))
               (send-event self 'fail)
               )
           )
         )
        (else
          (set-time! (-> self state-time))
          (let ((f0-39 (vector-vector-distance-squared (target-pos 0) (-> self trans)))
                (f1-23 20480.0)
                )
            (when (< f0-39 (* f1-23 f1-23))
              (set! (-> self touched) #t)
              (sound-play "start-pickup")
              (send-event (handle->process (-> self spirit)) 'play-pixie)
              )
            )
          (if (< 409600.0 (vector-vector-distance (target-pos 0) (-> self trans)))
              (send-event self 'fail)
              )
          )
        )
      )
    )
  :code (behavior ()
    (until #f
      (suspend)
      )
    #f
    )
  )

(deftype task-manager-bbush-spirit-chase-2 (task-manager-bbush-spirit-chase)
  ()
  )


(defmethod get-entity-name ((this task-manager-bbush-spirit-chase-2))
  (format 0 "tag1~%")
  "t-manager-4"
  )

(defmethod task-manager-bbush-spirit-chase-method-33 ((this task-manager-bbush-spirit-chase-2))
  18.0
  )

(defmethod task-manager-bbush-spirit-chase-method-34 ((this task-manager-bbush-spirit-chase-2))
  163840.0
  )

(deftype task-manager-bbush-spirit-chase-3 (task-manager-bbush-spirit-chase)
  ()
  )


(defmethod get-entity-name ((this task-manager-bbush-spirit-chase-3))
  (format 0 "tag1~%")
  "t-manager-5"
  )

(defmethod set-sbanks ((this task-manager-bbush-spirit-chase-3))
  (set-setting! 'city-sound '(citybb1) 0.0 2)
  (set-setting! 'music 'ctysprit 0.0 0)
  0
  (none)
  )

(defmethod task-manager-bbush-spirit-chase-method-33 ((this task-manager-bbush-spirit-chase-3))
  94208.0
  )

(defmethod task-manager-bbush-spirit-chase-method-34 ((this task-manager-bbush-spirit-chase-3))
  163840.0
  )

(deftype bb-score-a-pickup (process-hidden)
  ()
  )


(deftype bb-score-b-pickup (process-hidden)
  ()
  )


(deftype bb-score-c-pickup (process-hidden)
  ()
  )


(defun-debug bb-score-type->string ((arg0 bb-score-type))
  (case arg0
    (((bb-score-type large))
     "large"
     )
    (((bb-score-type small))
     "small"
     )
    (((bb-score-type medium))
     "medium"
     )
    (else
      "*unknown*"
      )
    )
  )

(deftype score-drop (process-drawable)
  ((src                  vector      :inline)
   (dst                  vector      :inline)
   (pickup-radius        float)
   (score                uint32)
   (score-pickup-radius  float)
   (bb-score-type        bb-score-type)
   (traj                 trajectory  :inline)
   )
  (:state-methods
    idle
    dormant
    die
    )
  )


(defstate dormant (score-drop)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trigger)
       (vector-copy! (-> self src) (the-as vector (-> block param 0)))
       (vector-copy! (-> self dst) (-> self root trans))
       (setup-from-to-duration! (-> self traj) (-> self src) (-> self dst) 300.0 -4.551111)
       (go-virtual idle)
       )
      )
    )
  :trans (behavior ()
    (add-debug-sphere #t (bucket-id debug) (-> self dst) (meters 1) *color-green*)
    (add-debug-sphere #t (bucket-id debug) (-> self root trans) (meters 2) *color-red*)
    )
  :code sleep-code
  )

(defstate idle (score-drop)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v0-0 (-> self src quad)))
      (set! (-> self root trans quad) v0-0)
      )
    )
  :trans (behavior ()
    (spawn (-> self part) (-> self root trans))
    (/ (the float (- (current-time) (-> self state-time))) (-> self traj time))
    (let ((f0-3 (vector-vector-distance-squared (target-pos 0) (-> self root trans)))
          (f1-1 (-> self pickup-radius))
          )
      (when (< f0-3 (* f1-1 f1-1))
        (send-event (ppointer->process (-> self parent)) 'score (-> self score))
        (case (-> self bb-score-type)
          (((bb-score-type small))
           (sound-play "small-pickup")
           )
          (((bb-score-type medium))
           (sound-play "medium-pickup")
           )
          (((bb-score-type large))
           (sound-play "large-pickup")
           )
          )
        (go-virtual die)
        )
      )
    )
  :code (behavior ()
    (until #f
      (compute-trans-at-time
        (-> self traj)
        (fmin (the float (- (current-time) (-> self state-time))) (-> self traj time))
        (-> self root trans)
        )
      (suspend)
      )
    #f
    )
  :post ja-post
  )

(defstate die (score-drop)
  :virtual #t
  :code (behavior ()
    (cleanup-for-death self)
    )
  )

(defmethod deactivate ((this score-drop))
  "Make a process dead, clean it up, remove it from the active pool, and return to dead pool."
  (if (nonzero? (-> this part))
      (kill-particles (-> this part))
      )
  ((method-of-type process-drawable deactivate) this)
  (none)
  )

;; WARN: Return type mismatch entity-perm-status vs object.
(defmethod init-from-entity! ((this score-drop) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (process-entity-status! this (entity-perm-status dead) #t)
  )

(defbehavior score-drop-init-by-other score-drop ((arg0 entity-actor))
  (process-entity-set! self arg0)
  (set! (-> self root) (new 'process 'trsqv))
  (process-drawable-from-entity! self arg0)
  (logclear! (-> self mask) (process-mask actor-pause))
  (cond
    ((= (-> arg0 etype) bb-score-a-pickup)
     (set! (-> self part) (create-launch-control (-> *part-group-id-table* 1545) self))
     (set! (-> self bb-score-type) (bb-score-type small))
     0
     )
    ((= (-> arg0 etype) bb-score-b-pickup)
     (set! (-> self part) (create-launch-control (-> *part-group-id-table* 1544) self))
     (set! (-> self bb-score-type) (bb-score-type medium))
     )
    (else
      (set! (-> self part) (create-launch-control (-> *part-group-id-table* 1543) self))
      (set! (-> self bb-score-type) (bb-score-type large))
      )
    )
  (set! (-> self pickup-radius) (res-lump-float arg0 'score-pickup-radius :default 4096.0))
  (format 0 "score-radius: ~f~%" (-> self pickup-radius))
  (set! (-> self score)
        (res-lump-value arg0 'score-amount uint :default (the-as uint128 100) :time -1000000000.0)
        )
  (go-virtual dormant)
  )

(deftype task-manager-bbush-spirit-drop (task-manager)
  ((actor-group                   (pointer actor-group))
   (actor-group-count             int32)
   (path-pos                      float)
   (trans                         vector  :inline)
   (touched                       symbol)
   (spirit                        handle)
   (score-drop-handles            handle  64)
   (score-drop-num                int32)
   (current-curve-distance        float)
   (current-curve-length          float)
   (goal-score                    uint32)
   (current-score                 uint32)
   (score-drop-activation-radius  float)
   (min-spirit-vel                float)
   (high-spirit-vel               float)
   (current-spirit-vel            float)
   (fail-radius                   float)
   (hud-score                     handle)
   (hud-goal                      handle)
   )
  (:methods
    (get-entity-name (_type_) string)
    (task-manager-bbush-spirit-drop-method-33 (_type_) float)
    (task-manager-bbush-spirit-drop-method-34 (_type_) float)
    (task-manager-bbush-spirit-drop-method-35 (_type_) int)
    (send-trigger (_type_) symbol)
    (spawn-drops (_type_) symbol)
    (set-sbanks (_type_) none)
    )
  )


(defstate resolution (task-manager-bbush-spirit-drop)
  :virtual #t
  :event task-manager-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :code (behavior ()
    (local-vars (v1-34 object))
    (when (logtest? (-> self info mask) (task-manager-mask resolution-scene))
      (let ((gp-1 (ppointer->handle (process-spawn
                                      scene-player
                                      :init scene-player-init
                                      (-> self info resolution-scene)
                                      #t
                                      (-> self info resolution-scene-continue)
                                      :name "scene-player"
                                      )
                                    )
                  )
            )
        (while (handle->process (the-as handle gp-1))
          (suspend)
          )
        )
      )
    (task-manager-method-27 self)
    (give *game-info* 'skill (the float (-> self info user-count)) (the-as handle #f))
    (until (< (* 45 (-> self info user-count)) (- (current-time) (-> self state-time)))
      (suspend)
      )
    (let ((gp-2 (-> self info on-complete)))
      (if gp-2
          (script-eval gp-2)
          )
      )
    (task-node-close! (-> self info final-node) 'event)
    (remove-setting! 'allow-progress)
    (while (begin
             (set! v1-34 (or (handle->process (-> self arrow)) (begin
                                                                 (countdown (v1-35 4)
                                                                   (when (handle->process (-> self hud v1-35))
                                                                     (set! v1-34 #t)
                                                                     (goto cfg-41)
                                                                     )
                                                                   )
                                                                 #f
                                                                 )
                             )
                   )
             (label cfg-41)
             v1-34
             )
      (suspend)
      )
    )
  )

(defmethod set-sbanks ((this task-manager-bbush-spirit-drop))
  (set-setting! 'extra-bank '((desert2 bbush1) (nest2 bbush1)) 0.0 0)
  (set-setting! 'music 'desring 0.0 0)
  0
  (none)
  )

(defmethod get-entity-name ((this task-manager-bbush-spirit-drop))
  "tmanager-6"
  )

(defmethod task-manager-bbush-spirit-drop-method-33 ((this task-manager-bbush-spirit-drop))
  36.0
  )

(defmethod task-manager-bbush-spirit-drop-method-34 ((this task-manager-bbush-spirit-drop))
  655360.0
  )

(defmethod task-manager-bbush-spirit-drop-method-35 ((this task-manager-bbush-spirit-drop))
  100
  )

(defmethod spawn-drops ((this task-manager-bbush-spirit-drop))
  (when (-> this actor-group 1)
    (set! (-> this score-drop-num) (-> this actor-group 1 length))
    (format 0 "num-drops: ~d~%" (-> this score-drop-num))
    (when (< 1 (-> this actor-group-count))
      (format 0 "activating score-drops~%")
      (dotimes (s5-0 (-> this actor-group 1 length))
        (let ((s4-0 (-> this actor-group 1 data s5-0)))
          (set! (-> this score-drop-handles s5-0)
                (ppointer->handle (process-spawn score-drop (-> s4-0 actor) :name "score-drop" :to this))
                )
          )
        )
      #f
      )
    )
  )

(defmethod send-trigger ((this task-manager-bbush-spirit-drop))
  (dotimes (s5-0 (-> this score-drop-num))
    (when (handle->process (-> this score-drop-handles s5-0))
      (let ((s4-0 (-> this score-drop-handles s5-0 process 0)))
        (if (< (vector-vector-distance (-> (the-as spirit s4-0) root trans) (-> this trans))
               (-> this score-drop-activation-radius)
               )
            (send-event s4-0 'trigger (-> this trans))
            )
        )
      )
    )
  #f
  )

;; WARN: Return type mismatch object vs none.
(defmethod set-time-limit ((this task-manager-bbush-spirit-drop))
  (local-vars (sv-16 res-tag))
  (let ((t9-0 (method-of-type task-manager set-time-limit)))
    (t9-0 this)
    )
  (set-setting! 'airlock #f 0.0 0)
  (set! (-> this path-pos) 0.0)
  (set! (-> this touched) #f)
  (set! (-> this spirit) (ppointer->handle (process-spawn spirit *null-vector* :name "spirit" :to this)))
  (let ((s5-2 (entity-by-name (get-entity-name this))))
    (when s5-2
      (set! (-> this entity) (the-as entity-actor s5-2))
      (set! (-> this goal-score)
            (res-lump-value s5-2 'goal-score uint :default (the-as uint128 200) :time -1000000000.0)
            )
      (set! (-> this score-drop-activation-radius)
            (res-lump-float s5-2 'score-drop-activation-radius :default 409600.0)
            )
      (format 0 "activation-radius: ~f~%" (-> this score-drop-activation-radius))
      (set! (-> this min-spirit-vel) (res-lump-float s5-2 'min-spirit-vel :default 163840.0))
      (set! (-> this high-spirit-vel) (res-lump-float s5-2 'high-spirit-vel :default 163840.0))
      (set! (-> this fail-radius) (res-lump-float s5-2 'fail-radius :default 655360.0))
      (set! sv-16 (new 'static 'res-tag))
      (let ((v1-16 (res-lump-data s5-2 'actor-groups pointer :tag-ptr (& sv-16))))
        (cond
          ((and v1-16 (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) v1-16))
           (spawn-drops this)
           )
          (else
            (format 0 "ERROR: ~s: entity missing actor-group!~%" (game-task->string (-> this node-info task)))
            )
          )
        )
      )
    )
  (if *cty-attack-controller*
      (logior! (-> *cty-attack-controller* target-attacker flags) (city-attacker-info-flag cai3))
      )
  (set-sbanks this)
  (set! (-> this hud-score)
        (ppointer->handle (process-spawn hud-big-score :init hud-init-by-other :name "hud-big-score" :to this))
        )
  (set! (-> this hud-goal)
        (ppointer->handle (process-spawn hud-goal :init hud-init-by-other :name "hud-goal" :to this))
        )
  (set! (-> *game-info* goal) (the float (-> this goal-score)))
  (set! (-> *game-info* score) 0.0)
  (set! (-> this current-score) (the-as uint 0))
  (set! (-> this current-spirit-vel) (-> this min-spirit-vel))
  (format 0 "num drops: ~d~%" (length (-> this score-drop-handles)))
  (none)
  )

(defstate active (task-manager-bbush-spirit-drop)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('goal)
       (send-event self 'complete)
       )
      (('score)
       (let* ((v1-3 (-> block param 0))
              (v0-0 (the-as object (+ (-> self current-score) v1-3)))
              )
         (set! (-> self current-score) (the-as uint v0-0))
         v0-0
         )
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set-time! (-> self start-time))
    (set! (-> self time-limit) (seconds 60))
    (set! (-> self current-curve-distance) 1.0)
    (set! (-> self current-curve-distance) 0.0)
    )
  :exit (behavior ()
    (if *cty-attack-controller*
        (logclear! (-> *cty-attack-controller* target-attacker flags) (city-attacker-info-flag cai3))
        )
    )
  :trans (behavior ()
    (local-vars (sv-240 vector) (sv-256 vector) (sv-272 vector))
    (rlet ((vf0 :class vf)
           (vf1 :class vf)
           (vf2 :class vf)
           )
      (init-vf0-vector)
      (set! (-> *game-info* score) (the float (-> self current-score)))
      (when (nonzero? (-> self actor-group))
        (dotimes (gp-0 (+ (length (-> self actor-group 0)) -1))
          (cond
            ((and (>= (-> self path-pos) (the float gp-0)) (>= (the float (+ gp-0 1)) (-> self path-pos)))
             (let ((v1-9 (-> self actor-group 0 data gp-0))
                   (a1-2 (-> self actor-group 0 data (+ gp-0 1)))
                   )
               (when (and v1-9 a1-2)
                 (let ((s3-0 (-> v1-9 actor))
                       (s5-0 (-> a1-2 actor))
                       (s4-0 (new 'stack 'cubic-curve))
                       )
                   (new 'stack-no-clear 'vector)
                   (when (and s3-0 s5-0)
                     (let ((s2-0 s4-0)
                           (s1-0 (method-of-type cubic-curve cubic-curve-method-9))
                           (s0-0 (-> s3-0 trans))
                           )
                       (set! sv-240 (new 'stack-no-clear 'vector))
                       (let ((v0-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> s3-0 quat)))
                             (f0-5 204800.0)
                             )
                         (.lvf vf1 (&-> v0-1 quad))
                         (let ((v1-16 f0-5))
                           (.mov vf2 v1-16)
                           )
                         )
                       (.add.x.vf.w vf1 vf0 vf0)
                       (.mul.x.vf.xyz vf1 vf1 vf2)
                       (.svf (&-> sv-240 quad) vf1)
                       (set! sv-256 (-> s5-0 trans))
                       (set! sv-272 (new 'stack-no-clear 'vector))
                       (let ((v0-2 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> s5-0 quat)))
                             (f0-6 204800.0)
                             )
                         (.lvf vf1 (&-> v0-2 quad))
                         (let ((v1-21 f0-6))
                           (.mov vf2 v1-21)
                           )
                         )
                       (.add.x.vf.w vf1 vf0 vf0)
                       (.mul.x.vf.xyz vf1 vf1 vf2)
                       (.svf (&-> sv-272 quad) vf1)
                       (s1-0 s2-0 s0-0 sv-240 sv-256 sv-272)
                       )
                     (set! (-> self current-curve-length) (vector-vector-distance (-> s3-0 trans) (-> s5-0 trans)))
                     (cubic-curve-method-10 s4-0 (-> self trans) (- (-> self path-pos) (the float gp-0)))
                     (cond
                       ((< (vector-vector-distance (target-pos 0) (-> s5-0 trans))
                           (+ 102400.0 (vector-vector-distance (-> self trans) (-> s5-0 trans)))
                           )
                        (let ((f0-13 (fmax (vector-length (-> *target* control transv)) (-> self high-spirit-vel))))
                          (seek! (-> self current-spirit-vel) (-> self high-spirit-vel) (* 0.5 (seconds-per-frame) f0-13))
                          )
                        )
                       (else
                         (seek!
                           (-> self current-spirit-vel)
                           (-> self min-spirit-vel)
                           (* 0.5 (seconds-per-frame) (-> self high-spirit-vel))
                           )
                         )
                       )
                     )
                   )
                 )
               )
             )
            (else
              (set! (-> self current-curve-distance) 0.0)
              )
            )
          )
        )
      (send-event (handle->process (-> self spirit)) 'trans (-> self trans))
      (send-trigger self)
      (cond
        ((-> self touched)
         (+! (-> self current-curve-distance) (* (-> self current-spirit-vel) (seconds-per-frame)))
         (+! (-> self path-pos) (/ (-> self current-curve-distance) (-> self current-curve-length)))
         (when (< (the float (+ (length (-> self actor-group 0)) -1)) (-> self path-pos))
           (set! (-> self path-pos) (the float (+ (length (-> self actor-group 0)) -1)))
           (send-event self 'fail)
           )
         (if (< (-> self fail-radius) (vector-vector-distance (target-pos 0) (-> self trans)))
             (send-event self 'fail)
             )
         (if (or (< (-> self goal-score) (-> self current-score)) (= (-> self current-score) (-> self goal-score)))
             (send-event self 'complete)
             )
         )
        (else
          (let ((f0-32 (vector-vector-distance-squared (target-pos 0) (-> self trans)))
                (f1-17 20480.0)
                )
            (when (< f0-32 (* f1-17 f1-17))
              (set! (-> self touched) #t)
              (sound-play "start-pickup")
              )
            )
          )
        )
      )
    )
  :code (behavior ()
    (set-setting! 'minimap 'clear 0.0 (minimap-flag minimap))
    (until #f
      (suspend)
      )
    #f
    )
  )
