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

(import "goal_src/jak1/import/sunken-elevator-ag.gc")

;; definition of type sunken-elevator
(deftype sunken-elevator (plat-button)
  ((play-at-top-going-up-camera? symbol  :offset-assert 240)
   (teleport-if-below-y          float   :offset-assert 244)
   (teleport-if-above-y          float   :offset-assert 248)
   )
  :heap-base #x90
  :method-count-assert 33
  :size-assert         #xfc
  :flag-assert         #x21009000fc
  )

;; definition for method 3 of type sunken-elevator
(defmethod inspect sunken-elevator ((obj sunken-elevator))
  (let ((t9-0 (method-of-type plat-button inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tplay-at-top-going-up-camera?: ~A~%" (-> obj play-at-top-going-up-camera?))
  (format #t "~T~Tteleport-if-below-y: ~f~%" (-> obj teleport-if-below-y))
  (format #t "~T~Tteleport-if-above-y: ~f~%" (-> obj teleport-if-above-y))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *sunken-elevator-sg* sunken-elevator sunken-elevator-lod0-jg sunken-elevator-pressed-ja
              ((sunken-elevator-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 -1 0 6.6)
              )

;; definition for method 30 of type sunken-elevator
(defmethod should-teleport? sunken-elevator ((obj sunken-elevator))
  (let ((f0-0 (-> (camera-pos) y)))
    (case (-> obj path-pos)
      ((0.0)
       (if (< f0-0 (-> obj teleport-if-below-y))
           (return #t)
           )
       )
      ((1.0)
       (if (< (-> obj teleport-if-above-y) f0-0)
           (return #t)
           )
       )
      )
    )
  #f
  )

;; failed to figure out what this is:
(defstate plat-button-pressed (sunken-elevator)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type plat-button plat-button-pressed) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (case (-> self path-pos)
      ((0.0)
       (load-state-want-display-level 'sunken 'display)
       (let ((gp-0 (get-process *default-dead-pool* village2cam #x4000)))
         (set! (-> (the-as village2cam (-> (when gp-0
                                             (let ((t9-3 (method-of-type village2cam activate)))
                                               (t9-3 (the-as village2cam gp-0) self 'village2cam (the-as pointer #x70004000))
                                               )
                                             (run-now-in-process
                                               gp-0
                                               pov-camera-init-by-other
                                               (-> self spawn-pos)
                                               *village2cam-sg*
                                               "elevator-at-top-going-down"
                                               0
                                               #f
                                               '()
                                               )
                                             (-> gp-0 ppointer)
                                             )
                                           0
                                           )
                           )
                   seq
                   )
               (the-as uint 0)
               )
         )
       0
       )
      ((1.0)
       (let ((v1-10 (process-spawn
                      village2cam
                      :init pov-camera-init-by-other
                      (-> self spawn-pos)
                      *village2cam-sg*
                      "elevator-at-top-going-down"
                      0
                      #f
                      '()
                      :to self
                      )
                    )
             )
         (set! (-> (the-as village2cam (-> v1-10 0)) seq) (the-as uint 1))
         )
       )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate plat-button-move-upward (sunken-elevator)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type plat-button plat-button-move-upward) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set! (-> self play-at-top-going-up-camera?) #t)
    (none)
    )
  :trans (behavior ()
    (let ((t9-0 (-> (method-of-type plat-button plat-button-move-upward) trans)))
      (if t9-0
          (t9-0)
          )
      )
    (when (and (-> self play-at-top-going-up-camera?) (>= 0.14 (-> self path-pos)))
      (set! *teleport* #t)
      (set! (-> self play-at-top-going-up-camera?) #f)
      (load-state-want-display-level 'sunken 'special)
      (let ((v1-8 (process-spawn
                    village2cam
                    :init pov-camera-init-by-other
                    (-> self spawn-pos)
                    *village2cam-sg*
                    "elevator-at-top-going-down"
                    0
                    #f
                    '()
                    :to self
                    )
                  )
            )
        (set! (-> (the-as village2cam (-> v1-8 0)) seq) (the-as uint 2))
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate plat-button-move-downward (sunken-elevator)
  :virtual #t
  :trans (behavior ()
    (let ((s5-0 (new 'stack-no-clear 'vector))
          (gp-0 (new 'stack-no-clear 'vector))
          )
      (set! *teleport* #t)
      (set! (-> s5-0 quad) (-> self root-override trans quad))
      (let ((t9-1 (-> (the-as (state sunken-elevator) (find-parent-method sunken-elevator 23)) trans)))
        (if t9-1
            (t9-1)
            )
        )
      (vector-! gp-0 (-> self root-override trans) s5-0)
      (when (< (-> self path-pos) 0.9)
        (move-by-vector! (-> *target* control) gp-0)
        (send-event *target* 'reset-height)
        )
      )
    (none)
    )
  )

;; definition for method 29 of type sunken-elevator
;; INFO: Return type mismatch float vs none.
(defmethod can-target-move? sunken-elevator ((obj sunken-elevator))
  (set! (-> obj play-at-top-going-up-camera?) #f)
  (let ((s5-0 (new 'stack-no-clear 'vector)))
    (eval-path-curve! (-> obj path) s5-0 0.4 'interp)
    (set! (-> obj teleport-if-above-y) (-> s5-0 y))
    (eval-path-curve! (-> obj path) s5-0 0.6 'interp)
    (set! (-> obj teleport-if-below-y) (-> s5-0 y))
    )
  (none)
  )

;; definition for method 27 of type sunken-elevator
;; INFO: Return type mismatch symbol vs none.
(defmethod TODO-RENAME-27 sunken-elevator ((obj sunken-elevator))
  (ja-channel-set! 1)
  (cond
    ((can-activate? obj)
     (let ((s5-0 (-> obj skel root-channel 0)))
       (joint-control-channel-group-eval!
         s5-0
         (the-as art-joint-anim (-> obj draw art-group data 2))
         num-func-identity
         )
       (set! (-> s5-0 frame-num) 0.0)
       )
     )
    (else
      (let ((s5-1 (-> obj skel root-channel 0)))
        (joint-control-channel-group-eval!
          s5-1
          (the-as art-joint-anim (-> obj draw art-group data 2))
          num-func-identity
          )
        (set! (-> s5-1 frame-num)
              (the float (+ (-> (the-as art-joint-anim (-> obj draw art-group data 2)) data 0 length) -1))
              )
        )
      )
    )
  (ja-post)
  (update-transforms! (-> obj root-override))
  (none)
  )

;; definition for method 31 of type sunken-elevator
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-31 sunken-elevator ((obj sunken-elevator))
  (initialize-skeleton obj *sunken-elevator-sg* '())
  0
  (none)
  )
