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

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

;; definition of type explorer
(deftype explorer (process-taskable)
  ()
  :heap-base #x110
  :method-count-assert 53
  :size-assert         #x17c
  :flag-assert         #x350110017c
  )

;; definition for method 3 of type explorer
(defmethod inspect explorer ((obj explorer))
  (let ((t9-0 (method-of-type process-taskable inspect)))
    (t9-0 obj)
    )
  obj
  )

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

;; definition for method 52 of type explorer
;; INFO: Return type mismatch shadow-flags vs none.
(defmethod dummy-52 explorer ((obj explorer))
  (let ((v1-1 (-> obj draw shadow-ctrl)))
    (when v1-1
      (let ((f0-0 (-> obj root-override trans y)))
        (let ((a0-2 v1-1))
          (set! (-> a0-2 settings bot-plane w) (- (+ -4096.0 f0-0)))
          )
        0
        (let ((a0-4 v1-1))
          (set! (-> a0-4 settings top-plane w) (- (+ 4096.0 f0-0)))
          )
        )
      0
      (logclear! (-> v1-1 settings flags) (shadow-flags shdf03))
      )
    )
  (none)
  )

;; definition for method 48 of type explorer
(defmethod draw-npc-shadow explorer ((obj explorer))
  (-> obj draw shadow-ctrl)
  (cond
    ((and (-> obj draw shadow)
          (zero? (-> obj draw cur-lod))
          (logtest? (-> obj draw status) (draw-status was-drawn))
          )
     (let ((v1-9 (-> obj draw shadow-ctrl)))
       (logclear! (-> v1-9 settings flags) (shadow-flags disable-draw))
       )
     0
     (update-direction-from-time-of-day (-> obj draw shadow-ctrl))
     )
    (else
      (let ((v1-14 (-> obj draw shadow-ctrl)))
        (logior! (-> v1-14 settings flags) (shadow-flags disable-draw))
        )
      0
      )
    )
  (none)
  )

