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

;; name: terraformer-head.gc
;; name in dgo: terraformer-head
;; dgos: DESBOSS2

;; +++terraformer-head-speech-instance-flag
(defenum terraformer-head-speech-instance-flag
  :type uint64
  :bitfield #t
  (thsi0 0)
  (thsi1 1)
  (thsi2 2)
  (thsi3 3)
  (thsi4 4)
  )
;; ---terraformer-head-speech-instance-flag


;; +++terraformer-head-speech-info-flag
(defenum terraformer-head-speech-info-flag
  :type uint8
  :bitfield #t
  (thsi0 0)
  (thsi1 1)
  )
;; ---terraformer-head-speech-info-flag


;; +++jmod-disc-lookat-flag
(defenum jmod-disc-lookat-flag
  :type uint32
  :bitfield #t
  (blend 0)
  (jdl1 1)
  (jdl2 2)
  )
;; ---jmod-disc-lookat-flag


;; +++terraformer-head-critter-tracker-flag
(defenum terraformer-head-critter-tracker-flag
  :type uint32
  :bitfield #t
  (thct0 0)
  (thct1 1)
  (thct2 2)
  )
;; ---terraformer-head-critter-tracker-flag


;; +++terraformer-head-flag
(defenum terraformer-head-flag
  :type uint64
  :bitfield #t
  (th0 0)
  (th1 1)
  (th2 2)
  (track-target 3)
  (laser 4)
  (laser-sound-playing 5)
  (laser-warmup-sound-playing 6)
  (th7 7)
  (th8 8)
  )
;; ---terraformer-head-flag


;; +++terraformer-head-cmd-action
(defenum terraformer-head-cmd-action
  :type uint64
  (cmd1 1)
  (cmd2 2)
  (cmd3 3)
  (extend-tentacles 4)
  (retract-tentacles 5)
  (start-laser 6)
  (stop-laser 7)
  (open-light-vent 8)
  (close-light-vent 9)
  (open-dark-vent 10)
  (close-dark-vent 11)
  (slam 12)
  (swing-laser 13)
  (spawn-critters 14)
  (wait 15)
  )
;; ---terraformer-head-cmd-action


(declare-type terraformer-head process-focusable)
(define-extern joint-mod-disc-look-at-callback (function cspace transformq none))

;; DECOMP BEGINS

(deftype terraformer-head-speech-instance (structure)
  ((speech       basic)
   (probability  float)
   (flags        terraformer-head-speech-instance-flag)
   (play-count   uint32)
   )
  )


(deftype terraformer-head-speech-info (structure)
  ((speeches          (array terraformer-head-speech-instance))
   (play-time         time-frame)
   (current-random    time-frame)
   (minimum-interval  time-frame)
   (random-interval   time-frame)
   (last-played       int8)
   (flags             terraformer-head-speech-info-flag)
   )
  )


(deftype terraformer-head-speech-group (structure)
  ((play-time  time-frame)
   (info       (array terraformer-head-speech-info))
   )
  )


