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

(import "goal_src/jak1/import/quicksandlurker-ag.gc")

;; failed to figure out what this is:
(defpartgroup group-quicksandlurker-missile
  :id 198
  :bounds (static-bspherem 0 0 0 3)
  :parts ((sp-item 2481 :flags (launch-asap) :binding 2479)
    (sp-item 2479 :flags (start-dead) :binding 2480)
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    (sp-item 2480 :flags (start-dead launch-asap))
    )
  )

;; failed to figure out what this is:
(defpart 2481
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x12 :page #x2))
    (sp-flt spt-num 1.0)
    (sp-flt spt-scale-x (meters 0.01))
    (sp-copy-from-other spt-scale-y -4)
    (sp-flt spt-a 0.0)
    (sp-int spt-timer 1200)
    (sp-cpuinfo-flags bit3)
    (sp-func spt-func 'sparticle-track-root-prim)
    )
  )

;; failed to figure out what this is:
(defpart 2479
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 2.0)
    (sp-flt spt-scale-x (meters 1))
    (sp-rnd-flt spt-rot-z (degrees 0.0) (degrees 360.0) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 96.0 64.0 1.0)
    (sp-rnd-flt spt-g 64.0 32.0 1.0)
    (sp-rnd-flt spt-b 96.0 64.0 1.0)
    (sp-flt spt-a 128.0)
    (sp-flt spt-scalevel-x (meters -0.006666667))
    (sp-copy-from-other spt-scalevel-y -4)
    (sp-flt spt-fade-r -1.0666667)
    (sp-flt spt-fade-g -1.0666667)
    (sp-flt spt-fade-b 0.0)
    (sp-int spt-timer 150)
    (sp-cpuinfo-flags bit2)
    (sp-int spt-next-time 81)
    (sp-launcher-by-id spt-next-launcher 2482)
    (sp-rnd-flt spt-conerot-x (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-y (degrees 0.0) (degrees 360.0) 1.0)
    (sp-flt spt-conerot-radius (meters 0.1))
    )
  )

;; failed to figure out what this is:
(defpart 2482
  :init-specs ((sp-flt spt-fade-r 0.0) (sp-flt spt-fade-g 0.0) (sp-flt spt-fade-b 0.0))
  )

;; failed to figure out what this is:
(defpart 2480
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-rnd-flt spt-num 1.0 5.0 1.0)
    (sp-rnd-flt spt-scale-x (meters 0.2) (meters 0.1) 1.0)
    (sp-rnd-flt spt-rot-z (degrees 0.0) (degrees 360.0) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 96.0 64.0 1.0)
    (sp-rnd-flt spt-g 64.0 32.0 1.0)
    (sp-rnd-flt spt-b 96.0 64.0 1.0)
    (sp-flt spt-a 128.0)
    (sp-rnd-flt spt-vel-y (meters 0.006666667) (meters 0.0033333334) 1.0)
    (sp-flt spt-scalevel-x (meters -0.0026666666))
    (sp-copy-from-other spt-scalevel-y -4)
    (sp-flt spt-fade-r -1.0666667)
    (sp-flt spt-fade-g -1.0666667)
    (sp-flt spt-fade-b 0.0)
    (sp-flt spt-accel-y -2.7306666)
    (sp-flt spt-friction 0.97)
    (sp-int-plain-rnd spt-timer 30 119 1)
    (sp-cpuinfo-flags bit2)
    (sp-int spt-next-time 60)
    (sp-launcher-by-id spt-next-launcher 2482)
    (sp-rnd-flt spt-conerot-x (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-y (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-radius (meters 0) (meters 0.4) 1.0)
    )
  )

;; failed to figure out what this is:
(defpartgroup group-quicksandlurker-pre-missile
  :id 199
  :duration 5
  :bounds (static-bspherem 0 0 0 3)
  :parts ((sp-item 2483))
  )

