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

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

;; definition of type lurkerpuppy
(deftype lurkerpuppy (nav-enemy)
  ()
  :heap-base #x120
  :method-count-assert 76
  :size-assert         #x190
  :flag-assert         #x4c01200190
  )

;; definition for method 3 of type lurkerpuppy
(defmethod inspect lurkerpuppy ((obj lurkerpuppy))
  (let ((t9-0 (method-of-type nav-enemy inspect)))
    (t9-0 obj)
    )
  obj
  )

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

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

;; failed to figure out what this is:
(defstate nav-enemy-notice (lurkerpuppy)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior lurkerpuppy)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (ja-no-eval :num! (loop!))
    (ja-channel-push! 1 (seconds 0.17))
    (ja-no-eval :group! lurkerpuppy-celebrate-ja :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (ja-blend-eval)
      (suspend)
      (ja :num! (seek!))
      )
    (go-virtual nav-enemy-chase)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-chase (lurkerpuppy)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior lurkerpuppy)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (cond
      ((ja-group? lurkerpuppy-jump-land-ja)
       (ja-channel-push! 1 (seconds 0.17))
       (ja-no-eval :group! lurkerpuppy-run-ja :num! (seek!) :frame-num (ja-aframe 4.0 0))
       (until (ja-done? 0)
         (suspend)
         (ja :num! (seek!))
         )
       )
      (else
        (ja-channel-push! 1 (seconds 0.17))
        )
      )
    (let ((f30-0 (rand-vu-float-range 0.9 1.1)))
      (loop
        (if (rand-vu-percent? 0.25)
            (sound-play "puppy-bark")
            )
        (ja-no-eval :group! lurkerpuppy-run-ja :num! (seek! max f30-0) :frame-num 0.0)
        (until (ja-done? 0)
          (if (logtest? (-> self nav-enemy-flags) (nav-enemy-flags navenmf8))
              (go-virtual nav-enemy-attack)
              )
          (suspend)
          (ja :num! (seek! max f30-0))
          )
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-stare (lurkerpuppy)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior lurkerpuppy)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (set! (-> self rotate-speed) 1456355.5)
    (set! (-> self turn-time) (seconds 0.1))
    (logclear! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
    (let ((f30-0 (rand-vu-float-range 0.8 1.2)))
      (loop
        (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
        (ja-channel-push! 1 (seconds 0.1))
        (ja-no-eval :group! lurkerpuppy-celebrate-ja :num! (seek! (ja-aframe 12.0 0) f30-0) :frame-num 0.0)
        (until (ja-done? 0)
          (let ((f0-3 (ja-aframe-num 0)))
            (logclear! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
            (if (and (>= f0-3 2.5) (>= 7.5 f0-3))
                (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
                )
            )
          (suspend)
          (ja :num! (seek! (ja-aframe 12.0 0) f30-0))
          )
        (logclear! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
        (ja-no-eval :num! (loop!))
        (ja-channel-push! 1 (seconds 0.1))
        (ja :group! lurkerpuppy-idle-ja)
        (ja :num-func num-func-identity :frame-num 0.0)
        (let ((gp-2 (rand-vu-int-range 750 900))
              (s5-0 (-> *display* base-frame-counter))
              )
          (until (>= (- (-> *display* base-frame-counter) s5-0) gp-2)
            (ja :num! (loop!))
            (ja-blend-eval)
            (suspend)
            )
          )
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-give-up (lurkerpuppy)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior lurkerpuppy)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (set! (-> self rotate-speed) 218453.33)
    (set! (-> self turn-time) (seconds 0.5))
    (ja-channel-push! 1 (seconds 0.075))
    (ja-no-eval :group! lurkerpuppy-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! lurkerpuppy-idle-ja :num! (seek! max 1.4) :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! max 1.4))
      )
    (go-virtual nav-enemy-patrol)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-attack (lurkerpuppy)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior lurkerpuppy)
    nav-enemy-default-event-handler
    )
  :code (behavior ()
    (sound-play "head-butt")
    (go-virtual nav-enemy-victory)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate nav-enemy-victory (lurkerpuppy)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior lurkerpuppy)
    nav-enemy-default-event-handler
    )
  :exit (behavior ()
    (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
    (none)
    )
  :code (behavior ()
    (logclear! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
    (ja-channel-push! 1 (seconds 0.075))
    (dotimes (gp-0 4)
      (ja-no-eval :group! lurkerpuppy-celebrate-ja :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (let ((f0-4 (ja-aframe-num 0)))
          (logclear! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
          (if (and (>= f0-4 2.5) (>= 7.5 f0-4))
              (logior! (-> self nav-enemy-flags) (nav-enemy-flags enable-travel))
              )
          )
        (suspend)
        (ja :num! (seek!))
        )
      )
    (go-virtual nav-enemy-chase)
    (none)
    )
  :post (the-as (function none :behavior lurkerpuppy) nav-enemy-face-player-post)
  )

;; definition for symbol *lurkerpuppy-nav-enemy-info*, type nav-enemy-info
(define *lurkerpuppy-nav-enemy-info* (new 'static 'nav-enemy-info
                                       :idle-anim 5
                                       :walk-anim 6
                                       :turn-anim 6
                                       :notice-anim 8
                                       :run-anim 7
                                       :jump-anim 9
                                       :jump-land-anim 10
                                       :victory-anim 8
                                       :taunt-anim 8
                                       :die-anim 11
                                       :neck-joint -1
                                       :player-look-at-joint 5
                                       :run-travel-speed (meters 5)
                                       :run-rotate-speed (degrees 3999.9998)
                                       :run-acceleration (meters 1)
                                       :run-turn-time (seconds 0.15)
                                       :walk-travel-speed (meters 2)
                                       :walk-rotate-speed (degrees 1999.9999)
                                       :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 1)
                                       :nav-nearest-y-threshold (meters 10)
                                       :notice-distance (meters 30)
                                       :stop-chase-distance (meters 40)
                                       :frustration-distance (meters 8)
                                       :frustration-time (seconds 4)
                                       :die-anim-hold-frame 6.0
                                       :jump-anim-start-frame 3.5
                                       :jump-land-anim-end-frame 14.0
                                       :jump-height-min (meters 1)
                                       :jump-height-factor 0.5
                                       :jump-start-anim-speed 1.0
                                       :shadow-max-y (meters 0.5)
                                       :shadow-min-y (meters -1)
                                       :shadow-locus-dist (meters 150)
                                       :use-align #f
                                       :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 #f
                                       :use-jump-patrol #f
                                       :gnd-collide-with (collide-kind background)
                                       :debug-draw-neck #f
                                       :debug-draw-jump #f
                                       )
        )

;; definition for method 47 of type lurkerpuppy
;; INFO: Return type mismatch int vs none.
(defmethod initialize-collision lurkerpuppy ((obj lurkerpuppy))
  (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-sphere s5-0 (the-as uint 3))))
      (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! (-> s4-0 prim-core offense) (collide-offense normal-attack))
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 4915.2)
      (set-root-prim! s5-0 s4-0)
      )
    (set! (-> s5-0 nav-radius) 2048.0)
    (backup-collide-with-as s5-0)
    (set! (-> obj collide-info) s5-0)
    )
  0
  (none)
  )

;; definition for method 48 of type lurkerpuppy
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-48 lurkerpuppy ((obj lurkerpuppy))
  (initialize-skeleton obj *lurkerpuppy-sg* '())
  (TODO-RENAME-45 obj *lurkerpuppy-nav-enemy-info*)
  (when (nonzero? (-> obj neck))
    (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)
  )
