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

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

;; definition of type sage-villagec
(deftype sage-villagec (process-taskable)
  ((evilbro   handle        :offset-assert 384)
   (evilsis   handle        :offset-assert 392)
   (assistant entity-actor  :offset-assert 400)
   )
  :heap-base #x130
  :method-count-assert 53
  :size-assert         #x194
  :flag-assert         #x3501300194
  )

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

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

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

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

;; definition for method 32 of type sage-villagec
(defmethod play-anim! sage-villagec ((obj sage-villagec) (arg0 symbol))
  (set! (-> obj talk-message) (game-text-id press-to-talk-to-sage))
  (case (current-status (-> obj tasks))
    (((task-status unknown) (task-status need-hint) (task-status need-introduction))
     (if (not arg0)
         (set! (-> obj will-talk) #t)
         )
     (case (current-task (-> obj tasks))
       (((game-task village3-button))
        (when arg0
          (close-status! (-> obj tasks) (task-status need-introduction))
          (send-event (-> obj assistant extra process) 'clone (process->handle obj))
          (set! (-> obj evilbro)
                (ppointer->handle
                  (manipy-spawn (-> obj root-override trans) (-> obj entity) *evilbro-village3-sg* #f :to obj)
                  )
                )
          (send-event (handle->process (-> obj evilbro)) 'anim-mode 'clone-anim)
          (send-event (handle->process (-> obj evilbro)) 'blend-shape #t)
          (send-event (handle->process (-> obj evilbro)) 'center-joint 3)
          (set! (-> obj evilsis)
                (ppointer->handle
                  (manipy-spawn (-> obj root-override trans) (-> obj entity) *evilsis-village3-sg* #f :to obj)
                  )
                )
          (send-event (handle->process (-> obj evilsis)) 'anim-mode 'clone-anim)
          (send-event (handle->process (-> obj evilsis)) 'blend-shape #t)
          (send-event (handle->process (-> obj evilsis)) 'center-joint 3)
          (set! (-> obj draw bounds w) 40960.0)
          )
        (new 'static 'spool-anim
          :name "sage-village3-introduction"
          :index 8
          :parts 58
          :command-list '((206 joint "cameraB")
            (268 joint "camera")
            (321 joint "cameraB")
            (415 joint "camera")
            (502 joint "cameraB")
            (655 joint "camera")
            (864 joint "cameraB")
            (958 joint "camera")
            (1178 joint "cameraB")
            (1295 joint "camera")
            (1377 joint "cameraB")
            (1683 joint "camera")
            (2066 joint "cameraB")
            (2209 joint "camera")
            (2389 joint "cameraB")
            (2707 joint "camera")
            (2769 joint "cameraB")
            (2901 joint "camera")
            (3021 joint "cameraB")
            (3158 joint "camera")
            (3301 joint "cameraB")
            (3533 joint "camera")
            (3632 joint "cameraB")
            (3692 joint "camera")
            (3780 joint "cameraB")
            (3818 joint "camera")
            (4188 joint "cameraB")
            (4324 joint "camera")
            (4462 joint "cameraB")
            (4542 joint "camera")
            )
          )
        )
       (((game-task cave-dark-crystals))
        (when arg0
          (let* ((s5-3 (-> obj tasks))
                 (s4-0 (method-of-object s5-3 save-reminder))
                 )
            (s4-0 s5-3 (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-village3-introduction-dark-eco"
          :index 4
          :parts 9
          :command-list '((111 joint "cameraB") (189 joint "camera") (455 joint "cameraB") (638 joint "camera") (753 joint "cameraB"))
          )
        )
       (else
         (if arg0
             (close-specific-task! (game-task snow-ram) (task-status need-introduction))
             )
         (new 'static 'spool-anim
           :name "sage-village3-introduction-rams"
           :index 6
           :parts 6
           :command-list '((155 joint "cameraB") (370 joint "camera"))
           )
         )
       )
     )
    (((task-status need-reminder-a) (task-status need-reminder))
     (set! (-> obj skippable) #t)
     (let ((s4-1 (+ (get-reminder (-> obj tasks) 0) 1)))
       (if (< (the-as uint 1) (the-as uint s4-1))
           (set! s4-1 0)
           )
       (countdown (s3-0 2)
         (cond
           ((zero? s4-1)
            (if (!= (get-task-status (game-task cave-dark-crystals)) (task-status need-reminder))
                (set! s4-1 1)
                )
            )
           (else
             (if (not (or (= (get-task-status (game-task snow-ram)) (task-status need-reminder))
                          (= (get-task-status (game-task snow-ram)) (task-status need-reminder-a))
                          )
                      )
                 (set! s4-1 0)
                 )
             )
           )
         )
       (if arg0
           (save-reminder (-> obj tasks) s4-1 0)
           )
       (if (zero? s4-1)
           (new 'static 'spool-anim :name "sage-village3-reminder-1-dark-eco" :index 5 :parts 2 :command-list '())
           (new 'static 'spool-anim :name "sage-village3-reminder-1-rams" :index 7 :parts 3 :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)))
            )
          )
      (get-art-elem obj)
      )
    )
  )

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

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

;; definition for method 43 of type sage-villagec
(defmethod TODO-RENAME-43 sage-villagec ((obj sage-villagec))
  (when (TODO-RENAME-10 (-> obj ambient) (new 'stack-no-clear 'vector) (seconds 30) 122880.0 obj)
    (let ((f0-2 (rand-float-gen)))
      (cond
        ((< 0.875 f0-2)
         (play-ambient (-> obj ambient) "SAGELP31" #f (-> obj root-override trans))
         )
        ((< 0.75 f0-2)
         (if (not (closed? (-> obj tasks) (game-task cave-dark-crystals) (task-status need-reminder)))
             (play-ambient (-> obj ambient) "SAGELP32" #f (-> obj root-override trans))
             )
         )
        ((< 0.625 f0-2)
         (if (nonzero? (get-task-status (game-task citadel-sage-green)))
             (play-ambient (-> obj ambient) "SAGELP33" #f (-> obj root-override trans))
             )
         )
        ((< 0.5 f0-2)
         (play-ambient (-> obj ambient) "SAGELP34" #f (-> obj root-override trans))
         )
        ((< 0.375 f0-2)
         (play-ambient (-> obj ambient) "SAGELP35" #f (-> obj root-override trans))
         )
        ((< 0.25 f0-2)
         (play-ambient (-> obj ambient) "SAGELP36" #f (-> obj root-override trans))
         )
        ((< 0.125 f0-2)
         (if (nonzero? (get-task-status (game-task citadel-sage-green)))
             (play-ambient (-> obj ambient) "SAGELP37" #f (-> obj root-override trans))
             )
         )
        ((!= (get-task-status (game-task citadel-sage-green)) (task-status need-resolution))
         (play-ambient (-> obj ambient) "SAGELP38" #f (-> obj root-override trans))
         )
        )
      )
    )
  )

;; failed to figure out what this is:
(defstate idle (sage-villagec)
  :virtual #t
  :trans (behavior ()
    (case (get-task-status (game-task village3-button))
      (((task-status need-introduction))
       (send-event self 'play-anim)
       )
      )
    ((-> (method-of-type process-taskable idle) trans))
    (none)
    )
  )

;; failed to figure out what this is:
(defstate play-anim (sage-villagec)
  :virtual #t
  :exit (behavior ()
    (set! (-> self draw bounds w) 10240.0)
    (send-event (-> self assistant extra process) 'end-mode)
    (let ((a0-2 (handle->process (-> self evilbro))))
      (if a0-2
          (deactivate a0-2)
          )
      )
    (let ((a0-6 (handle->process (-> self evilsis))))
      (if a0-6
          (deactivate a0-6)
          )
      )
    ((-> (method-of-type process-taskable play-anim) exit))
    (none)
    )
  )

;; definition for method 39 of type sage-villagec
(defmethod should-display? sage-villagec ((obj sage-villagec))
  (cond
    ((not (closed? (-> obj tasks) (game-task village3-button) (task-status need-hint)))
     (dummy-33 obj)
     #f
     )
    ((sages-kidnapped?)
     (dummy-33 obj)
     #f
     )
    (else
      #t
      )
    )
  )

;; definition for method 48 of type sage-villagec
(defmethod draw-npc-shadow sage-villagec ((obj sage-villagec))
  (let ((v1-1 (-> obj draw shadow-ctrl)))
    (cond
      ((and (-> obj draw shadow)
            (zero? (-> obj draw cur-lod))
            (logtest? (-> obj draw status) (draw-status was-drawn))
            )
       (logclear! (-> v1-1 settings flags) (shadow-flags shdf03))
       (logclear! (-> v1-1 settings flags) (shadow-flags shdf02))
       (set! (-> v1-1 settings bot-plane w) 20480.0)
       (let ((a0-8 v1-1))
         (logclear! (-> a0-8 settings flags) (shadow-flags disable-draw))
         )
       0
       (update-direction-from-time-of-day v1-1)
       )
      (else
        (logior! (-> v1-1 settings flags) (shadow-flags disable-draw))
        0
        )
      )
    )
  (none)
  )

;; definition for method 11 of type sage-villagec
(defmethod init-from-entity! sage-villagec ((obj sage-villagec) (arg0 entity-actor))
  (dummy-40 obj arg0 *sage-village3-sg* 3 40 (new 'static 'vector :w 8192.0) 5)
  (set! (-> obj tasks) (get-task-control (game-task cave-dark-crystals)))
  (set! (-> obj assistant) (entity-actor-lookup arg0 'alt-actor 0))
  (set! (-> obj evilbro) (the-as handle #f))
  (set! (-> obj evilsis) (the-as handle #f))
  (set! (-> obj sound-flava) (music-flava sage))
  (dummy-42 obj)
  (none)
  )
