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

;; name: egg-spider.gc
;; name in dgo: egg-spider
;; dgos: NSA, LFORP, LBBSPID

(declare-type spider-manager process-drawable)

;; DECOMP BEGINS

(define *egg-spider-always-trackable?* #f)

(defun check-drop-level-egg-spider-dirt-rubble ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 vector))
  (let ((f30-0 (-> arg1 key origin trans y)))
    (when (< (-> arg2 y) f30-0)
      (let ((gp-0 (new 'stack-no-clear 'vector)))
        (sp-kill-particle arg0 arg1)
        (set-vector! gp-0 (-> arg2 x) f30-0 (-> arg2 z) 1.0)
        (launch-particles (-> *part-id-table* 2482) gp-0)
        (launch-particles (-> *part-id-table* 2483) gp-0)
        (launch-particles (-> *part-id-table* 2484) gp-0)
        )
      )
    )
  (none)
  )

(defpartgroup group-egg-spider-explosion
  :id 638
  :flags (sp0)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 2485 :fade-after (meters 50) :falloff-to (meters 100) :period (seconds 20) :length (seconds 0.035)))
  )

(defpart 2485
  :init-specs ((:texture (water-drops level-default-sprite))
    (:num 10.0)
    (:z (meters 1) (meters 1))
    (:scale-x (meters 1) (meters 1))
    (:rot-z (degrees 0) (degrees 3600))
    (:scale-y :copy scale-x)
    (:r 64.0 64.0)
    (:g 100.0)
    (:b 10.0)
    (:a 64.0 64.0)
    (:vel-y (meters 0.033333335) (meters 0.033333335))
    (:scalevel-x (meters 0.016666668))
    (:scalevel-y :copy scalevel-x)
    (:fade-a -0.42666668 -0.42666668)
    (:accel-y (meters -0.0016666667))
    (:timer (seconds 1))
    (:flags (sp-cpuinfo-flag-2 launch-along-z))
    (:next-time (seconds 0.5))
    (:next-launcher 2486)
    (:conerot-x (degrees -45) (degrees 90))
    (:rotate-y (degrees 0) (degrees 3600))
    )
  )

(defpart 2486
  :init-specs ((:scalevel-x (meters 0.0033333334)) (:scalevel-y :copy scalevel-x))
  )

;; WARN: Return type mismatch float vs none.
(defun spt-birth-func-brightness-egg-spider ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo))
  (let ((s5-0 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 51) 200))
        (s3-0 (logand 0 (rand-uint31-gen *random-generator*)))
        (s4-0 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 11) 20))
        (v1-6 (+ (mod (the-as int (rand-uint31-gen *random-generator*)) 11) 60))
        )
    (set! (-> arg2 rotate-x) (the float (- s5-0 (the-as int s3-0))))
    (set! (-> arg2 rotate-y) (the float (- s5-0 s4-0)))
    (set! (-> arg2 rotate-z) (the float (- s5-0 v1-6)))
    )
  (none)
  )

(defpartgroup group-egg-spider-birth
  :id 639
  :duration (seconds 0.835)
  :linger-duration (seconds 2)
  :flags (sp0)
  :bounds (static-bspherem 0 3 0 8)
  :parts ((sp-item 2487 :fade-after (meters 50) :falloff-to (meters 100) :period (seconds 20) :length (seconds 0.835))
    (sp-item 2487 :fade-after (meters 50) :falloff-to (meters 100) :period (seconds 20) :length (seconds 0.667))
    (sp-item 2487 :fade-after (meters 50) :falloff-to (meters 100) :period (seconds 20) :length (seconds 0.5))
    (sp-item 2487 :fade-after (meters 50) :falloff-to (meters 100) :period (seconds 20) :length (seconds 0.335))
    (sp-item 2488 :fade-after (meters 50) :falloff-to (meters 100) :period (seconds 7.335) :length (seconds 0.4))
    (sp-item 2489 :fade-after (meters 50) :falloff-to (meters 100) :period (seconds 7.335) :length (seconds 1.067))
    )
  )

(defpart 2487
  :init-specs ((:texture (rockbit01 level-default-sprite))
    (:birth-func 'spt-birth-func-part-egg-spider-clumps)
    (:num 0.1 0.1)
    (:x (meters 0) (meters 1))
    (:scale-x (meters 0.1) (meters 0.2))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y (meters 0.1) (meters 0.2))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 128.0)
    (:vel-y (meters 0.06666667) (meters 0.033333335))
    (:rotvel-z (degrees -1.2) (degrees 2.4))
    (:accel-y (meters -0.002) (meters -0.002))
    (:friction 0.98)
    (:timer (seconds 1.167))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:userdata :data (new 'static 'boxed-array :type int32
                       10
                       1
                       0
                       #x408b00
                       #x408c00
                       #x40a100
                       #x40a200
                       #x40a300
                       #x40a400
                       #x40a500
                       #x40a600
                       #x40a700
                       #x40a800
                       #x40a900
                       #x40aa00
                       #x40ab00
                       #x40ac00
                       #x40ad00
                       #x40ae00
                       )
               )
    (:func 'spt-func-part-egg-spider-clumps)
    (:conerot-x (degrees 0) (degrees 15))
    (:conerot-y (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 360))
    (:conerot-radius (meters 0.1))
    )
  )

(defun spt-birth-func-part-egg-spider-clumps ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo) (arg3 object) (arg4 object))
  (birth-func-texture-group-2d arg0 arg1 arg2 arg3 arg4)
  (spt-birth-func-brightness-egg-spider arg0 arg1 arg2)
  (none)
  )

(defun spt-func-part-egg-spider-clumps ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo))
  (sparticle-texture-animate arg0 arg1 (-> arg2 launchrot))
  (check-drop-level-egg-spider-dirt-rubble arg0 arg1 (-> arg2 launchrot))
  (none)
  )

(defpart 2488
  :init-specs ((:texture (rockbit01 level-default-sprite))
    (:birth-func 'spt-birth-func-part-egg-spider-clumps-mass)
    (:num 0.25 0.25)
    (:x (meters 0) (meters 1))
    (:scale-x (meters 0.1) (meters 0.1))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y (meters 0.1) (meters 0.1))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 128.0)
    (:vel-y (meters 0.033333335) (meters 0.033333335))
    (:rotvel-z (degrees -1.2) (degrees 2.4))
    (:accel-y (meters -0.002) (meters -0.002))
    (:friction 0.98)
    (:timer (seconds 1.167))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:userdata :data (new 'static 'boxed-array :type int32
                       10
                       1
                       0
                       #x408b00
                       #x408c00
                       #x40a100
                       #x40a200
                       #x40a300
                       #x40a400
                       #x40a500
                       #x40a600
                       #x40a700
                       #x40a800
                       #x40a900
                       #x40aa00
                       #x40ab00
                       #x40ac00
                       #x40ad00
                       #x40ae00
                       )
               )
    (:func 'spt-birth-func-part-egg-spider-clumps-mass)
    (:conerot-x (degrees 0) (degrees 45))
    (:conerot-y (degrees 0) (degrees 360))
    (:rotate-y (degrees 0) (degrees 360))
    (:conerot-radius (meters 0.5))
    )
  )

