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

;; name: factory-boss-states.gc
;; name in dgo: factory-boss-states
;; dgos: FACD

;; +++facboss-cmd
(defenum facboss-cmd
  :type uint64
  (cmd1 1)
  (cmd2 2)
  (cmd3 3)
  (cmd4 4)
  (cmd5 5)
  (cmd6 6)
  (cmd7 7)
  (cmd8 8)
  (cmd9 9)
  (cmd10 10)
  (cmd11 11)
  (cmd12 12)
  (cmd13 13)
  (cmd14 14)
  (cmd15 15)
  (cmd16 16)
  (cmd17 17)
  (cmd18 18)
  (cmd19 19)
  (cmd20 20)
  (cmd21 21)
  )
;; ---facboss-cmd


;; DECOMP BEGINS

;; WARN: Return type mismatch float vs degrees.
(defbehavior factory-boss-angle-sub factory-boss ((arg0 degrees) (arg1 degrees))
  (let* ((v1-1 (+ 65536.0 arg0))
         (v1-4 (- v1-1 (* (the float (the int (/ v1-1 65536.0))) 65536.0)))
         (a0-2 (+ 65536.0 arg1))
         (a0-5 (- a0-2 (* (the float (the int (/ a0-2 65536.0))) 65536.0)))
         (v0-0 (- v1-4 a0-5))
         )
    (cond
      ((>= -32768.0 v0-0)
       (set! v0-0 (+ 65536.0 v0-0))
       )
      ((< 32768.0 v0-0)
       (set! v0-0 (+ -65536.0 v0-0))
       )
      )
    (the-as degrees v0-0)
    )
  )

(defbehavior factory-boss-target-pos factory-boss ((arg0 vector) (arg1 int) (arg2 int))
  (vector-copy! arg0 (target-pos 0))
  (set! (-> arg0 y) (-> self center y))
  (when (= arg1 1)
    (let ((a0-3 (- (the-as int (- (current-time) (-> self shot-timer)))))
          (v1-7 (vector-reset! (new 'stack-no-clear 'vector)))
          )
      (let ((a1-3 (-> self actor-group (-> self floor-targets arg2))))
        (dotimes (a2-4 (-> a1-3 length))
          (vector+! v1-7 v1-7 (-> a1-3 data a2-4 actor extra trans))
          )
        (vector-float*! v1-7 v1-7 (/ 1.0 (the float (-> a1-3 length))))
        )
      (set! (-> v1-7 y) (-> self center y))
      (vector-! arg0 arg0 v1-7)
      (vector+float*! arg0 v1-7 arg0 (fmax 0.0 (fmin 1.0 (* 0.008888889 (the float a0-3)))))
      )
    )
  arg0
  )

;; WARN: Return type mismatch vector vs none.
(defmethod factory-boss-method-29 ((this factory-boss) (arg0 float) (arg1 vector))
  (set! (-> arg1 x) (+ (-> this center x) (* 118784.0 (sin arg0))))
  (set! (-> arg1 y) (-> this root trans y))
  (set! (-> arg1 z) (+ (-> this center z) (* 118784.0 (cos arg0))))
  (none)
  )

;; WARN: Return type mismatch quaternion vs none.
(defbehavior factory-boss-move factory-boss ()
  (+! (-> self catwalk-angle) (* (-> self catwalk-vel) (-> self clock time-adjust-ratio)))
  (cond
    ((>= (-> self catwalk-angle) 65536.0)
     (+! (-> self catwalk-angle) -65536.0)
     (+! (-> self root-angle) -65536.0)
     )
    ((< (-> self catwalk-angle) 0.0)
     (+! (-> self catwalk-angle) 65536.0)
     (+! (-> self root-angle) 65536.0)
     )
    )
  (factory-boss-method-29 self (-> self catwalk-angle) (-> self root trans))
  (cond
    ((< (-> self catwalk-vel) 0.0)
     (seek!
       (-> self root-angle)
       (+ 48969.957 (-> self catwalk-angle))
       (* 1820.4445 (-> self clock time-adjust-ratio))
       )
     )
    ((< 0.0 (-> self catwalk-vel))
     (seek!
       (-> self root-angle)
       (+ 16566.045 (-> self catwalk-angle))
       (* 1820.4445 (-> self clock time-adjust-ratio))
       )
     )
    (else
      (seek!
        (-> self root-angle)
        (+ 32768.0 (-> self catwalk-angle))
        (* 1820.4445 (-> self clock time-adjust-ratio))
        )
      )
    )
  (quaternion-set!
    (-> self root quat)
    0.0
    (sin (/ (-> self root-angle) 2))
    0.0
    (cos (/ (-> self root-angle) 2))
    )
  (none)
  )

