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

;; name: spydroid.gc
;; name in dgo: spydroid
;; dgos: CTYPESC

;; DECOMP BEGINS

(defpart 4699
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.75))
    (:rot-x (degrees 1.125))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0)
    (:b 0.0)
    (:a 16.0)
    (:omega (degrees 1361.25))
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3 glow))
    (:userdata 409.6)
    )
  )

(defpart 4700
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.5))
    (:scale-y :copy scale-x)
    (:r 0.0)
    (:g 128.0 64.0)
    (:b 255.0)
    (:a 32.0 4.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4701
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.5))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 128.0 64.0)
    (:b 0.0)
    (:a 32.0 4.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4702
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.5))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0)
    (:b 0.0)
    (:a 32.0 4.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4703
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 2) (meters 0.2))
    (:rot-z (degrees -2) (degrees 4))
    (:scale-y :copy scale-x)
    (:r 0.0)
    (:g 128.0 64.0)
    (:b 255.0)
    (:a 12.0 2.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4704
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 2) (meters 0.2))
    (:rot-z (degrees -2) (degrees 4))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 128.0 64.0)
    (:b 0.0)
    (:a 12.0 2.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4705
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 2) (meters 0.2))
    (:rot-z (degrees -2) (degrees 4))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0)
    (:b 0.0)
    (:a 12.0 2.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4706
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.75) (meters 0.1))
    (:rot-z (degrees -2) (degrees 4))
    (:scale-y :copy scale-x)
    (:r 64.0)
    (:g 128.0 64.0)
    (:b 255.0)
    (:a 64.0 4.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4707
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.75) (meters 0.1))
    (:rot-z (degrees -2) (degrees 4))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 128.0 64.0)
    (:b 0.0)
    (:a 64.0 4.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defpart 4708
  :init-specs ((:texture (glow level-default-sprite))
    (:num 1.0)
    (:scale-x (meters 0.75) (meters 0.1))
    (:rot-z (degrees -2) (degrees 4))
    (:scale-y :copy scale-x)
    (:r 255.0)
    (:g 0.0)
    (:b 0.0)
    (:a 64.0 4.0)
    (:timer (seconds 0.017))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-3))
    )
  )

(defskelgroup skel-spydroid spydroid spydroid-lod0-jg spydroid-idle-ja
              ((spydroid-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 4)
              :shadow spydroid-shadow-mg
              )

(define *spydroid-debris-params*
  (new 'static 'debris-static-params
    :joints (new 'static 'boxed-array :type debris-static-joint-params
      (new 'static 'debris-static-joint-params :parent-joint-index 3 :group "skel-kg-debris-a")
      (new 'static 'debris-static-joint-params :parent-joint-index 4 :group "skel-kg-debris-b")
      (new 'static 'debris-static-joint-params :parent-joint-index 5 :group "skel-kg-debris-c")
      (new 'static 'debris-static-joint-params :parent-joint-index 8 :group "skel-kg-debris-d")
      (new 'static 'debris-static-joint-params :parent-joint-index 10 :group "skel-kg-debris-a")
      (new 'static 'debris-static-joint-params :parent-joint-index 13 :group "skel-kg-debris-b")
      (new 'static 'debris-static-joint-params :parent-joint-index 21 :group "skel-kg-debris-c")
      )
    )
  )

(deftype sensor-light-info (structure)
  ((joint       int16)
   (part-index  int16)
   (offset      vector  :inline)
   )
  )


(deftype spydroid (kg-squad-member)
  ((old-y-deg               float)
   (diff-angle              float)
   (desire-turn             symbol)
   (hit-target              symbol)
   (floor                   float)
   (explode-part            sparticle-launch-control)
   (alert-level             uint8)
   (next-check-player-time  time-frame)
   (part-ids                int16              9)
   (sensor-lights           sensor-light-info  3 :inline)
   (last-sensor-time        time-frame)
   (exiting-wait?           symbol)
   )
  (:state-methods
    attack
    search
    hunting
    scan
    undefined0
    spydroid-notice
    flip
    wait-for-vulnerable
    exit-transport
    )
  (:methods
    (spydroid-method-231 (_type_ uint) object)
    (spydroid-method-232 (_type_) int)
    (spydroid-method-233 (_type_) int)
    (spydroid-method-234 (_type_ vector) float)
    (spydroid-method-235 (_type_) symbol)
    (spydroid-method-236 (_type_) object)
    (spydroid-method-237 (_type_ traffic-danger-info) symbol)
    )
  (:states
    wait-for-vulnerable-close
    )
  )


(define *spydroid-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 #x3
        :param0 100
        :param1 100
        :param2 '((new 'static 'bfloat :data 1.0) (new 'static 'bfloat :data 1.0))
        )
      (new 'static 'idle-control-frame)
      )
    :idle-anim 3
    :notice-anim 3
    :hostile-anim 5
    :hit-anim -1
    :knocked-anim 9
    :knocked-land-anim 10
    :die-anim -1
    :die-falling-anim -1
    :victory-anim -1
    :jump-wind-up-anim -1
    :jump-in-air-anim -1
    :jump-land-anim -1
    :neck-joint 4
    :look-at-joint 4
    :bullseye-joint 4
    :sound-hit (static-sound-name "spydroid-hit")
    :sound-die (static-sound-name "spydroid-die")
    :notice-distance (meters 200)
    :notice-distance-delta (meters 10)
    :proximity-notice-distance (meters 20)
    :default-hit-points 1.0
    :gnd-collide-with (collide-spec backgnd obstacle hit-by-others-list)
    :overlaps-others-collide-with-filter (collide-spec jak civilian enemy vehicle-sphere hit-by-others-list player-list)
    :movement-gravity (meters -100)
    :friction 0.8
    :attack-shove-back (meters 3.5)
    :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)
    :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 6371.5557
    :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 51.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 1)
    :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)
    :knocked-off #t
    :callback-info #f
    :use-momentum #t
    :use-frustration #t
    :use-stop-chase #f
    :use-circling #f
    :use-pacing #f
    :walk-anim 4
    :turn-anim -1
    :run-anim 5
    :taunt-anim -1
    :run-travel-speed (meters 8)
    :run-acceleration (meters 32)
    :run-turning-acceleration (meters 40)
    :walk-travel-speed (meters 4)
    :walk-acceleration (meters 16)
    :walk-turning-acceleration (meters 40)
    :maximum-rotation-rate (degrees 360)
    :notice-nav-radius (meters 2)
    :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! (-> *spydroid-nav-enemy-info* fact-defaults) *fact-info-enemy-defaults*)

