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

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

;; definition of type sage
(deftype sage (process-taskable)
  ((reminder-played basic   :offset-assert 380)
   (assistant       handle  :offset-assert 384)
   )
  :heap-base #x120
  :method-count-assert 53
  :size-assert         #x188
  :flag-assert         #x3501200188
  )

;; definition for method 3 of type sage
(defmethod inspect sage ((obj sage))
  (let ((t9-0 (method-of-type process-taskable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Treminder-played: ~A~%" (-> obj reminder-played))
  (format #t "~T~Tassistant: ~D~%" (-> obj assistant))
  obj
  )

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

;; definition for method 32 of type sage
(defmethod play-anim! sage ((obj sage) (arg0 symbol))
  (when (!= *kernel-boot-message* 'play)
    (close-specific-task! (game-task intro) (task-status need-resolution))
    (return (new 'static 'spool-anim
              :name "sage-introduction-misty-cannon"
              :index 8
              :parts 12
              :command-list '((1 blackout 0)
                (100 want-levels village1 misty)
                (261 joint "cameraB")
                (521 joint "camera")
                (776 joint "cameraB")
                (810 joint "camera")
                (1171 joint "cameraB")
                (1235 joint "camera")
                (1235 save)
                (1418 blackout 30)
                )
              )
            )
    )
  (case (current-status (-> obj tasks))
    (((task-status need-hint) (task-status need-introduction))
     (case (current-task (-> obj tasks))
       (((game-task intro))
        (when arg0
          (close-status! (-> obj tasks) (task-status need-introduction))
          (set-setting! 'music-volume-movie 'abs 0.0 0)
          (apply-settings *setting-control*)
          )
        (new 'static 'spool-anim
          :name "sage-intro-sequence-d1"
          :index 16
          :parts 17
          :command-list '((0 display-level misty #f)
            (0 display-level village1 display)
            (0 want-vis vi1)
            (0 save)
            (0 want-force-inside village1 #t)
            (0 want-force-vis village1 #t)
            (0 kill "assistant-11")
            (0 kill "reflector-middle-2")
            (0 kill "eco-11")
            (0 kill "eco-10")
            (0 kill "sharkey-12")
            (0 kill "reflector-end-1")
            (0 kill "water-vol-10")
            (0 kill "water-vol-8")
            (0 kill "water-vol-7")
            (0 kill "fishermans-boat-2")
            (0 kill "revcycleprop-2")
            (0 kill "revcycle-8")
            (0 kill "ropebridge-5")
            (0 kill "ropebridge-4")
            (0 kill "villagea-water-2")
            (0 time-of-day 7)
            (1 time-of-day -1)
            (3 blackout 0)
            (25 blackout 0)
            (25 want-force-vis village1 #f)
            (56 joint "cameraB")
            (100 want-force-inside village1 #f)
            (107 joint "camera")
            (137 joint "cameraB")
            (202 joint "camera")
            (286 joint "cameraB")
            (554 joint "camera")
            (633 joint "cameraB")
            (711 joint "camera")
            (796 joint "cameraB")
            (921 joint "camera")
            (1021 shadow self #f)
            (1021 joint "cameraB")
            (1081 joint "camera")
            (1183 joint "cameraB")
            (1221 joint "camera")
            (1496 shadow self #t)
            (1496 joint "cameraB")
            (1496 time-of-day 18)
            (1721 joint "camera")
            (1721 time-of-day 7)
            (1722 time-of-day -1)
            )
          )
        )
       (((game-task beach-ecorocks))
        (when arg0
          (let* ((s5-1 (-> obj tasks))
                 (s4-0 (method-of-object s5-1 save-reminder))
                 )
            (s4-0 s5-1 (the int (the-as float (send-event *target* 'query 'pickup (pickup-type fuel-cell)))) 1)
            )
          (close-status! (-> obj tasks) (task-status need-introduction))
          )
        (new 'static 'spool-anim
          :name "sage-intro-sequence-e"
          :index 14
          :parts 13
          :command-list '((0 want-levels village1 beach)
            (0 blackout 0)
            (197 joint "cameraB")
            (361 joint "camera")
            (660 joint "cameraB")
            (937 display-level beach movie)
            (937 want-force-vis beach #t)
            (938 alive "ecoventrock-3")
            (938 alive "ecoventrock-4")
            (938 alive "ecoventrock-5")
            (938 alive "ecoventrock-6")
            (938 alive "ecoventrock-7")
            (938 alive "harvester-87")
            (938 alive "harvester-88")
            (938 alive "harvester-89")
            (938 alive "harvester-90")
            (938 alive "harvester-91")
            (940 joint "camera")
            (1160 joint "cameraB")
            (1162 dead "ecoventrock-3")
            (1162 dead "ecoventrock-4")
            (1162 dead "ecoventrock-5")
            (1162 dead "ecoventrock-6")
            (1162 dead "ecoventrock-7")
            (1162 dead "harvester-87")
            (1162 dead "harvester-88")
            (1162 dead "harvester-89")
            (1162 dead "harvester-90")
            (1162 dead "harvester-91")
            (1310 joint "camera")
            (1313 want-force-vis beach #f)
            (1313 display-level beach #f)
            (1313 send-event "warp-gate-switch-3" 'hide)
            )
          )
        )
       (else
         (if arg0
             (close-status! (-> obj tasks) (task-status need-introduction))
             )
         (new 'static 'spool-anim
           :name "sage-introduction-misty-cannon"
           :index 8
           :parts 12
           :command-list '((0 want-levels village1 beach)
             (261 joint "cameraB")
             (521 joint "camera")
             (776 joint "cameraB")
             (810 joint "camera")
             (1171 joint "cameraB")
             (1235 joint "camera")
             )
           )
         )
       )
     )
    (((task-status need-reminder))
     (set! (-> obj skippable) #t)
     (if arg0
         (set! (-> obj reminder-played) #t)
         )
     (case (get-reminder (-> obj tasks) 0)
       ((3)
        (new 'static 'spool-anim :name "sage-reminder-2-generic" :index 13 :parts 4 :command-list '())
        )
       ((2)
        (new 'static 'spool-anim :name "sage-reminder-1-generic" :index 12 :parts 3 :command-list '())
        )
       ((1)
        (new 'static 'spool-anim
          :name "sage-reminder-1-misty-cannon"
          :index 9
          :parts 5
          :command-list '((86 joint "cameraB") (320 joint "camera"))
          )
        )
       (else
         (new 'static 'spool-anim
           :name "sage-reminder-1-ecorocks"
           :index 11
           :parts 4
           :command-list '((0 want-levels village1 beach)
             (245 display-level beach movie)
             (245 want-force-vis beach #t)
             (246 alive "ecoventrock-3")
             (246 alive "ecoventrock-4")
             (246 alive "ecoventrock-5")
             (246 alive "ecoventrock-6")
             (246 alive "ecoventrock-7")
             (246 alive "harvester-87")
             (246 alive "harvester-88")
             (246 alive "harvester-89")
             (246 alive "harvester-90")
             (246 alive "harvester-91")
             (246 joint "cameraB")
             (365 want-force-vis beach #f)
             (365 display-level beach #f)
             (366 joint "camera")
             )
           )
         )
       )
     )
    (((task-status need-reward-speech))
     (when arg0
       (set-setting! 'music-volume-movie 'abs 0.0 0)
       (apply-settings *setting-control*)
       (close-status! (-> obj tasks) (task-status need-reward-speech))
       (set! (-> obj assistant)
             (ppointer->handle (manipy-spawn (-> obj root-override trans) (-> obj entity) *assistant-sg* #f :to obj))
             )
       (send-event (handle->process (-> obj assistant)) 'anim-mode 'clone-anim)
       (send-event (handle->process (-> obj assistant)) 'blend-shape #t)
       (send-event (handle->process (-> obj assistant)) 'center-joint 3)
       (let ((v1-68 (handle->process (-> obj assistant))))
         (if v1-68
             (set! (-> (the-as assistant v1-68) draw light-index) (the-as uint 1))
             )
         )
       (set! (-> obj draw bounds w) 40960.0)
       )
     (new 'static 'spool-anim
       :name "sage-intro-sequence-d2"
       :index 15
       :parts 20
       :command-list '((0 want-levels village1 beach)
         (0 kill "assistant-11")
         (0 kill "reflector-middle-2")
         (0 kill "eco-11")
         (0 kill "eco-10")
         (0 kill "sharkey-12")
         (0 kill "reflector-end-1")
         (0 kill "water-vol-10")
         (0 kill "water-vol-8")
         (0 kill "water-vol-7")
         (0 kill "fishermans-boat-2")
         (0 kill "revcycleprop-2")
         (0 kill "revcycle-8")
         (113 joint "cameraB")
         (232 joint "camera")
         (289 joint "cameraB")
         (338 joint "camera")
         (405 joint "cameraB")
         (560 joint "camera")
         (660 joint "cameraB")
         (699 joint "camera")
         (837 joint "cameraB")
         (837 shadow self #f)
         (910 joint "camera")
         (945 alive "farmer-3")
         (945 alive "hutlamp-2")
         (950 joint "cameraB")
         (974 display-level beach movie)
         (974 want-force-vis beach #t)
         (1011 alive "bird-lady-4")
         (1015 joint "camera")
         (1018 dead "farmer-3")
         (1018 dead "hutlamp-2")
         (1075 alive "explorer-4")
         (1080 joint "cameraB")
         (1080 want-force-vis beach #f)
         (1080 display-level beach #f)
         (1082 dead "bird-lady-4")
         (1133 joint "camera")
         (1135 dead "explorer-4")
         (1244 display-level beach movie)
         (1244 want-force-vis beach #t)
         (1245 alive "fuel-cell-42")
         (1246 joint "cameraB")
         (1369 joint "camera")
         (1438 alive "fuel-cell-42")
         (1438 want-force-vis beach #f)
         (1438 dead "fuel-cell-42")
         (1438 kill "villagea-water-2")
         (1438 kill "crate-3147")
         (1438 kill "crate-3146")
         (1438 kill "crate-3143")
         (1438 kill "sagesail-6")
         (1438 kill "windmill-sail-4")
         (1438 kill "ropebridge-4")
         (1438 kill "ropebridge-5")
         (1438 kill "windspinner-8")
         (1438 kill "windspinner-9")
         (1438 joint "cameraB")
         (1439 want-levels village1 training)
         (1439 save)
         (1529 joint "camera")
         (1691 joint "cameraB")
         (1753 joint "camera")
         (1874 joint "cameraB")
         (2057 joint "camera")
         (2176 joint "cameraB")
         (2226 joint "camera")
         (2226 shadow self #t)
         )
       )
     )
    (else
      (if arg0
          (format
            0
            "ERROR: <GMJ>: ~S playing anim for task status ~S~%"
            (-> obj name)
            (task-status->string (current-status (-> obj tasks)))
            )
          )
      (get-art-elem obj)
      )
    )
  )

;; definition for method 45 of type sage
(defmethod dummy-45 sage ((obj sage))
  (cond
    ((and (closed? (-> obj tasks) (game-task beach-ecorocks) (task-status need-reminder))
          (= (get-reminder (-> obj tasks) 0) 0)
          )
     #t
     )
    ((and (closed? (-> obj tasks) (game-task misty-cannon) (task-status need-reminder))
          (= (get-reminder (-> obj tasks) 0) 1)
          )
     #t
     )
    ((and (-> obj reminder-played) (< 81920.0 (vector-vector-distance (-> obj root-override trans) (camera-pos))))
     #t
     )
    (else
      #f
      )
    )
  )

;; definition for method 31 of type sage
(defmethod get-art-elem sage ((obj sage))
  (cond
    ((and (= (current-task (-> obj tasks)) (game-task beach-ecorocks))
          (or (= (current-status (-> obj tasks)) (task-status need-hint))
              (= (current-status (-> obj tasks)) (task-status need-introduction))
              )
          )
     (save-reminder (-> obj tasks) 0 0)
     )
    ((and (= (current-task (-> obj tasks)) (game-task misty-cannon))
          (or (= (current-status (-> obj tasks)) (task-status need-hint))
              (= (current-status (-> obj tasks)) (task-status need-introduction))
              )
          )
     (save-reminder (-> obj tasks) 1 0)
     )
    ((dummy-45 obj)
     (set! (-> obj reminder-played) #f)
     (cond
       ((= (current-task (-> obj tasks)) (game-task none))
        (case (get-reminder (-> obj tasks) 0)
          ((2)
           (save-reminder (-> obj tasks) 3 0)
           )
          (else
            (save-reminder (-> obj tasks) 2 0)
            )
          )
        )
       ((closed? (-> obj tasks) (game-task beach-ecorocks) (task-status need-reminder))
        (save-reminder (-> obj tasks) 1 0)
        )
       ((or (closed? (-> obj tasks) (game-task misty-cannon) (task-status need-reminder))
            (not (closed? (-> obj tasks) (game-task misty-cannon) (task-status need-introduction)))
            )
        (save-reminder (-> obj tasks) 0 0)
        )
       ((zero? (get-reminder (-> obj tasks) 0))
        (save-reminder (-> obj tasks) 1 0)
        )
       (else
         (save-reminder (-> obj tasks) 0 0)
         )
       )
     )
    )
  (case (get-reminder (-> obj tasks) 0)
    ((3)
     (-> obj draw art-group data 7)
     )
    ((2)
     (-> obj draw art-group data 6)
     )
    ((1)
     (-> obj draw art-group data 3)
     )
    (else
      (-> obj draw art-group data 4)
      )
    )
  )

;; definition for method 43 of type sage
(defmethod TODO-RENAME-43 sage ((obj sage))
  (let ((s5-0 (TODO-RENAME-10 (-> obj ambient) (new 'stack-no-clear 'vector) (seconds 30) 122880.0 obj)))
    (when s5-0
      (let ((f0-2 (rand-float-gen)))
        (cond
          ((< (-> s5-0 y) -12288.0)
           #f
           )
          ((< 0.8 f0-2)
           (play-ambient (-> obj ambient) "SAGELP03" #f (-> obj root-override trans))
           )
          ((< 0.6 f0-2)
           (play-ambient (-> obj ambient) "SAGELP04" #f (-> obj root-override trans))
           )
          ((< 0.4 f0-2)
           (play-ambient (-> obj ambient) "SAGELP05" #f (-> obj root-override trans))
           )
          ((< 0.2 f0-2)
           (play-ambient (-> obj ambient) "SAGELP06" #f (-> obj root-override trans))
           )
          (else
            (play-ambient (-> obj ambient) "SAGELP11" #f (-> obj root-override trans))
            )
          )
        )
      )
    )
  )

;; failed to figure out what this is:
(defstate idle (sage)
  :virtual #t
  :trans (behavior ()
    (case (get-task-status (game-task intro))
      (((task-status need-reward-speech))
       (if (process-grab? *target*)
           (send-event self 'play-anim)
           )
       )
      )
    ((-> (method-of-type process-taskable idle) trans))
    (none)
    )
  :code (behavior ()
    (if (!= (ja-group) (get-art-elem self))
        (ja-channel-push! 1 (seconds 0.2))
        )
    (loop
      (ja :group! (get-art-elem self))
      (let* ((f30-0 3.0)
             (v1-9 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-10 (the-as number (logior #x3f800000 v1-9)))
             )
        (countdown (gp-1 (+ (the int (* f30-0 (+ -1.0 (the-as float v1-10)))) 5))
          (TODO-RENAME-43 self)
          (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
          (until (ja-done? 0)
            (if (and (-> self reminder-played)
                     (< 81920.0 (vector-vector-distance (-> self root-override trans) (camera-pos)))
                     )
                (go-virtual idle)
                )
            (suspend)
            (ja :num! (seek!))
            )
          )
        )
      (when (ja-group? sage-idle-ecorocks-breathe-ja)
        (ja-no-eval :group! sage-idle-ecorocks-peer-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))
          )
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate play-anim (sage)
  :virtual #t
  :exit (behavior ()
    (set! (-> self draw bounds w) 10240.0)
    (let ((a0-1 (handle->process (-> self assistant))))
      (if a0-1
          (deactivate a0-1)
          )
      )
    ((-> (method-of-type process-taskable play-anim) exit))
    (case (get-task-status (game-task intro))
      (((task-status need-resolution))
       (remove-setting! 'music-volume-movie)
       (close-specific-task! (game-task intro) (task-status need-resolution))
       (start 'play (get-continue-by-name *game-info* "game-start"))
       )
      )
    (none)
    )
  :trans (behavior ()
    (case (get-task-status (game-task intro))
      (((task-status need-reward-speech))
       (spool-push *art-control* "sage-intro-sequence-d2" 0 self -1.0)
       )
      )
    ((-> (method-of-type process-taskable play-anim) trans))
    (none)
    )
  )

;; definition for method 39 of type sage
(defmethod should-display? sage ((obj sage))
  (not (sages-kidnapped?))
  )

;; definition for method 41 of type sage
;; INFO: Return type mismatch int vs none.
(defmethod initialize-collision sage ((obj sage) (arg0 int) (arg1 vector))
  (let ((s5-0 (new 'process 'collide-shape obj (collide-list-enum hit-by-player))))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
      (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 indestructible))
      (set! (-> s4-0 transform-index) arg0)
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 10240.0)
      (set-root-prim! s5-0 s4-0)
      (let ((s2-0 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
        (set! (-> s2-0 prim-core collide-as) (collide-kind enemy))
        (set! (-> s2-0 collide-with) (collide-kind target))
        (set! (-> s2-0 prim-core action) (collide-action solid))
        (set! (-> s2-0 prim-core offense) (collide-offense indestructible))
        (set! (-> s2-0 transform-index) arg0)
        (set-vector! (-> s2-0 local-sphere) 0.0 -2048.0 0.0 5324.8)
        (append-prim s4-0 s2-0)
        )
      (let ((s2-1 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
        (set! (-> s2-1 prim-core collide-as) (collide-kind enemy))
        (set! (-> s2-1 collide-with) (collide-kind target))
        (set! (-> s2-1 prim-core action) (collide-action solid))
        (set! (-> s2-1 prim-core offense) (collide-offense indestructible))
        (set! (-> s2-1 transform-index) arg0)
        (set-vector! (-> s2-1 local-sphere) 0.0 2048.0 0.0 5324.8)
        (append-prim s4-0 s2-1)
        )
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (backup-collide-with-as s5-0)
    (set! (-> obj root-override) s5-0)
    )
  0
  (none)
  )

;; definition for method 11 of type sage
(defmethod init-from-entity! sage ((obj sage) (arg0 entity-actor))
  (dummy-40 obj arg0 *sage-sg* 3 40 (new 'static 'vector :w 4096.0) 5)
  (set! (-> obj tasks) (get-task-control (game-task misty-cannon)))
  (set! (-> obj reminder-played) #f)
  (set! (-> obj sound-flava) (music-flava sage))
  (set! (-> obj assistant) (the-as handle #f))
  (set! (-> obj draw light-index) (the-as uint 1))
  (dummy-42 obj)
  (none)
  )
