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

;; name: metalhead-flitter.gc
;; name in dgo: metalhead-flitter
;; dgos: CWI

;; DECOMP BEGINS

(defskelgroup skel-mh-flitter city-flitter city-flitter-lod0-jg -1
              ((city-flitter-lod0-mg (meters 20)) (city-flitter-lod1-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 5.5)
              :shadow city-flitter-shadow-mg
              :origin-joint-index 3
              )

(deftype metalhead-flitter (mh-squad-member)
  ((move-angle        float)
   (heading           symbol)
   (change-dir-time   time-frame)
   (last-change-dir   time-frame)
   (off-screen-timer  time-frame)
   (amb-sound-timer   time-frame)
   (attack-time       time-frame)
   (target-pos        vector  :inline)
   (attack-pos        vector  :inline)
   (base-height       float)
   )
  (:state-methods
    attack
    ambush-jumping
    )
  (:methods
    (metalhead-flitter-method-224 (_type_) none)
    (metalhead-flitter-method-225 (_type_) none)
    (metalhead-flitter-method-226 (_type_ process-focusable) symbol)
    (metalhead-flitter-method-227 (_type_ symbol) none)
    (metalhead-flitter-method-228 (_type_) float)
    )
  )


(define *fact-info-mh-flitter-defaults*
  (new 'static 'fact-info-enemy-defaults :idle-distance (meters 80) :pickup-type 4)
  )

(define *metalhead-flitter-nav-enemy-info*
  (new 'static 'nav-enemy-info
    :use-die-falling #t
    :use-victory #f
    :use-jump-blocked #f
    :debug-draw-neck #f
    :jump-debug-draw #f
    :move-to-ground #t
    :hover-if-no-ground #f
    :idle-anim-script (new 'static 'inline-array idle-control-frame 3
      (new 'static 'idle-control-frame :command (idle-control-cmd push) :param0 30)
      (new 'static 'idle-control-frame
        :command (idle-control-cmd play)
        :anim #x4
        :param0 3
        :param1 6
        :param2 '((new 'static 'bfloat :data 1.0) (new 'static 'bfloat :data 1.0))
        )
      (new 'static 'idle-control-frame)
      )
    :idle-anim 4
    :notice-anim 4
    :hostile-anim 8
    :hit-anim 4
    :knocked-anim 14
    :knocked-land-anim 15
    :die-anim 13
    :die-falling-anim 12
    :victory-anim 4
    :jump-wind-up-anim 4
    :jump-in-air-anim 4
    :jump-land-anim 4
    :neck-joint -1
    :look-at-joint 28
    :bullseye-joint 3
    :sound-hit (static-sound-name "mh-flitter-hit")
    :sound-die (static-sound-name "mh-flitter-die")
    :notice-distance (meters 40)
    :notice-distance-delta (meters 10)
    :proximity-notice-distance (meters 20)
    :default-hit-points 1.0
    :gnd-collide-with (collide-spec backgnd)
    :overlaps-others-collide-with-filter (collide-spec jak civilian enemy vehicle-sphere hit-by-others-list player-list)
    :penetrate-knocked (penetrate
      generic-attack
      flop
      punch
      spin
      roll
      uppercut
      bonk
      tube
      flut-attack
      board
      mech-punch
      mech-bonk
      dark-skin
      dark-punch
      dark-bomb
      dark-smack
      flut
      shield
      explode
      jak-yellow-shot
      jak-red-shot
      jak-blue-shot
      jak-dark-shot
      enemy-yellow-shot
      enemy-dark-shot
      eco-yellow
      knocked
      )
    :movement-gravity (meters -100)
    :friction 0.8
    :attack-shove-back (meters 6)
    :attack-shove-up (meters 3)
    :attack-mode 'generic
    :attack-damage 1
    :recover-gnd-collide-with (collide-spec backgnd crate obstacle hit-by-others-list pusher)
    :knocked-can-land-timeout (seconds 0.1)
    :knocked-recover-timeout (seconds 2)
    :ragdoll-blend-out-time (seconds 0.25)
    :ragdoll-rotate-velocity-mult 1.0
    :jump-height-min (meters 3)
    :jump-height-factor 0.5
    :knocked-seek-ry-clamp 2730.6667
    :knocked-soft-vxz-lo (meters 17.6)
    :knocked-soft-vxz-hi (meters 26.4)
    :knocked-soft-vy-lo (meters 20)
    :knocked-soft-vy-hi (meters 30)
    :knocked-medium-vxz-lo (meters 36)
    :knocked-medium-vxz-hi (meters 48)
    :knocked-medium-vy-lo (meters 33)
    :knocked-medium-vy-hi (meters 37)
    :knocked-hard-vxz-lo (meters 19.2)
    :knocked-hard-vxz-hi (meters 28.8)
    :knocked-hard-vy-lo (meters 44.8)
    :knocked-hard-vy-hi (meters 67.2)
    :knocked-huge-vxz-lo (meters 40.2)
    :knocked-huge-vxz-hi (meters 60.8)
    :knocked-huge-vy-lo (meters 44.8)
    :knocked-huge-vy-hi (meters 53.2)
    :knocked-yellow-vxz-lo (meters 10)
    :knocked-yellow-vxz-hi (meters 12)
    :knocked-yellow-vy-lo (meters 14)
    :knocked-yellow-vy-hi (meters 20)
    :knocked-red-vxz-lo (meters 6)
    :knocked-red-vxz-hi (meters 48)
    :knocked-red-vy-lo (meters 23)
    :knocked-red-vy-hi (meters 37)
    :knocked-blue-vxz-lo (meters 10)
    :knocked-blue-vxz-hi (meters 12)
    :knocked-blue-vy-lo (meters 6)
    :knocked-blue-vy-hi (meters 20)
    :ragdoll-info #f
    :shadow-size (meters 2)
    :shadow-max-y (meters 1)
    :shadow-min-y (meters -1)
    :shadow-locus-dist (meters 150)
    :gem-joint 28
    :gem-seg #x2
    :gem-no-seg #x4
    :gem-offset (new 'static 'sphere :y 696.32 :z 1843.2 :r 163840.0)
    :knocked-off #t
    :callback-info #f
    :use-momentum #f
    :use-frustration #t
    :use-stop-chase #f
    :use-circling #f
    :use-pacing #f
    :walk-anim 7
    :turn-anim 9
    :run-anim 8
    :taunt-anim -1
    :run-travel-speed (meters 12)
    :run-acceleration (meters 8)
    :run-turning-acceleration (meters 120)
    :walk-travel-speed (meters 4)
    :walk-acceleration (meters 1)
    :walk-turning-acceleration (meters 5)
    :maximum-rotation-rate (degrees 720)
    :notice-nav-radius (meters 5)
    :frustration-distance (meters 12)
    :frustration-time (seconds 4)
    :blocked-time (seconds 0.3)
    :circle-dist-lo 20480.0
    :circle-dist-hi 61440.0
    :nav-mesh #f
    )
  )

(set! (-> *metalhead-flitter-nav-enemy-info* fact-defaults) *fact-info-mh-flitter-defaults*)

(defmethod metalhead-flitter-method-226 ((this metalhead-flitter) (arg0 process-focusable))
  (and (logtest? (-> this draw status) (draw-control-status on-screen))
       (let ((s4-0 (camera-matrix)))
         (camera-pos)
         (let* ((s3-0 (get-trans arg0 0))
                (s5-1 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> s4-0 fvec) 1.0))
                (v1-7 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> this root trans) s3-0) 1.0))
                )
           (< 0.0 (vector-dot s5-1 v1-7))
           )
         )
       )
  )

