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

;; definition of type jungle-elevator
(deftype jungle-elevator (plat-button)
  ((bottom-height       float  :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 jungle-elevator
(defmethod inspect jungle-elevator ((obj jungle-elevator))
  (let ((t9-0 (method-of-type plat-button inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tbottom-height: ~f~%" (-> obj bottom-height))
  (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
  )

;; definition for method 26 of type jungle-elevator
(defmethod can-activate? jungle-elevator ((obj jungle-elevator))
  (and ((method-of-type plat-button can-activate?) obj) (task-complete? *game-info* (game-task jungle-tower)))
  )

;; failed to figure out what this is:
(defstate plat-button-move-downward (jungle-elevator)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type plat-button plat-button-move-downward) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set! (-> self draw light-index) (the-as uint 255))
    (set! (-> self bottom-height) (-> jungle bottom-height))
    (set! (-> jungle bottom-height) (-> jungleb bottom-height))
    (send-event *target* 'reset-pickup 'eco)
    (none)
    )
  :exit (behavior ()
    (set! (-> jungle bottom-height) (-> self bottom-height))
    (let ((t9-0 (-> (method-of-type plat-button plat-button-move-downward) exit)))
      (if t9-0
          (t9-0)
          )
      )
    (none)
    )
  :trans (behavior ()
    (let ((s5-0 (new 'stack-no-clear 'vector))
          (gp-0 (new 'stack-no-clear 'vector))
          )
      (set! (-> s5-0 quad) (-> self root-override trans quad))
      (let ((t9-1 (-> (the-as (state plat-button) (find-parent-method jungle-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)
        )
      )
    (if (and (>= (-> self path-pos) 0.2) (< (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.2)))
        (load-commands-set! *level* (load-command-get-index *level* 'jungle 0))
        )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate plat-button-move-upward (jungle-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 draw light-index) (the-as uint 255))
    (set! (-> self bottom-height) (-> jungle bottom-height))
    (set! (-> jungle bottom-height) (-> jungleb bottom-height))
    (set! (-> self grab-player?) (process-grab? *target*))
    (none)
    )
  :exit (behavior ()
    (set! (-> jungle bottom-height) (-> self bottom-height))
    (let ((t9-0 (-> (method-of-type plat-button plat-button-move-upward) exit)))
      (if t9-0
          (t9-0)
          )
      )
    (none)
    )
  :trans (behavior ()
    (let ((t9-0 (-> (method-of-type plat-button plat-button-move-upward) trans)))
      (if t9-0
          (t9-0)
          )
      )
    (if (and (< (-> self path-pos) 0.8) (< (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.2)))
        (load-commands-set! *level* (load-command-get-index *level* 'jungle 1))
        )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate plat-button-at-end (jungle-elevator)
  :virtual #t
  :code (behavior ()
    (cond
      ((!= (-> self path-pos) 0.0)
       (set! (-> self draw light-index) (the-as uint 1))
       (let ((a1-1 (res-lump-struct (-> self entity) 'continue-name structure)))
         (when a1-1
           (let ((v1-4 (set-continue! *game-info* (the-as basic a1-1))))
             (load-commands-set! *level* (-> v1-4 load-commands))
             )
           )
         )
       )
      (else
        (set! (-> self draw light-index) (the-as uint 255))
        (load-commands-set! *level* '())
        )
      )
    (let ((t9-4 (-> (method-of-type plat-button plat-button-at-end) code)))
      (if t9-4
          ((the-as (function none :behavior plat-button) t9-4))
          )
      )
    (none)
    )
  )

;; definition for method 30 of type jungle-elevator
(defmethod should-teleport? jungle-elevator ((obj jungle-elevator))
  (let ((f0-0 (-> (camera-pos) y)))
    (case (-> obj path-pos)
      ((0.0)
       (when (< f0-0 (-> obj teleport-if-below-y))
         (set! (-> obj draw light-index) (the-as uint 1))
         (return #t)
         )
       )
      ((1.0)
       (when (< (-> obj teleport-if-above-y) f0-0)
         (set! (-> obj draw light-index) (the-as uint 255))
         (return #t)
         )
       )
      )
    )
  #f
  )

;; definition for method 29 of type jungle-elevator
;; INFO: Return type mismatch symbol vs none.
(defmethod can-target-move? jungle-elevator ((obj jungle-elevator))
  (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))
    )
  (set! (-> obj draw light-index) (the-as uint 255))
  (set! (-> obj bidirectional?) #f)
  (set! (-> obj should-grab-player?) #t)
  (none)
  )
