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

;; definition for method 11 of type rigid-body
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod clear-force-torque! rigid-body ((obj rigid-body))
  (set! (-> obj force quad) (-> *null-vector* quad))
  (set! (-> obj torque quad) (-> *null-vector* quad))
  0
  (none)
  )

;; definition for method 12 of type rigid-body
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod clear-momentum! rigid-body ((obj rigid-body))
  (set! (-> obj lin-momentum quad) (-> *null-vector* quad))
  (set! (-> obj ang-momentum quad) (-> *null-vector* quad))
  0
  (none)
  )

;; definition for method 21 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-21 rigid-body ((obj rigid-body))
  (quaternion->matrix (-> obj matrix) (-> obj rotation))
  (TODO-RENAME-18 obj (-> obj matrix vector 3))
  0
  (none)
  )

;; definition for method 22 of type rigid-body
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-22 rigid-body ((obj rigid-body) (arg0 vector) (arg1 quaternion) (arg2 float) (arg3 float))
  (clear-force-torque! obj)
  (clear-momentum! obj)
  (vector+! (-> obj position) arg0 (-> obj cm-offset-joint))
  (quaternion-copy! (-> obj rotation) arg1)
  (quaternion-normalize! (-> obj rotation))
  (set! (-> obj lin-momentum-damping-factor) arg2)
  (set! (-> obj ang-momentum-damping-factor) arg3)
  (TODO-RENAME-21 obj)
  (set! (-> obj lin-velocity quad) (-> *null-vector* quad))
  (set! (-> obj ang-velocity quad) (-> *null-vector* quad))
  (set! (-> obj inv-i-world vector 0 quad) (the-as uint128 0))
  (set! (-> obj inv-i-world vector 1 quad) (the-as uint128 0))
  (set! (-> obj inv-i-world vector 2 quad) (the-as uint128 0))
  (set! (-> obj inv-i-world vector 3 quad) (the-as uint128 0))
  (set! (-> obj max-ang-velocity) 0.0)
  (set! (-> obj max-ang-momentum) 0.0)
  0
  (none)
  )

;; definition for method 9 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-9 rigid-body ((obj rigid-body) (arg0 float) (arg1 float) (arg2 float) (arg3 float))
  (set! (-> obj mass) arg0)
  (let ((f0-1 arg0))
    (set! (-> obj inv-mass) (/ 1.0 f0-1))
    )
  (matrix-identity! (-> obj inertial-tensor))
  (matrix-identity! (-> obj inv-inertial-tensor))
  (let* ((f0-4 arg0)
         (f1-1 12.0)
         (f0-5 (* f0-4 (/ 1.0 f1-1)))
         )
    (let* ((f1-4 arg2)
           (f1-6 (* f1-4 f1-4))
           (f2-1 arg3)
           )
      (set! (-> obj inertial-tensor vector 0 x) (* f0-5 (+ f1-6 (* f2-1 f2-1))))
      )
    (let* ((f1-9 arg1)
           (f1-11 (* f1-9 f1-9))
           (f2-4 arg3)
           )
      (set! (-> obj inertial-tensor vector 1 y) (* f0-5 (+ f1-11 (* f2-4 f2-4))))
      )
    (let* ((f1-14 arg1)
           (f1-16 (* f1-14 f1-14))
           (f2-7 arg2)
           )
      (set! (-> obj inertial-tensor vector 2 z) (* f0-5 (+ f1-16 (* f2-7 f2-7))))
      )
    )
  (let ((f0-7 (-> obj inertial-tensor vector 0 x)))
    (set! (-> obj inv-inertial-tensor vector 0 x) (/ 1.0 f0-7))
    )
  (let ((f0-10 (-> obj inertial-tensor vector 1 y)))
    (set! (-> obj inv-inertial-tensor vector 1 y) (/ 1.0 f0-10))
    )
  (let ((f0-13 (-> obj inertial-tensor vector 2 z)))
    (set! (-> obj inv-inertial-tensor vector 2 z) (/ 1.0 f0-13))
    )
  0
  (none)
  )

;; definition for method 17 of type rigid-body
(defmethod TODO-RENAME-17 rigid-body ((obj rigid-body) (arg0 vector) (arg1 vector))
  (let ((v1-1 (vector-! (new 'stack-no-clear 'vector) arg0 (-> obj position))))
    (vector-cross! arg1 (-> obj ang-velocity) v1-1)
    )
  (vector+! arg1 arg1 (-> obj lin-velocity))
  arg1
  )

