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

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

;; DECOMP BEGINS

(deftype metalhead-predator-shot (metalhead-shot)
  ()
  )


;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this metalhead-predator-shot) (arg0 projectile-options))
  (case arg0
    (((projectile-options lose-altitude))
     (sound-play "pred-shot-hit")
     )
    (((projectile-options lose-altitude proj-options-2))
     (let ((f0-0 (doppler-pitch-shift (-> this root trans) (-> this root transv)))
           (a0-8 (static-sound-spec "pred-shot-loop" :volume 0.0 :mask (pitch reg0)))
           )
       (set! (-> a0-8 volume) 1024)
       (set! (-> a0-8 pitch-mod) (the int (* 1524.0 f0-0)))
       (sound-play-by-spec a0-8 (-> this sound-id) (-> this root trans))
       )
     )
    )
  (none)
  )

(defmethod init-proj-collision! ((this metalhead-predator-shot))
  "Init the [[projectile]]'s [[collide-shape]]"
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction)
          (the-as (function control-info collide-query vector vector collide-status) cshape-reaction-just-move)
          )
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate jak-yellow-shot))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 3))
      (set! (-> s4-0 prim-core collide-as) (collide-spec projectile))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec backgnd jak bot crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 2457.6)
      (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 projectile))
      (set! (-> v1-13 prim-core collide-with)
            (collide-spec backgnd jak bot crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list)
            )
      (set! (-> v1-13 prim-core action) (collide-action solid deadly))
      (set-vector! (-> v1-13 local-sphere) 0.0 0.0 0.0 819.2)
      )
    (let ((v1-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-15 prim-core collide-as) (collide-spec projectile))
      (set! (-> v1-15 prim-core collide-with)
            (collide-spec jak bot crate civilian enemy vehicle-sphere hit-by-others-list player-list)
            )
      (set! (-> v1-15 prim-core action) (collide-action deadly))
      (set-vector! (-> v1-15 local-sphere) 0.0 0.0 0.0 2457.6)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (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 1))
    (set! (-> s5-0 event-self) 'touched)
    (set! (-> this root) s5-0)
    )
  (set! (-> this root pat-ignore-mask)
        (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noproj #x1 :noendlessfall #x1)
        )
  (none)
  )

