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

;; name: terraformer-setup.gc
;; name in dgo: terraformer-setup
;; dgos: DESBOSS1

(declare-type terraformer-leg process-drawable)

;; DECOMP BEGINS

(define *terraformer-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 -40960000.0)
                                           :bot-plane (new 'static 'plane :y 1.0 :w 983040.0)
                                           :top-plane (new 'static 'plane :y 1.0 :w -245760.0)
                                           )
                               )
  )

(deftype terraformer-foot-mark-pt (structure)
  ((collision-pt  vector  :inline)
   (normal        vector  :inline)
   (found?        symbol)
   (angle         float)
   )
  )


(deftype terraformer-foot-mark-pt-array (basic)
  ((points         terraformer-foot-mark-pt  20 :inline)
   (origin         vector                    :inline)
   (radius         float)
   (current-point  int32)
   )
  (:methods
    (init! (_type_ vector float) none)
    (terraformer-foot-mark-pt-array-method-10 (_type_) int)
    (terraformer-foot-mark-pt-array-method-11 (_type_ process) int)
    )
  )


(defmethod init! ((this terraformer-foot-mark-pt-array) (arg0 vector) (arg1 float))
  (vector-copy! (-> this origin) arg0)
  (set! (-> this radius) arg1)
  (set! (-> this current-point) 0)
  0
  (none)
  )