(defmethod knocked-anim ((this metalhead-flitter) (arg0 enemy-knocked-info))
  "start the knocked animation."
  (case (-> this incoming knocked-type)
    (((knocked-type yellow-shot))
     (let ((a0-2 (-> this skel root-channel 0)))
       (set! (-> a0-2 frame-group) (the-as art-joint-anim (-> this draw art-group data 14)))
       (set! (-> a0-2 param 0)
             (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 14)) frames num-frames) -1))
             )
       (set! (-> a0-2 param 1) (-> arg0 anim-speed))
       (set! (-> a0-2 frame-num) 0.0)
       (joint-control-channel-group! a0-2 (the-as art-joint-anim (-> this draw art-group data 14)) num-func-seek!)
       )
     #t
     )
    (((knocked-type blue-shot))
     (let ((v1-17 (if (> (-> this skel active-channels) 0)
                      (-> this skel root-channel 0 frame-group)
                      )
                  )
           )
       (if (and v1-17 (= v1-17 (-> this draw art-group data 15)))
           (ja-channel-push! 1 (seconds 0.17))
           (ja-channel-push! 1 (seconds 0.02))
           )
       )
     (let ((a0-10 (-> this skel root-channel 0)))
       (set! (-> a0-10 frame-group) (the-as art-joint-anim (-> this draw art-group data 17)))
       (set! (-> a0-10 param 0)
             (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 17)) frames num-frames) -1))
             )
       (set! (-> a0-10 param 1) 1.0)
       (set! (-> a0-10 frame-num) 0.0)
       (joint-control-channel-group! a0-10 (the-as art-joint-anim (-> this draw art-group data 17)) num-func-seek!)
       )
     #t
     )
    (else
      ((method-of-type nav-enemy knocked-anim) this arg0)
      )
    )
  )