(defmethod init-proj-settings! ((this metalhead-predator-shot))
  "Init relevant settings for the [[projectile]] such as gravity, speed, timeout, etc"
  (set! (-> this tail-pos quad) (-> this root trans quad))
  (set! (-> this attack-mode) 'predator-shot)
  (set! (-> this max-speed) 532480.0)
  (set! (-> this move) metalhead-shot-move)
  (set! (-> this update-velocity) projectile-update-velocity-space-wars)
  (set! (-> this timeout) (seconds 0.767))
  (set! (-> this sound-id) (new-sound-id))
  (set-gravity-length (-> this root dynam) 573440.0)
  (none)
  )

(defskelgroup skel-metalhead-predator predator predator-lod0-jg predator-idle-ja
              ((predator-lod0-mg (meters 20)) (predator-lod1-mg (meters 40)) (predator-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 1 0 4)
              )

(define *metalhead-predator-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 #t
    :hover-if-no-ground #f
    :idle-anim-script (new 'static 'array idle-control-frame 4
      (new 'static 'idle-control-frame :command (ic-cmd play) :anim #x5 :param0 #x1 :param1 #x1)
      (new 'static 'idle-control-frame)
      (new 'static 'idle-control-frame)
      (new 'static 'idle-control-frame)
      )
    :idle-anim 5
    :notice-anim 5
    :hostile-anim -1
    :hit-anim 5
    :knocked-anim 12
    :knocked-land-anim 13
    :die-anim 11
    :die-falling-anim 11
    :victory-anim 5
    :jump-wind-up-anim 5
    :jump-in-air-anim 5
    :jump-land-anim 5
    :neck-joint 7
    :look-at-joint 8
    :bullseye-joint 6
    :sound-hit (static-sound-name "metalhead-preda")
    :sound-die (static-sound-name "metalhead-preda")
    :notice-distance-delta (meters 0.1)
    :default-hit-points 5
    :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
      touch
      generic-attack
      lunge
      flop
      punch
      spin
      roll
      uppercut
      bonk
      tube
      vehicle
      flut-attack
      board
      mech
      mech-punch
      mech-bonk
      dark-skin
      dark-punch
      dark-bomb
      dark-giant
      shield
      explode
      jak-yellow-shot
      jak-red-shot
      jak-blue-shot
      jak-dark-shot
      enemy-yellow-shot
      enemy-dark-shot
      eco-yellow
      eco-red
      eco-blue
      eco-green
      knocked
      penetrate-33
      penetrate-34
      penetrate-35
      penetrate-36
      penetrate-37
      penetrate-38
      penetrate-39
      penetrate-40
      penetrate-41
      penetrate-42
      penetrate-43
      penetrate-44
      penetrate-45
      penetrate-46
      penetrate-47
      penetrate-48
      penetrate-49
      penetrate-50
      penetrate-51
      penetrate-52
      penetrate-53
      penetrate-54
      penetrate-55
      penetrate-56
      penetrate-57
      penetrate-58
      penetrate-59
      penetrate-60
      penetrate-61
      penetrate-62
      penetrate-63
      )
    :movement-gravity (meters -100)
    :friction 0.8
    :attack-shove-back (meters 3)
    :attack-shove-up (meters 2)
    :attack-mode 'generic
    :attack-damage 2
    :recover-gnd-collide-with (collide-spec backgnd crate obstacle hit-by-others-list pusher)
    :jump-height-min (meters 0.5)
    :jump-height-factor 0.1
    :knocked-seek-ry-clamp 6371.5557
    :knocked-soft-vxz-lo 81920.0
    :knocked-soft-vxz-hi 81920.0
    :knocked-soft-vy-lo 69632.0
    :knocked-soft-vy-hi 69632.0
    :knocked-medium-vxz-lo 81920.0
    :knocked-medium-vxz-hi 81920.0
    :knocked-medium-vy-lo 69632.0
    :knocked-medium-vy-hi 69632.0
    :knocked-hard-vxz-lo 81920.0
    :knocked-hard-vxz-hi 81920.0
    :knocked-hard-vy-lo 69632.0
    :knocked-hard-vy-hi 69632.0
    :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 53248.0
    :knocked-yellow-vy-lo 40960.0
    :knocked-yellow-vy-hi 53248.0
    :knocked-red-vxz-lo 102400.0
    :knocked-red-vxz-hi 102400.0
    :knocked-red-vy-lo 81920.0
    :knocked-red-vy-hi 81920.0
    :knocked-blue-vxz-lo 32768.0
    :knocked-blue-vxz-hi 65536.0
    :knocked-blue-vy-lo 32768.0
    :knocked-blue-vy-hi 49152.0
    :shadow-size (meters 2)
    :shadow-max-y (meters 1)
    :shadow-min-y (meters -1)
    :shadow-locus-dist (meters 150)
    :gem-joint -1
    :gem-offset (new 'static 'sphere :r 163840.0)
    :callback-info #f
    :use-momentum #t
    :use-frustration #t
    :use-stop-chase #f
    :use-circling #f
    :use-pacing #f
    :walk-anim 6
    :turn-anim 5
    :run-anim 7
    :taunt-anim -1
    :run-travel-speed (meters 8)
    :run-acceleration (meters 6)
    :run-turning-acceleration (meters 30)
    :walk-travel-speed (meters 4)
    :walk-acceleration (meters 3)
    :walk-turning-acceleration (meters 8)
    :maximum-rotation-rate (degrees 720)
    :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! (-> *metalhead-predator-nav-enemy-info* fact-defaults) *fact-info-enemy-defaults*)

(deftype metalhead-predator (citizen-enemy)
  ((los                los-control  :inline)
   (want-stop          symbol)
   (target-pos         vector       :inline)
   (curr-node          int32)
   (hide-pos           vector       :inline)
   (next-change        int64)
   (shoot-angle        degrees)
   (miss-amount        float)
   (ambient-sound-id   sound-id)
   (shock-effect-time  time-frame)
   (shock-effect-end   int64)
   (fade               float)
   (dest-fade          float)
   )
  (:state-methods
    fire
    close-attack
    )
  (:methods
    (metalhead-predator-method-205 (_type_ symbol) none)
    (metalhead-predator-method-206 (_type_ int float) none)
    (metalhead-predator-method-207 (_type_ vector vector vector) symbol)
    (metalhead-predator-method-208 (_type_) none)
    )
  )


(set! (-> *lightning-spec-id-table* 15) (new 'static 'lightning-spec
                                          :name "lightning-metalhead-predator-shock-skel"
                                          :flags (lightning-spec-flags lsf0)
                                          :rand-func #x2
                                          :start-color (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80)
                                          :end-color (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80)
                                          :fade-to-color (new 'static 'rgba :r #xbf :b #x8f :a #x5)
                                          :fade-start-factor 0.2
                                          :fade-time 120.0
                                          :texture (new 'static 'texture-id :index #x83 :page #xc)
                                          :reduction 0.5
                                          :num-points 32
                                          :box-size 2048.0
                                          :merge-factor 0.5
                                          :merge-count 2
                                          :radius 2048.0
                                          :duration 30.0
                                          :sound (static-sound-spec "predator-zap")
                                          )
      )

(defmethod metalhead-predator-method-208 ((this metalhead-predator))
  (cond
    ((< (-> this hit-points) 2)
     (when (!= (-> this dest-fade) 128.0)
       (sound-play "pred-uncloak")
       (set! (-> this sound) (the-as ambient-sound 0))
       0
       )
     (set! (-> this dest-fade) 128.0)
     )
    (else
      (set! (-> this dest-fade) 0.0)
      )
    )
  (seek! (-> this fade) (-> this dest-fade) (* 60.0 (seconds-per-frame)))
  (set! (-> this draw force-fade) (the-as uint (the int (-> this fade))))
  (cond
    ((zero? (-> this draw force-fade))
     (setup-masks (-> this draw) 8 0)
     (setup-masks (-> this draw) 0 4)
     (logclear! (-> this draw status) (draw-control-status force-fade warp-cross-fade))
     )
    ((= (-> this draw force-fade) 128)
     (setup-masks (-> this draw) 0 8)
     (setup-masks (-> this draw) 4 0)
     (logclear! (-> this draw status) (draw-control-status force-fade warp-cross-fade))
     )
    (else
      (setup-masks (-> this draw) 8 0)
      (setup-masks (-> this draw) 4 0)
      (logior! (-> this draw status) (draw-control-status force-fade warp-cross-fade))
      )
    )
  (if (< 245760.0 (vector-vector-distance (-> this root trans) (camera-pos)))
      (setup-masks (-> this draw) 0 8)
      )
  (when (< (current-time) (-> this shock-effect-end))
    (when (time-elapsed? (-> this shock-effect-time) (seconds 0.04))
      (set-time! (-> this shock-effect-time))
      (process-drawable-shock-skel-effect
        this
        (-> *lightning-spec-id-table* 15)
        lightning-probe-callback
        (-> *part-id-table* 166)
        2048.0
        -1
        -1
        )
      )
    )
  0
  (none)
  )

(defmethod common-post ((this metalhead-predator))
  "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 citizen-enemy common-post)))
    (t9-0 this)
    )
  (metalhead-predator-method-208 this)
  (set-dst-proc! (-> this los) (-> this focus handle))
  (los-control-method-9 (-> this los) (the-as process-focusable #f) (the-as vector #f) 2048.0)
  (none)
  )

;; WARN: disable def twice: 21. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare.
(defmethod general-event-handler ((this metalhead-predator) (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
    (('attack)
     (set! (-> this shock-effect-end) (the-as int (+ (current-time) (seconds 1))))
     ((method-of-type citizen-enemy general-event-handler) this arg0 arg1 arg2 arg3)
     )
    (('combo)
     (and (not (and (-> this next-state) (= (-> this next-state name) 'inactive)))
          (and (not (logtest? (enemy-flag dislike-combo) (-> this enemy-flags))) (nonzero? (-> this hit-points)))
          )
     )
    (else
      ((method-of-type citizen-enemy general-event-handler) this arg0 arg1 arg2 arg3)
      )
    )
  )

(defmethod enemy-method-77 ((this metalhead-predator) (arg0 enemy-knocked-info))
  (cond
    ((zero? (-> this hit-points))
     (case (-> this incoming knocked-type)
       (((knocked-type knocked-type-5))
        (ja-channel-push! 1 (seconds 0.1))
        (let ((a0-3 (-> this skel root-channel 0)))
          (set! (-> a0-3 frame-group) (the-as art-joint-anim (-> this draw art-group data 18)))
          (set! (-> a0-3 param 0)
                (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 18)) frames num-frames) -1))
                )
          (set! (-> a0-3 param 1) (-> arg0 anim-speed))
          (set! (-> a0-3 frame-num) 0.0)
          (joint-control-channel-group! a0-3 (the-as art-joint-anim (-> this draw art-group data 18)) num-func-seek!)
          )
        )
       (else
         (ja-channel-push! 1 (seconds 0.1))
         (let ((a0-5 (-> this skel root-channel 0)))
           (set! (-> a0-5 frame-group) (the-as art-joint-anim (-> this draw art-group data 14)))
           (set! (-> a0-5 param 0)
                 (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 14)) frames num-frames) -1))
                 )
           (set! (-> a0-5 param 1) (-> arg0 anim-speed))
           (set! (-> a0-5 frame-num) 0.0)
           (joint-control-channel-group! a0-5 (the-as art-joint-anim (-> this draw art-group data 14)) num-func-seek!)
           )
         )
       )
     #t
     )
    (else
      (case (-> this incoming knocked-type)
        (((knocked-type knocked-type-6))
         (ja-channel-push! 1 (seconds 0.01))
         (let ((v1-32 (rnd-int-count this 2)))
           (cond
             ((zero? v1-32)
              (let ((a0-10 (-> this skel root-channel 0)))
                (set! (-> a0-10 frame-group) (the-as art-joint-anim (-> this draw art-group data 21)))
                (set! (-> a0-10 param 0)
                      (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 21)) frames num-frames) -1))
                      )
                (set! (-> a0-10 param 1) (-> arg0 anim-speed))
                (set! (-> a0-10 frame-num) 0.0)
                (joint-control-channel-group! a0-10 (the-as art-joint-anim (-> this draw art-group data 21)) num-func-seek!)
                )
              )
             ((= v1-32 1)
              (let ((a0-12 (-> this skel root-channel 0)))
                (set! (-> a0-12 frame-group) (the-as art-joint-anim (-> this draw art-group data 22)))
                (set! (-> a0-12 param 0)
                      (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 22)) frames num-frames) -1))
                      )
                (set! (-> a0-12 param 1) (-> arg0 anim-speed))
                (set! (-> a0-12 frame-num) 0.0)
                (joint-control-channel-group! a0-12 (the-as art-joint-anim (-> this draw art-group data 22)) num-func-seek!)
                )
              )
             )
           )
         )
        (((knocked-type knocked-type-5))
         (ja-channel-push! 1 (seconds 0.1))
         (let ((a0-15 (-> this skel root-channel 0)))
           (set! (-> a0-15 frame-group) (the-as art-joint-anim (-> this draw art-group data 18)))
           (set! (-> a0-15 param 0)
                 (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 18)) frames num-frames) -1))
                 )
           (set! (-> a0-15 param 1) (-> arg0 anim-speed))
           (set! (-> a0-15 frame-num) 0.0)
           (joint-control-channel-group! a0-15 (the-as art-joint-anim (-> this draw art-group data 18)) num-func-seek!)
           )
         )
        (else
          (ja-channel-push! 1 (seconds 0.1))
          (let ((a0-17 (-> this skel root-channel 0)))
            (set! (-> a0-17 frame-group) (the-as art-joint-anim (-> this draw art-group data 12)))
            (set! (-> a0-17 param 0)
                  (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 12)) frames num-frames) -1))
                  )
            (set! (-> a0-17 param 1) (-> arg0 anim-speed))
            (set! (-> a0-17 frame-num) 0.0)
            (joint-control-channel-group! a0-17 (the-as art-joint-anim (-> this draw art-group data 12)) num-func-seek!)
            )
          )
        )
      #t
      )
    )
  )