(defmethod terraformer-foot-mark-pt-array-method-10 ((this terraformer-foot-mark-pt-array))
  (if (>= (-> this current-point) 20)
      (return 0)
      )
  (let ((gp-0 (new 'stack-no-clear 'collide-query))
        (s5-0 (-> this points (-> this current-point)))
        )
    (set! (-> s5-0 found?) #f)
    (let* ((f0-0 3449.2632)
           (f30-0 (* f0-0 (the float (-> this current-point))))
           (s3-0 (new 'stack-no-clear 'vector))
           )
      (let ((f0-3 (+ f30-0 (rand-vu-float-range (* -0.43 f0-0) (* 0.43 f0-0)))))
        (set! (-> s5-0 angle) f0-3)
        (sincos! s3-0 f0-3)
        )
      (set! (-> s3-0 z) (* (-> s3-0 y) (-> this radius) (rand-vu-float-range 0.7 0.9)))
      (set! (-> s3-0 y) 32768.0)
      (set! (-> s3-0 x) (* (-> s3-0 x) (-> this radius) (rand-vu-float-range 0.7 0.9)))
      (vector+! (-> gp-0 start-pos) (-> this origin) s3-0)
      )
    (set-vector! (-> gp-0 move-dist) 0.0 -65536.0 0.0 1.0)
    (let ((v1-13 gp-0))
      (set! (-> v1-13 radius) 409.6)
      (set! (-> v1-13 collide-with) (collide-spec backgnd pusher))
      (set! (-> v1-13 ignore-process0) #f)
      (set! (-> v1-13 ignore-process1) #f)
      (set! (-> v1-13 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-13 action-mask) (collide-action solid))
      )
    (+! (-> this current-point) 1)
    (let ((f0-16 (fill-and-probe-using-line-sphere *collide-cache* gp-0)))
      (when (>= f0-16 0.0)
        (vector+*! (-> s5-0 collision-pt) (-> gp-0 start-pos) (-> gp-0 move-dist) f0-16)
        (+! (-> s5-0 collision-pt y) 204.8)
        (set! (-> s5-0 found?) #t)
        (vector-normalize-copy! (-> s5-0 normal) (-> gp-0 best-other-tri normal) 1.0)
        (let ((s3-1 (new 'stack-no-clear 'vector))
              (s4-1 (new 'stack-no-clear 'inline-array 'vector 4))
              )
          (vector-cross! s3-1 (-> s5-0 normal) (vector-get-unique! (new 'stack-no-clear 'vector) (-> s5-0 normal)))
          (vector-normalize! s3-1 10240.0)
          (vector-copy! (-> s4-1 0) s3-1)
          (vector-cross! (-> s4-1 1) s3-1 (-> s5-0 normal))
          (vector-negate! (-> s4-1 2) s3-1)
          (vector-cross! (-> s4-1 3) (-> s5-0 normal) s3-1)
          (vector-float*! s3-1 (-> s5-0 normal) 3072.0)
          (dotimes (v1-28 4)
            (vector+! (-> s4-1 v1-28) (-> s4-1 v1-28) s3-1)
            (vector+! (-> s4-1 v1-28) (-> s4-1 v1-28) (-> s5-0 collision-pt))
            )
          (vector-float*! (-> gp-0 move-dist) s3-1 -2.0)
          (let ((s3-2 (new 'stack-no-clear 'collide-query)))
            (let ((a1-20 (new 'stack-no-clear 'bounding-box)))
              (let* ((f0-21 409.6)
                     (f1-9 3072.0)
                     (f1-11 (* f1-9 f1-9))
                     (f2-0 10240.0)
                     (f0-22 (+ f0-21 (sqrtf (+ f1-11 (* f2-0 f2-0)))))
                     (v1-38 (new 'stack-no-clear 'vector))
                     )
                (set-vector! v1-38 f0-22 f0-22 f0-22 1.0)
                (vector+! (-> a1-20 max) (-> s5-0 collision-pt) v1-38)
                (vector-! (-> a1-20 min) (-> s5-0 collision-pt) v1-38)
                )
              (set! (-> s3-2 collide-with) (collide-spec backgnd pusher))
              (set! (-> s3-2 ignore-process0) #f)
              (set! (-> s3-2 ignore-process1) #f)
              (set! (-> s3-2 ignore-pat)
                    (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                    )
              (set! (-> s3-2 action-mask) (collide-action solid))
              (mem-copy! (the-as pointer (-> s3-2 bbox)) (the-as pointer a1-20) 32)
              )
            (fill-using-bounding-box *collide-cache* s3-2)
            )
          (dotimes (s3-3 4)
            (vector-copy! (-> gp-0 start-pos) (-> s4-1 s3-3))
            (when (< (probe-using-line-sphere *collide-cache* gp-0) 0.0)
              (set! (-> s5-0 found?) #f)
              (return 0)
              )
            )
          )
        )
      )
    )
  0
  )

(defmethod terraformer-foot-mark-pt-array-method-11 ((this terraformer-foot-mark-pt-array) (arg0 process))
  (let ((s4-0 (new 'stack-no-clear 'vector)))
    (set! (-> s4-0 x) 0.0)
    (set! (-> s4-0 y) 409.6)
    (set! (-> s4-0 z) 0.0)
    (set! (-> s4-0 w) 1.0)
    (let ((s3-0 (new 'stack-no-clear 'matrix)))
      (dotimes (s2-0 4)
        (+! (-> this current-point) -1)
        (if (< (-> this current-point) 0)
            (return 0)
            )
        (let ((s1-0 (-> this points (-> this current-point))))
          (when (-> s1-0 found?)
            (vector-copy! (-> s3-0 uvec) (-> s1-0 normal))
            (vector-cross!
              (-> s3-0 rvec)
              (-> s3-0 uvec)
              (vector-! (new 'stack-no-clear 'vector) (-> s1-0 collision-pt) (-> this origin))
              )
            (vector-normalize! (-> s3-0 rvec) 1.0)
            (vector-cross! (-> s3-0 fvec) (-> s3-0 rvec) (-> s3-0 uvec))
            (let ((s0-0 (matrix->quaternion (new 'stack-no-clear 'quaternion) s3-0)))
              (quaternion-rotate-local-y! s0-0 s0-0 49152.0)
              (quaternion->matrix s3-0 s0-0)
              )
            (vector+! (-> s3-0 trans) (-> s1-0 collision-pt) s4-0)
            (let ((v1-23
                    (if (logtest? (-> group-terraformer-foot-mark flags) (sp-group-flag sp13))
                        (part-tracker-spawn part-tracker-subsampler :to arg0 :group group-terraformer-foot-mark :mat-joint s3-0)
                        (part-tracker-spawn part-tracker :to arg0 :group group-terraformer-foot-mark :mat-joint s3-0)
                        )
                    )
                  )
              (send-event (ppointer->process v1-23) 'clock arg0)
              )
            )
          )
        )
      )
    )
  0
  )

(deftype terraformer-node (structure)
  ((position    vector  :inline)
   (edge-index  int16)
   (edge-count  int16)
   (pos-x       float   :overlay-at (-> position data 0))
   (pos-y       float   :overlay-at (-> position data 1))
   (pos-z       float   :overlay-at (-> position data 2))
   )
  )


(deftype terraformer-edge (structure)
  ((dest-node-id  uint16)
   )
  )


(deftype terraformer-graph (structure)
  ((node-count  uint16)
   (edge-count  uint16)
   (node        (inline-array terraformer-node))
   (edge        (inline-array terraformer-edge))
   )
  )


(define *terraformer-walk-graph* (new 'static 'terraformer-graph
                                   :node-count #xd
                                   :edge-count #xc
                                   :node (new 'static 'inline-array terraformer-node 13
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 4854128.0 :y 187006.56 :z 2035269.2)
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 6361250.5 :y 176355.33 :z 2473348.8)
                                       :edge-index 1
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 12365330.0 :y 118793.01 :z 7740005.0)
                                       :edge-index 2
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 14274681.0 :y 113428.89 :z 6088825.5)
                                       :edge-index 3
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 13698579.0 :y 192728.27 :z 3452370.0)
                                       :edge-index 4
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 13307247.0 :y 119303.375 :z 2811956.5)
                                       :edge-index 5
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 11517909.0 :y 106544.336 :z 1921154.6)
                                       :edge-index 6
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 8252865.5 :y 254936.67 :z 2569715.0)
                                       :edge-index 7
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 4372684.0 :y 218844.36 :z 5906963.5)
                                       :edge-index 8
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 5888695.0 :y 247336.55 :z 9088736.0)
                                       :edge-index 9
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 8337694.0 :y 111284.23 :z 11423251.0)
                                       :edge-index 10
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 11402484.0 :y 124463.92 :z 10601634.0)
                                       :edge-index 11
                                       :edge-count 1
                                       )
                                     (new 'static 'terraformer-node
                                       :position (new 'static 'vector :x 12095772.0 :y 190483.25 :z 9131334.0)
                                       :edge-index 12
                                       )
                                     )
                                   :edge (new 'static 'inline-array terraformer-edge 12
                                     (new 'static 'terraformer-edge :dest-node-id #x8)
                                     (new 'static 'terraformer-edge)
                                     (new 'static 'terraformer-edge :dest-node-id #x3)
                                     (new 'static 'terraformer-edge :dest-node-id #x4)
                                     (new 'static 'terraformer-edge :dest-node-id #x5)
                                     (new 'static 'terraformer-edge :dest-node-id #x6)
                                     (new 'static 'terraformer-edge :dest-node-id #x7)
                                     (new 'static 'terraformer-edge :dest-node-id #x1)
                                     (new 'static 'terraformer-edge :dest-node-id #x9)
                                     (new 'static 'terraformer-edge :dest-node-id #xa)
                                     (new 'static 'terraformer-edge :dest-node-id #xb)
                                     (new 'static 'terraformer-edge :dest-node-id #xc)
                                     )
                                   )
        )

(defskelgroup skel-terraformer terraformer terraformer-lod0-jg terraformer-walk-ja
              ((terraformer-lod0-mg (meters 20)) (terraformer-lod1-mg (meters 40)) (terraformer-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 175 75 250)
              :shadow terraformer-shadow-mg
              :origin-joint-index 3
              :shadow-joint-index 3
              :global-effects 32
              )

(defskelgroup skel-terraformer-leg-a terraformer-leg-a terraformer-leg-a-lod0-jg terraformer-leg-a-lf-walk-ja
              ((terraformer-leg-a-lod0-mg (meters 20))
               (terraformer-leg-a-lod1-mg (meters 40))
               (terraformer-leg-a-lod2-mg (meters 999999))
               )
              :bounds (static-spherem 0 38 0 50)
              :shadow terraformer-leg-a-shadow-mg
              :origin-joint-index 3
              :shadow-joint-index 3
              :global-effects 32
              )

(defskelgroup skel-terraformer-leg-b terraformer-leg-b terraformer-leg-b-lod0-jg terraformer-leg-b-lf-walk-ja
              ((terraformer-leg-b-lod0-mg (meters 20))
               (terraformer-leg-b-lod1-mg (meters 40))
               (terraformer-leg-b-lod2-mg (meters 999999))
               )
              :bounds (static-spherem 0 61 0 68)
              :shadow terraformer-leg-b-shadow-mg
              :origin-joint-index 4
              :shadow-joint-index 4
              :global-effects 32
              )

(defskelgroup skel-terraformer-leg-c terraformer-leg-c terraformer-leg-c-lod0-jg terraformer-leg-c-lf-walk-ja
              ((terraformer-leg-c-lod0-mg (meters 20))
               (terraformer-leg-c-lod1-mg (meters 40))
               (terraformer-leg-c-lod2-mg (meters 999999))
               )
              :bounds (static-spherem 0 25 0 75)
              :shadow terraformer-leg-c-shadow-mg
              :origin-joint-index 5
              :shadow-joint-index 5
              :global-effects 32
              )

(defskelgroup skel-terraformer-spike terraformer-spike terraformer-spike-lod0-jg terraformer-spike-idle-ja
              ((terraformer-spike-lod0-mg (meters 20))
               (terraformer-spike-lod1-mg (meters 40))
               (terraformer-spike-lod2-mg (meters 999999))
               )
              :bounds (static-spherem 0 40 20 35)
              :shadow terraformer-spike-shadow-mg
              :origin-joint-index 3
              :shadow-joint-index 3
              :global-effects 32
              )

(defskelgroup skel-terraformer-target terraformer-target terraformer-target-lod0-jg terraformer-target-idle-ja
              ((terraformer-target-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 5)
              :origin-joint-index 3
              :global-effects 32
              )

(defskelgroup skel-terraformer-mine terraformer-mine terraformer-mine-lod0-jg terraformer-mine-spike-out-ja
              ((terraformer-mine-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 5)
              :origin-joint-index 3
              :global-effects 32
              )

(deftype terraformer-ik-setup (structure)
  ((elbow-index  int32)
   (hand-dist    float)
   )
  )


(define *terraformer-ik-setup* (new 'static 'terraformer-ik-setup :elbow-index 6 :hand-dist 106496.0))

(deftype terraformer-foot-lock (structure)
  ((lock          cam-float-seeker  :inline)
   (old-position  vector            :inline)
   (old-normal    vector            :inline)
   (initialized   symbol)
   )
  )


(deftype terraformer (process-drawable)
  ((self                     terraformer   :override)
   (root                     collide-shape :override)
   (graph                    terraformer-graph)
   (current-node             uint16)
   (legs                     handle         6)
   (mine-timer               time-frame)
   (mines-to-launch          int8)
   (launch-drones            symbol)
   (old-target-pos           vector         :inline)
   (old-target-time          time-frame)
   (older-target-pos         vector         :inline)
   (older-target-time        time-frame)
   (anim-speed               float)
   (spooled-anim             spool-anim)
   (desired-nav-mesh-index   int8)
   (current-nav-mesh-index   int8)
   (mines                    handle         10)
   (jumper                   handle)
   (drone                    handle)
   (drone-time               time-frame)
   (jump-dest                vector         :inline)
   (target-rot               matrix         :inline)
   (mine-rounds-till-drones  int8)
   )
  (:state-methods
    dormant
    frozen
    stand-still-laddie!
    idle
    scrub-anim
    walk
    )
  )


(deftype terraformer-mine (process-focusable)
  ((parent                 (pointer terraformer) :override)
   (src-pos                vector                 :inline)
   (dest-pos               vector                 :inline)
   (traj                   trajectory             :inline)
   (which-trajectory       int8)
   (x-rotate               float)
   (y-rotate               float)
   (trail-part             sparticle-launch-control)
   (incoming-sound-played  symbol)
   (expand-sound-played    symbol)
   (exploded               symbol)
   )
  (:state-methods
    idle
    fly-to-dest
    )
  )


(deftype terraformer-target (process-focusable)
  ((parent  (pointer terraformer-leg) :override)
   )
  (:state-methods
    idle
    )
  )


(deftype terraformer-leg-minimap-dot (process-drawable)
  ((parent   (pointer terraformer-leg) :override)
   (minimap  connection-minimap)
   )
  (:state-methods
    idle
    )
  )


(deftype terraformer-foot-water-splash (structure)
  ((frame  float)
   )
  )


(define *terraformer-lf-water-splash-list* (new 'static 'boxed-array :type terraformer-foot-water-splash
                                             (new 'static 'terraformer-foot-water-splash :frame 1814.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3323.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3439.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3671.0)
                                             )
        )

(define *terraformer-lm-water-splash-list* (new 'static 'boxed-array :type terraformer-foot-water-splash
                                             (new 'static 'terraformer-foot-water-splash :frame 2003.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3743.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 4208.0)
                                             )
        )

(define *terraformer-lr-water-splash-list* (new 'static 'boxed-array :type terraformer-foot-water-splash
                                             (new 'static 'terraformer-foot-water-splash :frame 1945.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3569.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3801.0)
                                             )
        )

(define *terraformer-rf-water-splash-list* (new 'static 'boxed-array :type terraformer-foot-water-splash
                                             (new 'static 'terraformer-foot-water-splash :frame 1750.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3376.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3491.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3607.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3723.0)
                                             )
        )

(define *terraformer-rm-water-splash-list* (new 'static 'boxed-array :type terraformer-foot-water-splash
                                             (new 'static 'terraformer-foot-water-splash :frame 3429.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3544.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3660.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3777.0)
                                             )
        )

(define *terraformer-rr-water-splash-list* (new 'static 'boxed-array :type terraformer-foot-water-splash
                                             (new 'static 'terraformer-foot-water-splash :frame 1879.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3505.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3620.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3737.0)
                                             (new 'static 'terraformer-foot-water-splash :frame 3852.0)
                                             )
        )

(deftype terraformer-leg (process-drawable)
  ((parent                   (pointer terraformer) :override)
   (root                     collide-shape         :override)
   (prefix                   string)
   (kind                     int8)
   (side                     int8)
   (targets                  handle                 6)
   (mm-handle                handle)
   (joint-ik                 joint-mod-ik)
   (foot-lock                terraformer-foot-lock  :inline)
   (foot-marks               terraformer-foot-mark-pt-array)
   (collision-disable-timer  time-frame)
   (foot-up-frame            float)
   (last-effect              int8)
   (sand-drop-part           sparticle-launch-control)
   (water-drop-part          sparticle-launch-control)
   (splash-list              (array terraformer-foot-water-splash))
   (splash-list-index        int8)
   (stepped-in-water         symbol)
   )
  (:state-methods
    idle
    )
  )


(defbehavior terraformer-leg-minimap-dot-init-by-other terraformer-leg-minimap-dot ()
  (set! (-> self root) (new 'process 'trsqv))
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer-target" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (logclear! (-> self mask) (process-mask actor-pause))
  (logior! (-> self draw status) (draw-control-status no-draw-bounds))
  (go-virtual idle)
  )

(defstate idle (terraformer-leg-minimap-dot)
  :virtual #t
  :enter (behavior ()
    (set! (-> self minimap) (add-icon! *minimap* self (the-as uint 129) (the-as int #f) (the-as vector #t) 0))
    )
  :exit (behavior ()
    (kill-callback (-> *minimap* engine) (-> self minimap))
    )
  :trans (behavior ()
    (vector<-cspace! (-> self root trans) (-> (ppointer->process (-> self parent)) node-list data 6))
    )
  :code sleep-code
  )

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

;; WARN: Return type mismatch process-focusable vs terraformer-mine.
(defmethod relocate ((this terraformer-mine) (offset int))
  (if (nonzero? (-> this trail-part))
      (&+! (-> this trail-part) offset)
      )
  (the-as terraformer-mine ((method-of-type process-focusable relocate) this offset))
  )

(defbehavior terraformer-mine-init-by-other terraformer-mine ((arg0 vector) (arg1 vector))
  (let ((s4-0 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
    (let ((v1-2 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> v1-2 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-2 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-2 prim-core action) (collide-action solid))
      (set! (-> v1-2 transform-index) 3)
      (set-vector! (-> v1-2 local-sphere) 0.0 0.0 0.0 16384.0)
      (set! (-> s4-0 total-prims) (the-as uint 1))
      (set! (-> s4-0 root-prim) v1-2)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-5 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-5 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-5 prim-core collide-with))
      )
    (set! (-> s4-0 event-self) 'touched)
    (set! (-> self root) s4-0)
    )
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer-mine" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (set! (-> self draw light-index) (-> (ppointer->process (-> self parent)) draw light-index))
  (logior! (-> self mask) (process-mask enemy))
  (logclear! (-> self mask) (process-mask actor-pause))
  (vector-copy! (-> self src-pos) arg0)
  (vector-copy! (-> self dest-pos) arg1)
  (set! (-> self which-trajectory) 0)
  self
  (set! (-> self trail-part)
        (the-as
          sparticle-launch-control
          (new 'process 'sparticle-subsampler *sp-particle-system-2d* (-> *part-id-table* 1735) 5.0)
          )
        )
  (set! (-> self incoming-sound-played) #f)
  (set! (-> self expand-sound-played) #f)
  (set! (-> self exploded) #f)
  (set! (-> self event-hook) (-> (method-of-object self idle) event))
  (go-virtual fly-to-dest)
  )

;; WARN: Return type mismatch none vs object.
(defbehavior terraformer-mine-explode terraformer-mine ()
  (let ((gp-0 (new 'stack-no-clear 'explosion-init-params)))
    (sound-play "mine-explode" :position (-> self root trans))
    (vector-copy! (-> gp-0 spawn-point) (-> self root trans))
    (quaternion-identity! (-> gp-0 spawn-quat))
    (set! (-> gp-0 radius) 24576.0)
    (set! (-> gp-0 scale) 1.0)
    (set! (-> gp-0 group) group-kg-big-explosion)
    (set! (-> gp-0 collide-with) (collide-spec))
    (set! (-> gp-0 damage) 2.0)
    (set! (-> gp-0 damage-scale) 1.0)
    (set! (-> gp-0 vehicle-damage-factor) 1.0)
    (set! (-> gp-0 vehicle-impulse-factor) 1.0)
    (set! (-> gp-0 ignore-proc) (process->handle #f))
    (explosion-spawn gp-0 (the-as process-drawable *default-pool*))
    )
  (set! (-> self exploded) #t)
  (deactivate self)
  )

(defbehavior terraformer-mine-handler terraformer-mine ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('touch 'touched 'attack 'bonk 'explode)
     (if (and (not (-> self exploded)) (type? arg0 projectile))
         (turbo-pickup-spawn (-> self root trans))
         )
     (terraformer-mine-explode)
     )
    )
  )

(defstate idle (terraformer-mine)
  :virtual #t
  :event terraformer-mine-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (let ((v1-2 (ja-group)))
      (cond
        ((and v1-2 (= v1-2 terraformer-mine-idle-ja))
         (ja :num! (loop!))
         )
        (else
          (ja :num! (seek!))
          (if (ja-done? 0)
              (ja :group! terraformer-mine-idle-ja :num! min)
              )
          )
        )
      )
    (if (time-elapsed? (-> self state-time) (seconds 3))
        (terraformer-mine-explode)
        )
    )
  :code sleep-code
  :post (behavior ()
    (transform-post)
    (do-push-aways (-> self root))
    )
  )

(defstate fly-to-dest (terraformer-mine)
  :virtual #t
  :event terraformer-mine-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((f30-0 0.0)
          (f28-0 300.0)
          )
      (if (< (-> self src-pos y) (-> self dest-pos y))
          (+! f30-0 (- (-> self dest-pos y) (-> self src-pos y)))
          )
      (let ((f0-5 (* 0.0000024414062 (vector-vector-xz-distance (-> self src-pos) (-> self dest-pos)) f28-0)))
        (setup-from-to-duration-and-height! (-> self traj) (-> self src-pos) (-> self dest-pos) f0-5 f30-0)
        )
      )
    (set! (-> self which-trajectory) 0)
    (set! (-> self x-rotate) (* 65536.0 (rand-vu)))
    (set! (-> self y-rotate) (* 65536.0 (rand-vu)))
    (vector-copy! (-> self root trans) (-> self src-pos))
    )
  :trans (behavior ()
    (cond
      ((zero? (-> self which-trajectory))
       (+! (-> self x-rotate) 4369.067)
       (+! (-> self y-rotate) 3458.8445)
       )
      (else
        (+! (-> self x-rotate) 2730.6667)
        (+! (-> self y-rotate) 2002.4889)
        )
      )
    (if (< 65536.0 (-> self x-rotate))
        (+! (-> self x-rotate) -65536.0)
        )
    (if (< 65536.0 (-> self y-rotate))
        (+! (-> self y-rotate) -65536.0)
        )
    (let ((s5-0 (new 'stack-no-clear 'quaternion))
          (gp-0 (new 'stack-no-clear 'quaternion))
          )
      (quaternion-set! s5-0 (sin (/ (-> self x-rotate) 2)) 0.0 0.0 (cos (/ (-> self x-rotate) 2)))
      (quaternion-set! gp-0 0.0 (sin (/ (-> self y-rotate) 2)) 0.0 (cos (/ (-> self y-rotate) 2)))
      (quaternion-normalize! (quaternion*! (-> self root quat) gp-0 s5-0))
      )
    (cond
      ((time-elapsed? (-> self state-time) (the int (-> self traj time)))
       (cond
         ((zero? (-> self which-trajectory))
          (set! (-> self which-trajectory) 1)
          (compute-trans-at-time
            (-> self traj)
            (fmin (-> self traj time) (the float (- (current-time) (-> self state-time))))
            (-> self root trans)
            )
          (let ((gp-1 (new 'stack-no-clear 'matrix)))
            (matrix-identity! gp-1)
            (vector-copy! (-> gp-1 trans) (-> self root trans))
            (if (logtest? (-> group-terraformer-mine-dust flags) (sp-group-flag sp13))
                (part-tracker-spawn
                  part-tracker-subsampler
                  :to *entity-pool*
                  :group group-terraformer-mine-dust
                  :duration (seconds 1)
                  :mat-joint gp-1
                  )
                (part-tracker-spawn
                  part-tracker
                  :to *entity-pool*
                  :group group-terraformer-mine-dust
                  :duration (seconds 1)
                  :mat-joint gp-1
                  )
                )
            )
          (set-time! (-> self state-time))
          (let ((gp-3 (vector-! (new 'stack-no-clear 'vector) (-> self root trans) (-> self traj initial-position))))
            (set! (-> gp-3 y) 0.0)
            (vector-normalize! gp-3 12288.0)
            (vector+! gp-3 gp-3 (-> self root trans))
            (let ((s5-3 (new 'stack-no-clear 'collide-query)))
              (set-vector! (-> s5-3 move-dist) 0.0 -122880.0 0.0 1.0)
              (vector-copy! (-> s5-3 start-pos) gp-3)
              (+! (-> s5-3 start-pos y) 61440.0)
              (let ((v1-69 s5-3))
                (set! (-> v1-69 radius) 4096.0)
                (set! (-> v1-69 collide-with) (collide-spec backgnd))
                (set! (-> v1-69 ignore-process0) #f)
                (set! (-> v1-69 ignore-process1) #f)
                (set! (-> v1-69 ignore-pat)
                      (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                      )
                (set! (-> v1-69 action-mask) (collide-action solid))
                )
              (let ((f0-35 (fill-and-probe-using-line-sphere *collide-cache* s5-3)))
                (if (>= f0-35 0.0)
                    (vector+*! gp-3 (-> s5-3 start-pos) (-> s5-3 move-dist) f0-35)
                    )
                )
              )
            (setup-from-to-duration-and-height! (-> self traj) (-> self root trans) gp-3 180.0 61440.0)
            )
          )
         (else
           (go-virtual idle)
           )
         )
       )
      (else
        (compute-trans-at-time
          (-> self traj)
          (fmin (-> self traj time) (the float (- (current-time) (-> self state-time))))
          (-> self root trans)
          )
        )
      )
    (cond
      ((zero? (-> self which-trajectory))
       (when (and (not (-> self incoming-sound-played))
                  (time-elapsed? (-> self state-time) (the int (+ -135.0 (-> self traj time))))
                  )
         (sound-play "mine-incoming" :position (-> self root trans))
         (set! (-> self incoming-sound-played) #t)
         )
       (if (nonzero? (-> self trail-part))
           (push-back (-> self trail-part) (-> self root trans))
           )
       )
      (else
        (when (and (not (-> self expand-sound-played))
                   (time-elapsed? (-> self state-time) (the int (+ -90.0 (-> self traj time))))
                   )
          (sound-play "mine-expand" :position (-> self root trans))
          (set! (-> self expand-sound-played) #t)
          )
        (if (time-elapsed? (-> self state-time) (the int (+ -30.0 (-> self traj time))))
            (ja :num! (seek!))
            )
        )
      )
    )
  :code sleep-code
  :post (behavior ()
    (transform-post)
    (do-push-aways (-> self root))
    )
  )

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

(defbehavior terraformer-target-init-by-other terraformer-target ((arg0 int))
  (let ((s5-0 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
    (let ((v1-2 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-2 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-2 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list projectile))
      (set! (-> v1-2 prim-core action) (collide-action solid))
      (set! (-> v1-2 transform-index) 3)
      (set-vector! (-> v1-2 local-sphere) 0.0 0.0 0.0 20480.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-2)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-5 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-5 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-5 prim-core collide-with))
      )
    (set! (-> s5-0 event-self) 'touched)
    (set! (-> self root) s5-0)
    )
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer-target" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (set! (-> self draw light-index) (-> (ppointer->process (-> self parent)) draw light-index))
  (logior! (-> self mask) (process-mask enemy))
  (logclear! (-> self mask) (process-mask actor-pause))
  (let ((v1-20 (-> self node-list data)))
    (set! (-> v1-20 0 param0) (the-as (function cspace transformq none) cspace<-parent-joint!))
    (set! (-> v1-20 0 param1) (the-as basic (-> self parent)))
    (set! (-> v1-20 0 param2) (the-as basic arg0))
    )
  (let ((v1-22 (-> self root root-prim)))
    (set! (-> self root backup-collide-as) (-> v1-22 prim-core collide-as))
    (set! (-> self root backup-collide-with) (-> v1-22 prim-core collide-with))
    )
  (add-connection *part-engine* self 3 self 1747 (new 'static 'vector :x 6144.0 :w 819200.0))
  (set! (-> self event-hook) (-> (method-of-object self idle) event))
  (go-virtual idle)
  )

(defstate idle (terraformer-target)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('attack)
       (let ((gp-0 (new 'stack-no-clear 'explosion-init-params)))
         (sound-play "blow-target" :position (-> self root trans))
         (vector-copy! (-> gp-0 spawn-point) (-> self root trans))
         (quaternion-identity! (-> gp-0 spawn-quat))
         (set! (-> gp-0 radius) 8192.0)
         (set! (-> gp-0 scale) 1.0)
         (set! (-> gp-0 group) group-kg-big-explosion)
         (set! (-> gp-0 collide-with) (collide-spec))
         (set! (-> gp-0 damage) 2.0)
         (set! (-> gp-0 damage-scale) 1.0)
         (set! (-> gp-0 vehicle-damage-factor) 1.0)
         (set! (-> gp-0 vehicle-impulse-factor) 1.0)
         (set! (-> gp-0 ignore-proc) (process->handle #f))
         (explosion-spawn gp-0 (the-as process-drawable *default-pool*))
         )
       (deactivate self)
       #t
       )
      (('disable-collision)
       (let ((v1-19 (-> self root root-prim)))
         (set! (-> v1-19 prim-core collide-as) (collide-spec))
         (set! (-> v1-19 prim-core collide-with) (collide-spec))
         )
       0
       )
      (('enable-collision)
       (let ((v1-21 (-> self root root-prim)))
         (set! (-> v1-21 prim-core collide-as) (-> self root backup-collide-as))
         (let ((v0-5 (the-as object (-> self root backup-collide-with))))
           (set! (-> v1-21 prim-core collide-with) (the-as collide-spec v0-5))
           v0-5
           )
         )
       )
      )
    )
  :trans (behavior ()
    (ja :num! (loop!))
    (vector<-cspace! (-> self root trans) (-> self node-list data 0))
    )
  :code sleep-code
  :post (behavior ()
    (transform-post)
    (do-push-aways (-> self root))
    )
  )

(defbehavior terraformer-leg-frames-since-lift terraformer-leg ()
  (let ((f0-2 (+ (- 116.0 (-> self foot-up-frame)) (ja-aframe-num 0))))
    (- f0-2 (* (the float (the int (/ f0-2 116.0))) 116.0))
    )
  )

(defbehavior terraformer-leg-frames-till-down terraformer-leg ()
  (let ((f0-1 (- 33.0 (terraformer-leg-frames-since-lift))))
    (if (< f0-1 0.0)
        (set! f0-1 (+ 116.0 f0-1))
        )
    f0-1
    )
  )

(defbehavior terraformer-leg-frames-till-up terraformer-leg ()
  (- 116.0 (terraformer-leg-frames-since-lift))
  )

(defbehavior terraformer-leg-should-be-up? terraformer-leg ()
  (>= 33.0 (terraformer-leg-frames-since-lift))
  )

(defbehavior terraformer-leg-init-by-other terraformer-leg ((arg0 string) (arg1 int) (arg2 int) (arg3 float))
  (set! (-> self prefix) arg0)
  (set! (-> self kind) arg1)
  (set! (-> self side) arg2)
  (dotimes (v1-0 6)
    (set! (-> self targets v1-0) (the-as handle #f))
    )
  (set! (-> self mm-handle) (the-as handle #f))
  (let ((v1-3 arg1))
    (cond
      ((zero? v1-3)
       (let ((s5-0 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
         (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 1) 0)))
           (set! (-> s5-0 total-prims) (the-as uint 2))
           (set! (-> s4-0 prim-core collide-as) (collide-spec enemy))
           (set! (-> s4-0 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list projectile))
           (set! (-> s4-0 prim-core action) (collide-action solid))
           (set! (-> s4-0 transform-index) 3)
           (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 4096.0)
           (set! (-> s5-0 root-prim) s4-0)
           )
         (let ((v1-13 (new 'process 'collide-shape-prim-sphere s5-0 (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 projectile))
           (set! (-> v1-13 prim-core action) (collide-action solid))
           (set! (-> v1-13 transform-index) 3)
           (set-vector! (-> v1-13 local-sphere) 0.0 0.0 0.0 4096.0)
           )
         (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
         (let ((v1-16 (-> s5-0 root-prim)))
           (set! (-> s5-0 backup-collide-as) (-> v1-16 prim-core collide-as))
           (set! (-> s5-0 backup-collide-with) (-> v1-16 prim-core collide-with))
           )
         (set! (-> self root) s5-0)
         )
       (initialize-skeleton
         self
         (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer-leg-a" (the-as (pointer level) #f)))
         (the-as pair 0)
         )
       )
      ((= v1-3 1)
       (let ((s5-2 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
         (let ((s4-2 (new 'process 'collide-shape-prim-group s5-2 (the-as uint 1) 0)))
           (set! (-> s5-2 total-prims) (the-as uint 2))
           (set! (-> s4-2 prim-core collide-as) (collide-spec enemy))
           (set! (-> s4-2 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list projectile))
           (set! (-> s4-2 prim-core action) (collide-action solid))
           (set! (-> s4-2 transform-index) 4)
           (set-vector! (-> s4-2 local-sphere) 0.0 0.0 0.0 4096.0)
           (set! (-> s5-2 root-prim) s4-2)
           )
         (let ((v1-30 (new 'process 'collide-shape-prim-sphere s5-2 (the-as uint 0))))
           (set! (-> v1-30 prim-core collide-as) (collide-spec enemy))
           (set! (-> v1-30 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list projectile))
           (set! (-> v1-30 prim-core action) (collide-action solid))
           (set! (-> v1-30 transform-index) 4)
           (set-vector! (-> v1-30 local-sphere) 0.0 0.0 0.0 4096.0)
           )
         (set! (-> s5-2 nav-radius) (* 0.75 (-> s5-2 root-prim local-sphere w)))
         (let ((v1-33 (-> s5-2 root-prim)))
           (set! (-> s5-2 backup-collide-as) (-> v1-33 prim-core collide-as))
           (set! (-> s5-2 backup-collide-with) (-> v1-33 prim-core collide-with))
           )
         (set! (-> self root) s5-2)
         )
       (initialize-skeleton
         self
         (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer-leg-b" (the-as (pointer level) #f)))
         (the-as pair 0)
         )
       )
      ((= v1-3 2)
       (let ((s5-4 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
         (let ((s4-4 (new 'process 'collide-shape-prim-group s5-4 (the-as uint 8) 0)))
           (set! (-> s5-4 total-prims) (the-as uint 9))
           (set! (-> s4-4 prim-core collide-as) (collide-spec enemy))
           (set! (-> s4-4 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list projectile))
           (set! (-> s4-4 prim-core action) (collide-action solid))
           (set! (-> s4-4 transform-index) 6)
           (set-vector! (-> s4-4 local-sphere) 0.0 0.0 0.0 245760.0)
           (set! (-> s5-4 root-prim) s4-4)
           )
         (let ((v1-47 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 0) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-47 prim-core action) (collide-action solid))
           (set! (-> v1-47 transform-index) 8)
           (set-vector! (-> v1-47 local-sphere) -82.7392 47723.727 -655.36 64992.87)
           )
         (let ((v1-49 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 1) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-49 prim-core action) (collide-action solid))
           (set! (-> v1-49 transform-index) 10)
           (set-vector! (-> v1-49 local-sphere) 1209.5488 22236.773 3039.232 54229.402)
           )
         (let ((v1-51 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 2) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-51 prim-core action) (collide-action solid))
           (set! (-> v1-51 transform-index) 9)
           (set-vector! (-> v1-51 local-sphere) 840.9088 19957.35 -33.1776 26230.783)
           )
         (let ((v1-53 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 3) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-53 prim-core action) (collide-action solid))
           (set! (-> v1-53 transform-index) 12)
           (set-vector! (-> v1-53 local-sphere) 1242.7264 21906.227 3225.1904 53527.348)
           )
         (let ((v1-55 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 4) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-55 prim-core action) (collide-action solid))
           (set! (-> v1-55 transform-index) 11)
           (set-vector! (-> v1-55 local-sphere) 773.7344 19534.643 112.64 28606.055)
           )
         (let ((v1-57 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 5) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-57 prim-core action) (collide-action solid))
           (set! (-> v1-57 transform-index) 14)
           (set-vector! (-> v1-57 local-sphere) -21.2992 22408.396 2994.995 53195.98)
           )
         (let ((v1-59 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 6) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-59 prim-core action) (collide-action solid))
           (set! (-> v1-59 transform-index) 13)
           (set-vector! (-> v1-59 local-sphere) -361.2672 19156.992 307.2 31004.262)
           )
         (let ((v1-61 (new 'process 'collide-shape-prim-mesh s5-4 (the-as uint 7) (the-as uint 0))))
           (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 projectile))
           (set! (-> v1-61 prim-core action) (collide-action solid))
           (set! (-> v1-61 transform-index) 7)
           (set-vector! (-> v1-61 local-sphere) 1719.5009 -12972.032 -1329.9712 92613.43)
           )
         (set! (-> s5-4 nav-radius) (* 0.75 (-> s5-4 root-prim local-sphere w)))
         (let ((v1-64 (-> s5-4 root-prim)))
           (set! (-> s5-4 backup-collide-as) (-> v1-64 prim-core collide-as))
           (set! (-> s5-4 backup-collide-with) (-> v1-64 prim-core collide-with))
           )
         (set! (-> self root) s5-4)
         )
       (initialize-skeleton
         self
         (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer-leg-c" (the-as (pointer level) #f)))
         (the-as pair 0)
         )
       (set! (-> self mm-handle)
             (ppointer->handle (process-spawn terraformer-leg-minimap-dot :name "terraformer-leg-minimap-dot" :to self))
             )
       (set! (-> self sand-drop-part) (create-launch-control group-terraformer-foot-sand-drop self))
       (set! (-> self water-drop-part) (create-launch-control group-terraformer-foot-water-drop self))
       ((method-of-type cam-float-seeker init) (-> self foot-lock lock) 0.0 0.005 0.04 0.9)
       (set! (-> self foot-lock initialized) #f)
       (set! (-> self foot-marks) (new 'process 'terraformer-foot-mark-pt-array))
       (cond
         ((zero? (-> self side))
          (if (= arg3 58.0)
              (set! (-> self targets 0)
                    (ppointer->handle (process-spawn terraformer-target 15 :name "terraformer-target" :to self))
                    )
              )
          (set! (-> self targets 1)
                (ppointer->handle (process-spawn terraformer-target 16 :name "terraformer-target" :to self))
                )
          (set! (-> self targets 2)
                (ppointer->handle (process-spawn terraformer-target 17 :name "terraformer-target" :to self))
                )
          )
         (else
           (if (= arg3 108.0)
               (set! (-> self targets 3)
                     (ppointer->handle (process-spawn terraformer-target 18 :name "terraformer-target" :to self))
                     )
               )
           (set! (-> self targets 4)
                 (ppointer->handle (process-spawn terraformer-target 19 :name "terraformer-target" :to self))
                 )
           (set! (-> self targets 5)
                 (ppointer->handle (process-spawn terraformer-target 20 :name "terraformer-target" :to self))
                 )
           )
         )
       (cond
         ((terraformer-leg-should-be-up?)
          (set! (-> self last-effect) 1)
          )
         (else
           (set! (-> self last-effect) 0)
           0
           )
         )
       (set! (-> self splash-list-index) 0)
       (case arg3
         ((43.0)
          (set! (-> self splash-list) *terraformer-lf-water-splash-list*)
          )
         ((0.0)
          (set! (-> self splash-list) *terraformer-lm-water-splash-list*)
          )
         ((58.0)
          (set! (-> self splash-list) *terraformer-lr-water-splash-list*)
          )
         ((96.0)
          (set! (-> self splash-list) *terraformer-rf-water-splash-list*)
          )
         ((32.0)
          (set! (-> self splash-list) *terraformer-rm-water-splash-list*)
          )
         (else
           (set! (-> self splash-list) *terraformer-rr-water-splash-list*)
           )
         )
       )
      (else
        (let ((s5-13 (new 'process 'collide-shape self (collide-list-enum usually-hit-by-player))))
          (let ((s4-6 (new 'process 'collide-shape-prim-group s5-13 (the-as uint 1) 0)))
            (set! (-> s5-13 total-prims) (the-as uint 2))
            (set! (-> s4-6 prim-core collide-as) (collide-spec enemy))
            (set! (-> s4-6 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list projectile))
            (set! (-> s4-6 prim-core action) (collide-action solid))
            (set! (-> s4-6 transform-index) 3)
            (set-vector! (-> s4-6 local-sphere) 0.0 0.0 0.0 4096.0)
            (set! (-> s5-13 root-prim) s4-6)
            )
          (let ((v1-139 (new 'process 'collide-shape-prim-sphere s5-13 (the-as uint 0))))
            (set! (-> v1-139 prim-core collide-as) (collide-spec enemy))
            (set! (-> v1-139 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list projectile))
            (set! (-> v1-139 prim-core action) (collide-action solid))
            (set! (-> v1-139 transform-index) 3)
            (set-vector! (-> v1-139 local-sphere) 0.0 0.0 0.0 4096.0)
            )
          (set! (-> s5-13 nav-radius) (* 0.75 (-> s5-13 root-prim local-sphere w)))
          (let ((v1-142 (-> s5-13 root-prim)))
            (set! (-> s5-13 backup-collide-as) (-> v1-142 prim-core collide-as))
            (set! (-> s5-13 backup-collide-with) (-> v1-142 prim-core collide-with))
            )
          (set! (-> self root) s5-13)
          )
        (initialize-skeleton
          self
          (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer-spike" (the-as (pointer level) #f)))
          (the-as pair 0)
          )
        )
      )
    )
  (set! (-> self root event-self) 'touched)
  (vector-copy! (-> self root trans) (-> (ppointer->process (-> self parent)) root trans))
  (set! (-> self draw light-index) (-> (ppointer->process (-> self parent)) draw light-index))
  (logior! (-> self mask) (process-mask enemy))
  (logclear! (-> self mask) (process-mask actor-pause))
  (set! (-> self draw shadow-ctrl) *terraformer-shadow-control*)
  (logior! (-> self draw status) (draw-control-status no-bounds-check))
  (set! (-> self stepped-in-water) #f)
  (set! (-> self foot-up-frame) arg3)
  (set! (-> self event-hook) (-> (method-of-object self idle) event))
  (go-virtual idle)
  )

;; WARN: Return type mismatch sound-id vs object.
(defbehavior foot-impact terraformer-leg ()
  (local-vars (sv-256 entity-actor) (sv-272 entity-actor))
  (set-zero! *camera-smush-control*)
  (let* ((gp-0 lerp-scale)
         (s5-0 3686.4)
         (s4-0 0.0)
         (a2-0 (vector-vector-distance-squared (-> self foot-lock old-position) (target-pos 0)))
         (f0-0 204800.0)
         (a3-0 (* f0-0 f0-0))
         (f0-2 1024000.0)
         (f0-4 (gp-0 s5-0 s4-0 a2-0 a3-0 (* f0-2 f0-2)))
         )
    (activate! *camera-smush-control* f0-4 75 600 1.1 1.07 (-> *display* camera-clock))
    )
  (let ((gp-1 (new 'stack-no-clear 'vector)))
    (vector-copy! gp-1 (-> self foot-lock old-position))
    (let ((s5-1 (new 'stack-no-clear 'quaternion))
          (s4-1 (new 'stack-no-clear 'matrix))
          (s3-1 #f)
          )
      (+! (-> gp-1 y) 4096.0)
      (quaternion-from-two-vectors! s5-1 (new 'static 'vector :y 1.0) (-> self foot-lock old-normal))
      (quaternion->matrix s4-1 s5-1)
      (vector-copy! (-> s4-1 trans) gp-1)
      (when (nonzero? (-> self splash-list))
        (let ((f0-7 (ja-aframe-num 0))
              (v1-12 (-> self splash-list-index))
              )
          (cond
            ((>= v1-12 (-> self splash-list length))
             (if (< f0-7 (-> self splash-list 0 frame))
                 (set! v1-12 0)
                 )
             )
            (else
              (while (and (< v1-12 (-> self splash-list length)) (>= f0-7 (-> self splash-list v1-12 frame)))
                (if (< (fabs (- f0-7 (-> self splash-list v1-12 frame))) 10.0)
                    (set! s3-1 #t)
                    )
                (+! v1-12 1)
                )
              )
            )
          (set! (-> self splash-list-index) v1-12)
          )
        )
      (cond
        (s3-1
          (set! (-> self stepped-in-water) #t)
          (let ((s5-2 (new 'stack-no-clear 'matrix)))
            (matrix-identity! s5-2)
            (vector-copy! (-> s5-2 trans) gp-1)
            (set! (-> s5-2 trans y) 37273.6)
            (if (logtest? (-> group-terraformer-foot-splash flags) (sp-group-flag sp13))
                (part-tracker-spawn
                  part-tracker-subsampler
                  :to *entity-pool*
                  :group group-terraformer-foot-splash
                  :duration (seconds 1)
                  :mat-joint s5-2
                  )
                (part-tracker-spawn
                  part-tracker
                  :to *entity-pool*
                  :group group-terraformer-foot-splash
                  :duration (seconds 1)
                  :mat-joint s5-2
                  )
                )
            )
          (sound-play "terra-splash" :position gp-1)
          )
        (else
          (set! (-> self stepped-in-water) #f)
          (if (logtest? (-> group-terraformer-stomp-foot flags) (sp-group-flag sp13))
              (part-tracker-spawn
                part-tracker-subsampler
                :to *entity-pool*
                :group group-terraformer-stomp-foot
                :duration (seconds 1)
                :mat-joint s4-1
                )
              (part-tracker-spawn
                part-tracker
                :to *entity-pool*
                :group group-terraformer-stomp-foot
                :duration (seconds 1)
                :mat-joint s4-1
                )
              )
          (let* ((s3-4 (the-as manipy (get-process *default-dead-pool* manipy #x20000 1)))
                 (s4-5 (when s3-4
                         (let ((t9-24 (method-of-type manipy activate)))
                           (t9-24 s3-4 self "manipy" (the-as pointer #x70004000))
                           )
                         (let ((s4-6 run-function-in-process)
                               (s2-1 s3-4)
                               (s1-0 manipy-init)
                               (s0-0 gp-1)
                               )
                           (set! sv-256 (-> self entity))
                           (let ((t0-3 (art-group-get-by-name *level* "skel-bomb-blast" (the-as (pointer level) #f)))
                                 (t1-2 #f)
                                 (t2-2 0)
                                 )
                             ((the-as (function object object object object object object object none) s4-6)
                              s2-1
                              s1-0
                              s0-0
                              sv-256
                              t0-3
                              t1-2
                              t2-2
                              )
                             )
                           )
                         (-> s3-4 ppointer)
                         )
                       )
                 )
            (when s4-5
              (send-event (ppointer->process s4-5) 'rot-quat s5-1)
              (send-event (ppointer->process s4-5) 'anim-mode 'play1)
              (send-event (ppointer->process s4-5) 'anim "idle")
              (set-vector! (-> (the-as process-drawable (-> s4-5 0)) root scale) 1.0 1.0 1.0 1.0)
              (let ((v1-98 (lambda :behavior manipy
                             ()
                             (set-vector! (-> self draw color-mult) 0.0 0.0 0.0 1.0)
                             (cond
                               ((>= 10.0 (ja-aframe-num 0))
                                (let ((v0-1 (the-as vector (-> self draw color-emissive))))
                                  (set! (-> (the-as rgbaf v0-1) x) 1.0)
                                  (set! (-> (the-as rgbaf v0-1) y) 1.0)
                                  (set! (-> (the-as rgbaf v0-1) z) 1.0)
                                  (set! (-> (the-as rgbaf v0-1) w) 1.0)
                                  v0-1
                                  )
                                )
                               ((>= 20.0 (ja-aframe-num 0))
                                (vector-lerp!
                                  (-> self draw color-emissive)
                                  (new 'static 'vector :x 1.0 :y 1.0 :z 1.0 :w 1.0)
                                  (new 'static 'vector :x 0.5 :z 1.0 :w 1.0)
                                  (lerp-scale 0.0 1.0 (ja-aframe-num 0) 10.0 20.0)
                                  )
                                )
                               (else
                                 (vector-lerp!
                                   (-> self draw color-emissive)
                                   (new 'static 'vector :x 0.5 :z 1.0 :w 1.0)
                                   (new 'static 'vector :w 1.0)
                                   (lerp-scale 0.0 1.0 (ja-aframe-num 0) 20.0 30.0)
                                   )
                                 )
                               )
                             )
                           )
                    )
                (send-event (ppointer->process s4-5) 'trans-hook v1-98)
                )
              )
            )
          (let* ((s3-5 (get-process *default-dead-pool* manipy #x20000 1))
                 (s4-7 (when s3-5
                         (let ((t9-32 (method-of-type manipy activate)))
                           (t9-32 (the-as manipy s3-5) self "manipy" (the-as pointer #x70004000))
                           )
                         (let ((s4-8 run-function-in-process)
                               (s2-2 s3-5)
                               (s1-1 manipy-init)
                               (s0-1 gp-1)
                               )
                           (set! sv-272 (-> self entity))
                           (let ((t0-4 (art-group-get-by-name *level* "skel-generic-blast" (the-as (pointer level) #f)))
                                 (t1-3 #f)
                                 (t2-3 0)
                                 )
                             ((the-as (function object object object object object object object none) s4-8)
                              s2-2
                              s1-1
                              s0-1
                              sv-272
                              t0-4
                              t1-3
                              t2-3
                              )
                             )
                           )
                         (-> s3-5 ppointer)
                         )
                       )
                 )
            (when s4-7
              (send-event (ppointer->process s4-7) 'rot-quat s5-1)
              (send-event (ppointer->process s4-7) 'anim-mode 'play1)
              (send-event (ppointer->process s4-7) 'anim "idle")
              (set-vector! (-> (the-as process-drawable (-> s4-7 0)) root scale) 1.0 1.0 1.0 1.0)
              )
            )
          (sound-play "terra-step" :position gp-1)
          )
        )
      )
    )
  )

;; WARN: Return type mismatch process-focusable vs terraformer-leg.
(defmethod relocate ((this terraformer-leg) (offset int))
  (when (nonzero? (-> this joint-ik))
    (if (nonzero? (-> this joint-ik))
        (&+! (-> this joint-ik) offset)
        )
    )
  (when (nonzero? (-> this foot-marks))
    (if (nonzero? (-> this foot-marks))
        (&+! (-> this foot-marks) offset)
        )
    )
  (if (nonzero? (-> this sand-drop-part))
      (&+! (-> this sand-drop-part) offset)
      )
  (if (nonzero? (-> this water-drop-part))
      (&+! (-> this water-drop-part) offset)
      )
  (the-as terraformer-leg ((method-of-type process-focusable relocate) (the-as process-focusable this) offset))
  )

(defmethod deactivate ((this terraformer-leg))
  "Make a process dead, clean it up, remove it from the active pool, and return to dead pool."
  (if (nonzero? (-> this sand-drop-part))
      (kill-particles (-> this sand-drop-part))
      )
  (if (nonzero? (-> this water-drop-part))
      (kill-particles (-> this water-drop-part))
      )
  (call-parent-method this)
  (none)
  )

(defbehavior ik-adjust terraformer-leg ()
  (let* ((f0-1 (* 0.0033333334 (the float (- (current-time) (-> self state-time)))))
         (f0-2 (* 9102.223 f0-1))
         (f0-3 (- f0-2 (* (the float (the int (/ f0-2 65536.0))) 65536.0)))
         (f0-4 (sin f0-3))
         )
    (* 8192.0 f0-4)
    )
  )

(defbehavior terraformer-leg-deadly? terraformer-leg ()
  (let ((f0-0 (terraformer-leg-frames-since-lift)))
    (and (< f0-0 38.0) (< 18.0 f0-0))
    )
  )

;; WARN: Return type mismatch int vs object.
(defbehavior terraformer-leg-update-ik terraformer-leg ()
  (local-vars (sv-720 int))
  (let ((gp-0 (new 'stack-no-clear 'vector)))
    (cond
      ((nonzero? (-> self joint-ik))
       (let ((a1-0 (-> self joint-ik elbow-matrix-no-ik)))
         (vector+*! gp-0 (-> a1-0 trans) (-> a1-0 uvec) (-> *terraformer-ik-setup* hand-dist))
         )
       )
      (else
        (vector<-cspace! gp-0 (-> self node-list data 6))
        (let ((s5-0 (new 'stack-no-clear 'vector)))
          (vector-normalize-copy!
            s5-0
            (-> self node-list data 6 bone transform uvec)
            (-> *terraformer-ik-setup* hand-dist)
            )
          (vector+! gp-0 gp-0 s5-0)
          )
        )
      )
    (cond
      ((zero? (-> self last-effect))
       (when (< (terraformer-leg-frames-till-up) 12.0)
         (set! (-> self last-effect) 1)
         (sound-play "joint-servo-up" :position (-> self foot-lock old-position))
         )
       )
      (else
        (when (< (terraformer-leg-frames-till-down) 12.0)
          (set! (-> self last-effect) 0)
          (let ((s5-2 sound-play-by-name)
                (s4-1 (make-u128 (the-as uint #x6e642d6f7672) (the-as uint #x65732d746e696f6a)))
                (s3-0 (new-sound-id))
                (s2-0 1024)
                (s1-0 0)
                (s0-0 0)
                )
            (set! sv-720 0)
            (let ((t2-1 (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data 6))))
              (s5-2 (the-as sound-name s4-1) s3-0 s2-0 s1-0 s0-0 (the-as sound-group sv-720) t2-1)
              )
            )
          )
        )
      )
    (cond
      ((not (-> self foot-lock initialized))
       )
      ((terraformer-leg-should-be-up?)
       (if (nonzero? (-> self foot-marks))
           (terraformer-foot-mark-pt-array-method-11 (-> self foot-marks) self)
           )
       (when (!= (-> self foot-lock lock target) 0.0)
         (set! (-> self foot-lock lock target) 0.0)
         (let ((s5-3 (new 'stack-no-clear 'matrix)))
           (matrix-from-two-vectors! s5-3 (new 'static 'vector :y 1.0) (-> self foot-lock old-normal))
           (vector-copy! (-> s5-3 trans) (-> self foot-lock old-position))
           (cond
             ((-> self stepped-in-water)
              (set! (-> s5-3 trans y) 37273.6)
              (if (logtest? (-> group-terraformer-lift-foot-from-water flags) (sp-group-flag sp13))
                  (part-tracker-spawn
                    part-tracker-subsampler
                    :to *entity-pool*
                    :group group-terraformer-lift-foot-from-water
                    :duration (seconds 1)
                    :mat-joint s5-3
                    )
                  (part-tracker-spawn
                    part-tracker
                    :to *entity-pool*
                    :group group-terraformer-lift-foot-from-water
                    :duration (seconds 1)
                    :mat-joint s5-3
                    )
                  )
              )
             ((begin (+! (-> s5-3 trans y) 4096.0) (logtest? (-> group-terraformer-lift-foot flags) (sp-group-flag sp13)))
              (part-tracker-spawn
                part-tracker-subsampler
                :to *entity-pool*
                :group group-terraformer-lift-foot
                :duration (seconds 1)
                :mat-joint s5-3
                )
              )
             (else
               (part-tracker-spawn
                 part-tracker
                 :to *entity-pool*
                 :group group-terraformer-lift-foot
                 :duration (seconds 1)
                 :mat-joint s5-3
                 )
               )
             )
           )
         )
       )
      ((= (-> self foot-lock lock target) 1.0)
       (if (nonzero? (-> self foot-marks))
           (terraformer-foot-mark-pt-array-method-10 (-> self foot-marks))
           )
       )
      (else
        (let ((s5-4 (new 'stack-no-clear 'collide-query)))
          (let ((v1-92 (new 'stack-no-clear 'vector)))
            (vector-copy!
              v1-92
              (-> self node-list data (+ (-> *terraformer-ik-setup* elbow-index) 1) bone transform trans)
              )
            (let ((a2-29 (-> s5-4 bbox))
                  (a0-31 v1-92)
                  (a1-26 (new 'stack-no-clear 'vector))
                  )
              (set! (-> a1-26 x) 32768.0)
              (set! (-> a1-26 y) 327680.0)
              (set! (-> a1-26 z) 32768.0)
              (set! (-> a1-26 w) 1.0)
              (vector-! (-> a2-29 min) a0-31 a1-26)
              )
            (let ((a1-27 (-> s5-4 bbox max))
                  (a0-32 (new 'stack-no-clear 'vector))
                  )
              (set! (-> a0-32 x) 32768.0)
              (set! (-> a0-32 y) 163840.0)
              (set! (-> a0-32 z) 32768.0)
              (set! (-> a0-32 w) 1.0)
              (vector+! a1-27 v1-92 a0-32)
              )
            )
          (set! (-> s5-4 collide-with) (collide-spec backgnd))
          (set! (-> s5-4 ignore-process0) #f)
          (set! (-> s5-4 ignore-process1) #f)
          (set! (-> s5-4 ignore-pat)
                (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                )
          (fill-using-bounding-box *collide-cache* s5-4)
          (vector-copy! (-> s5-4 start-pos) gp-0)
          (+! (-> s5-4 start-pos y) 163840.0)
          (set-vector! (-> s5-4 move-dist) 0.0 -327680.0 0.0 1.0)
          (let ((v1-99 s5-4))
            (set! (-> v1-99 radius) 40.96)
            (set! (-> v1-99 collide-with) (collide-spec backgnd))
            (set! (-> v1-99 ignore-process0) #f)
            (set! (-> v1-99 ignore-process1) #f)
            (set! (-> v1-99 ignore-pat)
                  (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                  )
            (set! (-> v1-99 action-mask) (collide-action solid))
            )
          (let ((f0-27 (probe-using-line-sphere *collide-cache* s5-4)))
            (when (>= f0-27 0.0)
              (set! (-> self foot-lock lock target) 1.0)
              (vector+float*! (-> self foot-lock old-position) (-> s5-4 start-pos) (-> s5-4 move-dist) f0-27)
              (vector-copy! (-> self foot-lock old-normal) (-> s5-4 best-other-tri normal))
              (foot-impact)
              (if (nonzero? (-> self foot-marks))
                  (init! (-> self foot-marks) (-> self foot-lock old-position) 32768.0)
                  )
              )
            )
          )
        )
      )
    ((method-of-type cam-float-seeker update!) (-> self foot-lock lock) 0.0)
    (if (-> self foot-lock initialized)
        (vector-lerp!
          gp-0
          gp-0
          (-> self foot-lock old-position)
          (parameter-ease-sin-clamp (-> self foot-lock lock value))
          )
        (set! (-> self foot-lock initialized) #t)
        )
    (if (nonzero? (-> self joint-ik))
        (set-ik-target! (-> self joint-ik) gp-0)
        )
    )
  0
  )

(defstate idle (terraformer-leg)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('touched)
       (cond
         ((or (not (terraformer-leg-deadly?)) (!= (-> self kind) 2))
          )
         ((type? proc process-drawable)
          (let ((s5-0 proc)
                (s4-0 (new 'stack-no-clear 'vector))
                (f30-0 1.0)
                )
            (let ((v1-7 (-> self kind)))
              (cond
                ((zero? v1-7)
                 (vector<-cspace! s4-0 (-> self node-list data 3))
                 )
                ((= v1-7 1)
                 (vector<-cspace! s4-0 (-> self node-list data 4))
                 )
                ((= v1-7 2)
                 (vector<-cspace! s4-0 (-> self node-list data 6))
                 )
                (else
                  (vector<-cspace! s4-0 (-> self node-list data 3))
                  )
                )
              )
            (vector-! s4-0 (-> (the-as process-drawable s5-0) root trans) s4-0)
            (set! (-> s4-0 y) 0.0)
            (let ((f0-1 (vector-length-squared s4-0))
                  (f1-0 1.0)
                  )
              (if (< f0-1 (* f1-0 f1-0))
                  (set! (-> s4-0 x) 1.0)
                  )
              )
            (vector-normalize! s4-0 1.0)
            (set! (-> s4-0 y) 0.3)
            (vector-float*! s4-0 s4-0 4096.0)
            (if (type? s5-0 vehicle)
                (set! f30-0 (-> (the-as vehicle proc) info info mass))
                )
            (let ((a1-10 (new 'stack-no-clear 'event-message-block)))
              (set! (-> a1-10 from) (process->ppointer self))
              (set! (-> a1-10 num-params) 2)
              (set! (-> a1-10 message) 'attack)
              (set! (-> a1-10 param 0) (the-as uint #f))
              (set! (-> a1-10 param 1)
                    (the-as uint (static-attack-info :mask (vehicle-impulse-factor) ((id (new-attack-id))
                                                                                     (damage 8.0)
                                                                                     (vehicle-damage-factor 0.8325)
                                                                                     (vehicle-impulse-factor (* 0.625 f30-0))
                                                                                     (shield-damage 5.0)
                                                                                     (knock (knocked-type dark-shot))
                                                                                     (attacker-velocity s4-0)
                                                                                     (shove-back (meters 20))
                                                                                     (shove-up (meters 4))
                                                                                     )
                                                     )
                            )
                    )
              (when (and (send-event-function s5-0 a1-10) (or (= proc *target*) (type? s5-0 vehicle)))
                (dotimes (gp-1 6)
                  (send-event (handle->process (-> self targets gp-1)) 'disable-collision)
                  )
                (set-time! (-> self collision-disable-timer))
                (let ((v1-52 (-> self root root-prim)))
                  (set! (-> v1-52 prim-core collide-as) (collide-spec))
                  (set! (-> v1-52 prim-core collide-with) (collide-spec))
                  )
                0
                )
              )
            )
          )
         )
       #t
       )
      (('change-to)
       (let ((a0-34 (the-as object (-> block param 0))))
         (if (the-as uint a0-34)
             (change-to (the-as nav-mesh a0-34) self)
             )
         )
       )
      (else
        #t
        )
      )
    )
  :enter (behavior ()
    (let ((v1-1 (-> self root root-prim)))
      (set! (-> self root backup-collide-as) (-> v1-1 prim-core collide-as))
      (set! (-> self root backup-collide-with) (-> v1-1 prim-core collide-with))
      )
    )
  :trans (behavior ()
    (clone-anim-once (process->handle (ppointer->process (-> self parent))) #t (-> self prefix))
    (when (and (nonzero? (-> self collision-disable-timer))
               (time-elapsed? (-> self collision-disable-timer) (seconds 1))
               )
      (dotimes (gp-0 6)
        (send-event (handle->process (-> self targets gp-0)) 'enable-collision)
        )
      (set! (-> self collision-disable-timer) 0)
      (let ((v1-21 (-> self root root-prim)))
        (set! (-> v1-21 prim-core collide-as) (-> self root backup-collide-as))
        (set! (-> v1-21 prim-core collide-with) (-> self root backup-collide-with))
        )
      )
    (when (= (-> self kind) 2)
      (terraformer-leg-update-ik)
      (let ((v1-25 (vector<-cspace+vector!
                     (new 'stack-no-clear 'vector)
                     (-> self node-list data 6)
                     (new 'static 'vector :y 81920.0 :w 1.0)
                     )
                   )
            )
        (when (and (nonzero? (-> self nav)) (-> self nav))
          (let* ((a0-20 (-> self nav))
                 (f0-0 (-> a0-20 extra-nav-sphere w))
                 )
            (vector-copy! (-> a0-20 extra-nav-sphere) v1-25)
            (set! (-> a0-20 extra-nav-sphere w) f0-0)
            )
          0
          (let ((v1-29 (-> self nav)))
            (set! (-> v1-29 extra-nav-sphere w) 57344.0)
            )
          0
          (let ((v1-31 (-> self nav)))
            (logior! (-> v1-31 shape nav-flags) (nav-flags has-extra-sphere))
            )
          0
          )
        )
      (let ((f0-2 (terraformer-leg-frames-till-down)))
        (when (and (< f0-2 32.0) (< 20.0 f0-2))
          (let ((gp-1 (new 'stack-no-clear 'matrix)))
            (matrix-copy! gp-1 (-> self node-list data 6 bone transform))
            (vector<-cspace+vector! (-> gp-1 trans) (-> self node-list data 6) (new 'static 'vector :y 122880.0 :w 1.0))
            (if (-> self stepped-in-water)
                (spawn-from-mat (-> self water-drop-part) gp-1)
                (spawn-from-mat (-> self sand-drop-part) gp-1)
                )
            )
          )
        )
      )
    (let ((v1-45 0))
      (dotimes (a0-32 6)
        (if (handle->process (-> self targets a0-32))
            (+! v1-45 1)
            )
        )
      (when (zero? v1-45)
        (let ((a0-36 (handle->process (-> self mm-handle))))
          (when a0-36
            (deactivate a0-36)
            (set! (-> self mm-handle) (the-as handle #f))
            )
          )
        )
      )
    (if (< (vector-vector-distance (-> self draw origin) (math-camera-pos)) (-> self draw origin w))
        (logclear! (-> self draw status) (draw-control-status force-vu1))
        (logior! (-> self draw status) (draw-control-status force-vu1))
        )
    )
  :code sleep-code
  :post (behavior ()
    (transform-post)
    (do-push-aways (-> self root))
    )
  )

;; WARN: Return type mismatch process-focusable vs terraformer.
(defmethod relocate ((this terraformer) (offset int))
  (the-as terraformer ((method-of-type process-focusable relocate) (the-as process-focusable this) offset))
  )

(defbehavior terraformer-always terraformer ()
  (let ((f0-0 (vector-vector-distance
                (math-camera-pos)
                (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node terraformer-lod0-jg main))
                )
              )
        )
    (cond
      ((< f0-0 1843200.0)
       (let ((v1-3 (-> self draw shadow-ctrl)))
         (logclear! (-> v1-3 settings flags) (shadow-flags disable-draw))
         )
       0
       (set! (-> self draw shadow-ctrl settings shadow-dir w)
             (lerp-scale 1024000.0 40960000.0 f0-0 1843200.0 1433600.0)
             )
       )
      (else
        (let ((v1-9 (-> self draw shadow-ctrl)))
          (logior! (-> v1-9 settings flags) (shadow-flags disable-draw))
          )
        0
        )
      )
    )
  (if (< (vector-vector-distance (-> self draw origin) (math-camera-pos)) (-> self draw origin w))
      (logclear! (-> self draw status) (draw-control-status force-vu1))
      (logior! (-> self draw status) (draw-control-status force-vu1))
      )
  (when (!= (-> self desired-nav-mesh-index) (-> self current-nav-mesh-index))
    (let ((a0-14 (nav-mesh-from-res-tag (-> self entity) 'nav-mesh-actor (-> self desired-nav-mesh-index))))
      (if a0-14
          (change-to a0-14 self)
          )
      )
    )
  (let ((v1-23 0))
    (dotimes (a0-15 6)
      (let ((a1-10 (the-as terraformer-leg (handle->process (-> self legs a0-15)))))
        (when a1-10
          (dotimes (a2-7 6)
            (if (handle->process (-> a1-10 targets a2-7))
                (+! v1-23 1)
                )
            )
          )
        )
      )
    (if (zero? v1-23)
        (go-virtual frozen)
        (set! (-> *game-info* counter) (the float v1-23))
        )
    )
  )

(defbehavior find-mine-dest terraformer ((arg0 vector))
  (if (zero? (-> self older-target-time))
      (return #f)
      )
  (cond
    ((-> self launch-drones)
     (vector-copy! arg0 (-> self target-rot fvec))
     (set! (-> arg0 y) 0.0)
     (vector-normalize! arg0 819200.0)
     (vector+! arg0 arg0 (-> self old-target-pos))
     )
    (else
      (let ((s5-0 (new 'stack-no-clear 'vector)))
        (vector-! s5-0 (-> self old-target-pos) (-> self older-target-pos))
        (vector-float*! s5-0 s5-0 (/ 1.0 (the float (- (-> self old-target-time) (-> self older-target-time)))))
        (vector+float*! arg0 (-> self old-target-pos) s5-0 300.0)
        (vector-normalize! s5-0 163840.0)
        (vector+! arg0 arg0 s5-0)
        )
      )
    )
  (let ((f30-1 (* 65536.0 (rand-vu))))
    (+! (-> arg0 x) (* 32768.0 (sin f30-1)))
    (+! (-> arg0 z) (* 32768.0 (cos f30-1)))
    )
  (let ((s5-1 (new 'stack-no-clear 'collide-query)))
    (set-vector! (-> s5-1 move-dist) 0.0 -245760.0 0.0 1.0)
    (vector-copy! (-> s5-1 start-pos) arg0)
    (+! (-> s5-1 start-pos y) 122880.0)
    (let ((v1-19 s5-1))
      (set! (-> v1-19 radius) 4096.0)
      (set! (-> v1-19 collide-with) (collide-spec backgnd))
      (set! (-> v1-19 ignore-process0) #f)
      (set! (-> v1-19 ignore-process1) #f)
      (set! (-> v1-19 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-19 action-mask) (collide-action solid))
      )
    (let ((f0-18 (fill-and-probe-using-line-sphere *collide-cache* s5-1)))
      (if (>= f0-18 0.0)
          (vector+*! arg0 (-> s5-1 start-pos) (-> s5-1 move-dist) f0-18)
          (return #f)
          )
      )
    )
  #t
  )

;; WARN: Return type mismatch int vs object.
(defbehavior launch-mine terraformer ()
  ;; og:preserve-this int -> handle
  (local-vars (hand handle))
  (let ((gp-0 (new 'stack-no-clear 'vector))
        (s5-0 (new 'stack-no-clear 'vector))
        )
    (the-as
      handle
      (when (and (not (handle->process (-> self jumper)))
                 (and (not (handle->process (-> self drone))) (find-mine-dest gp-0))
                 )
        (set-time! (-> self mine-timer))
        (vector<-cspace! s5-0 (joint-node terraformer-lod0-jg main))
        (cond
          ((-> self launch-drones)
           (let ((s4-0 (new 'stack-no-clear 'enemy-init-by-other-params)))
             (vector-copy! (-> s4-0 trans) s5-0)
             (quaternion-copy! (-> s4-0 quat) (-> self root quat))
             (set! (-> s4-0 entity) (-> self entity))
             (set! (-> s4-0 directed?) #t)
             (set! (-> s4-0 no-initial-move-to-ground?) #t)
             (set! (-> s4-0 art-level) #f)
             (vector-copy! (-> self jump-dest) gp-0)
             (let ((gp-1 (get-process *default-dead-pool* terraformer-drone #x4000 1)))
               (set! hand (ppointer->handle
                            (when gp-1
                              (let ((t9-4 (method-of-type terraformer-drone activate)))
                                (t9-4 (the-as terraformer-drone gp-1) self "terraformer-drone" (the-as pointer #x70004000))
                                )
                              (run-now-in-process gp-1 enemy-init-by-other self s4-0)
                              (-> gp-1 ppointer)
                              )
                            )
                     )
               )
             )
           (set! (-> self jumper) (the-as handle hand))
           )
          (else
            (+! (-> self mines-to-launch) -1)
            (let ((s4-1 (get-process *default-dead-pool* terraformer-mine #x4000 1)))
              (set! hand (ppointer->handle
                           (when s4-1
                             (let ((t9-7 (method-of-type terraformer-mine activate)))
                               (t9-7 (the-as terraformer-mine s4-1) self "terraformer-mine" (the-as pointer #x70004000))
                               )
                             (run-now-in-process s4-1 terraformer-mine-init-by-other s5-0 gp-0)
                             (-> s4-1 ppointer)
                             )
                           )
                    )
              )
            (set! (-> self mines (-> self mines-to-launch)) (the-as handle hand))
            )
          )
        hand
        )
      )
    )
  )

;; WARN: Return type mismatch symbol vs object.
(defbehavior terraformer-init-mine-vars terraformer ()
  (set-time! (-> self mine-timer))
  (set! (-> self mines-to-launch) 0)
  (set! (-> self jumper) (the-as handle #f))
  (set! (-> self drone) (the-as handle #f))
  (set! (-> self launch-drones) #f)
  #f
  )

(defbehavior terraformer-update-mine-vars terraformer ((arg0 symbol))
  (local-vars (v0-11 object))
  (when (handle->process (-> self jumper))
    (+! (-> self mines-to-launch) -1)
    (when (send-event (handle->process (-> self jumper)) 'jump 2 (-> self jump-dest))
      (set! (-> self drone) (-> self jumper))
      (set-time! (-> self drone-time))
      (set! (-> self jumper) (the-as handle #f))
      )
    )
  (let ((a0-11 (handle->process (-> self drone))))
    (when a0-11
      (if (and (time-elapsed? (-> self drone-time) (seconds 10)) (not arg0))
          (send-event a0-11 'explode)
          )
      )
    )
  (dotimes (s5-0 10)
    (let ((s4-0 (the-as terraformer-mine (handle->process (-> self mines s5-0)))))
      (when s4-0
        (dotimes (s3-0 s5-0)
          (let ((s2-0 (handle->process (-> self mines s3-0))))
            (when (and (the-as terraformer-mine s2-0)
                       (let ((f0-0 (vector-vector-distance-squared (-> s4-0 root trans) (-> (the-as terraformer-mine s2-0) root trans)))
                             (f1-0 32768.0)
                             )
                         (< f0-0 (* f1-0 f1-0))
                         )
                       )
              (send-event s4-0 'explode)
              (send-event s2-0 'explode)
              )
            )
          )
        )
      )
    )
  (when (< (-> self old-target-time) (current-time))
    (set! (-> self older-target-time) (-> self old-target-time))
    (vector-copy! (-> self older-target-pos) (-> self old-target-pos))
    (set-time! (-> self old-target-time))
    (vector-copy! (-> self old-target-pos) (target-pos 0))
    (cond
      (*target*
        (quaternion->matrix (-> self target-rot) (get-quat *target* 0))
        )
      (*camera-combiner*
        (matrix-copy! (-> self target-rot) (-> *camera-combiner* inv-camera-rot))
        )
      (*math-camera*
        (matrix-copy! (-> self target-rot) (-> *math-camera* inv-camera-rot))
        )
      (else
        (matrix-copy! (-> self target-rot) *identity-matrix*)
        )
      )
    )
  (let ((s5-3 (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node terraformer-lod0-jg main)))
        (f0-1 1433600.0)
        )
    (cond
      ((< (* f0-1 f0-1) (vector-vector-distance-squared s5-3 (target-pos 0)))
       (set! (-> self mines-to-launch) 0)
       (set! v0-11 (current-time))
       (set! (-> self mine-timer) (the-as time-frame v0-11))
       v0-11
       )
      ((zero? (-> self mines-to-launch))
       (when (or (time-elapsed? (-> self mine-timer) (seconds 10))
                 (and arg0 (time-elapsed? (-> self mine-timer) (seconds 1)))
                 )
         (let ((f0-4 (ja-aframe-num 0)))
           (if (or (and (< 2200.0 f0-4) (< f0-4 4700.0))
                   (or (nonzero? (-> self mine-rounds-till-drones)) (handle->process (-> self drone)))
                   )
               (set! (-> self launch-drones) #f)
               (set! (-> self launch-drones) (not (-> self launch-drones)))
               )
           )
         (if arg0
             (set! (-> self launch-drones) #t)
             )
         (cond
           ((-> self launch-drones)
            (set! (-> self mines-to-launch) 3)
            )
           (else
             (set! (-> self mines-to-launch) 10)
             (+! (-> self mine-rounds-till-drones) -1)
             )
           )
         (set! v0-11 (current-time))
         (set! (-> self mine-timer) (the-as time-frame v0-11))
         v0-11
         )
       )
      ((time-elapsed? (-> self mine-timer) (seconds 0.5))
       (launch-mine)
       )
      )
    )
  )

;; WARN: Return type mismatch enemy-flag vs object.
(defbehavior terraformer-handler terraformer ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('nav-mesh-new)
     (set! (-> self current-nav-mesh-index) (-> self desired-nav-mesh-index))
     (let ((gp-0 (nav-mesh-from-res-tag (-> self entity) 'nav-mesh-actor (-> self current-nav-mesh-index))))
       (when gp-0
         (set! (-> *terraformer-drone-nav-enemy-info* nav-mesh) gp-0)
         (dotimes (s5-0 6)
           (send-event (handle->process (-> self legs s5-0)) 'change-to gp-0)
           )
         (the-as enemy-flag #f)
         )
       )
     )
    (('child-jumped)
     (let ((v0-1 (logclear (-> (the-as terraformer-drone arg0) enemy-flags) (enemy-flag directed))))
       (set! (-> (the-as terraformer-drone arg0) enemy-flags) v0-1)
       v0-1
       )
     )
    (('skip)
     (dotimes (gp-1 6)
       (let ((s5-1 (the-as terraformer-leg (handle->process (-> self legs gp-1)))))
         (when s5-1
           (dotimes (s4-0 6)
             (let ((a0-12 (handle->process (-> s5-1 targets s4-0))))
               (if a0-12
                   (deactivate a0-12)
                   )
               )
             )
           )
         )
       )
     (the-as enemy-flag #f)
     )
    )
  )

(defstate dormant (terraformer)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (if (and (task-node-closed? (game-task-node desert-final-boss-introduction))
             (not (logtest? (-> self entity extra perm status) (entity-perm-status subtask-complete)))
             (and (not (handle->process (-> *game-info* auto-save-proc))) (time-elapsed? (-> self state-time) (seconds 3)))
             )
        (go-virtual walk)
        )
    (terraformer-always)
    )
  :code sleep-code
  ;; og:preserve-this added post to prevent NaNs
  :post ja-post
  )

(defstate frozen (terraformer)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    (process-entity-status! self (entity-perm-status subtask-complete) #t)
    )
  :trans (behavior ()
    (set-blackout-frames (seconds 0.035))
    (if (time-elapsed? (-> self state-time) (seconds 0.25))
        (set! (-> *game-info* counter) 0.0)
        )
    )
  :code sleep-code
  )

(defstate walk (terraformer)
  :virtual #t
  :event terraformer-handler
  :enter (behavior ()
    (set-vector! (-> self root trans) 0.0 0.0 0.0 1.0)
    (terraformer-init-mine-vars)
    )
  :exit (behavior ()
    (when (= (-> *setting-control* user-current spooling) (process->ppointer self))
      (ja-abort-spooled-anim (-> self spooled-anim) (the-as art-joint-anim #f) -1)
      (ja-channel-set! 0)
      )
    (while (-> self child)
      (deactivate (-> self child 0))
      )
    (remove-process *gui-control* self (gui-channel art-load-next))
    )
  :trans (behavior ()
    (format *stdebug* "terraformer anim frame ~f~%" (ja-aframe-num 0))
    (terraformer-update-mine-vars #f)
    (let ((f0-0 (ja-aframe-num 0)))
      (cond
        ((< 4700.0 f0-0)
         (set! (-> self desired-nav-mesh-index) 0)
         0
         )
        ((< 1421.0 f0-0)
         (set! (-> self desired-nav-mesh-index) 2)
         )
        ((< 700.0 f0-0)
         (set! (-> self desired-nav-mesh-index) 1)
         )
        (else
          (set! (-> self desired-nav-mesh-index) 0)
          0
          )
        )
      )
    (terraformer-always)
    )
  :code (behavior ()
    (set! (-> self spooled-anim)
          (new 'static 'spool-anim :name "terraformer-walk-desert" :anim-name "walk-desert" :parts 86 :command-list '())
          )
    (let ((gp-0 (add-process
                  *gui-control*
                  self
                  (gui-channel art-load-next)
                  (gui-action queue)
                  (-> self spooled-anim name)
                  -1.0
                  0
                  )
                )
          )
      (while (!= (get-status *gui-control* gp-0) (gui-status ready))
        (suspend)
        )
      )
    (until #f
      (let ((v1-7
              (lookup-gui-connection
                *gui-control*
                self
                (gui-channel art-load-next)
                (the-as string #f)
                (new 'static 'sound-id)
                )
              )
            )
        (if v1-7
            (set! (-> v1-7 channel) (gui-channel art-load))
            )
        )
      (add-process
        *gui-control*
        self
        (gui-channel art-load-next)
        (gui-action queue)
        (-> self spooled-anim name)
        -1.0
        0
        )
      (ja-play-spooled-anim
        (-> self spooled-anim)
        (get-art-by-name (-> self draw art-group) "idle" art-joint-anim)
        (the-as art-joint-anim #f)
        (the-as (function process-drawable symbol) false-func)
        (spooler-flags)
        )
      )
    #f
    )
  :post ja-post
  )

(defstate scrub-anim (terraformer)
  :virtual #t
  :enter (behavior ()
    (set! (-> self anim-speed) 1.0)
    (ja :group! terraformer-walk-ja :num! min)
    )
  :trans (behavior ()
    (cond
      ((cpad-pressed? 0 square)
       (set! (-> self anim-speed) 0.0)
       )
      ((cpad-pressed? 0 x)
       (set! (-> self anim-speed) 1.0)
       )
      ((cpad-hold? 0 up)
       (set! (-> self anim-speed) (fmin 10.0 (+ 0.1 (-> self anim-speed))))
       )
      ((cpad-hold? 0 down)
       (set! (-> self anim-speed) (fmax -10.0 (+ -0.1 (-> self anim-speed))))
       )
      )
    (format *stdebug* "dpad up: faster~%")
    (format *stdebug* "dpad down: slower~%")
    (format *stdebug* "x: forward 1.0~%")
    (format *stdebug* "square: stop~%")
    (format *stdebug* "anim speed ~F~%" (-> self anim-speed))
    (ja :num! (loop! (-> self anim-speed)))
    (terraformer-always)
    )
  :code sleep-code
  :post ja-post
  )

(defstate idle (terraformer)
  :virtual #t
  :event terraformer-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (terraformer-init-mine-vars)
    )
  :trans (behavior ()
    (ja :num! (loop!))
    (terraformer-update-mine-vars #f)
    (when (-> self graph)
      (let ((gp-0 (-> self graph node (-> self current-node))))
        (let ((f0-1 (vector-vector-distance-squared (-> self root trans) (-> gp-0 position)))
              (f1-0 2048.0)
              )
          (when (< f0-1 (* f1-0 f1-0))
            (cond
              ((> (-> gp-0 edge-count) 0)
               (set! (-> self current-node) (-> self graph edge (-> gp-0 edge-index) dest-node-id))
               )
              (else
                (set! (-> self current-node) (the-as uint 0))
                0
                )
              )
            (set! gp-0 (-> self graph node (-> self current-node)))
            )
          )
        (vector-seek! (-> self root trans) (-> gp-0 position) 2048.0)
        (let ((s5-0 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> self root quat)))
              (a2-2
                (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> gp-0 position) (-> self root trans)) 1.0)
                )
              (gp-1 (new 'stack-no-clear 'matrix))
              )
          (v-slrp2! (-> gp-1 fvec) (-> s5-0 fvec) a2-2 0.1 (the-as vector #f) 9.102222)
          (set-vector! (-> gp-1 uvec) 0.0 1.0 0.0 0.0)
          (vector-flatten! (-> gp-1 fvec) (-> gp-1 fvec) (-> gp-1 uvec))
          (vector-normalize! (-> gp-1 fvec) 1.0)
          (vector-cross! (-> gp-1 rvec) (-> gp-1 uvec) (-> gp-1 fvec))
          (matrix->quaternion (-> self root quat) gp-1)
          )
        )
      )
    (terraformer-always)
    )
  :code sleep-code
  :post ja-post
  )

(defstate stand-still-laddie! (terraformer)
  :virtual #t
  :event terraformer-handler
  :enter (behavior ()
    (terraformer-init-mine-vars)
    )
  :trans (behavior ()
    (if (< 1 (-> self mines-to-launch))
        (set! (-> self mines-to-launch) 1)
        )
    (terraformer-update-mine-vars #f)
    (terraformer-always)
    )
  :code sleep-code
  :post ja-post
  )

;; ERROR: Function may read a register that is not set: t1
(defmethod init-from-entity! ((this terraformer) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (local-vars (t1-0 int))
  (stack-size-set! (-> this main-thread) 512)
  (let ((s4-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (let ((v1-4 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> v1-4 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-4 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list))
      (set! (-> v1-4 prim-core action) (collide-action solid))
      (set! (-> v1-4 transform-index) 3)
      (set-vector! (-> v1-4 local-sphere) 0.0 0.0 0.0 16384.0)
      (set! (-> s4-0 total-prims) (the-as uint 1))
      (set! (-> s4-0 root-prim) v1-4)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-7 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-7 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-7 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-terraformer" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (logior! (-> this mask) (process-mask enemy))
  (logclear! (-> this mask) (process-mask actor-pause))
  (set! (-> this draw shadow-ctrl) *terraformer-shadow-control*)
  (logior! (-> this draw status) (draw-control-status no-bounds-check))
  (set! (-> this current-node) (the-as uint 0))
  (set! (-> this graph) *terraformer-walk-graph*)
  (if (-> this graph)
      (vector-copy! (-> this root trans) (-> this graph node (-> this current-node) position))
      )
  (dotimes (v1-25 6)
    (set! (-> this legs v1-25) (the-as handle #f))
    )
  (dotimes (v1-28 10)
    (set! (-> this mines v1-28) (the-as handle #f))
    )
  (let ((s5-2 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-2
      (let ((t9-7 (method-of-type terraformer-leg activate)))
        (t9-7 (the-as terraformer-leg s5-2) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-8 run-function-in-process)
            (a0-29 s5-2)
            (a1-12 terraformer-leg-init-by-other)
            (a2-6 "lf-")
            (a3-4 0)
            (t0-0 0)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-8) a0-29 a1-12 a2-6 a3-4 t0-0 t1-0)
        )
      (-> s5-2 ppointer)
      )
    )
  (let ((s5-3 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-3
      (let ((t9-10 (method-of-type terraformer-leg activate)))
        (t9-10 (the-as terraformer-leg s5-3) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-11 run-function-in-process)
            (a0-32 s5-3)
            (a1-15 terraformer-leg-init-by-other)
            (a2-9 "lf-")
            (a3-7 1)
            (t0-1 0)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-11) a0-32 a1-15 a2-9 a3-7 t0-1 t1-0)
        )
      (-> s5-3 ppointer)
      )
    )
  (let ((s5-4 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (set! (-> this legs 0)
          (ppointer->handle
            (when s5-4
              (let ((t9-13 (method-of-type terraformer-leg activate)))
                (t9-13 (the-as terraformer-leg s5-4) this "terraformer-leg" (the-as pointer #x70004000))
                )
              (let ((t9-14 run-function-in-process)
                    (a0-35 s5-4)
                    (a1-18 terraformer-leg-init-by-other)
                    (a2-12 "lf-")
                    (a3-10 2)
                    (t0-2 0)
                    )
                (set! t1-0 #x422c0000)
                ((the-as (function object object object object object object none) t9-14) a0-35 a1-18 a2-12 a3-10 t0-2 t1-0)
                )
              (-> s5-4 ppointer)
              )
            )
          )
    )
  (let ((s5-5 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-5
      (let ((t9-16 (method-of-type terraformer-leg activate)))
        (t9-16 (the-as terraformer-leg s5-5) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-17 run-function-in-process)
            (a0-41 s5-5)
            (a1-21 terraformer-leg-init-by-other)
            (a2-15 "lm-")
            (a3-13 0)
            (t0-3 0)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-17) a0-41 a1-21 a2-15 a3-13 t0-3 t1-0)
        )
      (-> s5-5 ppointer)
      )
    )
  (let ((s5-6 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-6
      (let ((t9-19 (method-of-type terraformer-leg activate)))
        (t9-19 (the-as terraformer-leg s5-6) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-20 run-function-in-process)
            (a0-44 s5-6)
            (a1-24 terraformer-leg-init-by-other)
            (a2-18 "lm-")
            (a3-16 1)
            (t0-4 0)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-20) a0-44 a1-24 a2-18 a3-16 t0-4 t1-0)
        )
      (-> s5-6 ppointer)
      )
    )
  (let ((s5-7 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (set! (-> this legs 1)
          (ppointer->handle
            (when s5-7
              (let ((t9-22 (method-of-type terraformer-leg activate)))
                (t9-22 (the-as terraformer-leg s5-7) this "terraformer-leg" (the-as pointer #x70004000))
                )
              (let ((t9-23 run-function-in-process)
                    (a0-47 s5-7)
                    (a1-27 terraformer-leg-init-by-other)
                    (a2-21 "lm-")
                    (a3-19 2)
                    (t0-5 0)
                    )
                (set! t1-0 0)
                ((the-as (function object object object object object object none) t9-23) a0-47 a1-27 a2-21 a3-19 t0-5 t1-0)
                )
              (-> s5-7 ppointer)
              )
            )
          )
    )
  (let ((s5-8 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-8
      (let ((t9-25 (method-of-type terraformer-leg activate)))
        (t9-25 (the-as terraformer-leg s5-8) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-26 run-function-in-process)
            (a0-53 s5-8)
            (a1-30 terraformer-leg-init-by-other)
            (a2-24 "lr-")
            (a3-22 0)
            (t0-6 0)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-26) a0-53 a1-30 a2-24 a3-22 t0-6 t1-0)
        )
      (-> s5-8 ppointer)
      )
    )
  (let ((s5-9 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-9
      (let ((t9-28 (method-of-type terraformer-leg activate)))
        (t9-28 (the-as terraformer-leg s5-9) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-29 run-function-in-process)
            (a0-56 s5-9)
            (a1-33 terraformer-leg-init-by-other)
            (a2-27 "lr-")
            (a3-25 1)
            (t0-7 0)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-29) a0-56 a1-33 a2-27 a3-25 t0-7 t1-0)
        )
      (-> s5-9 ppointer)
      )
    )
  (let ((s5-10 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (set! (-> this legs 2)
          (ppointer->handle
            (when s5-10
              (let ((t9-31 (method-of-type terraformer-leg activate)))
                (t9-31 (the-as terraformer-leg s5-10) this "terraformer-leg" (the-as pointer #x70004000))
                )
              (let ((t9-32 run-function-in-process)
                    (a0-59 s5-10)
                    (a1-36 terraformer-leg-init-by-other)
                    (a2-30 "lr-")
                    (a3-28 2)
                    (t0-8 0)
                    )
                (set! t1-0 #x42680000)
                ((the-as (function object object object object object object none) t9-32) a0-59 a1-36 a2-30 a3-28 t0-8 t1-0)
                )
              (-> s5-10 ppointer)
              )
            )
          )
    )
  (let ((s5-11 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-11
      (let ((t9-34 (method-of-type terraformer-leg activate)))
        (t9-34 (the-as terraformer-leg s5-11) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-35 run-function-in-process)
            (a0-65 s5-11)
            (a1-39 terraformer-leg-init-by-other)
            (a2-33 "rf-")
            (a3-31 0)
            (t0-9 1)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-35) a0-65 a1-39 a2-33 a3-31 t0-9 t1-0)
        )
      (-> s5-11 ppointer)
      )
    )
  (let ((s5-12 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-12
      (let ((t9-37 (method-of-type terraformer-leg activate)))
        (t9-37 (the-as terraformer-leg s5-12) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-38 run-function-in-process)
            (a0-68 s5-12)
            (a1-42 terraformer-leg-init-by-other)
            (a2-36 "rf-")
            (a3-34 1)
            (t0-10 1)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-38) a0-68 a1-42 a2-36 a3-34 t0-10 t1-0)
        )
      (-> s5-12 ppointer)
      )
    )
  (let ((s5-13 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (set! (-> this legs 3)
          (ppointer->handle
            (when s5-13
              (let ((t9-40 (method-of-type terraformer-leg activate)))
                (t9-40 (the-as terraformer-leg s5-13) this "terraformer-leg" (the-as pointer #x70004000))
                )
              (let ((t9-41 run-function-in-process)
                    (a0-71 s5-13)
                    (a1-45 terraformer-leg-init-by-other)
                    (a2-39 "rf-")
                    (a3-37 2)
                    (t0-11 1)
                    )
                (set! t1-0 #x42c00000)
                ((the-as (function object object object object object object none) t9-41) a0-71 a1-45 a2-39 a3-37 t0-11 t1-0)
                )
              (-> s5-13 ppointer)
              )
            )
          )
    )
  (let ((s5-14 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-14
      (let ((t9-43 (method-of-type terraformer-leg activate)))
        (t9-43 (the-as terraformer-leg s5-14) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-44 run-function-in-process)
            (a0-77 s5-14)
            (a1-48 terraformer-leg-init-by-other)
            (a2-42 "rm-")
            (a3-40 0)
            (t0-12 1)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-44) a0-77 a1-48 a2-42 a3-40 t0-12 t1-0)
        )
      (-> s5-14 ppointer)
      )
    )
  (let ((s5-15 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-15
      (let ((t9-46 (method-of-type terraformer-leg activate)))
        (t9-46 (the-as terraformer-leg s5-15) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-47 run-function-in-process)
            (a0-80 s5-15)
            (a1-51 terraformer-leg-init-by-other)
            (a2-45 "rm-")
            (a3-43 1)
            (t0-13 1)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-47) a0-80 a1-51 a2-45 a3-43 t0-13 t1-0)
        )
      (-> s5-15 ppointer)
      )
    )
  (let ((s5-16 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (set! (-> this legs 4)
          (ppointer->handle
            (when s5-16
              (let ((t9-49 (method-of-type terraformer-leg activate)))
                (t9-49 (the-as terraformer-leg s5-16) this "terraformer-leg" (the-as pointer #x70004000))
                )
              (let ((t9-50 run-function-in-process)
                    (a0-83 s5-16)
                    (a1-54 terraformer-leg-init-by-other)
                    (a2-48 "rm-")
                    (a3-46 2)
                    (t0-14 1)
                    )
                (set! t1-0 #x42000000)
                ((the-as (function object object object object object object none) t9-50) a0-83 a1-54 a2-48 a3-46 t0-14 t1-0)
                )
              (-> s5-16 ppointer)
              )
            )
          )
    )
  (let ((s5-17 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-17
      (let ((t9-52 (method-of-type terraformer-leg activate)))
        (t9-52 (the-as terraformer-leg s5-17) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-53 run-function-in-process)
            (a0-89 s5-17)
            (a1-57 terraformer-leg-init-by-other)
            (a2-51 "rr-")
            (a3-49 0)
            (t0-15 1)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-53) a0-89 a1-57 a2-51 a3-49 t0-15 t1-0)
        )
      (-> s5-17 ppointer)
      )
    )
  (let ((s5-18 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (when s5-18
      (let ((t9-55 (method-of-type terraformer-leg activate)))
        (t9-55 (the-as terraformer-leg s5-18) this "terraformer-leg" (the-as pointer #x70004000))
        )
      (let ((t9-56 run-function-in-process)
            (a0-92 s5-18)
            (a1-60 terraformer-leg-init-by-other)
            (a2-54 "rr-")
            (a3-52 1)
            (t0-16 1)
            )
        (set! t1-0 0)
        ((the-as (function object object object object object object none) t9-56) a0-92 a1-60 a2-54 a3-52 t0-16 t1-0)
        )
      (-> s5-18 ppointer)
      )
    )
  (let ((s5-19 (get-process *default-dead-pool* terraformer-leg #x4000 1)))
    (set! (-> this legs 5)
          (ppointer->handle
            (when s5-19
              (let ((t9-58 (method-of-type terraformer-leg activate)))
                (t9-58 (the-as terraformer-leg s5-19) this "terraformer-leg" (the-as pointer #x70004000))
                )
              (let ((t9-59 run-function-in-process)
                    (a0-95 s5-19)
                    (a1-63 terraformer-leg-init-by-other)
                    (a2-57 "rr-")
                    (a3-55 2)
                    (t0-17 1)
                    )
                (set! t1-0 #x42d80000)
                ((the-as (function object object object object object object none) t9-59) a0-95 a1-63 a2-57 a3-55 t0-17 t1-0)
                )
              (-> s5-19 ppointer)
              )
            )
          )
    )
  (process-spawn terraformer-leg "lf-" 3 0 (the-as none t1-0) :name "terraformer-leg" :to this)
  (process-spawn terraformer-leg "lm-" 3 0 (the-as none t1-0) :name "terraformer-leg" :to this)
  (process-spawn terraformer-leg "lr-" 3 0 (the-as none t1-0) :name "terraformer-leg" :to this)
  (process-spawn terraformer-leg "rf-" 3 0 (the-as none t1-0) :name "terraformer-leg" :to this)
  (process-spawn terraformer-leg "rm-" 3 0 (the-as none t1-0) :name "terraformer-leg" :to this)
  (process-spawn terraformer-leg "rr-" 3 0 (the-as none t1-0) :name "terraformer-leg" :to this)
  (set! (-> this old-target-time) 0)
  (set! (-> this older-target-time) 0)
  (set! (-> this launch-drones) #f)
  (set! (-> this jumper) (the-as handle #f))
  (set! (-> this drone) (the-as handle #f))
  (set! (-> this mine-rounds-till-drones) 4)
  (set! (-> this event-hook) (-> (method-of-object this walk) event))
  (set! (-> this desired-nav-mesh-index) 0)
  (set! (-> this current-nav-mesh-index) -1)
  (let ((a0-118 (nav-mesh-from-res-tag (-> this entity) 'nav-mesh-actor (-> this desired-nav-mesh-index))))
    (if a0-118
        (change-to a0-118 this)
        )
    )
  (setup-masks (-> this draw) 0 4)
  (go (method-of-object this dormant))
  )

(deftype hud-terraformer (hud)
  ()
  )


(defmethod draw ((this hud-terraformer))
  (set-hud-piece-position! (-> this sprites 0) (the int (+ 472.0 (* 130.0 (-> this offset)))) 160)
  (format (clear (-> this strings 0 text)) "~D" (-> this values 0 current))
  (set-as-offset-from! (the-as hud-sprite (-> this strings 0 pos)) (-> this sprites 0 pos) 4 48)
  ((method-of-type hud draw) this)
  0
  (none)
  )

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

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

(deftype task-manager-terraformer (task-manager)
  ((pilot-mode?  symbol)
   )
  (:methods
    (task-manager-terraformer-method-32 (_type_) none)
    )
  )


;; WARN: Return type mismatch symbol vs none.
(defmethod task-manager-method-26 ((this task-manager-terraformer))
  (let ((t9-0 (method-of-type task-manager task-manager-method-26)))
    (t9-0 this)
    )
  (if (= (-> *game-info* counter) 0.0)
      (send-event this 'complete)
      )
  (cond
    ((and *target* (focus-test? *target* pilot) (nonzero? (-> *target* pilot)))
     (if (and (not (-> this pilot-mode?))
              (send-event (handle->process (-> *target* pilot vehicle)) 'set-string-height #x46400000)
              )
         (set! (-> this pilot-mode?) #t)
         )
     )
    (else
      (set! (-> this pilot-mode?) #f)
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defmethod task-manager-method-25 ((this task-manager-terraformer))
  (let ((t9-0 (method-of-type task-manager task-manager-method-25)))
    (t9-0 this)
    )
  (send-event (handle->process (-> this hud-counter)) 'hide-and-die)
  (none)
  )

;; WARN: Return type mismatch connection vs none.
(defmethod set-time-limit ((this task-manager-terraformer))
  (let ((t9-0 (method-of-type task-manager set-time-limit)))
    (t9-0 this)
    )
  (set! (-> this pilot-mode?) #f)
  (set! (-> *game-info* counter) 1.0)
  (set! (-> this hud-counter)
        (ppointer->handle (process-spawn hud-terraformer :init hud-init-by-other :name "hud-terraformer" :to this))
        )
  (set-setting! 'extra-bank '((desert1 desbos1) (desert2 desbos2)) 0.0 0)
  (set-setting! 'airlock #f 0.0 0)
  (set-setting! 'pilot-exit #f 0.0 0)
  (set-setting! 'pilot-death #t 0.0 0)
  (set-setting! 'cloth #f 0.0 0)
  (set-setting! 'fog-special-interp-rate #f 0.03 0)
  (set-setting! 'fog-special-interp-targ #f 0.5 0)
  (set-setting! 'music 'finboss1 0.0 0)
  (set-setting! 'exclusive-task #f 0.0 (-> this node-info task))
  (none)
  )