(defmethod knocked-land-anim ((this metalhead-flitter) (arg0 enemy-knocked-info))
  "start the knocked-land animation."
  (case (-> this incoming knocked-type)
    (((knocked-type blue-shot))
     (when (>= (-> this incoming blue-juggle-count) (the-as uint 2))
       (let ((v1-4 (-> this skel root-channel 0)))
         (set! (-> v1-4 frame-group) (the-as art-joint-anim (-> this draw art-group data 16)))
         (set! (-> v1-4 param 0)
               (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 16)) frames num-frames) -1))
               )
         (set! (-> v1-4 param 1) 1.0)
         (set! (-> v1-4 frame-num) 0.0)
         (joint-control-channel-group! v1-4 (the-as art-joint-anim (-> this draw art-group data 16)) num-func-seek!)
         )
       #t
       )
     )
    (else
      ((method-of-type mh-squad-member knocked-land-anim) this arg0)
      )
    )
  )

(defmethod go-stare2 ((this metalhead-flitter))
  (if (and (= (-> this focus aware) (enemy-aware aware2)) (not (nav-enemy-method-174 this)))
      (go (method-of-object this pacing))
      (go (method-of-object this stare))
      )
  )

(defstate ambush (metalhead-flitter)
  :virtual #t
  :enter (behavior ()
    (when (logtest? (-> self enemy-flags) (enemy-flag enable-on-notice))
      (logclear! (-> self enemy-flags) (enemy-flag enable-on-notice))
      (let ((gp-0 (-> self on-notice)))
        (if gp-0
            (script-eval gp-0 :vector (-> self root trans))
            )
        )
      )
    (set! (-> self base-height) (-> self root trans y))
    (let ((v1-13 (-> self root root-prim)))
      (set! (-> v1-13 prim-core collide-as) (collide-spec))
      (set! (-> v1-13 prim-core collide-with) (collide-spec))
      )
    0
    (let ((a0-4 (the-as process-focusable (handle->process (-> self focus handle)))))
      (when a0-4
        (let* ((gp-1 (-> self root))
               (s3-0 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (get-trans a0-4 0) (-> gp-1 trans)) 1.0))
               (f0-1 (deg-diff (quaternion-y-angle (-> gp-1 quat)) (vector-y-angle s3-0)))
               )
          (quaternion-rotate-y! (-> gp-1 quat) (-> gp-1 quat) f0-1)
          )
        )
      )
    )
  :code (behavior ()
    (case (-> self level name)
      (('ruins)
       (cond
         ((logtest? (-> *part-group-id-table* 255 flags) (sp-group-flag sp13))
          (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
          (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group (-> *part-group-id-table* 255))
          )
         (else
           (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
           (part-tracker-spawn part-tracker :to *entity-pool* :group (-> *part-group-id-table* 255))
           )
         )
       )
      (('strip)
       (cond
         ((logtest? (-> *part-group-id-table* 256 flags) (sp-group-flag sp13))
          (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
          (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group (-> *part-group-id-table* 256))
          )
         (else
           (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
           (part-tracker-spawn part-tracker :to *entity-pool* :group (-> *part-group-id-table* 256))
           )
         )
       )
      )
    (suspend-for (seconds 0.6)
      )
    (+! (-> self root trans y) -8192.0)
    (logior! (-> self draw status) (draw-control-status no-draw))
    (suspend-for (the int (* 300.0 (rnd-float-range self 0.0 0.6)))
      )
    (logclear! (-> self draw status) (draw-control-status no-draw))
    (go-virtual ambush-jumping)
    )
  )

(defstate ambush-jumping (metalhead-flitter)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (let ((v1-0 self))
      (if (not (logtest? (enemy-flag ef37) (-> v1-0 enemy-flags)))
          (set! (-> v1-0 enemy-flags) (the-as enemy-flag (logior (enemy-flag ef39) (-> v1-0 enemy-flags))))
          )
      (set! (-> v1-0 enemy-flags) (the-as enemy-flag (logior (enemy-flag ef37) (-> v1-0 enemy-flags))))
      (set! (-> v1-0 nav callback-info) (-> v1-0 enemy-info callback-info))
      )
    0
    (let ((v1-3 self))
      (set! (-> v1-3 enemy-flags) (the-as enemy-flag (logior (enemy-flag ef38) (-> v1-3 enemy-flags))))
      )
    0
    (set-look-at-mode! self 1)
    (set-time! (-> self state-time))
    (let ((gp-0 (-> self root)))
      (vector-reset! (-> gp-0 transv))
      (set! (-> gp-0 transv y) (* 4096.0 (rnd-float-range self 34.0 38.0)))
      )
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.1))
    (ja-no-eval :group! (-> self draw art-group data 5) :num! (seek!))
    (until #f
      (when (< (-> self base-height) (-> self root trans y))
        (cond
          ((logtest? (-> group-flitter-dust-puff flags) (sp-group-flag sp13))
           (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
           (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-flitter-dust-puff)
           )
          (else
            (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
            (part-tracker-spawn part-tracker :to *entity-pool* :group group-flitter-dust-puff)
            )
          )
        (goto cfg-14)
        )
      (suspend)
      (ja :num! (seek!))
      )
    #f
    (until #f
      (when (< (+ 204.8 (-> self base-height)) (-> self root trans y))
        (let ((v1-64 (-> self root root-prim)))
          (set! (-> v1-64 prim-core collide-as) (-> self root backup-collide-as))
          (set! (-> v1-64 prim-core collide-with) (-> self root backup-collide-with))
          )
        (goto cfg-15)
        )
      (label cfg-14)
      (suspend)
      (ja :num! (seek!))
      )
    #f
    (until #f
      (label cfg-15)
      (if (or (and (>= 0.0 (-> self root transv y)) (>= (+ 1638.4 (-> self base-height)) (-> self root trans y)))
              (logtest? (-> self root status) (collide-status on-ground))
              )
          (goto cfg-30)
          )
      (suspend)
      (if (not (ja-done? 0))
          (ja :num! (seek!))
          )
      )
    #f
    (label cfg-30)
    (ja-no-eval :group! (-> self draw art-group data 6) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (until #f
      (if (logtest? (-> self root status) (collide-status on-ground))
          (goto cfg-37)
          )
      (suspend)
      )
    #f
    (label cfg-37)
    (go-virtual hostile)
    )
  :post nav-enemy-falling-post
  )

(defmethod should-flee-from? ((this metalhead-flitter) (arg0 process-focusable))
  "Return if this enemy should flee from the process."
  (focus-test? arg0 mech)
  )

(defmethod metalhead-flitter-method-224 ((this metalhead-flitter))
  (let ((s3-0 (as-type (handle->process (-> this focus handle)) process-focusable)))
    (when s3-0
      (let* ((s5-1 (get-trans s3-0 0))
             (s4-1 (vector-! (new 'stack-no-clear 'vector) s5-1 (-> this root trans)))
             (f30-0 (vector-length s4-1))
             )
        (cond
          ((should-flee-from? this s3-0)
           (go-flee this)
           )
          ((and (< f30-0 32768.0) (not (metalhead-flitter-method-226 this s3-0)))
           (go (method-of-object this circling))
           )
          ((and (< f30-0 (-> this enemy-info notice-nav-radius)) (time-elapsed? (-> this state-time) (seconds 0.2)))
           (vector-copy! (-> this target-pos) s5-1)
           (let ((s3-1 (new 'stack-no-clear 'vector)))
             (vector-copy! s3-1 s4-1)
             (let ((s5-2 (new 'stack-no-clear 'vector)))
               (vector-copy! s5-2 (-> this root transv))
               (vector-normalize! s5-2 f30-0)
               (if (>= (vector-dot s3-1 s5-2) 0.98)
                   (go (method-of-object this attack))
                   )
               )
             )
           )
          ((< f30-0 32768.0)
           (vector-copy! (-> this target-pos) s5-1)
           )
          ((or (time-elapsed? (-> this last-change-dir) (-> this change-dir-time))
               (< (vector-vector-distance-squared (-> this root trans) (-> this target-pos)) 0.1)
               )
           (set-time! (-> this last-change-dir))
           (set! (-> this change-dir-time) (rand-vu-int-range (seconds 0.5) (seconds 0.7)))
           (let ((s3-2 (new 'stack-no-clear 'vector))
                 (f0-9 (* (/ f30-0 2) (tan (-> this move-angle))))
                 (s2-0 (new 'stack-no-clear 'vector))
                 )
             (if (-> this heading)
                 (set-vector! s3-2 (-> s4-1 z) (-> s4-1 y) (- (-> s4-1 x)) 1.0)
                 (set-vector! s3-2 (- (-> s4-1 z)) (-> s4-1 y) (-> s4-1 x) 1.0)
                 )
             (set! (-> this heading) (not (-> this heading)))
             (let ((f28-1 (rand-vu-float-range (* 0.75 f0-9) f0-9))
                   (s4-2 (vector-normalize-copy! (new 'stack-no-clear 'vector) s4-1 (* -0.6 f30-0)))
                   )
               (vector-normalize! s3-2 f28-1)
               (vector+! s3-2 s3-2 s4-2)
               )
             (clamp-vector-to-mesh-cross-gaps (-> this nav state) s3-2)
             (vector+! s2-0 s5-1 s3-2)
             (vector-copy! (-> this target-pos) s2-0)
             )
           )
          )
        )
      0
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch time-frame vs none.
(defmethod metalhead-flitter-method-225 ((this metalhead-flitter))
  (when (time-elapsed? (-> this amb-sound-timer) (the int (* 300.0 (rand-vu-float-range 1.5 3.0))))
    (sound-play "flitter-amb" :position (-> this root trans))
    (set-time! (-> this amb-sound-timer))
    )
  (none)
  )

(defbehavior metalhead-flitter-fall-and-play-death-anim metalhead-flitter ((arg0 int) (arg1 float) (arg2 time-frame))
  (local-vars (v1-29 symbol))
  (stop-look-at! self)
  (set! (-> self skel root-channel 0 frame-group) (the-as art-joint-anim arg0))
  (let ((s4-1 (get-knockback-dir! self (new 'stack-no-clear 'vector))))
    (when (as-type (-> self root) collide-shape-moving)
      (set! (-> self root transv y) 33775.48)
      (ja :num-func num-func-identity :frame-num 0.0)
      (set-time! (-> self state-time))
      (logclear! (-> self root status) (collide-status on-surface on-ground touch-surface))
      (until v1-29
        (let ((f0-2 102400.0))
          (set! (-> self root transv x) (* (-> s4-1 x) f0-2))
          (set! (-> self root transv z) (* (-> s4-1 z) f0-2))
          )
        (suspend)
        (ja :num! (seek! max arg1))
        (set! v1-29 (or (ja-done? 0) (time-elapsed? (-> self state-time) arg2)))
        )
      )
    )
  0
  (none)
  )

(defstate active (metalhead-flitter)
  :virtual #t
  :post (behavior ()
    (metalhead-flitter-method-225 self)
    (let ((t9-1 (-> (method-of-type mh-squad-member active) post)))
      (if t9-1
          ((the-as (function none) t9-1))
          )
      )
    )
  )

(defstate stare (metalhead-flitter)
  :virtual #t
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.1))
    (let ((f30-0 (rnd-float-range self 0.8 1.2)))
      (until #f
        (when (not (pointing-toward-focus? self 2730.6667 #t))
          (let ((v1-5 self))
            (set! (-> v1-5 enemy-flags) (the-as enemy-flag (logior (enemy-flag ef38) (-> v1-5 enemy-flags))))
            )
          0
          (ja-no-eval :num! (loop!))
          (ja-channel-push! 1 (seconds 0.2))
          (ja :group! (-> self draw art-group data 9))
          (ja :num-func num-func-identity :frame-num 0.0)
          (until (pointing-toward-focus? self 1820.4445 #t)
            (ja-blend-eval)
            (suspend)
            (ja :num! (loop! 0.75))
            )
          (let ((v1-25 self))
            (set! (-> v1-25 enemy-flags) (the-as enemy-flag (logclear (-> v1-25 enemy-flags) (enemy-flag ef38))))
            )
          0
          )
        (let ((v1-29 (ja-group)))
          (if (not (and v1-29 (= v1-29 (-> self draw art-group data (-> self enemy-info idle-anim)))))
              (ja-channel-push! 1 (seconds 0.2))
              )
          )
        (ja-no-eval :group! (-> self draw art-group data (-> self enemy-info idle-anim))
                    :num! (seek! max f30-0)
                    :frame-num 0.0
                    )
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek! max f30-0))
          )
        )
      )
    #f
    )
  :post (behavior ()
    (metalhead-flitter-method-225 self)
    (let ((t9-1 (-> (method-of-type mh-squad-member stare) post)))
      (if t9-1
          ((the-as (function none) t9-1))
          )
      )
    )
  )

(defstate hostile (metalhead-flitter)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self last-change-dir))
    (set! (-> self change-dir-time) 0)
    (set! (-> self attack-time) (+ (current-time) (seconds 0.35)))
    (let ((t9-0 (-> (method-of-type mh-squad-member hostile) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (nav-enemy-method-177 self)
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (let ((t9-0 (-> (method-of-type mh-squad-member hostile) trans)))
      (if t9-0
          (t9-0)
          )
      )
    (metalhead-flitter-method-224 self)
    )
  :post (behavior ()
    (let ((a0-0 (-> self nav state))
          (v1-1 (-> self target-pos))
          )
      (logclear! (-> a0-0 flags) (nav-state-flag directional-mode))
      (logior! (-> a0-0 flags) (nav-state-flag target-poly-dirty))
      (vector-copy! (-> a0-0 target-pos) v1-1)
      )
    0
    (nav-enemy-travel-post)
    )
  )

(defstate die (metalhead-flitter)
  :virtual #t
  :enter (behavior ()
    (sound-play "flitter-die")
    (let ((t9-2 (-> (method-of-type mh-squad-member die) enter)))
      (if t9-2
          (t9-2)
          )
      )
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (metalhead-flitter-fall-and-play-death-anim
      (the-as int (-> self draw art-group data (-> self enemy-info die-anim)))
      1.0
      (seconds 2)
      )
    (send-event self 'death-end)
    (cleanup-for-death self)
    )
  )

(defmethod metalhead-flitter-method-228 ((this metalhead-flitter))
  (lerp-scale 0.0 1.0 (- (-> this attack-pos y) (-> this root trans y)) 13926.4 25600.0)
  )

(defstate attack (metalhead-flitter)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (if (not (logtest? (enemy-flag ef37) (-> v1-2 enemy-flags)))
          (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logior (enemy-flag ef39) (-> v1-2 enemy-flags))))
          )
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logior (enemy-flag ef37) (-> v1-2 enemy-flags))))
      (set! (-> v1-2 nav callback-info) (-> v1-2 enemy-info callback-info))
      )
    0
    (set! (-> self amb-sound-timer) 0)
    (logior! (-> self focus-status) (focus-status dangerous))
    (let* ((v1-7 *game-info*)
           (a0-13 (+ (-> v1-7 attack-id) 1))
           )
      (set! (-> v1-7 attack-id) a0-13)
      (set! (-> self attack-id) a0-13)
      )
    (metalhead-flitter-method-227 self #t)
    )
  :exit (behavior ()
    (metalhead-flitter-method-227 self #f)
    (logclear! (-> self focus-status) (focus-status dangerous))
    )
  :trans (behavior ()
    (local-vars (s5-2 object))
    (let ((gp-0 (as-type (handle->process (-> self focus handle)) process-focusable)))
      (set! s5-2 (cond
                   ((and gp-0
                         (not (time-elapsed? (-> self state-time) (seconds 1.5)))
                         gp-0
                         (not (logtest? (-> gp-0 focus-status) (focus-status disable dead ignore grabbed)))
                         )
                    (let ((s5-1 (-> self nav state))
                          (v1-10 (get-trans gp-0 0))
                          )
                      (logclear! (-> s5-1 flags) (nav-state-flag directional-mode))
                      (logior! (-> s5-1 flags) (nav-state-flag target-poly-dirty))
                      (vector-copy! (-> s5-1 target-pos) v1-10)
                      )
                    0
                    (set! s5-2 (-> self attack-pos))
                    (set! (-> (the-as vector s5-2) quad) (-> (get-trans gp-0 3) quad))
                    s5-2
                    )
                   (else
                     (go-stare self)
                     )
                   )
            )
      )
    )
  :code (behavior ()
    (sound-play "flitter-attack")
    (ja-channel-push! 2 (seconds 0.1))
    (let ((f30-0 (metalhead-flitter-method-228 self)))
      (ja-no-eval :group! (-> self draw art-group data 10) :num! (seek! max 0.8) :frame-num 0.0)
      (ja-no-eval :chan 1
                  :group! (-> self draw art-group data 11)
                  :num! (chan 0)
                  :frame-interp0 f30-0
                  :frame-interp1 f30-0
                  :frame-num 0.0
                  )
      (until (ja-done? 0)
        (suspend)
        (set! f30-0 (seek f30-0 (metalhead-flitter-method-228 self) (* 0.2 (seconds-per-frame))))
        (ja :num! (seek! max 0.8))
        (ja :chan 1 :num! (chan 0) :frame-interp0 f30-0 :frame-interp1 f30-0)
        )
      )
    (let ((v1-41 self))
      (set! (-> v1-41 enemy-flags) (the-as enemy-flag (logclear (-> v1-41 enemy-flags) (enemy-flag ef37))))
      (set! (-> v1-41 nav callback-info) *null-nav-callback-info*)
      )
    0
    (ja-channel-push! 1 (seconds 0.1))
    (metalhead-flitter-method-227 self #f)
    (logclear! (-> self focus-status) (focus-status dangerous))
    (dotimes (gp-2 (rnd-int self 3))
      (ja-no-eval :group! (-> self draw art-group data 4) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (go-state-for-focused self)
    )
  :post nav-enemy-travel-post
  )

(defstate victory (metalhead-flitter)
  :virtual #t
  :post (behavior ()
    (metalhead-flitter-method-225 self)
    (nav-enemy-simple-post)
    )
  )

(defstate stare (metalhead-flitter)
  :virtual #t
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.1))
    (let ((f30-0 (rnd-float-range self 0.8 1.2)))
      (until #f
        (when (not (pointing-toward-focus? self 2730.6667 #t))
          (let ((v1-5 self))
            (set! (-> v1-5 enemy-flags) (the-as enemy-flag (logior (enemy-flag ef38) (-> v1-5 enemy-flags))))
            )
          0
          (ja-no-eval :num! (loop!))
          (ja-channel-push! 1 (seconds 0.2))
          (ja :group! (-> self draw art-group data 9))
          (ja :num-func num-func-identity :frame-num 0.0)
          (until (pointing-toward-focus? self 1820.4445 #t)
            (ja-blend-eval)
            (suspend)
            (ja :num! (loop! 0.75))
            )
          (let ((v1-25 self))
            (set! (-> v1-25 enemy-flags) (the-as enemy-flag (logclear (-> v1-25 enemy-flags) (enemy-flag ef38))))
            )
          0
          )
        (let ((v1-29 (ja-group)))
          (if (not (and v1-29 (= v1-29 (-> self draw art-group data (-> self enemy-info idle-anim)))))
              (ja-channel-push! 1 (seconds 0.2))
              )
          )
        (ja-no-eval :group! (-> self draw art-group data (-> self enemy-info idle-anim))
                    :num! (seek! max f30-0)
                    :frame-num 0.0
                    )
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek! max f30-0))
          )
        )
      )
    #f
    )
  :post (behavior ()
    (metalhead-flitter-method-225 self)
    (let ((t9-1 (-> (method-of-type nav-enemy stare) post)))
      (if t9-1
          ((the-as (function none) t9-1))
          )
      )
    )
  )

(defstate circling (metalhead-flitter)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type nav-enemy circling) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set-time! (-> self off-screen-timer))
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (let ((gp-0 (handle->process (-> self focus handle))))
      (if (the-as process-focusable gp-0)
          (vector-copy! (-> self focus-pos) (get-trans (the-as process-focusable gp-0) 0))
          )
      (when (time-elapsed? (-> self state-time) (seconds 0.1))
        (let ((v1-11 (-> self focus aware)))
          (cond
            ((= v1-11 (enemy-aware hostile))
             (cond
               ((if gp-0
                    (metalhead-flitter-method-226
                      self
                      (the-as process-focusable (as-type (handle->process (-> self focus handle)) process-focusable))
                      )
                    )
                (if (and (get-focus! self) (time-elapsed? (-> self off-screen-timer) (seconds 0.3)))
                    (go-hostile self)
                    )
                )
               (else
                 (set-time! (-> self off-screen-timer))
                 )
               )
             )
            ((= v1-11 (enemy-aware aware2))
             (go-stare self)
             )
            ((>= 1 (the-as int v1-11))
             (go-virtual active)
             )
            )
          )
        (if (or (nav-enemy-method-174 self) (logtest? (enemy-flag ef42) (-> self enemy-flags)))
            (go-stare2 self)
            )
        )
      )
    )
  :code (behavior ()
    (nav-enemy-method-177 self)
    (ja-channel-push! 1 (seconds 0.2))
    (until #f
      (ja-no-eval :group! (-> self draw art-group data (-> self enemy-info run-anim))
                  :num! (seek! max (rnd-float-range self 0.9 1.1))
                  :frame-num 0.0
                  )
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek! max (rnd-float-range self 0.9 1.1)))
        )
      )
    #f
    )
  )

