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

;; name: ragdoll-edit.gc
;; name in dgo: ragdoll-edit
;; dgos: GAME

;; DECOMP BEGINS

;; this file is debug only
(declare-file (debug))

(defun matrix->axis-angle ((arg0 vector) (arg1 matrix))
  (let ((s5-0 (matrix->quaternion (new 'stack-no-clear 'quaternion) arg1)))
    (vector-normalize-copy! arg0 (-> s5-0 vec) 1.0)
    (set! (-> arg0 w) (* 2.0 (acos (-> s5-0 w))))
    )
  )

(defmethod has-joint? ((this ragdoll-edit-info) (arg0 ragdoll-joint))
  (dotimes (v1-0 (-> this child-stack-num))
    (if (= (-> this child-stack v1-0) arg0)
        (return #t)
        )
    )
  #f
  )

(defmethod ragdoll-edit-info-method-10 ((this ragdoll-edit-info) (arg0 object) (arg1 ragdoll-joint))
  (dotimes (v1-0 (-> this child-stack-num))
    (if (= (-> this child-stack v1-0 joint-index) arg1)
        (return #t)
        )
    )
  #f
  )

(defmethod fill-child-stack! ((this ragdoll-edit-info) (arg0 ragdoll))
  "Fill the `child-stack` with the joints of the given ragdoll."
  (let ((v1-0 (-> this affect)))
    (cond
      ((zero? v1-0)
       (set! (-> this child-stack-num) 1)
       (set! (-> this child-stack 0) (-> arg0 ragdoll-joints (-> this current-joint)))
       )
      ((= v1-0 1)
       (set! (-> this child-stack-num) 1)
       (set! (-> this child-stack 0) (-> arg0 ragdoll-joints (-> this current-joint)))
       (let ((s4-0 (+ (-> this current-joint) 1))
             (a0-6 #t)
             )
         (while (< s4-0 (the-as int (-> arg0 num-joints)))
           (let ((v1-15 (-> arg0 ragdoll-joints s4-0)))
             (set! a0-6 (and (< (-> v1-15 parent-joint) 0) a0-6))
             (cond
               ((or a0-6 (and (>= (-> v1-15 parent-joint) 0)
                              (ragdoll-edit-info-method-10 this arg0 (the-as ragdoll-joint (-> v1-15 parent-joint)))
                              )
                    )
                (set! (-> this child-stack (-> this child-stack-num)) (-> arg0 ragdoll-joints s4-0))
                (set! (-> this child-stack-num) (min 60 (+ (-> this child-stack-num) 1)))
                (set! a0-6 #t)
                )
               (else
                 (set! a0-6 #f)
                 )
               )
             )
           (+! s4-0 1)
           )
         )
       )
      ((= v1-0 2)
       (dotimes (v1-29 (the-as int (-> arg0 num-joints)))
         (set! (-> this child-stack v1-29) (-> arg0 ragdoll-joints v1-29))
         )
       (set! (-> this child-stack-num) (the-as int (-> arg0 num-joints)))
       )
      )
    )
  0
  (none)
  )

(defmethod ragdoll-edit-info-method-12 ((this ragdoll-edit-info))
  (if (cpad-pressed? 0 up)
      (+! (-> this current-func) -1)
      )
  (if (cpad-pressed? 0 left)
      (+! (-> this current-func) -4)
      )
  (if (cpad-pressed? 0 down)
      (+! (-> this current-func) 1)
      )
  (if (cpad-pressed? 0 right)
      (+! (-> this current-func) 4)
      )
  (cond
    ((< (the-as int (-> this current-func)) 0)
     (set! (-> this current-func) (the-as uint 9))
     )
    ((>= (the-as int (-> this current-func)) 10)
     (set! (-> this current-func) (the-as uint 0))
     0
     )
    )
  (none)
  )

(defmethod cycle-joints! ((this ragdoll-edit-info) (arg0 ragdoll))
  "Cycle through joints based on controller input."
  (when (cpad-pressed? 0 r1)
    (+! (-> this current-joint) 1)
    (if (cpad-hold? 0 l1)
        (+! (-> this current-joint) 4)
        )
    )
  (when (cpad-pressed? 0 l1)
    (+! (-> this current-joint) -1)
    (if (cpad-hold? 0 r1)
        (+! (-> this current-joint) -4)
        )
    )
  (if (< (-> this current-joint) 0)
      (set! (-> this current-joint) (the-as int (+ (-> arg0 num-joints) -1)))
      )
  (when (>= (-> this current-joint) (the-as int (-> arg0 num-joints)))
    (set! (-> this current-joint) 0)
    0
    )
  (none)
  )

(defmethod ragdoll-edit-info-method-14 ((this ragdoll-edit-info)
                                       (arg0 matrix)
                                       (arg1 vector)
                                       (arg2 (inline-array ragdoll-joint))
                                       (arg3 ragdoll)
                                       (arg4 process-drawable)
                                       )
  (let ((s2-0 (get-parent-joint arg3 arg2)))
    (cond
      (s2-0
        (quaternion->matrix arg0 (-> s2-0 quat))
        (vector-copy! arg1 (-> s2-0 position))
        arg1
        )
      ((< (-> arg2 0 parent-joint) 0)
       (quaternion->matrix arg0 (-> arg4 root quat))
       (vector-copy! arg1 (-> arg4 root trans))
       arg1
       )
      (else
        (matrix-copy! arg0 (-> arg4 node-list data (-> arg2 0 parent-joint) bone transform))
        (vector<-cspace! arg1 (-> arg4 node-list data (-> arg2 0 parent-joint)))
        )
      )
    )
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod ragdoll-edit-info-method-15 ((this ragdoll-edit-info))
  (dotimes (s5-0 (-> this child-stack-num))
    (let ((s4-0 (-> this child-stack s5-0)))
      (case (-> this analog-func)
        ((5)
         (let ((s3-0 add-debug-text-3d)
               (s2-0 #t)
               (s1-0 577)
               )
           (format (clear *temp-string*) "~%~R~%" (-> s4-0 max-angle))
           (s3-0 s2-0 (the-as bucket-id s1-0) *temp-string* (-> s4-0 position) (font-color orange) (the-as vector2h #f))
           )
         )
        ((3)
         (let ((s3-1 add-debug-text-3d)
               (s2-1 #t)
               (s1-1 577)
               )
           (format (clear *temp-string*) "~%~R~%" (-> s4-0 axial-slop))
           (s3-1 s2-1 (the-as bucket-id s1-1) *temp-string* (-> s4-0 position) (font-color orange) (the-as vector2h #f))
           )
         )
        ((4)
         (let ((s3-2 add-debug-text-3d)
               (s2-2 #t)
               (s1-2 577)
               )
           (format (clear *temp-string*) "~%~M~%" (-> s4-0 joint-length))
           (s3-2 s2-2 (the-as bucket-id s1-2) *temp-string* (-> s4-0 position) (font-color orange) (the-as vector2h #f))
           )
         )
        ((6)
         (add-debug-sphere
           #t
           (bucket-id debug-no-zbuf1)
           (-> s4-0 position)
           (-> s4-0 coll-rad)
           (new 'static 'rgba :b #xff :a #x80)
           )
         )
        ((8)
         (let ((s3-3 add-debug-text-3d)
               (s2-3 #t)
               (s1-3 577)
               )
           (format
             (clear *temp-string*)
             "~%~f ~f ~f ~f~%"
             (-> s4-0 quat x)
             (-> s4-0 quat y)
             (-> s4-0 quat z)
             (-> s4-0 quat w)
             )
           (s3-3 s2-3 (the-as bucket-id s1-3) *temp-string* (-> s4-0 position) (font-color orange) (the-as vector2h #f))
           )
         )
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod ragdoll-edit-info-method-16 ((this ragdoll-edit-info) (arg0 ragdoll) (arg1 process-drawable))
  (local-vars
    (sv-4352 ragdoll-joint)
    (sv-4368 matrix)
    (sv-4384 vector)
    (sv-4400 matrix)
    (sv-4416 matrix)
    (sv-4432 vector)
    (sv-4448 quaternion)
    (sv-4464 matrix)
    (sv-4480 matrix)
    (sv-4496 matrix)
    )
  (let ((s3-0 (new 'stack-no-clear 'inline-array 'matrix 60)))
    (dotimes (v1-0 60)
      (let ((a0-2 (-> s3-0 v1-0)))
        (set! (-> a0-2 rvec quad) (the-as uint128 0))
        (set! (-> a0-2 uvec quad) (the-as uint128 0))
        (set! (-> a0-2 fvec quad) (the-as uint128 0))
        (set! (-> a0-2 trans quad) (the-as uint128 0))
        )
      )
    (dotimes (s2-0 (the-as int (-> arg0 num-joints)))
      (let ((s0-0 (-> arg0 ragdoll-joints s2-0)))
        (set! sv-4352 (get-parent-joint arg0 (the-as (inline-array ragdoll-joint) s0-0)))
        (set! sv-4368 (-> s3-0 s2-0))
        (let ((s1-0 (new 'stack-no-clear 'matrix)))
          (cond
            (sv-4352
              (set! sv-4416
                    (matrix-axis-angle! (new 'stack-no-clear 'matrix) (-> s0-0 pre-tform) (- (-> s0-0 pre-tform w)))
                    )
              (set! sv-4432 (new 'stack-no-clear 'vector))
              (matrix-copy!
                s1-0
                (-> s3-0
                    (/ (the-as uint (&- (the-as pointer sv-4352) (the-as uint (the-as pointer (-> arg0 ragdoll-joints)))))
                       (the-as uint 192)
                       )
                    )
                )
              (vector-copy! sv-4432 (-> s1-0 trans))
              (vector-reset! (-> s1-0 trans))
              (when (and (-> this auto-setup-now)
                         (ragdoll-edit-info-method-10 this arg0 (the-as ragdoll-joint (-> s0-0 joint-index)))
                         )
                (set! sv-4384 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (-> s0-0 position) sv-4432) 1.0))
                (set! sv-4400 (new 'stack-no-clear 'matrix))
                (matrix*! sv-4416 sv-4416 s1-0)
                (matrix-from-two-vectors! sv-4400 (-> sv-4416 uvec) sv-4384)
                (matrix*! sv-4416 sv-4416 sv-4400)
                (matrix-transpose! sv-4400 s1-0)
                (matrix*! sv-4416 sv-4416 sv-4400)
                (matrix->axis-angle (-> s0-0 pre-tform) sv-4416)
                )
              (let ((t9-10 matrix*!)
                    (a0-21 s1-0)
                    (a2-8 s1-0)
                    )
                (t9-10 a0-21 sv-4416 a2-8)
                )
              (vector-copy! (-> s1-0 trans) sv-4432)
              (vector-! (-> sv-4368 uvec) (-> s0-0 position) (-> sv-4352 position))
              (vector-normalize! (-> sv-4368 uvec) 1.0)
              (vector-flatten! (-> sv-4368 rvec) (-> s1-0 rvec) (-> sv-4368 uvec))
              (vector-normalize! (-> sv-4368 rvec) 1.0)
              (vector-cross! (-> sv-4368 fvec) (-> sv-4368 rvec) (-> sv-4368 uvec))
              (vector-copy! (-> sv-4368 trans) (-> s0-0 position))
              (set! (-> sv-4368 rvec w) 0.0)
              (set! (-> sv-4368 uvec w) 0.0)
              (set! (-> sv-4368 fvec w) 0.0)
              )
            ((= s0-0 (-> arg0 ragdoll-joints))
             (quaternion->matrix sv-4368 (-> s0-0 quat))
             (vector-copy! (-> sv-4368 trans) (-> s0-0 position))
             (quaternion->matrix s1-0 (-> arg1 root quat))
             (vector-copy! (-> s1-0 trans) (-> arg1 root trans))
             )
            (else
              (matrix-copy! sv-4368 (-> arg1 node-list data (-> s0-0 joint-index) bone transform))
              (vector-copy! (-> sv-4368 trans) (-> s0-0 position))
              (matrix-copy! s1-0 sv-4368)
              (vector<-cspace! (-> s1-0 trans) (-> arg1 node-list data (-> s0-0 parent-joint)))
              )
            )
          (when (and (-> this auto-setup-now)
                     (ragdoll-edit-info-method-10 this arg0 (the-as ragdoll-joint (-> s0-0 joint-index)))
                     )
            (set! sv-4464 (new 'stack-no-clear 'matrix))
            (set! sv-4480 (new 'stack-no-clear 'matrix))
            (matrix-copy! sv-4464 sv-4368)
            (vector-reset! (-> sv-4464 trans))
            (matrix-transpose! sv-4464 sv-4464)
            (set! sv-4448 (matrix->quaternion
                            (new 'stack-no-clear 'quaternion)
                            (-> arg1 node-list data (-> s0-0 joint-index) bone transform)
                            )
                  )
            (quaternion-normalize! sv-4448)
            (quaternion->matrix sv-4480 sv-4448)
            (matrix*! sv-4480 sv-4480 sv-4464)
            (matrix->axis-angle (-> s0-0 geo-tform) sv-4480)
            )
          (case (-> this skel-visible)
            ((1)
             (add-debug-line
               #t
               (bucket-id debug-no-zbuf1)
               (-> sv-4368 trans)
               (-> s1-0 trans)
               (new 'static 'rgba :r #xff :b #xff :a #x80)
               #f
               (the-as rgba -1)
               )
             (when (or (not (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
                       (zero? (-> this analog-func))
                       (not (ragdoll-edit-info-method-10 this arg0 (the-as ragdoll-joint (-> s0-0 joint-index))))
                       )
               (let ((f30-0 0.25))
                 (if (and (nonzero? (-> this analog-func))
                          (ragdoll-edit-info-method-10 this arg0 (the-as ragdoll-joint (-> s0-0 joint-index)))
                          )
                     (set! f30-0 0.35)
                     )
                 (add-debug-matrix #t (bucket-id debug-no-zbuf1) sv-4368 (* 4096.0 f30-0))
                 )
               )
             (set! sv-4496
                   (matrix-axis-angle! (new 'stack-no-clear 'matrix) (-> s0-0 geo-tform) (- (-> s0-0 geo-tform w)))
                   )
             (matrix*! sv-4496 sv-4496 sv-4368)
             (vector-copy! (-> sv-4496 trans) (-> (the-as matrix sv-4368) trans))
             (let ((t9-30 add-debug-matrix)
                   (a0-66 #t)
                   (a1-46 577)
                   (a3-10 #x4419999a)
                   )
               (t9-30 a0-66 (the-as bucket-id a1-46) sv-4496 (the-as meters a3-10))
               )
             (let ((a2-22 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> s0-0 quat))))
               (vector-copy! (-> a2-22 trans) (-> (the-as matrix sv-4368) trans))
               (add-debug-matrix #t (bucket-id debug-no-zbuf1) a2-22 (meters 0.15))
               )
             (when (or (not (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
                       (nonzero? (-> this analog-func))
                       (not (ragdoll-edit-info-method-10 this arg0 (the-as ragdoll-joint (-> s0-0 joint-index))))
                       )
               (let ((f30-1 0.25))
                 (if (and (zero? (-> this analog-func))
                          (ragdoll-edit-info-method-10 this arg0 (the-as ragdoll-joint (-> s0-0 joint-index)))
                          )
                     (set! f30-1 0.35)
                     )
                 (add-debug-matrix #t (bucket-id debug-no-zbuf1) s1-0 (* 4096.0 f30-1))
                 )
               )
             )
            )
          )
        )
      )
    )
  (none)
  )

(defun show-maya-skeleton ((arg0 process-drawable) (arg1 int) (arg2 int))
  (local-vars (sv-96 symbol) (sv-112 int) (sv-128 (function _varargs_ object)))
  (when arg0
    (dotimes (s3-0 (-> arg0 node-list length))
      (let ((s2-0 (new 'stack-no-clear 'matrix))
            (s1-0 (new 'stack-no-clear 'vector))
            )
        (matrix-copy! s2-0 (-> arg0 node-list data s3-0 bone transform))
        (vector<-cspace! (-> s2-0 trans) (-> arg0 node-list data s3-0))
        (when (or (= arg1 -1) (= arg1 s3-0))
          (add-debug-matrix #t (bucket-id debug-no-zbuf1) s2-0 (the-as meters arg2))
          (let ((s0-0 add-debug-text-3d))
            (set! sv-96 #t)
            (set! sv-112 577)
            (set! sv-128 format)
            (let ((a0-9 (clear *temp-string*))
                  (a1-6 "~%~D ~S~%")
                  (a2-3 s3-0)
                  (a3-5 (if (-> arg0 node-list data s3-0 joint)
                            (-> arg0 node-list data s3-0 joint name)
                            "?"
                            )
                        )
                  )
              (sv-128 a0-9 a1-6 a2-3 a3-5)
              )
            (let ((a2-4 *temp-string*)
                  (a3-6 (-> s2-0 trans))
                  (t0-0 4)
                  (t1-0 #f)
                  )
              (s0-0 sv-96 (the-as bucket-id sv-112) a2-4 a3-6 (the-as font-color t0-0) (the-as vector2h t1-0))
              )
            )
          )
        (let ((a1-8 (-> arg0 node-list data s3-0 parent)))
          (when a1-8
            (vector<-cspace! s1-0 a1-8)
            (add-debug-line
              #t
              (bucket-id debug-no-zbuf1)
              (-> s2-0 trans)
              s1-0
              (new 'static 'rgba :g #xff :b #xff :a #x80)
              #f
              (the-as rgba -1)
              )
            )
          )
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun ragdoll-print-default-joints ((arg0 process-drawable))
  (cond
    (arg0
      (dotimes (s5-0 (-> arg0 node-list length))
        (let ((s4-0 (-> arg0 node-list data s5-0 joint)))
          (when s4-0
            (let* ((s3-0 (-> s4-0 parent))
                   (s2-0 (or (not s3-0) (= (-> s3-0 number) (+ (-> s4-0 number) -1))))
                   )
              (if (not s2-0)
                  (format #t "~%")
                  )
              (format #t "(:joint-name ~15S  :parent-joint ~15S  )~%" (-> s4-0 name) (if s2-0
                                                                                         "-1"
                                                                                         (-> s3-0 name)
                                                                                         )
                      )
              )
            )
          )
        )
      )
    (else
      (format 0 "ragdoll-print-default-joints called with no process~%")
      )
    )
  (none)
  )

(defmethod ragdoll-edit-info-method-17 ((this ragdoll-edit-info) (arg0 ragdoll) (arg1 process-drawable))
  (local-vars (v0-23 object) (v0-32 object) (sv-848 matrix) (sv-864 matrix) (sv-880 matrix))
  (set! (-> this last-frame-dur) (- (current-time) (-> this last-frame)))
  (set-time! (-> this last-frame))
  (when (cpad-pressed? 0 l2)
    (set! (-> this editing) (not (-> this editing)))
    (cond
      ((-> this editing)
       (set! *external-cam-mode* 'locked)
       )
      (*target*
        (set! *external-cam-mode* #f)
        )
      (else
        (set! *external-cam-mode* 'pad-0)
        )
      )
    )
  (cond
    ((or (not (-> this editing)) (cpad-hold? 0 r2))
     (if (not (-> this editing))
         (format *stdcon* "press l2 to edit ragdoll~%")
         (format *stdcon* "release r2 to continue editing ragdoll~%")
         )
     (if (or (cpad-hold? 0 r2) (not *target*))
         (set! *external-cam-mode* 'pad-0)
         )
     (fill-child-stack! this arg0)
     )
    (else
      (set! *external-cam-mode* 'locked)
      (ragdoll-edit-info-method-12 this)
      (cycle-joints! this arg0)
      (fill-child-stack! this arg0)
      (set! (-> this auto-setup-now) #f)
      (let ((s2-0 ">")
            (s3-0 " ")
            )
        (if (not (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
            (set! s2-0 " ")
            )
        (format *stdcon* " r1/l1: select joint ~D~%" (-> this current-joint))
        (format *stdcon* " dpad: select function~%")
        (format *stdcon* " r2/l2: move camera~%")
        (format *stdcon* " r2: advance single-step~%")
        (format *stdcon* " x, tri: toggle/call~%")
        (format *stdcon* " rpush: stop editing~%")
        (format *stdcon* "------------------------~%")
        (let ((t9-13 format)
              (a0-19 *stdcon*)
              (a1-13 " ~S analog: ~S~%")
              (a2-2 (if (zero? (-> this current-func))
                        s2-0
                        s3-0
                        )
                    )
              (v1-42 (-> this analog-func))
              )
          (t9-13 a0-19 a1-13 a2-2 (cond
                                    ((zero? v1-42)
                                     "rotate parent"
                                     )
                                    ((= v1-42 1)
                                     "rotate geo"
                                     )
                                    ((= v1-42 2)
                                     "global scale"
                                     )
                                    ((= v1-42 3)
                                     "axial slop"
                                     )
                                    ((= v1-42 4)
                                     "length"
                                     )
                                    ((= v1-42 5)
                                     "max angle"
                                     )
                                    ((= v1-42 6)
                                     "collision radius"
                                     )
                                    ((= v1-42 7)
                                     "rotate orient"
                                     )
                                    ((= v1-42 8)
                                     "rotate"
                                     )
                                    (else
                                      "???"
                                      )
                                    )
                 )
          )
        (let* ((v1-46 (-> arg0 ragdoll-joints (-> this current-joint)))
               (t9-14 format)
               (a0-21 *stdcon*)
               (a1-14 " ~S joint type: ~S~%")
               (a2-4 (if (= (-> this current-func) 1)
                         s2-0
                         s3-0
                         )
                     )
               (v1-47 (-> v1-46 joint-type))
               )
          (t9-14 a0-21 a1-14 a2-4 (cond
                                    ((zero? v1-47)
                                     "cone"
                                     )
                                    ((= v1-47 1)
                                     "hinge"
                                     )
                                    (else
                                      "???"
                                      )
                                    )
                 )
          )
        (format *stdcon* " ~S auto setup~%" (if (= (-> this current-func) 2)
                                                s2-0
                                                s3-0
                                                )
                )
        (let ((t9-16 format)
              (a0-23 *stdcon*)
              (a1-16 " ~S skel: ~S~%")
              (a2-8 (if (= (-> this current-func) 3)
                        s2-0
                        s3-0
                        )
                    )
              (v1-50 (-> this skel-visible))
              )
          (t9-16 a0-23 a1-16 a2-8 (cond
                                    ((zero? v1-50)
                                     "visible"
                                     )
                                    ((= v1-50 1)
                                     "calculated"
                                     )
                                    ((= v1-50 2)
                                     "hidden"
                                     )
                                    ((= v1-50 3)
                                     "maya"
                                     )
                                    ((= v1-50 4)
                                     "ragdoll+maya"
                                     )
                                    (else
                                      "???"
                                      )
                                    )
                 )
          )
        (let ((t9-17 format)
              (a0-24 *stdcon*)
              (a1-17 " ~S run: ~S~%")
              (a2-10 (if (= (-> this current-func) 4)
                         s2-0
                         s3-0
                         )
                     )
              (v1-52 (-> this single-step))
              )
          (t9-17 a0-24 a1-17 a2-10 (cond
                                     ((zero? v1-52)
                                      "free"
                                      )
                                     ((= v1-52 1)
                                      "r2 single step"
                                      )
                                     ((= v1-52 2)
                                      "locked"
                                      )
                                     (else
                                       "???"
                                       )
                                     )
                 )
          )
        (format
          *stdcon*
          " ~S collision: ~S~%"
          (if (= (-> this current-func) 5)
              s2-0
              s3-0
              )
          (if (-> this collision)
              "on"
              "off"
              )
          )
        (format
          *stdcon*
          " ~S gravity: ~S~%"
          (if (= (-> this current-func) 6)
              s2-0
              s3-0
              )
          (if (-> this gravity)
              "on"
              "off"
              )
          )
        (format
          *stdcon*
          " ~S mirror: ~S~%"
          (if (= (-> this current-func) 7)
              s2-0
              s3-0
              )
          (if (= (-> arg1 node-list data 2 param0) cspace<-parented-matrix-joint-flip-z!)
              "on"
              "off"
              )
          )
        (let ((t9-21 format)
              (a0-28 *stdcon*)
              (a1-21 " ~S affect: ~S~%")
              (a2-18 (if (= (-> this current-func) 8)
                         s2-0
                         s3-0
                         )
                     )
              (v1-60 (-> this affect))
              )
          (t9-21 a0-28 a1-21 a2-18 (cond
                                     ((zero? v1-60)
                                      "current"
                                      )
                                     ((= v1-60 1)
                                      "children"
                                      )
                                     ((= v1-60 2)
                                      "all"
                                      )
                                     (else
                                       "???"
                                       )
                                     )
                 )
          )
        (format *stdcon* " ~S print to listener~%" (cond
                                                     ((= (-> this current-func) 9)
                                                      (empty)
                                                      s2-0
                                                      )
                                                     (else
                                                       s3-0
                                                       )
                                                     )
                )
        )
      (let ((v1-62 0))
        (if (cpad-pressed? 0 x)
            (+! v1-62 1)
            )
        (if (cpad-pressed? 0 triangle)
            (+! v1-62 -1)
            )
        (when (nonzero? v1-62)
          (let ((a0-43 (-> this current-func)))
            (set! v0-23
                  (cond
                    ((zero? a0-43)
                     (set! v0-23 (+ (-> this analog-func) v1-62))
                     (set! (-> this analog-func) (the-as uint v0-23))
                     v0-23
                     )
                    ((= a0-43 1)
                     (let ((a0-48 (-> arg0 ragdoll-joints (-> this current-joint))))
                       (+! (-> a0-48 joint-type) v1-62)
                       (cond
                         ((< (the-as int (-> a0-48 joint-type)) 0)
                          (set! (-> a0-48 joint-type) (the-as uint 1))
                          )
                         ((>= (the-as int (-> a0-48 joint-type)) 2)
                          (set! (-> a0-48 joint-type) (the-as uint 0))
                          0
                          )
                         )
                       (dotimes (v1-70 (-> this child-stack-num))
                         (set! (-> this child-stack v1-70 joint-type) (-> a0-48 joint-type))
                         )
                       )
                     #f
                     )
                    ((= a0-43 2)
                     (set! (-> this auto-setup-now) (the-as basic #t))
                     (if (= (-> arg1 node-list data 2 param0) cspace<-parented-matrix-joint-flip-z!)
                         (format 0 "WARNING: auto setup invoked on mirrored ragdoll--this probably won't work right.~%")
                         )
                     (if (!= (-> this affect) 2)
                         (format 0 "WARNING: auto setup invoked with affect not set to all.~%")
                         )
                     )
                    ((= a0-43 3)
                     (+! (-> this skel-visible) v1-62)
                     (cond
                       ((< (the-as int (-> this skel-visible)) 0)
                        (set! v0-23 4)
                        (set! (-> this skel-visible) (the-as uint v0-23))
                        v0-23
                        )
                       ((>= (the-as int (-> this skel-visible)) 5)
                        (set! (-> this skel-visible) (the-as uint 0))
                        0
                        )
                       )
                     )
                    ((= a0-43 4)
                     (+! (-> this single-step) v1-62)
                     (cond
                       ((< (the-as int (-> this single-step)) 0)
                        (set! v0-23 2)
                        (set! (-> this single-step) (the-as uint v0-23))
                        v0-23
                        )
                       ((>= (the-as int (-> this single-step)) 3)
                        (set! (-> this single-step) (the-as uint 0))
                        0
                        )
                       )
                     )
                    ((= a0-43 5)
                     (set! v0-23 (not (-> this collision)))
                     (set! (-> this collision) (the-as symbol v0-23))
                     v0-23
                     )
                    ((= a0-43 6)
                     (set! v0-23 (not (-> this gravity)))
                     (set! (-> this gravity) (the-as symbol v0-23))
                     v0-23
                     )
                    ((= a0-43 7)
                     (cond
                       ((= (-> arg1 node-list data 2 param0) cspace<-parented-matrix-joint-flip-z!)
                        (set! v0-23 (-> arg1 node-list data 2))
                        (set! (-> (the-as cspace v0-23) param0)
                              (the-as (function cspace transformq none) cspace<-parented-matrix-joint!)
                              )
                        (set! (-> (the-as cspace v0-23) param1) #f)
                        (set! (-> (the-as cspace v0-23) param2) #f)
                        )
                       (else
                         (set! v0-23 (-> arg1 node-list data 2))
                         (set! (-> (the-as cspace v0-23) param0)
                               (the-as (function cspace transformq none) cspace<-parented-matrix-joint-flip-z!)
                               )
                         (set! (-> (the-as cspace v0-23) param1) #f)
                         (set! (-> (the-as cspace v0-23) param2) #f)
                         )
                       )
                     v0-23
                     )
                    ((= a0-43 8)
                     (set! v0-23 (+ (-> this affect) v1-62))
                     (set! (-> this affect) (the-as uint v0-23))
                     v0-23
                     )
                    ((= a0-43 9)
                     (format #t "~%")
                     (format
                       #t
                       ":orient-tform (~7f ~7f ~7f ~9R)~%"
                       (-> arg0 orient-tform x)
                       (-> arg0 orient-tform y)
                       (-> arg0 orient-tform z)
                       (-> arg0 orient-tform w)
                       )
                     (format #t ":scale        (~7f ~7f ~7f)~%" (-> arg0 scale x) (-> arg0 scale y) (-> arg0 scale z))
                     (dotimes (s3-1 (the-as int (-> arg0 num-joints)))
                       (let ((s2-1 (-> arg0 ragdoll-joints s3-1)))
                         (if (!= (-> s2-1 parent-joint) -1)
                             (format #t "~%")
                             )
                         (format #t "(:joint-name ~15S  " (-> arg1 node-list data (-> s2-1 joint-index) joint name))
                         (set! v0-32
                               (cond
                                 ((= (-> s2-1 parent-joint) -1)
                                  (format #t ":parent-joint ~15D  " -1)
                                  v0-32
                                  )
                                 (else
                                   (let ((a2-30 (get-parent-joint arg0 (the-as (inline-array ragdoll-joint) s2-1))))
                                     (if a2-30
                                         (format #t ":parent-joint ~15S  " (-> arg1 node-list data (-> a2-30 joint-index) joint name))
                                         )
                                     )
                                   )
                                 )
                               )
                         (let ((t9-33 format)
                               (a0-69 #t)
                               (a1-45 ":joint-type ~S  ")
                               (v1-106 (-> s2-1 joint-type))
                               )
                           (t9-33 a0-69 a1-45 (cond
                                                ((= v1-106 1)
                                                 "hinge"
                                                 )
                                                ((zero? v1-106)
                                                 " cone"
                                                 )
                                                (else
                                                  "???"
                                                  )
                                                )
                                  )
                           )
                         (format #t ":axial-slop ~9R  " (-> s2-1 axial-slop))
                         (format #t ":max-angle ~9R  " (-> s2-1 max-angle))
                         (format #t ":coll-rad ~7M  " (-> s2-1 coll-rad))
                         (let ((a2-39 (sound-name->string (-> s2-1 hit-sound))))
                           (if (zero? (-> a2-39 data 0))
                               (set! a2-39 "\"\"")
                               )
                           (format #t ":hit-sound ~15s  " a2-39)
                           )
                         (format
                           #t
                           ":pre-tform (~7f ~7f ~7f ~9R)  "
                           (-> s2-1 pre-tform x)
                           (-> s2-1 pre-tform y)
                           (-> s2-1 pre-tform z)
                           (-> s2-1 pre-tform w)
                           )
                         (format
                           #t
                           ":geo-tform (~7f ~7f ~7f ~9R))~%"
                           (-> s2-1 geo-tform x)
                           (-> s2-1 geo-tform y)
                           (-> s2-1 geo-tform z)
                           (-> s2-1 geo-tform w)
                           )
                         )
                       )
                     (format #t "~%")
                     )
                    (else
                      (format 0 "~%ERROR<GMJ>: bad ragdoll-edit-func~%")
                      )
                    )
                  )
            )
          )
        )
      (cond
        ((< (the-as int (-> this analog-func)) 0)
         (set! (-> this analog-func) (the-as uint 8))
         )
        ((>= (the-as int (-> this analog-func)) 9)
         (set! (-> this analog-func) (the-as uint 0))
         0
         )
        )
      (cond
        ((< (the-as int (-> this affect)) 0)
         (set! (-> this affect) (the-as uint 2))
         )
        ((>= (the-as int (-> this affect)) 3)
         (set! (-> this affect) (the-as uint 0))
         0
         )
        )
      (let ((f30-0 (analog-input (the-as int (-> *cpad-list* cpads 0 rightx)) 128.0 48.0 110.0 1.0))
            (f28-0 (analog-input (the-as int (-> *cpad-list* cpads 0 righty)) 128.0 48.0 110.0 1.0))
            (f26-0 (analog-input (the-as int (-> *cpad-list* cpads 0 leftx)) 128.0 48.0 110.0 1.0))
            )
        (when (or (!= f30-0 0.0) (!= f28-0 0.0) (!= f26-0 0.0))
          (let ((v1-135 (-> this analog-func)))
            (cond
              ((or (zero? v1-135) (= v1-135 1) (= v1-135 7) (= v1-135 8))
               (set! f30-0 (* 546.13336 f30-0))
               (set! f28-0 (* -546.13336 f28-0))
               (set! f26-0 (* 546.13336 f26-0))
               )
              ((= v1-135 2)
               (let ((f0-25 (/ f30-0 100)))
                 (set! f30-0 (+ 1.0 f0-25))
                 )
               (let ((f0-27 (/ f28-0 -100)))
                 (set! f28-0 (+ 1.0 f0-27))
                 )
               (let ((f0-29 (/ f26-0 100)))
                 (set! f26-0 (+ 1.0 f0-29))
                 )
               )
              ((or (= v1-135 5) (= v1-135 3))
               (set! f30-0 (* 45.511112 f30-0))
               (set! f28-0 (* -45.511112 f28-0))
               (set! f26-0 (* 45.511112 f26-0))
               )
              ((or (= v1-135 4) (= v1-135 6))
               (set! f30-0 (* 40.96 f30-0))
               (set! f28-0 (* -40.96 f28-0))
               (set! f26-0 (* 40.96 f26-0))
               )
              )
            )
          (case (-> this analog-func)
            ((7)
             (let* ((s3-2 (-> arg0 orient-tform))
                    (s2-2 (matrix-axis-angle! (new 'stack-no-clear 'matrix) s3-2 (- (-> s3-2 w))))
                    )
               (let ((t9-47 matrix-rotate-xyz!)
                     (a0-96 (new 'stack-no-clear 'matrix))
                     (a1-64 (new 'stack-no-clear 'vector))
                     )
                 (set! (-> a1-64 x) f30-0)
                 (set! (-> a1-64 y) f28-0)
                 (set! (-> a1-64 z) f26-0)
                 (set! (-> a1-64 w) 1.0)
                 (let ((s1-0 (t9-47 a0-96 a1-64))
                       (s0-0 (new 'stack-no-clear 'matrix))
                       )
                   (let ((a2-46 (new 'stack-no-clear 'vector)))
                     (ragdoll-edit-info-method-14 this s0-0 a2-46 (-> arg0 ragdoll-joints) arg0 arg1)
                     )
                   (matrix*! s2-2 s0-0 s2-2)
                   (matrix*! s2-2 s1-0 s2-2)
                   (matrix-transpose! s0-0 s0-0)
                   (matrix*! s2-2 s0-0 s2-2)
                   )
                 )
               (matrix->axis-angle s3-2 s2-2)
               )
             )
            ((2)
             (set! (-> arg0 scale x) (* (-> arg0 scale x) f30-0))
             (set! (-> arg0 scale y) (* (-> arg0 scale y) f28-0))
             (set! (-> arg0 scale z) (* (-> arg0 scale z) f26-0))
             )
            (else
              (dotimes (s3-3 (-> this child-stack-num))
                (let ((s2-3 (-> this child-stack s3-3))
                      (v1-164 (-> this analog-func))
                      )
                  (cond
                    ((zero? v1-164)
                     (let* ((s2-4 (-> s2-3 pre-tform))
                            (s1-1 (matrix-axis-angle! (new 'stack-no-clear 'matrix) s2-4 (- (-> s2-4 w))))
                            )
                       (let ((t9-55 matrix-rotate-xyz!)
                             (a0-105 (new 'stack-no-clear 'matrix))
                             (a1-72 (new 'stack-no-clear 'vector))
                             )
                         (set! (-> a1-72 x) f30-0)
                         (set! (-> a1-72 y) f28-0)
                         (set! (-> a1-72 z) f26-0)
                         (set! (-> a1-72 w) 1.0)
                         (let ((s0-1 (t9-55 a0-105 a1-72)))
                           (set! sv-848 (new 'stack-no-clear 'matrix))
                           (let ((a2-51 (new 'stack-no-clear 'vector)))
                             (ragdoll-edit-info-method-14
                               this
                               sv-848
                               a2-51
                               (the-as (inline-array ragdoll-joint) (-> this child-stack s3-3))
                               arg0
                               arg1
                               )
                             )
                           (matrix*! s1-1 sv-848 s1-1)
                           (matrix*! s1-1 s0-1 s1-1)
                           )
                         )
                       (matrix-transpose! sv-848 sv-848)
                       (let ((t9-60 matrix*!)
                             (a0-110 s1-1)
                             (a2-54 s1-1)
                             )
                         (t9-60 a0-110 sv-848 a2-54)
                         )
                       (matrix->axis-angle s2-4 s1-1)
                       )
                     )
                    ((= v1-164 1)
                     (let* ((s1-2 (-> s2-3 geo-tform))
                            (s0-2 (matrix-axis-angle! (new 'stack-no-clear 'matrix) s1-2 (- (-> s1-2 w))))
                            )
                       (let ((t9-63 matrix-rotate-xyz!)
                             (a0-114 (new 'stack-no-clear 'matrix))
                             (a1-80 (new 'stack-no-clear 'vector))
                             )
                         (set! (-> a1-80 x) f30-0)
                         (set! (-> a1-80 y) f28-0)
                         (set! (-> a1-80 z) f26-0)
                         (set! (-> a1-80 w) 1.0)
                         (set! sv-864 (t9-63 a0-114 a1-80))
                         )
                       (set! sv-880 (new 'stack-no-clear 'matrix))
                       (let ((a2-56 (new 'stack-no-clear 'vector)))
                         (ragdoll-edit-info-method-14
                           this
                           sv-880
                           a2-56
                           (the-as (inline-array ragdoll-joint) (-> this child-stack s3-3))
                           arg0
                           arg1
                           )
                         )
                       (let ((a2-58 (matrix-axis-angle! (new 'stack-no-clear 'matrix) (-> s2-3 pre-tform) (- (-> s2-3 pre-tform w)))))
                         (matrix*! sv-880 sv-880 a2-58)
                         )
                       (matrix*! s0-2 sv-880 s0-2)
                       (let ((t9-68 matrix*!)
                             (a0-119 s0-2)
                             (a2-60 s0-2)
                             )
                         (t9-68 a0-119 sv-864 a2-60)
                         )
                       (matrix-transpose! sv-880 sv-880)
                       (let ((t9-70 matrix*!)
                             (a0-121 s0-2)
                             (a2-61 s0-2)
                             )
                         (t9-70 a0-121 sv-880 a2-61)
                         )
                       (matrix->axis-angle s1-2 s0-2)
                       )
                     )
                    ((= v1-164 5)
                     (set! (-> s2-3 max-angle) (fmin 65536.0 (fmax 0.0 (+ (-> s2-3 max-angle) f28-0))))
                     )
                    ((= v1-164 3)
                     (set! (-> s2-3 axial-slop) (fmin 65536.0 (fmax 0.0 (+ (-> s2-3 axial-slop) f28-0))))
                     )
                    ((= v1-164 4)
                     (set! (-> s2-3 joint-length) (fmax 40.96 (+ (-> s2-3 joint-length) f28-0)))
                     )
                    ((= v1-164 6)
                     (set! (-> s2-3 coll-rad) (fmax 0.0 (+ (-> s2-3 coll-rad) f28-0)))
                     )
                    ((= v1-164 8)
                     (let ((t9-72 matrix-rotate-xyz!)
                           (a0-128 (new 'stack-no-clear 'matrix))
                           (a1-89 (new 'stack-no-clear 'vector))
                           )
                       (set! (-> a1-89 x) f30-0)
                       (set! (-> a1-89 y) f28-0)
                       (set! (-> a1-89 z) f26-0)
                       (set! (-> a1-89 w) 1.0)
                       (let* ((a1-90 (t9-72 a0-128 a1-89))
                              (a2-62 (matrix->quaternion (new 'stack-no-clear 'quaternion) a1-90))
                              )
                         (quaternion*! (-> s2-3 quat) (-> s2-3 quat) a2-62)
                         )
                       )
                     (quaternion-normalize! (-> s2-3 quat))
                     )
                    (else
                      (format *stdcon* "~%ERROR<GMJ>: bad ragdoll-analog-func~%")
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  (let ((v1-183 (-> this skel-visible)))
    (if (or (zero? v1-183) (= v1-183 4) (= v1-183 1))
        (ragdoll-edit-info-method-15 this)
        )
    )
  (if (or (-> this auto-setup-now) (case (-> this skel-visible)
                                     ((1)
                                      #t
                                      )
                                     )
          )
      (ragdoll-edit-info-method-16 this arg0 arg1)
      )
  (let ((v1-194 (-> this skel-visible)))
    (if (or (= v1-194 3) (= v1-194 4))
        (show-maya-skeleton arg1 -1 #x4499999a)
        )
    )
  0
  (none)
  )