;; definition for function matrix-3x3-triple-transpose-product
(defun matrix-3x3-triple-transpose-product ((arg0 matrix) (arg1 matrix) (arg2 matrix))
  (let ((s2-0 (new 'stack-no-clear 'matrix))
        (s3-0 (new 'stack-no-clear 'matrix))
        )
    (matrix-transpose! s2-0 arg1)
    (cond
      (#t
        (matrix*! s3-0 arg1 arg2)
        (matrix*! arg0 s3-0 s2-0)
        )
      (else
        (matrix*! s3-0 s2-0 arg2)
        (matrix*! arg0 s3-0 arg1)
        )
      )
    )
  arg0
  )

;; definition for method 10 of type rigid-body
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod dummy-10 rigid-body ((obj rigid-body) (arg0 float))
  (vector+*! (-> obj lin-momentum) (-> obj lin-momentum) (-> obj force) arg0)
  (vector+*! (-> obj ang-momentum) (-> obj ang-momentum) (-> obj torque) arg0)
  (vector-float*! (-> obj lin-momentum) (-> obj lin-momentum) (-> obj lin-momentum-damping-factor))
  (vector-float*! (-> obj ang-momentum) (-> obj ang-momentum) (-> obj ang-momentum-damping-factor))
  (vector-float*! (-> obj lin-velocity) (-> obj lin-momentum) (-> obj inv-mass))
  (set! (-> obj matrix vector 3 quad) (-> *null-vector* quad))
  (matrix-3x3-triple-transpose-product (-> obj inv-i-world) (-> obj matrix) (-> obj inv-inertial-tensor))
  (vector-rotate*! (-> obj ang-velocity) (-> obj ang-momentum) (-> obj inv-i-world))
  (vector+*! (-> obj position) (-> obj position) (-> obj lin-velocity) arg0)
  (let ((s4-0 (new 'stack-no-clear 'quaternion)))
    (set! (-> (the-as vector (&-> s4-0 x)) quad) (-> obj ang-velocity quad))
    (set! (-> s4-0 w) 0.0)
    (quaternion*! s4-0 s4-0 (-> obj rotation))
    (quaternion-float*! s4-0 s4-0 0.5)
    (+! (-> obj rotation x) (* (-> s4-0 x) arg0))
    (+! (-> obj rotation y) (* (-> s4-0 y) arg0))
    (+! (-> obj rotation z) (* (-> s4-0 z) arg0))
    (+! (-> obj rotation w) (* (-> s4-0 w) arg0))
    )
  (quaternion-normalize! (-> obj rotation))
  (quaternion->matrix (-> obj matrix) (-> obj rotation))
  (TODO-RENAME-18 obj (-> obj matrix vector 3))
  0
  (none)
  )

;; definition for method 13 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-13 rigid-body ((obj rigid-body) (arg0 vector) (arg1 vector))
  (vector+! (-> obj force) (-> obj force) arg1)
  (let* ((v1-2 (vector-! (new 'stack-no-clear 'vector) arg0 (-> obj position)))
         (a1-2 (vector-cross! (new 'stack-no-clear 'vector) v1-2 arg1))
         )
    (vector+! (-> obj torque) (-> obj torque) a1-2)
    )
  0
  (none)
  )

;; definition for method 16 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-16 rigid-body ((obj rigid-body) (arg0 vector) (arg1 vector) (arg2 float))
  (vector+! (-> obj force) (-> obj force) arg1)
  (let* ((a0-3 (vector-! (new 'stack-no-clear 'vector) arg0 (-> obj position)))
         (s4-1 (vector-cross! (new 'stack-no-clear 'vector) a0-3 arg1))
         )
    (let ((f0-0 (vector-length a0-3)))
      (if (< arg2 f0-0)
          (vector-float*! s4-1 s4-1 (/ arg2 f0-0))
          )
      )
    (vector+! (-> obj torque) (-> obj torque) s4-1)
    )
  0
  (none)
  )

;; definition for method 14 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-14 rigid-body ((obj rigid-body) (arg0 vector) (arg1 vector))
  (let ((s5-0 (new 'stack-no-clear 'vector))
        (s4-0 (new 'stack-no-clear 'vector))
        )
    (vector-rotate*! s4-0 arg1 (-> obj matrix))
    (vector-rotate*! s5-0 arg0 (-> obj matrix))
    (vector+! s5-0 s5-0 (-> obj position))
    (TODO-RENAME-13 obj s5-0 s4-0)
    )
  0
  (none)
  )

;; definition for method 15 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-15 rigid-body ((obj rigid-body) (arg0 vector))
  (vector+! (-> obj force) (-> obj force) arg0)
  0
  (none)
  )

;; definition for method 18 of type rigid-body
(defmethod TODO-RENAME-18 rigid-body ((obj rigid-body) (arg0 vector))
  (let ((gp-0 (new 'stack-no-clear 'vector)))
    (vector-rotate*! gp-0 (-> obj cm-offset-joint) (-> obj matrix))
    (vector-! arg0 (-> obj position) gp-0)
    )
  arg0
  )