(defmethod enemy-common-post ((this spydroid))
  "Common implementation of post. Runs ja-post."
  (spydroid-method-236 this)
  ((method-of-type kg-squad-member enemy-common-post) this)
  0
  (none)
  )

(defmethod event-handler ((this spydroid) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  "Commmon handler for events."
  (case arg2
    (('jump)
     (set! (-> this floor) (-> (the-as enemy-jump-info (-> arg3 param 1)) anim-speed))
     ((method-of-type kg-squad-member event-handler) this arg0 arg1 arg2 arg3)
     )
    (else
      ((method-of-type kg-squad-member event-handler) this arg0 arg1 arg2 arg3)
      )
    )
  )

(defstate knocked (spydroid)
  :virtual #t
  :enter (behavior ()
    (sound-play "droid-explode")
    (cond
      ((logtest? (-> group-kg-small-explosion flags) (sp-group-flag sp13))
       (vector-copy!
         (-> *launch-matrix* trans)
         (vector+float*! (new 'stack-no-clear 'vector) (-> self root trans) *up-vector* 2048.0)
         )
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-kg-small-explosion)
       )
      (else
        (vector-copy!
          (-> *launch-matrix* trans)
          (vector+float*! (new 'stack-no-clear 'vector) (-> self root trans) *up-vector* 2048.0)
          )
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-kg-small-explosion)
        )
      )
    (if (not (-> *setting-control* user-current gun-special-mode))
        (drop-pickup (-> self fact) #t *entity-pool* (-> self fact) 0 #f)
        )
    (cleanup-for-death self)
    )
  :code sleep-code
  )

(defstate die-falling (spydroid)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type kg-squad-member die-falling) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (let ((t9-0 (-> (method-of-type kg-squad-member die-falling) trans)))
      (if t9-0
          (t9-0)
          )
      )
    (when (not (time-elapsed? (-> self state-time) (seconds 2)))
      (cond
        ((logtest? (-> group-kg-explosion flags) (sp-group-flag sp13))
         (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
         (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-kg-explosion)
         )
        (else
          (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
          (part-tracker-spawn part-tracker :to *entity-pool* :group group-kg-explosion)
          )
        )
      )
    )
  :code (behavior ()
    (if (not (-> *setting-control* user-current gun-special-mode))
        (drop-pickup (-> self fact) #t *entity-pool* (-> self fact) 0 #f)
        )
    (cleanup-for-death self)
    )
  )

(defmethod spydroid-method-233 ((this spydroid))
  (when (handle->process (-> this focus handle))
    (let ((s4-0 (handle->process (-> this focus handle)))
          (s3-0 (new 'stack-no-clear 'vector))
          )
      (vector-copy! s3-0 (-> (the-as process-focusable s4-0) root root-prim prim-core world-sphere))
      (let ((s5-1 (vector-! (new 'stack-no-clear 'vector) s3-0 (-> this root trans))))
        0.0
        (set! (-> s5-1 y) 0.0)
        (when (< (- (vector-normalize-ret-len! s5-1 1.0) (-> s3-0 w)) 10240.0)
          (if (not (and s4-0
                        (not (logtest? (-> (the-as process-focusable s4-0) focus-status) (focus-status disable dead ignore grabbed)))
                        )
                   )
              (return 3)
              )
          (let ((gp-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))))
            (set! (-> gp-1 y) 0.0)
            (vector-normalize! gp-1 1.0)
            (let ((f0-6 (vector-dot s5-1 gp-1)))
              (cond
                ((< 0.85 f0-6)
                 (return 2)
                 )
                ((< f0-6 0.0)
                 (return 1)
                 )
                )
              )
            )
          )
        )
      )
    )
  0
  )

(defstate wait-for-vulnerable-close (spydroid)
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (nav-enemy-method-181 self)
    )
  :trans (behavior ()
    (let ((gp-0 (the-as process-focusable (handle->process (-> self focus handle)))))
      (when gp-0
        (let ((s5-1 (vector-! (new 'stack-no-clear 'vector) (-> self root trans) (get-trans gp-0 0))))
          0.0
          (set! (-> s5-1 y) 0.0)
          (let ((f0-2 (vector-normalize-ret-len! s5-1 1.0)))
            (when (< 20480.0 f0-2)
              (cond
                ((and self (not (logtest? (-> self focus-status) (focus-status disable dead ignore grabbed))))
                 (set! (-> self exiting-wait?) #t)
                 (go-virtual hostile)
                 )
                (else
                  (go-virtual wait-for-vulnerable)
                  )
                )
              )
            )
          (vector-float*! s5-1 s5-1 49152.0)
          (let ((s4-2 (vector+! (new 'stack-no-clear 'vector) (get-trans gp-0 0) s5-1)))
            (nav-mesh-method-10 (-> self nav state mesh) s4-2 s4-2 (the-as nav-poly #f))
            (let ((v1-26 (-> self nav state)))
              (logclear! (-> v1-26 flags) (nav-state-flag directional-mode))
              (logior! (-> v1-26 flags) (nav-state-flag target-poly-dirty))
              (vector-copy! (-> v1-26 target-pos) s4-2)
              )
            )
          )
        0
        )
      )
    )
  :code (behavior ()
    (let ((v1-2 (ja-group)))
      (if (not (and v1-2 (= v1-2 spydroid-run-ja)))
          (ja-channel-push! 1 (seconds 0.2))
          )
      )
    (until #f
      (ja-no-eval :group! spydroid-run-ja :num! (seek! max 1.5) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek! max 1.5))
        )
      )
    #f
    )
  :post (behavior ()
    (nav-enemy-method-187 self)
    )
  )