;; WARN: Function factory-boss-pick-machine has a return type of none, but the expression builder found a return statement.
(defbehavior factory-boss-pick-machine factory-boss ()
  (let ((gp-0 10000)
        (a0-0 0)
        )
    (dotimes (v1-0 4)
      (cond
        ((< (-> self machine-state v1-0 state) gp-0)
         (set! gp-0 (-> self machine-state v1-0 state))
         (set! a0-0 1)
         )
        ((= (-> self machine-state v1-0 state) gp-0)
         (+! a0-0 1)
         )
        )
      )
    (let ((v1-3 (rand-vu-int-count a0-0)))
      (dotimes (a0-3 4)
        (when (>= gp-0 (-> self machine-state a0-3 state))
          (when (<= v1-3 0)
            (set! (-> self chosen-machine) a0-3)
            (return 0)
            )
          (+! v1-3 -1)
          )
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch connection vs none.
(defbehavior factory-boss-pick-camera factory-boss ()
  (let ((v1-0 (-> self chosen-machine)))
    (cond
      ((zero? v1-0)
       (set-setting! 'entity-name "camera-385" 0.0 0)
       )
      ((= v1-0 1)
       (set-setting! 'entity-name "camera-384" 0.0 0)
       )
      ((= v1-0 2)
       (set-setting! 'entity-name "camera-387" 0.0 0)
       )
      ((= v1-0 3)
       (set-setting! 'entity-name "camera-386" 0.0 0)
       )
      )
    )
  (none)
  )

(defbehavior factory-boss-pick-pers-camera factory-boss ()
  (let ((v1-0 (-> self chosen-machine)))
    (cond
      ((zero? v1-0)
       (persist-with-delay
         *setting-control*
         'entity-name
         (seconds 3)
         'entity-name
         (the-as symbol "camera-385")
         0.0
         0
         )
       )
      ((= v1-0 1)
       (persist-with-delay
         *setting-control*
         'entity-name
         (seconds 3)
         'entity-name
         (the-as symbol "camera-384")
         0.0
         0
         )
       )
      ((= v1-0 2)
       (persist-with-delay
         *setting-control*
         'entity-name
         (seconds 3)
         'entity-name
         (the-as symbol "camera-387")
         0.0
         0
         )
       )
      ((= v1-0 3)
       (persist-with-delay
         *setting-control*
         'entity-name
         (seconds 3)
         'entity-name
         (the-as symbol "camera-386")
         0.0
         0
         )
       )
      )
    )
  (none)
  )

(defbehavior factory-boss-machine-angle factory-boss ()
  (+ 8192.0 (* 16384.0 (the float (-> self chosen-machine))))
  )

(defbehavior factory-boss-approaching? factory-boss ((arg0 degrees))
  (let ((f0-1 (factory-boss-angle-sub arg0 (-> self catwalk-angle))))
    (or (and (< (-> self catwalk-vel) 0.0) (>= 0.0 f0-1)) (and (< 0.0 (-> self catwalk-vel)) (>= f0-1 0.0)))
    )
  )

(defbehavior factory-boss-move-to-dest-angle factory-boss ((arg0 float) (arg1 float))
  (if (= (-> self catwalk-angle) arg0)
      (return #t)
      )
  (cond
    ((!= (-> self catwalk-vel) 0.0)
     )
    ((< (factory-boss-angle-sub arg0 (-> self catwalk-angle)) 0.0)
     (set! (-> self catwalk-vel) (- arg1))
     )
    (else
      (set! (-> self catwalk-vel) arg1)
      )
    )
  (let ((s5-1 (factory-boss-approaching? arg0)))
    (factory-boss-move)
    (when (and s5-1 (not (factory-boss-approaching? arg0)))
      (set! (-> self catwalk-vel) 0.0)
      (set! (-> self catwalk-angle) arg0)
      (return #t)
      )
    )
  #f
  )

(defmethod next-catwalk-angle ((this factory-boss) (arg0 int))
  (+ (-> this catwalk-angle) (* 0.2 (the float arg0) (-> this catwalk-vel)))
  )

;; WARN: Return type mismatch int vs time-frame.
(defbehavior factory-boss-time-until-angle factory-boss ((arg0 degrees))
  (the-as time-frame (cond
                       ((= (-> self catwalk-angle) arg0)
                        0
                        )
                       ((= (-> self catwalk-vel) 0.0)
                        #x7530
                        )
                       (else
                         (let ((f0-3 (factory-boss-angle-sub arg0 (-> self catwalk-angle))))
                           (the int (* 5.0 (/ f0-3 (-> self catwalk-vel))))
                           )
                         )
                       )
          )
  )

(defbehavior factory-boss-get-particle-spawn-points factory-boss ((arg0 int) (arg1 vector) (arg2 vector) (arg3 matrix))
  (factory-boss-method-26 self arg0 arg1 arg2 #f)
  (vector-! (-> arg3 fvec) (-> self center) arg1)
  (set! (-> arg3 fvec y) 0.0)
  (vector-normalize! (-> arg3 fvec) 1.0)
  (set! (-> arg3 fvec w) 0.0)
  (set-vector! (-> arg3 rvec) (-> arg3 fvec z) 0.0 (- (-> arg3 fvec x)) 0.0)
  (set-vector! (-> arg3 uvec) 0.0 1.0 0.0 0.0)
  (vector+float*! arg2 arg1 (-> arg3 fvec) 0.0)
  (+! (-> arg2 y) 106496.0)
  0
  (none)
  )

(defbehavior factory-boss-drop-bomb factory-boss ((arg0 int))
  (let ((gp-0 (new 'stack-no-clear 'projectile-init-by-other-params)))
    (let ((s3-0 (new 'stack-no-clear 'vector))
          (s4-0 (new 'stack-no-clear 'vector))
          )
      (vector<-cspace! s3-0 (joint-node errol-lowres-lod0-jg Lhand))
      (factory-boss-target-pos s4-0 arg0 0)
      (set! (-> gp-0 ent) (-> self 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) s3-0)
      (vector-copy! (-> gp-0 vel) s4-0)
      )
    (set! (-> gp-0 notify-handle) (the-as handle #f))
    (set! (-> gp-0 owner-handle) (the-as handle #f))
    (set! (-> gp-0 target-handle) (the-as handle #f))
    (set! (-> gp-0 target-pos quad) (the-as uint128 0))
    (set! (-> gp-0 ignore-handle) (process->handle self))
    (let* ((v1-11 *game-info*)
           (a0-11 (+ (-> v1-11 attack-id) 1))
           )
      (set! (-> v1-11 attack-id) a0-11)
      (set! (-> gp-0 attack-id) a0-11)
      )
    (set! (-> gp-0 timeout) (seconds 4))
    (factory-boss-play-speech 1 self)
    (cond
      ((= arg0 1)
       (+! (-> self bombs-to-drop) -1)
       (let ((v1-16 (ppointer->process (spawn-projectile factory-boss-floorbuster-bomb gp-0 self *default-dead-pool*))))
         (when v1-16
           (set! (-> (the-as factory-boss-floorbuster-bomb v1-16) targetted-group) (-> self floor-targets 0))
           (+! (-> self num-floor-targets) -1)
           (dotimes (v1-20 (-> self num-floor-targets))
             (set! (-> self floor-targets v1-20) (-> self floor-targets (+ v1-20 1)))
             )
           (the-as (pointer process) #f)
           )
         )
       )
      ((= arg0 2)
       (+! (-> self bombs-to-drop) -1)
       (spawn-projectile factory-boss-shockwave-bomb gp-0 self *default-dead-pool*)
       )
      (else
        (+! (-> self bombs-to-drop) -1)
        (spawn-projectile factory-boss-shot gp-0 self *default-dead-pool*)
        )
      )
    )
  )

(defbehavior factory-boss-check-bomb-timer factory-boss ((arg0 int))
  (let ((s5-0 (>= (- (current-time) (+ (-> self shot-timer) (seconds -0.75))) 0)))
    (let ((v1-5 (ja-group)))
      (cond
        ((and v1-5 (or (= v1-5 errol-lowres-run-cw-ja)
                       (= v1-5 errol-lowres-run-ccw-ja)
                       (= v1-5 errol-lowres-idle-to-run-cw-ja)
                       (= v1-5 errol-lowres-idle-to-run-ccw-ja)
                       )
              )
         (ja-channel-push! 1 (seconds 0.1))
         (ja :group! errol-lowres-run-to-idle-ja :num! min)
         (set! s5-0 #f)
         )
        ((let ((v1-16 (ja-group)))
           (and v1-16 (= v1-16 errol-lowres-run-to-idle-ja))
           )
         (set! s5-0 #f)
         (ja :num! (seek!))
         (when (ja-done? 0)
           (ja-channel-push! 1 (seconds 0.1))
           (ja :group! errol-lowres-idle30-ja :num! min)
           (set! (-> self shot-timer) (+ (current-time) (the int (* 300.0 (rand-vu-float-range 2.0 4.0)))))
           )
         )
        ((let ((v1-39 (ja-group)))
           (and v1-39 (= v1-39 errol-lowres-idle-throw-ja))
           )
         (let ((f30-1 (ja-aframe-num 0)))
           (ja :num! (seek!))
           (when (>= (ja-aframe-num 0) 59.0)
             (if (or (zero? (-> self bombs-to-drop)) (!= arg0 1))
                 (set! s5-0 #f)
                 )
             (if (or (< f30-1 59.0) (and (> (-> self bombs-to-drop) 0) (= arg0 1)))
                 (factory-boss-drop-bomb arg0)
                 )
             )
           )
         (when (ja-done? 0)
           (ja-channel-push! 1 (seconds 0.1))
           (if (or (zero? (-> self bombs-to-drop)) (nonzero? arg0))
               (ja :group! errol-lowres-idle30-ja :num! min)
               (ja :group! errol-lowres-idle-throw-ja :num! min)
               )
           (cond
             ((= arg0 2)
              (set! (-> self shot-timer) (+ (current-time) (the int (* 300.0 (rand-vu-float-range 1.5 3.5)))))
              )
             (else
               (set! (-> self shot-timer) 0)
               0
               )
             )
           (return #t)
           )
         )
        ((and (>= (- (current-time) (+ (-> self shot-timer) (seconds -1))) 0) (nonzero? (-> self bombs-to-drop)))
         (ja-channel-push! 1 (seconds 0.1))
         (ja :group! errol-lowres-idle-throw-ja :num! min)
         )
        (else
          (ja :num! (loop!))
          )
        )
      )
    (cond
      (s5-0
        (let ((s5-4 0))
          (while (let ((v1-107 arg0))
                   (< s5-4 (if (= v1-107 1)
                               (-> self bombs-to-drop)
                               1
                               )
                      )
                   )
            (let ((s4-3 (factory-boss-target-pos (new 'stack-no-clear 'vector) arg0 s5-4)))
              (factory-boss-reticle-info-method-10
                (-> self reticle-info)
                s4-3
                (-> self root trans)
                (max 1 (- (the-as int (- (current-time) (-> self shot-timer)))))
                arg0
                )
              (when (zero? s5-4)
                (sound-play "reticle-track" :id (-> self reticle-sound) :position s4-3)
                (set! (-> self reticle-sound-playing) #t)
                )
              )
            (+! s5-4 1)
            )
          )
        )
      (else
        (factory-boss-method-30 self)
        )
      )
    )
  #f
  )

(defbehavior factory-boss-end-cutscene factory-boss ()
  (if (not (movie?))
      (process-release? *target*)
      )
  (remove-setting! 'entity-name)
  (set! (-> self camera-timer) 0)
  (set! (-> self draw force-lod) 1)
  (none)
  )

(defbehavior factory-boss-spawn-ring factory-boss ((arg0 matrix) (arg1 vector) (arg2 factory-boss-machine-state))
  (let ((v1-0 (new 'stack-no-clear 'vector)))
    (vector+float*! v1-0 arg1 (-> arg0 uvec) 14336.0)
    (vector+float*! v1-0 v1-0 (-> arg0 fvec) 7168.0)
    (vector-copy! (-> arg0 trans) v1-0)
    )
  (spawn-from-mat (-> arg2 ring-part) arg0)
  (none)
  )

;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 352 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 368 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 384 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 400 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 272 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 288 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 320 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 336 mismatch: defined as size 4, got size 16
;; WARN: Return type mismatch symbol vs none.
(defbehavior factory-boss-always factory-boss ()
  (local-vars
    (sv-256 (function float float float float float float))
    (sv-272 float)
    (sv-288 float)
    (sv-304 (function float float float float float float))
    (sv-320 float)
    (sv-336 float)
    (sv-352 float)
    (sv-368 float)
    (sv-384 float)
    (sv-400 float)
    )
  (factory-boss-play-speech 0 self)
  (if (and (nonzero? (-> self camera-timer)) (time-elapsed? (-> self camera-timer) (seconds 3)))
      (factory-boss-end-cutscene)
      )
  (cond
    ((and (-> self next-state) (let ((v1-9 (-> self next-state name)))
                                 (or (= v1-9 'run-to-machine)
                                     (= v1-9 'get-hit)
                                     (= v1-9 'launch-critters)
                                     (= v1-9 'drop-bombs)
                                     (= v1-9 'beaten)
                                     )
                                 )
          )
     (init! (-> self warp-blocker) (the-as int self))
     (init! (-> self entry-blocker) (the-as int self))
     )
    (else
      (disable (-> self warp-blocker))
      (disable (-> self entry-blocker))
      )
    )
  (dotimes (gp-0 4)
    (let ((s5-0 (-> self machine-state gp-0))
          (s4-0 (new 'stack-no-clear 'vector))
          (s0-0 (new 'stack-no-clear 'vector))
          (s1-0 (new 'stack-no-clear 'vector))
          (s3-0 (new 'stack-no-clear 'vector))
          (s2-0 (new 'stack-no-clear 'matrix))
          )
      (factory-boss-get-particle-spawn-points gp-0 s4-0 s0-0 s2-0)
      (let ((f1-0 2.5))
        (when (zero? (-> s5-0 state))
          (let ((f0-1 (* 0.0033333334 (the float (current-time)))))
            (set! f1-0 (the float (the int (* 5.9999 (- f0-1 (the float (the int f0-1)))))))
            )
          )
        (let ((f0-6 (+ 14745.6 (* 2048.0 f1-0))))
          (let ((f1-5 (+ 6553.6 (* 2048.0 f1-0))))
            (vector+float*! s1-0 s0-0 (-> s2-0 rvec) f0-6)
            (vector+float*! s1-0 s1-0 (-> s2-0 uvec) f1-5)
            )
          (vector+float*! s1-0 s1-0 (-> s2-0 fvec) -4096.0)
          (vector-copy! (-> s2-0 trans) s1-0)
          (vector+float*! s3-0 s1-0 (-> s2-0 rvec) (* -2.0 f0-6))
          )
        )
      (vector-copy! (-> s2-0 trans) s3-0)
      (if (logtest? (-> s5-0 flags) (facboss-machine-state-flag fms1))
          (factory-boss-spawn-ring s2-0 s4-0 s5-0)
          )
      (cond
        ((zero? (-> s5-0 state))
         (let ((v1-45 (-> s5-0 lightning state mode)))
           (when (or (zero? v1-45) (= v1-45 3))
             (let ((v1-47 (-> s5-0 lightning))
                   (a0-23 1)
                   )
               (let ((a1-14 (!= a0-23 (-> v1-47 state mode))))
                 (case a0-23
                   ((3)
                    (if a1-14
                        (set! (-> v1-47 state counter) 0.0)
                        )
                    )
                   ((1)
                    (set! (-> v1-47 state start-color) (-> v1-47 spec start-color))
                    (set! (-> v1-47 state end-color) (-> v1-47 spec end-color))
                    )
                   )
                 )
               (set! (-> v1-47 state mode) (the-as uint a0-23))
               )
             )
           )
         (set! (-> s5-0 lightning state meet data 0 quad) (-> s1-0 quad))
         (let ((v1-51 (-> s5-0 lightning)))
           (vector-copy! (-> v1-51 state meet data (+ (-> v1-51 state points-to-draw) -1)) s3-0)
           )
         )
        (else
          (let ((v1-55 (-> s5-0 lightning state mode)))
            (cond
              ((or (zero? v1-55) (= v1-55 3))
               )
              (else
                (let ((v1-57 (-> s5-0 lightning))
                      (a0-32 3)
                      )
                  (let ((a1-24 (!= a0-32 (-> v1-57 state mode))))
                    (case a0-32
                      ((3)
                       (if a1-24
                           (set! (-> v1-57 state counter) 0.0)
                           )
                       )
                      ((1)
                       (set! (-> v1-57 state start-color) (-> v1-57 spec start-color))
                       (set! (-> v1-57 state end-color) (-> v1-57 spec end-color))
                       )
                      )
                    )
                  (set! (-> v1-57 state mode) (the-as uint a0-32))
                  )
                )
              )
            )
          (vector-copy! (-> s2-0 trans) s4-0)
          (spawn-from-mat (-> s5-0 damaged-low-smoke-part) s2-0)
          (vector-copy! (-> s2-0 trans) s0-0)
          (spawn-from-mat (-> s5-0 damaged-high-smoke-part) s2-0)
          (cond
            ((< (- (current-time) (-> s5-0 ring-timer)) 0)
             )
            ((logtest? (-> s5-0 flags) (facboss-machine-state-flag fms1))
             (let ((s0-1 (current-time))
                   (f30-0 300.0)
                   )
               (set! sv-256 lerp-scale)
               (set! sv-272 (the-as float 0.05))
               (set! sv-288 (the-as float 0.15))
               (let* ((v1-73 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                      (v1-74 (the-as number (logior #x3f800000 v1-73)))
                      (a2-6 (+ -1.0 (the-as float v1-74)))
                      (a3-5 0.0)
                      (t0-0 1.0)
                      )
                 (set! (-> s5-0 ring-timer) (+ s0-1 (the int (* f30-0 (sv-256 sv-272 sv-288 a2-6 a3-5 t0-0)))))
                 )
               )
             (logclear! (-> s5-0 flags) (facboss-machine-state-flag fms1))
             )
            (else
              (let ((s0-2 (current-time))
                    (f30-1 300.0)
                    )
                (set! sv-304 lerp-scale)
                (set! sv-320 (the-as float 0.01))
                (set! sv-336 (the-as float 0.2))
                (let* ((v1-84 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                       (v1-85 (the-as number (logior #x3f800000 v1-84)))
                       (a2-7 (+ -1.0 (the-as float v1-85)))
                       (a3-6 0.0)
                       (t0-1 1.0)
                       )
                  (set! (-> s5-0 ring-timer) (+ s0-2 (the int (* f30-1 (sv-304 sv-320 sv-336 a2-7 a3-6 t0-1)))))
                  )
                )
              (logior! (-> s5-0 flags) (facboss-machine-state-flag fms1))
              )
            )
          (cond
            ((logtest? (-> s5-0 flags) (facboss-machine-state-flag fms2))
             (vector-copy! (-> s2-0 trans) s1-0)
             (spawn-from-mat (-> s5-0 damaged-left-spark-part) s2-0)
             (when (>= (- (current-time) (-> s5-0 left-spark-timer)) 0)
               (let ((s1-1 (current-time))
                     (f30-2 300.0)
                     (s0-3 lerp-scale)
                     )
                 (set! sv-352 (the-as float 0.3))
                 (set! sv-368 (the-as float 0.7))
                 (let* ((v1-103 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                        (v1-104 (the-as number (logior #x3f800000 v1-103)))
                        (a2-8 (+ -1.0 (the-as float v1-104)))
                        (a3-7 0.0)
                        (t0-2 1.0)
                        )
                   (set! (-> s5-0 left-spark-timer) (+ s1-1 (the int (* f30-2 (s0-3 sv-352 sv-368 a2-8 a3-7 t0-2)))))
                   )
                 )
               (logclear! (-> s5-0 flags) (facboss-machine-state-flag fms2))
               )
             )
            ((>= (- (current-time) (-> s5-0 left-spark-timer)) 0)
             (let ((s1-2 (current-time))
                   (f30-3 300.0)
                   (s0-4 lerp-scale)
                   )
               (set! sv-384 (the-as float 0.2))
               (set! sv-400 (the-as float 0.4))
               (let* ((v1-117 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                      (v1-118 (the-as number (logior #x3f800000 v1-117)))
                      (a2-9 (+ -1.0 (the-as float v1-118)))
                      (a3-8 0.0)
                      (t0-3 1.0)
                      )
                 (set! (-> s5-0 left-spark-timer) (+ s1-2 (the int (* f30-3 (s0-4 sv-384 sv-400 a2-9 a3-8 t0-3)))))
                 )
               )
             (logior! (-> s5-0 flags) (facboss-machine-state-flag fms2))
             )
            )
          (cond
            ((logtest? (-> s5-0 flags) (facboss-machine-state-flag fms3))
             (vector-copy! (-> s2-0 trans) s3-0)
             (spawn-from-mat (-> s5-0 damaged-right-spark-part) s2-0)
             (when (>= (- (current-time) (-> s5-0 right-spark-timer)) 0)
               (let* ((s3-1 (current-time))
                      (f30-4 300.0)
                      (s2-1 lerp-scale)
                      (s1-3 0.3)
                      (s0-5 0.7)
                      (v1-134 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                      (v1-135 (the-as number (logior #x3f800000 v1-134)))
                      )
                 (set! (-> s5-0 right-spark-timer)
                       (+ s3-1 (the int (* f30-4 (s2-1 s1-3 s0-5 (+ -1.0 (the-as float v1-135)) 0.0 1.0))))
                       )
                 )
               (logclear! (-> s5-0 flags) (facboss-machine-state-flag fms3))
               )
             )
            ((>= (- (current-time) (-> s5-0 right-spark-timer)) 0)
             (let* ((s3-2 (current-time))
                    (f30-5 300.0)
                    (s2-2 lerp-scale)
                    (s1-4 0.2)
                    (s0-6 0.4)
                    (v1-146 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                    (v1-147 (the-as number (logior #x3f800000 v1-146)))
                    )
               (set! (-> s5-0 right-spark-timer)
                     (+ s3-2 (the int (* f30-5 (s2-2 s1-4 s0-6 (+ -1.0 (the-as float v1-147)) 0.0 1.0))))
                     )
               )
             (logior! (-> s5-0 flags) (facboss-machine-state-flag fms3))
             )
            )
          (sound-play "steam-vent" :id (-> s5-0 machine-sound) :position s4-0)
          (logior! (-> s5-0 flags) (facboss-machine-state-flag fms0))
          )
        )
      )
    )
  (dotimes (gp-1 8)
    (let* ((s5-1 (-> self critter gp-1))
           (s4-1 (handle->process (-> s5-1 handle)))
           )
      (when s4-1
        (when (not (logtest? (-> s5-1 flags) (facboss-critter-tracker-flag fct1)))
          (send-event s4-1 'change-nav-mesh (-> self hits-taken))
          (if (send-event s4-1 'jump 2 (-> s5-1 dest))
              (logior! (-> s5-1 flags) (facboss-critter-tracker-flag fct1))
              )
          )
        (when (not (logtest? (-> s5-1 flags) (facboss-critter-tracker-flag fct2)))
          (if (send-event s4-1 'enable-envmap #f)
              (logior! (-> s5-1 flags) (facboss-critter-tracker-flag fct2))
              )
          )
        (when (and (not (logtest? (-> s5-1 flags) (facboss-critter-tracker-flag fct0)))
                   (and (-> s4-1 next-state)
                        (let ((v1-193 (-> s4-1 next-state name)))
                          (or (= v1-193 'die) (= v1-193 'die-falling) (= v1-193 'lift-off) (= v1-193 'explode))
                          )
                        )
                   (< (vector-vector-xz-distance (-> (the-as process-drawable s4-1) root trans) (-> self center)) 122880.0)
                   )
          (logior! (-> s5-1 flags) (facboss-critter-tracker-flag fct0))
          (dotimes (s3-3 10)
            (when (not (handle->process (-> self ammo s3-3)))
              (let ((s2-3 (new 'static 'fact-info)))
                (vector-copy! (new 'stack-no-clear 'vector) (-> (the-as process-drawable s4-1) root trans))
                (set-vector! (new 'stack-no-clear 'vector) 0.0 57001.605 0.0 1.0)
                (set! (-> s2-3 options) (actor-option fade-out fall no-distance-check-fadeout))
                (set! (-> s2-3 fade-time) (seconds 10))
                (set! (-> s2-3 pickup-spawn-amount) 1.0)
                (let* ((v1-210 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                       (v1-211 (the-as number (logior #x3f800000 v1-210)))
                       )
                  (cond
                    ((< (+ -1.0 (the-as float v1-211)) 0.9)
                     (set! (-> s2-3 pickup-type) (pickup-type ammo-random))
                     (set! (-> s2-3 pickup-amount) 10.0)
                     )
                    (else
                      (set! (-> s2-3 pickup-amount) (-> *FACT-bank* health-small-inc))
                      (set! (-> s2-3 pickup-type) (pickup-type health))
                      )
                    )
                  )
                (set! (-> s2-3 process) s4-1)
                (set! (-> self ammo s3-3) (ppointer->handle (drop-pickup s2-3 #t *entity-pool* (the-as fact-info #f) 0 #t)))
                )
              0
              (goto cfg-122)
              )
            )
          )
        (label cfg-122)
        (when (< (-> (the-as process-drawable s4-1) root trans y) (+ -81920.0 (-> self center y)))
          (logior! (-> s5-1 flags) (facboss-critter-tracker-flag fct0))
          (send-event s4-1 'die-fast)
          )
        )
      )
    )
  (none)
  )

(defbehavior factory-boss-always-handler factory-boss ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('complete)
     (go-virtual beaten)
     )
    (('in-cutscene?)
     (and *target* (nonzero? (-> self camera-timer)))
     )
    (('round?)
     (and (and (-> self next-state) (= (-> self next-state name) 'launch-critters))
          (>= (-> self current-round) (the-as int (+ (-> arg3 param 0) -1)))
          )
     )
    )
  )

;; WARN: disable def twice: 10. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare.
(defbehavior factory-boss-handler factory-boss ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (local-vars (v0-1 object))
  (case arg2
    (('child-jumped)
     (let ((v1-1 (as-type arg0 nav-enemy)))
       (when v1-1
         (set! v0-1 (logclear (-> (the-as nav-enemy v1-1) enemy-flags) (enemy-flag directed)))
         (set! (-> (the-as nav-enemy v1-1) enemy-flags) (the-as enemy-flag v0-1))
         v0-1
         )
       )
     )
    (('fall?)
     (let ((v1-2 (-> arg3 param 0))
           (a0-3 (-> arg3 param 1))
           )
       (set! v0-1 #f)
       (when (and (>= (the-as int a0-3) 0) (< (the-as int a0-3) (+ (-> self actor-group-count) -1)))
         (let ((gp-1 (-> self actor-group a0-3)))
           (dotimes (a0-6 (-> gp-1 length))
             (when (= (-> gp-1 data a0-6 actor) v1-2)
               (dotimes (s5-0 (-> gp-1 length))
                 (let ((a1-12 (new 'stack-no-clear 'event-message-block)))
                   (set! (-> a1-12 from) (process->ppointer self))
                   (set! (-> a1-12 num-params) 0)
                   (set! (-> a1-12 message) 'fall!)
                   (let ((t9-1 send-event-function)
                         (v1-7 (-> gp-1 data s5-0 actor))
                         )
                     (t9-1
                       (if v1-7
                           (-> v1-7 extra process)
                           )
                       a1-12
                       )
                     )
                   )
                 )
               (set! v0-1 #t)
               0
               (goto cfg-25)
               )
             )
           )
         )
       )
     (label cfg-25)
     v0-1
     )
    (('draw-reticle)
     (factory-boss-reticle-info-method-10
       (-> self reticle-info)
       (the-as vector (-> arg3 param 0))
       (the-as vector (-> arg3 param 1))
       0
       (the-as int (-> arg3 param 2))
       )
     )
    (else
      (factory-boss-always-handler arg0 arg1 arg2 arg3)
      )
    )
  )

(deftype factory-boss-command (structure)
  ((action  facboss-cmd)
   (suck    float)
   (random  float)
   (round   int8)
   )
  )


(define *factory-boss-swarm-0*
  (new 'static 'boxed-array :type factory-boss-command
    (new 'static 'factory-boss-command :action (facboss-cmd cmd1) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd1) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd1) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd1) :suck 0.3 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd1) :suck 0.6 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd8) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.3 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.6 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.75 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    )
  )

(define *factory-boss-swarm-1*
  (new 'static 'boxed-array :type factory-boss-command
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 0.75 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.3 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.6 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.3 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.6 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.3 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.6 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    )
  )

(define *factory-boss-swarm-2*
  (new 'static 'boxed-array :type factory-boss-command
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.75 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.75 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd9) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd4) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd19) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd4) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd19) :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd4) :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.25 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.5 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.75 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    )
  )

(define *factory-boss-swarm-3*
  (new 'static 'boxed-array :type factory-boss-command
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.75 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd8) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :suck 0.75 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.75 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd1) :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd1) :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd4) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.3 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.6 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd19) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd4) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd3) :suck 0.5 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.25 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.5 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.75 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    )
  )

(define *factory-boss-swarm-4*
  (new 'static 'boxed-array :type factory-boss-command
    (new 'static 'factory-boss-command :action (facboss-cmd cmd6) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd6) :suck 0.5 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd6) :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd8) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd5) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd19) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd5) :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd9) :suck 0.25 :random 1.0 :round 1)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd6) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd9) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd6) :suck 0.5 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 1.0 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.25 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.5 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd2) :suck 0.75 :random 1.0)
    (new 'static 'factory-boss-command :action (facboss-cmd cmd7) :suck 1.0 :random 1.0)
    )
  )

(defbehavior factory-boss-launch-critter-handler factory-boss ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('gonna-getcha)
     (format *stdebug* "gonna-getcha~%")
     (cond
       ((= (-> *game-info* counter) 3.0)
        (send-event self 'gotcha)
        )
       ((zero? (-> self camera-timer))
        (set-time! (-> self camera-timer))
        (process-grab? *target* #f)
        (set! (-> self draw force-lod) 0)
        (let ((v1-10 (-> self chosen-machine)))
          (cond
            ((zero? v1-10)
             (set-setting! 'entity-name "camera-414" 0.0 0)
             )
            ((= v1-10 1)
             (set-setting! 'entity-name "camera-415" 0.0 0)
             )
            ((= v1-10 2)
             (set-setting! 'entity-name "camera-417" 0.0 0)
             )
            ((= v1-10 3)
             (set-setting! 'entity-name "camera-416" 0.0 0)
             )
            )
          )
        )
       )
     )
    (('gotcha)
     (let ((v1-18 (-> self machine-state (-> self chosen-machine))))
       (+! (-> v1-18 state) 1)
       (when (>= (-> v1-18 state) 2)
         (let ((a1-8 (new 'stack-no-clear 'vector))
               (s5-0 (new 'stack-no-clear 'vector))
               (gp-0 (new 'stack-no-clear 'matrix))
               )
           (factory-boss-get-particle-spawn-points (-> self chosen-machine) a1-8 s5-0 gp-0)
           (vector-copy! (-> gp-0 trans) s5-0)
           (if (logtest? (-> *part-group-id-table* 1367 flags) (sp-group-flag sp13))
               (part-tracker-spawn
                 part-tracker-subsampler
                 :to *entity-pool*
                 :group (-> *part-group-id-table* 1367)
                 :mat-joint gp-0
                 )
               (part-tracker-spawn part-tracker :to *entity-pool* :group (-> *part-group-id-table* 1367) :mat-joint gp-0)
               )
           )
         )
       )
     (let ((gp-1 (the-as (pointer process-tree) (-> self child))))
       (while gp-1
         (send-event (ppointer->process gp-1) 'lift-off)
         (set! gp-1 (-> gp-1 0 brother))
         )
       )
     (+! (-> self hits-taken) 1)
     (set! (-> *game-info* counter) (the float (-> self hits-taken)))
     (if (= (-> *game-info* counter) 4.0)
         (go-virtual beaten)
         (go-virtual get-hit)
         )
     #t
     )
    (else
      (factory-boss-handler arg0 arg1 arg2 arg3)
      )
    )
  )

;; WARN: Return type mismatch time-frame vs none.
(defbehavior factory-boss-advance-launch-script factory-boss ()
  (+! (-> self command-index) 1)
  (set-time! (-> self command-timer))
  (none)
  )

(defbehavior factory-boss-check-launch-script factory-boss ()
  (local-vars (v1-20 facboss-cmd))
  (let ((v1-0 *factory-boss-swarm-4*))
    (let ((a0-0 (-> self hits-taken)))
      (cond
        ((zero? a0-0)
         (set! v1-0 *factory-boss-swarm-0*)
         )
        ((= a0-0 1)
         (set! v1-0 *factory-boss-swarm-1*)
         )
        ((= a0-0 2)
         (set! v1-0 *factory-boss-swarm-2*)
         )
        )
      )
    (when (>= (-> self command-index) (-> v1-0 length))
      (set! (-> self command-index) 0)
      (+! (-> self current-round) 1)
      )
    (let ((gp-0 (-> v1-0 (-> self command-index))))
      (cond
        ((or (and (>= (-> gp-0 suck) 0.0) (< (-> gp-0 suck) (you-suck-scale *game-info* #f 0)))
             (and (< (-> gp-0 suck) 0.0) (>= (- (-> gp-0 suck)) (you-suck-scale *game-info* #f 0)))
             )
         (factory-boss-advance-launch-script)
         7
         )
        ((or (and (> (-> gp-0 round) 0) (>= (-> self current-round) (-> gp-0 round)))
             (and (<= (-> gp-0 round) 0) (< (-> self current-round) (- (-> gp-0 round))))
             )
         (factory-boss-advance-launch-script)
         7
         )
        (else
          (let* ((f30-2 (-> gp-0 random))
                 (v1-17 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                 (v1-18 (the-as number (logior #x3f800000 v1-17)))
                 )
            (cond
              ((< f30-2 (+ -1.0 (the-as float v1-18)))
               (factory-boss-advance-launch-script)
               7
               )
              ((begin (set! v1-20 (-> gp-0 action)) (or (= v1-20 (facboss-cmd cmd7))
                                                        (= v1-20 (facboss-cmd cmd8))
                                                        (= v1-20 (facboss-cmd cmd9))
                                                        (= v1-20 (facboss-cmd cmd10))
                                                        (= v1-20 (facboss-cmd cmd11))
                                                        (= v1-20 (facboss-cmd cmd12))
                                                        (= v1-20 (facboss-cmd cmd13))
                                                        (= v1-20 (facboss-cmd cmd14))
                                                        (= v1-20 (facboss-cmd cmd15))
                                                        (= v1-20 (facboss-cmd cmd16))
                                                        (= v1-20 (facboss-cmd cmd17))
                                                        )
                      )
               (let ((v1-21 0))
                 (dotimes (a0-32 8)
                   (if (handle->process (-> self critter a0-32 handle))
                       (+! v1-21 1)
                       )
                   )
                 (when (>= (the-as int (+ (-> gp-0 action) -7)) v1-21)
                   (case (-> gp-0 action)
                     (((facboss-cmd cmd7))
                      (factory-boss-play-speech 5 self)
                      )
                     )
                   (factory-boss-advance-launch-script)
                   )
                 )
               7
               )
              ((or (= v1-20 (facboss-cmd cmd18))
                   (= v1-20 (facboss-cmd cmd19))
                   (= v1-20 (facboss-cmd cmd20))
                   (= v1-20 (facboss-cmd cmd21))
                   )
               (let* ((v1-29 (+ (-> gp-0 action) -18))
                      (a0-44 (shl 1 (the-as int v1-29)))
                      )
                 (if (time-elapsed? (-> self command-timer) (the int (* 300.0 (the float a0-44))))
                     (factory-boss-advance-launch-script)
                     )
                 )
               7
               )
              (else
                (the-as int (-> gp-0 action))
                )
              )
            )
          )
        )
      )
    )
  )

(defbehavior factory-boss-launch-critter factory-boss ((arg0 int))
  (case arg0
    ((7)
     )
    (else
      (dotimes (s2-0 8)
        (let ((s5-0 (-> self critter s2-0)))
          (when (not (handle->process (-> s5-0 handle)))
            (let ((gp-0 (new 'stack-no-clear 'vector))
                  (s4-0 (new 'stack-no-clear 'enemy-init-by-other-params))
                  )
              (when (factory-boss-method-26
                      self
                      (-> self chosen-machine)
                      gp-0
                      (-> s5-0 dest)
                      (the-as symbol (-> self launching-group))
                      )
                (set! (-> s5-0 flags) (facboss-critter-tracker-flag))
                (vector-copy! (-> s4-0 trans) gp-0)
                (quaternion-copy! (-> s4-0 quat) (-> self root quat))
                (set! (-> s4-0 entity) (-> self entity))
                (set! (-> s4-0 directed?) #t)
                (set! (-> s4-0 no-initial-move-to-ground?) #t)
                (set! (-> s4-0 art-level) #f)
                (let ((v1-16 arg0))
                  (cond
                    ((= v1-16 1)
                     (let ((s3-1 (get-process *default-dead-pool* roboguard #x4000 1)))
                       (set! (-> s5-0 handle) (ppointer->handle (when s3-1
                                                                  (let ((t9-3 (method-of-type process activate)))
                                                                    (t9-3 s3-1 self "roboguard" (the-as pointer #x70004000))
                                                                    )
                                                                  (run-now-in-process s3-1 enemy-init-by-other self s4-0)
                                                                  (-> s3-1 ppointer)
                                                                  )
                                                                )
                             )
                       )
                     )
                    ((zero? v1-16)
                     (let ((s3-2 (get-process *default-dead-pool* spydroid-orig #x4000 1)))
                       (set! (-> s5-0 handle) (ppointer->handle (when s3-2
                                                                  (let ((t9-6 (method-of-type process activate)))
                                                                    (t9-6 s3-2 self "spydroid-orig" (the-as pointer #x70004000))
                                                                    )
                                                                  (run-now-in-process s3-2 enemy-init-by-other self s4-0)
                                                                  (-> s3-2 ppointer)
                                                                  )
                                                                )
                             )
                       )
                     )
                    ((= v1-16 2)
                     (let ((s3-3 (get-process *default-dead-pool* missile-bot #x4000 1)))
                       (set! (-> s5-0 handle) (ppointer->handle (when s3-3
                                                                  (let ((t9-9 (method-of-type process activate)))
                                                                    (t9-9 s3-3 self "missile-bot" (the-as pointer #x70004000))
                                                                    )
                                                                  (run-now-in-process s3-3 enemy-init-by-other self s4-0)
                                                                  (-> s3-3 ppointer)
                                                                  )
                                                                )
                             )
                       )
                     (let ((s4-1 (handle->process (-> s5-0 handle))))
                       (when s4-1
                         (factory-boss-pick-pers-camera)
                         (send-event s4-1 'change-nav-mesh (-> self hits-taken))
                         (if (send-event s4-1 'jump 2 (-> s5-0 dest))
                             (logior! (-> s5-0 flags) (facboss-critter-tracker-flag fct1))
                             )
                         )
                       )
                     )
                    ((= v1-16 3)
                     (let ((s3-4 (get-process *default-dead-pool* kg-grunt #x4000 1)))
                       (set! (-> s5-0 handle) (ppointer->handle (when s3-4
                                                                  (let ((t9-15 (method-of-type process activate)))
                                                                    (t9-15 s3-4 self "kg-grunt" (the-as pointer #x70004000))
                                                                    )
                                                                  (run-now-in-process s3-4 enemy-init-by-other self s4-0)
                                                                  (-> s3-4 ppointer)
                                                                  )
                                                                )
                             )
                       )
                     )
                    ((= v1-16 4)
                     (set! (-> s4-0 directed?) #f)
                     (let ((s3-5 (get-process *default-dead-pool* robo-hover #x4000 1)))
                       (set! (-> s5-0 handle) (ppointer->handle (when s3-5
                                                                  (let ((t9-18 (method-of-type process activate)))
                                                                    (t9-18 s3-5 self "robo-hover" (the-as pointer #x70004000))
                                                                    )
                                                                  (run-now-in-process s3-5 enemy-init-by-other self s4-0)
                                                                  (-> s3-5 ppointer)
                                                                  )
                                                                )
                             )
                       )
                     (logior! (-> s5-0 flags) (facboss-critter-tracker-flag fct1))
                     )
                    ((= v1-16 5)
                     (set! (-> s4-0 directed?) #f)
                     (let ((s3-6 (get-process *default-dead-pool* neo-wasp #x4000 1)))
                       (set! (-> s5-0 handle) (ppointer->handle (when s3-6
                                                                  (let ((t9-21 (method-of-type process activate)))
                                                                    (t9-21 s3-6 self "neo-wasp" (the-as pointer #x70004000))
                                                                    )
                                                                  (run-now-in-process s3-6 enemy-init-by-other self s4-0)
                                                                  (-> s3-6 ppointer)
                                                                  )
                                                                )
                             )
                       )
                     (logior! (-> s5-0 flags) (facboss-critter-tracker-flag fct1))
                     )
                    ((= v1-16 6)
                     (let ((s3-7 (get-process *default-dead-pool* dp-bipedal #x4000 1)))
                       (set! (-> s5-0 handle) (ppointer->handle (when s3-7
                                                                  (let ((t9-24 (method-of-type process activate)))
                                                                    (t9-24 s3-7 self "dp-bipedal" (the-as pointer #x70004000))
                                                                    )
                                                                  (run-now-in-process s3-7 enemy-init-by-other self s4-0)
                                                                  (-> s3-7 ppointer)
                                                                  )
                                                                )
                             )
                       )
                     )
                    (else
                      (format 0 "~A can't launch unknown critter type ~D~%" (-> self name) arg0)
                      (return #t)
                      )
                    )
                  )
                (cond
                  ((handle->process (-> s5-0 handle))
                   (let ((s4-2 (new 'stack-no-clear 'matrix)))
                     (vector-! (-> s4-2 uvec) (-> s5-0 dest) gp-0)
                     (set! (-> s4-2 uvec y) 0.0)
                     (vector-normalize! (-> s4-2 uvec) 1.0)
                     (set! (-> s4-2 uvec w) 0.0)
                     (set-vector! (-> s4-2 fvec) 0.0 1.0 0.0 0.0)
                     (vector-cross! (-> s4-2 rvec) (-> s4-2 uvec) (-> s4-2 fvec))
                     (set! (-> s4-2 rvec w) 0.0)
                     (vector-copy! (-> s4-2 trans) gp-0)
                     (+! (-> s4-2 trans y) 8192.0)
                     (set! (-> s4-2 trans w) 1.0)
                     (if (logtest? (-> *part-group-id-table* 1377 flags) (sp-group-flag sp13))
                         (part-tracker-spawn
                           part-tracker-subsampler
                           :to *entity-pool*
                           :group (-> *part-group-id-table* 1377)
                           :duration (seconds 1)
                           :mat-joint s4-2
                           )
                         (part-tracker-spawn
                           part-tracker
                           :to *entity-pool*
                           :group (-> *part-group-id-table* 1377)
                           :duration (seconds 1)
                           :mat-joint s4-2
                           )
                         )
                     )
                   (return #t)
                   )
                  (else
                    (return #f)
                    )
                  )
                (the-as none 0)
                )
              )
            )
          )
        )
      )
    )
  #f
  )

(defstate beaten (factory-boss)
  :virtual #t
  :enter (behavior ()
    (logior! (-> self draw status) (draw-control-status no-draw))
    (dotimes (gp-0 8)
      (let ((a0-5 (as-type (handle->process (-> self critter gp-0 handle)) process-focusable)))
        (if a0-5
            (send-event a0-5 'die-fast)
            )
        )
      )
    (let ((gp-1 (the-as (pointer process-tree) (-> self child))))
      (while gp-1
        (let ((a0-6 (-> (the-as (pointer process) gp-1) 0 entity))
              (s5-1 gp-1)
              )
          (set! gp-1 (-> gp-1 0 brother))
          (if (and a0-6 (nonzero? (res-lump-value a0-6 'drop-from-movie uint128 :time -1000000000.0)))
              (deactivate (-> s5-1 0))
              )
          )
        )
      )
    (disable (-> self warp-blocker))
    (disable (-> self entry-blocker))
    (factory-boss-end-cutscene)
    (ja-post)
    )
  :code sleep-code
  )

(defstate run-to-machine (factory-boss)
  :virtual #t
  :event factory-boss-handler
  :enter (behavior ()
    (factory-boss-pick-machine)
    )
  :trans (behavior ()
    (factory-boss-always)
    (if (factory-boss-move-to-dest-angle (factory-boss-machine-angle) 145.63556)
        (go-virtual drop-bombs)
        )
    (let ((v1-6 (ja-group)))
      (cond
        ((and v1-6 (or (= v1-6 errol-lowres-run-cw-ja) (= v1-6 errol-lowres-run-ccw-ja)))
         (ja :num! (loop!))
         )
        ((let ((v1-14 (ja-group)))
           (and v1-14 (= v1-14 errol-lowres-idle-to-run-ccw-ja))
           )
         (ja :num! (seek!))
         (if (ja-done? 0)
             (ja :group! errol-lowres-run-ccw-ja :num! min)
             )
         )
        ((let ((v1-31 (ja-group)))
           (and v1-31 (= v1-31 errol-lowres-idle-to-run-cw-ja))
           )
         (ja :num! (seek!))
         (if (ja-done? 0)
             (ja :group! errol-lowres-run-cw-ja :num! min)
             )
         )
        ((< 0.0 (-> self catwalk-vel))
         (ja-channel-push! 1 (seconds 0.1))
         (ja :group! errol-lowres-idle-to-run-ccw-ja :num! min)
         )
        (else
          (ja-channel-push! 1 (seconds 0.1))
          (ja :group! errol-lowres-idle-to-run-cw-ja :num! min)
          )
        )
      )
    )
  :code sleep-code
  :post ja-post
  )

(defstate get-hit (factory-boss)
  :virtual #t
  :event factory-boss-handler
  :enter (behavior ()
    (factory-boss-play-speech 6 self)
    )
  :exit (behavior ()
    (factory-boss-end-cutscene)
    )
  :trans (behavior ()
    (factory-boss-always)
    (let ((v1-2 (ja-group)))
      (cond
        ((and v1-2 (= v1-2 errol-lowres-idle-knocked-ja))
         (ja :num! (seek!))
         (if (ja-done? 0)
             (go-virtual run-to-machine)
             )
         )
        (else
          (ja-channel-push! 1 (seconds 0.05))
          (ja :group! errol-lowres-idle-knocked-ja :num! min)
          )
        )
      )
    )
  :code sleep-code
  :post ja-post
  )

;; WARN: Return type mismatch object vs none.
(defbehavior factory-boss-launch-critter-pick-anim factory-boss ((arg0 int))
  (let* ((v1-1 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
         (v1-2 (the-as number (logior #x3f800000 v1-1)))
         (f0-2 (+ -1.0 (the-as float v1-2)))
         )
    (cond
      ((!= arg0 7)
       (ja-channel-push! 1 (seconds 0.1))
       (ja :group! errol-lowres-idle-hit-console-2-ja :num! min)
       (let ((v1-10 (-> self hits-taken)))
         (if (or (zero? v1-10) (= v1-10 1) (= v1-10 2) (= v1-10 3))
             (factory-boss-play-speech 3 self)
             (factory-boss-play-speech 4 self)
             )
         )
       )
      ((and (< f0-2 0.4) (let ((v1-17 (ja-group)))
                           (not (and v1-17 (= v1-17 errol-lowres-idle30-ja)))
                           )
            )
       (ja-channel-push! 1 (seconds 0.1))
       (ja :group! errol-lowres-idle30-ja :num! min)
       )
      ((and (or (< f0-2 0.8) (let ((v1-29 (ja-group)))
                               (and v1-29 (or (= v1-29 errol-lowres-idle-yell-ja) (= v1-29 errol-lowres-idle-yell-1-ja)))
                               )
                )
            (let ((v1-35 (ja-group)))
              (not (and v1-35 (= v1-35 errol-lowres-idle60-ja)))
              )
            )
       (ja-channel-push! 1 (seconds 0.1))
       (ja :group! errol-lowres-idle60-ja :num! min)
       )
      ((< f0-2 0.9)
       (ja-channel-push! 1 (seconds 0.1))
       (ja :group! errol-lowres-idle-yell-ja :num! min)
       )
      (else
        (ja-channel-push! 1 (seconds 0.1))
        (ja :group! errol-lowres-idle-yell-1-ja :num! min)
        )
      )
    )
  (none)
  )

(defstate launch-critters (factory-boss)
  :virtual #t
  :event factory-boss-launch-critter-handler
  :enter (behavior ()
    (set! (-> self command-index) 0)
    (set! (-> self command-timer) 0)
    (set! (-> self current-round) 0)
    (set! (-> self launching-group) #f)
    (let ((a0-1 (nav-mesh-from-res-tag (-> self entity) 'nav-mesh-actor (-> self hits-taken))))
      (if a0-1
          (change-to a0-1 self)
          )
      )
    )
  :exit (behavior ()
    (if (zero? (-> self camera-timer))
        (factory-boss-end-cutscene)
        )
    )
  :trans (behavior ()
    (let ((gp-0 (factory-boss-check-launch-script))
          (v1-2 (ja-group))
          )
      (cond
        ((and v1-2 (or (= v1-2 errol-lowres-idle-hit-console-ja) (= v1-2 errol-lowres-idle-hit-console-2-ja)))
         (let ((f30-0 (ja-aframe-num 0))
               (f28-0 60.0)
               )
           (let ((v1-8 (ja-group)))
             (if (and v1-8 (= v1-8 errol-lowres-idle-hit-console-2-ja))
                 (set! f28-0 17.0)
                 )
             )
           (ja :num! (seek!))
           (when (and (or (-> self launching-group) (and (>= (ja-aframe-num 0) f28-0) (< f30-0 f28-0)))
                      (factory-boss-launch-critter gp-0)
                      )
             (set! (-> self launching-group) (the-as sparticle-launch-group #t))
             (factory-boss-advance-launch-script)
             )
           )
         (if (ja-done? 0)
             (factory-boss-launch-critter-pick-anim gp-0)
             )
         )
        ((or (!= gp-0 7) (let ((v1-35 (ja-group)))
                           (not (and v1-35 (or (= v1-35 errol-lowres-idle30-ja) (= v1-35 errol-lowres-idle60-ja))))
                           )
             )
         (ja :num! (seek!))
         (when (ja-done? 0)
           (set! (-> self launching-group) #f)
           (factory-boss-launch-critter-pick-anim gp-0)
           )
         )
        (else
          (ja :num! (loop!))
          )
        )
      )
    (factory-boss-always)
    )
  :code sleep-code
  :post ja-post
  )

(defbehavior factory-boss-pick-floor-targets factory-boss ((arg0 int) (arg1 int))
  (let ((v1-1 (min 7 arg1)))
    (set! (-> self num-floor-targets) 0)
    (dotimes (a1-1 (+ (-> self actor-group-count) -1))
      (let ((a3-1 (-> self actor-group a1-1)))
        (when (and (nonzero? v1-1)
                   (>= arg0 a1-1)
                   (not (logtest? (-> a3-1 data 0 actor extra perm status) (entity-perm-status subtask-complete)))
                   )
          (set! (-> self floor-targets (-> self num-floor-targets)) a1-1)
          (+! (-> self num-floor-targets) 1)
          (+! v1-1 -1)
          )
        )
      )
    )
  (set! (-> self bombs-to-drop) (-> self num-floor-targets))
  (set! (-> self bomb-type) (facboss-bomb-type bomb1))
  0
  (none)
  )

(defstate drop-bombs (factory-boss)
  :virtual #t
  :event factory-boss-handler
  :enter (behavior ()
    (let ((v1-0 (-> self hits-taken)))
      (cond
        ((zero? v1-0)
         (set! (-> self shot-timer) (+ (current-time) (seconds 3)))
         (set! (-> self bombs-to-drop) 4)
         (set! (-> self bomb-type) (facboss-bomb-type bomb0))
         0
         )
        ((= v1-0 1)
         (set! (-> self shot-timer) 0)
         (set! (-> self bombs-to-drop) 3)
         (set! (-> self bomb-type) (facboss-bomb-type bomb2))
         )
        (else
          (set! (-> self shot-timer) 0)
          (set! (-> self bombs-to-drop) 4)
          (set! (-> self bomb-type) (facboss-bomb-type bomb2))
          )
        )
      )
    (factory-boss-pick-camera)
    )
  :exit (behavior ()
    (factory-boss-end-cutscene)
    (factory-boss-method-30 self)
    )
  :trans (behavior ()
    (when (and (<= (-> self bombs-to-drop) 0) (let ((v1-4 (ja-group)))
                                                (not (and v1-4 (= v1-4 errol-lowres-idle-throw-ja)))
                                                )
               )
      (let ((a1-0 0)
            (a0-5 0)
            (gp-0 0)
            )
        (let ((v1-8 (-> self hits-taken)))
          (cond
            ((zero? v1-8)
             )
            ((= v1-8 1)
             (set! a1-0 7)
             (set! a0-5 6)
             (set! gp-0 4)
             )
            ((= v1-8 2)
             (set! a1-0 7)
             (set! a0-5 13)
             (set! gp-0 4)
             )
            (else
              (set! a1-0 7)
              (set! a0-5 100)
              (set! gp-0 4)
              )
            )
          )
        (case (-> self bomb-type)
          (((facboss-bomb-type bomb2) (facboss-bomb-type bomb1))
           (factory-boss-pick-floor-targets a0-5 a1-0)
           (cond
             ((zero? (-> self bombs-to-drop))
              (set! (-> self bombs-to-drop) gp-0)
              (set! (-> self bomb-type) (facboss-bomb-type bomb0))
              0
              )
             (else
               (set! (-> self shot-timer) (+ (current-time) (the int (* 300.0 (rand-vu-float-range 1.0 2.0)))))
               )
             )
           )
          (else
            (go-virtual launch-critters)
            )
          )
        )
      )
    (if (and (= (-> self bomb-type) (facboss-bomb-type bomb1))
             (< (-> self num-floor-targets) (-> self bombs-to-drop))
             )
        (set! (-> self bombs-to-drop) (-> self num-floor-targets))
        )
    (factory-boss-always)
    (factory-boss-move)
    (factory-boss-check-bomb-timer (the-as int (-> self bomb-type)))
    )
  :code sleep-code
  :post ja-post
  )

(defstate hidden (factory-boss)
  :virtual #t
  :event factory-boss-always-handler
  :enter (behavior ()
    (logior! (-> self draw status) (draw-control-status no-draw))
    (set! (-> self chosen-machine) 0)
    (set! (-> self catwalk-angle) (factory-boss-machine-angle))
    (set! (-> self root-angle) (+ 32768.0 (-> self catwalk-angle)))
    (set! (-> self catwalk-vel) 0.0)
    (reset-factory-boss-speeches)
    (ja-post)
    )
  :exit (behavior ()
    (logclear! (-> self draw status) (draw-control-status no-draw))
    )
  :trans (behavior ()
    (cond
      ((task-node-closed? (game-task-node factory-boss-resolution))
       (go-virtual beaten)
       )
      ((task-node-closed? (game-task-node factory-boss-introduction))
       (go-virtual drop-bombs)
       )
      )
    )
  :code sleep-code
  )