(defmethod enemy-method-78 ((this metalhead-predator) (arg0 enemy-knocked-info))
  (cond
    ((zero? (-> this hit-points))
     (case (-> this incoming knocked-type)
       (((knocked-type knocked-type-5))
        (ja-channel-push! 1 (seconds 0.1))
        (let ((a0-3 (-> this skel root-channel 0)))
          (set! (-> a0-3 frame-group) (the-as art-joint-anim (-> this draw art-group data 20)))
          (set! (-> a0-3 param 0)
                (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 20)) frames num-frames) -1))
                )
          (set! (-> a0-3 param 1) (-> arg0 anim-speed))
          (set! (-> a0-3 frame-num) 0.0)
          (joint-control-channel-group! a0-3 (the-as art-joint-anim (-> this draw art-group data 20)) num-func-seek!)
          )
        )
       (else
         (ja-channel-push! 1 (seconds 0.1))
         (let ((a0-5 (-> this skel root-channel 0)))
           (set! (-> a0-5 frame-group) (the-as art-joint-anim (-> this draw art-group data 15)))
           (set! (-> a0-5 param 0)
                 (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 15)) frames num-frames) -1))
                 )
           (set! (-> a0-5 param 1) (-> arg0 anim-speed))
           (set! (-> a0-5 frame-num) 0.0)
           (joint-control-channel-group! a0-5 (the-as art-joint-anim (-> this draw art-group data 15)) num-func-seek!)
           )
         )
       )
     #t
     )
    (else
      (case (-> this incoming knocked-type)
        (((knocked-type knocked-type-6))
         (ja-channel-push! 1 (seconds 0.01))
         (let ((a0-8 (-> this skel root-channel 0)))
           (set! (-> a0-8 frame-group) (the-as art-joint-anim (-> this draw art-group data 23)))
           (set! (-> a0-8 param 0)
                 (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 23)) frames num-frames) -1))
                 )
           (set! (-> a0-8 param 1) (-> arg0 anim-speed))
           (set! (-> a0-8 frame-num) 0.0)
           (joint-control-channel-group! a0-8 (the-as art-joint-anim (-> this draw art-group data 23)) num-func-seek!)
           )
         )
        (((knocked-type knocked-type-5))
         (ja-channel-push! 1 (seconds 0.1))
         (let ((a0-11 (-> this skel root-channel 0)))
           (set! (-> a0-11 frame-group) (the-as art-joint-anim (-> this draw art-group data 19)))
           (set! (-> a0-11 param 0)
                 (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 19)) frames num-frames) -1))
                 )
           (set! (-> a0-11 param 1) (-> arg0 anim-speed))
           (set! (-> a0-11 frame-num) 0.0)
           (joint-control-channel-group! a0-11 (the-as art-joint-anim (-> this draw art-group data 19)) num-func-seek!)
           )
         )
        (else
          (ja-channel-push! 1 (seconds 0.1))
          (let ((a0-13 (-> this skel root-channel 0)))
            (set! (-> a0-13 frame-group) (the-as art-joint-anim (-> this draw art-group data 13)))
            (set! (-> a0-13 param 0)
                  (the float (+ (-> (the-as art-joint-anim (-> this draw art-group data 13)) frames num-frames) -1))
                  )
            (set! (-> a0-13 param 1) (-> arg0 anim-speed))
            (set! (-> a0-13 frame-num) 0.0)
            (joint-control-channel-group! a0-13 (the-as art-joint-anim (-> this draw art-group data 13)) num-func-seek!)
            )
          )
        )
      #t
      )
    )
  )

