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

;; name: jump-pad.gc
;; name in dgo: jump-pad
;; dgos: SEA, FRSTA

;; DECOMP BEGINS

(deftype jump-pad (bouncer)
  ((fan-quat           quaternion  :inline)
   (rot-vel            float)
   (fan-loop-sound-id  sound-id)
   (fan-loop-sound     sound-spec)
   (jump-sound         sound-spec)
   )
  (:methods
    (get-skel (_type_) art-group)
    (get-fan-joint-idx (_type_) int)
    (init-sounds (_type_) none)
    )
  )


(defstate idle (jump-pad)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trigger)
       (go-virtual fire)
       )
      (('attack)
       (let ((v1-3 (the-as object (-> block param 1)))
             (a0-3 (-> block param 0))
             (a2-1 0)
             )
         0.0
         (let ((f30-0 (-> self spring-height)))
           (cond
             ((= (-> (the-as attack-info v1-3) mode) 'flop)
              (set! a2-1 1)
              )
             ((= (-> (the-as attack-info v1-3) mode) 'board)
              (set! a2-1 9)
              )
             )
           (when (and (nonzero? a2-1) (and ((method-of-type touching-shapes-entry prims-touching?)
                                            (the-as touching-shapes-entry a0-3)
                                            (-> self root)
                                            (the-as uint a2-1)
                                            )
                                           (send-event proc 'jump f30-0 f30-0 (-> self mods))
                                           )
                      )
             (sound-play "trampoline")
             (go-virtual fire)
             #f
             )
           )
         )
       )
      (else
        ((-> (method-of-type bouncer idle) event) proc argc message block)
        )
      )
    )
  :trans (behavior ()
    (seek! (-> self rot-vel) 10922.667 (* 21845.334 (seconds-per-frame)))
    )
  :code (behavior ()
    (ja :group! (get-art-by-name (-> self draw art-group) "idle" art-joint-anim) :num! min)
    (transform-post)
    (sleep-code)
    )
  :post (behavior ()
    (when (-> self fan-loop-sound)
      (set! (-> self fan-loop-sound pitch-mod)
            (the int (* 1524.0 (lerp-scale -0.9 0.6 (-> self rot-vel) 10922.667 87381.336)))
            )
      (sound-play-by-spec (-> self fan-loop-sound) (-> self fan-loop-sound-id) (-> self root trans))
      )
    (ja-post)
    )
  )

(defstate fire (jump-pad)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    )
  :trans (behavior ()
    (seek! (-> self rot-vel) 87381.336 (* 87381.336 (seconds-per-frame)))
    )
  :code (behavior ()
    (cpad-set-buzz! (-> *cpad-list* cpads 0) 1 178 (seconds 0.1))
    (if (-> self jump-sound)
        (sound-play-by-spec (-> self jump-sound) (new-sound-id) (the-as vector #t))
        )
    (until (time-elapsed? (-> self state-time) (seconds 2))
      (suspend)
      )
    (go-virtual idle)
    )
  :post (behavior ()
    (when (-> self fan-loop-sound)
      (set! (-> self fan-loop-sound pitch-mod)
            (the int (* 1524.0 (lerp-scale -0.9 0.6 (-> self rot-vel) 10922.667 87381.336)))
            )
      (sound-play-by-spec (-> self fan-loop-sound) (-> self fan-loop-sound-id) (-> self root trans))
      )
    (let ((t9-2 (-> (method-of-type bouncer fire) post)))
      (if t9-2
          ((the-as (function none) t9-2))
          )
      )
    )
  )

(defun jump-pad-joint-fan ((arg0 cspace) (arg1 quaternion))
  (let ((gp-0 (-> arg0 param1)))
    (quaternion-rotate-local-y!
      (-> (the-as jump-pad gp-0) fan-quat)
      (-> (the-as jump-pad gp-0) fan-quat)
      (* (-> (the-as jump-pad gp-0) rot-vel) (seconds-per-frame))
      )
    (quaternion-copy! (&+ arg1 16) (-> (the-as jump-pad gp-0) fan-quat))
    )
  (cspace<-parented-transformq-joint! arg0 (the-as transformq arg1))
  0
  (none)
  )

(defmethod init-skel! ((this jump-pad))
  (initialize-skeleton this (the-as skeleton-group (get-skel this)) (the-as pair 0))
  (quaternion-copy! (-> this fan-quat) (-> this root quat))
  (let ((a0-6 (-> this node-list data (get-fan-joint-idx this))))
    (set! (-> a0-6 param0) (the-as (function cspace transformq none) jump-pad-joint-fan))
    (set! (-> a0-6 param1) this)
    (set! (-> a0-6 param2) (the-as basic 0))
    )
  0
  (none)
  )

(defmethod init-from-entity! ((this jump-pad) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (set! (-> this fan-loop-sound) #f)
  (set! (-> this jump-sound) #f)
  (init-sounds this)
  (if (-> this fan-loop-sound)
      (set! (-> this fan-loop-sound-id) (new-sound-id))
      )
  (call-parent-method this arg0)
  )
