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

(import "goal_src/jak1/import/sculptor-muse-ag.gc")
(import "goal_src/jak1/import/sculptor-ag.gc")

;; definition of type sculptor
(deftype sculptor (process-taskable)
  ((muse handle  :offset-assert 384)
   )
  :heap-base #x120
  :method-count-assert 53
  :size-assert         #x188
  :flag-assert         #x3501200188
  )

;; definition for method 3 of type sculptor
(defmethod inspect sculptor ((obj sculptor))
  (let ((t9-0 (method-of-type process-taskable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tmuse: ~D~%" (-> obj muse))
  obj
  )

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

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

;; definition for method 52 of type sculptor
;; INFO: Return type mismatch int vs none.
(defmethod dummy-52 sculptor ((obj sculptor))
  (let ((v1-1 (-> obj draw shadow-ctrl)))
    (when v1-1
      (let ((f0-0 (-> obj root-override trans y)))
        (let ((a0-2 v1-1))
          (set! (-> a0-2 settings bot-plane w) (- (+ -2048.0 f0-0)))
          )
        0
        (set! (-> v1-1 settings top-plane w) (- (+ 2048.0 f0-0)))
        )
      0
      )
    )
  (none)
  )

;; definition for method 48 of type sculptor
(defmethod draw-npc-shadow sculptor ((obj sculptor))
  (-> obj draw shadow-ctrl)
  (cond
    ((and (-> obj draw shadow)
          (zero? (-> obj draw cur-lod))
          (logtest? (-> obj draw status) (draw-status was-drawn))
          )
     (let ((v1-9 (-> obj draw shadow-ctrl)))
       (logclear! (-> v1-9 settings flags) (shadow-flags disable-draw))
       )
     0
     (update-direction-from-time-of-day (-> obj draw shadow-ctrl))
     )
    (else
      (let ((v1-14 (-> obj draw shadow-ctrl)))
        (logior! (-> v1-14 settings flags) (shadow-flags disable-draw))
        )
      0
      )
    )
  (none)
  )

;; definition for function muse-to-idle
(defbehavior muse-to-idle sculptor ((arg0 muse))
  (if (not (handle->process (-> arg0 incomming-attack-id)))
      (set! (-> arg0 incomming-attack-id)
            (ppointer->handle (manipy-spawn (-> arg0 collide-info trans) (-> arg0 entity) *sculptor-muse-sg* #f :to arg0))
            )
      )
  (let ((v1-11 (handle->process (-> arg0 incomming-attack-id))))
    (if v1-11
        (set! (-> (the-as muse v1-11) draw light-index) (the-as uint 3))
        )
    )
  (send-event (handle->process (-> arg0 incomming-attack-id)) 'anim-mode 'loop)
  (send-event (handle->process (-> arg0 incomming-attack-id)) 'art-joint-anim "idle" 0)
  (send-event (handle->process (-> arg0 incomming-attack-id)) 'draw #t)
  (send-event (handle->process (-> arg0 incomming-attack-id)) 'origin-joint-index 26)
  )

;; failed to figure out what this is:
(defstate give-cell (sculptor)
  :virtual #t
  :enter (behavior ()
    (muse-to-idle (the-as muse self))
    (none)
    )
  )

;; definition for method 32 of type sculptor
(defmethod play-anim! sculptor ((obj sculptor) (arg0 symbol))
  (case (current-status (-> obj tasks))
    (((task-status need-hint) (task-status need-introduction))
     (if arg0
         (close-status! (-> obj tasks) (task-status need-introduction))
         )
     (new 'static 'spool-anim
       :name "sculptor-introduction"
       :index 16
       :parts 14
       :command-list '((0 display-level beach special)
         (0 kill "med-res-level-2")
         (0 kill "med-res-level-4")
         (0 kill "med-res-level-6")
         (0 kill "med-res-level-7")
         (0 kill "med-res-level-8")
         (0 kill "med-res-level-11")
         (0 kill "med-res-level-14")
         (0 kill "med-res-level-22")
         (0 kill "med-res-level-23")
         (285 joint "cameraB")
         (331 joint "camera")
         (614 joint "cameraB")
         (760 joint "camera")
         (1183 joint "cameraB")
         (1278 joint "camera")
         (1433 joint "cameraB")
         )
       )
     )
    (((task-status need-reminder))
     (set! (-> obj skippable) #t)
     (new 'static 'spool-anim :name "sculptor-reminder-1" :index 17 :parts 2 :command-list '())
     )
    (((task-status need-reward-speech))
     (when arg0
       (set! (-> obj cell-for-task) (current-task (-> obj tasks)))
       (close-current! (-> obj tasks))
       (set! (-> obj muse)
             (ppointer->handle (manipy-spawn (-> obj root-override trans) (-> obj entity) *sculptor-muse-sg* #f :to obj))
             )
       (let ((v1-18 (handle->process (-> obj muse))))
         (if v1-18
             (set! (-> (the-as muse v1-18) draw light-index) (the-as uint 3))
             )
         )
       (send-event (handle->process (-> obj muse)) 'center-joint 4)
       (send-event (handle->process (-> obj muse)) 'anim-mode 'clone-anim)
       )
     (new 'static 'spool-anim
       :name "sculptor-resolution"
       :index 18
       :parts 4
       :command-list '((51 joint "cameraB") (87 joint "camera"))
       )
     )
    (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 4)
      )
    )
  )

;; definition for method 31 of type sculptor
(defmethod get-art-elem sculptor ((obj sculptor))
  (case (current-status (-> obj tasks))
    (((task-status invalid) (task-status need-resolution))
     (-> obj draw art-group data 11)
     )
    (else
      (-> obj draw art-group data 3)
      )
    )
  )

;; definition for method 43 of type sculptor
(defmethod TODO-RENAME-43 sculptor ((obj sculptor))
  (when (TODO-RENAME-10 (-> obj ambient) (new 'stack-no-clear 'vector) (seconds 30) 122880.0 obj)
    (let ((f0-2 (rand-float-gen)))
      (cond
        ((< 0.85714287 f0-2)
         (play-ambient (-> obj ambient) "SCU-LO01" #f (-> obj root-override trans))
         )
        ((< 0.71428573 f0-2)
         (play-ambient (-> obj ambient) "SCU-AM05" #f (-> obj root-override trans))
         )
        ((< 0.5714286 f0-2)
         (play-ambient (-> obj ambient) "SCU-AM06" #f (-> obj root-override trans))
         )
        ((< 0.42857143 f0-2)
         (play-ambient (-> obj ambient) "SCU-AM03" #f (-> obj root-override trans))
         )
        ((< 0.2857143 f0-2)
         (play-ambient (-> obj ambient) "SCU-AM04" #f (-> obj root-override trans))
         )
        ((< 0.14285715 f0-2)
         (play-ambient (-> obj ambient) "SCU-AM01" #f (-> obj root-override trans))
         )
        (else
          (play-ambient (-> obj ambient) "SCU-AM02" #f (-> obj root-override trans))
          )
        )
      )
    )
  )

;; failed to figure out what this is:
(defstate idle (sculptor)
  :virtual #t
  :code (behavior ()
    (when (!= (ja-group) (get-art-elem self))
      (ja-channel-push! 1 (seconds 0.2))
      (ja :group! (get-art-elem self))
      )
    (ja-no-eval :num! (seek!))
    (while (not (ja-done? 0))
      (suspend)
      (ja-eval)
      )
    (case (current-status (-> self tasks))
      (((task-status invalid) (task-status need-resolution))
       (ja-no-eval :group! sculptor-from-looking-ja :num! (seek!) :frame-num 0.0)
       (until (ja-done? 0)
         (suspend)
         (ja :num! (seek!))
         )
       (muse-to-idle (the-as muse self))
       )
      )
    (loop
      (let ((v1-43 (current-status (-> self tasks))))
        (cond
          ((or (= v1-43 (task-status invalid)) (= v1-43 (task-status need-resolution)))
           (ja-no-eval :group! sculptor-to-small-ja :num! (seek!) :frame-num 0.0)
           (until (ja-done? 0)
             (suspend)
             (ja :num! (seek!))
             )
           (let* ((f30-0 4.0)
                  (v1-68 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                  (v1-69 (the-as number (logior #x3f800000 v1-68)))
                  )
             (countdown (gp-1 (+ (the int (* f30-0 (+ -1.0 (the-as float v1-69)))) 4))
               (ja-no-eval :group! sculptor-small-ja :num! (seek!) :frame-num 0.0)
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               )
             )
           (let ((f30-1 (rand-float-gen)))
             (ja-no-eval :group! sculptor-small-to-looking-ja :num! (seek!) :frame-num 0.0)
             (until (ja-done? 0)
               (suspend)
               (ja :num! (seek!))
               )
             (ja-no-eval :group! sculptor-looking-ja :num! (seek!) :frame-num 0.0)
             (until (ja-done? 0)
               (suspend)
               (ja :num! (seek!))
               )
             (ja-no-eval :group! sculptor-from-looking-ja :num! (seek!) :frame-num 0.0)
             (until (ja-done? 0)
               (suspend)
               (ja :num! (seek!))
               )
             (when (< f30-1 0.5)
               (ja-no-eval :group! sculptor-to-huge-ja :num! (seek!) :frame-num 0.0)
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               (let* ((f30-2 2.0)
                      (v1-190 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                      (v1-191 (the-as number (logior #x3f800000 v1-190)))
                      )
                 (countdown (gp-2 (+ (the int (* f30-2 (+ -1.0 (the-as float v1-191)))) 2))
                   (ja-no-eval :group! sculptor-huge-ja :num! (seek!) :frame-num 0.0)
                   (until (ja-done? 0)
                     (suspend)
                     (ja :num! (seek!))
                     )
                   )
                 )
               (ja-no-eval :group! sculptor-huge-to-looking-ja :num! (seek!) :frame-num 0.0)
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               (ja-no-eval :group! sculptor-looking-ja :num! (seek!) :frame-num 0.0)
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               (ja-no-eval :group! sculptor-from-looking-ja :num! (seek!) :frame-num 0.0)
               (until (ja-done? 0)
                 (suspend)
                 (ja :num! (seek!))
                 )
               )
             )
           )
          ((begin
             (TODO-RENAME-43 self)
             (let* ((f30-3 4.0)
                    (v1-287 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                    (v1-288 (the-as number (logior #x3f800000 v1-287)))
                    )
               (countdown (gp-3 (+ (the int (* f30-3 (+ -1.0 (the-as float v1-288)))) 4))
                 (ja-no-eval :group! sculptor-idle-ja :num! (seek!) :frame-num 0.0)
                 (until (ja-done? 0)
                   (suspend)
                   (ja :num! (seek!))
                   )
                 )
               )
             (< (rand-float-gen) 0.5)
             )
           (ja-no-eval :group! sculptor-sigh-ja :num! (seek!) :frame-num 0.0)
           (until (ja-done? 0)
             (suspend)
             (ja :num! (seek!))
             )
           )
          (else
            (ja-no-eval :group! sculptor-strikestart-ja :num! (seek!) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek!))
              )
            (ja-no-eval :group! sculptor-strikemiddle-ja :num! (seek!) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek!))
              )
            (ja-no-eval :group! sculptor-strikeend-ja :num! (seek!) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek!))
              )
            )
          )
        )
      )
    (none)
    )
  )

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