(defstate wait-for-vulnerable (spydroid)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (nav-enemy-method-182 self)
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (let ((gp-0 (the-as process-focusable (handle->process (-> self focus handle)))))
      (when gp-0
        (if (and (= (-> gp-0 type) target)
                 (< (vector-vector-xz-distance (-> self root trans) (get-trans gp-0 0)) 12288.0)
                 )
            (go wait-for-vulnerable-close)
            )
        (when (and (time-elapsed? (-> self state-time) (-> self reaction-time))
                   (and self (not (logtest? (-> self focus-status) (focus-status disable dead ignore grabbed))))
                   (or (< 20480.0 (vector-vector-xz-distance (-> self root trans) (get-trans gp-0 0)))
                       (time-elapsed? (-> self state-time) (seconds 1.5))
                       )
                   )
          (set! (-> self exiting-wait?) #t)
          (go-virtual hostile)
          )
        )
      )
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (until #f
      (ja-no-eval :group! spydroid-idle-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  :post (behavior ()
    (transform-post)
    )
  )

(defstate hostile (spydroid)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (spydroid-method-231 self (the-as uint 3))
    (nav-enemy-method-181 self)
    (nav-enemy-method-177 self)
    (set-time! (-> self state-time))
    )
  :exit (behavior ()
    (set! (-> self exiting-wait?) #f)
    (if (-> self nav)
        (nav-enemy-method-176 self)
        )
    )
  :trans (behavior ()
    (let ((gp-0 (handle->process (-> self focus handle)))
          ;; og:preserve-this
          (go? (the object #f)))
      (if (and (the-as process-focusable gp-0)
               (not (and (the-as process-focusable gp-0)
                         (not (logtest? (-> (the-as process-focusable gp-0) focus-status) (focus-status disable dead ignore grabbed)))
                         )
                    )
               (= (-> (the-as process-focusable gp-0) type) target)
               )
          (go-virtual wait-for-vulnerable)
          )
      ;; og:preserve-this
      (set! go?
            (and (or (time-elapsed? (-> self state-time) (-> self reaction-time)) (-> self exiting-wait?)) gp-0)
            )
      (when go?
        (case (spydroid-method-233 self)
          ((2)
           (go-virtual attack)
           )
          ((1)
           (go-virtual flip)
           )
          ((3)
           (go-virtual wait-for-vulnerable)
           )
          )
        )
      )
    )
  :code (behavior ()
    (let ((v1-2 (ja-group)))
      (if (not (and v1-2 (= v1-2 spydroid-run-ja)))
          (ja-channel-push! 1 (seconds 0.2))
          )
      )
    (ja :group! spydroid-run-ja)
    (ja :num-func num-func-identity :frame-num 0.0)
    (let ((f30-0 (* (rnd-float-range self 0.9 1.1) (-> self travel-anim-scale-speed))))
      (until #f
        (suspend)
        (ja :num! (loop! f30-0))
        )
      )
    #f
    )
  :post (behavior ()
    (nav-enemy-chase-post)
    )
  )

(defmethod spydroid-method-234 ((this spydroid) (arg0 vector))
  (let ((gp-0 (vector-x-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)))
        (s4-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat)))
        )
    0.0
    0.0
    (let ((s5-1 (vector-! (new 'stack-no-clear 'vector) arg0 (-> this root trans))))
      0.0
      (set! (-> s5-1 y) 0.0)
      (set! (-> gp-0 y) 0.0)
      (set! (-> s4-0 y) 0.0)
      (vector-normalize! s5-1 1.0)
      (vector-normalize! gp-0 1.0)
      (vector-normalize! s4-0 1.0)
      (let* ((f0-7 (vector-dot s5-1 s4-0))
             (f0-8 (acos f0-7))
             )
        (if (< (vector-dot s5-1 gp-0) 0.0)
            (set! f0-8 (* -1.0 f0-8))
            )
        f0-8
        )
      )
    )
  )

(defstate flip (spydroid)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set! (-> self root penetrate-using) (penetrate generic-attack lunge))
    (nav-enemy-method-182 self)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.1))
    (let ((f28-0 0.0)
          (f0-0 0.0)
          (f30-0 1.0)
          )
      (let ((a0-2 (the-as process-focusable (handle->process (-> self focus handle)))))
        (when a0-2
          (let ((gp-0 (new 'stack-no-clear 'vector)))
            (vector-copy! gp-0 (get-trans a0-2 3))
            (set! f0-0 (spydroid-method-234 self gp-0))
            )
          (set! f28-0 (/ f0-0 METER_LENGTH))
          )
        )
      (if (logtest? (enemy-flag drawn-mirrored) (-> self enemy-flags))
          (set! f30-0 -1.0)
          )
      (cond
        ((>= f0-0 0.0)
         (ja-no-eval :group! spydroid-turn-180-ja :num! (seek! f28-0) :frame-num 0.0)
         (until (>= (ja-frame-num 0) f28-0)
           (quaternion-rotate-y! (-> self root quat) (-> self root quat) (* 65536.0 (seconds-per-frame) f30-0))
           (ja :num! (seek! f28-0))
           (suspend)
           )
         )
        (else
          (ja-no-eval :group! spydroid-turn-180-ja :num! (seek! 0.0) :frame-num (fabs f28-0))
          (until (= (ja-frame-num 0) 0.0)
            (quaternion-rotate-y! (-> self root quat) (-> self root quat) (* -65536.0 (seconds-per-frame) f30-0))
            (ja :num! (seek! 0.0))
            (suspend)
            )
          )
        )
      )
    (case (spydroid-method-233 self)
      ((2)
       (go-virtual attack)
       )
      (else
        (go-virtual hostile)
        )
      )
    )
  :post enemy-simple-post
  )