;; failed to figure out what this is:
(defpart 2483
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 32.0)
    (sp-rnd-flt spt-scale-x (meters 0.5) (meters 0.2) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 192.0 32.0 1.0)
    (sp-rnd-flt spt-g 64.0 32.0 1.0)
    (sp-rnd-flt spt-b 96.0 64.0 1.0)
    (sp-flt spt-a 128.0)
    (sp-rnd-flt spt-vel-y (meters 0.053333335) (meters 0.053333335) 1.0)
    (sp-flt spt-scalevel-x (meters -0.006666667))
    (sp-copy-from-other spt-scalevel-y -4)
    (sp-flt spt-fade-r -0.7111111)
    (sp-flt spt-fade-g -0.7111111)
    (sp-flt spt-fade-b 0.0)
    (sp-flt spt-accel-y -0.68266666)
    (sp-rnd-flt spt-friction 0.85 0.05 1.0)
    (sp-int-plain-rnd spt-timer 30 119 1)
    (sp-cpuinfo-flags bit2)
    (sp-int spt-next-time 90)
    (sp-launcher-by-id spt-next-launcher 2482)
    (sp-rnd-flt spt-conerot-x (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-y (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-radius (meters 0) (meters 0.4) 1.0)
    )
  )

;; failed to figure out what this is:
(defpartgroup group-quicksandlurker-missile-impact
  :id 200
  :duration 10
  :bounds (static-bspherem 0 0 0 3)
  :parts ((sp-item 2484) (sp-item 2485) (sp-item 2486))
  )

;; failed to figure out what this is:
(defpart 2484
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 64.0)
    (sp-rnd-flt spt-scale-x (meters 0.5) (meters 0.2) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 192.0 32.0 1.0)
    (sp-rnd-flt spt-g 64.0 32.0 1.0)
    (sp-rnd-flt spt-b 96.0 64.0 1.0)
    (sp-flt spt-a 128.0)
    (sp-rnd-flt spt-vel-y (meters 0.10666667) (meters 0.10666667) 1.0)
    (sp-flt spt-scalevel-x (meters -0.006666667))
    (sp-copy-from-other spt-scalevel-y -4)
    (sp-flt spt-fade-r -0.7111111)
    (sp-flt spt-fade-g -0.7111111)
    (sp-flt spt-fade-b 0.0)
    (sp-flt spt-accel-y -0.68266666)
    (sp-rnd-flt spt-friction 0.85 0.05 1.0)
    (sp-int-plain-rnd spt-timer 30 119 1)
    (sp-cpuinfo-flags bit2)
    (sp-int spt-next-time 90)
    (sp-launcher-by-id spt-next-launcher 2482)
    (sp-rnd-flt spt-conerot-x (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-y (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-radius (meters 0) (meters 0.4) 1.0)
    )
  )

;; failed to figure out what this is:
(defpart 2486
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :page #x2))
    (sp-flt spt-num 6.0)
    (sp-rnd-flt spt-scale-x (meters 3) (meters 3) 1.0)
    (sp-rnd-flt spt-rot-z (degrees 0.0) (degrees 360.0) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 96.0 64.0 1.0)
    (sp-rnd-flt spt-g 64.0 32.0 1.0)
    (sp-rnd-flt spt-b 96.0 64.0 1.0)
    (sp-rnd-flt spt-a 32.0 32.0 1.0)
    (sp-rnd-flt spt-rotvel-z (degrees -0.2) (degrees 0.4) 1.0)
    (sp-flt spt-fade-r -0.35555556)
    (sp-flt spt-fade-g -0.35555556)
    (sp-flt spt-fade-b 0.0)
    (sp-flt spt-fade-a -0.30476192)
    (sp-rnd-flt spt-accel-y -0.68266666 0.68266666 1.0)
    (sp-int spt-timer 210)
    (sp-cpuinfo-flags bit2)
    (sp-int spt-next-time 60)
    (sp-launcher-by-id spt-next-launcher 2482)
    (sp-rnd-flt spt-rotate-y (degrees 0.0) (degrees 180.0) 1.0)
    )
  )

