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

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

;; definition of type bonelurker
(deftype bonelurker (nav-enemy)
  ((bump-player-time time-frame  :offset-assert 400)
   )
  :heap-base #x130
  :method-count-assert 76
  :size-assert         #x198
  :flag-assert         #x4c01300198
  (:states
    bonelurker-stun
    )
  )

;; definition for method 3 of type bonelurker
(defmethod inspect bonelurker ((obj bonelurker))
  (let ((t9-0 (method-of-type nav-enemy inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tbump-player-time: ~D~%" (-> obj bump-player-time))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *bonelurker-sg* bonelurker bonelurker-lod0-jg bonelurker-idle-ja
              ((bonelurker-lod0-mg (meters 20)) (bonelurker-lod1-mg (meters 40)) (bonelurker-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 2 0 6)
              :shadow bonelurker-shadow-mg
              )

;; definition for function bonelurker-set-small-bounds-sphere
;; INFO: Return type mismatch int vs none.
(defbehavior bonelurker-set-small-bounds-sphere bonelurker ()
  (set! (-> self draw bounds w) 12288.0)
  0
  (none)
  )

;; definition for function bonelurker-set-large-bounds-sphere
;; INFO: Return type mismatch int vs none.
(defbehavior bonelurker-set-large-bounds-sphere bonelurker ()
  (set! (-> self draw bounds w) 24576.0)
  0
  (none)
  )

;; definition for method 44 of type bonelurker
;; INFO: Return type mismatch symbol vs object.
(defmethod dummy-44 bonelurker ((obj bonelurker) (arg0 process) (arg1 event-message-block))
  (the-as object (when (and (logtest? (-> obj nav-enemy-flags) (nav-enemy-flags navenmf6))
                            ((method-of-type touching-shapes-entry prims-touching?)
                             (the-as touching-shapes-entry (-> arg1 param 0))
                             (-> obj collide-info)
                             (the-as uint 1)
                             )
                            )
                   (when (nav-enemy-send-attack arg0 (the-as touching-shapes-entry (-> arg1 param 0)) 'generic)
                     (set! (-> obj speed-scale) 0.5)
                     #t
                     )
                   )
          )
  )

;; definition for method 43 of type bonelurker
;; INFO: Return type mismatch symbol vs object.
(defmethod dummy-43 bonelurker ((obj bonelurker) (arg0 process) (arg1 event-message-block))
  (with-pp
    (set! (-> obj state-time) (-> *display* base-frame-counter))
    (let ((a1-1 (new 'stack-no-clear 'event-message-block)))
      (set! (-> a1-1 from) pp)
      (set! (-> a1-1 num-params) 2)
      (set! (-> a1-1 message) 'query)
      (set! (-> a1-1 param 0) (the-as uint 'powerup))
      (set! (-> a1-1 param 1) (the-as uint 2))
      (the-as
        object
        (cond
          ((or (send-event-function *target* a1-1) (= (-> arg1 param 1) 'explode))
           (logclear! (-> obj mask) (process-mask actor-pause))
           (go (method-of-object obj nav-enemy-die))
           'die
           )
          (else
            (cond
              (((method-of-type touching-shapes-entry prims-touching?)
                (the-as touching-shapes-entry (-> arg1 param 0))
                (-> obj collide-info)
                (the-as uint 2)
                )
               (send-event arg0 'shove (-> arg1 param 0) (static-attack-info ((shove-back (meters 4)))))
               (go bonelurker-stun)
               #t
               )
              ((and ((method-of-type touching-shapes-entry prims-touching?)
                     (the-as touching-shapes-entry (-> arg1 param 0))
                     (-> obj collide-info)
                     (the-as uint 1)
                     )
                    (= (-> obj skel root-channel 0) (-> obj skel channel))
                    (let ((v1-30 (if (> (-> obj skel active-channels) 0)
                                     (-> obj skel root-channel 0 frame-group)
                                     )
                                 )
                          )
                      (or (= v1-30 (-> obj draw art-group data 9)) (= v1-30 (-> obj draw art-group data 10)))
                      )
                    )
               (send-event arg0 'shove (-> arg1 param 0) (static-attack-info ((shove-back (meters 4)))))
               (set! (-> obj bump-player-time) (-> *display* base-frame-counter))
               (logclear! (-> obj nav-enemy-flags) (nav-enemy-flags navenmf6))
               'push
               )
              )
            )
          )
        )
      )
    )
  )

;; definition for function bonelurker-stunned-event-handler
;; INFO: Return type mismatch symbol vs object.
(defbehavior bonelurker-stunned-event-handler bonelurker ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (let ((v1-0 arg2))
    (the-as object (when (= v1-0 'attack)
                     (when (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.5))
                       (nav-enemy-set-hit-from-direction arg0)
                       (send-event arg0 'get-attack-count 1)
                       (logclear! (-> self mask) (process-mask actor-pause))
                       (go-virtual nav-enemy-die)
                       'die
                       )
                     )
            )
    )
  )

;; failed to figure out what this is:
nav-enemy-default-event-handler

;; definition for function bonelurker-push-post
;; Used lq/sq
(defbehavior bonelurker-push-post bonelurker ()
  (compute-alignment! (-> self align))
  (dummy-11 (-> self nav) (-> self nav target-pos))
  (align-vel-and-quat-only!
    (-> self align)
    (align-opts adjust-xz-vel)
    (-> self nav travel)
    (the-as int 1.0)
    1.0
    (* (-> self enemy-info speed) (-> self speed-scale))
    )
  (vector-v++!
    (-> self collide-info transv)
    (compute-acc-due-to-gravity (-> self collide-info) (new-stack-vector0) 0.0)
    )
  (align! (-> self align) (align-opts adjust-quat) 1.0 1.0 1.0)
  (integrate-for-enemy-with-move-to-ground!
    (-> self collide-info)
    (-> self collide-info transv)
    (collide-kind background)
    8192.0
    #t
    #f
    #f
    )
  (nav-enemy-common-post)
  (none)
  )

;; failed to figure out what this is:
(defstate nav-enemy-idle (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :exit (behavior ()
    (bonelurker-set-large-bounds-sphere)
    (none)
    )
  :code (behavior ()
    (bonelurker-set-small-bounds-sphere)
    ((the-as (function none :behavior bonelurker) (-> (method-of-type nav-enemy nav-enemy-idle) code)))
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-patrol (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (ja-channel-push! 1 (seconds 0.2))
    ((the-as (function none :behavior bonelurker) (-> (method-of-type nav-enemy nav-enemy-patrol) code)))
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-notice (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :code (-> (method-of-type nav-enemy nav-enemy-notice) code)
  )

;; failed to figure out what this is:
(defstate nav-enemy-chase (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :trans (behavior ()
    ((-> (method-of-type nav-enemy nav-enemy-chase) trans))
    (if (and (zero? (logand (-> self nav-enemy-flags) (nav-enemy-flags navenmf6)))
             (>= (- (-> *display* base-frame-counter) (-> self bump-player-time)) (seconds 0.5))
             )
        (logior! (-> self nav-enemy-flags) (nav-enemy-flags navenmf6))
        )
    (none)
    )
  :code (behavior ()
    (set! (-> self rotate-speed) 524288.0)
    (set! (-> self turn-time) (seconds 0.1))
    (set! (-> self speed-scale) 1.0)
    (let ((f30-0 (nav-enemy-rnd-float-range 0.8 1.2)))
      (cond
        ((ja-group? bonelurker-win-ja)
         (ja-channel-push! 1 (seconds 0.3))
         )
        ((ja-group? bonelurker-stun-ja)
         (ja-channel-push! 1 (seconds 0.2))
         )
        (else
          (ja-channel-push! 1 (seconds 0.15))
          )
        )
      (ja-no-eval :group! bonelurker-charge-left-ja :num! (seek! max f30-0) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek! max f30-0))
        )
      (ja-no-eval :group! bonelurker-charge-right-ja :num! (seek! max f30-0) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek! max f30-0))
        )
      (loop
        (cond
          ((or (not *target*)
               (< 36864.0 (vector-vector-distance (-> self collide-info trans) (-> *target* control trans)))
               )
           (ja-no-eval :group! bonelurker-charge-ja :num! (seek! max f30-0) :frame-num 0.0)
           (until (ja-done? 0)
             (suspend)
             (ja :num! (seek! max f30-0))
             )
           )
          (else
            (ja-no-eval :group! bonelurker-charge-left-ja :num! (seek! max f30-0) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek! max f30-0))
              )
            (if (logtest? (-> self nav-enemy-flags) (nav-enemy-flags navenmf8))
                (go-virtual nav-enemy-victory)
                )
            (ja-no-eval :group! bonelurker-charge-right-ja :num! (seek! max f30-0) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek! max f30-0))
              )
            (if (logtest? (-> self nav-enemy-flags) (nav-enemy-flags navenmf8))
                (go-virtual nav-enemy-victory)
                )
            (ja-no-eval :group! bonelurker-charge-ja :num! (seek! max f30-0) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek! max f30-0))
              )
            )
          )
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-stop-chase (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :code (-> (method-of-type nav-enemy nav-enemy-stop-chase) code)
  )

;; failed to figure out what this is:
(defstate nav-enemy-stare (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (set! (-> self rotate-speed) 524288.0)
    (set! (-> self turn-time) (seconds 0.2))
    (let ((f30-0 (rand-vu-float-range 0.8 1.2)))
      (when (and (nav-enemy-player-vulnerable?) (nav-enemy-rnd-percent? 0.5))
        (ja-channel-push! 1 (seconds 0.1))
        (ja-no-eval :group! bonelurker-win-ja :num! (seek! (ja-aframe 48.0 0) f30-0) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek! (ja-aframe 48.0 0) f30-0))
          )
        )
      (loop
        (when (not (nav-enemy-facing-player? 2730.6667))
          (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
          (ja-channel-push! 1 (seconds 0.2))
          (ja :group! bonelurker-turn-ja)
          (ja :num-func num-func-identity :frame-num 0.0)
          (until (nav-enemy-facing-player? 1820.4445)
            (ja-blend-eval)
            (suspend)
            (ja :num! (loop!))
            )
          (logclear! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
          )
        (ja-channel-push! 1 (seconds 0.25))
        (ja-no-eval :group! bonelurker-idle-ja :num! (seek! max f30-0) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek! max f30-0))
          )
        (ja-no-eval :num! (loop!))
        (when (rand-vu-percent? 0.15)
          (ja-channel-push! 1 (seconds 0.1))
          (ja-no-eval :group! bonelurker-win-ja :num! (seek! (ja-aframe 48.0 0) f30-0) :frame-num 0.0)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek! (ja-aframe 48.0 0) f30-0))
            )
          )
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-give-up (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (set! (-> self rotate-speed) 524288.0)
    (set! (-> self turn-time) (seconds 0.1))
    (ja-channel-push! 1 (seconds 0.15))
    (let ((s4-0 (-> self collide-info))
          (s5-0 (target-pos 0))
          )
      (when (< (fabs
                 (deg-diff (y-angle s4-0) (vector-y-angle (vector-! (new 'stack-no-clear 'vector) s5-0 (-> s4-0 trans))))
                 )
               12743.111
               )
        (ja-no-eval :group! bonelurker-idle-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))
          )
        (ja-no-eval :group! bonelurker-idle-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))
          )
        (ja-no-eval :group! bonelurker-idle-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))
          )
        )
      )
    (logclear! (-> self nav flags) (nav-control-flags navcf17 navcf19))
    (nav-enemy-get-new-patrol-point)
    (ja-no-eval :group! bonelurker-idle-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (seek-to-point-toward-point!
        (-> self collide-info)
        (-> self nav destination-pos)
        (-> self rotate-speed)
        (-> self turn-time)
        )
      (suspend)
      (ja :num! (seek!))
      )
    (go-virtual nav-enemy-patrol)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-victory (bonelurker)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior bonelurker)
    nav-enemy-default-event-handler
    )
  :code (-> (method-of-type nav-enemy nav-enemy-victory) code)
  )

;; failed to figure out what this is:
(defstate bonelurker-stun (bonelurker)
  :event bonelurker-stunned-event-handler
  :enter (behavior ()
    (nav-enemy-neck-control-inactive)
    (none)
    )
  :exit (behavior ()
    (nav-enemy-neck-control-look-at)
    (none)
    )
  :code (behavior ()
    (let ((gp-0 (new 'stack-no-clear 'vector)))
      (vector-normalize-copy! gp-0 (-> self hit-from-dir) 16384.0)
      (vector+! gp-0 (-> self collide-info trans) gp-0)
      (set! (-> self nav target-pos quad) (-> gp-0 quad))
      )
    (ja-channel-push! 1 (seconds 0.1))
    (ja-no-eval :group! bonelurker-stun-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (go-virtual nav-enemy-chase)
    (none)
    )
  :post bonelurker-push-post
  )

;; definition for symbol *bonelurker-nav-enemy-info*, type nav-enemy-info
(define *bonelurker-nav-enemy-info* (new 'static 'nav-enemy-info
                                      :idle-anim 5
                                      :walk-anim 6
                                      :turn-anim 16
                                      :notice-anim 7
                                      :run-anim 8
                                      :jump-anim 17
                                      :jump-land-anim 18
                                      :victory-anim 13
                                      :taunt-anim 13
                                      :die-anim 14
                                      :neck-joint 5
                                      :player-look-at-joint 5
                                      :run-travel-speed (meters 6)
                                      :run-rotate-speed (degrees 2880.0)
                                      :run-acceleration (meters 1)
                                      :run-turn-time (seconds 0.1)
                                      :walk-travel-speed (meters 3)
                                      :walk-rotate-speed (degrees 2880.0)
                                      :walk-acceleration (meters 1)
                                      :walk-turn-time (seconds 0.1)
                                      :attack-shove-back (meters 3)
                                      :attack-shove-up (meters 2)
                                      :shadow-size (meters 2)
                                      :notice-nav-radius (meters 5)
                                      :nav-nearest-y-threshold (meters 5)
                                      :notice-distance (meters 30)
                                      :stop-chase-distance (meters 40)
                                      :frustration-distance (meters 8)
                                      :frustration-time (seconds 4)
                                      :die-anim-hold-frame 24.0
                                      :jump-anim-start-frame 10.0
                                      :jump-land-anim-end-frame 32.0
                                      :jump-height-min (meters 3)
                                      :jump-height-factor 0.5
                                      :jump-start-anim-speed 1.0
                                      :shadow-max-y (meters 1)
                                      :shadow-min-y (meters -1)
                                      :shadow-locus-dist (meters 150)
                                      :use-align #t
                                      :draw-shadow #t
                                      :move-to-ground #t
                                      :hover-if-no-ground #f
                                      :use-momentum #f
                                      :use-flee #f
                                      :use-proximity-notice #f
                                      :use-jump-blocked #t
                                      :use-jump-patrol #f
                                      :gnd-collide-with (collide-kind background)
                                      :debug-draw-neck #f
                                      :debug-draw-jump #f
                                      )
        )

;; definition for method 47 of type bonelurker
;; INFO: Return type mismatch int vs none.
(defmethod initialize-collision bonelurker ((obj bonelurker))
  (let ((s5-0 (new 'process 'collide-shape-moving obj (collide-list-enum usually-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-group s5-0 (the-as uint 3) 0)))
      (set! (-> s4-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s4-0 collide-with) (collide-kind target))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 10240.0 0.0 24576.0)
      (set-root-prim! s5-0 s4-0)
      (let ((s3-0 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 3))))
        (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! (-> s3-0 prim-core offense) (collide-offense touch))
        (set-vector! (-> s3-0 local-sphere) 0.0 8192.0 0.0 4096.0)
        (append-prim s4-0 s3-0)
        )
      (let ((s3-1 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 3))))
        (set! (-> s3-1 prim-core collide-as) (collide-kind enemy))
        (set! (-> s3-1 collide-with) (collide-kind target))
        (set! (-> s3-1 prim-core action) (collide-action solid))
        (set! (-> s3-1 prim-core offense) (collide-offense touch))
        (set-vector! (-> s3-1 local-sphere) 0.0 11468.8 0.0 4096.0)
        (append-prim s4-0 s3-1)
        )
      (let ((s3-2 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 1))))
        (set! (-> s3-2 prim-core collide-as) (collide-kind enemy))
        (set! (-> s3-2 collide-with) (collide-kind target))
        (set! (-> s3-2 prim-core offense) (collide-offense normal-attack))
        (set! (-> s3-2 transform-index) 29)
        (set-vector! (-> s3-2 local-sphere) 0.0 4915.2 0.0 4915.2)
        (append-prim s4-0 s3-2)
        )
      )
    (set! (-> s5-0 nav-radius) 8192.0)
    (backup-collide-with-as s5-0)
    (set! (-> s5-0 max-iteration-count) (the-as uint 1))
    (set! (-> obj collide-info) s5-0)
    )
  0
  (none)
  )

;; definition for method 48 of type bonelurker
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-48 bonelurker ((obj bonelurker))
  (initialize-skeleton obj *bonelurker-sg* '())
  (TODO-RENAME-45 obj *bonelurker-nav-enemy-info*)
  (set! (-> obj neck up) (the-as uint 0))
  (set! (-> obj neck nose) (the-as uint 1))
  (set! (-> obj neck ear) (the-as uint 2))
  0
  (none)
  )