(defmethod get-inv-mass ((this metalhead-predator))
  0.5
  )

(defmethod metalhead-predator-method-207 ((this metalhead-predator) (arg0 vector) (arg1 vector) (arg2 vector))
  (let ((s5-0 (new 'stack-no-clear 'collide-query)))
    (let ((f0-0 1228.8)
          (f30-0 6144.0)
          )
      (set! (-> s5-0 start-pos quad) (-> arg0 quad))
      (vector-! (-> s5-0 move-dist) arg1 arg0)
      (let ((v1-4 s5-0))
        (set! (-> v1-4 radius) f0-0)
        (set! (-> v1-4 collide-with) (collide-spec backgnd))
        (set! (-> v1-4 ignore-process0) this)
        (set! (-> v1-4 ignore-process1) (handle->process (-> this focus handle)))
        (set! (-> v1-4 ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1))
        (set! (-> v1-4 action-mask) (collide-action solid))
        )
      (let ((f0-1 (fill-and-probe-using-line-sphere *collide-cache* s5-0)))
        (cond
          ((>= f0-1 0.0)
           (vector-float*! (-> s5-0 move-dist) (-> s5-0 move-dist) f0-1)
           (cond
             ((< (vector-dot
                   (-> s5-0 best-other-tri normal)
                   (vector-! (new 'stack-no-clear 'vector) arg2 (the-as vector (-> s5-0 best-other-tri)))
                   )
                 0.0
                 )
              )
             (else
               )
             )
           )
          (else
            (vector-! (-> s5-0 move-dist) arg1 arg0)
            )
          )
        )
      (set! (-> s5-0 start-pos quad) (-> arg0 quad))
      (let ((v1-14 s5-0))
        (set! (-> v1-14 radius) f30-0)
        (set! (-> v1-14 collide-with) (collide-spec enemy hit-by-player-list hit-by-others-list))
        (set! (-> v1-14 ignore-process0) this)
        (set! (-> v1-14 ignore-process1) (handle->process (-> this focus handle)))
        (set! (-> v1-14 ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1))
        (set! (-> v1-14 action-mask) (collide-action solid))
        )
      )
    (cond
      ((< (fill-and-probe-using-line-sphere *collide-cache* s5-0) 0.0)
       #t
       )
      (else
        (let ((s4-1 (-> s5-0 best-other-tri collide-ptr)))
          (if (and (if (type? s4-1 collide-shape-prim)
                       s4-1
                       )
                   (< (vector-dot
                        (-> s5-0 best-other-tri normal)
                        (vector-! (new 'stack-no-clear 'vector) arg2 (the-as vector (-> s5-0 best-other-tri)))
                        )
                      0.0
                      )
                   )
              #f
              )
          )
        )
      )
    )
  )

