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

(import "goal_src/jak1/import/wedge-plat-outer-ag.gc")
(import "goal_src/jak1/import/wedge-plat-ag.gc")

;; definition of type wedge-plat-master
(deftype wedge-plat-master (process)
  ((center       vector :inline :offset-assert 112)
   (rotspeed     float          :offset-assert 128)
   (rotate-inner float          :offset-assert 132)
   (rotate-outer float          :offset-assert 136)
   )
  :heap-base #x20
  :method-count-assert 14
  :size-assert         #x8c
  :flag-assert         #xe0020008c
  (:states
    wedge-plat-master-idle
    )
  )

;; definition for method 3 of type wedge-plat-master
(defmethod inspect wedge-plat-master ((obj wedge-plat-master))
  (let ((t9-0 (method-of-type process inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tcenter: #<vector @ #x~X>~%" (-> obj center))
  (format #t "~T~Trotspeed: ~f~%" (-> obj rotspeed))
  (format #t "~T~Trotate-inner: ~f~%" (-> obj rotate-inner))
  (format #t "~T~Trotate-outer: ~f~%" (-> obj rotate-outer))
  obj
  )

;; failed to figure out what this is:
(defstate wedge-plat-master-idle (wedge-plat-master)
  :code (behavior ()
    (loop
      (set! (-> self rotate-inner)
            (the float
                 (sar (shl (the int (+ (-> self rotate-inner) (* (-> self rotspeed) (-> *display* seconds-per-frame)))) 48) 48)
                 )
            )
      (set! (-> self rotate-outer)
            (the float
                 (sar (shl (the int (- (-> self rotate-outer) (* (-> self rotspeed) (-> *display* seconds-per-frame)))) 48) 48)
                 )
            )
      (suspend)
      )
    (none)
    )
  )

;; definition for method 11 of type wedge-plat-master
;; INFO: Return type mismatch object vs none.
;; Used lq/sq
(defmethod init-from-entity! wedge-plat-master ((obj wedge-plat-master) (arg0 entity-actor))
  (set! (-> obj mask) (logior (process-mask platform) (-> obj mask)))
  (set! (-> obj center quad) (-> arg0 extra trans quad))
  (set! (-> obj center y) (+ 819.2 (-> obj center y)))
  (set! (-> obj rotspeed) (res-lump-float arg0 'rotspeed))
  (set! (-> obj rotate-inner) 0.0)
  (set! (-> obj rotate-outer) 0.0)
  (logclear! (-> obj mask) (process-mask actor-pause))
  (go wedge-plat-master-idle)
  (none)
  )

;; definition of type wedge-plat
(deftype wedge-plat (baseplat)
  ((master   wedge-plat-master  :offset-assert 228)
   (distance float              :offset-assert 232)
   (offset   float              :offset-assert 236)
   )
  :heap-base #x80
  :method-count-assert 28
  :size-assert         #xf0
  :flag-assert         #x1c008000f0
  (:methods
    (dummy-27 (_type_) symbol 27)
    )
  (:states
    wedge-plat-idle
    wedge-plat-tip
    )
  )

;; definition for method 3 of type wedge-plat
(defmethod inspect wedge-plat ((obj wedge-plat))
  (let ((t9-0 (method-of-type baseplat inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tmaster: ~A~%" (-> obj master))
  (format #t "~T~Tdistance: ~f~%" (-> obj distance))
  (format #t "~T~Toffset: ~f~%" (-> obj offset))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *wedge-plat-sg* wedge-plat wedge-plat-lod0-jg wedge-plat-idle-ja
              ((wedge-plat-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 6)
              )

;; definition for method 27 of type wedge-plat
(defmethod dummy-27 wedge-plat ((obj wedge-plat))
  (let* ((a0-1 (-> obj master))
         (v1-0 (if a0-1
                   (-> (the-as process-drawable (-> a0-1 ppointer)) brother)
                   )
               )
         )
    (when v1-0
      (let ((s4-0 (&-> v1-0 27))
            (f30-0 (-> obj distance))
            (f28-0 (the float (sar (shl (the int (+ (the-as float (-> v1-0 32)) (-> obj offset))) 48) 48)))
            (s5-0 #f)
            )
        (quaternion-axis-angle!
          (-> obj root-override quat)
          0.0
          1.0
          0.0
          (the float (sar (shl (the int (- 49152.0 f28-0)) 48) 48))
          )
        (set! (-> obj basetrans x) (+ (the-as float (-> s4-0 0)) (* f30-0 (cos f28-0))))
        (set! (-> obj basetrans y) (the-as float (-> s4-0 1)))
        (set! (-> obj basetrans z) (+ (the-as float (-> s4-0 2)) (* f30-0 (sin f28-0))))
        (let ((f0-16 (cos f28-0)))
          (if (or (< 0.95 f0-16) (< f0-16 -0.95))
              (set! s5-0 #t)
              )
          )
        s5-0
        )
      )
    )
  )

;; failed to figure out what this is:
(defstate wedge-plat-idle (wedge-plat)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (if (= v1-0 'bonk)
                         (dummy-22 self)
                         )
              )
      )
    )
  :trans (the-as (function none :behavior wedge-plat) plat-trans)
  :code (behavior ()
    (ja :num-func num-func-identity :frame-num (ja-aframe 0.0 0))
    (loop
      (if (dummy-27 self)
          (go wedge-plat-tip)
          )
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior wedge-plat) plat-post)
  )

;; failed to figure out what this is:
(defstate wedge-plat-tip (wedge-plat)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (cond
                       ((= v1-0 'bonk)
                        (dummy-22 self)
                        )
                       ((= v1-0 'touch)
                        (send-event arg0 'no-look-around (seconds 1.5))
                        #f
                        )
                       )
              )
      )
    )
  :trans (the-as (function none :behavior wedge-plat) plat-trans)
  :code (behavior ()
    (ja-no-eval :group! (-> self draw art-group data 3)
                :num! (seek! (ja-aframe 60.0 0))
                :frame-num (ja-aframe 0.0 0)
                )
    (until (ja-done? 0)
      (dummy-27 self)
      (suspend)
      (ja :num! (seek! (ja-aframe 60.0 0)))
      )
    (ja-no-eval :group! (-> self draw art-group data 3)
                :num! (seek! (ja-aframe 100.0 0))
                :frame-num (ja-aframe 60.0 0)
                )
    (until (ja-done? 0)
      (dummy-27 self)
      (suspend)
      (ja :num! (seek! (ja-aframe 100.0 0)))
      )
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (until (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 1))
      (ja :num-func num-func-identity :frame-num (ja-aframe 100.0 0))
      (dummy-27 self)
      (suspend)
      )
    (ja-no-eval :group! (-> self draw art-group data 3)
                :num! (seek! (ja-aframe 153.0 0))
                :frame-num (ja-aframe 100.0 0)
                )
    (until (ja-done? 0)
      (dummy-27 self)
      (suspend)
      (ja :num! (seek! (ja-aframe 153.0 0)))
      )
    (go wedge-plat-idle)
    (none)
    )
  :post (the-as (function none :behavior wedge-plat) plat-post)
  )

;; definition for method 11 of type wedge-plat
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! wedge-plat ((obj wedge-plat) (arg0 entity-actor))
  (set! (-> obj mask) (logior (process-mask platform) (-> obj mask)))
  (let ((s4-0 (new 'process 'collide-shape-moving obj (collide-list-enum hit-by-player))))
    (set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s4-0 reaction) default-collision-reaction)
    (set! (-> s4-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (alloc-riders s4-0 1)
    (let ((s3-0 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid ca-1))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set! (-> s3-0 transform-index) 3)
      (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 24576.0)
      (set-root-prim! s4-0 s3-0)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> obj root-override) s4-0)
    )
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *wedge-plat-sg* '())
  (logior! (-> obj skel status) (janim-status inited))
  (update-transforms! (-> obj root-override))
  (dummy-21 obj)
  (set! (-> obj master) (the-as wedge-plat-master (entity-actor-lookup arg0 'alt-actor 0)))
  (set! (-> obj offset) (res-lump-float arg0 'rotoffset))
  (set! (-> obj distance) (res-lump-float arg0 'distance :default 36864.0))
  (logclear! (-> obj mask) (process-mask actor-pause))
  (go wedge-plat-idle)
  (none)
  )

;; definition of type wedge-plat-outer
(deftype wedge-plat-outer (wedge-plat)
  ()
  :heap-base #x80
  :method-count-assert 28
  :size-assert         #xf0
  :flag-assert         #x1c008000f0
  (:states
    wedge-plat-outer-idle
    wedge-plat-outer-tip
    )
  )

;; definition for method 3 of type wedge-plat-outer
(defmethod inspect wedge-plat-outer ((obj wedge-plat-outer))
  (let ((t9-0 (method-of-type wedge-plat inspect)))
    (t9-0 obj)
    )
  obj
  )

;; failed to figure out what this is:
(defskelgroup *wedge-plat-outer-sg* wedge-plat-outer wedge-plat-outer-lod0-jg wedge-plat-outer-idle-ja
              ((wedge-plat-outer-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 8)
              )

;; definition for method 27 of type wedge-plat-outer
(defmethod dummy-27 wedge-plat-outer ((obj wedge-plat-outer))
  (let* ((a0-1 (-> obj master))
         (v1-0 (if a0-1
                   (-> (the-as process-drawable (-> a0-1 ppointer)) brother)
                   )
               )
         )
    (when v1-0
      (let ((s4-0 (&-> v1-0 27))
            (f30-0 (-> obj distance))
            (f28-0 (the float (sar (shl (the int (+ (the-as float (-> v1-0 33)) (-> obj offset))) 48) 48)))
            (s5-0 #f)
            )
        (quaternion-axis-angle!
          (-> obj root-override quat)
          0.0
          1.0
          0.0
          (the float (sar (shl (the int (- 49152.0 f28-0)) 48) 48))
          )
        (set! (-> obj basetrans x) (+ (the-as float (-> s4-0 0)) (* f30-0 (cos f28-0))))
        (set! (-> obj basetrans y) (the-as float (-> s4-0 1)))
        (set! (-> obj basetrans z) (+ (the-as float (-> s4-0 2)) (* f30-0 (sin f28-0))))
        (let ((f0-16 (sin f28-0)))
          (if (or (< 0.95 f0-16) (< f0-16 -0.95))
              (set! s5-0 #t)
              )
          )
        s5-0
        )
      )
    )
  )

;; failed to figure out what this is:
(defstate wedge-plat-outer-idle (wedge-plat-outer)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (if (= v1-0 'bonk)
                         (dummy-22 self)
                         )
              )
      )
    )
  :trans (the-as (function none :behavior wedge-plat-outer) plat-trans)
  :code (behavior ()
    (loop
      (ja :num-func num-func-identity :frame-num (ja-aframe 0.0 0))
      (if (dummy-27 self)
          (go wedge-plat-outer-tip)
          )
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior wedge-plat-outer) plat-post)
  )

;; failed to figure out what this is:
(defstate wedge-plat-outer-tip (wedge-plat-outer)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (cond
                       ((= v1-0 'bonk)
                        (dummy-22 self)
                        )
                       ((= v1-0 'touch)
                        (send-event arg0 'no-look-around (seconds 1.5))
                        )
                       )
              )
      )
    )
  :trans (the-as (function none :behavior wedge-plat-outer) plat-trans)
  :code (behavior ()
    (ja-no-eval :group! (-> self draw art-group data 3)
                :num! (seek! (ja-aframe 60.0 0))
                :frame-num (ja-aframe 0.0 0)
                )
    (until (ja-done? 0)
      (dummy-27 self)
      (suspend)
      (ja :num! (seek! (ja-aframe 60.0 0)))
      )
    (ja-no-eval :group! (-> self draw art-group data 3)
                :num! (seek! (ja-aframe 100.0 0))
                :frame-num (ja-aframe 60.0 0)
                )
    (until (ja-done? 0)
      (dummy-27 self)
      (suspend)
      (ja :num! (seek! (ja-aframe 100.0 0)))
      )
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (until (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 1))
      (ja :num-func num-func-identity :frame-num (ja-aframe 100.0 0))
      (dummy-27 self)
      (suspend)
      )
    (ja-no-eval :group! (-> self draw art-group data 3)
                :num! (seek! (ja-aframe 153.0 0))
                :frame-num (ja-aframe 100.0 0)
                )
    (until (ja-done? 0)
      (dummy-27 self)
      (suspend)
      (ja :num! (seek! (ja-aframe 153.0 0)))
      )
    (go wedge-plat-outer-idle)
    (none)
    )
  :post (the-as (function none :behavior wedge-plat-outer) plat-post)
  )

;; definition for method 11 of type wedge-plat-outer
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! wedge-plat-outer ((obj wedge-plat-outer) (arg0 entity-actor))
  (set! (-> obj mask) (logior (process-mask platform) (-> obj mask)))
  (let ((s4-0 (new 'process 'collide-shape-moving obj (collide-list-enum hit-by-player))))
    (set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s4-0 reaction) default-collision-reaction)
    (set! (-> s4-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (alloc-riders s4-0 1)
    (let ((s3-0 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid ca-1 ca-4))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set! (-> s3-0 transform-index) 3)
      (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 32768.0)
      (set-root-prim! s4-0 s3-0)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> obj root-override) s4-0)
    )
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *wedge-plat-sg* '())
  (logior! (-> obj skel status) (janim-status inited))
  (update-transforms! (-> obj root-override))
  (dummy-21 obj)
  (set! (-> obj master) (the-as wedge-plat-master (entity-actor-lookup arg0 'alt-actor 0)))
  (set! (-> obj offset) (res-lump-float arg0 'rotoffset))
  (set! (-> obj distance) (res-lump-float arg0 'distance :default 69632.0))
  (logclear! (-> obj mask) (process-mask actor-pause))
  (go wedge-plat-outer-idle)
  (none)
  )
