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

;; DECOMP BEGINS

(deftype oracle (process-taskable)
  ((first-task     uint8)
   (second-task    uint8)
   (left-eye-cell  handle)
   (right-eye-cell handle)))

(defskelgroup *oracle-sg*
  oracle
  oracle-lod0-jg
  oracle-idle-ja
  ((oracle-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 0 0 4))

(defmethod play-anim! ((this oracle) (arg0 symbol))
  (set! (-> this talk-message) (text-id press-to-talk))
  (case (current-status (-> this tasks))
    (((task-status need-hint) (task-status need-introduction))
     (when arg0
       (close-specific-task! (the-as game-task (-> this first-task)) (task-status need-introduction))
       (close-specific-task! (the-as game-task (-> this second-task)) (task-status need-introduction)))
     (case (-> (level-get-target-inside *level*) name)
       (('village1) (new 'static 'spool-anim :name "oracle-intro-1" :index 9 :parts 5 :command-list '()))
       (('village2)
        (new 'static
             'spool-anim
             :name "oracle-intro-2"
             :index 11
             :parts 4
             :command-list
             '((0 kill "pontoonten-20")
              (0 kill "pontoonten-19")
              (0 kill "pontoonten-18")
              (0 kill "pontoonten-15")
              (0 kill "pontoonten-14")
              (0 kill "pontoonfive-14")
              (0 kill "pontoonfive-15")
              (0 kill "pontoonfive-19")
              (0 kill "pontoonfive-20")
              (0 kill "med-res-level-12")
              (0 kill "med-res-level-13")
              (0 kill "med-res-level-15")
              (0 kill "money-2844")
              (0 kill "money-2845")
              (0 kill "money-2846")
              (0 kill "money-2847")
              (0 kill "money-2848")
              (0 kill "money-2849")
              (0 kill "money-2850")
              (0 kill "money-2854")
              (0 kill "money-2855")
              (0 kill "money-2856")
              (0 kill "money-2860")
              (0 kill "money-2861")
              (0 kill "money-2862")
              (0 kill "eco-27")
              (0 kill "eco-26")
              (0 kill "sharkey-25")
              (0 kill "barrel-13")
              (0 kill "barrel-14")
              (0 kill "barrel-15")
              (0 kill "barrel-16")
              (0 kill "barrel-17")
              (0 kill "barrel-18")
              (0 kill "barrel-19")
              (0 kill "barrel-20")
              (0 kill "barrel-21")
              (0 kill "barrel-22")
              (0 kill "barrel-23")
              (0 kill "villageb-part-18")
              (0 kill "villageb-part-19")
              (0 kill "villageb-part-20")
              (0 kill "villageb-part-21")
              (0 kill "villageb-part-28")
              (0 kill "villageb-part-29")
              (0 kill "villageb-part-30")
              (0 kill "villageb-part-31")
              (0 kill "villageb-part-32")
              (0 kill "villageb-part-33")
              (0 kill "villageb-part-35")
              (0 kill "villageb-part-37")
              (0 kill "villageb-part-38")
              (0 kill "villageb-part-47")
              (0 kill "villageb-part-48")
              (0 kill "villageb-part-49")
              (0 kill "villageb-part-50")
              (0 kill "villageb-part-56")
              (0 kill "villageb-part-62")
              (0 kill "villageb-part-63")
              (0 kill "villageb-ogreboss-1")
              (0 kill "crate-3127")
              (0 kill "crate-3128")
              (0 kill "crate-3129")
              (0 kill "crate-3133")
              (0 kill "geologist-1")
              (0 kill "fireboulder-2")
              (0 kill "fireboulder-3")
              (0 kill "fireboulder-4")
              (0 kill "water-vol-100")
              (0 kill "water-vol-101")
              (0 kill "water-vol-102")
              (0 kill "water-vol-103")
              (0 kill "water-vol-284")
              (0 kill "water-vol-285")
              (0 kill "water-vol-286")
              (0 kill "ceilingflag-6")
              (0 kill "ceilingflag-7")
              (0 kill "ceilingflag-8")
              (0 kill "ceilingflag-9")
              (0 kill "orb-cache-top-14")
              (0 setting-reset ocean-off near)
              (399 setting-unset ocean-off))))
       (('village3) (new 'static 'spool-anim :name "oracle-intro-3" :index 13 :parts 4 :command-list '()))))
    (((task-status need-reminder))
     (set! (-> this skippable) #t)
     (case (-> (level-get-target-inside *level*) name)
       (('village1) (new 'static 'spool-anim :name "oracle-reminder-1" :index 10 :parts 4 :command-list '()))
       (('village2) (new 'static 'spool-anim :name "oracle-reminder-2" :index 12 :parts 2 :command-list '()))
       (('village3) (new 'static 'spool-anim :name "oracle-reminder-3" :index 14 :parts 2 :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-oracle-inc)))
        (cond
          ((= (current-task (-> this tasks)) (-> this first-task))
           (let ((a0-25 (handle->process (-> this right-eye-cell)))) (if a0-25 (deactivate a0-25))))
          (else (let ((a0-29 (handle->process (-> this left-eye-cell)))) (if a0-29 (deactivate a0-29))))))
       (else (set! (-> this will-talk) #t) (set! (-> this talk-message) (text-id press-to-trade-money-oracle))))
     (cond
       ((= (current-task (-> this tasks)) (-> this first-task))
        (case (-> (level-get-target-inside *level*) name)
          (('village1) (new 'static 'spool-anim :name "oracle-right-eye-1" :index 3 :parts 2 :command-list '()))
          (('village2) (new 'static 'spool-anim :name "oracle-right-eye-2" :index 5 :parts 2 :command-list '()))
          (('village3) (new 'static 'spool-anim :name "oracle-right-eye-3" :index 7 :parts 2 :command-list '()))))
       (else
        (case (-> (level-get-target-inside *level*) name)
          (('village1) (new 'static 'spool-anim :name "oracle-left-eye-1" :index 4 :parts 2 :command-list '()))
          (('village2) (new 'static 'spool-anim :name "oracle-left-eye-2" :index 6 :parts 2 :command-list '()))
          (('village3) (new 'static 'spool-anim :name "oracle-left-eye-3" :index 8 :parts 2 :command-list '()))))))
    (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 2))))

(defmethod get-art-elem ((this oracle))
  (-> this draw art-group data 2))

(defstate idle (oracle)
  :virtual #t
  :exit
    (behavior ()
      (stop! (-> self sound))
      ((-> (method-of-type process-taskable idle) exit)))
  :trans
    (behavior ()
      (update! (-> self sound))
      ((-> (method-of-type process-taskable idle) trans))))

(defmethod init-from-entity! ((this oracle) (arg0 entity-actor))
  (process-taskable-method-40 this arg0 *oracle-sg* 3 4 (new 'static 'vector :y -4096.0 :w 4096.0) -1)
  (set! (-> this sound) (new 'process 'ambient-sound (static-sound-spec "oracle-sleep" :fo-max 50) (-> this root trans)))
  (set! (-> this first-task) (the-as uint (-> arg0 extra perm task)))
  (set! (-> this second-task) (res-lump-value arg0 'alt-task uint))
  (set! (-> this tasks) (get-task-control (the-as game-task (-> this first-task))))
  (set! (-> this right-eye-cell) (the-as handle #f))
  (set! (-> this left-eye-cell) (the-as handle #f))
  (logior! (-> this draw status) (draw-status skip-bones))
  (let ((s4-0 (new 'stack-no-clear 'vector))
        (s5-1 (lambda :behavior oracle ()
                (let* ((gp-0 (-> self root))
                       (v1-1 (if (and (nonzero? gp-0) (type-type? (-> gp-0 type) collide-shape)) gp-0))
                       (a1-1 (if v1-1 (-> v1-1 root-prim prim-core) (-> self root trans))))
                  (spawn (-> self part) (the-as vector a1-1)))
                0
                (none))))
    (ja-post)
    (when (not (task-closed? (the-as game-task (-> this first-task)) (task-status need-resolution)))
      (vector<-cspace! s4-0 (-> this node-list data 5))
      (set! (-> this right-eye-cell)
            (ppointer->handle (manipy-spawn s4-0 (-> this entity) *fuel-cell-sg* (new 'static 'vector :w 4915.2) :to this)))
      (send-event (handle->process (-> this right-eye-cell))
                  'eval
                  (lambda :behavior oracle ()
                    (let ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self)))
                      (set! (-> self part) v0-0)
                      (the-as sparticle-launch-group v0-0))))
      (send-event (handle->process (-> this right-eye-cell)) 'trans-hook s5-1))
    (when (not (task-closed? (the-as game-task (-> this second-task)) (task-status need-resolution)))
      (vector<-cspace! s4-0 (-> this node-list data 6))
      (set! (-> this left-eye-cell)
            (ppointer->handle (manipy-spawn s4-0 (-> this entity) *fuel-cell-sg* (new 'static 'vector :w 4915.2) :to this)))
      (send-event (handle->process (-> this left-eye-cell))
                  'eval
                  (lambda :behavior oracle ()
                    (let ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self)))
                      (set! (-> self part) v0-0)
                      (the-as sparticle-launch-group v0-0))))
      (send-event (handle->process (-> this left-eye-cell)) 'trans-hook s5-1)))
  (process-taskable-method-42 this)
  (none))