;; definition for method 32 of type explorer
(defmethod play-anim! explorer ((obj explorer) (arg0 symbol))
  (set! (-> obj talk-message) (game-text-id press-to-talk))
  (case (current-status (-> obj tasks))
    (((task-status need-hint) (task-status need-introduction))
     (if arg0
         (close-status! (-> obj tasks) (task-status need-introduction))
         )
     (new 'static 'spool-anim
       :name "explorer-introduction"
       :index 9
       :parts 11
       :command-list '((418 joint "cameraB") (695 shadow self #f) (695 joint "camera") (838 shadow self #t) (838 joint "cameraB"))
       )
     )
    (((task-status need-reminder))
     (set! (-> obj skippable) #t)
     (cond
       ((zero? (get-reminder (-> obj tasks) 0))
        (if arg0
            (save-reminder (-> obj tasks) 1 0)
            )
        (new 'static 'spool-anim
          :name "explorer-reminder-1"
          :index 10
          :parts 5
          :command-list '((0 send-event target draw #f)
            (148 send-event target draw #t)
            (148 joint "cameraB")
            (390 send-event target draw #f)
            (390 joint "camera")
            (505 send-event target draw #t)
            )
          )
        )
       (else
         (if arg0
             (save-reminder (-> obj tasks) 0 0)
             )
         (new 'static 'spool-anim :name "explorer-reminder-2" :index 11 :parts 3 :command-list '())
         )
       )
     )
    (((task-status need-reward-speech))
     (cond
       (arg0
         (set! (-> obj cell-for-task) (current-task (-> obj tasks)))
         (close-current! (-> obj tasks))
         (send-event *target* 'get-pickup 5 (- (-> *GAME-bank* money-task-inc)))
         )
       (else
         (set! (-> obj will-talk) #t)
         (set! (-> obj talk-message) (game-text-id press-to-trade-money))
         )
       )
     (new 'static 'spool-anim
       :name "explorer-resolution"
       :index 12
       :parts 5
       :command-list '((167 joint "cameraB") (310 joint "camera"))
       )
     )
    (else
      (if arg0
          (format
            0
            "ERROR: <GMJ>: ~S playing anim for task status ~S~%"
            (-> obj name)
            (task-status->string (current-status (-> obj tasks)))
            )
          )
      (-> obj draw art-group data 3)
      )
    )
  )

;; definition for method 31 of type explorer
(defmethod get-art-elem explorer ((obj explorer))
  (-> obj draw art-group data 3)
  )

;; definition for method 43 of type explorer
(defmethod TODO-RENAME-43 explorer ((obj explorer))
  (when (TODO-RENAME-10 (-> obj ambient) (new 'stack-no-clear 'vector) (seconds 30) 122880.0 obj)
    (let ((f0-2 (rand-float-gen)))
      (cond
        ((< 0.85714287 f0-2)
         (play-ambient (-> obj ambient) "EXP-AM05" #f (-> obj root-override trans))
         )
        ((< 0.71428573 f0-2)
         (if (not (closed? (-> obj tasks) (game-task village1-uncle-money) (task-status need-reminder)))
             (play-ambient (-> obj ambient) "EXP-LO02" #f (-> obj root-override trans))
             )
         )
        ((< 0.5714286 f0-2)
         (play-ambient (-> obj ambient) "EXP-AM04" #f (-> obj root-override trans))
         )
        ((< 0.42857143 f0-2)
         (play-ambient (-> obj ambient) "EXP-AM03" #f (-> obj root-override trans))
         )
        ((< 0.2857143 f0-2)
         (play-ambient (-> obj ambient) "EXP-AM02" #f (-> obj root-override trans))
         )
        ((< 0.14285715 f0-2)
         (if (not (closed? (-> obj tasks) (game-task village1-uncle-money) (task-status need-reminder)))
             (play-ambient (-> obj ambient) "EXP-AM01" #f (-> obj root-override trans))
             )
         )
        (else
          (play-ambient (-> obj ambient) "EXP-LO1A" #f (-> obj root-override trans))
          )
        )
      )
    )
  )

;; definition for method 47 of type explorer
;; INFO: Return type mismatch basic vs symbol.
(defmethod target-above-threshold? explorer ((obj explorer))
  (the-as symbol (and *target* (< (-> (target-pos 0) x) -202752.0) (< 98304.0 (-> (target-pos 0) z))))
  )

;; failed to figure out what this is:
(defstate idle (explorer)
  :virtual #t
  :code (behavior ()
    (if (!= (ja-group) explorer-idle-ja)
        (ja-channel-push! 1 (seconds 0.2))
        )
    (loop
      (TODO-RENAME-43 self)
      (ja :group! explorer-idle-ja)
      (let* ((f30-0 2.0)
             (v1-11 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-12 (the-as number (logior #x3f800000 v1-11)))
             )
        (countdown (gp-0 (+ (the int (* f30-0 (+ -1.0 (the-as float v1-12)))) 1))
          (ja-no-eval :group! explorer-idle-ja :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek!))
            )
          )
        )
      (cond
        ((< (rand-float-gen) 0.5)
         (ja-no-eval :group! explorer-idle2-look-at-map-ja :num! (seek!) :frame-num 0.0)
         (until (ja-done? 0)
           (suspend)
           (ja :num! (seek!))
           )
         (let ((gp-1 (-> *display* base-frame-counter)))
           (while (let ((s5-0 (-> *display* base-frame-counter))
                        (f30-1 300.0)
                        (f28-0 0.5)
                        (f26-0 0.5)
                        )
                    (< (- s5-0 (the-as time-frame (the int (* f30-1 (+ f28-0 (* f26-0 (rand-float-gen))))))) gp-1)
                    )
             (suspend)
             )
           )
         (when (< (rand-float-gen) 0.75)
           (ja-no-eval :group! explorer-idle2-look-right-map-ja :num! (seek!) :frame-num 0.0)
           (until (ja-done? 0)
             (suspend)
             (ja :num! (seek!))
             )
           (let ((gp-2 (-> *display* base-frame-counter)))
             (while (let ((s5-1 (-> *display* base-frame-counter))
                          (f30-2 300.0)
                          (f28-1 0.5)
                          (f26-1 0.5)
                          )
                      (< (- s5-1 (the-as time-frame (the int (* f30-2 (+ f28-1 (* f26-1 (rand-float-gen))))))) gp-2)
                      )
               (suspend)
               )
             )
           (ja-no-eval :group! (ja-group) :num! (seek! 0.0) :frame-num max)
           (until (ja-done? 0)
             (suspend)
             (ja :num! (seek! 0.0))
             )
           (when (< (rand-float-gen) 0.5)
             (ja-no-eval :group! explorer-idle2-look-right-map-ja :num! (seek!) :frame-num 0.0)
             (until (ja-done? 0)
               (suspend)
               (ja :num! (seek!))
               )
             (let ((gp-3 (-> *display* base-frame-counter)))
               (while (let ((s5-2 (-> *display* base-frame-counter))
                            (f30-3 300.0)
                            (f28-2 0.5)
                            (f26-2 0.5)
                            )
                        (< (- s5-2 (the-as time-frame (the int (* f30-3 (+ f28-2 (* f26-2 (rand-float-gen))))))) gp-3)
                        )
                 (suspend)
                 )
               )
             (ja-no-eval :group! (ja-group) :num! (seek! 0.0) :frame-num max)
             (until (ja-done? 0)
               (suspend)
               (ja :num! (seek! 0.0))
               )
             )
           )
         (ja-no-eval :group! explorer-idle2-look-at-map-ja :num! (seek! 0.0) :frame-num max)
         (until (ja-done? 0)
           (suspend)
           (ja :num! (seek! 0.0))
           )
         )
        (else
          (ja-no-eval :group! explorer-idle3-step-right-ja :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek!))
            )
          (let ((gp-4 (-> *display* base-frame-counter)))
            (while (let ((s5-3 (-> *display* base-frame-counter))
                         (f30-4 300.0)
                         (f28-3 0.5)
                         (f26-3 0.5)
                         )
                     (< (- s5-3 (the-as time-frame (the int (* f30-4 (+ f28-3 (* f26-3 (rand-float-gen))))))) gp-4)
                     )
              (suspend)
              )
            )
          (ja-no-eval :group! explorer-idle3-looking-ja :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek!))
            )
          (let ((gp-5 (-> *display* base-frame-counter)))
            (while (let ((s5-4 (-> *display* base-frame-counter))
                         (f30-5 300.0)
                         (f28-4 0.5)
                         (f26-4 0.5)
                         )
                     (< (- s5-4 (the-as time-frame (the int (* f30-5 (+ f28-4 (* f26-4 (rand-float-gen))))))) gp-5)
                     )
              (suspend)
              )
            )
          (ja-no-eval :group! (ja-group) :num! (seek! 0.0) :frame-num max)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek! 0.0))
            )
          (let ((gp-6 (-> *display* base-frame-counter)))
            (while (let ((s5-5 (-> *display* base-frame-counter))
                         (f30-6 300.0)
                         (f28-5 0.5)
                         (f26-5 0.5)
                         )
                     (< (- s5-5 (the-as time-frame (the int (* f30-6 (+ f28-5 (* f26-5 (rand-float-gen))))))) gp-6)
                     )
              (suspend)
              )
            )
          (ja-no-eval :group! explorer-idle3-step-left-ja :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (suspend)
            (ja :num! (seek!))
            )
          )
        )
      )
    (none)
    )
  )

;; definition for method 11 of type explorer
(defmethod init-from-entity! explorer ((obj explorer) (arg0 entity-actor))
  (dummy-40 obj arg0 *explorer-sg* 3 42 (new 'static 'vector :w 4096.0) 5)
  (set! (-> obj tasks) (get-task-control (game-task village1-uncle-money)))
  (set! (-> obj sound-flava) (music-flava explorer))
  (set! (-> obj draw light-index) (the-as uint 5))
  (dummy-42 obj)
  (none)
  )
