;;-*-Lisp-*-
(in-package goal)
(bundles "VI1.DGO")
(require "engine/common-obs/process-taskable.gc")

;; DECOMP BEGINS

(deftype explorer (process-taskable) ())

(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)

(defmethod process-taskable-method-52 ((this explorer))
  (let ((v1-1 (-> this draw shadow-ctrl)))
    (when v1-1
      (let ((f0-0 (-> this root 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))

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

(defmethod play-anim! ((this explorer) (arg0 symbol))
  (set! (-> this talk-message) (text-id press-to-talk))
  (case (current-status (-> this tasks))
    (((task-status need-hint) (task-status need-introduction))
     (if arg0 (close-status! (-> this 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! (-> this skippable) #t)
     (cond
       ((zero? (get-reminder (-> this tasks) 0))
        (if arg0 (save-reminder (-> this 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 (-> this 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! (-> this cell-for-task) (current-task (-> this tasks)))
        (close-current! (-> this tasks))
        (send-event *target* 'get-pickup 5 (- (-> *GAME-bank* money-task-inc))))
       (else (set! (-> this will-talk) #t) (set! (-> this talk-message) (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~%"
               (-> this name)
               (task-status->string (current-status (-> this tasks)))))
     (-> this draw art-group data 3))))

(defmethod get-art-elem ((this explorer))
  (-> this draw art-group data 3))

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

(defmethod target-above-threshold? ((this explorer))
  (the-as symbol (and *target* (< (-> (target-pos 0) x) -202752.0) (< 98304.0 (-> (target-pos 0) z)))))

(defstate idle (explorer)
  :virtual #t
  :code
    (behavior ()
      (if (!= (ja-group) explorer-idle-ja) (ja-channel-push! 1 (seconds 0.2)))
      (loop
        (process-taskable-method-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 (current-time)))
             (while (let ((s5-0 (current-time))
                          (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 (current-time)))
               (while (let ((s5-1 (current-time))
                            (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 (current-time)))
                 (while (let ((s5-2 (current-time))
                              (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 (current-time)))
             (while (let ((s5-3 (current-time))
                          (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 (current-time)))
             (while (let ((s5-4 (current-time))
                          (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 (current-time)))
             (while (let ((s5-5 (current-time))
                          (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!))))))))

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