;; failed to figure out what this is:
(defpart 2485
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 1.0)
    (sp-rnd-flt spt-scale-x (meters 6) (meters 1) 1.0)
    (sp-rnd-flt spt-rot-z (degrees 0.0) (degrees 360.0) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 128.0 32.0 1.0)
    (sp-rnd-flt spt-g 64.0 32.0 1.0)
    (sp-rnd-flt spt-b 128.0 32.0 1.0)
    (sp-flt spt-a 96.0)
    (sp-flt spt-fade-a -4.8)
    (sp-int spt-timer 15)
    (sp-cpuinfo-flags bit2)
    )
  )

;; failed to figure out what this is:
(defpartgroup group-quicksandlurker-hide
  :id 201
  :duration 900
  :flags (use-local-clock)
  :bounds (static-bspherem 0 -12 0 14)
  :parts ((sp-item 124 :flags (is-3d) :period 900 :length 63)
    (sp-item 125 :period 900 :length 15)
    (sp-item 126 :flags (is-3d) :period 900 :length 15)
    (sp-item 127 :flags (is-3d) :period 900 :length 15)
    (sp-item 128 :period 900 :length 10 :binding 129)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    )
  )

;; failed to figure out what this is:
(defpartgroup group-quicksandlurker-popup
  :id 202
  :duration 900
  :flags (use-local-clock)
  :bounds (static-bspherem 0 -12 0 14)
  :parts ((sp-item 124 :flags (is-3d) :period 900 :length 63)
    (sp-item 125 :period 900 :length 15)
    (sp-item 126 :flags (is-3d) :period 900 :length 15)
    (sp-item 127 :flags (is-3d) :period 900 :length 15)
    (sp-item 128 :period 900 :length 10 :binding 129)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    (sp-item 129 :flags (start-dead) :period 900 :length 120)
    )
  )

;; definition of type quicksandlurker-missile
(deftype quicksandlurker-missile (process-drawable)
  ((root-override collide-shape-moving  :offset 112)
   )
  :heap-base #x40
  :method-count-assert 20
  :size-assert         #xb0
  :flag-assert         #x14004000b0
  (:states
    quicksandlurker-missile-idle
    quicksandlurker-missile-impact
    )
  )

;; definition for method 3 of type quicksandlurker-missile
(defmethod inspect quicksandlurker-missile ((obj quicksandlurker-missile))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  obj
  )

;; failed to figure out what this is:
(defstate quicksandlurker-missile-idle (quicksandlurker-missile)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('touched)
       (when (cond
               ((= (-> arg0 type) target)
                (send-event arg0 'attack (-> arg3 param 0) (static-attack-info ((mode 'explode))))
                )
               (else
                 (let ((a1-4 (new 'stack-no-clear 'event-message-block)))
                   (set! (-> a1-4 from) self)
                   (set! (-> a1-4 num-params) 4)
                   (set! (-> a1-4 message) 'attack)
                   (set! (-> a1-4 param 0) (-> arg3 param 0))
                   (set! (-> a1-4 param 1) (the-as uint 'explode))
                   (let ((v1-12 (+ *global-attack-id* 1)))
                     (set! *global-attack-id* v1-12)
                     (set! (-> a1-4 param 2) (the-as uint v1-12))
                     )
                   (set! (-> a1-4 param 3) (the-as uint 0))
                   (send-event-function arg0 a1-4)
                   )
                 )
               )
         (send-event (ppointer->process (-> self parent)) 'victory)
         (go quicksandlurker-missile-impact)
         )
       )
      )
    )
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (none)
    )
  :code (behavior ()
    (while (< (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 4))
      (fill-cache-integrate-and-collide!
        (-> self root-override)
        (-> self root-override transv)
        (-> self root-override root-prim collide-with)
        )
      (if (or (logtest? (-> self root-override status) (cshape-moving-flags twall))
              (< (vector-vector-distance (-> self root-override trans) (the-as vector (-> self root-override trans-old)))
                 40.96
                 )
              )
          (go quicksandlurker-missile-impact)
          )
      (spawn (-> self part) (-> self root-override trans))
      (find-ground-and-draw-shadow
        (-> self root-override trans)
        (the-as vector #f)
        8192.0
        (collide-kind background)
        (the-as process-drawable #f)
        0.0
        81920.0
        )
      (suspend)
      )
    (cleanup-for-death self)
    (none)
    )
  :post (behavior ()
    (update-transforms! (-> self root-override))
    (none)
    )
  )

;; failed to figure out what this is:
(defstate quicksandlurker-missile-impact (quicksandlurker-missile)
  :code (behavior ()
    (sound-play "sack-land" :position (the-as symbol (-> self root-override trans)))
    (process-spawn
      part-tracker
      :init part-tracker-init
      (-> *part-group-id-table* 200)
      -1
      #f
      #f
      #f
      (-> self root-override trans)
      :to *entity-pool*
      )
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (until (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 1))
      (suspend)
      )
    (cleanup-for-death self)
    (none)
    )
  )

