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

;; name: target-launch.gc
;; name in dgo: target-launch
;; dgos: GAME

;; DECOMP BEGINS

(defstate target-launch-dir (target)
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (cond
      ((and (= message 'query) (= (-> block param 0) 'mode))
       'target-launch-dir
       )
      ((= message 'launch-dir)
       #f
       )
      (else
        (target-standard-event-handler proc argc message block)
        )
      )
    )
  :enter (behavior ()
    (set-time! (-> self state-time))
    (set! (-> self control did-move-to-pole-or-max-jump-height) 0.0)
    (sound-play "jak-launch")
    (set! (-> self control unknown-vector37 y)
          (- (-> self control unknown-vector37 y) (* 0.5 (the-as float (-> self control unknown-word04))))
          )
    (set! (-> self control unknown-quat39 quad) (-> self control trans quad))
    )
  :exit (behavior ()
    (target-state-hook-exit)
    )
  :trans (behavior ()
    (cond
      ((not (time-elapsed? (-> self state-time) (-> self control sliding-start-time)))
       (let ((s5-0 (new 'stack-no-clear 'vector)))
         (vector-copy! s5-0 (-> self control unknown-vector37))
         (let ((gp-0 (new 'stack-no-clear 'quaternion)))
           (set! (-> gp-0 quad) (-> self control unknown-vector37 quad))
           (set! (-> gp-0 y) 0.0)
           (vector-normalize! (-> gp-0 vec) 1.0)
           (let ((f30-0 (vector-normalize-ret-len! s5-0 1.0)))
             0.0
             (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self control quat))
             (vector-z-quaternion! (new 'stack-no-clear 'vector) (-> self control dir-targ))
             (quaternion-rotate-y-to-vector! (-> self control dir-targ) (-> self control dir-targ) gp-0 18204.445)
             (set-quaternion! (-> self control) (-> self control dir-targ))
             (let* ((f0-4
                      (/ (the float (- (current-time) (-> self state-time))) (the float (-> self control sliding-start-time)))
                      )
                    (f0-5 (- 1.0 f0-4))
                    )
               (let ((f1-5 (* 1.4 f0-5 (/ f30-0 (* 0.0033333334 (the float (-> self control sliding-start-time)))))))
                 (* (/ f1-5 300) (the float (- (current-time) (-> self clock old-frame-counter))))
                 )
               (let ((f0-6 (- 1.0 f0-5)))
                 (vector+float*!
                   (-> self control trans)
                   (-> self control unknown-quat39 vec)
                   (-> self control unknown-vector37)
                   f0-6
                   )
                 (+! (-> self control trans y) (* (/ f0-6 2) f0-6 (the-as float (-> self control unknown-word04))))
                 (set! (-> self control transv quad) (the-as uint128 0))
                 (vector-copy! (-> self control transv) (-> self control unknown-vector37))
                 (+! (-> self control transv y) (* f0-6 (the-as float (-> self control unknown-word04))))
                 )
               )
             )
           )
         )
       (+! (-> self control did-move-to-pole-or-max-jump-height)
           (* (the float (-> self control sliding-start-time)) (seconds-per-frame))
           )
       )
      (else
        (let ((v1-53 (logclear (-> self control status) (collide-status on-surface)))
              (a0-19 (-> self control))
              )
          (set! (-> a0-19 status) v1-53)
          (go target-falling a0-19)
          )
        )
      )
    )
  :code (behavior ()
    (send-event self 'end-mode 'gun)
    (ja-channel-push! 1 (seconds 0.15))
    (set-forward-vel 0.0)
    (cond
      ((and (focus-test? self dark) (nonzero? (-> self darkjak)))
       (ja-no-eval :group! (-> self draw art-group data 474) :num! (seek! (ja-aframe 15.0 0) 3.0) :frame-num 0.0)
       (until (ja-done? 0)
         (suspend)
         (ja :num! (seek! (ja-aframe 15.0 0) 3.0))
         )
       )
      ((= (-> self ext-anim) (target-anim default))
       (ja-no-eval :group! jakb-duck-stance-ja :num! (seek! (ja-aframe 15.0 0) 3.0) :frame-num 0.0)
       (until (ja-done? 0)
         (suspend)
         (ja :num! (seek! (ja-aframe 15.0 0) 3.0))
         )
       )
      )
    (ja-channel-push! 1 (seconds 0.2))
    (if (and (focus-test? self dark) (nonzero? (-> self darkjak)))
        (ja :group! (-> self draw art-group data 444) :num! min)
        (ja :group! jakb-jump-ja :num! min)
        )
    (until #f
      (ja-no-eval :group! jakb-launch-jump-loop-ja :num! (seek! max 0.5) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek! max 0.5))
        )
      )
    #f
    (until (time-elapsed? (-> self state-time) (-> self control sliding-start-time))
      (ja :num! (identity
                 (* 20.0
                    (/ (the float (- (current-time) (-> self state-time))) (the float (-> self control sliding-start-time)))
                    )
                 )
          )
      (suspend)
      )
    (until #f
      (suspend)
      )
    #f
    )
  :post (behavior ()
    (target-no-move-post)
    (when (time-elapsed? (-> self state-time) (seconds 0.1))
      (let ((a2-0 (new 'stack-no-clear 'collide-query)))
        (let ((v1-3 (-> self control)))
          (set! (-> a2-0 collide-with) (-> v1-3 backup-collide-with))
          (set! (-> a2-0 ignore-process0) self)
          (set! (-> a2-0 ignore-process1) #f)
          (set! (-> a2-0 ignore-pat) (-> v1-3 pat-ignore-mask))
          )
        (set! (-> a2-0 action-mask) (collide-action solid))
        (fill-cache-for-shape (-> self control) (+ 4096.0 (vector-length (-> self control transv))) a2-0)
        )
      (target-method-28 *target* *collide-cache* *collide-edge-spec*)
      )
    )
  )
