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

;; name: centipede.gc
;; name in dgo: centipede
;; dgos: UNB

;; DECOMP BEGINS

(deftype centipede-cam (structure)
  ((init?             symbol)
   (trans             vector  :inline)
   (dir               vector  :inline)
   (track-focus-tilt  float)
   )
  )


(deftype centipede (nav-enemy)
  ((id                      int8)
   (anim-ctr                int8)
   (focus-pos-hist-count    int8)
   (legs-sound              ambient-sound)
   (grabbed-focus?          symbol)
   (using-chan1-effects?    symbol)
   (set-camera-mode?        symbol)
   (talking-volume          float)
   (desired-talking-volume  float)
   (legs-volume             float)
   (focus-gnd-height        float)
   (track-focus-tilt        float)
   (bobbing-intensity       float)
   (bobbing                 trsqv)
   (src-quat                quaternion     :inline)
   (dest-quat               quaternion     :inline)
   (cam                     centipede-cam  :inline)
   (focus-pos-hist          vector         15 :inline)
   )
  (:state-methods
    attack
    attack-failed
    hidden
    grab-cam
    thru-grating
    )
  (:methods
    (centipede-method-183 (_type_) none)
    (set-chan1-effects (_type_) none)
    (target-close? (_type_) symbol)
    (centipede-method-186 (_type_) none)
    (centipede-method-187 (_type_) none)
    (centipede-method-188 (_type_) none)
    )
  )