;; definition for method 19 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod dummy-19 rigid-body ((obj rigid-body))
  (format #t "  force ~M ~M ~M" (-> obj force x) (-> obj force y) (-> obj force z))
  (format #t "  torque ~f ~f ~f~%" (-> obj torque x) (-> obj torque y) (-> obj torque z))
  (format #t "  position ~M ~M ~M" (-> obj position x) (-> obj position y) (-> obj position z))
  (format
    #t
    "  rotation ~f ~f ~f ~f~%"
    (-> obj rotation x)
    (-> obj rotation y)
    (-> obj rotation z)
    (-> obj rotation w)
    )
  (format #t "  lin-mom ~M ~M ~M" (-> obj lin-momentum x) (-> obj lin-momentum y) (-> obj lin-momentum z))
  (format #t "  ang-mom ~f ~f ~f~%" (-> obj ang-momentum x) (-> obj ang-momentum y) (-> obj ang-momentum z))
  (format #t "  lin-vel ~M ~M ~M" (-> obj lin-velocity x) (-> obj lin-velocity y) (-> obj lin-velocity z))
  (format #t "  ang-vel ~f ~f ~f~%" (-> obj ang-velocity x) (-> obj ang-velocity y) (-> obj ang-velocity z))
  0
  (none)
  )

;; definition for method 20 of type rigid-body
;; INFO: Return type mismatch int vs none.
(defmethod dummy-20 rigid-body ((obj rigid-body))
  (format #t "  force ~M ~M ~M" (-> obj force x) (-> obj force y) (-> obj force z))
  (format #t "  torque ~f ~f ~f~%" (-> obj torque x) (-> obj torque y) (-> obj torque z))
  0
  (none)
  )

;; definition of type rigid-body-platform-constants
(deftype rigid-body-platform-constants (structure)
  ((drag-factor           float       :offset-assert   0)
   (buoyancy-factor       float       :offset-assert   4)
   (max-buoyancy-depth    meters      :offset-assert   8)
   (gravity-factor        float       :offset-assert  12)
   (gravity               meters      :offset-assert  16)
   (player-weight         meters      :offset-assert  20)
   (player-bonk-factor    float       :offset-assert  24)
   (player-dive-factor    float       :offset-assert  28)
   (player-force-distance meters      :offset-assert  32)
   (player-force-clamp    meters      :offset-assert  36)
   (player-force-timeout  time-frame  :offset-assert  40)
   (explosion-force       meters      :offset-assert  48)
   (linear-damping        float       :offset-assert  52)
   (angular-damping       float       :offset-assert  56)
   (control-point-count   int32       :offset-assert  60)
   (mass                  float       :offset-assert  64)
   (inertial-tensor-x     meters      :offset-assert  68)
   (inertial-tensor-y     meters      :offset-assert  72)
   (inertial-tensor-z     meters      :offset-assert  76)
   (cm-joint-x            meters      :offset-assert  80)
   (cm-joint-y            meters      :offset-assert  84)
   (cm-joint-z            meters      :offset-assert  88)
   (idle-distance         meters      :offset-assert  92)
   (platform              symbol      :offset-assert  96)
   (sound-name            string      :offset-assert 100)
   )
  :method-count-assert 9
  :size-assert         #x68
  :flag-assert         #x900000068
  )

;; definition for method 3 of type rigid-body-platform-constants
(defmethod inspect rigid-body-platform-constants ((obj rigid-body-platform-constants))
  (format #t "[~8x] ~A~%" obj 'rigid-body-platform-constants)
  (format #t "~Tdrag-factor: ~f~%" (-> obj drag-factor))
  (format #t "~Tbuoyancy-factor: ~f~%" (-> obj buoyancy-factor))
  (format #t "~Tmax-buoyancy-depth: (meters ~m)~%" (-> obj max-buoyancy-depth))
  (format #t "~Tgravity-factor: ~f~%" (-> obj gravity-factor))
  (format #t "~Tgravity: (meters ~m)~%" (-> obj gravity))
  (format #t "~Tplayer-weight: (meters ~m)~%" (-> obj player-weight))
  (format #t "~Tplayer-bonk-factor: ~f~%" (-> obj player-bonk-factor))
  (format #t "~Tplayer-dive-factor: ~f~%" (-> obj player-dive-factor))
  (format #t "~Tplayer-force-distance: (meters ~m)~%" (-> obj player-force-distance))
  (format #t "~Tplayer-force-clamp: (meters ~m)~%" (-> obj player-force-clamp))
  (format #t "~Tplayer-force-timeout: ~D~%" (-> obj player-force-timeout))
  (format #t "~Texplosion-force: (meters ~m)~%" (-> obj explosion-force))
  (format #t "~Tlinear-damping: ~f~%" (-> obj linear-damping))
  (format #t "~Tangular-damping: ~f~%" (-> obj angular-damping))
  (format #t "~Tcontrol-point-count: ~D~%" (-> obj control-point-count))
  (format #t "~Tmass: ~f~%" (-> obj mass))
  (format #t "~Tinertial-tensor-x: (meters ~m)~%" (-> obj inertial-tensor-x))
  (format #t "~Tinertial-tensor-y: (meters ~m)~%" (-> obj inertial-tensor-y))
  (format #t "~Tinertial-tensor-z: (meters ~m)~%" (-> obj inertial-tensor-z))
  (format #t "~Tcm-joint-x: (meters ~m)~%" (-> obj cm-joint-x))
  (format #t "~Tcm-joint-y: (meters ~m)~%" (-> obj cm-joint-y))
  (format #t "~Tcm-joint-z: (meters ~m)~%" (-> obj cm-joint-z))
  (format #t "~Tidle-distance: (meters ~m)~%" (-> obj idle-distance))
  (format #t "~Tplatform: ~A~%" (-> obj platform))
  (format #t "~Tsound-name: ~A~%" (-> obj sound-name))
  obj
  )

;; definition of type rigid-body-control-point-inline-array
(deftype rigid-body-control-point-inline-array (inline-array-class)
  ((data rigid-body-control-point :inline :dynamic :offset  16)
   )
  :method-count-assert 9
  :size-assert         #x10
  :flag-assert         #x900000010
  )

;; definition for method 3 of type rigid-body-control-point-inline-array
(defmethod inspect rigid-body-control-point-inline-array ((obj rigid-body-control-point-inline-array))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tlength: ~D~%" (-> obj length))
  (format #t "~Tallocated-length: ~D~%" (-> obj allocated-length))
  (format #t "~Tdata[0] @ #x~X~%" (-> obj data))
  obj
  )

;; failed to figure out what this is:
(set! (-> rigid-body-control-point-inline-array heap-base) (the-as uint 48))

;; definition of type rigid-body-platform
(deftype rigid-body-platform (process-drawable)
  ((root-overlay          collide-shape-moving                          :offset        112)
   (info                  rigid-body-platform-constants                 :offset-assert 176)
   (rbody                 rigid-body                            :inline :offset-assert 192)
   (control-point-array   rigid-body-control-point-inline-array         :offset-assert 616)
   (player-velocity       vector                                :inline :offset-assert 624)
   (player-velocity-prev  vector                                :inline :offset-assert 640)
   (player-force-position vector                                :inline :offset-assert 656)
   (player-force          vector                                :inline :offset-assert 672)
   (sim-time-remaining    float                                         :offset-assert 688)
   (float-height-offset   float                                         :offset-assert 692)
   (player-attack-id      int32                                         :offset-assert 696)
   (player-bonk-timeout   time-frame                                    :offset-assert 704)
   (water-anim            water-anim                                    :offset-assert 712)
   (player-contact        basic                                         :offset-assert 716)
   (player-impulse        collide-shape-prim-mesh                       :offset-assert 720)
   )
  :heap-base #x270
  :method-count-assert 35
  :size-assert         #x2d4
  :flag-assert         #x23027002d4
  (:methods
    (rigid-body-platform-idle () _type_ :state 20)
    (rigid-body-platform-float () _type_ :state 21)
    (TODO-RENAME-22 (_type_ vector float) float 22)
    (TODO-RENAME-23 (_type_ float) none 23)
    (TODO-RENAME-24 (_type_ rigid-body-control-point float) none 24)
    (TODO-RENAME-25 (_type_) none 25)
    (TODO-RENAME-26 (_type_) none 26)
    (TODO-RENAME-27 (_type_ vector) none 27)
    (TODO-RENAME-28 (_type_) none 28)
    (TODO-RENAME-29 (_type_ rigid-body-platform-constants) none 29)
    (TODO-RENAME-30 (_type_) none 30)
    (TODO-RENAME-31 (_type_) none 31)
    (dummy-32 (_type_) sound-id 32)
    (dummy-33 (_type_) object 33)
    (TODO-RENAME-34 (_type_) none 34)
    )
  )

;; definition for method 3 of type rigid-body-platform
(defmethod inspect rigid-body-platform ((obj rigid-body-platform))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tinfo: #<rigid-body-platform-constants @ #x~X>~%" (-> obj info))
  (format #t "~T~Trbody: #<rigid-body @ #x~X>~%" (-> obj rbody))
  (format #t "~T~Tcontrol-point-array: ~A~%" (-> obj control-point-array))
  (format #t "~T~Tplayer-velocity: #<vector @ #x~X>~%" (-> obj player-velocity))
  (format #t "~T~Tplayer-velocity-prev: #<vector @ #x~X>~%" (-> obj player-velocity-prev))
  (format #t "~T~Tplayer-force-position: #<vector @ #x~X>~%" (-> obj player-force-position))
  (format #t "~T~Tplayer-force: #<vector @ #x~X>~%" (-> obj player-force))
  (format #t "~T~Tsim-time-remaining: ~f~%" (-> obj sim-time-remaining))
  (format #t "~T~Tfloat-height-offset: ~f~%" (-> obj float-height-offset))
  (format #t "~T~Tplayer-attack-id: ~D~%" (-> obj player-attack-id))
  (format #t "~T~Tplayer-bonk-timeout: ~D~%" (-> obj player-bonk-timeout))
  (format #t "~T~Twater-anim: ~A~%" (-> obj water-anim))
  (format #t "~T~Tplayer-contact: ~A~%" (-> obj player-contact))
  (format #t "~T~Tplayer-impulse: ~A~%" (-> obj player-impulse))
  obj
  )

;; definition for method 7 of type rigid-body-platform
;; INFO: Return type mismatch process-drawable vs rigid-body-platform.
(defmethod relocate rigid-body-platform ((obj rigid-body-platform) (arg0 int))
  (if (nonzero? (-> obj control-point-array))
      (set! (-> obj control-point-array)
            (the-as rigid-body-control-point-inline-array (+ (the-as int (-> obj control-point-array)) arg0))
            )
      )
  (the-as
    rigid-body-platform
    ((the-as (function process-drawable int process-drawable) (find-parent-method rigid-body-platform 7))
     obj
     arg0
     )
    )
  )

;; definition for method 22 of type rigid-body-platform
(defmethod TODO-RENAME-22 rigid-body-platform ((obj rigid-body-platform) (arg0 vector) (arg1 float))
  (let ((v1-0 (-> obj water-anim)))
    0.0
    (+ (the-as float (cond
                       (v1-0
                         (let* ((a2-1 v1-0)
                                (a0-1 (if a2-1
                                          (-> a2-1 ppointer-water-anim 3)
                                          )
                                      )
                                )
                           (if a0-1
                               (get-ripple-height a0-1 arg0)
                               (-> v1-0 ppointer-water-anim 9)
                               )
                           )
                         )
                       (else
                         (ocean-get-height arg0)
                         )
                       )
               )
       (-> obj float-height-offset)
       )
    )
  )

;; definition for method 24 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-24 rigid-body-platform ((obj rigid-body-platform) (arg0 rigid-body-control-point) (arg1 float))
  (set! (-> arg0 world-pos w) (TODO-RENAME-22 obj (-> arg0 world-pos) arg1))
  (let* ((s4-0 (new 'stack-no-clear 'vector))
         (f0-2 (- (-> arg0 world-pos w) (-> arg0 world-pos y)))
         (f30-0 (/ f0-2 (-> obj info max-buoyancy-depth)))
         )
    (when (< 0.0 f0-2)
      (vector-float*! s4-0 *y-vector* (* (-> obj rbody mass)
                                         (fmin 1.0 f30-0)
                                         (/ (-> obj info gravity) (the float (-> obj info control-point-count)))
                                         (-> obj info gravity-factor)
                                         (-> obj info buoyancy-factor)
                                         )
                      )
      (TODO-RENAME-13 (-> obj rbody) (-> arg0 world-pos) s4-0)
      (vector-float*! s4-0 (-> arg0 velocity) (* -1.0 (-> obj info drag-factor) (fmin 1.0 f30-0)))
      (TODO-RENAME-13 (-> obj rbody) (-> arg0 world-pos) s4-0)
      )
    )
  0
  0
  (none)
  )

;; definition for method 25 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-25 rigid-body-platform ((obj rigid-body-platform))
  (when (or (-> obj player-impulse) (-> obj player-contact))
    (set! (-> obj player-impulse) #f)
    (TODO-RENAME-16
      (-> obj rbody)
      (-> obj player-force-position)
      (-> obj player-force)
      (-> obj info player-force-distance)
      )
    )
  0
  (none)
  )

;; definition for method 26 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-26 rigid-body-platform ((obj rigid-body-platform))
  (let ((a1-0 (new 'stack-no-clear 'vector)))
    (vector-float*!
      a1-0
      *y-vector*
      (* -1.0 (-> obj info gravity-factor) (-> obj info gravity) (-> obj rbody mass))
      )
    (TODO-RENAME-15 (-> obj rbody) a1-0)
    )
  0
  (none)
  )

;; definition for method 27 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-27 rigid-body-platform ((obj rigid-body-platform) (arg0 vector))
  (let ((gp-0 (new 'stack-no-clear 'vector)))
    (vector-! gp-0 arg0 (-> obj rbody position))
    (set! (-> gp-0 y) 0.0)
    (let* ((f0-1 (vector-length gp-0))
           (f1-1 (* 10.0 (fmax 0.0 (fmin 4096.0 (+ -4096.0 f0-1)))))
           )
      (when (< 0.0 f1-1)
        (vector-float*! gp-0 gp-0 (/ f1-1 f0-1))
        (TODO-RENAME-15 (-> obj rbody) gp-0)
        )
      )
    )
  0
  (none)
  )

;; definition for method 23 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-23 rigid-body-platform ((obj rigid-body-platform) (arg0 float))
  (let ((s4-0 (-> obj rbody matrix)))
    (dotimes (s3-0 (-> obj info control-point-count))
      (let ((s2-0 (-> obj control-point-array data s3-0)))
        (vector-matrix*! (-> s2-0 world-pos) (-> s2-0 local-pos) s4-0)
        (TODO-RENAME-17 (-> obj rbody) (-> s2-0 world-pos) (-> s2-0 velocity))
        (TODO-RENAME-24 obj s2-0 arg0)
        )
      )
    )
  (TODO-RENAME-26 obj)
  (TODO-RENAME-25 obj)
  0
  (none)
  )

;; definition for method 28 of type rigid-body-platform
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-28 rigid-body-platform ((obj rigid-body-platform))
  (if (-> obj info platform)
      (detect-riders! (-> obj root-overlay))
      )
  (set! (-> obj player-velocity-prev quad) (-> obj player-velocity quad))
  (if *target*
      (set! (-> obj player-velocity quad) (-> *target* control transv quad))
      (set! (-> obj player-velocity quad) (-> *null-vector* quad))
      )
  (+! (-> obj sim-time-remaining)
      (* 0.0033333334 (the float (- (-> *display* base-frame-counter) (-> *display* old-base-frame-counter))))
      )
  (let ((f30-0 0.016666668)
        (f28-0 (* 0.0033333334 (the float (logand #xffffff (-> *display* base-frame-counter)))))
        )
    (while (>= (-> obj sim-time-remaining) (* 0.5 f30-0))
      (clear-force-torque! (-> obj rbody))
      (TODO-RENAME-23 obj f28-0)
      (dummy-10 (-> obj rbody) f30-0)
      (set! (-> obj sim-time-remaining) (- (-> obj sim-time-remaining) f30-0))
      )
    )
  (set! (-> obj player-contact) #f)
  0
  (none)
  )

;; definition for function rigid-body-platform-event-handler
;; INFO: Used lq/sq
(defbehavior rigid-body-platform-event-handler rigid-body-platform ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('bonk)
     (when (>= (- (-> *display* base-frame-counter) (-> self player-bonk-timeout)) (-> self info player-force-timeout))
       (set! (-> self player-bonk-timeout) (-> *display* base-frame-counter))
       (let* ((s5-0 arg0)
              (v1-7 (if (and (nonzero? s5-0) (type-type? (-> s5-0 type) process-drawable))
                        s5-0
                        )
                    )
              )
         (when v1-7
           (set! (-> self player-impulse) (the-as collide-shape-prim-mesh #t))
           (set! (-> self player-force-position quad) (-> (the-as process-drawable v1-7) root trans quad))
           (let ((f0-4 (fmin
                         (* 0.00012207031
                            (the-as float (-> arg3 param 1))
                            (-> self info player-bonk-factor)
                            (-> self info player-weight)
                            )
                         (-> self info player-force-clamp)
                         )
                       )
                 )
             (vector-float*! (-> self player-force) *y-vector* (- f0-4))
             )
           )
         )
       )
     )
    (('attack)
     (let ((v1-16 (-> arg3 param 2)))
       (when (!= v1-16 (-> self player-attack-id))
         (set! (-> self player-attack-id) (the-as int v1-16))
         (cond
           ((= (-> arg3 param 1) 'flop)
            (when (>= (- (-> *display* base-frame-counter) (-> self player-bonk-timeout)) (-> self info player-force-timeout))
              (set! (-> self player-bonk-timeout) (-> *display* base-frame-counter))
              (let* ((gp-1 arg0)
                     (v1-24 (if (and (nonzero? gp-1) (type-type? (-> gp-1 type) process-drawable))
                                gp-1
                                )
                            )
                     )
                (when v1-24
                  (set! (-> self player-impulse) (the-as collide-shape-prim-mesh #t))
                  (set! (-> self player-force-position quad) (-> (the-as process-drawable v1-24) root trans quad))
                  (let ((f0-9 (fmin
                                (* 16.0 (-> self info player-weight) (-> self info player-dive-factor))
                                (-> self info player-force-clamp)
                                )
                              )
                        )
                    (vector-float*! (-> self player-force) *y-vector* (- f0-9))
                    )
                  )
                )
              )
            )
           ((= (-> arg3 param 1) 'explode)
            (let* ((gp-2 arg0)
                   (v1-34 (if (and (nonzero? gp-2) (type-type? (-> gp-2 type) process-drawable))
                              gp-2
                              )
                          )
                   )
              (when v1-34
                (set! (-> self player-impulse) (the-as collide-shape-prim-mesh #t))
                (set! (-> self player-force-position quad) (-> (the-as process-drawable v1-34) root trans quad))
                (vector-! (-> self player-force) (-> self rbody position) (-> (the-as process-drawable v1-34) root trans))
                (vector-normalize! (-> self player-force) (-> self info explosion-force))
                )
              )
            )
           (else
             (the-as vector #f)
             )
           )
         )
       )
     )
    (('impulse)
     (let ((s5-1 arg0))
       (when (if (and (nonzero? s5-1) (type-type? (-> s5-1 type) process-drawable))
                 s5-1
                 )
         (set! (-> self player-impulse) (the-as collide-shape-prim-mesh #t))
         (set! (-> self player-force-position quad) (-> self rbody position quad))
         (let ((v0-0 (-> self player-force)))
           (set! (-> v0-0 quad) (-> (the-as vector (-> arg3 param 0)) quad))
           v0-0
           )
         )
       )
     )
    (('edge-grabbed)
     (let ((v1-44 (-> arg3 param 0)))
       (when (not (-> self player-impulse))
         (set! (-> self player-contact) #t)
         (set! (-> self player-force-position quad) (-> (the-as vector (+ v1-44 32)) quad))
         (vector-float*! (-> self player-force) *y-vector* (* -1.0 (-> self info player-weight)))
         )
       )
     )
    (('ridden)
     (let ((v1-48 (the-as object (-> arg3 param 0))))
       (when (the-as uint v1-48)
         (let ((v1-50 (handle->process (-> (the-as (pointer handle) v1-48) 0))))
           (when (and v1-50 (= v1-50 *target*) (!= (-> *target* control unknown-surface00 mode) 'swim))
             (when (not (-> self player-impulse))
               (set! (-> self player-contact) #t)
               (set! (-> self player-force-position quad) (-> (the-as process-drawable v1-50) root trans quad))
               (set! (-> self player-force quad) (-> *null-vector* quad))
               (vector+*! (-> self player-force) (-> self player-force) *y-vector* (* -1.0 (-> self info player-weight)))
               )
             )
           )
         )
       )
     )
    )
  )

;; definition for function rigid-body-platform-post
(defbehavior rigid-body-platform-post rigid-body-platform ()
  (set! (-> self rbody lin-momentum-damping-factor) (-> self info linear-damping))
  (set! (-> self rbody ang-momentum-damping-factor) (-> self info angular-damping))
  (if (-> self player-impulse)
      (sound-play-by-name
        (string->sound-name (-> self info sound-name))
        (new-sound-id)
        1024
        0
        0
        (sound-group sfx)
        #t
        )
      )
  (TODO-RENAME-28 self)
  (quaternion-copy! (-> self root-overlay quat) (-> self rbody rotation))
  (TODO-RENAME-18 (-> self rbody) (-> self root-overlay trans))
  (if (-> self info platform)
      (rider-post)
      (transform-post)
      )
  )

;; failed to figure out what this is:
(defstate rigid-body-platform-idle (rigid-body-platform)
  :virtual #t
  :trans (behavior ()
    (if (and *target* (>= (-> self info idle-distance)
                          (vector-vector-distance (-> self root-overlay trans) (-> *target* control trans))
                          )
             )
        (go-virtual rigid-body-platform-float)
        )
    (none)
    )
  :code (behavior ()
    (loop
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior rigid-body-platform) ja-post)
  )

;; failed to figure out what this is:
(defstate rigid-body-platform-float (rigid-body-platform)
  :virtual #t
  :event rigid-body-platform-event-handler
  :trans (behavior ()
    (if (or (not *target*) (< (-> self info idle-distance)
                              (vector-vector-distance (-> self root-overlay trans) (-> *target* control trans))
                              )
            )
        (go-virtual rigid-body-platform-idle)
        )
    (none)
    )
  :code (behavior ()
    (loop
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior rigid-body-platform) rigid-body-platform-post)
  )

;; definition for method 29 of type rigid-body-platform
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-29 rigid-body-platform ((obj rigid-body-platform) (arg0 rigid-body-platform-constants))
  (set! (-> obj info) arg0)
  (set! (-> obj control-point-array)
        (new 'process 'rigid-body-control-point-inline-array (-> obj info control-point-count))
        )
  (logior! (-> obj skel status) (janim-status inited))
  (update-transforms! (-> obj root-overlay))
  (set-vector!
    (-> obj rbody cm-offset-joint)
    (-> obj info cm-joint-x)
    (-> obj info cm-joint-y)
    (-> obj info cm-joint-z)
    1.0
    )
  (TODO-RENAME-22
    (-> obj rbody)
    (-> obj root-overlay trans)
    (-> obj root-overlay quat)
    (-> obj info linear-damping)
    (-> obj info angular-damping)
    )
  (TODO-RENAME-9
    (-> obj rbody)
    (-> obj info mass)
    (-> obj info inertial-tensor-x)
    (-> obj info inertial-tensor-y)
    (-> obj info inertial-tensor-z)
    )
  (set! (-> obj player-impulse) #f)
  (set! (-> obj player-contact) #f)
  (set! (-> obj player-bonk-timeout) (-> *display* base-frame-counter))
  (set! (-> obj player-force quad) (-> *null-vector* quad))
  (set! (-> obj player-velocity quad) (-> *null-vector* quad))
  (set! (-> obj player-velocity-prev quad) (-> *null-vector* quad))
  (set! (-> obj water-anim) (the-as water-anim (entity-actor-lookup (-> obj entity) 'water-actor 0)))
  0
  (none)
  )

;; definition for method 30 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-30 rigid-body-platform ((obj rigid-body-platform))
  (let ((s5-0 (new 'process 'collide-shape-moving obj (collide-list-enum hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) default-collision-reaction)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (alloc-riders s5-0 1)
    (let ((s4-0 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> s4-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s4-0 collide-with) (collide-kind target))
      (set! (-> s4-0 prim-core action) (collide-action solid ca-1))
      (set! (-> s4-0 prim-core offense) (collide-offense indestructible))
      (set! (-> s4-0 transform-index) 0)
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 20480.0)
      (set-root-prim! s5-0 s4-0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (backup-collide-with-as s5-0)
    (set! (-> obj root-overlay) s5-0)
    )
  0
  (none)
  )

;; definition for symbol *rigid-body-platform-constants*, type rigid-body-platform-constants
(define *rigid-body-platform-constants* (new 'static 'rigid-body-platform-constants
                                          :drag-factor 0.8
                                          :buoyancy-factor 1.5
                                          :max-buoyancy-depth (meters 1.5)
                                          :gravity-factor 1.0
                                          :gravity (meters 10)
                                          :player-weight (meters 6.6)
                                          :player-bonk-factor 1.0
                                          :player-dive-factor 1.0
                                          :player-force-distance (meters 1000)
                                          :player-force-clamp (meters 1000000)
                                          :player-force-timeout (seconds 0.1)
                                          :explosion-force (meters 1000)
                                          :linear-damping 1.0
                                          :angular-damping 1.0
                                          :control-point-count 1
                                          :mass 2.0
                                          :inertial-tensor-x (meters 3)
                                          :inertial-tensor-y (meters 2)
                                          :inertial-tensor-z (meters 3)
                                          :idle-distance (meters 50)
                                          :platform #t
                                          :sound-name #f
                                          )
        )

;; definition for method 34 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-34 rigid-body-platform ((obj rigid-body-platform))
  (go (method-of-object obj rigid-body-platform-idle))
  0
  (none)
  )

;; definition for method 31 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-31 rigid-body-platform ((obj rigid-body-platform))
  (set! (-> obj float-height-offset) 0.0)
  (TODO-RENAME-29 obj *rigid-body-platform-constants*)
  (let ((s5-0 (-> obj info control-point-count)))
    (dotimes (s4-0 s5-0)
      (let ((s3-0 (-> obj control-point-array data s4-0)))
        (let ((f30-0 (* 65536.0 (/ (the float s4-0) (the float s5-0)))))
          (set! (-> s3-0 local-pos x) (* 12288.0 (sin f30-0)))
          (set! (-> s3-0 local-pos y) -10240.0)
          (set! (-> s3-0 local-pos z) (* 12288.0 (cos f30-0)))
          )
        (set! (-> s3-0 local-pos w) 1.0)
        )
      )
    )
  0
  (none)
  )

;; definition for method 11 of type rigid-body-platform
;; INFO: Return type mismatch int vs none.
(defmethod init-from-entity! rigid-body-platform ((obj rigid-body-platform) (arg0 entity-actor))
  (set! (-> obj mask) (logior (process-mask platform) (-> obj mask)))
  (TODO-RENAME-30 obj)
  (process-drawable-from-entity! obj arg0)
  (TODO-RENAME-31 obj)
  (TODO-RENAME-34 obj)
  0
  (none)
  )