(defmethod metalhead-predator-method-206 ((this metalhead-predator) (arg0 int) (arg1 float))
  (local-vars (sv-240 vector) (sv-256 vector))
  (rlet ((acc :class vf)
         (vf0 :class vf)
         (vf4 :class vf)
         (vf5 :class vf)
         (vf6 :class vf)
         (vf7 :class vf)
         )
    (init-vf0-vector)
    (let ((a1-1 (-> this node-list data arg0))
          (s5-0 (new 'stack-no-clear 'projectile-init-by-other-params))
          )
      (set! (-> s5-0 ent) (-> this entity))
      (set! (-> s5-0 charge) 1.0)
      (set! (-> s5-0 options) (projectile-options))
      (set! (-> s5-0 notify-handle) (process->handle this))
      (set! (-> s5-0 owner-handle) (the-as handle #f))
      (set! (-> s5-0 ignore-handle) (process->handle this))
      (let* ((v1-10 *game-info*)
             (a0-11 (+ (-> v1-10 attack-id) 1))
             )
        (set! (-> v1-10 attack-id) a0-11)
        (set! (-> s5-0 attack-id) a0-11)
        )
      (set! (-> s5-0 timeout) (seconds 4))
      (vector<-cspace! (-> s5-0 pos) a1-1)
      (let ((s3-0 (handle->process (-> this focus handle)))
            (s2-0 (new 'stack-no-clear 'vector))
            )
        (when s3-0
          (seek! (-> this miss-amount) (* 0.2 (vector-length (-> (the-as process-drawable s3-0) root transv))) 4096.0)
          (set! (-> s2-0 quad) (-> (get-trans (the-as process-focusable s3-0) 3) quad))
          (set! sv-240 (new 'stack-no-clear 'vector))
          (let ((v1-25 (-> s5-0 pos))
                (a0-18 s2-0)
                )
            (.lvf vf4 (&-> v1-25 quad))
            (.lvf vf5 (&-> a0-18 quad))
            )
          (.mov.vf.w vf6 vf0)
          (.sub.vf.xyz vf6 vf4 vf5)
          (.svf (&-> sv-240 quad) vf6)
          (let* ((f0-5 (vector-length sv-240))
                 (f0-6 (/ f0-5 (meters 130)))
                 )
            (set! sv-256 (new 'stack-no-clear 'vector))
            (let ((s0-0 (new 'stack-no-clear 'vector))
                  (s1-1 (new 'stack-no-clear 'vector))
                  )
              (let ((a0-19 s2-0))
                (let ((v1-31 s2-0))
                  (let ((a1-6 (-> (the-as process-focusable s3-0) root transv)))
                    (let ((a2-2 f0-6))
                      (.mov vf7 a2-2)
                      )
                    (.lvf vf5 (&-> a1-6 quad))
                    )
                  (.lvf vf4 (&-> v1-31 quad))
                  )
                (.add.x.vf.w vf6 vf0 vf0)
                (.mul.x.vf.xyz acc vf5 vf7)
                (.add.mul.w.vf.xyz vf6 vf4 vf0 acc)
                (.svf (&-> a0-19 quad) vf6)
                )
              (vector-normalize! sv-240 1.0)
              (vector-flatten! sv-256 *up-vector* sv-240)
              (vector-normalize! sv-256 1.0)
              (vector-cross! s0-0 sv-240 sv-256)
              (vector-normalize! s0-0 1.0)
              (let ((a2-5 (quaternion-vector-angle! (new 'stack-no-clear 'quaternion) sv-240 (-> this shoot-angle))))
                (vector-orient-by-quat! sv-256 sv-256 a2-5)
                )
              (let* ((t9-9 quaternion-vector-angle!)
                     (a0-27 (new 'stack-no-clear 'quaternion))
                     (a2-6 (-> this shoot-angle))
                     (a2-7 (t9-9 a0-27 sv-240 a2-6))
                     )
                (vector-orient-by-quat! s0-0 s0-0 a2-7)
                )
              (let ((a0-29 s1-1))
                (let ((v1-33 s2-0))
                  (let ((a1-17 (-> this miss-amount)))
                    (.mov vf7 a1-17)
                    )
                  (.lvf vf5 (&-> sv-256 quad))
                  (.lvf vf4 (&-> v1-33 quad))
                  )
                (.add.x.vf.w vf6 vf0 vf0)
                (.mul.x.vf.xyz acc vf5 vf7)
                (.add.mul.w.vf.xyz vf6 vf4 vf0 acc)
                (.svf (&-> a0-29 quad) vf6)
                )
              (let ((v1-34 s2-0))
                (let ((a0-30 (* arg1 (-> this miss-amount))))
                  (.mov vf7 a0-30)
                  )
                (.lvf vf5 (&-> s0-0 quad))
                (.lvf vf4 (&-> s1-1 quad))
                (.add.x.vf.w vf6 vf0 vf0)
                (.mul.x.vf.xyz acc vf5 vf7)
                (.add.mul.w.vf.xyz vf6 vf4 vf0 acc)
                (.svf (&-> v1-34 quad) vf6)
                )
              )
            )
          (vector-! (-> s5-0 vel) s2-0 (-> s5-0 pos))
          (vector-normalize! (-> s5-0 vel) 409600.0)
          (when (metalhead-predator-method-207
                  this
                  (-> s5-0 pos)
                  (vector+! (new 'stack-no-clear 'vector) (-> s5-0 pos) (-> s5-0 vel))
                  (get-trans (the-as process-focusable s3-0) 3)
                  )
            (vector-normalize! (-> s5-0 vel) 532480.0)
            (spawn-projectile metalhead-predator-shot s5-0 this *default-dead-pool*)
            )
          )
        )
      )
    0
    (none)
    )
  )

(defstate active (metalhead-predator)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type citizen-enemy active) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (logclear! (-> self enemy-flags) (enemy-flag lock-focus))
    )
  :trans (behavior ()
    (let ((t9-0 (-> (method-of-type citizen-enemy active) trans)))
      (if t9-0
          (t9-0)
          )
      )
    )
  )

