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

;; name: desert-chase.gc
;; name in dgo: desert-chase
;; dgos: DESCHASE

;; DECOMP BEGINS

(deftype deschase-point (structure)
  ((pos     vector      :inline)
   (quat    quaternion  :inline)
   (i-node  int8        :overlay-at (-> pos data 3))
   )
  )


(define *stronghold-inside-point* (new 'static 'vector :x 6253938.5 :y 99123.2 :z 12145754.0 :w 1.0))

(define *stronghold-vehicle-stop-point* (new 'static 'vector :x 6413203.5 :y 103606.27 :z 12111851.0 :w 1.0))

(define *stronghold-player-goto-point* (new 'static 'vector :x 6321789.5 :y 99123.2 :z 12098191.0 :w 1.0))

(define *stronghold-marauder-start* (new 'static 'boxed-array :type deschase-point
                                      (new 'static 'deschase-point
                                        :pos (new 'static 'vector :x 6207577.5 :y 159539.2 :z 11966325.0 :w 1.0)
                                        :quat (new 'static 'quaternion :x -0.0002 :y -0.1364 :w -0.9906)
                                        )
                                      (new 'static 'deschase-point
                                        :pos (new 'static 'vector :x 6395575.0 :y 159329.08 :z 12035728.0 :w 1.0)
                                        :quat (new 'static 'quaternion :y -0.3977 :w 0.9174)
                                        )
                                      (new 'static 'deschase-point
                                        :pos (new 'static 'vector :x 6444253.0 :y 159329.08 :z 12226157.0 :w 1.0)
                                        :quat (new 'static 'quaternion :y 0.7455 :w -0.6664)
                                        )
                                      (new 'static 'deschase-point
                                        :pos (new 'static 'vector :x 6297671.5 :y 158481.2 :z 12361336.0 :w 1.0)
                                        :quat (new 'static 'quaternion :y -0.9791 :w 0.2032)
                                        )
                                      (new 'static 'deschase-point
                                        :pos (new 'static 'vector :x 6063449.5 :y 159329.08 :z 12111502.0 :w 1.0)
                                        :quat (new 'static 'quaternion :y 0.5197 :w 0.8543)
                                        )
                                      )
        )

(define *deschase-catapult-spawn-point*
  (new 'static 'boxed-array :type deschase-point
    (new 'static 'deschase-point
      :pos (new 'static 'vector :x 5243015.0 :y 196608.0 :z 11060786.0 :w 1.0)
      :quat (new 'static 'quaternion :y 0.3797 :w 0.925)
      )
    (new 'static 'deschase-point
      :pos (new 'static 'vector :x 5784936.5 :y 84433.305 :z 10807021.0 :w 1.0)
      :quat (new 'static 'quaternion :y 0.1997 :w 0.9798)
      )
    (new 'static 'deschase-point
      :pos (new 'static 'vector :x 6550656.5 :y 69453.82 :z 10759278.0 :w 1.0)
      :quat (new 'static 'quaternion :y -0.0015 :w 0.9999)
      )
    (new 'static 'deschase-point
      :pos (new 'static 'vector :x 7493730.0 :y 122130.84 :z 10950285.0 :w 1.0)
      :quat (new 'static 'quaternion :y -0.3666 :w 0.9303)
      )
    )
  )

(defpartgroup group-catapult-embers-fire
  :id 454
  :flags (sp0 sp1 sp4)
  :bounds (static-bspherem 0 0 0 1000)
  :parts ((sp-item 1806 :fade-after (meters 10000) :falloff-to (meters 10000) :flags (sp7)))
  )

(defpart 1806
  :init-specs ((:texture (explosion-nebula level-default-sprite))
    (:num 1.0)
    (:x (meters -0.25) (meters 0.25))
    (:y (meters -0.25))
    (:z (meters -0.25) (meters 0.25))
    (:scale-x (meters 2) (meters 0.5))
    (:rot-z (degrees 0) (degrees 3600))
    (:scale-y :copy scale-x)
    (:r 128.0)
    (:g 40.0)
    (:b -64.0 4.0 32.0)
    (:a 128.0 128.0)
    (:scalevel-x (meters -0.02))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.21333334 -0.21333334)
    (:accel-y (meters 0.0016666667) (meters 0.0016666667))
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-0 sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    (:rotate-y (degrees 0))
    )
  )

(deftype v-catapult-shot-embers (metalhead-grenade-shot)
  ((ptracker-proc  handle)
   )
  )


(defstate impact (v-catapult-shot-embers)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('touch 'touched)
       (let ((v1-3 (-> self root root-prim)))
         (set! (-> v1-3 prim-core collide-as) (collide-spec))
         (set! (-> v1-3 prim-core collide-with) (collide-spec))
         )
       0
       (send-event (handle->process (-> self ptracker-proc)) 'draw #f)
       (projectile-event-handler proc argc message block)
       )
      (else
        (projectile-event-handler proc argc message block)
        )
      )
    )
  :code (behavior ()
    (suspend)
    (suspend-for (seconds 3)
      (let ((a1-0 (new 'stack-no-clear 'overlaps-others-params)))
        (set! (-> a1-0 options) (overlaps-others-options))
        (set! (-> a1-0 collide-with-filter) (the-as collide-spec -1))
        (set! (-> a1-0 tlist) *touching-list*)
        (find-overlapping-shapes (-> self root) a1-0)
        )
      )
    (let ((v1-10 (-> self root root-prim)))
      (set! (-> v1-10 prim-core collide-as) (collide-spec))
      (set! (-> v1-10 prim-core collide-with) (collide-spec))
      )
    0
    (while (-> self child)
      (suspend)
      )
    (deactivate self)
    )
  )

(defmethod projectile-method-25 ((this v-catapult-shot-embers))
  (if (nonzero? (-> this part))
      (spawn (-> this part) (-> this root trans))
      )
  0
  (none)
  )