(defstate attack (spydroid)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set! (-> self root penetrate-using) (penetrate generic-attack lunge))
    (reset-penetrate-later! self)
    (logior! (-> self focus-status) (focus-status dangerous))
    (nav-enemy-method-182 self)
    (let* ((v1-7 *game-info*)
           (v0-2 (+ (-> v1-7 attack-id) 1))
           )
      (set! (-> v1-7 attack-id) v0-2)
      (set! (-> self attack-id) v0-2)
      )
    )
  :exit (behavior ()
    (logclear! (-> self focus-status) (focus-status dangerous))
    )
  :code (behavior ()
    (let ((gp-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self root quat))))
      (let ((a0-2 (the-as process-focusable (handle->process (-> self focus handle)))))
        (when a0-2
          (let ((s5-0 (new 'stack-no-clear 'vector)))
            (vector-copy! s5-0 (get-trans a0-2 3))
            (vector-! gp-0 s5-0 (-> self root trans))
            )
          )
        )
      (set! (-> gp-0 y) 0.0)
      (vector-normalize! gp-0 1.0)
      (ja-channel-push! 1 (seconds 0.1))
      (ja-no-eval :group! spydroid-attack-jump-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (let ((s5-2 (vector-float*! (new 'stack-no-clear 'vector) gp-0 (* 49152.0 (seconds-per-frame)))))
          (let* ((s4-0 (new 'stack-no-clear 'vector))
                 (s1-0 (closest-point-on-mesh (-> self nav) s4-0 (-> self root trans) (the-as nav-poly #f)))
                 (s2-0 (new 'stack 'clamp-travel-vector-to-mesh-return-info))
                 (s3-0 (new 'stack-no-clear 'vector))
                 )
            (vector-copy! s3-0 s5-2)
            (when s1-0
              (set! (-> s3-0 y) 0.0)
              (clamp-vector-to-mesh-no-gaps (-> self nav) s4-0 s1-0 s3-0 s2-0)
              (if (-> s2-0 found-boundary)
                  (vector-copy! s5-2 s3-0)
                  )
              )
            )
          (vector+! (-> self root trans) (-> self root trans) s5-2)
          )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (ja-channel-push! 1 (seconds 0.1))
    (ja-no-eval :group! spydroid-attack-land-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (go-virtual hostile)
    )
  :post enemy-simple-post
  )

(defmethod spydroid-method-231 ((this spydroid) (arg0 uint))
  (when (!= (-> this alert-level) arg0)
    (remove-from-process *part-engine* this)
    (add-connection
      *part-engine*
      this
      8
      this
      4699
      (new 'static 'vector :x -204.8 :y 122.88 :z 1720.32 :w 573440.0)
      )
    (add-connection
      *part-engine*
      this
      10
      this
      4699
      (new 'static 'vector :x -245.76 :y -122.88 :z 901.12 :w 573440.0)
      )
    (let ((v1-8 arg0))
      (cond
        ((zero? v1-8)
         (add-connection
           *part-engine*
           this
           4
           this
           4700
           (new 'static 'vector :x 819.2 :y -122.88 :z 3358.72 :w 573440.0)
           )
         (add-connection *part-engine* this 6 this 4703 (new 'static 'vector :z 614.4 :w 573440.0))
         (add-connection *part-engine* this 6 this 4706 (new 'static 'vector :z 614.4 :w 573440.0))
         )
        ((= v1-8 1)
         (add-connection
           *part-engine*
           this
           4
           this
           4701
           (new 'static 'vector :x 819.2 :y -122.88 :z 3358.72 :w 573440.0)
           )
         (add-connection *part-engine* this 6 this 4704 (new 'static 'vector :z 614.4 :w 573440.0))
         (add-connection *part-engine* this 6 this 4707 (new 'static 'vector :z 614.4 :w 573440.0))
         )
        ((= v1-8 3)
         (add-connection
           *part-engine*
           this
           4
           this
           4702
           (new 'static 'vector :x 819.2 :y -122.88 :z 3358.72 :w 573440.0)
           )
         (add-connection *part-engine* this 6 this 4705 (new 'static 'vector :z 614.4 :w 573440.0))
         (add-connection *part-engine* this 6 this 4708 (new 'static 'vector :z 614.4 :w 573440.0))
         )
        )
      )
    )
  (set! (-> this alert-level) arg0)
  (let ((v1-28 (-> this alert-level)))
    (cond
      ((zero? v1-28)
       (set-focus! this (get-target-focus (-> this squad)) (the-as enemy-aware #f))
       )
      ((= v1-28 3)
       (if (and (zero? (get-alert-level1 (-> this squad))) (= (-> this faction-mode) 0))
           (increment-alert-level (-> this squad) 1)
           )
       )
      )
    )
  )

(defmethod nav-enemy-method-177 ((this spydroid))
  (set! (-> this travel-anim-scale-speed) 1.75)
  (call-parent-method this)
  (none)
  )

(defmethod nav-enemy-method-176 ((this spydroid))
  (set! (-> this travel-anim-scale-speed) 0.5)
  (call-parent-method this)
  (none)
  )

(defmethod spydroid-method-232 ((this spydroid))
  (if (< (current-time) (-> this next-check-player-time))
      (return 0)
      )
  (set! (-> this next-check-player-time)
        (the-as time-frame (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 51) 25 (current-time)))
        )
  (when (handle->process (-> this focus handle))
    (let ((a0-10 (the-as process-focusable (handle->process (-> this focus handle))))
          (s5-0 (new 'stack-no-clear 'vector))
          )
      (vector-copy! s5-0 (get-trans a0-10 3))
      (let ((s4-1 (vector-! (new 'stack-no-clear 'vector) s5-0 (-> this root trans))))
        0.0
        0.0
        (let ((f30-0 1.0)
              (f0-2 (-> s4-1 y))
              )
          (if (not (logtest? (-> this draw status) (draw-control-status on-screen)))
              (set! f30-0 (/ f30-0 10))
              )
          (when (< f0-2 40960.0)
            (set! (-> s4-1 y) 0.0)
            (let ((f28-0 (vector-normalize-ret-len! s4-1 1.0)))
              (when (< f28-0 (* 102400.0 f30-0))
                (let ((s3-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> this root quat))))
                  (set! (-> s3-0 y) 0.0)
                  (vector-normalize! s3-0 1.0)
                  (let ((f30-1 (vector-dot s4-1 s3-0)))
                    (when (or (< 0.707 f30-1) (and (< -0.7 f30-1) (< f28-0 18432.0)) (< f28-0 16384.0))
                      (let ((a1-6 (new 'stack-no-clear 'collide-query)))
                        (vector-copy! (-> a1-6 start-pos) (-> this root trans))
                        (+! (-> a1-6 start-pos y) 4096.0)
                        (vector-! (-> a1-6 move-dist) s5-0 (-> a1-6 start-pos))
                        (let ((v1-45 a1-6))
                          (set! (-> v1-45 radius) 40.96)
                          (set! (-> v1-45 collide-with) (collide-spec backgnd obstacle))
                          (set! (-> v1-45 ignore-process0) #f)
                          (set! (-> v1-45 ignore-process1) #f)
                          (set! (-> v1-45 ignore-pat)
                                (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                                )
                          (set! (-> v1-45 action-mask) (collide-action solid))
                          )
                        (return (cond
                                  ((!= (fill-and-probe-using-line-sphere *collide-cache* a1-6) -100000000.0)
                                   0
                                   )
                                  ((< 0.707 f30-1)
                                   2
                                   )
                                  (else
                                    1
                                    )
                                  )
                                )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  0
  )

(defstate search (spydroid)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('panic)
       (let ((gp-0 (the-as traffic-danger-info (-> block param 0))))
         (when (spydroid-method-237 self gp-0)
           (vector-copy! (-> self move-dest) (-> gp-0 sphere))
           (let ((a0-4 (-> self nav state))
                 (v1-5 (-> self move-dest))
                 )
             (logclear! (-> a0-4 flags) (nav-state-flag directional-mode))
             (logior! (-> a0-4 flags) (nav-state-flag target-poly-dirty))
             (vector-copy! (-> a0-4 target-pos) v1-5)
             )
           0
           )
         )
       )
      (else
        (enemy-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (let ((a0-0 (-> self nav state))
          (v1-1 (-> self move-dest))
          )
      (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
    (set-time! (-> self state-time))
    (spydroid-method-231 self (the-as uint 1))
    (set-look-at-mode! self 2)
    )
  :trans (behavior ()
    (if (or (time-elapsed? (-> self state-time) (seconds 15))
            (let ((f0-0 (vector-vector-xz-distance-squared (-> self root trans) (-> self move-dest)))
                  (f1-0 20480.0)
                  )
              (< f0-0 (* f1-0 f1-0))
              )
            )
        (go-virtual scan)
        )
    (if (= (spydroid-method-232 self) 2)
        (go-virtual spydroid-notice)
        )
    (when (> (get-alert-level1 (-> self squad)) 0)
      (spydroid-method-231 self (the-as uint 3))
      (set-focus! self (get-target-focus (-> self squad)) (the-as enemy-aware #f))
      (go-virtual hostile)
      )
    )
  :code (behavior ()
    (citizen-travel-anim (the-as int (-> self draw art-group data (-> self enemy-info walk-anim))) 300)
    )
  :post (behavior ()
    (nav-enemy-method-187 self)
    )
  )

(defstate scan (spydroid)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (nav-enemy-method-182 self)
    (spydroid-method-231 self (the-as uint 1))
    (stop-look-at! self)
    )
  :trans (behavior ()
    (if (= (spydroid-method-232 self) 2)
        (go-virtual spydroid-notice)
        )
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (ja-no-eval :group! spydroid-idle-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (if (>= (-> self alert-level) (the-as uint 3))
        (go-virtual hostile)
        )
    (let ((a1-4 (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self root quat))))
      (vector-float*! a1-4 a1-4 -1.0)
      (citizen-method-208 self a1-4)
      )
    (go-virtual active)
    )
  :post enemy-simple-post
  )

(defstate spydroid-notice (spydroid)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (sound-play "spydroid-jabber")
    (set-time! (-> self state-time))
    (nav-enemy-method-182 self)
    (set-look-at-mode! self 1)
    (spydroid-method-231 self (the-as uint 2))
    (remove-from-process *part-engine* self)
    (add-connection
      *part-engine*
      self
      8
      self
      4699
      (new 'static 'vector :x -204.8 :y 122.88 :z 1720.32 :w 573440.0)
      )
    (add-connection
      *part-engine*
      self
      10
      self
      4699
      (new 'static 'vector :x -245.76 :y -122.88 :z 901.12 :w 573440.0)
      )
    (set-time! (-> self last-sensor-time))
    )
  :trans (behavior ()
    (if (< (+ (current-time) (seconds -0.15)) (-> self last-sensor-time))
        (spydroid-method-235 self)
        )
    (if (>= (+ (current-time) (seconds -0.2)) (-> self last-sensor-time))
        (set-time! (-> self last-sensor-time))
        )
    (if (>= (-> self alert-level) (the-as uint 3))
        (go-virtual hostile)
        )
    (when (time-elapsed? (-> self state-time) (seconds 0.1))
      (when (handle->process (-> self focus handle))
        (let* ((a0-9 (the-as process-focusable (handle->process (-> self focus handle))))
               (f0-0 (vector-vector-xz-distance-squared (get-trans a0-9 3) (-> self root trans)))
               (f1-0 143360.0)
               )
          (when (< (* f1-0 f1-0) f0-0)
            (spydroid-method-231 self (the-as uint 3))
            (go-virtual hostile)
            )
          )
        )
      (set-time! (-> self state-time))
      )
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (ja-no-eval :group! spydroid-idle-ja
                :num! (seek! max (kg-squad-control-method-54 (-> self squad)))
                :frame-num 0.0
                )
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! max (kg-squad-control-method-54 (-> self squad))))
      )
    (spydroid-method-231 self (the-as uint 3))
    (go-virtual hostile)
    )
  :post enemy-simple-post
  )

(defstate wait (spydroid)
  :virtual #t
  :enter (behavior ()
    (go-virtual scan)
    )
  )

(defmethod init-enemy-collision! ((this spydroid))
  "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)
          )
    (set! (-> s5-0 penetrated-by) (penetrate
                                    generic-attack
                                    lunge
                                    flop
                                    punch
                                    spin
                                    roll
                                    uppercut
                                    bonk
                                    tube
                                    flut-attack
                                    board
                                    mech-punch
                                    dark-punch
                                    dark-smack
                                    flut
                                    )
          )
    (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 enemy))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec backgnd jak bot civilian enemy obstacle hit-by-others-list player-list)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid semi-solid no-standon))
      (set-vector! (-> s4-0 local-sphere) 0.0 2048.0 0.0 6144.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 backgnd jak bot obstacle hit-by-others-list player-list)
            )
      (set! (-> v1-13 prim-core action) (collide-action solid))
      (set! (-> v1-13 transform-index) 3)
      (set-vector! (-> v1-13 local-sphere) 0.0 0.0 0.0 4096.0)
      )
    (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 civilian enemy hit-by-others-list player-list))
      (set! (-> v1-15 prim-core action) (collide-action deadly))
      (set! (-> v1-15 transform-index) 3)
      (set-vector! (-> v1-15 local-sphere) 0.0 0.0 0.0 8192.0)
      )
    (set! (-> s5-0 nav-radius) 8192.0)
    (let ((v1-17 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-17 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-17 prim-core collide-with))
      )
    (set! (-> s5-0 event-priority) (the-as uint 8))
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod coin-flip? ((this spydroid))
  "Return #t half the time, #f the other."
  #f
  )

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

;; WARN: Return type mismatch kg-squad-member vs spydroid.
(defmethod relocate ((this spydroid) (offset int))
  (when (nonzero? (-> this explode-part))
    (if (nonzero? (-> this explode-part))
        (&+! (-> this explode-part) offset)
        )
    )
  (the-as spydroid ((method-of-type kg-squad-member relocate) this offset))
  )

;; WARN: Return type mismatch float vs none.
(defmethod citizen-method-194 ((this spydroid))
  (call-parent-method this)
  (add-connection
    *part-engine*
    this
    4
    this
    4700
    (new 'static 'vector :x 819.2 :y -122.88 :z 3358.72 :w 573440.0)
    )
  (add-connection *part-engine* this 6 this 4703 (new 'static 'vector :z 614.4 :w 573440.0))
  (add-connection *part-engine* this 6 this 4706 (new 'static 'vector :z 614.4 :w 573440.0))
  (set! (-> this exiting-wait?) #f)
  (let* ((v1-7 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
         (v1-8 (the-as number (logior #x3f800000 v1-7)))
         (f0-2 (+ -1.0 (the-as float v1-8)))
         )
    (cond
      ((< f0-2 0.1)
       (set! (-> this fact pickup-type) (pickup-type eco-pill-light))
       (set! (-> this fact pickup-amount) 1.0)
       (set! (-> this fact pickup-spawn-amount) 1.0)
       )
      ((< f0-2 0.18)
       (set! (-> this fact pickup-type) (pickup-type health))
       (set! (-> this fact pickup-amount) 1.0)
       (set! (-> this fact pickup-spawn-amount) 1.0)
       )
      (else
        (set! (-> this fact pickup-type) (pickup-type ammo-random))
        (set! (-> this fact pickup-amount) 5.0)
        (set! (-> this fact pickup-spawn-amount) 1.0)
        )
      )
    )
  (set! (-> this enemy-flags)
        (the-as enemy-flag (logclear (-> this enemy-flags) (enemy-flag auto-death-phase-out)))
        )
  (set! (-> this choose-new-enemy-delay-time) (seconds 0.1))
  (let ((v1-33 (-> this nav)))
    (set! (-> v1-33 speed-scale) 1.0)
    )
  0
  (spydroid-method-231 this (the-as uint 0))
  (logclear! (-> this focus-status) (focus-status dangerous))
  (set! (-> this next-check-player-time) 0)
  (set! (-> this travel-anim-scale-speed) 0.5)
  (none)
  )

(defmethod spydroid-method-235 ((this spydroid))
  (cond
    ((not (and (-> this next-state) (let ((v1-3 (-> this next-state name)))
                                      (or (= v1-3 'wait-for-vulnerable) (= v1-3 'scan))
                                      )
               )
          )
     (set! (-> this sensor-lights 1 offset z) 0.15)
     (set! (-> this sensor-lights 2 offset z) 0.15)
     )
    (else
      (set! (-> this sensor-lights 1 offset z) 0.0)
      (set! (-> this sensor-lights 2 offset z) 0.0)
      )
    )
  (dotimes (s5-0 3)
    (let ((s3-0 (-> this sensor-lights s5-0))
          (s4-0 (new 'stack-no-clear 'matrix))
          )
      (let ((s2-0 (new 'stack-no-clear 'vector)))
        (let ((a1-1 (-> this node-list data (-> s3-0 joint))))
          (matrix-copy! s4-0 (-> a1-1 bone transform))
          (vector<-cspace! (-> s4-0 trans) a1-1)
          )
        (vector-copy! s2-0 (-> s3-0 offset))
        (set! (-> s2-0 w) 1.0)
        (vector-matrix*! (-> s4-0 trans) s2-0 s4-0)
        )
      (launch-particles (-> *part-id-table* (-> s3-0 part-index)) s4-0 :origin-is-matrix #t)
      )
    )
  #f
  )

(defmethod init-enemy! ((this spydroid))
  "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-spydroid" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (setup-enemy! this *spydroid-nav-enemy-info*)
  (call-parent-method this)
  (let ((v1-5 (-> this neck)))
    (set! (-> v1-5 up) (the-as uint 1))
    (set! (-> v1-5 nose) (the-as uint 2))
    (set! (-> v1-5 ear) (the-as uint 0))
    (set-vector! (-> v1-5 twist-max) 3640.889 11832.889 0.0 1.0)
    (set! (-> v1-5 ignore-angle) 15473.777)
    )
  (let ((v1-7 (-> this nav)))
    (set! (-> v1-7 speed-scale) 1.0)
    )
  0
  (logior! (-> this nav flags) (nav-control-flag momentum-ignore-heading))
  (set! (-> this part-ids 0) 4700)
  (set! (-> this part-ids 1) 4703)
  (set! (-> this part-ids 2) 4706)
  (set! (-> this part-ids 3) 4701)
  (set! (-> this part-ids 4) 4704)
  (set! (-> this part-ids 5) 4707)
  (set! (-> this part-ids 6) 4702)
  (set! (-> this part-ids 7) 4705)
  (set! (-> this part-ids 8) 4708)
  (set! (-> this sensor-lights 0 part-index) (-> this part-ids 6))
  (set! (-> this sensor-lights 0 joint) 4)
  (set-vector! (-> this sensor-lights 0 offset) 0.2 -0.03 0.82 1.0)
  (set! (-> this sensor-lights 1 part-index) (-> this part-ids 7))
  (set! (-> this sensor-lights 1 joint) 6)
  (set! (-> this sensor-lights 1 offset quad) (the-as uint128 0))
  (set! (-> this sensor-lights 2 part-index) (-> this part-ids 8))
  (set! (-> this sensor-lights 2 joint) 6)
  (set! (-> this sensor-lights 2 offset quad) (the-as uint128 0))
  (set! (-> this anim-shuffle) 3)
  (set! (-> this anim-walk) 4)
  (set! (-> this speed-walk) 16384.0)
  (set! (-> this dist-walk-anim) 8192.0)
  (set! (-> this dist-run-anim) 16384.0)
  (set! (-> this anim-run) 5)
  (set! (-> this speed-run) 32768.0)
  (logclear! (-> this focus-status) (focus-status dangerous))
  (set! (-> this water-anim) 5)
  0
  (none)
  )

(defmethod go-inactive ((this spydroid))
  (let ((v1-1 (-> this root root-prim)))
    (set! (-> v1-1 prim-core collide-as) (collide-spec))
    (set! (-> v1-1 prim-core collide-with) (collide-spec))
    )
  0
  (call-parent-method this)
  (none)
  )

(defstate hunting (spydroid)
  :virtual #t
  :parent (spydroid active)
  :event enemy-event-handler
  :enter (behavior ()
    (let ((a0-0 (-> self state parent)))
      (when a0-0
        (let ((t9-0 (-> a0-0 enter)))
          (if t9-0
              ((the-as (function none) t9-0))
              )
          )
        )
      )
    (spydroid-method-231 self (the-as uint 3))
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (if (handle->process (-> self focus handle))
        (go-virtual hostile)
        )
    (let ((f0-0 2867.2)
          (v1-9 (-> self root transv))
          )
      (if (< f0-0 (sqrtf (+ (* (-> v1-9 x) (-> v1-9 x)) (* (-> v1-9 z) (-> v1-9 z)))))
          (set-time! (-> self cp-next-time))
          )
      )
    (when (< (+ (-> self cp-next-time) (seconds 2)) (current-time))
      (let ((a1-2 (vector-! (new 'stack-no-clear 'vector) (-> self controller path-prev-point) (-> self dest-point))))
        (set-time! (-> self cp-next-time))
        (citizen-method-208 self a1-2)
        )
      )
    )
  )

(defmethod spydroid-method-237 ((this spydroid) (arg0 traffic-danger-info))
  (when (zero? (-> this faction-mode))
    (let ((f30-0 (+ 204800.0 (-> arg0 notify-radius))))
      (and (< 0.98 (-> arg0 danger-level))
           (and (or (= (-> arg0 danger-type) 0) (= (-> arg0 danger-type) 3) (= (-> arg0 danger-type) 5))
                (< (fabs (- (-> arg0 sphere y) (-> this root trans y))) 61440.0)
                (< (vector-vector-xz-distance-squared (-> this root trans) (-> arg0 sphere)) (* f30-0 f30-0))
                )
           )
      )
    )
  )

(defstate active (spydroid)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('panic)
       (let ((gp-0 (the-as traffic-danger-info (-> block param 0))))
         (when (spydroid-method-237 self gp-0)
           (vector-copy! (-> self move-dest) (-> gp-0 sphere))
           (go-virtual search)
           )
         )
       )
      (else
        (enemy-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (call-parent-state-handler enter)
    (spydroid-method-231 self (the-as uint 0))
    (set-time! (-> self state-time))
    (logior! (-> self flags) (citizen-flag neck-no-auto-look-at))
    )
  :trans (behavior ()
    (call-parent-state-handler trans)
    (when (or (!= (-> self faction-mode) 0) (logtest? (-> self flags) (citizen-flag in-mission)))
      (spydroid-method-236 self)
      (go-virtual hostile)
      )
    (case (spydroid-method-232 self)
      ((2)
       (go-virtual spydroid-notice)
       )
      )
    (when (> (get-alert-level1 (-> self squad)) 0)
      (spydroid-method-231 self (the-as uint 3))
      (set-focus! self (get-target-focus (-> self squad)) (the-as enemy-aware #f))
      (go-virtual hostile)
      )
    )
  )

;; WARN: disable def twice: 120. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare.
(defmethod spydroid-method-236 ((this spydroid))
  (local-vars (v0-6 object))
  (when (not (handle->process (-> this current-enemy)))
    (set! (-> this focus handle) (the-as handle #f))
    (set! (-> this current-enemy) (the-as handle #f))
    )
  (let ((a0-6 (get-current-enemy this)))
    (if a0-6
        (set! (-> this current-enemy) (process->handle a0-6))
        (set! (-> this current-enemy) (the-as handle #f))
        )
    )
  (when (logtest? (-> this attacker-info flags) (city-attacker-info-flag cai2))
    (set! (-> this attacker-info next-update-target-time) (+ (current-time) (seconds 3)))
    (logclear! (-> this attacker-info flags) (city-attacker-info-flag cai2))
    )
  (let ((a0-18 (as-type (handle->process (-> this current-enemy)) process-focusable)))
    (cond
      ((and a0-18
            (not (logtest? (-> (the-as process-focusable a0-18) focus-status) (focus-status disable dead inactive)))
            )
       (set-focus!
         this
         (the-as process-focusable (as-type (handle->process (-> this current-enemy)) process-focusable))
         (the-as enemy-aware #f)
         )
       (update-focus this)
       (let ((f0-0 (vector-vector-xz-distance-squared (-> this root trans) (-> this focus-pos)))
             (f1-0 266240.0)
             )
         (cond
           ((< f0-0 (* f1-0 f1-0))
            (when (not (logtest? (-> this squad alert-state flags) (squad-alert-flag war)))
              (set! v0-6 (logior (-> this flags) (citizen-flag persistent)))
              (set! (-> this flags) (the-as citizen-flag v0-6))
              v0-6
              )
            )
           (else
             (set! v0-6 (logclear (-> this flags) (citizen-flag persistent)))
             (set! (-> this flags) (the-as citizen-flag v0-6))
             v0-6
             )
           )
         )
       )
      (else
        (set! (-> this focus handle) (the-as handle #f))
        (logclear! (-> this flags) (citizen-flag persistent))
        (when (and (-> this next-state) (= (-> this next-state name) 'hostile))
          (if (nonzero? (-> this faction-mode))
              (go (method-of-object this hunting))
              (go (method-of-object this active))
              )
          )
        )
      )
    )
  )

(defmethod citizen-method-195 ((this spydroid))
  (call-parent-method this)
  (let ((v1-0 (-> this nav)))
    (set! (-> v1-0 sphere-mask) (the-as uint #x1000f8))
    )
  0
  (none)
  )

(defmethod citizen-method-215 ((this spydroid))
  (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 11)
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defmethod go-from-behavior ((this spydroid) (arg0 traffic-object-spawn-params))
  (case (-> arg0 behavior)
    ((6)
     (vector-copy! (-> this root trans) (-> arg0 position))
     (go (method-of-object this exit-transport))
     )
    (else
      (call-parent-method this arg0)
      )
    )
  (none)
  )

(defstate exit-transport (spydroid)
  :virtual #t
  :enter (behavior ()
    (nav-enemy-method-182 self)
    (logclear! (-> self root status) (collide-status on-surface touch-surface impact-surface))
    )
  :trans (behavior ()
    (if (logtest? (-> self root status) (collide-status on-surface touch-surface impact-surface))
        (go-virtual hostile)
        )
    )
  :code (behavior ()
    (ja-channel-push! 1 0)
    (ja-no-eval :group! spydroid-knocked0-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (sleep-code)
    )
  :post (behavior ()
    (enemy-falling-post)
    )
  )
