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

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

;; definition of type oracle
(deftype oracle (process-taskable)
  ((first-task     uint8   :offset-assert 380)
   (second-task    uint8   :offset-assert 381)
   (left-eye-cell  handle  :offset-assert 384)
   (right-eye-cell handle  :offset-assert 392)
   )
  :heap-base #x120
  :method-count-assert 53
  :size-assert         #x190
  :flag-assert         #x3501200190
  )

;; definition for method 3 of type oracle
(defmethod inspect oracle ((obj oracle))
  (let ((t9-0 (method-of-type process-taskable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tfirst-task: ~D~%" (-> obj first-task))
  (format #t "~T~Tsecond-task: ~D~%" (-> obj second-task))
  (format #t "~T~Tleft-eye-cell: ~D~%" (-> obj left-eye-cell))
  (format #t "~T~Tright-eye-cell: ~D~%" (-> obj right-eye-cell))
  obj
  )

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

;; definition for method 32 of type oracle
(defmethod play-anim! oracle ((obj oracle) (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))
     (when arg0
       (close-specific-task! (the-as game-task (-> obj first-task)) (task-status need-introduction))
       (close-specific-task! (the-as game-task (-> obj 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! (-> obj 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! (-> obj cell-for-task) (current-task (-> obj tasks)))
         (close-current! (-> obj tasks))
         (send-event *target* 'get-pickup 5 (- (-> *GAME-bank* money-oracle-inc)))
         (cond
           ((= (current-task (-> obj tasks)) (-> obj first-task))
            (let ((a0-25 (handle->process (-> obj right-eye-cell))))
              (if a0-25
                  (deactivate a0-25)
                  )
              )
            )
           (else
             (let ((a0-29 (handle->process (-> obj left-eye-cell))))
               (if a0-29
                   (deactivate a0-29)
                   )
               )
             )
           )
         )
       (else
         (set! (-> obj will-talk) #t)
         (set! (-> obj talk-message) (game-text-id press-to-trade-money-oracle))
         )
       )
     (cond
       ((= (current-task (-> obj tasks)) (-> obj 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~%"
            (-> obj name)
            (task-status->string (current-status (-> obj tasks)))
            )
          )
      (-> obj draw art-group data 2)
      )
    )
  )

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

;; failed to figure out what this is:
(defstate idle (oracle)
  :virtual #t
  :exit (behavior ()
    (stop! (-> self sound))
    ((-> (method-of-type process-taskable idle) exit))
    (none)
    )
  :trans (behavior ()
    (update! (-> self sound))
    ((-> (method-of-type process-taskable idle) trans))
    (none)
    )
  )

;; definition for method 11 of type oracle
(defmethod init-from-entity! oracle ((obj oracle) (arg0 entity-actor))
  (dummy-40 obj arg0 *oracle-sg* 3 4 (new 'static 'vector :y -4096.0 :w 4096.0) -1)
  (set! (-> obj sound)
        (new 'process 'ambient-sound (static-sound-spec "oracle-sleep" :fo-max 50) (-> obj root-override trans))
        )
  (set! (-> obj first-task) (the-as uint (-> arg0 extra perm task)))
  (set! (-> obj second-task) (res-lump-value arg0 'alt-task uint))
  (set! (-> obj tasks) (get-task-control (the-as game-task (-> obj first-task))))
  (set! (-> obj right-eye-cell) (the-as handle #f))
  (set! (-> obj left-eye-cell) (the-as handle #f))
  (logior! (-> obj draw status) (draw-status skip-bones))
  (let ((s4-0 (new 'stack-no-clear 'vector))
        (s5-1 (lambda :behavior oracle
                ()
                (let* ((gp-0 (-> self root-override))
                       (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-override trans)
                                 )
                             )
                       )
                  (spawn (-> self part) (the-as vector a1-1))
                  )
                0
                (none)
                )
              )
        )
    (ja-post)
    (when (not (task-closed? (the-as game-task (-> obj first-task)) (task-status need-resolution)))
      (vector<-cspace! s4-0 (-> obj node-list data 5))
      (set! (-> obj right-eye-cell)
            (ppointer->handle (manipy-spawn s4-0 (-> obj entity) *fuel-cell-sg* (new 'static 'vector :w 4915.2) :to obj))
            )
      (send-event
        (handle->process (-> obj 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 (-> obj right-eye-cell)) 'trans-hook s5-1)
      )
    (when (not (task-closed? (the-as game-task (-> obj second-task)) (task-status need-resolution)))
      (vector<-cspace! s4-0 (-> obj node-list data 6))
      (set! (-> obj left-eye-cell)
            (ppointer->handle (manipy-spawn s4-0 (-> obj entity) *fuel-cell-sg* (new 'static 'vector :w 4915.2) :to obj))
            )
      (send-event
        (handle->process (-> obj 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 (-> obj left-eye-cell)) 'trans-hook s5-1)
      )
    )
  (dummy-42 obj)
  (none)
  )