(defmethod projectile-method-26 ((this v-catapult-shot-embers))
  (set! (-> this ptracker-proc)
        (process->handle
          (-> (cond
                ((logtest? (-> group-catapult-embers-fire flags) (sp-group-flag sp13))
                 (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
                 (part-tracker-spawn part-tracker-subsampler :to this :group group-catapult-embers-fire :duration (seconds 3))
                 )
                (else
                  (vector-copy! (-> *launch-matrix* trans) (-> this root trans))
                  (part-tracker-spawn part-tracker :to this :group group-catapult-embers-fire :duration (seconds 3))
                  )
                )
              0
              )
          )
        )
  0
  (none)
  )

(defmethod projectile-method-40 ((this v-catapult-shot-embers))
  512
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod init-proj-settings! ((this v-catapult-shot-embers))
  (set! (-> this attack-mode) 'eco-yellow)
  (set! (-> this blast-radius) 4096.0)
  (set! (-> this max-speed) 135168.0)
  (set! (-> this update-velocity) projectile-update-velocity-add-gravity)
  (set! (-> this move) gren-canister-move)
  (set! (-> this root dynam gravity y) 102400.0)
  (set! (-> this root dynam gravity-length) 102400.0)
  (set! (-> this root dynam gravity-max) 102400.0)
  (let ((f0-5 1092.2667))
    (quaternion-axis-angle! (-> this tumble-quat) 1.0 0.0 0.0 f0-5)
    )
  (set! (-> this part) (create-launch-control group-catapult-embers-fire this))
  (set! (-> this ptracker-proc) (the-as handle #f))
  (none)
  )

(defpartgroup group-catapult-target-glow
  :id 455
  :flags (sp0 sp4)
  :bounds (static-bspherem 0 0 0 20)
  :parts ((sp-item 1807 :flags (sp6 sp7)))
  )

(defpart 1807
  :init-specs ((:texture (glow-soft level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 20))
    (:rot-x (degrees 225))
    (:scale-y (meters 20))
    (:r 128.0)
    (:g 40.0)
    (:b 0.0)
    (:a 0.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-3 glow))
    (:userdata 4096.0)
    (:rotate-y (degrees 0))
    )
  )

(defpartgroup group-catapult-target-scorched-earth
  :id 456
  :flags (sp0 sp1)
  :bounds (static-bspherem 0 0 0 640)
  :parts ((sp-item 1808 :flags (is-3d sp3 sp7)))
  )

(defpart 1808
  :init-specs ((:texture (dirtpuff01 level-default-sprite))
    (:num 16.0)
    (:y (meters 0.1))
    (:z (meters 8))
    (:scale-x (meters 1) (meters 2))
    (:scale-y (meters 5) (meters 5))
    (:r 0.0)
    (:g 0.0)
    (:b 0.0)
    (:a 0.0)
    (:fade-a 0.85333335 0.85333335)
    (:timer (seconds 3))
    (:flags (left-multiply-quat))
    (:next-time (seconds 0.25))
    (:next-launcher 1809)
    (:rotate-y (degrees 0) (degrees 36000))
    )
  )

(defpart 1809
  :init-specs ((:fade-a 0.0) (:next-time (seconds 0.75)) (:next-launcher 1810))
  )

(defpart 1810
  :init-specs ((:fade-a -0.21333334))
  )

(deftype catapult-target (process-drawable)
  ((alpha  float)
   )
  (:state-methods
    idle
    )
  (:methods
    (catapult-target-method-21 (_type_) none)
    )
  )


(defbehavior catapult-target-handler catapult-target ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (local-vars (v0-1 object))
  (case arg2
    (('update)
     (let ((f0-1 (- (-> (the-as vector (-> arg3 param 0)) y) (-> self root trans y))))
       (set! (-> self alpha) (lerp-scale 128.0 0.0 f0-1 0.0 614400.0))
       )
     0
     )
    (('on)
     (set! v0-1 (logclear (-> self draw status) (draw-control-status no-draw)))
     (set! (-> self draw status) (the-as draw-control-status v0-1))
     v0-1
     )
    (('off)
     (set! v0-1 (logior (-> self draw status) (draw-control-status no-draw)))
     (set! (-> self draw status) (the-as draw-control-status v0-1))
     v0-1
     )
    (('die)
     (activate! *camera-smush-control* 2048.0 30 150 1.0 0.8 (-> *display* camera-clock))
     (cond
       ((logtest? (-> group-catapult-target-scorched-earth flags) (sp-group-flag sp13))
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-catapult-target-scorched-earth)
        )
       (else
         (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
         (part-tracker-spawn part-tracker :to *entity-pool* :group group-catapult-target-scorched-earth)
         )
       )
     (let ((gp-2 (quaternion-copy! (new 'stack-no-clear 'quaternion) (-> self root quat)))
           (s5-0 (new 'stack-no-clear 'quaternion))
           (s4-0 (new 'stack-no-clear 'vector))
           )
       (quaternion-rotate-y! gp-2 gp-2 (* 182.04445 (the float (rand-vu-int-count 90))))
       (dotimes (s3-1 4)
         (let ((s2-1 (new 'stack-no-clear 'projectile-init-by-other-params)))
           (quaternion-rotate-y! gp-2 gp-2 16384.0)
           (quaternion-rotate-local-x! s5-0 gp-2 -12743.111)
           (vector-z-quaternion! s4-0 gp-2)
           (vector-normalize! s4-0 40960.0)
           (vector+! s4-0 s4-0 (-> self root trans))
           (set! (-> s2-1 ent) (-> self entity))
           (set! (-> s2-1 charge) 1.0)
           (set! (-> s2-1 options) (projectile-options))
           (logclear! (-> s2-1 options) (projectile-options po14 po15 po16))
           (vector-copy!
             (-> s2-1 pos)
             (vector+! (new 'stack-no-clear 'vector) (-> self root trans) (new 'static 'vector :y 4096.0 :w 1.0))
             )
           (set! (-> s2-1 notify-handle) (the-as handle #f))
           (set! (-> s2-1 owner-handle) (the-as handle #f))
           (set! (-> s2-1 target-handle) (the-as handle #f))
           (set! (-> s2-1 target-pos quad) (the-as uint128 0))
           (set! (-> s2-1 ignore-handle) (process->handle self))
           (let* ((v1-55 *game-info*)
                  (a0-42 (+ (-> v1-55 attack-id) 1))
                  )
             (set! (-> v1-55 attack-id) a0-42)
             (set! (-> s2-1 attack-id) a0-42)
             )
           (set! (-> s2-1 timeout) (seconds 5))
           (set! (-> s2-1 damage) 1.0)
           (logior! (-> s2-1 options) (projectile-options po14))
           (vector-normalize-copy! (-> s2-1 vel) (vector-z-quaternion! s4-0 s5-0) 81920.0)
           (spawn-projectile v-catapult-shot-embers s2-1 (-> self parent 0) *default-dead-pool*)
           )
         )
       )
     (go empty-state)
     )
    )
  )

(defstate idle (catapult-target)
  :virtual #t
  :event catapult-target-handler
  :trans (behavior ()
    (catapult-target-method-21 self)
    )
  :code sleep-code
  )

;; WARN: Return type mismatch object vs none.
(defmethod catapult-target-method-21 ((this catapult-target))
  (set! (-> *part-id-table* 1807 init-specs 2 initial-valuef)
        (lerp-scale 20480.0 32768.0 (- (-> (math-camera-pos) y) (-> this root trans y)) 12288.0 49152.0)
        )
  (set! (-> *part-id-table* 1807 init-specs 8 initial-valuef) (-> this alpha))
  (spawn (-> this part) (-> this root trans))
  (none)
  )

(defbehavior catapult-target-init-by-other catapult-target ((arg0 vector))
  (set! (-> self root) (new 'process 'trsqv))
  (vector-copy! (-> self root trans) arg0)
  (set! (-> self part) (create-launch-control group-catapult-target-glow self))
  (go-virtual idle)
  )

(deftype deschase-vehicle (structure)
  ((handle       handle)
   (wait-timer   time-frame)
   (shot-fired?  symbol)
   )
  :allow-misaligned
  )


(deftype desert-chase-ambush-manager (task-manager)
  ((marauder-nav-mesh    nav-mesh)
   (marauder             handle            5)
   (m-free-list          (array uint8))
   (marauder-count       uint8)
   (total-spawned        uint8)
   (check-timer          time-frame)
   (marauder-entity      entity-actor)
   (h-player-controller  handle)
   (player-moved?        symbol)
   (vehicle-nav-mesh     nav-mesh)
   (vehicle              deschase-vehicle  4 :inline)
   (vehicle-count        uint8)
   (v-free-list          (array uint8))
   (total-veh-spawned    uint8)
   (target-point         vector            4 :inline)
   (last-shot-time       time-frame)
   )
  (:methods
    (spawn-marauder (_type_ deschase-point) none)
    (spawn-v-catapult (_type_ int) handle)
    (fire-catapult-shot (_type_ vector vector) none)
    (desert-chase-ambush-manager-method-35 (_type_ int) none)
    )
  )


;; WARN: Found some very strange gotos. Check result carefully, this is not well tested.
(defbehavior desert-chase-ambush-intro-sequence desert-chase-ambush-manager ()
  (local-vars
    (a0-4 process)
    (a1-0 event-message-block)
    (t9-2 (function process-tree event-message-block object))
    )
  (was-squad-manager-start self)
  (let ((v1-0 *was-squad-control*))
    (set! (-> v1-0 target-count) 3)
    (set! (-> v1-0 reserve-count) 40)
    )
  (label cfg-1)
  (let ((gp-0 (entity-by-name "des-draw-bridge-1")))
    (when (not gp-0)
      (suspend)
      (goto cfg-1)
      )
    (set! (-> *was-squad-control* target-count) 0)
    (until (t9-2 a0-4 a1-0)
      (suspend)
      (set! 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) 'down?)
      (set! t9-2 send-event-function)
      (let ((v1-6 gp-0))
        (set! a0-4 (if v1-6
                       (-> v1-6 extra process)
                       )
              )
        )
      )
    )
  (was-squad-manager-kill)
  (set-setting! 'extra-bank '((desert1 strong1) (desert2 desert5)) 0.0 0)
  (while (< 184320.0 (vector-vector-distance *stronghold-inside-point* (target-pos 0)))
    (suspend)
    )
  (set-setting! 'music 'chasmara 0.0 0)
  (dotimes (gp-2 4)
    (spawn-v-catapult self gp-2)
    )
  (suspend)
  (dotimes (gp-3 4)
    (let ((s5-1 (as-type (handle->process (-> self vehicle gp-3 handle)) process-focusable)))
      (when s5-1
        (send-event s5-1 'ai-ignore-nav-mesh)
        (send-event s5-1 'ai-set-mode 0)
        (send-event s5-1 'ai-set-target-speed 0)
        )
      )
    )
  (when (and *target* (focus-test? *target* pilot-riding) (handle->process (-> *target* pilot vehicle)))
    (-> self player-vehicle)
    (set-setting! 'letterbox 'abs 1.0 0)
    (set-setting! 'letterbox-speed 'abs 2.0 0)
    (set-setting! 'entity-name "camera-394" 0.0 0)
    (sound-play "camera-pan-1" :position #f)
    (let ((gp-5 (-> *target* pilot vehicle)))
      (send-event (handle->process gp-5) 'ignore-damage #t)
      (send-event (handle->process gp-5) 'ignore-impulse #t)
      (send-event (handle->process gp-5) 'set-control-hook-ai)
      (send-event (handle->process gp-5) 'ai-ignore-nav-mesh #t)
      (send-event (handle->process gp-5) 'ai-set-target-speed 122880.0)
      (send-event (handle->process gp-5) 'ai-set-target-position *stronghold-vehicle-stop-point*)
      )
    (while (let ((f0-1 81920.0))
             (< (* f0-1 f0-1) (vector-vector-distance-squared (target-pos 0) *stronghold-vehicle-stop-point*))
             )
      (suspend)
      )
    (process-spawn
      simple-nav-sphere
      40960.0
      *stronghold-vehicle-stop-point*
      (-> self marauder-nav-mesh)
      -1
      :name "simple-nav-sphere"
      :to self
      )
    (set-setting! 'stop-vehicle? #t 0.0 0)
    (send-event *target* 'change-mode 'normal)
    (set-setting! 'pilot #f 0.0 0)
    )
  (send-event *vehicle-manager* 'no-extra-bank)
  (set-setting! 'extra-bank '((wasall1 strong2) (desert1 strong1) (desert2 desert5)) 0.0 0)
  (persist-with-delay *setting-control* 'blur-a (seconds 1.5) 'blur-a 'abs 0.5 0)
  (set! (-> *display* force-sync) (the-as uint 240))
  (sound-play "camera-pan-2" :position #f)
  (set-setting! 'entity-name "camera-399" 0.0 0)
  (let ((v1-137 (-> self vehicle 3 handle process)))
    (set-setting! 'sound-ear v1-137 0.0 (-> v1-137 0 pid))
    )
  (suspend-for (seconds 1.5)
    )
  (desert-chase-ambush-manager-method-35 self 3)
  (suspend-for (seconds 1)
    )
  (persist-with-delay *setting-control* 'blur-a (seconds 1.5) 'blur-a 'abs 0.5 0)
  (set! (-> *display* force-sync) (the-as uint 240))
  (sound-play "camera-pan-3" :position #f)
  (let ((v1-157 (-> self vehicle 2 handle process)))
    (set-setting! 'sound-ear v1-157 0.0 (-> v1-157 0 pid))
    )
  (set-setting! 'entity-name "camera-400" 0.0 0)
  (suspend-for (seconds 1.5)
    )
  (desert-chase-ambush-manager-method-35 self 2)
  (suspend-for (seconds 1)
    )
  (desert-chase-ambush-manager-method-35 self 1)
  (persist-with-delay *setting-control* 'blur-a (seconds 1.5) 'blur-a 'abs 0.5 0)
  (set! (-> *display* force-sync) (the-as uint 240))
  (sound-play "camera-pan-4" :position #f)
  (let ((v1-181 (-> self vehicle 0 handle process)))
    (set-setting! 'sound-ear v1-181 0.0 (-> v1-181 0 pid))
    )
  (set-setting! 'entity-name "camera-402" 0.0 0)
  (suspend-for (seconds 1.5)
    )
  (desert-chase-ambush-manager-method-35 self 0)
  (suspend-for (seconds 1)
    )
  (remove-setting! 'sound-ear)
  (persist-with-delay *setting-control* 'blur-a (seconds 1.5) 'blur-a 'abs 0.5 0)
  (set! (-> *display* force-sync) (the-as uint 240))
  (sound-play "camera-pan-5" :position #f)
  (set-setting! 'entity-name "camera-394" 0.0 0)
  (remove-setting! 'letterbox)
  (set-blackout-frames 0)
  (until (process-release? *target*)
    (suspend)
    )
  (when *target*
    (logior! (-> *target* focus-status) (focus-status teleporting))
    (process-drawable-show-all-cloth *target* #f)
    (logior! (-> *target* draw status) (draw-control-status no-draw))
    (let ((gp-18 (get-continue-by-name *game-info* "desertf-stronghold-start")))
      (move-to-point! (-> *target* control) (-> gp-18 trans))
      (let ((t9-64 quaternion-copy!)
            (a0-97 (-> *target* control quat-for-control))
            (a1-57 (new 'stack-no-clear 'quaternion))
            )
        (set! (-> a1-57 x) (* 0.00003051851 (the float (-> gp-18 quat x))))
        (set! (-> a1-57 y) (* 0.00003051851 (the float (-> gp-18 quat y))))
        (set! (-> a1-57 z) (* 0.00003051851 (the float (-> gp-18 quat z))))
        (set! (-> a1-57 w) (* 0.00003051851 (the float (-> gp-18 quat w))))
        (t9-64 a0-97 a1-57)
        )
      )
    (rot->dir-targ! (-> *target* control))
    )
  (suspend)
  (when *target*
    (process-drawable-show-all-cloth *target* #t)
    (logclear! (-> *target* draw status) (draw-control-status no-draw))
    )
  (suspend)
  (if *target*
      (logclear! (-> *target* focus-status) (focus-status teleporting))
      )
  (suspend-for (seconds 2.5)
    )
  (remove-setting! 'entity-name)
  (dotimes (gp-20 4)
    (let ((s5-7 (-> self vehicle gp-20))
          (v1-253 (-> self vehicle gp-20 handle))
          )
      (when (!= v1-253 #f)
        (let ((a0-110 (handle->process v1-253)))
          (when a0-110
            (send-event a0-110 'go-die)
            (set! (-> s5-7 handle) (the-as handle #f))
            (+! (-> self vehicle-count) -1)
            (let ((s5-8 (-> self v-free-list)))
              (set! (-> s5-8 (length s5-8)) (the-as uint gp-20))
              (+! (-> s5-8 length) 1)
              )
            )
          )
        )
      )
    )
  (task-node-close! (game-task-node desert-chase-marauders-get-to-stronghold) 'event)
  (none)
  )

(defstate active (desert-chase-ambush-manager)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('reached-destination)
       (set! (-> self player-moved?) #t)
       (send-event proc 'change-mode 'lock)
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :code (behavior ()
    ;; og:preserve-this
    (local-vars (v1-6 object))
    (when (not (task-node-closed? (game-task-node desert-chase-marauders-introduction)))
      (while (or (not *target*) (not (logtest? (-> *target* focus-status) (focus-status pilot-riding))))
        (suspend)
        )
      (until v1-6
        (suspend)
        (set! v1-6
              (and *target*
                   (focus-test? *target* pilot-riding)
                   (as-type (handle->process (-> *target* pilot vehicle)) v-toad)
                   )
              )
        )
      )
    (let ((t1-0 8))
      (set-setting! 'vehicles 'set (shr t1-0 32) t1-0)
      )
    (set-setting! 'pilot-exit #f 0.0 0)
    (cond
      ((task-node-closed? (game-task-node desert-chase-marauders-get-to-stronghold))
       (let ((gp-1 (new 'stack-no-clear 'inline-array 'traffic-object-spawn-params 1)))
         (set! (-> gp-1 0 object-type) (traffic-type guard-a))
         (set! (-> gp-1 0 behavior) (the-as uint 0))
         (set! (-> gp-1 0 id) (the-as uint 0))
         (set! (-> gp-1 0 nav-mesh) #f)
         (set! (-> gp-1 0 nav-branch) #f)
         (set! (-> gp-1 0 proc) #f)
         (set! (-> gp-1 0 handle) (the-as handle #f))
         (set! (-> gp-1 0 user-data) (the-as uint 0))
         (set! (-> gp-1 0 flags) (traffic-spawn-flags tsf5 tsf6))
         (set! (-> gp-1 0 guard-type) (the-as uint 11))
         (set! (-> gp-1 0 entity) #f)
         (vector-reset! (-> gp-1 0 velocity))
         (vector-copy! (-> gp-1 0 position) *stronghold-vehicle-stop-point*)
         (quaternion-copy! (-> gp-1 0 rotation) (new 'static 'quaternion :x -0.0297 :y -0.879 :z -0.019 :w -0.4753))
         (let ((gp-2 (vehicle-spawn (vehicle-type v-toad) (-> gp-1 0))))
           (when gp-2
             (set! (-> self player-vehicle) (process->handle gp-2))
             (process-spawn
               simple-nav-sphere
               40960.0
               *stronghold-vehicle-stop-point*
               (-> self marauder-nav-mesh)
               -1
               :name "simple-nav-sphere"
               :to self
               )
             (set-setting! 'pilot #f 0.0 0)
             (send-event gp-2 'ignore-damage #t)
             (send-event gp-2 'ignore-impulse #t)
             )
           )
         )
       )
      (else
        (desert-chase-ambush-intro-sequence)
        )
      )
    (set-setting! 'extra-bank '((wasall1 strong2) (desert1 strong1) (desert2 desert5)) 0.0 0)
    (set-setting! 'music 'chasmara 0.0 0)
    (set! (-> self hud-counter)
          (ppointer->handle (process-spawn hud-marauder :init hud-init-by-other :name "hud-marauder" :to self))
          )
    (set! (-> *game-info* counter) (the float (- (+ (-> self marauder-count) 60) (-> self total-spawned))))
    (suspend-for (seconds 3)
      )
    (until (and (>= (-> self total-spawned) (the-as uint 60)) (zero? (-> self marauder-count)))
      (when (>= (+ (current-time) (seconds -0.5)) (-> self check-timer))
        (let* ((gp-5 (length *stronghold-marauder-start*))
               (s4-0 (rand-vu-int-count gp-5))
               )
          (dotimes (s5-1 gp-5)
            (when (and (< (-> self marauder-count) (the-as uint 5)) (< (-> self total-spawned) (the-as uint 60)))
              (spawn-marauder self (-> *stronghold-marauder-start* s4-0))
              (set! s4-0 (mod (+ s4-0 1) gp-5))
              )
            (set-time! (-> self check-timer))
            )
          )
        )
      (dotimes (gp-6 4)
        (let ((s5-2 (-> self vehicle gp-6)))
          (when (and (time-elapsed? (-> s5-2 wait-timer) (seconds 5)) (time-elapsed? (-> self last-shot-time) (seconds 3)))
            (let ((s4-1 (new 'stack-no-clear 'vector))
                  (s3-0 (-> self target-point gp-6))
                  )
              (vector-copy! s3-0 (target-pos 0))
              (cond
                ((rand-vu-percent? 0.2)
                 (+! (-> s3-0 x) (rand-vu-float-range -20480.0 20480.0))
                 (+! (-> s3-0 z) (rand-vu-float-range -20480.0 20480.0))
                 )
                (else
                  (let ((f30-2 (rand-vu-float-range 40960.0 81920.0)))
                    (+! (-> s3-0 x) (if (rand-vu-percent? 0.5)
                                        (- f30-2)
                                        f30-2
                                        )
                        )
                    (+! (-> s3-0 z) (if (rand-vu-percent? 0.5)
                                        (- f30-2)
                                        f30-2
                                        )
                        )
                    )
                  )
                )
              (when (nav-mesh-method-11 (-> self marauder-nav-mesh) s3-0)
                (set! (-> s3-0 y) (-> self marauder-nav-mesh bounds y))
                (vector+! s4-1 s3-0 (new 'static 'vector :y 614400.0 :w 1.0))
                (fire-catapult-shot self s4-1 s3-0)
                (set-time! (-> self last-shot-time))
                )
              )
            (set! (-> s5-2 wait-timer) (+ (current-time) (the int (fmin 750.0 (* 1500.0 (rand-vu))))))
            )
          )
        )
      (let ((v1-119 (- (+ (-> self marauder-count) 60) (-> self total-spawned))))
        (cond
          ((zero? v1-119)
           (when (-> self hud-counter)
             (send-event (handle->process (-> self hud-counter)) 'hide-and-die)
             (set! (-> self hud-counter) (the-as handle #f))
             )
           )
          (else
            (set! (-> *game-info* counter) (the float v1-119))
            )
          )
        )
      (suspend)
      )
    (send-event *vehicle-manager* 'extra-bank '((wasall1 wastoad) (desert2 desert5)))
    (send-event self 'complete)
    )
  )

(defmethod fire-catapult-shot ((this desert-chase-ambush-manager) (arg0 vector) (arg1 vector))
  (let ((gp-0 (new 'stack-no-clear 'projectile-init-by-other-params)))
    (let ((v1-5 (ppointer->handle (process-spawn catapult-target arg1 :name "catapult-target" :to this))))
      (set! (-> gp-0 ent) (-> this entity))
      (set! (-> gp-0 charge) 1.0)
      (set! (-> gp-0 options) (projectile-options))
      (logclear! (-> gp-0 options) (projectile-options po14 po15 po16))
      (vector-copy! (-> gp-0 pos) arg0)
      (set! (-> gp-0 notify-handle) (process->handle this))
      (set! (-> gp-0 owner-handle) (process->handle this))
      ;; og:preserve-this
      (set! (-> gp-0 target-handle) v1-5)
      )
    (vector-copy! (-> gp-0 target-pos) arg1)
    (set! (-> gp-0 ignore-handle) (process->handle this))
    (let* ((v1-13 *game-info*)
           (a0-27 (+ (-> v1-13 attack-id) 1))
           )
      (set! (-> v1-13 attack-id) a0-27)
      (set! (-> gp-0 attack-id) a0-27)
      )
    (set! (-> gp-0 timeout) (seconds 10))
    (set! (-> gp-0 damage) 4.0)
    (logior! (-> gp-0 options) (projectile-options po14))
    (spawn-projectile v-catapult-shot gp-0 this *default-dead-pool*)
    )
  0
  (none)
  )

(defmethod task-manager-method-26 ((this desert-chase-ambush-manager))
  (dotimes (s5-0 5)
    (let ((v1-2 (-> this marauder s5-0)))
      (when (!= v1-2 #f)
        (cond
          ((as-type (handle->process v1-2) process-focusable)
           )
          (else
            (set! (-> this marauder s5-0) (the-as handle #f))
            (+! (-> this marauder-count) -1)
            (let ((s4-1 (-> this m-free-list)))
              (set! (-> s4-1 (length s4-1)) (the-as uint s5-0))
              (+! (-> s4-1 length) 1)
              )
            )
          )
        )
      )
    )
  ((method-of-type task-manager task-manager-method-26) this)
  (none)
  )

(defmethod desert-chase-ambush-manager-method-35 ((this desert-chase-ambush-manager) (arg0 int))
  (let* ((gp-0 (-> this vehicle arg0))
         (v1-2 (-> gp-0 handle))
         )
    (when (!= v1-2 #f)
      (let ((s4-0 (as-type (handle->process v1-2) process-focusable)))
        (when s4-0
          (let ((s3-1 (-> this target-point arg0)))
            (vector-copy! s3-1 *stronghold-inside-point*)
            (+! (-> s3-1 x) (rand-vu-float-range -122880.0 122880.0))
            (+! (-> s3-1 z) (rand-vu-float-range -122880.0 122880.0))
            (send-event s4-0 'launch s3-1 this)
            )
          (set! (-> gp-0 shot-fired?) #t)
          (set-time! (-> gp-0 wait-timer))
          )
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch connection-minimap vs none.
(defmethod spawn-marauder ((this desert-chase-ambush-manager) (arg0 deschase-point))
  (let ((s5-0 (-> this m-free-list)))
    (when (nonzero? (length s5-0))
      (let ((s4-0 (-> s5-0 (+ (length s5-0) -1)))
            (s3-0 43)
            (f30-0 10.0)
            )
        (when (and *target* (and (>= 5.0 (-> *target* fact health)) (rand-vu-percent? 0.6)))
          (set! s3-0 20)
          (set! f30-0 2.0)
          )
        (let ((s1-0 (new 'stack-no-clear 'marauder-init-by-other-params)))
          (vector-copy! (-> s1-0 trans) (-> arg0 pos))
          (quaternion-copy! (-> s1-0 quat) (-> arg0 quat))
          (set! (-> s1-0 entity) (-> this marauder-entity))
          (set! (-> s1-0 directed?) #f)
          (set! (-> s1-0 no-initial-move-to-ground?) #t)
          (set! (-> s1-0 multi-focus) #f)
          (set! (-> s1-0 skip-jump) #f)
          (let ((s2-2 (ppointer->process (process-spawn marauder this s1-0 :name "marauder" :to this))))
            (when s2-2
              (change-to (-> this marauder-nav-mesh) (the-as process-drawable s2-2))
              (let ((v1-26 (-> (the-as marauder s2-2) nav state)))
                (set! (-> v1-26 current-poly) (the-as nav-poly #f))
                )
              0
              (reset-to-collide-spec
                (-> (the-as marauder s2-2) focus)
                (collide-spec jak bot hit-by-others-list player-list jak-vehicle)
                )
              (set! (-> (the-as marauder s2-2) fact pickup-type) (the-as pickup-type s3-0))
              (set! (-> (the-as marauder s2-2) fact pickup-amount) f30-0)
              (set! (-> (the-as marauder s2-2) gun?) #f)
              (set! (-> this marauder s4-0) (process->handle (the-as marauder s2-2)))
              (+! (-> this marauder-count) 1)
              (+! (-> s5-0 length) -1)
              (+! (-> this total-spawned) 1)
              (add-icon! *minimap* (the-as marauder s2-2) (the-as uint 117) (the-as int #f) (the-as vector #t) 0)
              )
            )
          )
        )
      )
    )
  (none)
  )

(defmethod spawn-v-catapult ((this desert-chase-ambush-manager) (arg0 int))
  (let ((gp-0 (-> this v-free-list)))
    (when (nonzero? (length gp-0))
      (let ((s4-0 (-> this vehicle (-> gp-0 (+ (length gp-0) -1))))
            (s3-1 (-> *deschase-catapult-spawn-point* arg0))
            (s2-0 (new 'stack-no-clear 'mystery-traffic-object-spawn-params0))
            )
        (vector-z-quaternion! (-> s2-0 vec) (-> s3-1 quat))
        (vector-float*! (-> s2-0 vec) (-> s2-0 vec) 0.0)
        (set! (-> s2-0 params object-type) (traffic-type guard-a))
        (set! (-> s2-0 params behavior) (the-as uint 3))
        (set! (-> s2-0 params id) (the-as uint 0))
        (set! (-> s2-0 params nav-mesh) #f)
        (set! (-> s2-0 params nav-branch) #f)
        (set! (-> s2-0 params proc) #f)
        (set! (-> s2-0 params handle) (the-as handle #f))
        (set! (-> s2-0 params user-data) (the-as uint 0))
        (set! (-> s2-0 params flags) (traffic-spawn-flags tsf6))
        (set! (-> s2-0 params guard-type) (the-as uint 11))
        (set! (-> s2-0 params entity) #f)
        (vector-copy! (-> s2-0 params velocity) (-> s2-0 vec))
        (vector-copy! (-> s2-0 params position) (-> s3-1 pos))
        (quaternion-copy! (-> s2-0 params rotation) (-> s3-1 quat))
        (let ((a0-12 (vehicle-spawn (vehicle-type v-catapult) (-> s2-0 params))))
          (when a0-12
            (set! (-> s4-0 handle) (process->handle a0-12))
            (set! (-> s4-0 wait-timer) (the-as time-frame (+ (- 900 (the int (* 1500.0 (rand-vu)))) (current-time))))
            (+! (-> this vehicle-count) 1)
            (+! (-> this total-veh-spawned) 1)
            (+! (-> gp-0 length) -1)
            (return (-> s4-0 handle))
            )
          )
        )
      )
    )
  (the-as handle #f)
  )

(defmethod task-manager-method-25 ((this desert-chase-ambush-manager))
  (send-event (handle->process (-> this player-vehicle)) 'ignore-damage #f)
  (send-event (handle->process (-> this player-vehicle)) 'ignore-impulse #f)
  (let ((t9-2 (method-of-type task-manager task-manager-method-25)))
    (t9-2 this)
    )
  (set! (-> *marauder-nav-enemy-info* attack-damage) 2)
  (let ((a0-14 (handle->process (-> this h-player-controller))))
    (if a0-14
        (deactivate a0-14)
        )
    )
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod init! ((this desert-chase-ambush-manager))
  (let ((t9-0 (method-of-type task-manager init!)))
    (t9-0 this)
    )
  (set! (-> this h-player-controller) (the-as handle #f))
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod set-time-limit ((this desert-chase-ambush-manager))
  (let ((t9-0 (method-of-type task-manager set-time-limit)))
    (t9-0 this)
    )
  (set-setting! 'extra-bank '((desert2 desert5) (desert3 desert6)) 0.0 0)
  (set! (-> this marauder-nav-mesh) (get-nav-mesh (the-as actor-id #xf064)))
  (set! (-> this m-free-list) (new 'static 'boxed-array :type uint8 :length 0 :allocated-length 5))
  (dotimes (v1-4 5)
    (set! (-> this marauder v1-4) (the-as handle #f))
    (set! (-> this m-free-list v1-4) (the-as uint v1-4))
    )
  (set! (-> this m-free-list length) 5)
  (set! (-> this marauder-entity) (the-as entity-actor (entity-by-name "marauder-3")))
  (set! (-> *marauder-nav-enemy-info* attack-damage) 1)
  (set! (-> this marauder-nav-mesh) (get-nav-mesh (the-as actor-id #xf064)))
  (set! (-> this v-free-list) (new 'static 'boxed-array :type uint8 :length 0 :allocated-length 4))
  (dotimes (v1-10 4)
    (set! (-> this vehicle v1-10 handle) (the-as handle #f))
    (set! (-> this vehicle v1-10 shot-fired?) #f)
    (set! (-> this v-free-list v1-10) (the-as uint v1-10))
    )
  (set! (-> this v-free-list length) 4)
  (set! (-> this player-moved?) #f)
  (none)
  )

(deftype deschase-artifact (process-drawable)
  ((arrow  handle)
   (pos    vector  :inline)
   (angs   vector  :inline)
   )
  (:state-methods
    idle
    )
  (:methods
    (check-pickup (_type_) none)
    (rotate (_type_) none)
    )
  )


(defskelgroup skel-deschase-artifact pre-artifact-a pre-artifact-a-lod0-jg pre-artifact-a-idle-ja
              ((pre-artifact-a-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 4)
              )

(defbehavior deschase-artifact-init-by-other deschase-artifact ((arg0 vector))
  (set! (-> self level) (level-get *level* 'deschase))
  (set! (-> self root) (new 'process 'trsqv))
  (vector-copy! (-> self pos) arg0)
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-deschase-artifact" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (if (-> self draw shadow)
      (set! (-> self draw shadow-ctrl) (new
                                         'process
                                         'shadow-control
                                         -40960.0
                                         40960.0
                                         614400.0
                                         (the-as vector #f)
                                         (shadow-flags shdf00 shdf04)
                                         245760.0
                                         )
            )
      )
  (let ((s5-1 (new 'stack-no-clear 'task-arrow-params)))
    (vector-copy! (-> s5-1 pos) arg0)
    (quaternion-identity! (-> s5-1 quat))
    (set! (-> s5-1 flags) (task-arrow-flags taf3))
    (set! (-> s5-1 map-icon) (the-as uint 13))
    (set! (-> self arrow) (process->handle (task-arrow-spawn s5-1 self)))
    )
  (go-virtual idle)
  )

(defstate idle (deschase-artifact)
  :virtual #t
  :trans (behavior ()
    (check-pickup self)
    )
  :code (behavior ()
    (ja :group! (ja-group) :num! min)
    (ja-post)
    (sleep-code)
    )
  :post (behavior ()
    (rotate self)
    )
  )

(defmethod check-pickup ((this deschase-artifact))
  (let ((v1-0 *target*)
        (s5-0 (new 'stack-no-clear 'vector))
        )
    (when v1-0
      (vector-copy! s5-0 (-> v1-0 control trans))
      (set! (-> s5-0 w) 4096.0)
      (when (focus-test? v1-0 pilot)
        (let ((a1-4 (the-as process-focusable (handle->process (-> v1-0 pilot vehicle)))))
          (vector-copy! s5-0 (-> a1-4 root root-prim prim-core world-sphere))
          )
        )
      (let ((f0-1 (vector-vector-distance-squared (-> this root trans) s5-0))
            (f1-1 (+ 12288.0 (-> s5-0 w)))
            )
        (when (>= (* f1-1 f1-1) f0-1)
          (sound-play "artifact-pickup")
          (deactivate this)
          )
        )
      )
    )
  0
  (none)
  )

(defmethod rotate ((this deschase-artifact))
  (let ((gp-0 (new 'stack-no-clear 'matrix)))
    (set! (-> gp-0 fvec x) (seconds-per-frame))
    (+! (-> this angs x) (* 32768.0 (-> gp-0 fvec x)))
    (+! (-> this angs y) (* 23665.777 (-> gp-0 fvec x)))
    (+! (-> this angs z) (* 20024.889 (-> gp-0 fvec x)))
    (+! (-> this angs w) (* 22755.555 (-> gp-0 fvec x)))
    (dotimes (v1-5 4)
      (if (< 32768.0 (-> this angs data v1-5))
          (+! (-> this angs data v1-5) -65536.0)
          )
      (if (< (-> this angs data v1-5) -32768.0)
          (+! (-> this angs data v1-5) 65536.0)
          )
      )
    (vector-reset! (-> gp-0 rvec))
    (set! (-> gp-0 rvec y) (+ 4915.2 (* 2048.0 (sin (-> this angs x)))))
    (set! (-> gp-0 rvec x) (* 1024.0 (sin (-> this angs y))))
    (set! (-> gp-0 rvec z) (* 1024.0 (cos (-> this angs y))))
    (vector+! (-> this root trans) (-> this pos) (-> gp-0 rvec))
    (vector-reset! (-> gp-0 uvec))
    (set! (-> gp-0 uvec z) (* 5461.3335 (sin (-> this angs z))))
    (set! (-> gp-0 uvec y) (-> this angs w))
    (quaternion-zxy! (-> this root quat) (-> gp-0 uvec))
    )
  (ja-post)
  0
  (none)
  )

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

;; WARN: Return type mismatch process vs deschase-artifact.
(defun deschase-artifact-spawn ((arg0 process) (arg1 vector))
  (let ((gp-0 (the-as process #f)))
    (let ((v1-1 (process-spawn deschase-artifact arg1 :name "deschase-artifact" :to arg0)))
      (if v1-1
          (set! gp-0 (-> v1-1 0))
          )
      )
    (the-as deschase-artifact gp-0)
    )
  )

(deftype hud-desert-chase-marauders (hud)
  ()
  )


(defmethod draw ((this hud-desert-chase-marauders))
  (set-hud-piece-position! (-> this sprites 0) (the int (+ 482.0 (* 130.0 (-> this offset)))) 25)
  (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) -20 45)
  ((method-of-type hud draw) this)
  0
  (none)
  )

(defmethod update-values! ((this hud-desert-chase-marauders))
  (set! (-> this values 0 target) (the int (-> *game-info* counter)))
  (set! (-> this values 1 target) (the int (-> *game-info* score)))
  ((method-of-type hud update-values!) this)
  0
  (none)
  )

(defmethod init-callback ((this hud-desert-chase-marauders))
  (set! (-> this level) (level-get *level* 'deschase))
  (set! (-> this gui-id)
        (add-process *gui-control* this (gui-channel hud-upper-right) (gui-action hidden) (-> this name) 81920.0 0)
        )
  (logior! (-> this flags) (hud-flags show))
  (set! (-> this sprites 0 tid)
        (the-as texture-id (lookup-texture-by-id (new 'static 'texture-id :page #xc70)))
        )
  (set! (-> this sprites 0 flags) (hud-sprite-flags hsf2))
  (set! (-> this sprites 0 scale-x) 1.0)
  (set! (-> this sprites 0 scale-y) 1.0)
  (alloc-string-if-needed this 0)
  (set! (-> this strings 0 scale) 0.8)
  (set! (-> this strings 0 flags) (font-flags shadow kerning middle large))
  (set! (-> this strings 0 color) (font-color white))
  0
  (none)
  )

(define *stronghold-vehicle-start* (new 'static 'boxed-array :type deschase-point
                                     (new 'static 'deschase-point
                                       :pos (new 'static 'vector :x 6089183.0 :y 99123.2 :z 11991433.0 :w 1.0)
                                       :quat (new 'static 'quaternion :y -0.4923 :z 0.0004 :w -0.8703)
                                       )
                                     (new 'static 'deschase-point
                                       :pos (new 'static 'vector :x 6419560.5 :y 99123.2 :z 12347280.0 :w 1.0)
                                       :quat (new 'static 'quaternion :x -0.0004 :y -0.9183 :w 0.3957)
                                       )
                                     )
        )

(define *desert-chase-vehicle-start* (new 'static 'boxed-array :type deschase-point
                                       (new 'static 'deschase-point
                                         :pos (new 'static 'vector :x 8088014.5 :y 167103.69 :z 12576974.0 :w 1.0)
                                         :quat (new 'static 'quaternion :x -0.3283 :y 0.9339 :z -0.0804 :w 0.1161)
                                         )
                                       (new 'static 'deschase-point
                                         :pos (new 'static 'vector :x 8003995.5 :y 131172.36 :z 12836982.0 :w 1.0)
                                         :quat (new 'static 'quaternion :x -0.1975 :y 0.9546 :z 0.0761 :w 0.209)
                                         )
                                       (new 'static 'deschase-point
                                         :pos (new 'static 'vector :x 7909497.5 :y 107760.02 :z 13230446.0 :w 1.0)
                                         :quat (new 'static 'quaternion :x -0.178 :y 0.9448 :z -0.0933 :w 0.2583)
                                         )
                                       (new 'static 'deschase-point
                                         :pos (new 'static 'vector :x 7661562.5 :y 84980.125 :z 13392549.0 :w 1.0)
                                         :quat (new 'static 'quaternion :x -0.1404 :y 0.936 :z -0.0788 :w 0.3128)
                                         )
                                       )
        )

(set! (-> *desert-chase-vehicle-start* 0 i-node) 45)

(set! (-> *desert-chase-vehicle-start* 1 i-node) 45)

(set! (-> *desert-chase-vehicle-start* 2 i-node) 45)

(set! (-> *desert-chase-vehicle-start* 3 i-node) 46)

(deftype deschase-vehicle-control (structure)
  ((vehicle       handle)
   (target        handle)
   (path          deschase-path)
   (speed         float)
   (i-node        int32)
   (max-dist      float)
   (speed-factor  float)
   )
  :allow-misaligned
  (:methods
    (deschase-vehicle-control-method-9 (_type_) none)
    (deschase-vehicle-control-method-10 (_type_) none)
    (deschase-vehicle-control-method-11 (_type_) none)
    (deschase-vehicle-control-method-12 (_type_) none)
    )
  )


(defmethod deschase-vehicle-control-method-9 ((this deschase-vehicle-control))
  (set! (-> this vehicle) (the-as handle #f))
  (set! (-> this target) (the-as handle #f))
  (set! (-> this speed-factor) 1.0)
  0
  (none)
  )

(defmethod deschase-vehicle-control-method-11 ((this deschase-vehicle-control))
  (let ((gp-0 (handle->process (-> this vehicle))))
    (when gp-0
      (let* ((s5-0 (-> this path node (-> this i-node)))
             (f0-0 (-> s5-0 speed))
             )
        (if (>= 16384.0 f0-0)
            (set! f0-0 327680.0)
            )
        (let ((f30-0 (fmin f0-0 (* (-> this speed-factor) (-> this speed)))))
          (send-event gp-0 'ai-set-target-process (handle->process (-> this target)))
          (send-event gp-0 'ai-set-target-position (-> s5-0 position))
          (send-event gp-0 'ai-set-target-speed f30-0)
          )
        )
      ;; og:preserve-this
      ;; original game bug.
      (send-event gp-0 'ai-ignore-nav-mesh #t)
      )
    )
  0
  (none)
  )

(defmethod deschase-vehicle-control-method-10 ((this deschase-vehicle-control))
  (let ((v1-3 (as-type (handle->process (-> this vehicle)) process-focusable)))
    (when v1-3
      (let* ((s5-1 (-> this path node (-> this i-node)))
             (f0-0 (vector-vector-distance-squared (-> v1-3 root trans) (-> s5-1 position)))
             (f1-0 40960.0)
             )
        (when (< f0-0 (* f1-0 f1-0))
          (let ((v1-7 (-> s5-1 next-node)))
            (if (!= v1-7 -1)
                (set! (-> this i-node) v1-7)
                )
            )
          )
        )
      (deschase-vehicle-control-method-11 this)
      )
    )
  0
  (none)
  )

(defmethod deschase-vehicle-control-method-12 ((this deschase-vehicle-control))
  (let ((gp-0 (as-type (handle->process (-> this vehicle)) process-focusable)))
    (when (and (the-as process-focusable gp-0)
               (not (logtest? (-> (the-as process-focusable gp-0) focus-status) (focus-status dead)))
               )
      (let ((s4-0 (new 'stack-no-clear 'matrix)))
        (vector-copy! (-> s4-0 uvec) (-> (the-as process-focusable gp-0) root trans))
        (vector-float*! (-> s4-0 rvec) (-> (the-as process-focusable gp-0) root transv) 0.1)
        (set! (-> s4-0 fvec x) 24576.0)
        (let ((s5-1 (the-as (array collide-shape) ((method-of-type array new)
                                                   (the-as symbol (new 'stack-no-clear 'array 'collide-shape 128))
                                                   array
                                                   collide-shape
                                                   128
                                                   )
                            )
                    )
              )
          (set! (-> s5-1 length) (fill-actor-list-for-sphere
                                   *actor-hash*
                                   (-> s4-0 uvec)
                                   (-> s4-0 rvec)
                                   (-> s4-0 fvec x)
                                   (-> s5-1 data)
                                   (-> s5-1 allocated-length)
                                   -1
                                   )
                )
          (dotimes (s4-1 (-> s5-1 length))
            (let ((a0-15 (as-type (-> s5-1 s4-1 process) v-marauder)))
              (if (and a0-15 (!= a0-15 gp-0))
                  (send-event
                    a0-15
                    'attack
                    #f
                    (static-attack-info
                      :mask (vehicle-impulse-factor)
                      ((id (new-attack-id)) (damage 30.0) (vehicle-damage-factor 1.0) (vehicle-impulse-factor 0.0))
                      )
                    )
                  )
              )
            )
          )
        )
      )
    )
  0
  (none)
  )

(deftype desert-chase-chase-manager (task-manager)
  ((h-player-controller  handle)
   (check-timer          time-frame)
   (speech-time          time-frame)
   (last-speech          int8)
   (death-count          int16)
   (max-dist             float)
   (suck-factor          float)
   (player-moved?        symbol)
   (control-array        deschase-vehicle-control  4 :inline)
   (minimap              connection-minimap        :offset 472)
   (artifact             handle)
   )
  (:methods
    (spawn-chase-vehicle (_type_ deschase-vehicle deschase-point) none)
    (update-chase-status (_type_) none)
    )
  )


(defmethod task-manager-method-25 ((this desert-chase-chase-manager))
  (let ((t9-0 (method-of-type task-manager task-manager-method-25)))
    (t9-0 this)
    )
  (let ((a0-3 (handle->process (-> this h-player-controller))))
    (if a0-3
        (deactivate a0-3)
        )
    )
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod init! ((this desert-chase-chase-manager))
  (let ((t9-0 (method-of-type task-manager init!)))
    (t9-0 this)
    )
  (set! (-> this h-player-controller) (the-as handle #f))
  (set! (-> this artifact) (the-as handle #f))
  (dotimes (s5-0 4)
    (deschase-vehicle-control-method-9 (-> this control-array s5-0))
    )
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod set-time-limit ((this desert-chase-chase-manager))
  (let ((t9-0 (method-of-type task-manager set-time-limit)))
    (t9-0 this)
    )
  (let ((t1-0 8))
    (set-setting! 'vehicles 'set (shr t1-0 32) t1-0)
    )
  (set-setting! 'exclusive-task #f 0.0 (-> this node-info task))
  (set-setting! 'pilot-exit #f 0.0 0)
  (let ((a2-3 (-> *game-info* sub-task-list (-> this info final-node) death-count)))
    (set! (-> this death-count) (the-as int a2-3))
    (set! (-> this suck-factor) (cond
                                  ((< a2-3 (the-as uint 5))
                                   0.0
                                   )
                                  ((< a2-3 (the-as uint 10))
                                   0.25
                                   )
                                  (else
                                    (fmin 1.0 (* 0.05 (the float a2-3)))
                                    )
                                  )
          )
    (format #t "desert-chase-marauders::initialize death-count ~d, suck-factor ~f~%" a2-3 (-> this suck-factor))
    )
  (set! (-> this player-moved?) #f)
  (none)
  )

(defmethod task-manager-method-26 ((this desert-chase-chase-manager))
  (when (!= (-> this player-vehicle) #f)
    (let ((a0-5 (as-type (handle->process (-> this player-vehicle)) process-focusable)))
      (if (or (not a0-5) (focus-test? a0-5 dead))
          (send-event this 'fail)
          )
      )
    )
  (let ((s5-1 0))
    (dotimes (s4-0 4)
      (let ((s3-0 (-> this control-array s4-0)))
        (let ((a0-14 (as-type (handle->process (-> s3-0 vehicle)) process-focusable)))
          (if (and a0-14 (not (logtest? (-> (the-as process-focusable a0-14) focus-status) (focus-status dead))))
              (+! s5-1 1)
              )
          )
        (deschase-vehicle-control-method-10 s3-0)
        )
      )
    (set! (-> *game-info* counter) (the float s5-1))
    )
  (hud-timer-handler this)
  ((method-of-type task-manager task-manager-method-26) this)
  (none)
  )

(defmethod spawn-chase-vehicle ((this desert-chase-chase-manager) (arg0 deschase-vehicle) (arg1 deschase-point))
  (let ((s5-0 (new 'stack-no-clear 'traffic-object-spawn-params)))
    (set! (-> s5-0 object-type) (traffic-type guard-a))
    (set! (-> s5-0 behavior) (the-as uint 3))
    (set! (-> s5-0 id) (the-as uint 0))
    (set! (-> s5-0 nav-mesh) #f)
    (set! (-> s5-0 nav-branch) #f)
    (set! (-> s5-0 proc) #f)
    (set! (-> s5-0 handle) (the-as handle #f))
    (set! (-> s5-0 user-data) (the-as uint 0))
    (set! (-> s5-0 flags) (traffic-spawn-flags))
    (set! (-> s5-0 guard-type) (the-as uint 11))
    (set! (-> s5-0 entity) #f)
    (vector-reset! (-> s5-0 velocity))
    (vector-copy! (-> s5-0 position) (-> arg1 pos))
    (quaternion-copy! (-> s5-0 rotation) (-> arg1 quat))
    (let ((s5-1 (vehicle-spawn (vehicle-type v-marauder-b) (the-as traffic-object-spawn-params (&-> s5-0 object-type))))
          )
      (if (not s5-1)
          (format #t "vehicle-spawn failed~%")
          )
      (when s5-1
        (format #t "vehicle-spawn pid ~d~%" (-> s5-1 pid))
        (set! (-> arg0 handle) (process->handle s5-1))
        )
      )
    )
  0
  (none)
  )

;; WARN: new jak 2 until loop case, check carefully
(defmethod update-chase-status ((this desert-chase-chase-manager))
  (let ((s4-0 -1)
        (s5-0 -1)
        )
    (let ((s3-0 #f)
          (s2-0 3)
          )
      (until #f
        (let ((a0-5 (as-type (handle->process (-> this control-array s2-0 vehicle)) process-focusable)))
          (cond
            ((or (not a0-5) (focus-test? (the-as process-focusable a0-5) dead))
             (if s3-0
                 (set! s4-0 s2-0)
                 )
             )
            (else
              (when (not s3-0)
                (set! s3-0 #t)
                (set! s5-0 s2-0)
                )
              )
            )
          )
        (+! s2-0 -1)
        (if (< s2-0 0)
            (goto cfg-21)
            )
        )
      )
    #f
    (label cfg-21)
    (when (!= s4-0 -1)
      (let ((v1-21 (-> this control-array s4-0 vehicle)))
        (let ((a0-8 (+ s4-0 1)))
          (while (>= s5-0 a0-8)
            (set! (-> this control-array (+ a0-8 -1) vehicle) (-> this control-array a0-8 vehicle))
            (+! a0-8 1)
            )
          )
        (set! (-> this control-array s5-0 vehicle) v1-21)
        )
      )
    )
  0
  (none)
  )

;; WARN: new jak 2 until loop case, check carefully
(defbehavior desert-chase-chase-intro-sequence desert-chase-chase-manager ()
  (set-setting! 'extra-bank '((wasall1 wastoad) (desert2 desert5)) 0.0 0)
  (set! (-> self player-moved?) #f)
  (when *target*
    (set-setting! 'entity-name "camera-394" 0.0 0)
    (let ((gp-0 (new 'stack-no-clear 'player-controller-init-params)))
      (set! (-> gp-0 mode) 'active)
      (set! (-> gp-0 flags) (player-controller-flag pc1 lock-features letterbox pc4))
      (vector-copy! (-> gp-0 targ-pos) *stronghold-player-goto-point*)
      (set! (-> gp-0 notify-proc) (process->handle self))
      (set! (-> self h-player-controller)
            (ppointer->handle (process-spawn player-controller gp-0 :name "player-controller" :to *target*))
            )
      )
    )
  (set-setting! 'sound-ear-scale 'abs 0.25 0)
  (let ((gp-1 (new 'stack-no-clear 'event-message-block)))
    (set! (-> gp-1 from) (process->ppointer self))
    (set! (-> gp-1 num-params) 0)
    (set! (-> gp-1 message) 'raise)
    (let ((s5-1 send-event-function)
          (v1-21 (entity-by-name "des-jump-bridge-2"))
          )
      (s5-1
        (if v1-21
            (-> v1-21 extra process)
            )
        gp-1
        )
      )
    )
  (let ((gp-2 (new 'stack-no-clear 'event-message-block)))
    (set! (-> gp-2 from) (process->ppointer self))
    (set! (-> gp-2 num-params) 0)
    (set! (-> gp-2 message) 'raise)
    (let ((s5-2 send-event-function)
          (v1-26 (entity-by-name "des-jump-bridge-1"))
          )
      (s5-2
        (if v1-26
            (-> v1-26 extra process)
            )
        gp-2
        )
      )
    )
  (set-time! (-> self check-timer))
  (until #f
    (if (or (-> self player-moved?)
            (or (< (vector-vector-distance (target-pos 0) *stronghold-player-goto-point*) 40960.0)
                (time-elapsed? (-> self check-timer) (seconds 5))
                )
            )
        (goto cfg-32)
        )
    (suspend)
    )
  #f
  (label cfg-32)
  (let ((gp-4 (new 'stack-no-clear 'event-message-block)))
    (set! (-> gp-4 from) (process->ppointer self))
    (set! (-> gp-4 num-params) 0)
    (set! (-> gp-4 message) 'open)
    (let ((s5-3 send-event-function)
          (v1-44 (entity-by-name "des-garage-door-2"))
          )
      (s5-3
        (if v1-44
            (-> v1-44 extra process)
            )
        gp-4
        )
      )
    )
  (dotimes (v1-47 4)
    (let ((a0-29 (-> self control-array v1-47)))
      (set! (-> a0-29 speed) 327680.0)
      )
    )
  (let ((gp-5 (-> self control-array)))
    (when (not (handle->process (-> gp-5 0 vehicle)))
      (spawn-chase-vehicle self (the-as deschase-vehicle gp-5) (-> *stronghold-vehicle-start* 0))
      (set! (-> gp-5 0 path) *desert-chase-marauder-path*)
      (set! (-> gp-5 0 i-node) 0)
      0
      )
    )
  (suspend-for (seconds 1)
    )
  (let ((gp-7 (new 'stack-no-clear 'event-message-block)))
    (set! (-> gp-7 from) (process->ppointer self))
    (set! (-> gp-7 num-params) 0)
    (set! (-> gp-7 message) 'open)
    (let ((s5-4 send-event-function)
          (v1-66 (entity-by-name "des-garage-door-1"))
          )
      (s5-4
        (if v1-66
            (-> v1-66 extra process)
            )
        gp-7
        )
      )
    )
  (let ((gp-8 (-> self control-array 1)))
    (when (not (handle->process (-> gp-8 vehicle)))
      (spawn-chase-vehicle self (the-as deschase-vehicle gp-8) (-> *stronghold-vehicle-start* 1))
      (set! (-> gp-8 path) *desert-chase-marauder-path*)
      (set! (-> gp-8 i-node) 48)
      )
    )
  (suspend-for (seconds 1)
    )
  (let ((gp-10 (-> self control-array 2)))
    (when (not (handle->process (-> gp-10 vehicle)))
      (spawn-chase-vehicle self (the-as deschase-vehicle gp-10) (-> *stronghold-vehicle-start* 0))
      (set! (-> gp-10 path) *desert-chase-marauder-path*)
      (set! (-> gp-10 i-node) 0)
      0
      )
    )
  (suspend-for (seconds 1)
    )
  (let ((gp-12 (new 'stack-no-clear 'event-message-block)))
    (set! (-> gp-12 from) (process->ppointer self))
    (set! (-> gp-12 num-params) 0)
    (set! (-> gp-12 message) 'close)
    (let ((s5-5 send-event-function)
          (v1-99 (entity-by-name "des-garage-door-2"))
          )
      (s5-5
        (if v1-99
            (-> v1-99 extra process)
            )
        gp-12
        )
      )
    )
  (let ((gp-13 (-> self control-array 3)))
    (when (not (handle->process (-> gp-13 vehicle)))
      (spawn-chase-vehicle self (the-as deschase-vehicle gp-13) (-> *stronghold-vehicle-start* 1))
      (set! (-> gp-13 path) *desert-chase-marauder-path*)
      (set! (-> gp-13 i-node) 48)
      )
    )
  (suspend-for (seconds 1)
    )
  (let ((gp-15 (new 'stack-no-clear 'event-message-block)))
    (set! (-> gp-15 from) (process->ppointer self))
    (set! (-> gp-15 num-params) 0)
    (set! (-> gp-15 message) 'close)
    (let ((s5-6 send-event-function)
          (v1-118 (entity-by-name "des-garage-door-1"))
          )
      (s5-6
        (if v1-118
            (-> v1-118 extra process)
            )
        gp-15
        )
      )
    )
  (suspend-for (seconds 1)
    )
  (suspend-for (seconds 4)
    )
  (send-event (handle->process (-> self h-player-controller)) 'change-mode 'idle)
  (dotimes (gp-18 4)
    (let ((s5-7 (-> self control-array gp-18)))
      (send-event (handle->process (-> s5-7 vehicle)) 'go-die)
      (set! (-> s5-7 vehicle) (the-as handle #f))
      )
    )
  (remove-setting! 'pilot)
  (remove-setting! 'entity-name)
  (remove-setting! 'sound-ear-scale)
  (send-event *vehicle-manager* 'no-extra-bank)
  (remove-setting! 'extra-bank)
  (none)
  )

(defstate active (desert-chase-chase-manager)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('reached-destination)
       (set! (-> self player-moved?) #t)
       (send-event proc 'change-mode 'lock)
       )
      (else
        (task-manager-event-handler proc argc message block)
        )
      )
    )
  :code (behavior ()
    (set-setting! 'allow-progress #f 0.0 0)
    (until #f
      (let ((a1-1 *target*))
        (if (and a1-1 (not (logtest? (focus-status teleporting) (-> a1-1 focus-status))))
            (goto cfg-8)
            )
        )
      (suspend)
      )
    #f
    (label cfg-8)
    (set-setting! 'music 'desres1 0.0 0)
    (suspend)
    (when (not (task-node-closed? (game-task-node desert-chase-marauders-chase)))
      (desert-chase-chase-intro-sequence)
      (task-node-close! (game-task-node desert-chase-marauders-chase) 'event)
      )
    (set! (-> self player-vehicle) (-> *vehicle-info* handle-by-vehicle-type 15))
    (dotimes (gp-0 3)
      (send-event (handle->process (-> self player-vehicle)) 'turbo-pickup)
      )
    (remove-setting! 'allow-progress)
    (talker-spawn-func (-> *talker-speech* 174) *entity-pool* (target-pos 0) (the-as region #f))
    (dotimes (gp-2 4)
      (let ((s5-1 (-> self control-array gp-2)))
        (let ((s4-1 (-> *desert-chase-vehicle-start* gp-2)))
          (spawn-chase-vehicle self (the-as deschase-vehicle s5-1) s4-1)
          (set! (-> s5-1 path) *desert-chase-marauder-path*)
          (set! (-> s5-1 i-node) (-> s4-1 i-node))
          )
        (set! (-> s5-1 speed) 0.0)
        (set! (-> s5-1 max-dist) 1638400.0)
        )
      )
    (set! (-> self hud-counter)
          (ppointer->handle
            (process-spawn hud-desert-chase-marauders :init hud-init-by-other :name "hud-desert-chase-marauders" :to self)
            )
          )
    (suspend)
    (set-time! (-> self state-time))
    (until #f
      (if (or (and *target* (focus-test? *target* pilot-riding))
              (or (< 204800.0 (vector-vector-distance (target-pos 0) *stronghold-player-goto-point*))
                  (time-elapsed? (-> self state-time) (seconds 10))
                  )
              )
          (goto cfg-43)
          )
      (suspend)
      )
    #f
    (label cfg-43)
    (let ((v1-58 (new 'static 'vector :x 204800.0 :y 192512.0 :z 180224.0 :w 122880.0)))
      (dotimes (a0-27 4)
        (let ((a1-16 (-> self control-array a0-27)))
          (set! (-> a1-16 speed) (+ (-> v1-58 data a0-27) (* -24576.0 (-> self suck-factor))))
          (if *target*
              (set! (-> a1-16 target) (process->handle *target*))
              )
          )
        )
      )
    (suspend-for (seconds 1)
      )
    (was-squad-manager-start self)
    (let ((v1-66 *was-squad-control*))
      (set! (-> v1-66 target-count) 2)
      (set! (-> v1-66 reserve-count) 400)
      (set! (-> v1-66 target-speed) 143360.0)
      )
    (let ((gp-6 3))
      (until #f
        (let ((v1-68 gp-6))
          (set! (-> self time-limit) (the-as time-frame (cond
                                                          ((zero? v1-68)
                                                           0
                                                           )
                                                          ((= v1-68 1)
                                                           #x4650
                                                           )
                                                          ((= v1-68 2)
                                                           #x4650
                                                           )
                                                          ((= v1-68 3)
                                                           (+ (if (zero? (-> self death-count))
                                                                  900
                                                                  0
                                                                  )
                                                              #x34bc
                                                              )
                                                           )
                                                          (else
                                                            0
                                                            )
                                                          )
                                             )
                )
          )
        (set! (-> self max-dist) 2457600.0)
        (if (= gp-6 3)
            (set! (-> self max-dist) 3072000.0)
            )
        (if (nonzero? gp-6)
            (set-time! (-> self start-time))
            )
        (set! (-> self minimap) #f)
        (until #f
          (update-chase-status self)
          (dotimes (s5-2 4)
            (deschase-vehicle-control-method-12 (-> self control-array s5-2))
            )
          (dotimes (s5-3 gp-6)
            (let* ((s4-2 (-> self control-array s5-3))
                   (s2-0 (-> self control-array (+ s5-3 1)))
                   (s3-0 (as-type (handle->process (-> s4-2 vehicle)) process-focusable))
                   (v1-101 (as-type (handle->process (-> s2-0 vehicle)) process-focusable))
                   )
              (when (and s3-0 v1-101)
                (let ((f0-8 (vector-vector-distance
                              (-> (the-as process-focusable s3-0) root trans)
                              (-> (the-as process-focusable v1-101) root trans)
                              )
                            )
                      )
                  (set! (-> s4-2 speed-factor) 1.0)
                  (if (< (-> s4-2 max-dist) f0-8)
                      (set! (-> s4-2 speed-factor) 0.0)
                      )
                  )
                )
              )
            )
          (let ((v1-109 (-> self control-array gp-6)))
            (set! (-> v1-109 speed-factor) 1.0)
            (let ((s5-4 (as-type (handle->process (-> v1-109 vehicle)) process-focusable)))
              (when (the-as process-focusable s5-4)
                (if (not (-> self minimap))
                    (set! (-> self minimap)
                          (add-icon! *minimap* (the-as process-focusable s5-4) (the-as uint 12) (the-as int #f) (the-as vector #t) 0)
                          )
                    )
                (let ((f30-1 (vector-vector-distance (target-pos 0) (-> (the-as process-focusable s5-4) root trans))))
                  (if (< (-> self max-dist) f30-1)
                      (send-event self 'fail)
                      )
                  (when (and (< f30-1 532480.0) (time-elapsed? (-> self speech-time) (seconds 5)))
                    (set-time! (-> self speech-time))
                    (let ((v1-131 (rand-vu-int-count 4)))
                      (when (!= v1-131 (-> self last-speech))
                        (set! (-> self last-speech) v1-131)
                        (cond
                          ((zero? v1-131)
                           (talker-spawn-func (-> *talker-speech* 177) *entity-pool* (target-pos 0) (the-as region #f))
                           )
                          ((= v1-131 1)
                           (talker-spawn-func (-> *talker-speech* 178) *entity-pool* (target-pos 0) (the-as region #f))
                           )
                          ((= v1-131 2)
                           (talker-spawn-func (-> *talker-speech* 180) *entity-pool* (target-pos 0) (the-as region #f))
                           )
                          ((= v1-131 3)
                           (talker-spawn-func (-> *talker-speech* 181) *entity-pool* (target-pos 0) (the-as region #f))
                           )
                          )
                        )
                      )
                    )
                  )
                0
                )
              (when (or (not s5-4) (focus-test? (the-as process-focusable s5-4) dead))
                (if (and s5-4 (zero? gp-6))
                    (set! (-> self artifact)
                          (process->handle (deschase-artifact-spawn self (-> (the-as process-focusable s5-4) root trans)))
                          )
                    )
                (goto cfg-146)
                )
              )
            )
          (suspend)
          )
        #f
        (label cfg-146)
        (set! (-> self start-time) 0)
        (send-event (handle->process (-> self hud-timer)) 'hide-and-die)
        (if (-> self minimap)
            (logior! (-> self minimap flags) (minimap-flag fade-out))
            )
        (suspend-for (seconds 1)
          )
        (+! gp-6 -1)
        (if (= gp-6 -1)
            (goto cfg-176)
            )
        (if (zero? gp-6)
            (send-event (handle->process (-> self control-array 0 vehicle)) 'no-pickup)
            )
        (let ((v1-176 gp-6))
          (cond
            ((zero? v1-176)
             (talker-spawn-func (-> *talker-speech* 179) *entity-pool* (target-pos 0) (the-as region #f))
             )
            ((= v1-176 1)
             (talker-spawn-func (-> *talker-speech* 175) *entity-pool* (target-pos 0) (the-as region #f))
             )
            ((= v1-176 2)
             (talker-spawn-func (-> *talker-speech* 176) *entity-pool* (target-pos 0) (the-as region #f))
             )
            )
          )
        )
      )
    #f
    (label cfg-176)
    (send-event (handle->process (-> self hud-counter)) 'hide-and-die)
    (set! (-> *was-squad-control* target-count) 0)
    0
    (until #f
      (if (not (handle->process (-> self artifact)))
          (goto cfg-193)
          )
      (suspend)
      )
    #f
    (label cfg-193)
    (send-event self 'complete)
    )
  )

(defstate complete (desert-chase-chase-manager)
  :virtual #t
  :code (behavior ()
    (suspend-for (seconds 4)
      )
    (call-parent-state-handler code)
    )
  )