(defun spt-birth-func-part-egg-spider-clumps-mass ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo) (arg3 object) (arg4 object))
  (birth-func-texture-group-2d arg0 arg1 arg2 arg3 arg4)
  (spt-birth-func-brightness-egg-spider arg0 arg1 arg2)
  (none)
  )

(defun spt-func-part-egg-spider-clumps-mass ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo))
  (sparticle-texture-animate arg0 arg1 (-> arg2 launchrot))
  (check-drop-level-egg-spider-dirt-rubble arg0 arg1 (-> arg2 launchrot))
  (none)
  )

(defpart 2482
  :init-specs ((:texture (rockbit01 level-default-sprite))
    (:birth-func 'spt-birth-func-part-egg-spider-clumps-pop)
    (:num 1.0 2.0)
    (:scale-x (meters 0.05) (meters 0.15))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y (meters 0.05) (meters 0.15))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 128.0)
    (:vel-y (meters 0.006666667) (meters 0.026666667))
    (:rotvel-z (degrees -1.2) (degrees 2.4))
    (:fade-a -0.42666668 -0.85333335)
    (:accel-y (meters -0.00066666666))
    (:timer (seconds 2))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:userdata :data (new 'static 'boxed-array :type int32
                       10
                       1
                       0
                       #x408b00
                       #x408c00
                       #x40a100
                       #x40a200
                       #x40a300
                       #x40a400
                       #x40a500
                       #x40a600
                       #x40a700
                       #x40a800
                       #x40a900
                       #x40aa00
                       #x40ab00
                       #x40ac00
                       #x40ad00
                       #x40ae00
                       )
               )
    (:func 'spt-birth-func-part-egg-spider-clumps-pop)
    (:conerot-x (degrees 10) (degrees 60))
    (:conerot-y (degrees 0) (degrees 360))
    )
  )

(defun spt-birth-func-part-egg-spider-clumps-pop ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo) (arg3 object) (arg4 object))
  (birth-func-texture-group-2d arg0 arg1 arg2 arg3 arg4)
  (spt-birth-func-brightness-egg-spider arg0 arg1 arg2)
  (none)
  )

(defun spt-func-part-egg-spider-clumps-pop ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo))
  (sparticle-texture-animate arg0 arg1 (-> arg2 launchrot))
  (check-drop-level-egg-spider-dirt-rubble arg0 arg1 (-> arg2 launchrot))
  (none)
  )

(defpart 2483
  :init-specs ((:texture (rockbit01 level-default-sprite))
    (:birth-func 'spt-birth-func-part-egg-spider-clumps-stays)
    (:num 1.0 1.0)
    (:scale-x (meters 0.05) (meters 0.15))
    (:rot-z (degrees 0) (degrees 360))
    (:scale-y (meters 0.05) (meters 0.15))
    (:r 128.0)
    (:g 128.0)
    (:b 128.0)
    (:a 128.0)
    (:vel-y (meters 0) (meters 0.04))
    (:rotvel-z (degrees -1.2) (degrees 2.4))
    (:friction 0.94 0.02)
    (:timer (seconds 8))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:userdata :data (new 'static 'boxed-array :type int32
                       10
                       1
                       0
                       #x408b00
                       #x408c00
                       #x40a100
                       #x40a200
                       #x40a300
                       #x40a400
                       #x40a500
                       #x40a600
                       #x40a700
                       #x40a800
                       #x40a900
                       #x40aa00
                       #x40ab00
                       #x40ac00
                       #x40ad00
                       #x40ae00
                       )
               )
    (:func 'spt-birth-func-part-egg-spider-clumps-stays)
    (:next-time (seconds 1.5) (seconds 0.497))
    (:next-launcher 2490)
    (:conerot-x (degrees 90))
    (:conerot-y (degrees 0) (degrees 360))
    )
  )

(defun spt-birth-func-part-egg-spider-clumps-stays ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo) (arg3 object) (arg4 object))
  (birth-func-texture-group-2d arg0 arg1 arg2 arg3 arg4)
  (spt-birth-func-brightness-egg-spider arg0 arg1 arg2)
  (none)
  )

(defun spt-func-part-egg-spider-clumps-stays ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sparticle-launchinfo))
  (sparticle-texture-animate arg0 arg1 (-> arg2 launchrot))
  (check-drop-level-egg-spider-dirt-rubble arg0 arg1 (-> arg2 launchrot))
  (none)
  )

(defpart 2490
  :init-specs ((:rotvel-z (degrees 0)) (:fade-a -0.10666667 -0.10666667))
  )

(defpart 2489
  :init-specs ((:texture (bigpuff level-default-sprite))
    (:num 0.4 0.4)
    (:scale-x (meters 1) (meters 0.5))
    (:scale-y (meters 1) (meters 0.5))
    (:r 80.0 10.0)
    (:g 60.0 10.0)
    (:b 40.0 10.0)
    (:a 16.0 40.0)
    (:vel-y (meters 0.026666667) (meters 0.026666667))
    (:scalevel-x (meters 0.006666667) (meters 0.0016666667))
    (:scalevel-y (meters 0.0033333334) (meters 0.0016666667))
    (:fade-a -0.053333335 -0.053333335)
    (:accel-y (meters 0) (meters 0.00033333333))
    (:friction 0.85 0.05)
    (:timer (seconds 8))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:conerot-x (degrees 0) (degrees 90))
    (:conerot-y (degrees 0) (degrees 360))
    (:conerot-radius (meters 0) (meters 0.5))
    )
  )

(defpart 2484
  :init-specs ((:texture (dirtpuff01 level-default-sprite))
    (:num 1.0)
    (:sound (static-sound-spec "debris-ground" :num 0.01 :group 0 :volume 100.0))
    (:scale-x (meters 0.5) (meters 0.25))
    (:scale-y (meters 0.25) (meters 0.25))
    (:r 100.0)
    (:g 80.0)
    (:b 60.0)
    (:a 30.0 40.0)
    (:vel-y (meters 0.013333334) (meters 0.026666667))
    (:scalevel-x (meters 0.0033333334) (meters 0.0016666667))
    (:scalevel-y (meters 0.0033333334) (meters 0.0016666667))
    (:fade-a -0.06666667 -0.06666667)
    (:accel-y (meters 0) (meters 0.00033333333))
    (:friction 0.9 0.05)
    (:timer (seconds 8))
    (:flags (sp-cpuinfo-flag-2 sp-cpuinfo-flag-13))
    (:conerot-x (degrees 70) (degrees 20))
    (:conerot-y (degrees 0) (degrees 360))
    )
  )

(deftype egg-spider-shot (metalhead-grenade-shot)
  ()
  )


(defmethod projectile-method-26 ((this egg-spider-shot))
  0
  (none)
  )