;; definition of type quicksandlurker-missile-init-data
(deftype quicksandlurker-missile-init-data (structure)
  ((position vector  :offset-assert   0)
   (velocity vector  :offset-assert   4)
   )
  :method-count-assert 9
  :size-assert         #x8
  :flag-assert         #x900000008
  )

;; definition for method 3 of type quicksandlurker-missile-init-data
(defmethod inspect quicksandlurker-missile-init-data ((obj quicksandlurker-missile-init-data))
  (format #t "[~8x] ~A~%" obj 'quicksandlurker-missile-init-data)
  (format #t "~Tposition: #<vector @ #x~X>~%" (-> obj position))
  (format #t "~Tvelocity: #<vector @ #x~X>~%" (-> obj velocity))
  obj
  )

;; definition for function quicksandlurker-missile-init-by-other
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defbehavior quicksandlurker-missile-init-by-other quicksandlurker-missile ((arg0 quicksandlurker-missile-init-data) (arg1 entity-actor))
  (set! (-> self entity) arg1)
  (let ((s5-0 (new 'process 'collide-shape-moving self (collide-list-enum hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) default-collision-reaction)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (let ((s4-0 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> s4-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s4-0 collide-with)
            (collide-kind background cak-2 cak-3 target crate enemy wall-object ground-object)
            )
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set! (-> s4-0 prim-core offense) (collide-offense indestructible))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 2867.2)
      (set-root-prim! s5-0 s4-0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (backup-collide-with-as s5-0)
    (set! (-> s5-0 max-iteration-count) (the-as uint 1))
    (set! (-> s5-0 event-self) 'touched)
    (set! (-> self root-override) s5-0)
    )
  (set! (-> self root-override trans quad) (-> arg0 position quad))
  (set! (-> self root-override quat vec quad)
        (-> (the-as process-drawable (-> self parent 0)) root quat vec quad)
        )
  (vector-identity! (-> self root-override scale))
  (set! (-> self root-override transv quad) (-> arg0 velocity quad))
  (set! (-> self part) (create-launch-control (-> *part-group-id-table* 198) self))
  (go quicksandlurker-missile-idle)
  (none)
  )

;; definition for function spawn-quicksandlurker-missile
;; INFO: Return type mismatch int vs none.
(defun spawn-quicksandlurker-missile ((arg0 process) (arg1 vector) (arg2 vector) (arg3 entity-actor))
  (let ((s5-0 (new 'stack-no-clear 'quicksandlurker-missile-init-data)))
    (set! (-> s5-0 position) arg1)
    (set! (-> s5-0 velocity) arg2)
    (process-spawn quicksandlurker-missile s5-0 arg3 :to arg0)
    )
  0
  (none)
  )

;; definition of type quicksandlurker
(deftype quicksandlurker (process-drawable)
  ((root-override     collide-shape         :offset        112)
   (original-position vector        :inline :offset-assert 176)
   (y-offset          float                 :offset-assert 192)
   (theta-angle       float                 :offset-assert 196)
   (radial-offset     float                 :offset-assert 200)
   (bob-angle         float                 :offset-assert 204)
   (mud-entity        entity-actor          :offset-assert 208)
   )
  :heap-base #x70
  :method-count-assert 20
  :size-assert         #xd4
  :flag-assert         #x14007000d4
  (:states
    quicksandlurker-attack
    quicksandlurker-die
    quicksandlurker-hide
    quicksandlurker-idle
    quicksandlurker-popup
    quicksandlurker-track
    quicksandlurker-victory
    quicksandlurker-wait
    quicksandlurker-yawn
    )
  )

;; definition for method 3 of type quicksandlurker
(defmethod inspect quicksandlurker ((obj quicksandlurker))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Toriginal-position: #<vector @ #x~X>~%" (-> obj original-position))
  (format #t "~T~Ty-offset: ~f~%" (-> obj y-offset))
  (format #t "~T~Ttheta-angle: ~f~%" (-> obj theta-angle))
  (format #t "~T~Tradial-offset: ~f~%" (-> obj radial-offset))
  (format #t "~T~Tbob-angle: ~f~%" (-> obj bob-angle))
  (format #t "~T~Tmud-entity: ~A~%" (-> obj mud-entity))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *quicksandlurker-sg* quicksandlurker quicksandlurker-lod0-jg quicksandlurker-idle-ja
              ((quicksandlurker-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 5)
              )

;; definition for function orient-to-face-target
(defbehavior orient-to-face-target quicksandlurker ()
  (if *target*
      (seek-to-point-toward-point! (-> self root-override) (-> *target* control trans) 65536.0 (seconds 0.2))
      )
  )

;; definition for function get-height-over-navmesh!
;; ERROR: function has no type analysis. Cannot decompile.

;; definition for function intersects-nav-mesh?
(defun intersects-nav-mesh? ((arg0 nav-control) (arg1 vector))
  (if (dummy-16 arg0 arg1)
      #t
      )
  )

;; definition for function quicksandlurker-default-event-handler
(defbehavior quicksandlurker-default-event-handler quicksandlurker ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('attack)
     enter-state
     (go quicksandlurker-die)
     )
    (('victory)
     (go quicksandlurker-victory)
     )
    )
  )

;; definition for function inc-angle
(defun inc-angle ((arg0 (pointer float)) (arg1 float))
  (+! (-> arg0 0) arg1)
  (when (< 65536.0 (-> arg0 0))
    (let ((f0-4 (+ -65536.0 (-> arg0 0))))
      (set! (-> arg0 0) f0-4)
      f0-4
      )
    )
  )

;; definition for function quicksandlurker-post
;; INFO: Return type mismatch int vs none.
(defbehavior quicksandlurker-post quicksandlurker ()
  (inc-angle (&-> self theta-angle) (* 9102.223 (-> *display* seconds-per-frame)))
  (inc-angle (&-> self bob-angle) (* 14563.556 (-> *display* seconds-per-frame)))
  (let ((f28-0 (* (-> self radial-offset) (cos (-> self theta-angle))))
        (f30-2 (* 0.0 (sin (-> self theta-angle))))
        )
    (let ((f0-10 (* (-> self radial-offset) (sin (-> self theta-angle)))))
      (set! (-> self root-override trans x) (+ (-> self original-position x) f28-0))
      (set! (-> self root-override trans z) (+ (-> self original-position z) f0-10))
      )
    (let* ((v1-4 (-> self mud-entity))
           (a0-5 (if v1-4
                     (-> v1-4 extra process)
                     )
                 )
           )
      (if a0-5
          (set! (-> self root-override trans y)
                (+ (get-ripple-height (the-as water-anim a0-5) (-> self root-override trans)) f30-2 (-> self y-offset))
                )
          (set! (-> self root-override trans y) (+ (-> self original-position y) f30-2 (-> self y-offset)))
          )
      )
    )
  (transform-post)
  (none)
  )

;; definition for function quicksandlurker-check-hide-transition
;; INFO: Return type mismatch object vs none.
(defbehavior quicksandlurker-check-hide-transition quicksandlurker ()
  (when *target*
    (if (and (and *target* (>= 20480.0 (vector-vector-distance (-> self root-override trans) (-> *target* control trans))))
             (!= (-> *target* next-state name) 'target-flop)
             )
        (go quicksandlurker-hide)
        )
    0.0
    (let ((a0-2 (-> self nav))
          (a1-1 (-> *target* control trans))
          )
      (when (if (dummy-16 a0-2 a1-1)
                #t
                )
        (if (< (- (-> *target* control trans y) (-> self original-position y)) 0.0)
            (go quicksandlurker-hide)
            )
        )
      )
    )
  (none)
  )

;; failed to figure out what this is:
(defstate quicksandlurker-idle (quicksandlurker)
  :event (the-as (function process int symbol event-message-block object :behavior quicksandlurker) #f)
  :enter (behavior ()
    (logior! (-> self draw status) (draw-status hidden))
    (none)
    )
  :exit (behavior ()
    (logclear! (-> self draw status) (draw-status hidden))
    (none)
    )
  :trans (behavior ()
    (if (and *target*
             (>= 163840.0 (vector-vector-distance (-> self root-override trans) (-> *target* control trans)))
             )
        (go quicksandlurker-wait)
        )
    (none)
    )
  :code (behavior ()
    (loop
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior quicksandlurker) ja-post)
  )

;; failed to figure out what this is:
(defstate quicksandlurker-wait (quicksandlurker)
  :event quicksandlurker-default-event-handler
  :trans (behavior ()
    (cond
      ((and *target* (>= 81920.0 (vector-vector-distance (-> self root-override trans) (-> *target* control trans))))
       (set! (-> self y-offset) 1228.8)
       (go quicksandlurker-track)
       )
      ((or (not *target*)
           (< 163840.0 (vector-vector-distance (-> self root-override trans) (-> *target* control trans)))
           )
       (seek! (-> self y-offset) -6553.6 (* 20480.0 (-> *display* seconds-per-frame)))
       (if (= (-> self y-offset) -6553.6)
           (go quicksandlurker-idle)
           )
       )
      (else
        (seek! (-> self y-offset) 1228.8 (* 20480.0 (-> *display* seconds-per-frame)))
        )
      )
    (none)
    )
  :code (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (let ((gp-0 (the int (* 300.0 (rand-vu-float-range 1.5 2.0))))
          (s5-0 5)
          (s4-0 0)
          )
      (ja-channel-push! 1 (seconds 0.1))
      (loop
        (when (>= (- (-> *display* base-frame-counter) (-> self state-time)) gp-0)
          (ja-no-eval :group! quicksandlurker-idle-ja :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek!))
            )
          (set! (-> self state-time) (-> *display* base-frame-counter))
          (+! s4-0 1)
          (when (< s5-0 s4-0)
            (set! s4-0 0)
            (ja-no-eval :group! quicksandlurker-yawn-ja :num! (seek!) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek!))
              )
            )
          )
        (orient-to-face-target)
        (ja :group! quicksandlurker-idle-ja)
        (ja :num-func num-func-identity :frame-num 0.0)
        (suspend)
        )
      )
    (none)
    )
  :post quicksandlurker-post
  )

;; failed to figure out what this is:
(defstate quicksandlurker-yawn (quicksandlurker)
  :event quicksandlurker-default-event-handler
  :code (behavior ()
    (ja-no-eval :group! quicksandlurker-yawn-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (go quicksandlurker-wait)
    (none)
    )
  :post quicksandlurker-post
  )

;; failed to figure out what this is:
(defstate quicksandlurker-track (quicksandlurker)
  :event quicksandlurker-default-event-handler
  :trans (behavior ()
    (if (or (not *target*)
            (< 81920.0 (vector-vector-distance (-> self root-override trans) (-> *target* control trans)))
            )
        (go quicksandlurker-wait)
        )
    (quicksandlurker-check-hide-transition)
    (none)
    )
  :code (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (let ((gp-0 (the int (* 300.0 (rand-vu-float-range 0.8 1.2))))
          (s5-0 1)
          (s4-0 0)
          )
      (loop
        (when (>= (- (-> *display* base-frame-counter) (-> self state-time)) gp-0)
          (ja-no-eval :group! quicksandlurker-idle-ja :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek!))
            )
          (set! (-> self state-time) (-> *display* base-frame-counter))
          (+! s4-0 1)
          (when (>= s4-0 s5-0)
            (if (logtest? (-> self draw status) (draw-status was-drawn))
                (go quicksandlurker-attack)
                )
            )
          )
        (orient-to-face-target)
        (ja :group! quicksandlurker-idle-ja)
        (ja :num-func num-func-identity :frame-num 0.0)
        (suspend)
        )
      )
    (none)
    )
  :post quicksandlurker-post
  )

;; definition for function quicksandlurker-spit
;; INFO: Used lq/sq
;; INFO: Return type mismatch (pointer process) vs (pointer part-tracker).
(defbehavior quicksandlurker-spit quicksandlurker ()
  (let ((gp-0 (new-stack-vector0)))
    (let ((s5-0 (new-stack-vector0)))
      (set! (-> gp-0 quad) (-> (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data 9)) quad))
      (vector-! s5-0 (target-pos 5) gp-0)
      (let ((f1-0 (vector-xz-length s5-0)))
        (set! (-> s5-0 y) (fmin (-> s5-0 y) (* 0.5 f1-0)))
        )
      (vector-normalize! s5-0 49152.0)
      (spawn-quicksandlurker-missile self gp-0 s5-0 (-> self entity))
      )
    (process-spawn
      part-tracker
      :init part-tracker-init
      (-> *part-group-id-table* 199)
      -1
      #f
      #f
      #f
      gp-0
      :to *entity-pool*
      )
    )
  )

;; failed to figure out what this is:
(defstate quicksandlurker-attack (quicksandlurker)
  :event quicksandlurker-default-event-handler
  :trans quicksandlurker-check-hide-transition
  :code (behavior ()
    (let ((gp-0 #f)
          (f30-0 51.0)
          )
      (ja-no-eval :group! quicksandlurker-spit-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (orient-to-face-target)
        (when (and (not gp-0) (>= (ja-aframe-num 0) f30-0))
          (set! gp-0 #t)
          (quicksandlurker-spit)
          )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (go quicksandlurker-track)
    (none)
    )
  :post quicksandlurker-post
  )

;; failed to figure out what this is:
(defstate quicksandlurker-victory (quicksandlurker)
  :event quicksandlurker-default-event-handler
  :trans quicksandlurker-check-hide-transition
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (cond
      ((rand-vu-percent? 0.5)
       (ja-no-eval :group! quicksandlurker-victory-ja :num! (seek!) :frame-num 0.0)
       (until (ja-done? 0)
         (suspend)
         (ja :num! (seek!))
         )
       )
      (else
        (ja-no-eval :group! quicksandlurker-victory2-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))
          )
        )
      )
    (go quicksandlurker-track)
    (none)
    )
  :post quicksandlurker-post
  )

;; failed to figure out what this is:
(defstate quicksandlurker-hide (quicksandlurker)
  :event quicksandlurker-default-event-handler
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (none)
    )
  :exit (behavior ()
    (restore-collide-with-as (-> self root-override))
    (none)
    )
  :trans (behavior ()
    (if (not *target*)
        (go quicksandlurker-wait)
        )
    (let ((a0-0 (-> self nav))
          (a1-0 (-> *target* control trans))
          )
      (cond
        ((or (if (dummy-16 a0-0 a1-0)
                 #t
                 )
             (and *target* (>= 16384.0 (vector-vector-distance (-> self root-override trans) (-> *target* control trans))))
             )
         (set! (-> self state-time) (-> *display* base-frame-counter))
         )
        (else
          (if (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 2))
              (go quicksandlurker-popup)
              )
          )
        )
      )
    (none)
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    (ja-no-eval :group! quicksandlurker-hide-ja :num! (seek! max 0.75) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek! max 0.75))
      )
    (process-spawn
      part-tracker
      :init part-tracker-init
      (-> *part-group-id-table* 201)
      -1
      #f
      #f
      #f
      (-> self root-override trans)
      :to *entity-pool*
      )
    (clear-collide-with-as (-> self root-override))
    (loop
      (orient-to-face-target)
      (suspend)
      )
    (none)
    )
  :post quicksandlurker-post
  )

;; failed to figure out what this is:
(defstate quicksandlurker-popup (quicksandlurker)
  :trans quicksandlurker-check-hide-transition
  :code (behavior ()
    (process-spawn
      part-tracker
      :init part-tracker-init
      (-> *part-group-id-table* 202)
      -1
      #f
      #f
      #f
      (-> self root-override trans)
      :to *entity-pool*
      )
    (ja-no-eval :group! quicksandlurker-popup-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (orient-to-face-target)
      (suspend)
      (ja :num! (seek!))
      )
    (go quicksandlurker-track)
    (none)
    )
  :post quicksandlurker-post
  )

;; failed to figure out what this is:
(defstate quicksandlurker-die (quicksandlurker)
  :event (the-as
    (function process int symbol event-message-block object :behavior quicksandlurker)
    process-drawable-death-event-handler
    )
  :code (behavior ()
    (logclear! (-> self mask) (process-mask actor-pause))
    (ja-channel-push! 1 (seconds 0.2))
    (ja-no-eval :group! quicksandlurker-die-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (cleanup-for-death self)
    (none)
    )
  :post quicksandlurker-post
  )

;; definition for method 11 of type quicksandlurker
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! quicksandlurker ((obj quicksandlurker) (arg0 entity-actor))
  (set! (-> obj mask) (logior (process-mask enemy) (-> obj mask)))
  (let ((s4-0 (new 'process 'collide-shape obj (collide-list-enum usually-hit-by-player))))
    (let ((s3-0 (new 'process 'collide-shape-prim-group s4-0 (the-as uint 3) 0)))
      (set! (-> s3-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid))
      (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 8192.0)
      (set-root-prim! s4-0 s3-0)
      (let ((s2-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
        (set! (-> s2-0 prim-core collide-as) (collide-kind enemy))
        (set! (-> s2-0 collide-with) (collide-kind target))
        (set! (-> s2-0 prim-core action) (collide-action solid))
        (set! (-> s2-0 prim-core offense) (collide-offense touch))
        (set! (-> s2-0 transform-index) 3)
        (set-vector! (-> s2-0 local-sphere) 0.0 0.0 0.0 4096.0)
        (append-prim s3-0 s2-0)
        )
      (let ((s2-1 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
        (set! (-> s2-1 prim-core collide-as) (collide-kind enemy))
        (set! (-> s2-1 collide-with) (collide-kind target))
        (set! (-> s2-1 prim-core action) (collide-action solid))
        (set! (-> s2-1 prim-core offense) (collide-offense touch))
        (set! (-> s2-1 transform-index) 5)
        (set-vector! (-> s2-1 local-sphere) 0.0 0.0 0.0 4096.0)
        (append-prim s3-0 s2-1)
        )
      (let ((s2-2 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 1))))
        (set! (-> s2-2 prim-core offense) (collide-offense normal-attack))
        (set! (-> s2-2 transform-index) 5)
        (set-vector! (-> s2-2 local-sphere) 0.0 -2048.0 0.0 5324.8)
        (append-prim s3-0 s2-2)
        )
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> obj root-override) s4-0)
    )
  (process-drawable-from-entity! obj arg0)
  (set! (-> obj root-override trans y) (+ -2048.0 (-> obj root-override trans y)))
  (set! (-> obj original-position quad) (-> obj root-override trans quad))
  (set! (-> obj theta-angle) (rand-vu-float-range 0.0 65536.0))
  (set! (-> obj bob-angle) (rand-vu-float-range 0.0 65536.0))
  (set! (-> obj radial-offset) 4096.0)
  (set! (-> obj y-offset) -6553.6)
  (set-yaw-angle-clear-roll-pitch! (-> obj root-override) (rand-vu-float-range 0.0 65536.0))
  (initialize-skeleton obj *quicksandlurker-sg* '())
  (set! (-> obj nav) (new 'process 'nav-control (-> obj root-override) 16 40960.0))
  (logior! (-> obj nav flags) (nav-control-flags display-marks navcf3 navcf5 navcf6 navcf7))
  (set! (-> obj fact)
        (new 'process 'fact-info-enemy obj (pickup-type eco-pill-random) (-> *FACT-bank* default-pill-inc))
        )
  (set! (-> obj mud-entity) (entity-actor-lookup (-> obj entity) 'water-actor 0))
  (go quicksandlurker-idle)
  (none)
  )
