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

;; DECOMP BEGINS

(deftype assistant-lavatube-start (process-taskable) ())

(defskelgroup *assistant-lavatube-start-sg*
  assistant-lavatube-start
  assistant-lavatube-start-lod0-jg
  assistant-lavatube-start-idle-ja
  ((assistant-lavatube-start-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 0 0 4)
  :shadow assistant-lavatube-start-shadow-mg)

(defmethod play-anim! ((this assistant-lavatube-start) (arg0 symbol))
  (case (current-status (-> this tasks))
    (((task-status need-reward-speech))
     (if arg0 (close-current! (-> this tasks)))
     (new 'static
          'spool-anim
          :name "assistant-lavatube-start-resolution"
          :index 5
          :parts 11
          :command-list
          '((232 joint "cameraB") (491 joint "camera") (866 joint "cameraB") (1061 joint "camera"))))
    (else
     (if arg0
       (format 0
               "ERROR: <GMJ>: ~S playing anim for task status ~S~%"
               (-> this name)
               (task-status->string (current-status (-> this tasks)))))
     (get-art-elem this))))

(defmethod get-art-elem ((this assistant-lavatube-start))
  (-> this draw art-group data 3))

(defstate hidden (assistant-lavatube-start)
  :virtual #t
  :trans
    (behavior ()
      ((-> (method-of-type process-taskable hidden) trans))
      (when (and (cond
                   ((and *target* (>= 61440.0 (vector-vector-distance (-> self root trans) (-> *target* control trans)))) #t)
                   (else (set-time! (-> self state-time)) #f))
                 (and (not (closed? (-> self tasks) (game-task lavatube-start) (task-status need-reward-speech)))
                      (not (movie?))
                      (not (level-hint-displayed?))
                      (not (and *cheat-mode* (cpad-hold? 0 l3)))
                      (not (time-elapsed? (-> self state-time) (seconds 10)))))
        (hide-hud)
        (kill-current-level-hint '() '(sidekick voicebox) 'exit)
        (when (and (seen-text? *game-info* (text-id assistant-lavatube-need-cells))
                   (hud-hidden?)
                   (can-grab-display? self)
                   (not (-> *setting-control* current hint)))
          (let ((gp-0 (new 'stack 'font-context *font-default-matrix* 32 160 0.0 (font-color default) (font-flags shadow kerning))))
            (let ((v1-26 gp-0)) (set! (-> v1-26 width) (the float 448)))
            (let ((v1-27 gp-0)) (set! (-> v1-27 height) (the float 80)))
            (let ((v1-28 gp-0)) (set! (-> v1-28 scale) 0.8))
            (set! (-> gp-0 flags) (font-flags shadow kerning middle large))
            (print-game-text (lookup-text! *common-text* (text-id assistant-lavatube-need-cells-text) #f) gp-0 #f 128 22)))
        (level-hint-spawn (text-id assistant-lavatube-need-cells) "asstva74" (the-as entity #f) *entity-pool* (game-task none)))))

(defstate idle (assistant-lavatube-start)
  :virtual #t
  :code
    (behavior ()
      (loop
        (when (!= (ja-group) (get-art-elem self))
          (ja-channel-push! 1 (seconds 0.05))
          (ja :group! assistant-lavatube-start-idle-ja))
        (let* ((f30-0 2.0)
               (v1-7 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
               (v1-8 (the-as number (logior #x3f800000 v1-7))))
          (countdown (gp-0 (+ (the int (* f30-0 (+ -1.0 (the-as float v1-8)))) 2))
            (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
            (until (ja-done? 0)
              (suspend)
              (ja :num! (seek!)))))
        (ja-channel-push! 1 (seconds 0.05))
        (ja-no-eval :group! assistant-lavatube-start-idle-b-ja :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))))))

(defmethod should-display? ((this assistant-lavatube-start))
  (first-any (-> this tasks) #t)
  (= (current-status (-> this tasks)) (task-status need-reward-speech)))

(defmethod init-from-entity! ((this assistant-lavatube-start) (arg0 entity-actor))
  (process-taskable-method-40 this arg0 *assistant-lavatube-start-sg* 3 29 (new 'static 'vector :w 4096.0) 5)
  (set! (-> this tasks) (get-task-control (game-task lavatube-start)))
  (first-any (-> this tasks) #t)
  (process-taskable-method-42 this)
  (none))