(defmethod metalhead-flitter-method-227 ((this metalhead-flitter) (arg0 symbol))
  (let ((v1-1 (-> this root root-prim)))
    (dotimes (a0-1 (the-as int (-> v1-1 specific 0)))
      (let ((a2-1 (-> (the-as collide-shape-prim-group v1-1) child a0-1)))
        (if arg0
            (logior! (-> a2-1 prim-core action) (collide-action deadly))
            (logclear! (-> a2-1 prim-core action) (collide-action deadly))
            )
        )
      )
    )
  0
  (none)
  )

(defmethod init-enemy-collision! ((this metalhead-flitter))
  "Typical place to construct collision shapes"
  (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 3) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 4))
      (set! (-> s4-0 prim-core collide-as) (collide-spec enemy))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec backgnd jak bot crate civilian enemy obstacle hit-by-others-list player-list)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid can-ride deadly no-standon))
      (set-vector! (-> s4-0 local-sphere) 0.0 10240.0 0.0 15360.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-12 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-12 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-12 prim-core collide-with)
            (collide-spec backgnd jak bot crate obstacle hit-by-others-list player-list)
            )
      (set! (-> v1-12 prim-core action) (collide-action solid can-ride deadly no-standon))
      (set-vector! (-> v1-12 local-sphere) 0.0 5734.4 0.0 5734.4)
      )
    (let ((v1-14 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-14 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-14 prim-core collide-with) (collide-spec jak bot crate civilian hit-by-others-list player-list))
      (set! (-> v1-14 prim-core action) (collide-action deadly))
      (set! (-> v1-14 transform-index) 34)
      (set-vector! (-> v1-14 local-sphere) 0.0 0.0 0.0 3481.6)
      )
    (let ((v1-16 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-16 prim-core collide-as) (collide-spec enemy))
      (set! (-> v1-16 prim-core collide-with) (collide-spec jak bot crate civilian hit-by-others-list player-list))
      (set! (-> v1-16 prim-core action) (collide-action deadly))
      (set! (-> v1-16 transform-index) 35)
      (set-vector! (-> v1-16 local-sphere) 0.0 0.0 0.0 3481.6)
      )
    (set! (-> s5-0 nav-radius) 3686.4)
    (let ((v1-18 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-18 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-18 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 3))
    (set! (-> s5-0 event-priority) (the-as uint 8))
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod init-enemy! ((this metalhead-flitter))
  "Typical place for shared init code. Runs from entity or process style init."
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-mh-flitter" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (setup-enemy! this *metalhead-flitter-nav-enemy-info*)
  (set! (-> this move-angle) 10922.667)
  (set! (-> this heading) (if (= (rand-vu-int-range 0 1) 1)
                              #t
                              #f
                              )
        )
  (set! (-> this change-dir-time) 0)
  (set! (-> this off-screen-timer) 0)
  (set! (-> this amb-sound-timer) 0)
  (set-gravity-length (-> this root dynam) 491520.0)
  (set! (-> this minimap) #f)
  (set! (-> this water-anim) 8)
  (none)
  )

(defmethod citizen-method-194 ((this metalhead-flitter))
  (let ((t9-0 (method-of-type mh-squad-member citizen-method-194)))
    (t9-0 this)
    )
  (add-connection
    *part-engine*
    this
    28
    this
    468
    (new 'static 'vector :x 942.08 :y -860.16 :z 1269.76 :w 163840.0)
    )
  (add-connection
    *part-engine*
    this
    28
    this
    468
    (new 'static 'vector :x -942.08 :y -860.16 :z 1269.76 :w 163840.0)
    )
  (set! (-> this speed-walk) (-> this enemy-info walk-travel-speed))
  (set! (-> this dist-walk-anim) (-> this enemy-info walk-travel-speed))
  (set! (-> this dist-run-anim) (-> this enemy-info run-travel-speed))
  0
  (none)
  )

(defmethod citizen-method-215 ((this metalhead-flitter))
  (when (nonzero? *cty-attack-controller*)
    (set! (-> this mission-squad) *cty-attack-controller*)
    (when (not (-> this attacker-info))
      (set! (-> this attacker-info) (allocate-attacker (-> this mission-squad)))
      (init! (-> this attacker-info) this 7)
      )
    )
  (none)
  )

(defstate in-ditch (metalhead-flitter)
  :virtual #t
  :enter (behavior ()
    (go-inactive self)
    )
  )

(defstate die-fast (metalhead-flitter)
  :virtual #t
  :enter (behavior ()
    (go-inactive self)
    )
  )