(defstate hostile (metalhead-predator)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type citizen-enemy hostile) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set! (-> self want-stop) #f)
    (set-time! (-> self state-time))
    (set! (-> self next-change) (the-as int (+ (current-time) (the int (* 300.0 (rand-vu-float-range 4.0 8.0))))))
    (if (zero? (rnd-int-count self 3))
        (sound-play "pred-talk")
        )
    )
  :trans (behavior ()
    (let ((t9-0 (-> (method-of-type citizen-enemy hostile) trans)))
      (if t9-0
          (t9-0)
          )
      )
    (let ((gp-0 (handle->process (-> self focus handle))))
      (if (and gp-0 (or (focus-test? (the-as process-focusable gp-0) inactive)
                        (focus-test? (the-as process-focusable gp-0) disable)
                        )
               )
          (set! gp-0 (the-as process #f))
          )
      (if (not gp-0)
          (go-virtual active)
          )
      (when (get-enemy-target self)
        (when (and gp-0 (time-elapsed? (-> self state-time) (-> self reaction-time)))
          (cond
            ((< (vector-vector-xz-distance (get-trans (the-as process-focusable gp-0) 0) (-> self root trans)) 16384.0)
             (go-virtual close-attack)
             )
            ((check-los? (-> self los) 0)
             (go-virtual fire)
             )
            )
          )
        )
      )
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (ja-no-eval :group! predator-run0-ja :num! (seek!) :frame-num 6.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (until #f
      (ja-no-eval :group! predator-run0-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  )

(defstate fire (metalhead-predator)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (logior! (-> self focus-status) (focus-status dangerous))
    (let* ((v1-2 *game-info*)
           (a0-1 (+ (-> v1-2 attack-id) 1))
           )
      (set! (-> v1-2 attack-id) a0-1)
      (set! (-> self attack-id) a0-1)
      )
    (traffic-danger-init! self)
    (logior! (-> self enemy-flags) (enemy-flag lock-focus))
    )
  :exit (behavior ()
    (if (logtest? (-> self enemy-flags) (enemy-flag dangerous-backup))
        (logior! (-> self focus-status) (focus-status dangerous))
        (logclear! (-> self focus-status) (focus-status dangerous))
        )
    )
  :trans (behavior ()
    (let ((v1-2 (handle->process (-> self focus handle))))
      (if (and v1-2 (or (focus-test? (the-as process-focusable v1-2) inactive)
                        (focus-test? (the-as process-focusable v1-2) disable)
                        )
               )
          (set! v1-2 (the-as process #f))
          )
      (if (not v1-2)
          (go-virtual active)
          )
      )
    )
  :code (behavior ()
    (label cfg-0)
    1.0
    (let ((gp-0 0))
      (set! (-> self shoot-angle) (* 182.04445 (rand-vu-float-range -45.0 45.0)))
      (ja-channel-push! 1 (seconds 0.2))
      (ja-no-eval :group! predator-shoot-guns0-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (when (and (< 9.0 (ja-frame-num 0)) (zero? gp-0))
          (set! gp-0 1)
          (metalhead-predator-method-206 self 12 1.0)
          )
        (when (and (< 11.0 (ja-frame-num 0)) (= gp-0 1))
          (set! gp-0 2)
          (metalhead-predator-method-206 self 16 -1.0)
          )
        (let ((s5-0 (handle->process (-> self focus handle))))
          (when s5-0
            (seek-toward-heading-vec!
              (-> self root)
              (vector-! (new 'stack-no-clear 'vector) (get-trans (the-as process-focusable s5-0) 0) (-> self root trans))
              32768.0
              (seconds 0.05)
              )
            (if (< (vector-vector-distance (-> self root trans) (get-trans (the-as process-focusable s5-0) 0)) 24576.0)
                (go-virtual close-attack)
                )
            )
          )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (b! #t cfg-26 :delay (nop!))
    (b! (not #f) cfg-0 :delay (empty-form))
    (label cfg-26)
    (go-hostile self)
    )
  :post enemy-simple-post
  )

(defstate close-attack (metalhead-predator)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (traffic-danger-init! self)
    (logior! (-> self enemy-flags) (enemy-flag lock-focus))
    (logior! (-> self focus-status) (focus-status dangerous))
    (set! (-> self root penetrate-using) (penetrate generic-attack lunge))
    (enemy-method-49 self)
    (let* ((v1-9 *game-info*)
           (a0-5 (+ (-> v1-9 attack-id) 1))
           )
      (set! (-> v1-9 attack-id) a0-5)
      (set! (-> self attack-id) a0-5)
      )
    (let ((v1-10 (-> self nav)))
      (set! (-> v1-10 target-speed) 4096.0)
      )
    0
    )
  :exit (behavior ()
    (metalhead-predator-method-205 self #f)
    (logclear! (-> self enemy-flags) (enemy-flag lock-focus))
    (if (logtest? (-> self enemy-flags) (enemy-flag dangerous-backup))
        (logior! (-> self focus-status) (focus-status dangerous))
        (logclear! (-> self focus-status) (focus-status dangerous))
        )
    )
  :trans (behavior ()
    (enemy-method-49 self)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (let ((gp-0 #f))
      (ja-no-eval :group! predator-close-attack-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (when (and (< 4.0 (ja-frame-num 0)) (not gp-0))
          (metalhead-predator-method-205 self #t)
          (set! gp-0 #t)
          )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (let ((v1-32 (-> self nav state)))
      (set! (-> v1-32 speed) 0.0)
      )
    0
    (ja-no-eval :group! predator-close-attack-recover-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (if (zero? (rnd-int-count self 3))
        (sound-play "pred-talk")
        )
    (go-hostile self)
    )
  :post nav-enemy-chase-post
  )

(defmethod metalhead-predator-method-205 ((this metalhead-predator) (arg0 symbol))
  (let ((v1-1 (-> this root root-prim)))
    (dotimes (a0-1 (the-as int (+ (-> v1-1 specific 0) -2)))
      (let ((a2-1 (-> (the-as collide-shape-prim-group v1-1) child (+ a0-1 2))))
        (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-predator))
  "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)
          )
    (set! (-> s5-0 penetrated-by) (penetrate
                                    generic-attack
                                    lunge
                                    flop
                                    punch
                                    spin
                                    roll
                                    uppercut
                                    bonk
                                    tube
                                    vehicle
                                    flut-attack
                                    board
                                    mech-punch
                                    dark-punch
                                    dark-giant
                                    )
          )
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 5) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 6))
      (set! (-> s4-0 prim-core collide-as) (collide-spec enemy))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec backgnd jak civilian enemy hit-by-others-list player-list)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid no-standon))
      (set-vector! (-> s4-0 local-sphere) 0.0 11264.0 0.0 17203.2)
      (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 backgnd jak civilian hit-by-others-list player-list))
      (set! (-> v1-13 prim-core action) (collide-action solid))
      (set-vector! (-> v1-13 local-sphere) 0.0 5120.0 0.0 5120.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 backgnd jak civilian hit-by-others-list player-list))
      (set! (-> v1-15 prim-core action) (collide-action solid no-standon))
      (set-vector! (-> v1-15 local-sphere) 0.0 9216.0 0.0 5120.0)
      )
    (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 civilian hit-by-others-list player-list))
      (set! (-> v1-17 prim-core action) (collide-action solid no-standon))
      (set! (-> v1-17 transform-index) 7)
      (set-vector! (-> v1-17 local-sphere) 0.0 0.0 0.0 3072.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 civilian hit-by-others-list player-list))
      (set! (-> v1-19 transform-index) 16)
      (set-vector! (-> v1-19 local-sphere) 0.0 0.0 0.0 3276.8)
      )
    (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 civilian hit-by-others-list player-list))
      (set! (-> v1-21 transform-index) 12)
      (set-vector! (-> v1-21 local-sphere) 0.0 0.0 0.0 3276.8)
      )
    (set! (-> s5-0 nav-radius) 6144.0)
    (let ((v1-23 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-23 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-23 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 relocate ((this metalhead-predator) (offset int))
  (call-parent-method this offset)
  )

(defmethod init-enemy! ((this metalhead-predator))
  "Common method called to initialize the enemy, typically sets up default field values and calls ancillary helper methods"
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-metalhead-predator" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (init-enemy-behaviour-and-stats! this *metalhead-predator-nav-enemy-info*)
  (let ((v1-5 (-> this nav)))
    (set! (-> v1-5 speed-scale) 1.0)
    )
  0
  (set! (-> this draw lod-set lod 0 dist) 491520.0)
  (set! (-> this draw lod-set lod 1 dist) 573440.0)
  (set! (-> this anim-shuffle) 6)
  (set! (-> this anim-walk) 6)
  (set! (-> this speed-walk) 12288.0)
  (set! (-> this dist-walk-anim) 16179.2)
  (set! (-> this dist-run-anim) 26214.4)
  (set! (-> this anim-run) 7)
  (set! (-> this speed-run) 49152.0)
  (set! (-> this water-anim) -1)
  (add-connection *part-engine* this 8 this 318 (new 'static 'vector :x 1228.8 :y 450.56 :z 983.04 :w 614400.0))
  (add-connection
    *part-engine*
    this
    8
    this
    318
    (new 'static 'vector :x -1228.8 :y 450.56 :z 983.04 :w 614400.0)
    )
  (new-source! (-> this los) this (seconds 0.2) (collide-spec backgnd obstacle))
  (set! (-> this minimap) #f)
  0
  (none)
  )

(defmethod citizen-init! ((this metalhead-predator))
  "Initialize [[citizen]] defaults."
  (let ((t9-0 (method-of-type citizen-enemy citizen-init!)))
    (t9-0 this)
    )
  (setup-masks (-> this draw) 8 0)
  (setup-masks (-> this draw) 0 4)
  (logior! (-> this draw status) (draw-control-status force-fade warp-cross-fade))
  (set! (-> this draw force-fade) (the-as uint 0))
  (set! (-> this fade) 0.0)
  (set! (-> this dest-fade) 0.0)
  (set! (-> this curr-node) -1)
  (set! (-> this next-change) 0)
  (set! (-> this miss-amount) 16384.0)
  (set-vector! (-> this draw color-mult) 1.0 1.0 1.0 1.0)
  0
  (none)
  )