(defskelgroup skel-centipede centipede centipede-lod0-jg centipede-idle-ja
              ((centipede-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 3 10)
              :shadow centipede-shadow-mg
              :origin-joint-index 3
              )

(define *centipede-nav-enemy-info*
  (new 'static 'nav-enemy-info
    :use-die-falling #f
    :use-victory #f
    :use-jump-blocked #f
    :debug-draw-neck #f
    :jump-debug-draw #f
    :move-to-ground #f
    :hover-if-no-ground #t
    :idle-anim-script (new 'static 'array idle-control-frame 4
      (new 'static 'idle-control-frame :command (ic-cmd push) :param0 #x1e)
      (new 'static 'idle-control-frame :command (ic-cmd play) :anim #x3 :param0 #x1 :param1 #x1)
      (new 'static 'idle-control-frame)
      (new 'static 'idle-control-frame)
      )
    :idle-anim 3
    :notice-anim 3
    :hostile-anim -1
    :hit-anim 3
    :knocked-anim -1
    :knocked-land-anim -1
    :die-anim 3
    :die-falling-anim 3
    :victory-anim -1
    :jump-wind-up-anim 3
    :jump-in-air-anim 3
    :jump-land-anim 3
    :neck-joint 4
    :look-at-joint 6
    :bullseye-joint 6
    :sound-hit (static-sound-name "centipede-hit")
    :sound-die (static-sound-name "centipede-die")
    :notice-distance (meters 500)
    :notice-distance-delta (meters 10)
    :proximity-notice-distance (meters 500)
    :default-hit-points #x3e8
    :gnd-collide-with (collide-spec backgnd)
    :movement-gravity (meters -100)
    :friction 0.8
    :attack-shove-back (meters 5)
    :attack-shove-up (meters 3)
    :attack-mode 'generic
    :attack-damage 2
    :recover-gnd-collide-with (collide-spec backgnd crate obstacle hit-by-others-list pusher)
    :jump-height-min (meters 3)
    :jump-height-factor 0.5
    :knocked-seek-ry-clamp 2730.6667
    :knocked-soft-vxz-lo 72089.6
    :knocked-soft-vxz-hi 108134.4
    :knocked-soft-vy-lo 81920.0
    :knocked-soft-vy-hi 122880.0
    :knocked-medium-vxz-lo 147456.0
    :knocked-medium-vxz-hi 196608.0
    :knocked-medium-vy-lo 135168.0
    :knocked-medium-vy-hi 151552.0
    :knocked-hard-vxz-lo 78643.2
    :knocked-hard-vxz-hi 117964.8
    :knocked-hard-vy-lo 183500.8
    :knocked-hard-vy-hi 209715.2
    :knocked-huge-vxz-lo 164659.2
    :knocked-huge-vxz-hi 249036.8
    :knocked-huge-vy-lo 183500.8
    :knocked-huge-vy-hi 217907.2
    :knocked-yellow-vxz-lo 40960.0
    :knocked-yellow-vxz-hi 49152.0
    :knocked-yellow-vy-lo 57344.0
    :knocked-yellow-vy-hi 81920.0
    :knocked-red-vxz-lo 24576.0
    :knocked-red-vxz-hi 196608.0
    :knocked-red-vy-lo 94208.0
    :knocked-red-vy-hi 151552.0
    :knocked-blue-vxz-lo 40960.0
    :knocked-blue-vxz-hi 49152.0
    :knocked-blue-vy-lo 24576.0
    :knocked-blue-vy-hi 81920.0
    :shadow-size (meters 2)
    :shadow-max-y (meters 2)
    :shadow-min-y (meters -3)
    :shadow-locus-dist (meters 150)
    :gem-joint -1
    :gem-offset (new 'static 'sphere :r 163840.0)
    :callback-info #f
    :use-momentum #t
    :use-frustration #f
    :use-stop-chase #f
    :use-circling #f
    :use-pacing #f
    :walk-anim 3
    :turn-anim -1
    :run-anim 3
    :taunt-anim 3
    :run-travel-speed (meters 6)
    :run-acceleration (meters 24)
    :run-turning-acceleration (meters 50)
    :walk-travel-speed (meters 4)
    :walk-acceleration (meters 6)
    :walk-turning-acceleration (meters 3)
    :maximum-rotation-rate (degrees 90)
    :notice-nav-radius (meters 7)
    :frustration-distance (meters 8)
    :frustration-time (seconds 4)
    :blocked-time (seconds 0.3)
    :circle-dist-lo 20480.0
    :circle-dist-hi 61440.0
    :nav-mesh #f
    )
  )

(set! (-> *centipede-nav-enemy-info* fact-defaults) *fact-info-enemy-defaults*)

(defmethod general-event-handler ((this centipede) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  "Handles various events for the enemy
@TODO - unsure if there is a pattern for the events and this should have a more specific name"
  (case arg2
    (('under-break-floor)
     (go (method-of-object this thru-grating))
     )
    (else
      ((method-of-type nav-enemy general-event-handler) this arg0 arg1 arg2 arg3)
      )
    )
  )

;; WARN: Return type mismatch nav-enemy vs centipede.
(defmethod relocate ((this centipede) (arg0 int))
  (if (nonzero? (-> this bobbing))
      (&+! (-> this bobbing) arg0)
      )
  (if (nonzero? (-> this legs-sound))
      (&+! (-> this legs-sound) arg0)
      )
  (the-as centipede ((method-of-type nav-enemy relocate) this arg0))
  )

(defmethod deactivate ((this centipede))
  (when (-> this set-camera-mode?)
    (set! (-> this set-camera-mode?) #f)
    (remove-setting-by-arg0 *setting-control* 'mode-name)
    )
  (if (nonzero? (-> this legs-sound))
      (stop! (-> this legs-sound))
      )
  ((method-of-type nav-enemy deactivate) this)
  (none)
  )

;; WARN: Return type mismatch float vs none.
(defmethod centipede-method-187 ((this centipede))
  (let ((centipede-cam (-> this cam)))
    (let ((cam-dir (new 'stack-no-clear 'vector)))
      (set! (-> cam-dir quad) (-> centipede-cam dir quad))
      (vector-z-quaternion! (-> centipede-cam dir) (-> this root quat))
      (set! (-> centipede-cam dir y) 0.0)
      (vector-normalize! (-> centipede-cam dir) 1.0)
      (set! (-> centipede-cam trans quad) (-> this root trans quad))
      (set! (-> centipede-cam trans y) (+ 32768.0
                                          (* (+ (* 2048.0 (cos (* 218.45334 (the float (mod (current-time) 300)))))
                                                (* 614.4 (cos (* 68.91272 (the float (mod (current-time) 951)))))
                                                )
                                             (-> this bobbing-intensity)
                                             )
                                          (-> centipede-cam trans y)
                                          )
            )
      (if (= (-> this id) 1)
          (set! (-> centipede-cam dir y) -0.574)
          (set! (-> centipede-cam dir y) -0.474)
          )
      (vector-normalize! (-> centipede-cam dir) 1.0)
      (let ((proc (handle->process (-> this focus handle)))
            (s3-0 #f)
            )
        (when (and proc (not (and (-> this next-state) (let ((v1-27 (-> this next-state name)))
                                                         (or (= v1-27 'attack) (= v1-27 'attack-failed))
                                                         )
                                  )
                             )
                   )
          (let ((s2-0 (new 'stack-no-clear 'vector)))
            (vector-! s2-0 (get-trans (the-as process-focusable proc) 0) (-> this root trans))
            (vector-normalize! s2-0 1.0)
            (when (>= (vector-dot s2-0 (-> centipede-cam dir)) 0.342)
              (let ((f0-23 (fmax
                             0.0
                             (fmin 8192.0 (atan (-> s2-0 y) (sqrtf (+ (* (-> s2-0 x) (-> s2-0 x)) (* (-> s2-0 z) (-> s2-0 z))))))
                             )
                           )
                    )
                (seek! (-> centipede-cam track-focus-tilt) f0-23 (* 65536.0 (seconds-per-frame)))
                )
              (set! s3-0 #t)
              )
            )
          )
        (if (not s3-0)
            (seek! (-> centipede-cam track-focus-tilt) 0.0 (* 65536.0 (seconds-per-frame)))
            )
        )
      (let ((s4-1 (new 'stack-no-clear 'vector))
            (s3-1 (new 'stack-no-clear 'quaternion))
            (s2-1 (new 'stack-no-clear 'matrix))
            )
        (vector-rotate90-around-y! s4-1 (-> centipede-cam dir))
        (set! (-> s4-1 y) 0.0)
        (vector-normalize! s4-1 1.0)
        (quaternion-vector-angle! s3-1 s4-1 (-> centipede-cam track-focus-tilt))
        (quaternion->matrix s2-1 s3-1)
        (vector-matrix*! (-> centipede-cam dir) (-> centipede-cam dir) s2-1)
        )
      (cond
        ((-> centipede-cam init?)
         (set! (-> centipede-cam init?) #f)
         )
        (else
          (let ((s3-2 (new 'stack-no-clear 'matrix))
                (s4-2 (new 'stack-no-clear 'vector))
                )
            (matrix-from-two-vectors-max-angle! s3-2 (-> centipede-cam dir) cam-dir 8192.0)
            (vector-matrix*! s4-2 (-> centipede-cam dir) s3-2)
            (matrix-from-two-vectors-smooth! s3-2 s4-2 (-> centipede-cam dir) 65536.0 150)
            (vector-matrix*! (-> centipede-cam dir) s4-2 s3-2)
            )
          )
        )
      )
    (let ((v1-47 *camera*))
      (when v1-47
        (let ((v1-48 (-> v1-47 slave)))
          (when v1-48
            (set! (-> v1-48 0 saved-pt quad) (-> centipede-cam trans quad))
            (let ((s5-1 (-> v1-48 0 tracking)))
              (vector-cross! (the-as vector (-> s5-1 inv-mat)) *up-vector* (-> centipede-cam dir))
              (vector-normalize! (the-as vector (-> s5-1 inv-mat)) 1.0)
              (vector-cross! (-> s5-1 inv-mat vector 1) (-> centipede-cam dir) (the-as vector (-> s5-1 inv-mat)))
              (set! (-> s5-1 inv-mat vector 2 quad) (-> centipede-cam dir quad))
              (set! (-> s5-1 inv-mat vector 0 w) 0.0)
              (set! (-> s5-1 inv-mat vector 1 w) 0.0)
              (set! (-> s5-1 inv-mat vector 2 w) 0.0)
              )
            )
          )
        )
      )
    )
  (none)
  )

(defmethod centipede-method-188 ((this centipede))
  (local-vars (s5-0 art-element))
  (let ((janim (if (> (-> this skel active-channels) 0)
                   (-> this skel root-channel 0 frame-group)
                   )
               )
        )
    (cond
      ((and janim (= janim (-> this draw art-group data 4)))
       (when (ja-done? 1)
         (-> this draw art-group data 7)
         (let ((v1-10 (rnd-int-count this 100))
               (a0-9 (if (> (-> this skel active-channels) 0)
                         (-> this skel root-channel 1 frame-group)
                         )
                     )
               )
           (cond
             ((and (= a0-9 (-> this draw art-group data 7)) (> (-> this anim-ctr) 0))
              (+! (-> this anim-ctr) -1)
              (set! s5-0 (-> this draw art-group data 7))
              )
             ((= a0-9 (-> this draw art-group data 11))
              (set! s5-0 (-> this draw art-group data 12))
              (set! (-> this anim-ctr) (rnd-int-range this 0 3))
              )
             ((= a0-9 (-> this draw art-group data 12))
              (let ((v1-20 (-> this anim-ctr)))
                (cond
                  ((> v1-20 0)
                   (set! (-> this anim-ctr) (+ v1-20 -1))
                   (set! s5-0 (-> this draw art-group data 12))
                   )
                  (else
                    (set! s5-0 (-> this draw art-group data 13))
                    )
                  )
                )
              )
             ((= a0-9 (-> this draw art-group data 13))
              (set! s5-0 (-> this draw art-group data 14))
              (set! (-> this anim-ctr) (rnd-int-range this 0 3))
              )
             ((and (= a0-9 (-> this draw art-group data 14)) (> (-> this anim-ctr) 0))
              (+! (-> this anim-ctr) -1)
              (set! s5-0 (-> this draw art-group data 14))
              )
             ((< v1-10 10)
              (set! s5-0 (-> this draw art-group data 11))
              )
             ((< v1-10 30)
              (set! s5-0 (-> this draw art-group data 8))
              )
             ((< v1-10 50)
              (set! s5-0 (-> this draw art-group data 9))
              )
             ((< v1-10 65)
              (set! s5-0 (-> this draw art-group data 10))
              )
             (else
               (set! s5-0 (-> this draw art-group data 7))
               (set! (-> this anim-ctr) (rnd-int-range this 2 6))
               )
             )
           )
         (let ((a0-17 (-> this skel root-channel 1)))
           (set! (-> a0-17 frame-interp 1) 1.0)
           (set! (-> this skel interp-select 0) 192)
           (set! (-> this skel interp-select 1) 0)
           (set! (-> a0-17 frame-group) (the-as art-joint-anim s5-0))
           (set! (-> a0-17 param 0) (the float (+ (-> (the-as art-joint-anim s5-0) frames num-frames) -1)))
           (set! (-> a0-17 param 1) 1.0)
           (set! (-> a0-17 frame-num) 0.0)
           (joint-control-channel-group! a0-17 (the-as art-joint-anim s5-0) num-func-seek!)
           )
         )
       (let ((a0-18 (-> this skel root-channel 0)))
         (set! (-> a0-18 param 0) 0.7)
         (joint-control-channel-group-eval! a0-18 (the-as art-joint-anim #f) num-func-loop!)
         )
       (let ((a0-19 (-> this skel root-channel 1)))
         (set! (-> a0-19 param 0) (the float (+ (-> a0-19 frame-group frames num-frames) -1)))
         (set! (-> a0-19 param 1) 1.0)
         (joint-control-channel-group-eval! a0-19 (the-as art-joint-anim #f) num-func-seek!)
         )
       )
      (else
        (ja-channel-push! 2 (seconds 0.15))
        (let ((a0-21 (-> this skel root-channel 0)))
          (set! (-> a0-21 frame-group) (the-as art-joint-anim (-> this draw art-group data 4)))
          (set! (-> a0-21 param 0) 0.7)
          (joint-control-channel-group! a0-21 (the-as art-joint-anim (-> this draw art-group data 4)) num-func-loop!)
          )
        (let ((a0-22 (-> this skel root-channel 1)))
          (set! (-> a0-22 frame-interp 1) 1.0)
          (set! (-> this skel interp-select 0) 192)
          (set! (-> this skel interp-select 1) 0)
          (set! (-> a0-22 frame-group) (the-as art-joint-anim (-> this draw art-group data 7)))
          (set! (-> a0-22 param 0)
                (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 7)) frames num-frames) -1))
                )
          (set! (-> a0-22 param 1) 1.0)
          (joint-control-channel-group! a0-22 (the-as art-joint-anim (-> this draw art-group data 7)) num-func-seek!)
          )
        (set! (-> this anim-ctr) (rnd-int-range this 2 6))
        (when (not (-> this using-chan1-effects?))
          (set! (-> this using-chan1-effects?) #t)
          (let ((v1-106 (-> this skel effect)))
            (set! (-> v1-106 channel-offset) 1)
            )
          0
          )
        )
      )
    )
  (none)
  )

(defmethod set-chan1-effects ((this centipede))
  (when (-> this using-chan1-effects?)
    (set! (-> this using-chan1-effects?) #f)
    (let ((v1-2 (-> this skel effect)))
      (set! (-> v1-2 channel-offset) 0)
      )
    0
    )
  (none)
  )

;; WARN: Return type mismatch quaternion vs none.
(defmethod nav-enemy-method-142 ((this centipede) (arg0 nav-control))
  (let ((t9-0 (method-of-type nav-enemy nav-enemy-method-142)))
    (t9-0 this arg0)
    )
  (let ((s5-0 (new 'stack-no-clear 'vector)))
    (vector-z-quaternion! s5-0 (-> this root quat))
    (vector-normalize! s5-0 1.0)
    (let ((s3-0 (handle->process (-> this focus handle)))
          (s4-0 #f)
          )
      (cond
        (s3-0
          (let ((s2-0 (-> this focus-pos-hist-count)))
            (countdown (v1-7 (min 14 s2-0))
              (set! (-> this focus-pos-hist (+ v1-7 1) quad) (-> this focus-pos-hist v1-7 quad))
              )
            (set! (-> this focus-pos-hist 0 quad) (-> (get-trans (the-as process-focusable s3-0) 0) quad))
            (if (< s2-0 15)
                (set! (-> this focus-pos-hist-count) (+ s2-0 1))
                )
            )
          )
        (else
          (set! (-> this focus-pos-hist-count) 0)
          0
          )
        )
      (when s3-0
        (let ((s3-1 (new 'stack-no-clear 'vector)))
          (vector-! s3-1 (-> this focus-pos-hist (+ (-> this focus-pos-hist-count) -1)) (-> this root trans))
          (vector-normalize! s3-1 1.0)
          (when (>= (vector-dot s3-1 s5-0) 0.342)
            (let ((f0-9
                    (fmax
                      0.0
                      (fmin 8192.0 (atan (-> s3-1 y) (sqrtf (+ (* (-> s3-1 x) (-> s3-1 x)) (* (-> s3-1 z) (-> s3-1 z))))))
                      )
                    )
                  )
              (set! (-> this track-focus-tilt)
                    (seek-with-smooth (-> this track-focus-tilt) f0-9 (* 5461.3335 (seconds-per-frame)) 0.25 1.0)
                    )
              )
            (set! s4-0 #t)
            )
          )
        )
      (if (not s4-0)
          (set! (-> this track-focus-tilt)
                (seek-with-smooth (-> this track-focus-tilt) 0.0 (* 5461.3335 (seconds-per-frame)) 0.25 1.0)
                )
          )
      )
    (let ((s3-2 (new 'stack-no-clear 'vector))
          (s4-1 (new 'stack-no-clear 'quaternion))
          )
      (vector-rotate90-around-y! s3-2 s5-0)
      (quaternion-vector-angle! s4-1 s3-2 (+ 4551.1113 (-> this track-focus-tilt)))
      (quaternion*! (-> this root quat) s4-1 (-> this root quat))
      )
    )
  (none)
  )

(defmethod coin-flip? ((this centipede))
  "@returns The result of a 50/50 RNG roll"
  #f
  )

(defmethod in-aggro-range? ((this centipede) (arg0 process-focusable) (arg1 vector))
  "Should the enemy activate.
- if `activate-distance` is `0.0`, always true
- otherwise, check if the provided process is close enough
@param proc The process used to distance check
@returns true/false"
  (when arg0
    (if (not arg1)
        (set! arg1 (get-trans arg0 0))
        )
    (when arg1
      (let* ((f0-0 (-> this root trans y))
             (v1-4 (-> this root))
             (f1-0 (-> v1-4 trans y))
             (a0-2 (-> this fact))
             )
        (when (and (< f0-0 (+ f1-0 (-> a0-2 notice-top))) (< (- f1-0 (-> a0-2 notice-bottom)) f0-0))
          (let* ((f30-0 (-> this enemy-info notice-nav-radius))
                 (f0-1 f30-0)
                 )
            (or (>= (* f0-1 f0-1) (vector-vector-xz-distance-squared (-> v1-4 trans) arg1))
                (is-in-mesh? (-> this nav) arg1 f30-0)
                )
            )
          )
        )
      )
    )
  )

;; WARN: Return type mismatch process vs process-focusable.
(defmethod get-enemy-target ((this centipede))
  "@returns the [[process-focusable]] that the enemy is currently focusing on, or [[#f]] otherwise"
  (let ((v0-0 (handle->process (-> this focus handle))))
    (if (and v0-0 (focus-test? (the-as process-focusable v0-0) disable dead grabbed))
        (set! v0-0 (the-as process #f))
        )
    (the-as process-focusable v0-0)
    )
  )

(defmethod target-close? ((this centipede))
  "Is the target close enough to attack?"
  (let ((targ (get-enemy-target this)))
    (when targ
      (let* ((targ-pos (get-trans targ 0))
             (y-off (- (-> targ-pos y) (-> this root trans y)))
             (dist 28672.0)
             )
        (and (>= (* dist dist) (vector-vector-xz-distance-squared (-> this root trans) targ-pos))
             (or (>= y-off -12288.0) (or (>= 24576.0 y-off) (focus-test? targ edge-grab)))
             )
        )
      )
    )
  )

(defmethod centipede-method-183 ((this centipede))
  (when (not (and (-> this next-state) (= (-> this next-state name) 'thru-grating)))
    (centipede-method-187 this)
    (when (= (-> this id) 2)
      (let ((overlap-parms (new 'stack-no-clear 'overlaps-others-params)))
        (set! (-> overlap-parms options) (overlaps-others-options))
        (set! (-> overlap-parms collide-with-filter) (the-as collide-spec -1))
        (set! (-> overlap-parms tlist) *touching-list*)
        (find-overlapping-shapes (-> this root) overlap-parms)
        )
      )
    (let* ((travel-speed (-> *centipede-nav-enemy-info* run-travel-speed))
           (f0-2 (fmin 1.0 (/ (vector-length (-> this root transv)) travel-speed)))
           )
      (seek! (-> this bobbing-intensity) f0-2 (* 4.0 (seconds-per-frame)))
      )
    (quaternion-copy! (-> this bobbing quat) (-> this root quat))
    (set! (-> this bobbing trans quad) (-> this root trans quad))
    (let ((s5-0 (new 'stack-no-clear 'vector))
          (f30-1 (* 2662.4 (cos (* 283.70563 (the float (mod (current-time) 231))))))
          (bob-trans (-> this bobbing trans))
          )
      (vector-z-quaternion! s5-0 (-> this root quat))
      (set! (-> s5-0 y) 0.0)
      (vector-normalize! s5-0 (* f30-1 (-> this bobbing-intensity)))
      (vector+! (the-as vector (&-> bob-trans x)) (the-as vector (&-> bob-trans x)) s5-0)
      )
    )
  (update-trans! (-> this sound) (-> this root trans))
  (when (!= (-> this talking-volume) (-> this desired-talking-volume))
    (seek! (-> this talking-volume) (-> this desired-talking-volume) (* 4.0 (seconds-per-frame)))
    (update-vol! (-> this sound) (-> this talking-volume))
    )
  (update! (-> this sound))
  (update-trans! (-> this legs-sound) (-> this root trans))
  (let ((f0-20 (fmin 1.0 (* 0.00012207031 (vector-length (-> this root transv))))))
    (when (!= (-> this legs-volume) f0-20)
      (seek! (-> this legs-volume) f0-20 (* 4.0 (seconds-per-frame)))
      (update-vol! (-> this legs-sound) (-> this legs-volume))
      )
    )
  (update! (-> this legs-sound))
  (none)
  )

(defmethod common-post ((this centipede))
  "Does a lot of various things relating to interacting with the target
- tracks when the enemy was last drawn
- looks at the target and handles attacking
@TODO Not extremely well understood yet"
  (let ((t9-0 (method-of-type nav-enemy common-post)))
    (t9-0 this)
    )
  (let ((a0-3 (handle->process (-> this focus handle))))
    (when a0-3
      (let ((f0-0 (-> (get-trans (the-as process-focusable a0-3) 1) y)))
        (if (!= f0-0 -40959590.0)
            (set! (-> this focus-gnd-height) f0-0)
            )
        )
      )
    )
  (let ((s5-0 (-> this root)))
    (set! (-> s5-0 gspot-pos quad) (-> s5-0 trans quad))
    (let ((v1-12 (-> this nav))
          (a0-8 (-> s5-0 trans))
          (a1-2 (new 'stack-no-clear 'nav-find-poly-parms))
          )
      (vector-! (-> a1-2 point) a0-8 (-> v1-12 state mesh bounds))
      (set! (-> a1-2 y-threshold) (-> v1-12 nearest-y-threshold))
      (set! (-> a1-2 ignore) (the-as uint 2))
      (let ((a1-3 (find-poly-containing-point-local (-> v1-12 state mesh) a1-2))
            (s4-0 (new 'stack-no-clear 'collide-query))
            )
        (when a1-3
          (let ((s2-0 (-> this nav))
                (s3-0 (-> s4-0 best-other-tri intersect))
                )
            (let ((a3-2 (-> s4-0 best-other-tri normal))
                  (v1-15 (-> s5-0 trans))
                  )
              (project-point-onto-plane-of-poly-local
                (-> s2-0 state mesh)
                a1-3
                s3-0
                a3-2
                (vector-! (new 'stack-no-clear 'vector) v1-15 (-> s2-0 state mesh bounds))
                )
              )
            (vector+! s3-0 s3-0 (-> s2-0 state mesh bounds))
            )
          0
          (let ((f0-2 1024.0))
            (if (>= (* f0-2 f0-2) (vector-vector-xz-distance-squared (-> s4-0 best-other-tri intersect) (-> s5-0 trans)))
                (set! (-> s5-0 gspot-pos y) (-> s4-0 best-other-tri intersect y))
                )
            )
          )
        )
      )
    (let ((f0-6 (-> this root trans y)))
      (cond
        ((>= (-> s5-0 gspot-pos y) f0-6)
         (set! (-> s5-0 trans y) (-> s5-0 gspot-pos y))
         )
        ((and (!= (-> this focus-gnd-height) -40959590.0)
              (>= (- (-> this focus-gnd-height) (-> s5-0 gspot-pos y)) 4096.0)
              )
         (set! (-> s5-0 trans y)
               (seek-with-smooth (-> s5-0 trans y) (-> this focus-gnd-height) (* 24576.0 (seconds-per-frame)) 0.25 1.0)
               )
         )
        (else
          (set! (-> s5-0 trans y)
                (seek-with-smooth (-> s5-0 trans y) (-> s5-0 gspot-pos y) (* 24576.0 (seconds-per-frame)) 0.25 1.0)
                )
          )
        )
      )
    )
  (centipede-method-183 this)
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defmethod go-idle ((this centipede))
  (case (-> this id)
    ((1)
     (cond
       ((or (not *target*)
            (task-node-closed? (game-task-node under-sig-centipede1-end))
            (and *debug-segment* (cpad-hold? 0 l2))
            )
        (cleanup-for-death this)
        (go (method-of-object this die-fast))
        )
       ((task-node-closed? (game-task-node under-sig-centipede1-start))
        (logclear! (-> this mask) (process-mask actor-pause))
        (logclear! (-> this enemy-flags) (enemy-flag actor-pause-backup))
        (process-entity-status! this (entity-perm-status no-kill) #t)
        (go (method-of-object this grab-cam))
        )
       (else
         (go (method-of-object this hidden))
         )
       )
     )
    ((2)
     (cond
       ((or (not *target*)
            (task-node-closed? (game-task-node under-sig-resolution))
            (and *debug-segment* (cpad-hold? 0 l2))
            )
        (cleanup-for-death this)
        (go (method-of-object this die-fast))
        )
       ((task-node-closed? (game-task-node under-sig-centipede2-start))
        (logclear! (-> this mask) (process-mask actor-pause))
        (logclear! (-> this enemy-flags) (enemy-flag actor-pause-backup))
        (process-entity-status! this (entity-perm-status no-kill) #t)
        (go (method-of-object this grab-cam))
        )
       (else
         (go (method-of-object this hidden))
         )
       )
     )
    (else
      (go process-drawable-art-error "bad centipede id")
      )
    )
  (none)
  )

(defstate hidden (centipede)
  :virtual #t
  :enter (behavior ()
    (logior! (-> self focus-status) (focus-status disable))
    (vector-reset! (-> self root transv))
    (set! (-> self desired-talking-volume) 0.0)
    (let ((v1-5 (-> self root root-prim)))
      (set! (-> v1-5 prim-core collide-as) (collide-spec))
      (set! (-> v1-5 prim-core collide-with) (collide-spec))
      )
    0
    (logior! (-> self draw status) (draw-control-status no-draw))
    )
  :exit (behavior ()
    (logclear! (-> self draw status) (draw-control-status no-draw))
    (logclear! (-> self focus-status) (focus-status disable))
    (let ((v1-5 (-> self root root-prim)))
      (set! (-> v1-5 prim-core collide-as) (-> self root backup-collide-as))
      (set! (-> v1-5 prim-core collide-with) (-> self root backup-collide-with))
      )
    )
  :code sleep-code
  )

(defstate grab-cam (centipede)
  :virtual #t
  :exit (behavior ()
    (set-chan1-effects self)
    )
  :code (behavior ()
    (logior! (-> self enemy-flags) (enemy-flag alert))
    (set! (-> self desired-talking-volume) 0.0)
    (centipede-method-187 self)
    (set-setting! 'interp-time 'abs 0.0 0)
    (when (not (-> self set-camera-mode?))
      (set! (-> self set-camera-mode?) #t)
      (set-setting-by-param *setting-control* 'mode-name 'cam-fixed 0 0)
      )
    (set-setting! 'allow-look-around #f 0.0 0)
    (suspend)
    (until #f
      (let ((v1-13 *camera*))
        (when (and v1-13 (-> v1-13 slave))
          (logclear! (-> self enemy-flags) (enemy-flag use-notice-distance directed directed-ready use-trigger))
          (logior! (-> self enemy-flags) (enemy-flag chase-startup))
          (logclear! (-> self mask) (process-mask actor-pause))
          (go-hostile self)
          )
        )
      (centipede-method-188 self)
      (suspend)
      )
    #f
    )
  )

(defstate idle (centipede)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type nav-enemy idle) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (stop-looking-at-target! self)
    (logclear! (-> self enemy-flags) (enemy-flag use-notice-distance))
    (logior! (-> self enemy-flags) (enemy-flag alert))
    (vector-reset! (-> self root transv))
    (set! (-> self desired-talking-volume) 1.0)
    )
  :exit (behavior ()
    (set-chan1-effects self)
    (let ((t9-1 (-> (method-of-type nav-enemy idle) exit)))
      (if t9-1
          (t9-1)
          )
      )
    )
  :code (behavior ()
    (until #f
      (cond
        (*target*
          (set-time! (-> self state-time))
          )
        (else
          (when (time-elapsed? (-> self state-time) (seconds 2))
            (cleanup-for-death self)
            (go-virtual die-fast)
            )
          )
        )
      (centipede-method-188 self)
      (suspend)
      )
    #f
    )
  :post nav-enemy-simple-post
  )

(defstate active (centipede)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type nav-enemy active) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (stop-looking-at-target! self)
    (logclear! (-> self enemy-flags) (enemy-flag use-notice-distance))
    (logior! (-> self enemy-flags) (enemy-flag alert))
    (vector-reset! (-> self root transv))
    (set! (-> self desired-talking-volume) 1.0)
    )
  :exit (behavior ()
    (set-chan1-effects self)
    (let ((t9-1 (-> (method-of-type nav-enemy active) exit)))
      (if t9-1
          (t9-1)
          )
      )
    )
  :code (-> (method-of-type centipede idle) code)
  :post (-> (method-of-type centipede idle) post)
  )

(defstate stare (centipede)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type nav-enemy stare) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (stop-looking-at-target! self)
    (logclear! (-> self enemy-flags) (enemy-flag use-notice-distance))
    (logior! (-> self enemy-flags) (enemy-flag alert))
    (vector-reset! (-> self root transv))
    (set! (-> self desired-talking-volume) 1.0)
    )
  :exit (behavior ()
    (set-chan1-effects self)
    (let ((t9-1 (-> (method-of-type nav-enemy stare) exit)))
      (if t9-1
          (t9-1)
          )
      )
    )
  :code (-> (method-of-type centipede idle) code)
  )

(defstate hostile (centipede)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type nav-enemy hostile) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (stop-looking-at-target! self)
    (set! (-> self desired-talking-volume) 1.0)
    )
  :exit (behavior ()
    (set-chan1-effects self)
    (let ((t9-1 (-> (method-of-type nav-enemy hostile) exit)))
      (if t9-1
          (t9-1)
          )
      )
    )
  :trans (behavior ()
    (when (time-elapsed? (-> self state-time) (seconds 0.5))
      (let ((v1-6 (handle->process (-> self focus handle))))
        (if (or (not v1-6) (focus-test? (the-as process-focusable v1-6) dead))
            (go-virtual stop-chase)
            )
        )
      )
    (let ((t9-1 (-> (method-of-type nav-enemy hostile) trans)))
      (if t9-1
          (t9-1)
          )
      )
    (if (target-close? self)
        (go-virtual attack)
        )
    )
  :code sleep-code
  :post (behavior ()
    (centipede-method-188 self)
    (let ((a0-2 (handle->process (-> self focus handle))))
      (when a0-2
        (let ((gp-0 (new 'stack-no-clear 'vector)))
          (set! (-> gp-0 quad) (-> (get-trans (the-as process-focusable a0-2) 0) quad))
          (set! (-> gp-0 y) (-> self root trans y))
          (let ((v1-12 (-> self nav state)))
            (logclear! (-> v1-12 flags) (nav-state-flag directional-mode))
            (logior! (-> v1-12 flags) (nav-state-flag target-poly-dirty))
            (set! (-> v1-12 target-post quad) (-> gp-0 quad))
            )
          )
        0
        )
      )
    (nav-enemy-method-176 self)
    )
  )

(defstate stop-chase (centipede)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type nav-enemy stop-chase) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (stop-looking-at-target! self)
    (set! (-> self desired-talking-volume) 1.0)
    )
  :exit (behavior ()
    (set-chan1-effects self)
    (let ((t9-1 (-> (method-of-type nav-enemy stop-chase) exit)))
      (if t9-1
          (t9-1)
          )
      )
    )
  :trans (behavior ()
    (if (time-elapsed? (-> self state-time) (seconds 2))
        (react-to-focus self)
        )
    )
  :code sleep-code
  :post (behavior ()
    (centipede-method-188 self)
    (nav-enemy-method-176 self)
    )
  )

;; WARN: Return type mismatch quaternion vs none.
(defmethod centipede-method-186 ((this centipede))
  (let ((proc (handle->process (-> this focus handle))))
    (when proc
      (set! (-> this focus-pos quad) (-> (get-trans (the-as process-focusable proc) 0) quad))
      (when (and (not (-> this grabbed-focus?)) (= (-> proc type) target) (>= (ja-frame-num 0) 5.0))
        (if (send-event proc 'attack-invinc #f (static-attack-info ((id (new-attack-id)) (mode 'centipede))))
            (set! (-> this grabbed-focus?) #t)
            )
        )
      (when (not (-> this grabbed-focus?))
        (let ((s5-1 (new 'stack-no-clear 'vector)))
          (let ((cam-dir (new 'stack-no-clear 'vector))
                (trans-off (new 'stack-no-clear 'vector))
                )
            (let ((s2-0 (new 'stack-no-clear 'matrix)))
              (set! (-> cam-dir quad) (-> this cam dir quad))
              (set! (-> cam-dir y) 0.0)
              (vector-normalize! cam-dir 1.0)
              (vector-! trans-off (-> this focus-pos) (-> this root trans))
              (set! (-> s5-1 quad) (-> trans-off quad))
              (set! (-> s5-1 y) 0.0)
              (vector-normalize! s5-1 1.0)
              (matrix-from-two-vectors-max-angle! s2-0 cam-dir s5-1 7281.778)
              (vector-matrix*! s5-1 cam-dir s2-0)
              )
            (let ((v1-25 s5-1)
                  (a0-22 s5-1)
                  (a1-9 trans-off)
                  )
              (vector-float*! v1-25 a0-22 (sqrtf (+ (* (-> a1-9 x) (-> a1-9 x)) (* (-> a1-9 z) (-> a1-9 z)))))
              )
            (set! (-> s5-1 y) (+ 49152.0 (-> trans-off y)))
            )
          (vector-normalize! s5-1 1.0)
          (quaternion-look-at! (-> this dest-quat) s5-1 *up-vector*)
          )
        )
      )
    )
  (let ((f0-12 (fmin 1.0 (* 0.16666667 (ja-frame-num 0)))))
    (quaternion-slerp! (-> this root quat) (-> this src-quat) (-> this dest-quat) f0-12)
    )
  (none)
  )

(defstate attack (centipede)
  :virtual #t
  :enter (behavior ()
    (let ((v1-0 self))
      (set! (-> v1-0 enemy-flags) (the-as enemy-flag (logclear (-> v1-0 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-0 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (logior! (-> self enemy-flags) (enemy-flag lock-focus))
    (set! (-> self grabbed-focus?) #f)
    (vector-reset! (-> self root transv))
    (set! (-> self desired-talking-volume) 0.0)
    (let ((gp-0 (handle->process (-> self focus handle))))
      (if (not gp-0)
          (go-hostile self)
          )
      (set! (-> self focus-pos quad) (-> (get-trans (the-as process-focusable gp-0) 0) quad))
      )
    (quaternion-copy! (-> self src-quat) (-> self root quat))
    (quaternion-copy! (-> self dest-quat) (-> self src-quat))
    )
  :exit (behavior ()
    (logclear! (-> self enemy-flags) (enemy-flag lock-focus))
    )
  :trans (behavior ()
    (when (-> self grabbed-focus?)
      (let ((v1-3 (handle->process (-> self focus handle))))
        (if v1-3
            (vector-seek-3d-smooth!
              (-> (the-as process-focusable v1-3) root trans)
              (-> self root trans)
              (* 28672.0 (seconds-per-frame))
              0.8
              )
            )
        )
      )
    )
  :code (behavior ()
    (local-vars (a1-5 event-message-block))
    (ja-channel-push! 1 (seconds 0.17))
    (ja-no-eval :group! centipede-attack0-ja :num! (seek! max 3.0) :frame-num 0.0)
    (until (ja-done? 0)
      (centipede-method-186 self)
      (suspend)
      (ja :num! (seek! max 3.0))
      )
    (if (not (-> self grabbed-focus?))
        (go-virtual attack-failed)
        )
    (ja-no-eval :group! centipede-eat0-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (when (-> self grabbed-focus?)
      (until (send-event-function *target* a1-5)
        (suspend)
        (set! a1-5 (new 'stack-no-clear 'event-message-block))
        (let ((v1-57 (process->ppointer self)))
          (set! (-> a1-5 from) v1-57)
          )
        (set! (-> a1-5 num-params) 0)
        (set! (-> a1-5 message) 'end-mode)
        )
      )
    (go-hostile self)
    )
  :post (behavior ()
    (transform-post)
    (centipede-method-183 self)
    )
  )

(defstate attack-failed (centipede)
  :virtual #t
  :exit (behavior ()
    (set-chan1-effects self)
    )
  :code (behavior ()
    (set-time! (-> self state-time))
    (set! (-> self desired-talking-volume) 1.0)
    (while (not (time-elapsed? (-> self state-time) (seconds 0.35)))
      (let* ((v1-5 (- (current-time) (-> self state-time)))
             (f1-2 (* 0.00952381 (the float v1-5)))
             )
        (quaternion-slerp! (-> self root quat) (-> self src-quat) (-> self dest-quat) (- 1.0 (* f1-2 f1-2)))
        )
      (centipede-method-188 self)
      (suspend)
      )
    (while (not (time-elapsed? (-> self state-time) (seconds 1)))
      (centipede-method-188 self)
      (suspend)
      )
    (go-hostile self)
    )
  :post (-> (method-of-type centipede attack) post)
  )

(defstate thru-grating (centipede)
  :virtual #t
  :enter (behavior ()
    (let ((v1-0 self))
      (set! (-> v1-0 enemy-flags) (the-as enemy-flag (logclear (-> v1-0 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-0 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (vector-reset! (-> self root transv))
    (set! (-> self desired-talking-volume) 1.0)
    )
  :exit (behavior ()
    (set-chan1-effects self)
    )
  :code (behavior ()
    (logior! (-> self focus-status) (focus-status disable))
    (let ((v1-3 (-> self root root-prim)))
      (set! (-> v1-3 prim-core collide-as) (collide-spec))
      (set! (-> v1-3 prim-core collide-with) (collide-spec))
      )
    0
    (when (-> self set-camera-mode?)
      (set! (-> self set-camera-mode?) #f)
      (remove-setting-by-arg0 *setting-control* 'mode-name)
      )
    (remove-setting! 'allow-look-around)
    (set-setting! 'entity-name "camera-252" 0.0 0)
    (centipede-method-188 self)
    (suspend)
    (suspend)
    (remove-setting! 'interp-time)
    (remove-setting! 'entity-name)
    (logior! (-> self draw status) (draw-control-status no-draw))
    (cleanup-for-death self)
    (sleep-code)
    )
  :post (behavior ()
    (centipede-method-183 self)
    )
  )

;; WARN: Return type mismatch collide-shape-moving vs none.
(defmethod init-enemy-collision! ((this centipede))
  "Initializes the [[collide-shape-moving]] and any ancillary tasks to make the enemy collide properly"
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 9) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 10))
      (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 pusher))
      (set! (-> s4-0 prim-core action) (collide-action solid semi-solid))
      (set! (-> s4-0 transform-index) 3)
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 12288.0 40960.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 pusher))
      (set! (-> v1-13 prim-core action) (collide-action solid))
      (set! (-> v1-13 transform-index) 3)
      (set-vector! (-> v1-13 local-sphere) 0.0 -4096.0 -8192.0 14336.0)
      )
    (let ((v1-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-15 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-15 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-15 prim-core action) (collide-action solid))
      (set! (-> v1-15 transform-index) 3)
      (set-vector! (-> v1-15 local-sphere) 0.0 -4096.0 6144.0 13721.6)
      )
    (let ((v1-17 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-17 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-17 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-17 prim-core action) (collide-action solid))
      (set! (-> v1-17 transform-index) 3)
      (set-vector! (-> v1-17 local-sphere) 0.0 -4096.0 12288.0 13312.0)
      )
    (let ((v1-19 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-19 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-19 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-19 prim-core action) (collide-action solid))
      (set! (-> v1-19 transform-index) 7)
      (set-vector! (-> v1-19 local-sphere) 0.0 0.0 0.0 7782.4)
      )
    (let ((v1-21 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-21 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-21 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-21 prim-core action) (collide-action solid))
      (set! (-> v1-21 transform-index) 7)
      (set-vector! (-> v1-21 local-sphere) 4096.0 12288.0 0.0 3686.4)
      )
    (let ((v1-23 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-23 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-23 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-23 prim-core action) (collide-action semi-solid))
      (set! (-> v1-23 transform-index) 7)
      (set-vector! (-> v1-23 local-sphere) 3276.8 20480.0 0.0 2457.6)
      )
    (let ((v1-25 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-25 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-25 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-25 prim-core action) (collide-action solid))
      (set! (-> v1-25 transform-index) 8)
      (set-vector! (-> v1-25 local-sphere) 0.0 0.0 0.0 7782.4)
      )
    (let ((v1-27 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-27 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-27 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-27 prim-core action) (collide-action solid))
      (set! (-> v1-27 transform-index) 8)
      (set-vector! (-> v1-27 local-sphere) -4096.0 12288.0 0.0 3686.4)
      )
    (let ((v1-29 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-29 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-29 prim-core collide-with) (collide-spec jak bot hit-by-others-list player-list pusher))
      (set! (-> v1-29 prim-core action) (collide-action semi-solid))
      (set! (-> v1-29 transform-index) 8)
      (set-vector! (-> v1-29 local-sphere) -3276.8 20480.0 0.0 2457.6)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-32 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-32 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-32 prim-core collide-with))
      )
    (set! (-> s5-0 event-other) 'centipede)
    (set! (-> this root) s5-0)
    )
  (none)
  )

(defmethod init-enemy! ((this centipede))
  "Common method called to initialize the enemy, typically sets up default field values and calls ancillary helper methods"
  (set! (-> this id) (res-lump-value (-> this entity) 'extra-id int :time -1000000000.0))
  (set! (-> this cam init?) #t)
  (set! (-> this using-chan1-effects?) #f)
  (set! (-> this set-camera-mode?) #f)
  (set! (-> this focus-gnd-height) -40959590.0)
  (set! (-> this bobbing-intensity) 1.0)
  (set-vector! (-> this root scale) 0.75 0.75 0.75 1.0)
  (+! (-> this root trans y) 4096.0)
  (case (-> this id)
    ((1)
     (let ((v1-10 (-> this root)))
       (set-vector! (-> v1-10 quat) -0.2103 -0.2293 -0.0508 0.949)
       (set! (-> v1-10 trans x) -248325.33)
       (set! (-> v1-10 trans z) 8201697.0)
       )
     (set! (-> *centipede-nav-enemy-info* run-travel-speed) 32768.0)
     )
    ((2)
     (let ((v1-16 (-> this root)))
       (set-vector! (-> v1-16 quat) -0.1832 0.519 0.115 0.827)
       (set! (-> v1-16 trans x) -1001253.25)
       (set! (-> v1-16 trans z) 7913366.5)
       )
     (set! (-> *centipede-nav-enemy-info* run-travel-speed) 30720.0)
     )
    )
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-centipede" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (set! (-> this skel generate-frame-function) create-interpolated2-joint-animation-frame)
  (init-enemy-behaviour-and-stats! this *centipede-nav-enemy-info*)
  (logclear! (-> this mask) (process-mask enemy))
  (logior! (-> this mask) (process-mask bot))
  (let ((v1-31 (-> this nav)))
    (set! (-> v1-31 sphere-mask) (the-as uint 64))
    )
  0
  (logclear! (-> this root nav-flags) (nav-flags has-root-sphere has-extra-sphere))
  (let ((v1-35 (-> this nav)))
    (set! (-> v1-35 speed-scale) 1.0)
    )
  0
  (set-gravity-length (-> this root dynam) 573440.0)
  (logclear! (-> this enemy-flags) (enemy-flag vulnerable vulnerable-backup))
  (set! (-> this bobbing) (the-as trsqv (new 'process 'joint-mod-set-world this 3 #t)))
  (set! (-> this sound)
        (new 'process 'ambient-sound (static-sound-spec "cent-talk" :fo-max 90) (-> this root trans))
        )
  (update-vol! (-> this sound) 0.0)
  (set! (-> this talking-volume) 0.0)
  (set! (-> this desired-talking-volume) 0.0)
  (set! (-> this legs-sound)
        (new 'process 'ambient-sound (static-sound-spec "cent-legs-loop" :fo-max 90) (-> this root trans))
        )
  (update-vol! (-> this sound) 0.0)
  (set! (-> this legs-volume) 0.0)
  0
  (none)
  )