(define *terraformer-head-speech*
  (new 'static 'terraformer-head-speech-group
    :info (new 'static 'boxed-array :type terraformer-head-speech-info
      (new 'static 'terraformer-head-speech-info
        :speeches (new 'static 'boxed-array :type terraformer-head-speech-instance
          (new 'static 'terraformer-head-speech-instance :speech "erolt101" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot007" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot023" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot024" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot027" :probability 1.0)
          )
        :minimum-interval (seconds 20)
        :random-interval (seconds 4)
        :flags (terraformer-head-speech-info-flag thsi0)
        )
      (new 'static 'terraformer-head-speech-info
        :speeches (new 'static 'boxed-array :type terraformer-head-speech-instance
          (new 'static 'terraformer-head-speech-instance :speech "erolt105" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance
            :speech "erolt107"
            :probability 1.0
            :flags (terraformer-head-speech-instance-flag thsi2)
            )
          (new 'static 'terraformer-head-speech-instance :speech "erot004" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot013" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot020" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot022" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot005" :probability 1.0)
          )
        :minimum-interval (seconds 20)
        :random-interval (seconds 5)
        :flags (terraformer-head-speech-info-flag thsi0)
        )
      (new 'static 'terraformer-head-speech-info
        :speeches (new 'static 'boxed-array :type terraformer-head-speech-instance
          (new 'static 'terraformer-head-speech-instance :speech "erot014" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot017" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot035" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot059" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot037" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot038" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot075" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot072" :probability 1.0)
          )
        :minimum-interval (seconds 9)
        )
      (new 'static 'terraformer-head-speech-info
        :speeches (new 'static 'boxed-array :type terraformer-head-speech-instance
          (new 'static 'terraformer-head-speech-instance :speech "erot042" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot098" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot099" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot100" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot101" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot102" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot103" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot104" :probability 1.0)
          )
        :minimum-interval (seconds 3)
        )
      (new 'static 'terraformer-head-speech-info
        :speeches (new 'static 'boxed-array :type terraformer-head-speech-instance
          (new 'static 'terraformer-head-speech-instance :speech "erot074" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot073" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot041" :probability 1.0)
          (new 'static 'terraformer-head-speech-instance :speech "erot019" :probability 1.0)
          )
        :minimum-interval (seconds 20)
        :random-interval (seconds 5)
        :flags (terraformer-head-speech-info-flag thsi0)
        )
      )
    )
  )

;; WARN: Return type mismatch symbol vs none.
(defbehavior reset-terraformer-head-speeches terraformer-head ()
  (set! (-> *terraformer-head-speech* play-time) 0)
  (dotimes (v1-1 (-> *terraformer-head-speech* info length))
    (let ((a0-2 (-> *terraformer-head-speech* info v1-1)))
      (dotimes (a1-2 (-> a0-2 speeches length))
        (set! (-> a0-2 speeches a1-2 play-count) (the-as uint 0))
        )
      (set! (-> a0-2 play-time) 0)
      (set! (-> a0-2 current-random) 0)
      (set! (-> a0-2 last-played) -1)
      )
    )
  (none)
  )

;; WARN: Function terraformer-head-play-speech has a return type of none, but the expression builder found a return statement.
(defun terraformer-head-play-speech ((arg0 int) (arg1 terraformer-head))
  (if (not (task-node-closed? (game-task-node desert-final-boss-climb)))
      (return 0)
      )
  (let ((gp-1 (-> *terraformer-head-speech* info arg0)))
    (if (zero? (-> gp-1 speeches length))
        (return 0)
        )
    (if (logtest? (-> gp-1 flags) (terraformer-head-speech-info-flag thsi0))
        (set! (-> gp-1 play-time) (-> *terraformer-head-speech* play-time))
        )
    (if (not (time-elapsed? (-> gp-1 play-time) (+ (-> gp-1 minimum-interval) (-> gp-1 current-random))))
        (return 0)
        )
    (let ((f30-0 0.0)
          (s4-0 (-> gp-1 speeches 0 play-count))
          )
      (dotimes (v1-20 (-> gp-1 speeches length))
        (let ((a0-9 (-> gp-1 speeches v1-20)))
          (cond
            ((or (< s4-0 (-> a0-9 play-count))
                 (and (logtest? (-> a0-9 flags) (terraformer-head-speech-instance-flag thsi1)) (nonzero? (-> gp-1 play-time)))
                 (and (logtest? (-> a0-9 flags) (terraformer-head-speech-instance-flag thsi2)) (zero? (-> gp-1 play-time)))
                 (and (logtest? (-> a0-9 flags) (terraformer-head-speech-instance-flag thsi0)) (> (-> a0-9 play-count) 0))
                 (and (not (logtest? (-> a0-9 flags) (terraformer-head-speech-instance-flag thsi3)))
                      (= (-> gp-1 last-played) v1-20)
                      )
                 )
             (logclear! (-> a0-9 flags) (terraformer-head-speech-instance-flag thsi4))
             )
            ((= (-> a0-9 play-count) s4-0)
             (+! f30-0 (-> a0-9 probability))
             (logior! (-> a0-9 flags) (terraformer-head-speech-instance-flag thsi4))
             )
            (else
              (set! s4-0 (-> a0-9 play-count))
              (set! f30-0 (-> a0-9 probability))
              (logior! (-> a0-9 flags) (terraformer-head-speech-instance-flag thsi4))
              )
            )
          )
        )
      (let ((f0-2 (* f30-0 (rand-vu))))
        (dotimes (s3-0 (-> gp-1 speeches length))
          (let ((s2-0 (-> gp-1 speeches s3-0)))
            (cond
              ((or (not (logtest? (-> s2-0 flags) (terraformer-head-speech-instance-flag thsi4)))
                   (< s4-0 (-> s2-0 play-count))
                   )
               )
              ((or (>= (-> s2-0 probability) f0-2) (logtest? (-> s2-0 flags) (terraformer-head-speech-instance-flag thsi1)))
               (let ((a1-28 (add-process
                              *gui-control*
                              arg1
                              (gui-channel sig)
                              (gui-action play)
                              (the-as string (-> s2-0 speech))
                              81920.0
                              0
                              )
                            )
                     )
                 (when (sound-params-set! *gui-control* a1-28 #f -1 -1 -1 (* 4.0 (-> *setting-control* user-current talker-volume)))
                   (set! (-> s2-0 play-count) (+ s4-0 1))
                   (set-time! (-> *terraformer-head-speech* play-time))
                   (set-time! (-> gp-1 play-time))
                   (set! (-> gp-1 current-random)
                         (the-as time-frame (the int (* (rand-vu) (the float (-> gp-1 random-interval)))))
                         )
                   (set! (-> gp-1 last-played) s3-0)
                   )
                 )
               (return 0)
               )
              (else
                (set! f0-2 (- f0-2 (-> gp-1 speeches s3-0 probability)))
                )
              )
            )
          )
        )
      )
    )
  0
  (none)
  )

(defskelgroup skel-terraformer-head-ingame terraformer-head terraformer-head-lod0-jg terraformer-head-idle-ja
              ((terraformer-head-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 110)
              :shadow terraformer-head-shadow-mg
              :origin-joint-index 7
              :shadow-joint-index 7
              )

(deftype joint-mod-disc-look-at (basic)
  ((flags              jmod-disc-lookat-flag)
   (up                 int8)
   (nose               int8)
   (target             vector  :inline)
   (blend-duration     time-frame)
   (blend-start-time   time-frame)
   (blend-start-value  float)
   (blend-max          float)
   )
  (:methods
    (initialize (_type_ process-drawable int) none)
    (set-target! (_type_ vector) none)
    (blend-on! (_type_ time-frame float symbol) none)
    (blend-to-off! (_type_ time-frame symbol) none)
    (get-blend-lerped (_type_) float)
    )
  )


;; WARN: Return type mismatch float vs none.
(defmethod initialize ((this joint-mod-disc-look-at) (arg0 process-drawable) (arg1 int))
  (let ((a1-2 (-> arg0 node-list data arg1)))
    (set! (-> a1-2 param0) joint-mod-disc-look-at-callback)
    (set! (-> a1-2 param1) this)
    )
  (set! (-> this flags) (jmod-disc-lookat-flag blend))
  (set! (-> this up) 1)
  (set! (-> this nose) 2)
  (set! (-> this blend-duration) 0)
  (set! (-> this blend-start-value) 0.0)
  (set! (-> this blend-max) 1.0)
  (none)
  )

(defmethod set-target! ((this joint-mod-disc-look-at) (arg0 vector))
  (vector-copy! (-> this target) arg0)
  0
  (none)
  )

(defmethod blend-on! ((this joint-mod-disc-look-at) (arg0 time-frame) (arg1 float) (arg2 symbol))
  (cond
    ((and (not arg2) (not (logtest? (-> this flags) (jmod-disc-lookat-flag blend))))
     )
    ((zero? arg0)
     (set! (-> this blend-start-value) arg1)
     (set! (-> this blend-max) arg1)
     (set! (-> this blend-duration) arg0)
     (logclear! (-> this flags) (jmod-disc-lookat-flag blend))
     )
    (else
      (set-time! (-> this blend-start-time))
      (set! (-> this blend-start-value) (get-blend-lerped this))
      (set! (-> this blend-max) arg1)
      (set! (-> this blend-duration) arg0)
      (logclear! (-> this flags) (jmod-disc-lookat-flag blend))
      )
    )
  0
  (none)
  )

(defmethod blend-to-off! ((this joint-mod-disc-look-at) (arg0 time-frame) (arg1 symbol))
  (cond
    ((and (not arg1) (logtest? (-> this flags) (jmod-disc-lookat-flag blend)))
     )
    ((zero? arg0)
     (set! (-> this blend-start-value) 0.0)
     (set! (-> this blend-duration) arg0)
     (logior! (-> this flags) (jmod-disc-lookat-flag blend))
     )
    (else
      (set-time! (-> this blend-start-time))
      (set! (-> this blend-start-value) (get-blend-lerped this))
      (set! (-> this blend-duration) arg0)
      (logior! (-> this flags) (jmod-disc-lookat-flag blend))
      )
    )
  0
  (none)
  )

(defmethod get-blend-lerped ((this joint-mod-disc-look-at))
  (local-vars (f0-2 float))
  (cond
    ((zero? (-> this blend-duration))
     (-> this blend-start-value)
     )
    ((begin
       (set! f0-2 (the float (- (current-time) (-> this blend-start-time))))
       (logtest? (-> this flags) (jmod-disc-lookat-flag blend))
       )
     (let ((f0-5 (lerp-scale (-> this blend-start-value) 0.0 f0-2 0.0 (the float (-> this blend-duration)))))
       (when (= f0-5 0.0)
         (set! (-> this blend-start-value) f0-5)
         (set! (-> this blend-duration) 0)
         0
         )
       f0-5
       )
     )
    (else
      (let ((f0-8
              (lerp-scale (-> this blend-start-value) (-> this blend-max) f0-2 0.0 (the float (-> this blend-duration)))
              )
            )
        (when (>= f0-8 (-> this blend-max))
          (set! (-> this blend-start-value) f0-8)
          (set! (-> this blend-duration) 0)
          0
          )
        f0-8
        )
      )
    )
  )

(defun joint-mod-disc-look-at-callback ((arg0 cspace) (arg1 transformq))
  (let* ((s4-0 (the-as joint-mod-disc-look-at (-> arg0 param1)))
         (f30-0 (get-blend-lerped s4-0))
         )
    (cspace<-parented-transformq-joint! arg0 arg1)
    (when (< 0.0 f30-0)
      (let* ((t9-2 vector-normalize-copy!)
             (a0-3 (new 'stack-no-clear 'vector))
             (v1-3 (abs (-> s4-0 nose)))
             (s3-0 (t9-2 a0-3 (the-as vector (&-> arg0 bone transform quad v1-3)) 1.0))
             (t9-3 vector-normalize-copy!)
             (a0-4 (new 'stack-no-clear 'vector))
             (v1-6 (abs (-> s4-0 up)))
             (s1-0 (t9-3 a0-4 (the-as vector (&-> arg0 bone transform quad v1-6)) 1.0))
             (s2-1 (vector-! (new 'stack-no-clear 'vector) (-> s4-0 target) (-> arg0 bone transform trans)))
             (s5-1 (new 'stack-no-clear 'matrix))
             )
        (if (logtest? (-> s4-0 flags) (jmod-disc-lookat-flag jdl1))
            (vector-negate! s3-0 s3-0)
            )
        (vector-flatten! s2-1 s2-1 s1-0)
        (vector-normalize! s2-1 1.0)
        (if (< f30-0 1.0)
            (matrix-from-two-vectors-partial-linear! s5-1 s3-0 s2-1 f30-0)
            (matrix-from-two-vectors! s5-1 s3-0 s2-1)
            )
        (let ((s4-1 (matrix->trans (-> arg0 bone transform) (new 'stack-no-clear 'vector))))
          (set-vector! (-> arg0 bone transform trans) 0.0 0.0 0.0 1.0)
          (matrix*! (-> arg0 bone transform) (-> arg0 bone transform) s5-1)
          (vector-copy! (-> arg0 bone transform trans) s4-1)
          )
        )
      )
    )
  0
  (none)
  )

(deftype terraformer-head-target (process-focusable)
  ((parent    (pointer terraformer-head) :override)
   (been-hit  symbol)
   )
  (:state-methods
    idle
    )
  )


;; WARN: Return type mismatch int vs search-info-flag.
(defmethod get-search-info-flag ((this terraformer-head-target))
  "Get search-info-flag for this process."
  (the-as search-info-flag 16)
  )

(defstate idle (terraformer-head-target)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('attack)
       (when (not (-> self been-hit))
         (set! (-> self been-hit) #t)
         (send-event (ppointer->process (-> self parent)) 'get-hit)
         )
       )
      )
    )
  :code sleep-code
  :post transform-post
  )

;; WARN: Return type mismatch object vs none.
(defbehavior terraformer-head-target-init-by-other terraformer-head-target ()
  (let ((gp-0 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
    (set! (-> gp-0 penetrated-by) (the-as penetrate -1))
    (let ((v1-3 (new 'process 'collide-shape-prim-sphere gp-0 (the-as uint 0))))
      (set! (-> v1-3 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-3 prim-core collide-with) (collide-spec hit-by-others-list player-list projectile))
      (set! (-> v1-3 prim-core action) (collide-action solid))
      (set! (-> v1-3 transform-index) 3)
      (set-vector! (-> v1-3 local-sphere) -8601.6 2048.0 0.0 22528.0)
      (set! (-> gp-0 total-prims) (the-as uint 1))
      (set! (-> gp-0 root-prim) v1-3)
      )
    (set! (-> gp-0 nav-radius) (* 0.75 (-> gp-0 root-prim local-sphere w)))
    (let ((v1-6 (-> gp-0 root-prim)))
      (set! (-> gp-0 backup-collide-as) (-> v1-6 prim-core collide-as))
      (set! (-> gp-0 backup-collide-with) (-> v1-6 prim-core collide-with))
      )
    (set! (-> self root) gp-0)
    )
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-blocking-plane" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (logior! (-> self draw status) (draw-control-status no-draw-bounds))
  (vector<-cspace! (-> self root trans) (-> (ppointer->process (-> self parent)) node-list data 39))
  (logclear! (-> self mask) (process-mask actor-pause))
  (logior! (-> self mask) (process-mask enemy))
  (set! (-> self been-hit) #f)
  (let ((v1-23 (-> self node-list data)))
    (set! (-> v1-23 0 param0) (the-as (function cspace transformq none) cspace<-parent-joint!))
    (set! (-> v1-23 0 param1) (the-as basic (-> self parent)))
    (set! (-> v1-23 0 param2) (the-as basic 39))
    )
  (go-virtual idle)
  (none)
  )

(deftype terraformer-head-laser-projectile (projectile)
  ()
  )


(defmethod setup-collision! ((this terraformer-head-laser-projectile))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (let ((v1-6 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-6 prim-core collide-as) (collide-spec projectile))
      (set! (-> v1-6 prim-core collide-with)
            (collide-spec backgnd jak enemy obstacle hit-by-others-list player-list)
            )
      (set! (-> v1-6 prim-core action) (collide-action solid))
      (set-vector! (-> v1-6 local-sphere) 0.0 0.0 0.0 3072.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-6)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-9 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-9 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-9 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 1))
    (set! (-> s5-0 event-self) 'touched)
    (set! (-> this root) s5-0)
    )
  (set! (-> this root pat-ignore-mask)
        (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noproj #x1 :noendlessfall #x1 :board #x1)
        )
  0
  (none)
  )

(defmethod init-proj-settings! ((this terraformer-head-laser-projectile))
  (set! (-> this attack-mode) 'eco-dark)
  (set! (-> this event-hook) (-> (method-of-object this moving) event))
  ((method-of-type projectile init-proj-settings!) this)
  0
  (none)
  )

(defstate moving (terraformer-head-laser-projectile)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (local-vars (at-0 int))
    (rlet ((vf0 :class vf)
           (vf1 :class vf)
           (vf2 :class vf)
           )
      (init-vf0-vector)
      (case message
        (('move)
         (let ((v1-1 (-> self root)))
           (vector-copy! (-> self starting-pos) (the-as vector (-> block param 0)))
           (vector-copy! (-> self root trans) (-> self starting-pos))
           (vector-! (-> self root transv) (the-as vector (-> block param 1)) (-> self starting-pos))
           (let ((a0-7 (-> self root transv)))
             (.lvf vf1 (&-> (-> self root transv) quad))
             (let ((f0-0 (-> self clock frames-per-second)))
               (.mov at-0 f0-0)
               )
             (.mov vf2 at-0)
             (.mov.vf.w vf1 vf0)
             (.mul.x.vf.xyz vf1 vf1 vf2)
             (.svf (&-> a0-7 quad) vf1)
             )
           (vector-copy! (-> self pre-move-transv) (-> v1-1 transv))
           )
         (vector-normalize-copy! (-> self starting-dir) (-> self root transv) 1.0)
         (set! (-> self hits) 0)
         (set! (-> self max-hits) 100)
         ((-> self move) self)
         (let ((v0-2 (the-as object (-> block param 1))))
           (set! (-> (the-as vector v0-2) quad) (-> self root trans quad))
           v0-2
           )
         )
        (else
          (projectile-event-handler proc argc message block)
          )
        )
      )
    )
  :trans #f
  :code sleep-code
  )

(defpart 1760
  :init-specs ((:texture (pal-lightning-red level-default-sprite))
    (:birth-func 'birth-func-set-quat)
    (:num 1.0)
    (:scale-x (meters 0.5) (meters 0.5))
    (:scale-y (meters 1))
    (:r 128.0 64.0)
    (:g 128.0 64.0)
    (:b 128.0 64.0)
    (:a 80.0 128.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 left-multiply-quat))
    )
  )

(defpart 1761
  :init-specs ((:texture (radial-gradient-yellow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 8))
    (:rot-x (degrees 22.5))
    (:scale-y :copy scale-x)
    (:r 128.0 64.0)
    (:g 80.0 20.0)
    (:b 128.0 64.0)
    (:a 128.0)
    (:omega (degrees 9011.25))
    (:rotvel-z (degrees 0.3))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 4096.0)
    )
  )

(defpart 1762
  :init-specs ((:texture (starflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.5) (meters 0.2))
    (:rot-z (degrees 0) (degrees 3600))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 180.0)
    (:b 100.0)
    (:a 200.0 55.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 1763
  :init-specs ((:texture (pal-lightning-red level-default-sprite))
    (:birth-func 'birth-func-set-quat)
    (:num 1.0)
    (:scale-x (meters 3) (meters 1))
    (:scale-y (meters 1))
    (:r 128.0 64.0)
    (:g 128.0 64.0)
    (:b 128.0 64.0)
    (:a 80.0 128.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 left-multiply-quat))
    )
  )

(defpart 1764
  :init-specs ((:texture (radial-gradient-yellow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 15))
    (:rot-x (degrees 22.5))
    (:scale-y :copy scale-x)
    (:r 128.0 64.0)
    (:g 80.0 20.0)
    (:b 128.0 64.0)
    (:a 128.0)
    (:omega (degrees 9011.25))
    (:rotvel-z (degrees 0.3))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 4096.0)
    )
  )

(defpart 1765
  :init-specs ((:texture (starflash level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 3) (meters 1))
    (:rot-z (degrees 0) (degrees 3600))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 180.0)
    (:b 100.0)
    (:a 200.0 55.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 1766
  :init-specs ((:texture (radial-gradient-yellow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 10))
    (:rot-x (degrees 11.25))
    (:scale-y :copy scale-x)
    (:r 128.0 64.0)
    (:g 10.0 20.0)
    (:b 128.0 64.0)
    (:a 128.0)
    (:omega (degrees 9011.25))
    (:rotvel-z (degrees 0.3))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 0.0)
    )
  )

(define *terraformer-head-shadow-control*
  (new 'static 'shadow-control :settings (new 'static 'shadow-settings
                                           :center (new 'static 'vector :w (the-as float #x9a))
                                           :shadow-dir (new 'static 'vector :y -1.0 :w -4096000.0)
                                           :bot-plane (new 'static 'plane :y 1.0 :w 204800.0)
                                           :top-plane (new 'static 'plane :y 1.0 :w -204800.0)
                                           )
                               )
  )

(deftype terraformer-head-critter-tracker (structure)
  ((handle  handle)
   (flags   terraformer-head-critter-tracker-flag)
   (dest    vector  :inline)
   )
  )


(deftype terraformer-head-ammo-tracker (structure)
  ((handle           handle)
   (where            vector  :inline)
   (birth-next-time  symbol)
   (timer            time-frame)
   )
  )


(deftype terraformer-head (process-focusable)
  ((head-aim-jm              joint-mod-polar-look-at)
   (neck-aim-jm              joint-mod-disc-look-at)
   (target-spline            tracking-spline                   :inline)
   (target-position          vector                            :inline)
   (beam-projectile          handle)
   (hit-points               float)
   (stage                    uint8)
   (incoming-attack-id       uint32)
   (flags                    terraformer-head-flag)
   (initial-position         vector                            :inline)
   (position-seeker          cam-vector-seeker                 :inline)
   (actor-group              (pointer actor-group))
   (actor-group-count        int32)
   (vulnerable-timer         time-frame)
   (very-vulnerable-timer    time-frame)
   (num-attacks              int8)
   (current-round            int8)
   (command-index            int8)
   (command-timer            time-frame)
   (critter                  terraformer-head-critter-tracker  8 :inline)
   (terraformer-head-target  handle)
   (light-vent-timer         time-frame)
   (light-vent-connection    connection)
   (dark-vent-timer          time-frame)
   (dark-vent-connection     connection)
   (ammo                     terraformer-head-ammo-tracker     20 :inline)
   (laser-sound-id           sound-id)
   (warmup-sound-id          sound-id)
   )
  (:state-methods
    run-script
    take-hit
    swing-laser
    slam
    initial-state
    )
  )


;; WARN: Return type mismatch int vs search-info-flag.
(defmethod get-search-info-flag ((this terraformer-head))
  "Get search-info-flag for this process."
  (the-as search-info-flag 1)
  )

(defmethod get-trans ((this terraformer-head) (arg0 int))
  "Get the `trans` for this process."
  (local-vars (gp-0 vector))
  (cond
    ((or (= arg0 2) (= arg0 3))
     (set! gp-0 (new 'static 'vector))
     (let ((s4-0 (new 'stack-no-clear 'vector)))
       (vector<-cspace! gp-0 (-> this node-list data 39))
       (vector<-cspace! s4-0 (-> this node-list data 40))
       (vector+! gp-0 gp-0 s4-0)
       )
     (vector-float*! gp-0 gp-0 0.5)
     )
    (else
      (set! gp-0 ((method-of-type process-focusable get-trans) this arg0))
      )
    )
  gp-0
  )

(defbehavior terraformer-head-get-actor-group terraformer-head ((arg0 int))
  (if (< arg0 (-> self actor-group-count))
      (-> self actor-group arg0)
      (the-as actor-group #f)
      )
  )

;; WARN: Return type mismatch symbol vs none.
(defbehavior terraformer-head-send-group-event terraformer-head ((arg0 int) (arg1 symbol))
  (let ((s5-0 (terraformer-head-get-actor-group arg0)))
    (when s5-0
      (dotimes (s4-0 (-> s5-0 length))
        (let ((a1-1 (new 'stack-no-clear 'event-message-block)))
          (set! (-> a1-1 from) (process->ppointer self))
          (set! (-> a1-1 num-params) 0)
          (set! (-> a1-1 message) arg1)
          (let ((t9-1 send-event-function)
                (v1-3 (-> s5-0 data s4-0 actor))
                )
            (t9-1
              (if v1-3
                  (-> v1-3 extra process)
                  )
              a1-1
              )
            )
          )
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch terraformer-head-flag vs none.
(defbehavior terraformer-head-fire-beam terraformer-head ((arg0 vector))
  (let ((gp-0 (new 'stack-no-clear 'vector)))
    (vector<-cspace! gp-0 (joint-node terraformer-head-lod0-jg gun_main))
    (when (not (handle->process (-> self beam-projectile)))
      (let ((a1-2 (new 'stack-no-clear 'projectile-init-by-other-params)))
        (set! (-> a1-2 ent) (-> self entity))
        (set! (-> a1-2 charge) 1.0)
        (set! (-> a1-2 options) (projectile-options))
        (logclear! (-> a1-2 options) (projectile-options po14 po15 po16))
        (vector-copy! (-> a1-2 pos) (-> self root trans))
        (vector-copy! (-> a1-2 vel) (new 'static 'vector :x 1.0))
        (set! (-> a1-2 notify-handle) (the-as handle #f))
        (set! (-> a1-2 owner-handle) (the-as handle #f))
        (set! (-> a1-2 target-handle) (the-as handle #f))
        (set! (-> a1-2 target-pos quad) (the-as uint128 0))
        (set! (-> a1-2 ignore-handle) (process->handle self))
        (let* ((v1-15 *game-info*)
               (a0-17 (+ (-> v1-15 attack-id) 1))
               )
          (set! (-> v1-15 attack-id) a0-17)
          (set! (-> a1-2 attack-id) a0-17)
          )
        (set! (-> a1-2 timeout) (seconds 4))
        (let ((v1-17 (spawn-projectile terraformer-head-laser-projectile a1-2 self *default-dead-pool*)))
          (if v1-17
              (set! (-> self beam-projectile) (ppointer->handle v1-17))
              )
          )
        )
      )
    (send-event (handle->process (-> self beam-projectile)) 'move gp-0 arg0)
    (let ((a2-2 (new 'stack-no-clear 'vector)))
      (vector-! a2-2 arg0 gp-0)
      (set! (-> *part-id-table* 1763 init-specs 4 initial-valuef) (vector-length a2-2))
      (draw-beam (-> *part-id-table* 1763) gp-0 a2-2 #f)
      )
    (launch-particles (-> *part-id-table* 1765) arg0)
    (let ((s5-1 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) arg0 gp-0) 1.0)))
      (let ((s4-0 (new 'stack-no-clear 'vector)))
        (if *target*
            (vector-! s4-0 (get-trans *target* 3) gp-0)
            )
        (vector+float*! s5-1 gp-0 s5-1 (vector-dot s5-1 s4-0))
        )
      (sound-play "laser-loop" :id (-> self laser-sound-id) :position s5-1)
      )
    )
  (logior! (-> self flags) (terraformer-head-flag laser-sound-playing))
  (when (logtest? (-> self flags) (terraformer-head-flag laser-warmup-sound-playing))
    (sound-stop (-> self warmup-sound-id))
    (logclear! (-> self flags) (terraformer-head-flag laser-warmup-sound-playing))
    )
  (none)
  )

;; WARN: Return type mismatch connection vs none.
(defbehavior terraformer-head-connect-tank-glows terraformer-head ()
  (add-connection *part-engine* self 39 self 1766 (new 'static 'vector :x 4096.0 :z -4096.0 :w 819200.0))
  (add-connection *part-engine* self 40 self 1766 (new 'static 'vector :x -4096.0 :z -4096.0 :w 819200.0))
  (none)
  )

(defbehavior terraformer-head-always terraformer-head ((arg0 symbol) (arg1 float))
  (local-vars (sv-320 int))
  (if (and *target* (focus-test? *target* hit))
      (terraformer-head-play-speech 2 self)
      (terraformer-head-play-speech 0 self)
      )
  (script-eval '(want-anim "desert-final-boss-res"))
  (if (or (and (< (vector-vector-distance (-> self draw origin) (math-camera-pos)) (-> self draw origin w))
               (not *target*)
               )
          (< (-> (camera-pos) x) 9814016.0)
          )
      (logclear! (-> self draw status) (draw-control-status force-vu1))
      (logior! (-> self draw status) (draw-control-status force-vu1))
      )
  (dotimes (s4-1 20)
    (cond
      ((handle->process (-> self ammo s4-1 handle))
       (if (and (nonzero? (-> self ammo s4-1 timer)) (time-elapsed? (-> self ammo s4-1 timer) (seconds 20)))
           (send-event (handle->process (-> self ammo s4-1 handle)) 'die)
           )
       )
      ((-> self ammo s4-1 birth-next-time)
       (set! (-> self ammo s4-1 birth-next-time) #f)
       (set-time! (-> self ammo s4-1 timer))
       (let ((a0-29 (new 'static 'fact-info)))
         (set-vector! (new 'stack-no-clear 'vector) 0.0 57001.605 0.0 1.0)
         (set! (-> a0-29 options) (actor-option fade-out fall no-distance-check-fadeout))
         (set! (-> a0-29 fade-time) (seconds 10))
         (set! (-> a0-29 pickup-spawn-amount) 1.0)
         (set! (-> a0-29 pickup-type) (pickup-type ammo-random))
         (set! (-> a0-29 pickup-amount) 10.0)
         (let ((s3-1 (new 'stack-no-clear 'vector)))
           (vector-copy! s3-1 (-> self root trans))
           (set! (-> self root trans quad)
                 (-> (the-as (pointer uint128) (+ (the-as uint (-> self ammo 0 where)) (* 48 s4-1))))
                 )
           (set! (-> a0-29 process) self)
           (set! (-> self ammo s4-1 handle)
                 (ppointer->handle (drop-pickup a0-29 #t *entity-pool* (the-as fact-info #f) 0 #t))
                 )
           (vector-copy! (-> self root trans) s3-1)
           )
         )
       )
      )
    )
  (cond
    ((>= (- (current-time) (-> self dark-vent-timer)) 0)
     (when (not (-> self dark-vent-connection))
       (let ((t1-1 58))
         (set! (-> self dark-vent-connection) (add-setting! 'features 'clear-bit (sar t1-1 32) t1-1))
         )
       )
     )
    ((-> self dark-vent-connection)
     (setting-control-method-14 *setting-control* (-> self dark-vent-connection))
     (set! (-> self dark-vent-connection) #f)
     )
    )
  (cond
    ((>= (- (current-time) (-> self light-vent-timer)) 0)
     (when (not (-> self light-vent-connection))
       (let ((t1-2 57))
         (set! (-> self light-vent-connection) (add-setting! 'features 'clear-bit (sar t1-2 32) t1-2))
         )
       )
     )
    ((-> self light-vent-connection)
     (setting-control-method-14 *setting-control* (-> self light-vent-connection))
     (set! (-> self light-vent-connection) #f)
     )
    )
  (if arg0
      (set! arg1 1.0)
      )
  (let* ((v1-100 (fmax 0.0 (fmin 1.0 arg1)))
         (s5-1 (* 61440.0 v1-100))
         )
    (when *target*
      (let ((a1-19 (get-trans *target* 3)))
        (set! (-> a1-19 y) (fmin 454656.0 (-> a1-19 y)))
        (tracking-spline-method-17 (-> self target-spline) a1-19 2048.0 0.0 #t)
        )
      )
    (let ((f0-15 (lerp-scale 409.6 204800.0 (-> self target-spline summed-len) 24576.0 409600.0)))
      (tracking-spline-method-21
        (-> self target-spline)
        (-> self target-position)
        20.48
        f0-15
        0.1
        0.0
        (the-as vector #f)
        )
      )
    (tracking-spline-method-9 (-> self target-spline))
    (logclear! (-> self flags) (terraformer-head-flag laser))
    (cond
      ((< 409.6 s5-1)
       (set! (-> *part-id-table* 1764 init-specs 2 initial-valuef) s5-1)
       (when (not (logtest? (-> self flags) (terraformer-head-flag th2)))
         (add-connection *part-engine* self 14 self 1764 (new 'static 'vector :w 819200.0))
         (logior! (-> self flags) (terraformer-head-flag th2))
         (terraformer-head-play-speech 1 self)
         )
       (logior! (-> self flags) (terraformer-head-flag laser))
       (when (not (logtest? (-> self flags) (terraformer-head-flag laser-sound-playing laser-warmup-sound-playing)))
         (let ((s5-2 sound-play-by-name)
               (sname (static-sound-name "laser-charge"))
               (s3-2 (-> self warmup-sound-id))
               (s2-0 1024)
               (s1-0 0)
               (s0-0 0)
               )
           (set! sv-320 0)
           (let ((t2-1 (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node terraformer-head-lod0-jg gun_main))))
             (s5-2 (the-as sound-name sname) s3-2 s2-0 s1-0 s0-0 (the-as sound-group sv-320) t2-1)
             )
           )
         (logior! (-> self flags) (terraformer-head-flag laser-warmup-sound-playing))
         )
       )
      ((logtest? (-> self flags) (terraformer-head-flag th2))
       (remove-from-process *part-engine* self)
       (logclear! (-> self flags) (terraformer-head-flag th2))
       (terraformer-head-connect-tank-glows)
       (when (logtest? (-> self flags) (terraformer-head-flag laser-warmup-sound-playing))
         (sound-stop (-> self warmup-sound-id))
         (logclear! (-> self flags) (terraformer-head-flag laser-warmup-sound-playing))
         )
       )
      )
    )
  (cond
    ((not arg0)
     (when (logtest? (-> self flags) (terraformer-head-flag laser-sound-playing))
       (sound-stop (-> self laser-sound-id))
       (logclear! (-> self flags) (terraformer-head-flag laser-sound-playing))
       )
     )
    ((logtest? (-> self flags) (terraformer-head-flag th1))
     (let ((gp-1 (new 'stack-no-clear 'vector)))
       (vector<-cspace+vector!
         gp-1
         (joint-node terraformer-head-lod0-jg gun_main)
         (new 'static 'vector :y -49152.0 :z 614400.0 :w 1.0)
         )
       (terraformer-head-fire-beam gp-1)
       )
     )
    (else
      (terraformer-head-fire-beam (-> self target-position))
      )
    )
  (update! (-> self position-seeker) (the-as vector #f))
  (vector-copy! (-> self root trans) (-> self position-seeker value))
  (dotimes (gp-2 8)
    (let* ((s5-3 (-> self critter gp-2))
           (s4-3 (handle->process (-> s5-3 handle)))
           )
      (when s4-3
        (when (not (logtest? (-> s5-3 flags) (terraformer-head-critter-tracker-flag thct1)))
          (if (send-event s4-3 'jump 2 (-> s5-3 dest))
              (logior! (-> s5-3 flags) (terraformer-head-critter-tracker-flag thct1))
              )
          )
        (when (not (logtest? (-> s5-3 flags) (terraformer-head-critter-tracker-flag thct2)))
          (if (send-event s4-3 'enable-envmap #f)
              (logior! (-> s5-3 flags) (terraformer-head-critter-tracker-flag thct2))
              )
          )
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch int vs object.
(defbehavior terraformer-head-always-handler terraformer-head ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('child-jumped)
     (let ((v0-0 (the-as int (logclear (-> (the-as terraformer-drone arg0) enemy-flags) (enemy-flag directed)))))
       (set! (-> (the-as terraformer-drone arg0) enemy-flags) (the-as enemy-flag v0-0))
       v0-0
       )
     )
    (('eco-creature-died)
     (terraformer-head-play-speech 4 self)
     (dotimes (v1-2 20)
       (when (and (not (-> self ammo v1-2 birth-next-time)) (not (handle->process (-> self ammo v1-2 handle))))
         (set! (-> (the-as (pointer uint128) (+ (the-as uint (-> self ammo 0 where)) (* 48 v1-2))))
               (-> (the-as vector (-> arg3 param 0)) quad)
               )
         (set! (-> self ammo v1-2 birth-next-time) #t)
         (return (the-as object 0))
         )
       )
     (the-as int #f)
     )
    )
  )

(defbehavior terraformer-head-handler terraformer-head ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('get-hit)
     (let ((f0-0 0.251))
       (if (logtest? (-> *game-info* secrets) (game-secrets hero-mode))
           (set! f0-0 (* 0.6666667 f0-0))
           )
       (set! (-> self hit-points) (fmax 0.0 (- (-> self hit-points) f0-0)))
       )
     (set! (-> *game-info* counter) (-> self hit-points))
     (go-virtual take-hit)
     )
    (('touch 'bonk)
     (send-event arg0 'attack #f (static-attack-info :mask (vehicle-impulse-factor) ((id (new-attack-id))
                                                                                     (damage 2.0)
                                                                                     (vehicle-damage-factor 1.0)
                                                                                     (vehicle-impulse-factor 1.0)
                                                                                     (shove-up (meters 1))
                                                                                     (shove-back (meters 3))
                                                                                     )
                                                     )
                 )
     #t
     )
    (else
      (terraformer-head-always-handler arg0 arg1 arg2 arg3)
      )
    )
  )

(deftype terraformer-head-command (structure)
  ((action  terraformer-head-cmd-action)
   (suck    float)
   (random  float)
   (round   int8)
   (num     float)
   )
  )


(define *terraformer-head-swarm-0* (new 'static 'boxed-array :type terraformer-head-command
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action extend-tentacles)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command :suck 1.0 :random 1.0 :num 1.0)
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.3
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.6
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.3
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.6
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       :num 2.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.75
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.5
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.25
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action retract-tentacles)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action start-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 6.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action stop-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action open-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 100.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action open-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 100.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action swing-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 4.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     )
        )

(define *terraformer-head-swarm-1* (new 'static 'boxed-array :type terraformer-head-command
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action extend-tentacles)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command :suck 1.0 :random 1.0 :num 1.0)
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.3
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.6
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 4.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd3)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 8.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd3)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.3
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.6
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       :num 2.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.75
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.5
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.25
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action retract-tentacles)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action start-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 5.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 5.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 5.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command :suck 0.5 :random 1.0 :num 1.0)
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 0.75
                                       :random 1.0
                                       :round 1
                                       :num 5.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 0.5
                                       :random 1.0
                                       :round 1
                                       :num 5.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 0.25
                                       :random 1.0
                                       :round 1
                                       :num 5.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action stop-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action open-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 100.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action open-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 100.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action swing-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 4.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     )
        )

(define *terraformer-head-swarm-2* (new 'static 'boxed-array :type terraformer-head-command
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action extend-tentacles)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action start-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command :suck 1.0 :random 1.0 :num 1.0)
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.3
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.6
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 8.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd3)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd1)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.3
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.6
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 8.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd3)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       :num 2.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.75
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.5
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 0.25
                                       :random 1.0
                                       :round 1
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action wait)
                                       :suck 1.0
                                       :random 1.0
                                       :num 8.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd3)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action cmd2)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action spawn-critters)
                                       :suck 1.0
                                       :random 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action stop-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action retract-tentacles)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action slam)
                                       :suck 1.0
                                       :random 1.0
                                       :num 3.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action open-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 100.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action open-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 100.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action swing-laser)
                                       :suck 1.0
                                       :random 1.0
                                       :num 4.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-light-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     (new 'static 'terraformer-head-command
                                       :action (terraformer-head-cmd-action close-dark-vent)
                                       :suck 1.0
                                       :random 1.0
                                       :num 1.0
                                       )
                                     )
        )

(defbehavior terraformer-head-point-occupied? terraformer-head ((arg0 vector))
  (let ((a1-0 (new 'stack-no-clear 'vector)))
    (vector-copy! a1-0 arg0)
    (set! (-> a1-0 w) 16384.0)
    (check-sphere-blocked! (-> self nav) a1-0 255)
    )
  )

(defbehavior terraformer-head-get-spawn-point terraformer-head ((arg0 vector) (arg1 vector))
  (set-vector! arg0 9797632.0 405504.0 2428928.0 1.0)
  (set-vector! arg1 9891840.0 446464.0 2404352.0 1.0)
  (if (not (terraformer-head-point-occupied? arg1))
      (return #t)
      )
  (set-vector! arg0 9830400.0 405504.0 2220032.0 1.0)
  (set-vector! arg1 9883648.0 442368.0 2281472.0 1.0)
  (if (not (terraformer-head-point-occupied? arg1))
      (return #t)
      )
  (set! (-> arg0 x) 9752576.0)
  (set! (-> arg0 y) 405504.0)
  (set! (-> arg0 z) 2359296.0)
  (set! (-> arg0 w) 1.0)
  (set-vector! arg1 9846784.0 442368.0 2338816.0 1.0)
  (if (not (terraformer-head-point-occupied? arg1))
      (return #t)
      )
  #f
  )

(defbehavior terraformer-head-launch-critter terraformer-head ((arg0 int))
  (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 (terraformer-head-get-spawn-point gp-0 (-> s5-0 dest))
            (set! (-> s5-0 flags) (terraformer-head-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?) #f)
            (set! (-> s4-0 no-initial-move-to-ground?) #f)
            (set! (-> s4-0 art-level) 'deswalk)
            (let ((v1-11 arg0))
              (cond
                ((zero? v1-11)
                 (let ((s3-1 (process-spawn
                               prebot-large-eco-creature
                               :init enemy-init-by-other
                               self
                               s4-0
                               :name "prebot-large-eco-creature"
                               :to self
                               )
                             )
                       )
                   (when s3-1
                     (sound-play "caveco-toss" :position gp-0)
                     (set! (-> s5-0 handle) (ppointer->handle s3-1))
                     (send-event (ppointer->process s3-1) 'set-dest gp-0 (-> s5-0 dest) #x46c00000 #x43960000)
                     (logior! (-> s5-0 flags) (terraformer-head-critter-tracker-flag thct1))
                     )
                   )
                 )
                ((= v1-11 1)
                 (let ((s3-2 (process-spawn
                               medium-eco-creature-launched
                               :init enemy-init-by-other
                               self
                               s4-0
                               :name "medium-eco-creature-launched"
                               :to self
                               )
                             )
                       )
                   (when s3-2
                     (sound-play "caveco-toss" :position gp-0)
                     (set! (-> s5-0 handle) (ppointer->handle s3-2))
                     (send-event (ppointer->process s3-2) 'set-dest gp-0 (-> s5-0 dest) #x46c00000 #x43960000)
                     (logior! (-> s5-0 flags) (terraformer-head-critter-tracker-flag thct1))
                     )
                   )
                 )
                ((= v1-11 2)
                 (let ((s3-3 (process-spawn
                               small-eco-creature-launched
                               :init enemy-init-by-other
                               self
                               s4-0
                               :name "small-eco-creature-launched"
                               :to self
                               )
                             )
                       )
                   (when s3-3
                     (sound-play "caveco-toss" :position gp-0)
                     (set! (-> s5-0 handle) (ppointer->handle s3-3))
                     (send-event (ppointer->process s3-3) 'set-dest gp-0 (-> s5-0 dest) #x46c00000 #x43960000)
                     (logior! (-> s5-0 flags) (terraformer-head-critter-tracker-flag thct1))
                     )
                   )
                 )
                ((= v1-11 3)
                 (sound-play "caveco-toss" :position gp-0)
                 (set! (-> s4-0 directed?) #t)
                 (set! (-> s4-0 no-initial-move-to-ground?) #t)
                 (let ((v1-61 (process-spawn
                                terraformer-drone-small
                                :init enemy-init-by-other
                                self
                                s4-0
                                :name "terraformer-drone-small"
                                :to self
                                )
                              )
                       )
                   (if v1-61
                       (set! (-> s5-0 handle) (ppointer->handle v1-61))
                       )
                   )
                 )
                (else
                  (format 0 "~A can't launch unknown critter type ~D~%" (-> self name) arg0)
                  (return #t)
                  )
                )
              )
            (cond
              ((handle->process (-> s5-0 handle))
               (let ((s4-4 (new 'stack-no-clear 'matrix)))
                 (vector-! (-> s4-4 uvec) (-> s5-0 dest) gp-0)
                 (set! (-> s4-4 uvec y) 0.0)
                 (vector-normalize! (-> s4-4 uvec) 1.0)
                 (set! (-> s4-4 uvec w) 0.0)
                 (set-vector! (-> s4-4 fvec) 0.0 1.0 0.0 0.0)
                 (vector-cross! (-> s4-4 rvec) (-> s4-4 uvec) (-> s4-4 fvec))
                 (set! (-> s4-4 rvec w) 0.0)
                 (vector-copy! (-> s4-4 trans) gp-0)
                 (+! (-> s4-4 trans y) 8192.0)
                 (set! (-> s4-4 trans w) 1.0)
                 )
               (return #t)
               )
              (else
                (return #f)
                )
              )
            (the-as none 0)
            )
          )
        )
      )
    )
  #f
  )

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

;; WARN: Return type mismatch object vs none.
(defbehavior terraformer-head-check-launch-script terraformer-head ()
  (local-vars (v1-20 terraformer-head-cmd-action))
  (let ((v1-0 *terraformer-head-swarm-2*))
    (let ((a0-0 (-> self stage)))
      (cond
        ((zero? a0-0)
         (set! v1-0 *terraformer-head-swarm-0*)
         )
        ((= a0-0 1)
         (set! v1-0 *terraformer-head-swarm-1*)
         )
        )
      )
    (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)))
             )
         (terraformer-head-advance-launch-script)
         )
        ((or (and (> (-> gp-0 round) 0) (>= (-> self current-round) (-> gp-0 round)))
             (and (<= (-> gp-0 round) 0) (< (-> self current-round) (- (-> gp-0 round))))
             )
         (terraformer-head-advance-launch-script)
         )
        (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)))
               (terraformer-head-advance-launch-script)
               )
              ((begin (set! v1-20 (-> gp-0 action)) (= v1-20 (terraformer-head-cmd-action spawn-critters)))
               (let ((v1-21 0))
                 (dotimes (a0-21 8)
                   (if (handle->process (-> self critter a0-21 handle))
                       (+! v1-21 1)
                       )
                   )
                 (if (>= (the int (-> gp-0 num)) v1-21)
                     (terraformer-head-advance-launch-script)
                     )
                 )
               )
              ((= v1-20 (terraformer-head-cmd-action wait))
               (if (time-elapsed? (-> self command-timer) (the int (* 300.0 (-> gp-0 num))))
                   (terraformer-head-advance-launch-script)
                   )
               )
              ((= v1-20 (terraformer-head-cmd-action extend-tentacles))
               (terraformer-head-advance-launch-script)
               (terraformer-head-send-group-event 0 'extend)
               )
              ((= v1-20 (terraformer-head-cmd-action retract-tentacles))
               (terraformer-head-advance-launch-script)
               (terraformer-head-send-group-event 0 'retract)
               )
              ((= v1-20 (terraformer-head-cmd-action start-laser))
               (terraformer-head-advance-launch-script)
               (when (not (logtest? (-> self flags) (terraformer-head-flag track-target)))
                 (logior! (-> self flags) (terraformer-head-flag track-target))
                 (set-time! (-> self state-time))
                 )
               )
              ((= v1-20 (terraformer-head-cmd-action stop-laser))
               (when (not (logtest? (-> self flags) (terraformer-head-flag laser)))
                 (terraformer-head-advance-launch-script)
                 (logclear! (-> self flags) (terraformer-head-flag track-target))
                 )
               )
              ((= v1-20 (terraformer-head-cmd-action open-light-vent))
               (terraformer-head-advance-launch-script)
               (set! (-> self light-vent-timer) (+ (current-time) (the int (* 300.0 (-> gp-0 num)))))
               )
              ((= v1-20 (terraformer-head-cmd-action close-light-vent))
               (terraformer-head-advance-launch-script)
               (set! (-> self light-vent-timer) 0)
               0
               )
              ((= v1-20 (terraformer-head-cmd-action open-dark-vent))
               (terraformer-head-advance-launch-script)
               (set! (-> self dark-vent-timer) (+ (current-time) (the int (* 300.0 (-> gp-0 num)))))
               )
              ((= v1-20 (terraformer-head-cmd-action close-dark-vent))
               (terraformer-head-advance-launch-script)
               (set! (-> self dark-vent-timer) 0)
               0
               )
              ((= v1-20 (terraformer-head-cmd-action slam))
               (terraformer-head-advance-launch-script)
               (set! (-> self num-attacks) (the int (-> gp-0 num)))
               (go-virtual slam)
               )
              ((= v1-20 (terraformer-head-cmd-action swing-laser))
               (terraformer-head-advance-launch-script)
               (set! (-> self num-attacks) (the int (-> gp-0 num)))
               (go-virtual swing-laser)
               )
              (else
                (when (terraformer-head-launch-critter (the-as int (-> gp-0 action)))
                  (terraformer-head-play-speech 1 self)
                  (terraformer-head-advance-launch-script)
                  )
                )
              )
            )
          )
        )
      )
    )
  (none)
  )

(defstate run-script (terraformer-head)
  :virtual #t
  :event terraformer-head-handler
  :enter (behavior ()
    (terraformer-head-send-group-event 0 'retract)
    (let ((v1-0 (new 'stack-no-clear 'vector)))
      (vector-copy! v1-0 (-> self initial-position))
      (+! (-> v1-0 x) 204800.0)
      (+! (-> v1-0 y) -102400.0)
      (set! (-> self position-seeker target quad) (-> v1-0 quad))
      )
    (set-time! (-> self state-time))
    )
  :exit (behavior ()
    (blend-to-off! (-> self head-aim-jm) (seconds 1) #f)
    (blend-to-off! (-> self neck-aim-jm) (seconds 1) #f)
    (logclear! (-> self flags) (terraformer-head-flag track-target))
    )
  :trans (behavior ()
    (terraformer-head-check-launch-script)
    (let ((v1-2 (ja-group)))
      (cond
        ((and v1-2 (= v1-2 terraformer-head-idle-ja))
         (ja :num! (loop!))
         )
        (else
          (ja-channel-push! 1 (seconds 0.5))
          (ja :group! terraformer-head-idle-ja :num! min)
          )
        )
      )
    (cond
      ((logtest? (-> self flags) (terraformer-head-flag track-target))
       (when (time-elapsed? (-> self state-time) (seconds 6))
         (set-time! (-> self state-time))
         (+! (-> self state-time) (seconds 4))
         )
       (blend-on! (-> self head-aim-jm) (seconds 1) 1.0 #f)
       (set-target! (-> self head-aim-jm) (-> self target-position))
       (blend-on! (-> self neck-aim-jm) (seconds 1) 1.0 #f)
       (set-target! (-> self neck-aim-jm) (-> self target-position))
       )
      (else
        (set-time! (-> self state-time))
        (blend-to-off! (-> self head-aim-jm) (seconds 1) #f)
        (blend-to-off! (-> self neck-aim-jm) (seconds 1) #f)
        )
      )
    (terraformer-head-always
      (time-elapsed? (-> self state-time) (seconds 2))
      (lerp-scale 0.0 1.0 (the float (- (current-time) (-> self state-time))) 0.0 600.0)
      )
    )
  :code sleep-code
  :post transform-post
  )

(defstate take-hit (terraformer-head)
  :virtual #t
  :event terraformer-head-always-handler
  :enter (behavior ()
    ;; og:preserve-this
    (#when PC_PORT
      (when (= (-> self hit-points) 0.0)
        (set! (-> *autosplit-info-jak3* errol-dead?) 1)))
    (terraformer-head-play-speech 3 self)
    (let ((gp-0 (get-trans self 3)))
      (cond
        ((logtest? (-> group-kg-huge-explosion flags) (sp-group-flag sp13))
         (vector-copy! (-> *launch-matrix* trans) gp-0)
         (part-tracker-spawn part-tracker-subsampler :to self :group group-kg-huge-explosion)
         )
        (else
          (vector-copy! (-> *launch-matrix* trans) gp-0)
          (part-tracker-spawn part-tracker :to self :group group-kg-huge-explosion)
          )
        )
      (sound-play "hit-boss-head" :position gp-0)
      )
    )
  :trans (behavior ()
    (let ((v1-2 (ja-group)))
      (cond
        ((or (and v1-2
                  (or (= v1-2 terraformer-head-sweep-to-left-windup-ja) (= v1-2 terraformer-head-sweep-to-right-idle-ja))
                  )
             (let ((v1-8 (ja-group)))
               (and (and v1-8 (= v1-8 terraformer-head-sweep-to-left-ja)) (< (ja-aframe-num 0) 30.0))
               )
             (let ((v1-15 (ja-group)))
               (and (and v1-15 (= v1-15 terraformer-head-sweep-to-right-ja)) (< 130.0 (ja-aframe-num 0)))
               )
             )
         (ja-channel-push! 1 (seconds 0.2))
         (ja :group! terraformer-head-hit-right-ja :num! min)
         )
        (else
          (let ((v1-26 (ja-group)))
            (cond
              ((and v1-26 (or (= v1-26 terraformer-head-sweep-to-right-windup-ja)
                              (= v1-26 terraformer-head-sweep-to-left-idle-ja)
                              (= v1-26 terraformer-head-sweep-to-left-ja)
                              (= v1-26 terraformer-head-sweep-to-right-ja)
                              )
                    )
               (ja-channel-push! 1 (seconds 0.2))
               (ja :group! terraformer-head-hit-left-ja :num! min)
               )
              ((let ((v1-36 (ja-group)))
                 (and v1-36 (or (= v1-36 terraformer-head-hit-left-ja) (= v1-36 terraformer-head-hit-right-ja)))
                 )
               (ja :num! (seek!))
               (if (ja-done? 0)
                   (go-virtual initial-state)
                   )
               )
              (else
                (go-virtual initial-state)
                )
              )
            )
          )
        )
      )
    (terraformer-head-always #f 0.0)
    )
  :code sleep-code
  :post transform-post
  )

;; WARN: Return type mismatch object vs none.
(defbehavior terraformer-head-target-enable terraformer-head ((arg0 symbol))
  (let ((v1-1 (handle->process (-> self terraformer-head-target))))
    (cond
      (arg0
        (when (not v1-1)
          (let ((v1-4 (process-spawn terraformer-head-target :name "terraformer-head-target" :to self)))
            (if v1-4
                (set! (-> self terraformer-head-target) (ppointer->handle v1-4))
                )
            )
          )
        )
      (v1-1
        (deactivate v1-1)
        )
      )
    )
  (none)
  )

(defstate swing-laser (terraformer-head)
  :virtual #t
  :event terraformer-head-handler
  :enter (behavior ()
    (terraformer-head-play-speech 1 self)
    (logior! (-> self flags) (terraformer-head-flag th1))
    (logior! (-> self skel status) (joint-control-status sync-math))
    (set-time! (-> self state-time))
    (let ((v1-7 (new 'stack-no-clear 'vector)))
      (vector-copy! v1-7 (-> self initial-position))
      (+! (-> v1-7 x) 204800.0)
      (+! (-> v1-7 y) -223232.0)
      (set! (-> self position-seeker target quad) (-> v1-7 quad))
      )
    )
  :exit (behavior ()
    (logclear! (-> self flags) (terraformer-head-flag th1))
    (logclear! (-> self skel status) (joint-control-status sync-math))
    (set! (-> self position-seeker target z) (-> self initial-position z))
    (terraformer-head-target-enable #f)
    )
  :trans (behavior ()
    (let ((gp-0 (time-elapsed? (-> self state-time) (seconds 1)))
          (f30-0 0.0)
          )
      (let ((v1-5 (ja-group)))
        (cond
          ((and v1-5 (= v1-5 terraformer-head-sweep-to-left-windup-ja))
           (ja :num! (seek!))
           (terraformer-head-target-enable #t)
           (set! gp-0 #f)
           (set! f30-0 (lerp-scale 0.0 1.0 (ja-frame-num 0) 0.0 (the float (ja-num-frames 0))))
           (when (ja-done? 0)
             (let* ((f28-0 (-> self initial-position z))
                    (f26-0 12288.0)
                    (f24-0 -0.5)
                    (v1-20 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                    (v1-21 (the-as number (logior #x3f800000 v1-20)))
                    )
               (set! (-> self position-seeker target z) (+ f28-0 (* f26-0 (+ f24-0 (+ -1.0 (the-as float v1-21))))))
               )
             (set! (-> self position-seeker target y) (+ -222822.4 (-> self initial-position y)))
             (ja-channel-push! 1 (seconds 0.05))
             (ja :group! terraformer-head-sweep-to-left-ja :num! min)
             )
           )
          ((let ((v1-31 (ja-group)))
             (and v1-31 (= v1-31 terraformer-head-sweep-to-left-ja))
             )
           (ja :num! (seek!))
           (let ((f0-17 (ja-aframe-num 0)))
             (cond
               ((< 40.0 f0-17)
                (set! (-> self position-seeker target y) (+ -219136.0 (-> self initial-position y)))
                )
               ((< 38.0 f0-17)
                (set! (-> self position-seeker target y) (+ -221184.0 (-> self initial-position y)))
                )
               )
             (terraformer-head-target-enable (or (< f0-17 8.0) (< 48.0 f0-17)))
             )
           (when (ja-done? 0)
             (ja-channel-push! 1 (seconds 0.05))
             (ja :group! terraformer-head-sweep-to-left-idle-ja :num! min)
             )
           )
          ((let ((v1-62 (ja-group)))
             (and v1-62 (= v1-62 terraformer-head-sweep-to-left-idle-ja))
             )
           (set! gp-0 #f)
           (ja :num! (seek!))
           (terraformer-head-target-enable #t)
           (cond
             ((not (ja-done? 0))
              )
             ((>= 1 (-> self num-attacks))
              (go-virtual run-script)
              )
             (else
               (+! (-> self num-attacks) -1)
               (ja-channel-push! 1 (seconds 0.05))
               (ja :group! terraformer-head-sweep-to-right-windup-ja :num! min)
               )
             )
           )
          ((let ((v1-87 (ja-group)))
             (and v1-87 (= v1-87 terraformer-head-sweep-to-right-windup-ja))
             )
           (set! gp-0 #f)
           (ja :num! (seek!))
           (terraformer-head-target-enable #t)
           (set! f30-0 (lerp-scale 0.0 1.0 (ja-frame-num 0) 0.0 (the float (ja-num-frames 0))))
           (when (ja-done? 0)
             (let* ((f28-1 (-> self initial-position z))
                    (f26-1 12288.0)
                    (f24-1 -0.5)
                    (v1-102 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                    (v1-103 (the-as number (logior #x3f800000 v1-102)))
                    )
               (set! (-> self position-seeker target z) (+ f28-1 (* f26-1 (+ f24-1 (+ -1.0 (the-as float v1-103))))))
               )
             (set! (-> self position-seeker target y) (+ -223232.0 (-> self initial-position y)))
             (ja-channel-push! 1 (seconds 0.05))
             (ja :group! terraformer-head-sweep-to-right-ja :num! min)
             )
           )
          ((let ((v1-113 (ja-group)))
             (and v1-113 (= v1-113 terraformer-head-sweep-to-right-ja))
             )
           (ja :num! (seek!))
           (let ((f0-40 (ja-aframe-num 0)))
             (cond
               ((< 140.0 f0-40)
                (set! (-> self position-seeker target y) (+ -218726.4 (-> self initial-position y)))
                )
               ((< 138.0 f0-40)
                (set! (-> self position-seeker target y) (+ -221184.0 (-> self initial-position y)))
                )
               )
             (terraformer-head-target-enable (or (< f0-40 107.0) (< 146.0 f0-40)))
             )
           (when (ja-done? 0)
             (ja-channel-push! 1 (seconds 0.05))
             (ja :group! terraformer-head-sweep-to-right-idle-ja :num! min)
             )
           )
          (else
            (let ((v1-144 (ja-group)))
              (cond
                ((and v1-144 (= v1-144 terraformer-head-sweep-to-right-idle-ja))
                 (set! gp-0 #f)
                 (ja :num! (seek!))
                 (terraformer-head-target-enable #t)
                 (cond
                   ((not (ja-done? 0))
                    )
                   ((>= 1 (-> self num-attacks))
                    (go-virtual run-script)
                    )
                   (else
                     (+! (-> self num-attacks) -1)
                     (ja-channel-push! 1 (seconds 0.05))
                     (ja :group! terraformer-head-sweep-to-left-windup-ja :num! min)
                     )
                   )
                 )
                (else
                  (set! gp-0 #f)
                  (ja-channel-push! 1 (seconds 0.5))
                  (ja :group! terraformer-head-sweep-to-left-windup-ja :num! min)
                  )
                )
              )
            )
          )
        )
      (terraformer-head-always gp-0 f30-0)
      )
    )
  :code sleep-code
  :post transform-post
  )

(defstate slam (terraformer-head)
  :virtual #t
  :event terraformer-head-handler
  :enter (behavior ()
    (terraformer-head-play-speech 1 self)
    (logclear! (-> self flags) (terraformer-head-flag th0))
    (set! (-> self position-seeker target y) (+ -57344.0 (-> self initial-position y)))
    (set-setting! 'entity-name "camera-427" 0.0 0)
    )
  :exit (behavior ()
    (remove-setting! 'entity-name)
    )
  :trans (behavior ()
    (let ((v1-2 (ja-group)))
      (cond
        ((and v1-2 (= v1-2 terraformer-head-slam-middle-ja))
         (ja :num! (seek!))
         (ja :chan 1 :num! (chan 0))
         (ja :chan 2 :num! (chan 0))
         (let ((f0-5 (ja-aframe-num 0)))
           (cond
             ((< f0-5 15.0)
              (when *target*
                (let ((f1-2 (+ (- -53248.0 (-> self initial-position x)) (-> (get-trans *target* 3) x))))
                  (set! (-> self position-seeker target x)
                        (+ (-> self initial-position x) (fmin 229376.0 (fmax -32768.0 f1-2)))
                        )
                  )
                (let ((f0-11 (- (-> (get-trans *target* 3) z) (-> self initial-position z))))
                  (cond
                    ((< f0-11 0.0)
                     (let ((gp-0 (-> self skel root-channel 1))
                           (f0-12 (lerp-scale 0.0 1.0 f0-11 0.0 -81920.0))
                           )
                       (set! (-> gp-0 frame-interp 1) f0-12)
                       (set! (-> gp-0 frame-interp 0) f0-12)
                       )
                     (let ((v1-36 (-> self skel root-channel 2))
                           (f0-13 0.0)
                           )
                       (set! (-> v1-36 frame-interp 1) f0-13)
                       (set! (-> v1-36 frame-interp 0) f0-13)
                       )
                     )
                    (else
                      (let ((v1-40 (-> self skel root-channel 1))
                            (f1-7 0.0)
                            )
                        (set! (-> v1-40 frame-interp 1) f1-7)
                        (set! (-> v1-40 frame-interp 0) f1-7)
                        )
                      (let ((gp-1 (-> self skel root-channel 2))
                            (f0-14 (lerp-scale 0.0 1.0 f0-11 0.0 81920.0))
                            )
                        (set! (-> gp-1 frame-interp 1) f0-14)
                        (set! (-> gp-1 frame-interp 0) f0-14)
                        )
                      )
                    )
                  )
                )
              )
             ((and (not (logtest? (-> self flags) (terraformer-head-flag th0))) (>= f0-5 30.0))
              (logior! (-> self flags) (terraformer-head-flag th0))
              (set-zero! *camera-smush-control*)
              (activate! *camera-smush-control* 8192.0 60 600 0.995 1.07 (-> *display* camera-clock))
              )
             )
           )
         (when (ja-done? 0)
           (+! (-> self num-attacks) -1)
           (cond
             ((<= (-> self num-attacks) 0)
              (go-virtual run-script)
              )
             (else
               (ja-channel-push! 3 (seconds 0.2))
               (ja :group! terraformer-head-slam-middle-ja :num! min)
               (let ((gp-3 (-> self skel root-channel 1)))
                 (let ((f0-16 0.0))
                   (set! (-> gp-3 frame-interp 1) f0-16)
                   (set! (-> gp-3 frame-interp 0) f0-16)
                   )
                 (joint-control-channel-group-eval!
                   gp-3
                   (the-as art-joint-anim terraformer-head-slam-left-ja)
                   num-func-identity
                   )
                 (set! (-> gp-3 frame-num) 0.0)
                 )
               (let ((gp-4 (-> self skel root-channel 2)))
                 (let ((f0-18 0.0))
                   (set! (-> gp-4 frame-interp 1) f0-18)
                   (set! (-> gp-4 frame-interp 0) f0-18)
                   )
                 (joint-control-channel-group-eval!
                   gp-4
                   (the-as art-joint-anim terraformer-head-slam-right-ja)
                   num-func-identity
                   )
                 (set! (-> gp-4 frame-num) 0.0)
                 )
               (logclear! (-> self flags) (terraformer-head-flag th0))
               )
             )
           )
         )
        (else
          (ja-channel-push! 3 (seconds 0.2))
          (ja :group! terraformer-head-slam-middle-ja :num! min)
          (let ((gp-6 (-> self skel root-channel 1)))
            (let ((f0-21 0.0))
              (set! (-> gp-6 frame-interp 1) f0-21)
              (set! (-> gp-6 frame-interp 0) f0-21)
              )
            (joint-control-channel-group-eval!
              gp-6
              (the-as art-joint-anim terraformer-head-slam-left-ja)
              num-func-identity
              )
            (set! (-> gp-6 frame-num) 0.0)
            )
          (let ((gp-7 (-> self skel root-channel 2)))
            (let ((f0-23 0.0))
              (set! (-> gp-7 frame-interp 1) f0-23)
              (set! (-> gp-7 frame-interp 0) f0-23)
              )
            (joint-control-channel-group-eval!
              gp-7
              (the-as art-joint-anim terraformer-head-slam-right-ja)
              num-func-identity
              )
            (set! (-> gp-7 frame-num) 0.0)
            )
          )
        )
      )
    (terraformer-head-always #f 0.0)
    )
  :code sleep-code
  :post transform-post
  )

(defstate initial-state (terraformer-head)
  :virtual #t
  :enter (behavior ()
    (set! (-> self command-index) 0)
    (set! (-> self command-timer) 0)
    (set! (-> self current-round) 0)
    0
    )
  :trans (behavior ()
    (cond
      ((= (-> self hit-points) 0.0)
       (let ((a1-0 (new 'stack-no-clear 'event-message-block)))
         (set! (-> a1-0 from) (process->ppointer self))
         (set! (-> a1-0 num-params) 0)
         (set! (-> a1-0 message) 'complete)
         (let ((t9-0 send-event-function)
               (v1-4 (-> *game-info* sub-task-list (game-task-node desert-final-boss-climb)))
               )
           (t9-0
             (handle->process (if (-> v1-4 manager)
                                  (-> v1-4 manager manager)
                                  (the-as handle #f)
                                  )
                              )
             a1-0
             )
           )
         )
       )
      ((not (task-node-closed? (game-task-node desert-final-boss-climb)))
       (set! (-> self dark-vent-timer) (+ (current-time) 1))
       (set! (-> self light-vent-timer) (+ (current-time) 1))
       (terraformer-head-send-group-event 0 'retract)
       )
      ((and (>= 0.25 (-> self hit-points)) (< (-> self stage) (the-as uint 2)))
       (set! (-> self stage) (the-as uint 2))
       (set! (-> self num-attacks) 2)
       (go-virtual slam)
       )
      ((and (>= 0.75 (-> self hit-points)) (< (-> self stage) (the-as uint 1)))
       (set! (-> self stage) (the-as uint 1))
       (set! (-> self num-attacks) 1)
       (go-virtual slam)
       )
      (else
        (go-virtual run-script)
        )
      )
    (let ((v1-40 (ja-group)))
      (cond
        ((and v1-40 (= v1-40 terraformer-head-idle-ja))
         (ja :num! (loop!))
         )
        (else
          (ja-channel-push! 1 (seconds 0.75))
          (ja :group! terraformer-head-idle-ja :num! min)
          )
        )
      )
    (terraformer-head-always #f 0.0)
    )
  :code sleep-code
  :post transform-post
  )

(defmethod relocate ((this terraformer-head) (offset int))
  (if (nonzero? (-> this head-aim-jm))
      (&+! (-> this head-aim-jm) offset)
      )
  (if (nonzero? (-> this neck-aim-jm))
      (&+! (-> this neck-aim-jm) offset)
      )
  (when (logtest? (-> this flags) (terraformer-head-flag laser-sound-playing))
    (sound-stop (-> this laser-sound-id))
    (logclear! (-> this flags) (terraformer-head-flag laser-sound-playing))
    )
  (when (logtest? (-> this flags) (terraformer-head-flag laser-warmup-sound-playing))
    (sound-stop (-> this warmup-sound-id))
    (logclear! (-> this flags) (terraformer-head-flag laser-warmup-sound-playing))
    )
  (call-parent-method this offset)
  )

(defmethod init-from-entity! ((this terraformer-head) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (local-vars (sv-16 res-tag))
  (let ((s4-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (let ((s3-0 (new 'process 'collide-shape-prim-group s4-0 (the-as uint 38) 0)))
      (set! (-> s4-0 total-prims) (the-as uint 39))
      (set! (-> s3-0 prim-core collide-as) (collide-spec enemy))
      (set! (-> s3-0 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> s3-0 prim-core action) (collide-action solid))
      (set! (-> s3-0 transform-index) 7)
      (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 450560.0)
      (set! (-> s4-0 root-prim) s3-0)
      )
    (let ((v1-9 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-9 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-9 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-9 prim-core action) (collide-action solid))
      (set! (-> v1-9 transform-index) 23)
      (set-vector! (-> v1-9 local-sphere) 0.0 2406.4 57.344 7281.459)
      )
    (let ((v1-11 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 1) (the-as uint 0))))
      (set! (-> v1-11 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-11 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-11 prim-core action) (collide-action solid))
      (set! (-> v1-11 transform-index) 22)
      (set-vector! (-> v1-11 local-sphere) 0.0 1138.688 -78.2336 2923.7249)
      )
    (let ((v1-13 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 2) (the-as uint 0))))
      (set! (-> v1-13 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-13 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-13 prim-core action) (collide-action solid))
      (set! (-> v1-13 transform-index) 21)
      (set-vector! (-> v1-13 local-sphere) 0.0 1412.7104 -78.2336 3553.28)
      )
    (let ((v1-15 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 3) (the-as uint 0))))
      (set! (-> v1-15 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-15 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-15 prim-core action) (collide-action solid))
      (set! (-> v1-15 transform-index) 20)
      (set-vector! (-> v1-15 local-sphere) 0.0 1806.336 -112.2304 4064.0513)
      )
    (let ((v1-17 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 4) (the-as uint 0))))
      (set! (-> v1-17 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-17 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-17 prim-core action) (collide-action solid))
      (set! (-> v1-17 transform-index) 19)
      (set-vector! (-> v1-17 local-sphere) 0.0 1499.9552 -156.0576 3604.0703)
      )
    (let ((v1-19 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 5) (the-as uint 0))))
      (set! (-> v1-19 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-19 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-19 prim-core action) (collide-action solid))
      (set! (-> v1-19 transform-index) 18)
      (set-vector! (-> v1-19 local-sphere) 0.0 2103.7056 -199.0656 4292.608)
      )
    (let ((v1-21 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 6) (the-as uint 0))))
      (set! (-> v1-21 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-21 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-21 prim-core action) (collide-action solid))
      (set! (-> v1-21 transform-index) 17)
      (set-vector! (-> v1-21 local-sphere) 0.0 1941.504 -215.04 3946.0864)
      )
    (let ((v1-23 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 7) (the-as uint 0))))
      (set! (-> v1-23 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-23 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-23 prim-core action) (collide-action solid))
      (set! (-> v1-23 transform-index) 16)
      (set-vector! (-> v1-23 local-sphere) 0.0 2340.864 -195.7888 4779.213)
      )
    (let ((v1-25 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 8) (the-as uint 0))))
      (set! (-> v1-25 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-25 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-25 prim-core action) (collide-action solid))
      (set! (-> v1-25 transform-index) 33)
      (set-vector! (-> v1-25 local-sphere) 0.4096 2406.4 57.344 7281.459)
      )
    (let ((v1-27 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 9) (the-as uint 0))))
      (set! (-> v1-27 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-27 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-27 prim-core action) (collide-action solid))
      (set! (-> v1-27 transform-index) 32)
      (set-vector! (-> v1-27 local-sphere) 0.4096 1138.688 -78.2336 2923.7249)
      )
    (let ((v1-29 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 10) (the-as uint 0))))
      (set! (-> v1-29 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-29 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-29 prim-core action) (collide-action solid))
      (set! (-> v1-29 transform-index) 31)
      (set-vector! (-> v1-29 local-sphere) 0.4096 1412.7104 -78.2336 3553.28)
      )
    (let ((v1-31 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 11) (the-as uint 0))))
      (set! (-> v1-31 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-31 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-31 prim-core action) (collide-action solid))
      (set! (-> v1-31 transform-index) 30)
      (set-vector! (-> v1-31 local-sphere) 0.4096 1806.336 -112.2304 4064.0513)
      )
    (let ((v1-33 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 12) (the-as uint 0))))
      (set! (-> v1-33 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-33 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-33 prim-core action) (collide-action solid))
      (set! (-> v1-33 transform-index) 29)
      (set-vector! (-> v1-33 local-sphere) 0.4096 1499.9552 -156.0576 3604.0703)
      )
    (let ((v1-35 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 13) (the-as uint 0))))
      (set! (-> v1-35 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-35 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-35 prim-core action) (collide-action solid))
      (set! (-> v1-35 transform-index) 28)
      (set-vector! (-> v1-35 local-sphere) 0.4096 2103.7056 -199.0656 4292.608)
      )
    (let ((v1-37 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 14) (the-as uint 0))))
      (set! (-> v1-37 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-37 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-37 prim-core action) (collide-action solid))
      (set! (-> v1-37 transform-index) 27)
      (set-vector! (-> v1-37 local-sphere) 0.4096 1941.504 -215.04 3946.0864)
      )
    (let ((v1-39 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 15) (the-as uint 0))))
      (set! (-> v1-39 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-39 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-39 prim-core action) (collide-action solid))
      (set! (-> v1-39 transform-index) 26)
      (set-vector! (-> v1-39 local-sphere) 0.4096 2340.864 -195.7888 4779.213)
      )
    (let ((v1-41 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 16) (the-as uint 2))))
      (set! (-> v1-41 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-41 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-41 prim-core action) (collide-action solid))
      (set! (-> v1-41 transform-index) 39)
      (set-vector! (-> v1-41 local-sphere) -199.0656 1118.6176 -54.8864 13074.842)
      )
    (let ((v1-43 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 17) (the-as uint 2))))
      (set! (-> v1-43 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-43 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-43 prim-core action) (collide-action solid))
      (set! (-> v1-43 transform-index) 40)
      (set-vector! (-> v1-43 local-sphere) 199.8848 1118.6176 -54.8864 13074.842)
      )
    (let ((v1-45 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 18) (the-as uint 1))))
      (set! (-> v1-45 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-45 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-45 prim-core action) (collide-action solid))
      (set! (-> v1-45 transform-index) 44)
      (set-vector! (-> v1-45 local-sphere) -839.68 5391.9746 -917.0944 7594.3936)
      )
    (let ((v1-47 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 19) (the-as uint 1))))
      (set! (-> v1-47 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-47 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-47 prim-core action) (collide-action solid))
      (set! (-> v1-47 transform-index) 43)
      (set-vector! (-> v1-47 local-sphere) -781.5168 11664.18 -807.7312 7633.7153)
      )
    (let ((v1-49 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 20) (the-as uint 1))))
      (set! (-> v1-49 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-49 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-49 prim-core action) (collide-action solid))
      (set! (-> v1-49 transform-index) 36)
      (set-vector! (-> v1-49 local-sphere) -599.2448 5496.0127 -965.4272 7401.0625)
      )
    (let ((v1-51 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 21) (the-as uint 1))))
      (set! (-> v1-51 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-51 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-51 prim-core action) (collide-action solid))
      (set! (-> v1-51 transform-index) 35)
      (set-vector! (-> v1-51 local-sphere) -777.4208 10016.768 -934.2976 10309.223)
      )
    (let ((v1-53 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 22) (the-as uint 1))))
      (set! (-> v1-53 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-53 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-53 prim-core action) (collide-action solid))
      (set! (-> v1-53 transform-index) 46)
      (set-vector! (-> v1-53 local-sphere) 577.536 5498.061 -966.2464 7400.653)
      )
    (let ((v1-55 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 23) (the-as uint 1))))
      (set! (-> v1-55 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-55 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-55 prim-core action) (collide-action solid))
      (set! (-> v1-55 transform-index) 45)
      (set-vector! (-> v1-55 local-sphere) 776.192 10017.178 -934.2976 10309.223)
      )
    (let ((v1-57 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 24) (the-as uint 1))))
      (set! (-> v1-57 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-57 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-57 prim-core action) (collide-action solid))
      (set! (-> v1-57 transform-index) 48)
      (set-vector! (-> v1-57 local-sphere) 733.184 5415.731 -924.0576 7594.803)
      )
    (let ((v1-59 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 25) (the-as uint 1))))
      (set! (-> v1-59 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-59 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-59 prim-core action) (collide-action solid))
      (set! (-> v1-59 transform-index) 47)
      (set-vector! (-> v1-59 local-sphere) 734.0032 11667.047 -812.2368 7633.7153)
      )
    (let ((v1-61 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 26) (the-as uint 1))))
      (set! (-> v1-61 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-61 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-61 prim-core action) (collide-action solid))
      (set! (-> v1-61 transform-index) 13)
      (set-vector! (-> v1-61 local-sphere) 0.0 18407.014 8227.635 41536.72)
      )
    (let ((v1-63 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 27) (the-as uint 1))))
      (set! (-> v1-63 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-63 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-63 prim-core action) (collide-action solid))
      (set! (-> v1-63 transform-index) 13)
      (set-vector! (-> v1-63 local-sphere) 0.0 -108.544 -162.6112 14893.056)
      )
    (let ((v1-65 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 28) (the-as uint 1))))
      (set! (-> v1-65 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-65 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-65 prim-core action) (collide-action solid))
      (set! (-> v1-65 transform-index) 12)
      (set-vector! (-> v1-65 local-sphere) 6.9632 28440.986 113.8688 40957.133)
      )
    (let ((v1-67 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 29) (the-as uint 0))))
      (set! (-> v1-67 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-67 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-67 prim-core action) (collide-action solid))
      (set! (-> v1-67 transform-index) 11)
      (set-vector! (-> v1-67 local-sphere) 0.0 13346.816 2224.5376 35631.51)
      )
    (let ((v1-69 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 30) (the-as uint 0))))
      (set! (-> v1-69 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-69 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-69 prim-core action) (collide-action solid))
      (set! (-> v1-69 transform-index) 10)
      (set-vector! (-> v1-69 local-sphere) 0.0 23511.86 -7367.885 51299.125)
      )
    (let ((v1-71 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 31) (the-as uint 0))))
      (set! (-> v1-71 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-71 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-71 prim-core action) (collide-action solid))
      (set! (-> v1-71 transform-index) 9)
      (set-vector! (-> v1-71 local-sphere) 0.0 34826.65 -8377.14 60566.734)
      )
    (let ((v1-73 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 32) (the-as uint 0))))
      (set! (-> v1-73 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-73 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-73 prim-core action) (collide-action solid))
      (set! (-> v1-73 transform-index) 8)
      (set-vector! (-> v1-73 local-sphere) 0.0 37076.992 -9768.141 56511.69)
      )
    (let ((v1-75 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 33) (the-as uint 0))))
      (set! (-> v1-75 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-75 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-75 prim-core action) (collide-action solid))
      (set! (-> v1-75 transform-index) 7)
      (set-vector! (-> v1-75 local-sphere) 0.0 33041.613 -8002.355 59857.305)
      )
    (let ((v1-77 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 34) (the-as uint 0))))
      (set! (-> v1-77 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-77 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-77 prim-core action) (collide-action solid))
      (set! (-> v1-77 transform-index) 6)
      (set-vector! (-> v1-77 local-sphere) 0.0 37052.008 -810.1888 66761.52)
      )
    (let ((v1-79 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 35) (the-as uint 0))))
      (set! (-> v1-79 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-79 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-79 prim-core action) (collide-action solid))
      (set! (-> v1-79 transform-index) 5)
      (set-vector! (-> v1-79 local-sphere) 0.0 37220.35 -5197.005 58764.492)
      )
    (let ((v1-81 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 36) (the-as uint 0))))
      (set! (-> v1-81 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-81 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-81 prim-core action) (collide-action solid))
      (set! (-> v1-81 transform-index) 4)
      (set-vector! (-> v1-81 local-sphere) 0.0 41623.55 14107.443 62561.895)
      )
    (let ((v1-83 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 37) (the-as uint 0))))
      (set! (-> v1-83 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-83 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-83 prim-core action) (collide-action solid))
      (set! (-> v1-83 transform-index) 3)
      (set-vector! (-> v1-83 local-sphere) 0.0 167802.06 25416.5 96510.77)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-86 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-86 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-86 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (process-drawable-from-entity! this arg0)
  (vector-copy! (-> this initial-position) (-> this root trans))
  (+! (-> this root trans x) 204800.0)
  (+! (-> this root trans y) -57344.0)
  (init (-> this position-seeker) (-> this root trans) 40.96 4096.0 0.3)
  (initialize-skeleton
    this
    (the-as
      skeleton-group
      (art-group-get-by-name *level* "skel-terraformer-head-ingame" (the-as (pointer level) #f))
      )
    (the-as pair 0)
    )
  (set! (-> this draw shadow-ctrl) *terraformer-head-shadow-control*)
  (logclear! (-> this mask) (process-mask actor-pause))
  (logior! (-> this mask) (process-mask enemy))
  (set! (-> this head-aim-jm) (new 'process 'joint-mod-polar-look-at))
  (initialize (-> this head-aim-jm) this 13)
  (set! (-> this head-aim-jm ear) 0)
  (set! (-> this head-aim-jm up) 2)
  (set! (-> this head-aim-jm nose) 1)
  (set! (-> this neck-aim-jm) (new 'process 'joint-mod-disc-look-at))
  (initialize (-> this neck-aim-jm) this 12)
  (set! (-> this neck-aim-jm up) 1)
  (set! (-> this neck-aim-jm nose) 2)
  (logior! (-> this neck-aim-jm flags) (jmod-disc-lookat-flag jdl1))
  (vector-copy! (-> this target-position) (target-pos 0))
  (tracking-spline-method-10 (-> this target-spline) (-> this target-position))
  (set! (-> this beam-projectile) (the-as handle #f))
  (set! (-> this hit-points) 1.0)
  (set! (-> this stage) (the-as uint 0))
  (set! (-> this incoming-attack-id) (the-as uint 0))
  (set! (-> *game-info* counter) (-> this hit-points))
  (set! (-> this vulnerable-timer) 0)
  (set! (-> this very-vulnerable-timer) 0)
  (set! (-> this flags) (terraformer-head-flag))
  (set! (-> this actor-group-count) 0)
  (set! sv-16 (new 'static 'res-tag))
  (let ((v1-127 (res-lump-data arg0 'actor-groups pointer :tag-ptr (& sv-16))))
    (cond
      ((and v1-127 (nonzero? (-> sv-16 elt-count)))
       (set! (-> this actor-group-count) (the-as int (-> sv-16 elt-count)))
       (set! (-> this actor-group) (the-as (pointer actor-group) v1-127))
       )
      (else
        (format 0 "ERROR: ~S: entity missing actor-group!~%" (-> this name))
        )
      )
    )
  (let ((a0-263 (nav-mesh-from-res-tag (-> this entity) 'nav-mesh-actor 0)))
    (when a0-263
      (change-to a0-263 this)
      (when (-> this nav)
        (let ((v1-134 (-> this nav)))
          (set! (-> v1-134 sphere-mask) (the-as uint 0))
          )
        0
        )
      )
    )
  (dotimes (v1-136 8)
    (set! (-> this critter v1-136 handle) (the-as handle #f))
    )
  (dotimes (v1-139 20)
    (set! (-> this ammo v1-139 handle) (the-as handle #f))
    (set! (-> this ammo v1-139 birth-next-time) #f)
    )
  (set! (-> this terraformer-head-target) (the-as handle #f))
  (set! (-> this dark-vent-timer) 0)
  (set! (-> this dark-vent-connection) #f)
  (set! (-> this light-vent-timer) 0)
  (set! (-> this light-vent-connection) #f)
  (terraformer-head-connect-tank-glows)
  (set! (-> this laser-sound-id) (new-sound-id))
  (set! (-> this warmup-sound-id) (new-sound-id))
  (go (method-of-object this initial-state))
  )