(defmethod setup-collision! ((this egg-spider-shot))
  (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) gren-cshape-reaction-canister)
          )
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate enemy-dark-shot))
    (let ((v1-7 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-7 prim-core collide-as) (collide-spec projectile))
      (set! (-> v1-7 prim-core collide-with)
            (collide-spec jak crate obstacle hit-by-others-list player-list pusher)
            )
      (set! (-> v1-7 prim-core action) (collide-action solid))
      (set-vector! (-> v1-7 local-sphere) 0.0 0.0 0.0 32768.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-7)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-10 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-10 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-10 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 2))
    (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 :board #x1)
        )
  (none)
  )

(defmethod play-impact-sound ((this egg-spider-shot) (arg0 projectile-options))
  (case arg0
    (((projectile-options po0))
     )
    (((projectile-options po0 po1))
     )
    )
  0
  (none)
  )

(defmethod projectile-method-25 ((this egg-spider-shot))
  0
  (none)
  )

;; WARN: Return type mismatch sound-id vs none.
(defmethod init-proj-settings! ((this egg-spider-shot))
  (set! (-> this attack-mode) 'eco-yellow)
  (set! (-> this blast-radius) 4096.0)
  (set! (-> this max-speed) 135168.0)
  (set! (-> this timeout) (seconds 4))
  (set! (-> this update-velocity) projectile-update-velocity-add-gravity)
  (set! (-> this root dynam gravity y) 1.0)
  (set! (-> this root dynam gravity-length) 0.0)
  (set! (-> this root dynam gravity-max) 0.0)
  (let ((f0-5 1092.2667))
    (quaternion-axis-angle! (-> this tumble-quat) 1.0 0.0 0.0 f0-5)
    )
  (set! (-> this sound-id) (new-sound-id))
  (none)
  )

(deftype egg-spider (nav-enemy)
  ((base-height        float)
   (target-pos         vector      :inline)
   (offset-target-pos  vector      :inline)
   (change-dir-time    time-frame)
   (last-change-dir    time-frame)
   (onscreen-time      time-frame)
   (next-explosion     time-frame)
   (move-angle         float)
   (heading            symbol)
   (size               float)
   (angle-spot         float)
   (trackable?         symbol)
   (vehicle-attack?    symbol)
   (seat-index         int32)
   (wvehicle           handle)
   (vec-up             vector      :inline)
   (vec-up-speed       vector      :inline)
   (traj               trajectory  :inline)
   (init-pos           vector      :inline)
   (jump-pos           float)
   )
  (:state-methods
    undefined
    attack
    on-vehicle
    jump-on-vehicle
    )
  (:methods
    (egg-spider-method-194 (_type_) none)
    (egg-spider-method-195 (_type_ nav-control vector) none)
    (kill-if-offscreen (_type_) object)
    )
  )


(defskelgroup skel-egg-spider egg-spider egg-spider-lod0-jg -1
              ((egg-spider-lod0-mg (meters 20)) (egg-spider-lod1-mg (meters 40)) (egg-spider-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 2)
              :shadow egg-spider-shadow-mg
              :origin-joint-index 3
              )

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

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

(defmethod get-inv-mass ((this egg-spider))
  50.0
  )

;; ERROR: Stack slot load at 16 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 16 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 16 mismatch: defined as size 4, got size 16
;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16
(defmethod event-handler ((this egg-spider) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  "Commmon handler for events."
  (local-vars (sv-16 float) (sv-32 float))
  (case arg2
    (('attack)
     (let ((s1-0 (the-as attack-info (-> arg3 param 1))))
       (set! (-> this vehicle-attack?) #f)
       (when (= (-> s1-0 mode) 'vehicle)
         (set! (-> this vehicle-attack?) #t)
         (vector-float*! (-> s1-0 vector) (-> s1-0 vector) 1.0)
         (let ((s0-0 lerp))
           (set! sv-16 (the-as float 40960.0))
           (set! sv-32 (the-as float 81920.0))
           (let ((a2-2 (rnd-float-range this 0.0 1.0)))
             (set! (-> s1-0 vector y) (s0-0 sv-16 sv-32 a2-2))
             )
           )
         )
       )
     ((method-of-type nav-enemy event-handler) this arg0 arg1 arg2 arg3)
     )
    (('impact-impulse)
     (let ((v1-11 (the-as object (-> arg3 param 0))))
       (when (< 0.0 (-> (the-as rigid-body-impact v1-11) impulse))
         (logior! (-> this root penetrated-by) (penetrate vehicle))
         (set! (-> this vehicle-attack?) #t)
         (set! (-> this hit-points) 0.0)
         (go (method-of-object this knocked))
         #t
         )
       )
     )
    (('death-end)
     ((method-of-type nav-enemy event-handler) this arg0 arg1 arg2 arg3)
     )
    (else
      ((method-of-type nav-enemy event-handler) this arg0 arg1 arg2 arg3)
      )
    )
  )

;; WARN: Return type mismatch int vs search-info-flag.
(defmethod get-search-info-flag ((this egg-spider))
  "Get search-info-flag for this process."
  (the-as search-info-flag (if (or *egg-spider-always-trackable?* (-> this trackable?))
                               (the-as int ((method-of-type nav-enemy get-search-info-flag) this))
                               0
                               )
          )
  )

(defmethod normalize-heading! ((this egg-spider) (arg0 nav-control))
  (let ((t9-0 (method-of-object this egg-spider-method-195))
        (v1-1 arg0)
        (a3-0 (-> arg0 state))
        (a2-0 (new 'stack-no-clear 'vector))
        )
    (vector-copy! a2-0 (-> a3-0 heading))
    (t9-0 this v1-1 a2-0)
    )
  0
  (none)
  )

(defmethod egg-spider-method-195 ((this egg-spider) (arg0 nav-control) (arg1 vector))
  (set! (-> arg1 y) 0.0)
  (vector-normalize! arg1 1.0)
  (let ((gp-0 (new 'stack-no-clear 'quaternion))
        (s5-1 (-> this root quat))
        )
    (quaternion-set! gp-0 0.0 (-> arg1 x) 0.0 (+ 1.0 (-> arg1 z)))
    (quaternion-normalize! gp-0)
    (quaternion-smooth-seek!
      s5-1
      s5-1
      gp-0
      (* (fmax 0.5 (/ (-> arg0 state speed) METER_LENGTH)) (seconds-per-frame))
      )
    )
  0
  (none)
  )

(defmethod nav-enemy-method-187 ((this egg-spider))
  (nav-enemy-method-188 this)
  (when (nav-enemy-method-185 this)
    (cond
      ((logtest? (enemy-flag ef39) (-> this enemy-flags))
       (set! (-> this enemy-flags) (the-as enemy-flag (logclear (-> this enemy-flags) (enemy-flag ef39))))
       (vector-copy! (-> this root gspot-pos) (-> this root trans))
       )
      (else
        (normalize-heading! this (-> this nav))
        (nav-enemy-method-161 this (-> this nav))
        )
      )
    )
  (enemy-common-post this)
  (update-transforms (-> this root))
  0
  (none)
  )

(defmethod egg-spider-method-194 ((this egg-spider))
  (let ((s2-0 (as-type (handle->process (-> this focus handle)) process-focusable)))
    (when s2-0
      (let ((s3-0 (vector-rotate-around-y! (new 'stack-no-clear 'vector) *z-vector* (-> this angle-spot)))
            (s1-0 (get-trans (the-as process-focusable s2-0) 0))
            )
        (vector+*!
          (new 'stack-no-clear 'vector)
          (get-trans (the-as process-focusable s2-0) 0)
          (get-transv (the-as process-focusable s2-0))
          (rnd-float-range this 2.0 3.0)
          )
        (let* ((s5-3 (new 'stack-no-clear 'vector))
               (s4-2 (vector-! (new 'stack-no-clear 'vector) s1-0 (-> this root trans)))
               (f30-0 (vector-length s4-2))
               )
          (let ((f28-0 (vector-vector-distance (-> this root trans) s1-0)))
            (new 'stack-no-clear 'vector)
            (let ((s1-2 (vector-z-quaternion! (new 'stack-no-clear 'vector) (get-quat (the-as process-focusable s2-0) 0))))
              (set! (-> s4-2 y) 0.0)
              (vector-normalize! s4-2 1.0)
              (set! (-> s1-2 y) 0.0)
              (vector-normalize! s1-2 1.0)
              (when (< 0.0 (vector-dot s3-0 s1-2))
                )
              )
            (vector+*! s5-3 (get-trans s2-0 0) s3-0 (+ 40960.0 (* 0.4 f28-0)))
            )
          (cond
            ((< f30-0 (-> this enemy-info notice-nav-radius))
             (vector-copy! (-> this target-pos) s5-3)
             (let ((s3-1 (new 'stack-no-clear 'vector)))
               (vector-copy! s3-1 s4-2)
               (let ((s5-4 (new 'stack-no-clear 'vector)))
                 (vector-copy! s5-4 (-> this root transv))
                 (vector-normalize! s5-4 f30-0)
                 (if (>= (vector-dot s3-1 s5-4) 0.98)
                     (go (method-of-object this attack))
                     )
                 )
               )
             )
            ((or (time-elapsed? (-> this last-change-dir) (-> this change-dir-time))
                 (< (vector-vector-distance-squared (-> this root trans) (-> this target-pos)) 0.1)
                 )
             (set-time! (-> this last-change-dir))
             (set! (-> this change-dir-time) (rand-vu-int-range (seconds 0.5) (seconds 0.7)))
             (let ((s3-2 (new 'stack-no-clear 'vector))
                   (f0-14 (* (/ f30-0 2) (tan (-> this move-angle))))
                   (s2-1 (new 'stack-no-clear 'vector))
                   )
               (if (-> this heading)
                   (set-vector! s3-2 (-> s4-2 z) (-> s4-2 y) (- (-> s4-2 x)) 1.0)
                   (set-vector! s3-2 (- (-> s4-2 z)) (-> s4-2 y) (-> s4-2 x) 1.0)
                   )
               (set! (-> this heading) (not (-> this heading)))
               (let ((f28-2 (rand-vu-float-range (* 0.75 f0-14) f0-14))
                     (s4-3 (vector-normalize-copy! (new 'stack-no-clear 'vector) s4-2 (* -0.6 f30-0)))
                     )
                 (vector-normalize! s3-2 f28-2)
                 (vector+! s3-2 s3-2 s4-3)
                 )
               (clamp-vector-to-mesh-cross-gaps (-> this nav state) s3-2)
               (vector+! s2-1 s5-3 s3-2)
               (vector-copy! (-> this target-pos) s2-1)
               )
             )
            )
          )
        )
      )
    )
  0
  (none)
  )

(defstate idle (egg-spider)
  :virtual #t
  :post (behavior ()
    (let ((t9-0 (-> (method-of-type enemy idle) post)))
      (if t9-0
          ((the-as (function none) t9-0))
          )
      )
    (kill-if-offscreen self)
    )
  )

(defmethod kill-if-offscreen ((this egg-spider))
  (cond
    ((not (logtest? (-> this draw status) (draw-control-status no-draw)))
     (if (logtest? (-> this draw status) (draw-control-status on-screen))
         (set! (-> this onscreen-time) (+ (current-time) (seconds 5)))
         )
     )
    (else
      (set! (-> this onscreen-time) (+ (current-time) (seconds 5)))
      )
    )
  (if (or (< (-> this onscreen-time) (current-time))
          (< 573440.0 (vector-vector-xz-distance (-> this root trans) (target-pos 0)))
          )
      (go (method-of-object this die-fast))
      )
  )

(defmethod on-dying ((this egg-spider))
  (if (or (>= 0.0 (-> this hit-points)) (nonzero? (-> this fated-time)))
      (send-event (ppointer->process (-> this parent)) 'dead)
      )
  ((method-of-type nav-enemy on-dying) this)
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defmethod enemy-common-post ((this egg-spider))
  "Common implementation of post. Runs ja-post."
  (let ((t9-0 (method-of-type nav-enemy enemy-common-post)))
    (t9-0 this)
    )
  (+! (-> this angle-spot) (* 182.04445 (* 100.0 (seconds-per-frame))))
  (kill-if-offscreen this)
  (none)
  )

(defmethod nav-enemy-method-164 ((this egg-spider))
  (let ((v1-1 (-> this nav state))
        (a0-2 (-> this root trans))
        )
    (logclear! (-> v1-1 flags) (nav-state-flag directional-mode))
    (logior! (-> v1-1 flags) (nav-state-flag target-poly-dirty))
    (vector-copy! (-> v1-1 target-pos) a0-2)
    )
  0
  (none)
  )

(defstate attack (egg-spider)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (nav-enemy-method-181 self)
    (sound-play "flitter-attack")
    (logior! (-> self focus-status) (focus-status dangerous))
    (let* ((v1-7 *game-info*)
           (a0-4 (+ (-> v1-7 attack-id) 1))
           )
      (set! (-> v1-7 attack-id) a0-4)
      (set! (-> self attack-id) a0-4)
      )
    (sound-play "spider-attack")
    )
  :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 ((a0-4 (as-type (handle->process (-> self focus handle)) process-focusable)))
      (cond
        ((and a0-4
              (not (time-elapsed? (-> self state-time) (seconds 1.5)))
              a0-4
              (not (logtest? (-> (the-as process-focusable a0-4) focus-status) (focus-status disable dead ignore grabbed)))
              )
         (let ((gp-1 (-> self nav state))
               (v1-10 (get-trans (the-as process-focusable a0-4) 0))
               )
           (logclear! (-> gp-1 flags) (nav-state-flag directional-mode))
           (logior! (-> gp-1 flags) (nav-state-flag target-poly-dirty))
           (vector-copy! (-> gp-1 target-pos) v1-10)
           )
         0
         )
        (else
          (go-stare self)
          )
        )
      )
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.1))
    (ja-no-eval :group! egg-spider-attack-jump-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (nav-enemy-method-182 self)
    (ja-channel-push! 1 (seconds 0.1))
    (if (logtest? (-> self enemy-flags) (enemy-flag dangerous-backup))
        (logior! (-> self focus-status) (focus-status dangerous))
        (logclear! (-> self focus-status) (focus-status dangerous))
        )
    (dotimes (gp-0 (rnd-int self 3))
      (ja-no-eval :group! egg-spider-idle-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (go-state-for-focused self)
    )
  :post nav-enemy-travel-post
  )

(defstate jump-on-vehicle (egg-spider)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    (nav-enemy-method-182 self)
    (vector-copy! (-> self init-pos) (-> self root trans))
    (set! (-> self jump-pos) 0.0)
    (let ((v1-6 (-> self root root-prim)))
      (set! (-> v1-6 prim-core collide-as) (collide-spec))
      (set! (-> v1-6 prim-core collide-with) (collide-spec))
      )
    0
    )
  :exit (behavior ()
    '()
    )
  :trans (behavior ()
    (let ((s4-0 (handle->process (-> self wvehicle)))
          (gp-0 (new 'stack-no-clear 'vector))
          (s5-0 (new 'stack-no-clear 'vector))
          )
      (new 'stack-no-clear 'vector)
      (new 'stack-no-clear 'vector)
      (new 'stack-no-clear 'vector)
      (cond
        (s4-0
          (wvehicle-method-171 (the-as wvehicle s4-0) gp-0 (-> self seat-index))
          (wvehicle-method-172 (the-as wvehicle s4-0) (the-as quaternion s5-0) (-> self seat-index))
          (quaternion-pseudo-seek (-> self root quat) (-> self root quat) (the-as quaternion s5-0) (seconds-per-frame))
          (+! (-> self jump-pos) (* 6.0 (seconds-per-frame)))
          (setup-from-to-height! (-> self traj) (-> self init-pos) gp-0 8192.0 -16384.0)
          (compute-trans-at-time (-> self traj) (-> self jump-pos) (-> self root trans))
          (if (< (-> self traj time) (-> self jump-pos))
              (go-virtual on-vehicle)
              )
          )
        (else
          (set! (-> self vehicle-attack?) #f)
          (go-virtual knocked)
          )
        )
      )
    )
  :code (behavior ()
    (ja-no-eval :group! egg-spider-jump-car-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (until #f
      (suspend)
      )
    #f
    )
  :post nav-enemy-simple-post
  )

(define *egg-spider-next-knocked-vehicle* (the-as time-frame 0))

(defstate on-vehicle (egg-spider)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    (nav-enemy-method-182 self)
    (let* ((v1-4 *game-info*)
           (a0-2 (+ (-> v1-4 attack-id) 1))
           )
      (set! (-> v1-4 attack-id) a0-2)
      (set! (-> self attack-id) a0-2)
      )
    (sound-play "spider-land-veh")
    (vector-copy! (-> self init-pos) (-> self root trans))
    )
  :exit (behavior ()
    (let ((a0-1 (handle->process (-> self wvehicle))))
      (if a0-1
          (remove-attached-from-arr (the-as wvehicle a0-1) self)
          )
      )
    )
  :trans (behavior ()
    (let ((s5-0 (handle->process (-> self wvehicle)))
          (s1-0 (new 'stack-no-clear 'vector))
          (s4-0 (new 'stack-no-clear 'vector))
          (s3-0 (new 'stack-no-clear 'quaternion))
          (gp-0 (new 'stack-no-clear 'vector))
          (s2-0 (new 'stack-no-clear 'vector))
          )
      (cond
        (s5-0
          (if (focus-test? (the-as process-focusable s5-0) dead)
              (go-virtual knocked)
              )
          (wvehicle-method-171 (the-as wvehicle s5-0) s1-0 (-> self seat-index))
          (wvehicle-method-172 (the-as wvehicle s5-0) (the-as quaternion s4-0) (-> self seat-index))
          (rigid-body-control-method-23 (-> (the-as wvehicle s5-0) rbody) (-> self root trans) gp-0)
          (vector-y-quaternion! s2-0 (the-as quaternion s4-0))
          (vector+*! s2-0 s2-0 gp-0 -0.00001)
          (vector-normalize! s2-0 1.0)
          (vector+*!
            (-> self vec-up)
            (-> self vec-up)
            (vector-! (new 'stack-no-clear 'vector) s2-0 (-> self vec-up))
            (* 2.0 (seconds-per-frame))
            )
          (vector-normalize! (-> self vec-up) 1.0)
          (vector-copy! (-> self root trans) s1-0)
          (quaternion-from-two-vectors! s3-0 (-> self vec-up) s2-0)
          (quaternion*! (-> self root quat) (the-as quaternion s4-0) s3-0)
          (send-event
            s5-0
            'attack
            #f
            (static-attack-info
              :mask (vehicle-impulse-factor)
              ((id (new-attack-id)) (damage 2.0) (vehicle-damage-factor 0.00333) (vehicle-impulse-factor 0.0))
              )
            )
          (when (and (< 49152.0 (vector-length gp-0)) (< *egg-spider-next-knocked-vehicle* (current-time)))
            (set! *egg-spider-next-knocked-vehicle* (+ (current-time) (rand-vu-int-range (seconds 0.1) (seconds 0.3))))
            (set! (-> self vehicle-attack?) #f)
            (go-virtual knocked)
            )
          )
        (else
          (go-virtual knocked)
          )
        )
      )
    )
  :code (behavior ()
    (ja-no-eval :group! egg-spider-land-car-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (until #f
      (ja-no-eval :group! egg-spider-bite-car-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    #f
    )
  :post nav-enemy-simple-post
  )

(defstate hostile (egg-spider)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self last-change-dir))
    (set! (-> self change-dir-time) 0)
    (let ((t9-0 (-> (method-of-type nav-enemy hostile) enter)))
      (if t9-0
          (t9-0)
          )
      )
    )
  :trans (behavior ()
    (if (time-elapsed? (-> self state-time) (seconds 0.5))
        (set! (-> self trackable?) #t)
        )
    (let ((t9-0 (-> (method-of-type nav-enemy hostile) trans)))
      (if t9-0
          (t9-0)
          )
      )
    (egg-spider-method-194 self)
    (let ((gp-0 (handle->process (-> self focus handle))))
      (if (type? gp-0 process-focusable)
          (empty)
          )
      )
    (when (and *target* (focus-test? *target* pilot))
      (let ((gp-1 (as-type (handle->process (-> *target* pilot vehicle)) wvehicle)))
        (when (and gp-1
                   (< (vector-length (-> (the-as wvehicle gp-1) root transv)) 81920.0)
                   (< (vector-vector-distance (-> (the-as wvehicle gp-1) root trans) (-> self root trans)) 73728.0)
                   )
          (let ((s5-1 (wvehicle-method-173 (the-as wvehicle gp-1) (-> self root trans)))
                (s1-0 (new 'stack-no-clear 'vector))
                (s3-0 (new 'stack-no-clear 'vector))
                (s2-0 (new 'stack-no-clear 'vector))
                (s4-0 (new 'stack-no-clear 'vector))
                )
            (when (and (!= s5-1 -1) (not (get-attached-by-idx (the-as wvehicle gp-1) s5-1)))
              (set! (-> self seat-index) s5-1)
              (set! (-> self wvehicle) (process->handle gp-1))
              (wvehicle-method-171 (the-as wvehicle gp-1) s1-0 s5-1)
              (vector-! s3-0 (-> self root trans) s1-0)
              (vector-normalize! s3-0 1.0)
              (vector-! s2-0 (-> (the-as wvehicle gp-1) root trans) s1-0)
              (vector-normalize! s2-0 1.0)
              (vector-y-quaternion! s4-0 (-> (the-as wvehicle gp-1) root quat))
              (when (and (< (vector-dot s2-0 s3-0) -0.7) (< 0.5 (-> s4-0 y)))
                (add-attached-at-idx (the-as wvehicle gp-1) s5-1 self)
                (go-virtual jump-on-vehicle)
                )
              )
            )
          )
        )
      )
    )
  :post (behavior ()
    (let ((a0-0 (-> self nav state))
          (v1-1 (-> self target-pos))
          )
      (logclear! (-> a0-0 flags) (nav-state-flag directional-mode))
      (logior! (-> a0-0 flags) (nav-state-flag target-poly-dirty))
      (vector-copy! (-> a0-0 target-pos) v1-1)
      )
    0
    (nav-enemy-travel-post)
    )
  )

(defstate knocked (egg-spider)
  :virtual #t
  :enter (behavior ()
    (sound-play "spider-explode")
    (if (-> self vehicle-attack?)
        (sound-play "spider-crunch")
        (sound-play "spider-get-hit")
        )
    (cond
      ((logtest? (-> group-egg-spider-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-egg-spider-explosion)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-egg-spider-explosion)
        )
      )
    (let ((t9-12 (-> (method-of-type nav-enemy knocked) enter)))
      (if t9-12
          (t9-12)
          )
      )
    (if (-> self vehicle-attack?)
        (go-virtual die-fast)
        )
    )
  )

(defstate ambush (egg-spider)
  :virtual #t
  :enter (behavior ()
    (when (logtest? (-> self enemy-flags) (enemy-flag enable-on-notice))
      (logclear! (-> self enemy-flags) (enemy-flag enable-on-notice))
      (let ((gp-0 (-> self on-notice)))
        (if gp-0
            (script-eval gp-0 :vector (-> self root trans))
            )
        )
      )
    (set! (-> self base-height) (-> self root trans y))
    (let ((v1-13 (-> self root root-prim)))
      (set! (-> v1-13 prim-core collide-as) (collide-spec))
      (set! (-> v1-13 prim-core collide-with) (collide-spec))
      )
    0
    (logior! (-> self draw status) (draw-control-status no-draw))
    (set-time! (-> self state-time))
    (set-time! (-> self onscreen-time))
    (set! (-> self next-explosion) (+ (current-time) (rand-vu-int-range (seconds 0.5) (seconds 5))))
    )
  :exit (behavior ()
    (let ((t9-0 (-> (method-of-type nav-enemy ambush) exit)))
      (if t9-0
          (t9-0)
          )
      )
    (set-time! (-> self state-time))
    )
  :code (behavior ()
    (cond
      ((logtest? (-> group-egg-spider-birth flags) (sp-group-flag sp13))
       (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
       (part-tracker-spawn part-tracker-subsampler :to *entity-pool* :group group-egg-spider-birth)
       )
      (else
        (vector-copy! (-> *launch-matrix* trans) (-> self root trans))
        (part-tracker-spawn part-tracker :to *entity-pool* :group group-egg-spider-birth)
        )
      )
    (suspend-for (seconds 0.6)
      )
    (let ((v1-38 (-> self root root-prim)))
      (set! (-> v1-38 prim-core collide-as) (-> self root backup-collide-as))
      (set! (-> v1-38 prim-core collide-with) (-> self root backup-collide-with))
      )
    (logclear! (-> self draw status) (draw-control-status no-draw))
    (quaternion-identity! (-> self root quat))
    (update-focus self)
    (let ((a0-22 (handle->process (-> self focus handle))))
      (when a0-22
        (let* ((gp-3 (-> self root))
               (s3-0
                 (vector-normalize!
                   (vector-! (new 'stack-no-clear 'vector) (get-trans (the-as process-focusable a0-22) 0) (-> gp-3 trans))
                   1.0
                   )
                 )
               (f0-1 (deg-diff (quaternion-y-angle (-> gp-3 quat)) (vector-y-angle s3-0)))
               )
          (quaternion-rotate-y! (-> gp-3 quat) (-> gp-3 quat) f0-1)
          )
        )
      )
    (suspend-for (the int (* 300.0 (rnd-float-range self 0.0 0.6)))
      )
    (ja-channel-push! 1 0)
    (ja-no-eval :group! egg-spider-crawl-from-ground-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (logclear! (-> self draw status) (draw-control-status no-draw))
    (nav-enemy-method-181 self)
    (nav-enemy-method-183 self)
    (set-look-at-mode! self 1)
    (set-time! (-> self state-time))
    (go-virtual hostile)
    )
  :post (behavior ()
    (nav-enemy-simple-post)
    )
  )

;; WARN: Return type mismatch entity-perm-status vs object.
(defmethod init-from-entity! ((this egg-spider) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (process-entity-status! this (entity-perm-status dead) #t)
  )

(defbehavior egg-spider-init-by-other egg-spider ((arg0 spider-manager) (arg1 enemy-init-by-other-params) (arg2 float))
  (set! (-> self size) (rnd-float-range self 0.8 arg2))
  (enemy-init-by-other arg0 arg1)
  )

;; WARN: Return type mismatch int vs object.
(defmethod setup-enemy! ((this egg-spider) (arg0 nav-enemy-info))
  (set! (-> arg0 nav-mesh) *default-nav-mesh*)
  (let ((t9-0 (method-of-type nav-enemy setup-enemy!)))
    (t9-0 this arg0)
    )
  (logclear! (-> this mask) (process-mask actor-pause))
  (logclear! (-> this enemy-flags) (enemy-flag actor-pause-backup))
  (set-vector! (-> this root scale) (-> this size) (-> this size) (-> this size) 1.0)
  (set! (-> this draw bounds w) (* (-> this draw bounds w) (-> this size)))
  (set! (-> this angle-spot) (* 182.04445 (rnd-float-range this 0.0 360.0)))
  (let ((v1-13 (-> this nav)))
    (logclear! (-> v1-13 flags) (nav-control-flag limit-rotation-rate output-sphere-hash))
    (logclear! (-> this nav flags) (nav-control-flag update-heading-from-facing))
    (set! (-> this enemy-flags) (the-as enemy-flag (logclear (-> this enemy-flags) (enemy-flag ef44))))
    (let ((a0-12 v1-13))
      (set! (-> a0-12 sphere-mask) (the-as uint #x1000fe))
      )
    0
    (let ((a0-14 v1-13))
      (set! (-> a0-14 nav-cull-radius) 12288.0)
      )
    0
    (logclear! (-> v1-13 flags) (nav-control-flag output-sphere-hash))
    )
  (set! (-> this enemy-info callback-info) *physics-nav-callback-info*)
  (nav-enemy-method-181 this)
  0
  )

(defmethod init-enemy-collision! ((this egg-spider))
  "Typical place to construct collision shapes"
  (let ((f30-0 (* 3276.8 (-> this size)))
        (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))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 1) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 2))
      (set! (-> s4-0 prim-core collide-as) (collide-spec enemy))
      (set! (-> s4-0 prim-core collide-with)
            (collide-spec backgnd jak bot crate obstacle hit-by-others-list player-list)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid can-ride deadly no-standon))
      (set-vector! (-> s4-0 local-sphere) 0.0 f30-0 0.0 f30-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 crate obstacle hit-by-others-list player-list)
            )
      (set! (-> v1-13 prim-core action) (collide-action solid can-ride deadly no-standon))
      (set-vector! (-> v1-13 local-sphere) 0.0 f30-0 0.0 f30-0)
      )
    (set! (-> s5-0 nav-radius) (* 3686.4 (-> this size)))
    (let ((v1-15 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-15 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-15 prim-core collide-with))
      )
    (set! (-> s5-0 max-iteration-count) (the-as uint 3))
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod init-enemy! ((this egg-spider))
  "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-egg-spider" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (setup-enemy! this *egg-spider-nav-enemy-info*)
  (set! (-> this move-angle) 10922.667)
  (set! (-> this heading) (if (= (rand-vu-int-range 0 1) 1)
                              #t
                              #f
                              )
        )
  (set! (-> this change-dir-time) 0)
  (set! (-> this onscreen-time) 0)
  (set! (-> this trackable?) #f)
  (set-gravity-length (-> this root dynam) 491520.0)
  (set! (-> this fact pickup-type) (pickup-type eco-pill-random))
  (none)
  )

(deftype spider-manager (process-drawable)
  ((child              (pointer egg-spider) :override)
   (count-alive        int32)
   (next-spawn-time    time-frame)
   (min-spawn-delay    int32)
   (max-spawn-delay    int32)
   (next-spot-time     time-frame)
   (min-spot-delay     int32)
   (max-spot-delay     int32)
   (actor-group        (pointer actor-group))
   (actor-group-count  int32)
   (spawn-pos          vector                :inline)
   (nav-id             uint32)
   (can-rid            handle)
   (next-explosion     time-frame)
   (num-nav-mesh       int32)
   (count-max          int32)
   (max-spawn-size     float)
   (count-death        uint32)
   )
  (:state-methods
    idle
    )
  (:methods
    (spider-manager-method-21 (_type_) none)
    (go-idle (_type_) object)
    (check-can-rid (_type_) int)
    (spider-manager-method-24 (_type_ vector) none)
    (spider-manager-method-25 (_type_ sphere) symbol)
    )
  )


(defmethod check-can-rid ((this spider-manager))
  (local-vars (sv-16 process-tree))
  (let ((s2-0 (the-as (pointer process-tree) (-> this child)))
        (s5-0 0)
        )
    (let ((s4-0 0)
          (dist 0.0)
          )
      (set! (-> this can-rid) (the-as handle #f))
      (while s2-0
        (set! sv-16 (as-type (-> s2-0 0) egg-spider))
        (when sv-16
          (when (not (logtest? (-> (the-as egg-spider sv-16) draw status) (draw-control-status on-screen)))
            (let ((f0-0 (vector-vector-xz-distance (-> (the-as egg-spider sv-16) root trans) (target-pos 0))))
              (when (< (the float dist) f0-0)
                (set! dist f0-0)
                (set! (-> this can-rid) (process->handle (the-as process sv-16)))
                )
              )
            (+! s4-0 1)
            )
          (+! s5-0 1)
          )
        (set! s2-0 (-> s2-0 0 brother))
        )
      )
    (when (-> this can-rid)
      )
    (set! (-> this count-alive) s5-0)
    s5-0
    )
  )

(defmethod spider-manager-method-24 ((this spider-manager) (arg0 vector))
  (let ((s5-0 (new 'stack-no-clear 'cquery-with-vec)))
    (vector-copy! (-> s5-0 vec0) arg0)
    (vector-copy! (-> s5-0 cquery start-pos) (-> s5-0 vec0))
    (set-vector! (-> s5-0 cquery move-dist) 0.0 -40960.0 0.0 1.0)
    (when (= (level-status? *level* 'desert #f) 'active)
      (set-vector! (-> s5-0 cquery move-dist) 0.0 -409600.0 0.0 1.0)
      (+! (-> s5-0 cquery start-pos y) 204800.0)
      )
    (let ((v1-9 (-> s5-0 cquery)))
      (set! (-> v1-9 radius) 1024.0)
      (set! (-> v1-9 collide-with) (collide-spec backgnd))
      (set! (-> v1-9 ignore-process0) #f)
      (set! (-> v1-9 ignore-process1) #f)
      (set! (-> v1-9 ignore-pat)
            (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
            )
      (set! (-> v1-9 action-mask) (collide-action solid))
      )
    (let ((f0-11 (fill-and-probe-using-line-sphere *collide-cache* (-> s5-0 cquery))))
      (when (>= f0-11 0.0)
        (vector+float*! (-> s5-0 vec0) (-> s5-0 cquery start-pos) (-> s5-0 cquery move-dist) f0-11)
        (vector-copy! (-> s5-0 vec1) (-> s5-0 cquery best-other-tri normal))
        (vector-copy! arg0 (-> s5-0 vec0))
        )
      )
    )
  0
  (none)
  )

(defmethod spider-manager-method-25 ((this spider-manager) (arg0 sphere))
  (dotimes (s2-0 (-> this num-nav-mesh))
    (let ((s4-0 (nav-mesh-from-res-tag (-> this entity) 'nav-mesh-actor s2-0)))
      (when s4-0
        (new 'stack-no-clear 'vector)
        (new 'stack-no-clear 'vector)
        (let ((s3-0 (new 'stack-no-clear 'vector)))
          (vector-copy! s3-0 arg0)
          (let ((a1-2 (new 'stack-no-clear 'nav-poly)))
            (set! (-> a1-2 vertex1 x) 122880.0)
            (set! (-> a1-2 data 20) (the-as uint 2))
            (vector-! (-> a1-2 vertex 0) s3-0 (the-as vector (-> s4-0 bounds)))
            (vector-copy! s3-0 (-> a1-2 vertex 0))
            (let ((a1-3 (nav-mesh-method-45 s4-0 a1-2)))
              (when a1-3
                (let ((s2-1 (new 'stack-no-clear 'vector)))
                  (let ((a3-0 (new 'stack-no-clear 'vector)))
                    (project-point-onto-plane-of-poly-local s4-0 a1-3 s2-1 a3-0 s3-0)
                    )
                  (set! (-> s3-0 y) (-> s2-1 y))
                  )
                (vector+! s3-0 s3-0 (the-as vector (-> s4-0 bounds)))
                (spider-manager-method-24 this s3-0)
                (set! (-> arg0 quad) (-> s3-0 quad))
                (set! (-> this nav-id) (-> s4-0 entity aid))
                (return #t)
                )
              )
            )
          )
        )
      )
    )
  #f
  )

(defmethod run-logic? ((this spider-manager))
  "Should this process be run? Checked by execute-process-tree."
  #t
  )

(defstate idle (spider-manager)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('next-explosion)
       (cond
         ((< (-> self next-explosion) (current-time))
          (set! (-> self next-explosion) (+ (current-time) (rand-vu-int-range (seconds 0.6) (seconds 1.2))))
          #t
          )
         (else
           #f
           )
         )
       )
      (('dead)
       (let ((v0-1 (the-as object (+ (-> self count-death) 1))))
         (set! (-> self count-death) (the-as uint v0-1))
         v0-1
         )
       )
      (('count-death)
       (-> self count-death)
       )
      )
    )
  :enter (behavior ()
    (set! (-> self next-explosion) 0)
    0
    )
  :trans (behavior ()
    (check-can-rid self)
    (when (< (-> self next-spot-time) (current-time))
      (let ((s5-0 (new 'stack-no-clear 'vector)))
        (vector-copy! s5-0 (camera-pos))
        (let ((f28-0 (camera-angle))
              (s4-0 (new 'stack-no-clear 'vector))
              (gp-0 (new 'stack-no-clear 'vector))
              )
          (let ((f30-0 0.0))
            (if *target*
                (+! f30-0 (vector-length (-> *target* control transv)))
                )
            (vector-rotate-around-y! s4-0 *z-vector* (+ f28-0 (* 182.04445 (rand-vu-float-range -30.0 30.0))))
            (vector+*! gp-0 s5-0 s4-0 (+ (* 2.0 f30-0) (* 4096.0 (rand-vu-float-range 40.0 80.0))))
            )
          (when (spider-manager-method-25 self (the-as sphere gp-0))
            (vector-copy! (-> self spawn-pos) gp-0)
            (set! (-> self next-spot-time)
                  (+ (current-time) (rand-vu-int-range (-> self min-spot-delay) (-> self max-spot-delay)))
                  )
            )
          )
        )
      )
    (if (and (= (-> self count-alive) (-> self count-max)) (-> self can-rid))
        (send-event (handle->process (-> self can-rid)) 'die-fast)
        )
    (when (and (< (-> self count-alive) (-> self count-max))
               *target*
               (not (-> *setting-control* user-current nuke-active?))
               )
      (when (< (-> self next-spawn-time) (current-time))
        (set! (-> self next-spawn-time)
              (+ (current-time) (rand-vu-int-range (-> self min-spawn-delay) (-> self max-spawn-delay)))
              )
        (let ((gp-3 (new 'stack-no-clear 'sphere)))
          (set! (-> gp-3 quad) (-> self spawn-pos quad))
          (+! (-> gp-3 x) (* 4096.0 (rand-vu-float-range -3.0 3.0)))
          (+! (-> gp-3 z) (* 4096.0 (rand-vu-float-range -3.0 3.0)))
          (set! (-> gp-3 r) 4096.0)
          (when (and (sphere-in-view-frustum? gp-3) (spider-manager-method-25 self gp-3))
            (let ((s5-1 (new 'stack-no-clear 'enemy-init-by-other-params)))
              (vector-copy! (-> s5-1 trans) gp-3)
              (quaternion-copy! (-> s5-1 quat) *unity-quaternion*)
              (set! (-> s5-1 entity) (-> self actor-group 0 data 0 actor))
              (set! (-> s5-1 directed?) #f)
              (set! (-> s5-1 no-initial-move-to-ground?) #f)
              (set! (-> s5-1 art-level) #f)
              (let ((gp-5
                      (as-type
                        (ppointer->process (process-spawn egg-spider self s5-1 (-> self max-spawn-size) :name "egg-spider" :to self))
                        process-focusable
                        )
                      )
                    (s5-3 (as-type (entity-nav-mesh-by-aid (the-as actor-id (-> self nav-id))) entity-nav-mesh))
                    )
                (when (and (task-node-closed? (game-task-node forest-kill-plants-introduction))
                           (not (task-node-closed? (game-task-node forest-kill-plants-resolution)))
                           )
                  (set! (-> (the-as process-focusable gp-5) fact pickup-type) (pickup-type none))
                  (set! (-> (the-as process-focusable gp-5) fact pickup-amount) 0.0)
                  )
                (when s5-3
                  (change-to (-> s5-3 nav-mesh) (the-as process-drawable gp-5))
                  (let ((v1-63 (-> (the-as process-focusable gp-5) nav state)))
                    (set! (-> v1-63 current-poly) (the-as nav-poly #f))
                    )
                  0
                  )
                )
              )
            )
          )
        )
      )
    )
  :code sleep-code
  )

(defmethod spider-manager-method-21 ((this spider-manager))
  0
  (none)
  )

;; WARN: Return type mismatch int vs object.
(defmethod go-idle ((this spider-manager))
  (if (and (-> this entity) (logtest? (-> this entity extra perm status) (entity-perm-status subtask-complete)))
      (go (method-of-object this idle))
      (go (method-of-object this idle))
      )
  0
  )

(defmethod init-from-entity! ((this spider-manager) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (local-vars (sv-16 res-tag) (sv-32 res-tag))
  (logior! (-> this mask) (process-mask enemy))
  (let ((s4-0 (new 'process 'trsqv)))
    (set! (-> this root) s4-0)
    (vector-copy! (-> s4-0 trans) (-> arg0 extra trans))
    (quaternion-copy! (-> s4-0 quat) (-> arg0 quat))
    (vector-identity! (-> s4-0 scale))
    )
  (set! (-> this min-spawn-delay) 30)
  (set! (-> this max-spawn-delay) 60)
  (set! (-> this min-spot-delay) 150)
  (set! (-> this max-spot-delay) 300)
  (set! sv-16 (new 'static 'res-tag))
  (res-lump-data (-> this entity) 'nav-mesh-actor pointer :tag-ptr (& sv-16))
  (set! (-> this num-nav-mesh) (the-as int (-> sv-16 elt-count)))
  (set! sv-32 (new 'static 'res-tag))
  (let ((v1-16 (res-lump-data (-> this entity) 'actor-groups pointer :tag-ptr (& sv-32))))
    (cond
      ((and v1-16 (nonzero? (-> sv-32 elt-count)))
       (set! (-> this actor-group) (the-as (pointer actor-group) v1-16))
       (set! (-> this actor-group-count) (the-as int (-> sv-32 elt-count)))
       )
      (else
        (set! (-> this actor-group) (the-as (pointer actor-group) #f))
        (set! (-> this actor-group-count) 0)
        (go process-drawable-art-error "actor-group spider-battle")
        )
      )
    )
  (set! (-> this count-death) (the-as uint 0))
  (set! (-> this count-max)
        (res-lump-value (-> this entity) 'max-count int :default (the-as uint128 30) :time -1000000000.0)
        )
  (set! (-> this max-spawn-size) (res-lump-float (-> this entity) 'max-size :default 2.0))
  (set! *egg-spider-always-trackable?*
        (if (zero? (res-lump-value (-> this entity) 'always-trackable? uint128 :time -1000000000.0))
            #f
            #t
            )
        )
  (spider-manager-method-21 this)
  (go-idle this)
  )
