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

(import "goal_src/jak1/import/evilbro-ag.gc")
(import "goal_src/jak1/import/fishermans-boat-ag.gc")
(import "goal_src/jak1/import/evilsis-ag.gc")

;; definition for symbol *fishermans-boat-constants*, type rigid-body-platform-constants
(define *fishermans-boat-constants* (new 'static 'rigid-body-platform-constants
                                      :drag-factor 2.0
                                      :buoyancy-factor 1.5
                                      :max-buoyancy-depth (meters 1)
                                      :gravity-factor 1.0
                                      :gravity (meters 80)
                                      :player-weight (meters 40)
                                      :player-bonk-factor 1.0
                                      :player-dive-factor 1.0
                                      :player-force-distance (meters 10)
                                      :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 6
                                      :mass 2.0
                                      :inertial-tensor-x (meters 4)
                                      :inertial-tensor-y (meters 10)
                                      :inertial-tensor-z (meters 15)
                                      :cm-joint-y (meters 3)
                                      :cm-joint-z (meters 1)
                                      :idle-distance (meters 50)
                                      :platform #t
                                      :sound-name #f
                                      )
        )

;; definition of type boat-stabilizer
(deftype boat-stabilizer (structure)
  ((local-pos vector :inline :offset-assert   0)
   (normal    vector :inline :offset-assert  16)
   )
  :method-count-assert 9
  :size-assert         #x20
  :flag-assert         #x900000020
  )

;; definition for method 3 of type boat-stabilizer
(defmethod inspect boat-stabilizer ((obj boat-stabilizer))
  (format #t "[~8x] ~A~%" obj 'boat-stabilizer)
  (format #t "~Tlocal-pos: #<vector @ #x~X>~%" (-> obj local-pos))
  (format #t "~Tnormal: #<vector @ #x~X>~%" (-> obj normal))
  obj
  )

;; definition of type vehicle-path
(deftype vehicle-path (structure)
  ((point-array vector 10 :inline :offset-assert   0)
   (point-count int32             :offset-assert 160)
   )
  :method-count-assert 14
  :size-assert         #xa4
  :flag-assert         #xe000000a4
  (:methods
    (get-point-count (_type_) int 9)
    (nth-point (_type_ int vector) vector 10)
    (distance-to-next-point (_type_ int vector) vector 11)
    (add-point! (_type_ float float float float) none 12)
    (debug-draw (_type_) symbol 13)
    )
  )

;; definition for method 3 of type vehicle-path
(defmethod inspect vehicle-path ((obj vehicle-path))
  (format #t "[~8x] ~A~%" obj 'vehicle-path)
  (format #t "~Tpoint-array[10] @ #x~X~%" (-> obj point-array))
  (format #t "~Tpoint-count: ~D~%" (-> obj point-count))
  obj
  )

;; definition for method 9 of type vehicle-path
(defmethod get-point-count vehicle-path ((obj vehicle-path))
  (-> obj point-count)
  )

;; definition for method 10 of type vehicle-path
;; Used lq/sq
(defmethod nth-point vehicle-path ((obj vehicle-path) (arg0 int) (arg1 vector))
  (set! (-> arg1 quad) (-> obj point-array arg0 quad))
  arg1
  )

;; definition for method 11 of type vehicle-path
(defmethod distance-to-next-point vehicle-path ((obj vehicle-path) (arg0 int) (arg1 vector))
  (let ((a2-1 (+ arg0 1)))
    (if (>= a2-1 (-> obj point-count))
        (set! a2-1 0)
        )
    (vector-! arg1 (-> obj point-array a2-1) (-> obj point-array arg0))
    )
  (set! (-> arg1 y) 0.0)
  (vector-normalize! arg1 1.0)
  arg1
  )

;; definition for method 12 of type vehicle-path
;; INFO: Return type mismatch int vs none.
(defmethod add-point! vehicle-path ((obj vehicle-path) (arg0 float) (arg1 float) (arg2 float) (arg3 float))
  (let ((v1-0 (-> obj point-count)))
    (when (< v1-0 10)
      (set-vector! (-> obj point-array v1-0) arg0 arg1 arg2 arg3)
      (+! (-> obj point-count) 1)
      )
    )
  0
  (none)
  )

;; definition for method 13 of type vehicle-path
;; Used lq/sq
(defmethod debug-draw vehicle-path ((obj vehicle-path))
  (local-vars (sv-64 int) (sv-80 (function _varargs_ object)))
  (let ((s5-0 (new 'stack-no-clear 'vector))
        (s4-0 (new 'stack-no-clear 'vector))
        (s3-0 (new 'stack-no-clear 'vector))
        )
    (set! (-> s5-0 y) 0.0)
    (set! (-> s5-0 w) 1.0)
    (dotimes (s2-0 (-> obj point-count))
      (let ((v1-1 (mod (+ s2-0 1) (-> obj point-count))))
        (set! (-> s4-0 quad) (-> obj point-array s2-0 quad))
        (set! (-> s3-0 quad) (-> obj point-array v1-1 quad))
        )
      (let ((f30-0 (-> s4-0 y))
            (f28-0 (-> s4-0 w))
            )
        (set! (-> s5-0 x) (* f30-0 (cos f28-0)))
        (set! (-> s5-0 z) (* f30-0 (sin f28-0)))
        )
      (set! (-> s4-0 y) 0.0)
      (set! (-> s4-0 w) 1.0)
      (set! (-> s3-0 y) 0.0)
      (set! (-> s3-0 w) 1.0)
      (add-debug-line
        #t
        (bucket-id debug-no-zbuf)
        s4-0
        s3-0
        (new 'static 'rgba :r #xff :g #xff :a #x80)
        #f
        (the-as rgba -1)
        )
      (add-debug-vector
        #t
        (bucket-id debug-no-zbuf)
        s4-0
        s5-0
        (meters 0.00024414062)
        (new 'static 'rgba :r #xff :a #x80)
        )
      (let ((s1-0 add-debug-text-3d)
            (s0-0 #t)
            )
        (set! sv-64 68)
        (set! sv-80 format)
        (let ((a0-9 (clear *temp-string*))
              (a1-6 "~D")
              (a2-2 s2-0)
              )
          (sv-80 a0-9 a1-6 a2-2)
          )
        (let ((a2-3 *temp-string*)
              (a3-2 s4-0)
              (t0-2 4)
              (t1-2 #f)
              )
          (s1-0 s0-0 (the-as bucket-id sv-64) a2-3 a3-2 (the-as font-color t0-2) (the-as vector2h t1-2))
          )
        )
      )
    )
  #f
  )

;; definition for symbol *boat-turning-radius-table*, type (pointer float)
(define *boat-turning-radius-table* (new 'static 'array float 32
                                      409600.0
                                      90931.2
                                      94699.52
                                      95600.64
                                      100802.56
                                      97566.72
                                      99246.08
                                      98713.6
                                      95846.4
                                      100474.88
                                      88842.24
                                      105472.0
                                      95436.8
                                      97525.76
                                      102481.92
                                      96501.76
                                      97198.08
                                      93102.08
                                      98631.68
                                      100270.08
                                      96788.48
                                      100884.48
                                      97402.88
                                      98590.72
                                      97280.0
                                      100065.28
                                      104079.36
                                      92610.56
                                      97034.24
                                      88309.76
                                      0.0
                                      0.0
                                      )
        )

;; definition for symbol *boat-throttle-control-table*, type (pointer float)
(define *boat-throttle-control-table* (new 'static 'array float 32
                                        0.0
                                        0.031
                                        0.0646
                                        0.0952
                                        0.1237
                                        0.1508
                                        0.1753
                                        0.2018
                                        0.2231
                                        0.2473
                                        0.2695
                                        0.2904
                                        0.3119
                                        0.3312
                                        0.3514
                                        0.3701
                                        0.3906
                                        0.4148
                                        0.4272
                                        0.4483
                                        0.4686
                                        0.4856
                                        0.5096
                                        0.5203
                                        0.5507
                                        0.5697
                                        0.5856
                                        0.6184
                                        0.6366
                                        0.6694
                                        0.0
                                        0.0
                                        )
        )

;; definition of type vehicle-controller
(deftype vehicle-controller (structure)
  ((path                   vehicle-path            :offset-assert   0)
   (turning-radius-table   (pointer float)         :offset-assert   4)
   (throttle-control-table (pointer float)         :offset-assert   8)
   (table-step             float                   :offset-assert  12)
   (table-length           int32                   :offset-assert  16)
   (circle-radius          float                   :offset-assert  20)
   (throttle               float                   :offset-assert  24)
   (steering               float                   :offset-assert  28)
   (path-dest-index        int8                    :offset-assert  32)
   (left-circle            int8                    :offset-assert  33)
   (path-dest-point        vector          :inline :offset-assert  48)
   (path-dest-velocity     vector          :inline :offset-assert  64)
   (dest-circle            vector          :inline :offset-assert  80)
   (target-point           vector          :inline :offset-assert  96)
   (sample-dir             vector          :inline :offset-assert 112)
   (sample-time            time-frame              :offset-assert 128)
   (sample-index           int32                   :offset-assert 136)
   )
  :method-count-assert 17
  :size-assert         #x8c
  :flag-assert         #x110000008c
  (:methods
    (init! (_type_ vehicle-path (pointer float) (pointer float) int float) none 9)
    (TODO-RENAME-10 (_type_ vector float int) none 10)
    (dummy-11 (_type_) none 11)
    (TODO-RENAME-12 (_type_ int vector) none 12)
    (move-to-next-point (_type_ vector) none 13)
    (TODO-RENAME-14 (_type_ vector vector) none 14)
    (dummy-15 (_type_ collide-shape-moving) none 15)
    (dummy-16 (_type_) none 16)
    )
  )

;; definition for method 3 of type vehicle-controller
(defmethod inspect vehicle-controller ((obj vehicle-controller))
  (format #t "[~8x] ~A~%" obj 'vehicle-controller)
  (format #t "~Tpath: #<vehicle-path @ #x~X>~%" (-> obj path))
  (format #t "~Tturning-radius-table: #x~X~%" (-> obj turning-radius-table))
  (format #t "~Tthrottle-control-table: #x~X~%" (-> obj throttle-control-table))
  (format #t "~Ttable-step: ~f~%" (-> obj table-step))
  (format #t "~Ttable-length: ~D~%" (-> obj table-length))
  (format #t "~Tcircle-radius: ~f~%" (-> obj circle-radius))
  (format #t "~Tthrottle: ~f~%" (-> obj throttle))
  (format #t "~Tsteering: ~f~%" (-> obj steering))
  (format #t "~Tpath-dest-index: ~D~%" (-> obj path-dest-index))
  (format #t "~Tleft-circle: ~D~%" (-> obj left-circle))
  (format #t "~Tpath-dest-point: #<vector @ #x~X>~%" (-> obj path-dest-point))
  (format #t "~Tpath-dest-velocity: #<vector @ #x~X>~%" (-> obj path-dest-velocity))
  (format #t "~Tdest-circle: #<vector @ #x~X>~%" (-> obj dest-circle))
  (format #t "~Ttarget-point: #<vector @ #x~X>~%" (-> obj target-point))
  (format #t "~Tsample-dir: #<vector @ #x~X>~%" (-> obj sample-dir))
  (format #t "~Tsample-time: ~D~%" (-> obj sample-time))
  (format #t "~Tsample-index: ~D~%" (-> obj sample-index))
  obj
  )

;; definition for method 7 of type vehicle-controller
;; INFO: Return type mismatch int vs vehicle-controller.
(defmethod relocate vehicle-controller ((obj vehicle-controller) (arg0 int))
  (if (nonzero? (-> obj path))
      (&+! (-> obj path) arg0)
      )
  (the-as vehicle-controller 0)
  )

;; definition for method 12 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defmethod TODO-RENAME-12 vehicle-controller ((obj vehicle-controller) (arg0 int) (arg1 vector))
  (when (< arg0 (get-point-count (-> obj path)))
    (set! (-> obj path-dest-index) arg0)
    (nth-point (-> obj path) arg0 (-> obj path-dest-point))
    (let ((f30-0 (-> obj path-dest-point y))
          (f28-0 (-> obj path-dest-point w))
          )
      (set! (-> obj path-dest-velocity x) (* f30-0 (cos f28-0)))
      (set! (-> obj path-dest-velocity z) (* f30-0 (sin f28-0)))
      )
    (set! (-> obj path-dest-velocity y) 0.0)
    (set! (-> obj path-dest-velocity w) 1.0)
    (set! (-> obj path-dest-point y) 0.0)
    (set! (-> obj path-dest-point w) 1.0)
    (let ((s5-1 (new 'stack-no-clear 'vector)))
      (let ((s3-0 (new 'stack-no-clear 'vector)))
        (vector-! s3-0 (-> obj path-dest-point) arg1)
        (set! (-> s5-1 quad) (-> obj path-dest-velocity quad))
        (set! (-> s5-1 x) (-> obj path-dest-velocity z))
        (set! (-> s5-1 z) (- (-> obj path-dest-velocity x)))
        (vector-xz-normalize! s5-1 1.0)
        (set! (-> obj left-circle) 1)
        (when (< 0.0 (vector-dot s3-0 s5-1))
          (set! (-> obj left-circle) 0)
          (vector-float*! s5-1 s5-1 -1.0)
          )
        )
      (vector+*! (-> obj dest-circle) (-> obj path-dest-point) s5-1 (-> obj circle-radius))
      )
    (set! (-> obj dest-circle w) (-> obj circle-radius))
    )
  0
  (none)
  )

;; definition for method 13 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
(defmethod move-to-next-point vehicle-controller ((obj vehicle-controller) (arg0 vector))
  (let ((s4-0 (+ (-> obj path-dest-index) 1)))
    (if (>= s4-0 (get-point-count (-> obj path)))
        (set! s4-0 0)
        )
    (TODO-RENAME-12 obj s4-0 arg0)
    )
  0
  (none)
  )

;; definition for method 14 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defmethod TODO-RENAME-14 vehicle-controller ((obj vehicle-controller) (arg0 vector) (arg1 vector))
  (let ((s5-0 (new 'stack-no-clear 'vector))
        (s3-0 (new 'stack-no-clear 'vector))
        )
    (vector-! s5-0 (-> obj dest-circle) arg0)
    (let ((f30-0 (vector-xz-length s5-0))
          (f28-0 (-> obj dest-circle w))
          )
      (if (< f30-0 f28-0)
          (set! f28-0 (* 0.9 f30-0))
          )
      (vector-normalize! s5-0 1.0)
      (set! (-> s3-0 x) (-> s5-0 z))
      (set! (-> s3-0 z) (- (-> s5-0 x)))
      (if (= (-> obj left-circle) 1)
          (vector-float*! s3-0 s3-0 -1.0)
          )
      (let* ((f0-5 f30-0)
             (f0-7 (* f0-5 f0-5))
             (f1-0 f28-0)
             (f0-9 (sqrtf (- f0-7 (* f1-0 f1-0))))
             (f28-1 (/ (* f28-0 f0-9) f30-0))
             )
        (let ((f0-12 (/ (* f0-9 f0-9) f30-0)))
          (set! (-> arg1 quad) (-> arg0 quad))
          (vector+*! arg1 (-> obj target-point) s5-0 f0-12)
          )
        (vector+*! arg1 (-> obj target-point) s3-0 f28-1)
        )
      )
    )
  0
  (none)
  )

;; definition for method 15 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defmethod dummy-15 vehicle-controller ((obj vehicle-controller) (arg0 collide-shape-moving))
  (TODO-RENAME-14 obj (-> arg0 trans) (-> obj target-point))
  (let ((s3-0 (new 'stack-no-clear 'vector))
        (s4-0 (new 'stack-no-clear 'vector))
        )
    (set! (-> s3-0 quad) (-> obj path-dest-velocity quad))
    (vector-xz-normalize! s3-0 1.0)
    (vector-! s4-0 (-> obj path-dest-point) (-> arg0 trans))
    (let ((f30-0 (vector-dot s3-0 s4-0)))
      (if (and (< (vector-xz-length s4-0) (-> obj circle-radius)) (< f30-0 0.0))
          (move-to-next-point obj (-> arg0 trans))
          )
      )
    )
  (let ((s4-2 (max 0 (min
                       (the int (/ (vector-xz-length (-> obj path-dest-velocity)) (-> obj table-step)))
                       (+ (-> obj table-length) -1)
                       )
                   )
              )
        )
    (set! (-> obj throttle) (-> obj throttle-control-table s4-2))
    )
  (let ((s3-1 (new 'stack-no-clear 'vector))
        (s4-3 (new 'stack-no-clear 'vector))
        )
    (vector-z-quaternion! s3-1 (-> arg0 quat))
    (vector-x-quaternion! s4-3 (-> arg0 quat))
    (let* ((v1-16 (-> arg0 trans))
           (f0-9 (- (vector-dot s3-1 (-> obj target-point)) (vector-dot s3-1 v1-16)))
           (f3-0 (- (vector-dot s4-3 (-> obj target-point)) (vector-dot s4-3 v1-16)))
           )
      (set! (-> obj steering) (fmax -1.0 (fmin 1.0 (/ (* 4.0 f3-0) (fmax 4096.0 f0-9)))))
      )
    )
  0
  0
  (none)
  )

;; definition for method 11 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
(defmethod dummy-11 vehicle-controller ((obj vehicle-controller))
  (format #t "(define *turning-radius-table* (new 'static 'inline-array 'float 0~%")
  (dotimes (s5-0 (-> obj table-length))
    (format #t "					     (meters ~4,,2M)~%" (-> obj turning-radius-table s5-0))
    )
  (format #t "					     )~%")
  (format #t "  )~%")
  (format #t "(define *throttle-control-table* (new 'static 'inline-array 'float 0~%")
  (dotimes (s5-1 (-> obj table-length))
    (format #t "				       ~f~%" (-> obj throttle-control-table s5-1))
    )
  (format #t "				       )~%")
  (format #t "  )~%")
  0
  (none)
  )

;; definition for method 10 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defmethod TODO-RENAME-10 vehicle-controller ((obj vehicle-controller) (arg0 vector) (arg1 float) (arg2 int))
  (let ((s3-0 (new 'stack-no-clear 'vector)))
    (set! (-> s3-0 quad) (-> arg0 quad))
    (set! (-> s3-0 y) 0.0)
    (vector-xz-normalize! s3-0 1.0)
    (cond
      ((= arg2 (-> obj sample-index))
       (let* ((f30-0 (* 0.0033333334 (the float (- (-> *display* base-frame-counter) (-> obj sample-time)))))
              (f28-0 (* (-> obj table-step) (the float arg2)))
              (f0-4 (acos-rad (vector-dot s3-0 (-> obj sample-dir))))
              (f26-0 (/ (* f28-0 f30-0) f0-4))
              )
         (when (and (>= arg2 0) (< arg2 (-> obj table-length)))
           (set! (-> obj turning-radius-table arg2) f26-0)
           (set! (-> obj throttle-control-table arg2) arg1)
           (format #t "sample ~d (~M m/s) angle ~f deg, time ~f sec~%" arg2 f28-0 (* 57.29747 f0-4) f30-0)
           (format #t "sample ~d (~M m/s) radius ~M throttle ~f~%" arg2 f28-0 f26-0 arg1)
           )
         )
       )
      (else
        (set! (-> obj sample-index) arg2)
        (set! (-> obj sample-time) (-> *display* base-frame-counter))
        (set! (-> obj sample-dir quad) (-> s3-0 quad))
        )
      )
    )
  0
  (none)
  )

;; definition for method 16 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
(defmethod dummy-16 vehicle-controller ((obj vehicle-controller))
  (debug-draw (-> obj path))
  (add-debug-sphere
    #t
    (bucket-id debug-no-zbuf)
    (-> obj dest-circle)
    (-> obj dest-circle w)
    (new 'static 'rgba :g #xff :a #x80)
    )
  (add-debug-x
    #t
    (bucket-id debug-no-zbuf)
    (-> obj target-point)
    (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80)
    )
  0
  (none)
  )

;; definition for method 9 of type vehicle-controller
;; INFO: Return type mismatch int vs none.
(defmethod init! vehicle-controller ((obj vehicle-controller)
                                   (arg0 vehicle-path)
                                   (arg1 (pointer float))
                                   (arg2 (pointer float))
                                   (arg3 int)
                                   (arg4 float)
                                   )
  (set! (-> obj path) arg0)
  (set! (-> obj turning-radius-table) arg1)
  (set! (-> obj throttle-control-table) arg2)
  (set! (-> obj table-length) arg3)
  (set! (-> obj table-step) arg4)
  (set! (-> obj circle-radius) 102400.0)
  0
  (none)
  )

;; definition of type fishermans-boat
(deftype fishermans-boat (rigid-body-platform)
  ((stabilizer-array        boat-stabilizer    2 :inline :offset-assert 736)
   (engine-thrust-local-pos vector             :inline   :offset-assert 800)
   (ignition                symbol                       :offset-assert 816)
   (engine-thrust           float                        :offset-assert 820)
   (propeller               joint-mod-spinner            :offset-assert 824)
   (dock-point              vector             :inline   :offset-assert 832)
   (dest-dir                vector             :inline   :offset-assert 848)
   (dock-point-index        int8                         :offset-assert 864)
   (auto-pilot              symbol                       :offset-assert 868)
   (anchored                symbol                       :offset-assert 872)
   (waiting-for-player      symbol                       :offset-assert 876)
   (player-riding           symbol                       :offset-assert 880)
   (boat-path               vehicle-path       :inline   :offset-assert 896)
   (cam-tracker             handle                       :offset-assert 1064)
   (kill-player             symbol                       :offset        1076)
   (engine-sound-id         sound-id                     :offset        1080)
   (engine-sound-envelope   float                        :offset        1084)
   (debug-draw              basic                        :offset        1088)
   (debug-path-record       basic                        :offset        1092)
   (debug-path-playback     basic                        :offset        1096)
   (measure-parameters      basic                        :offset        1100)
   (controller              vehicle-controller :inline   :offset        1104)
   (anim                    spool-anim                   :offset        1244)
   (old-target-pos          transformq         :inline   :offset        1248)
   (evilbro                 handle                       :offset        1296)
   (evilsis                 handle                       :offset        1304)
   )
  :heap-base #x4b0
  :method-count-assert 35
  :size-assert         #x520
  :flag-assert         #x2304b00520
  (:states
    fishermans-boat-docked-misty
    fishermans-boat-docked-village
    fishermans-boat-entering-misty
    fishermans-boat-entering-village
    fishermans-boat-leaving-misty
    fishermans-boat-leaving-village
    fishermans-boat-measurements
    fishermans-boat-player-control
    fishermans-boat-ride-to-misty
    fishermans-boat-ride-to-village1
    )
  )

;; definition for method 3 of type fishermans-boat
(defmethod inspect fishermans-boat ((obj fishermans-boat))
  (let ((t9-0 (method-of-type rigid-body-platform inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tstabilizer-array[2] @ #x~X~%" (-> obj stabilizer-array))
  (format #t "~T~Tengine-thrust-local-pos: #<vector @ #x~X>~%" (-> obj engine-thrust-local-pos))
  (format #t "~T~Tignition: ~A~%" (-> obj ignition))
  (format #t "~T~Tengine-thrust: ~f~%" (-> obj engine-thrust))
  (format #t "~T~Tpropeller: ~A~%" (-> obj propeller))
  (format #t "~T~Tdock-point: #<vector @ #x~X>~%" (-> obj dock-point))
  (format #t "~T~Tdest-dir: #<vector @ #x~X>~%" (-> obj dest-dir))
  (format #t "~T~Tdock-point-index: ~D~%" (-> obj dock-point-index))
  (format #t "~T~Tauto-pilot: ~A~%" (-> obj auto-pilot))
  (format #t "~T~Tanchored: ~A~%" (-> obj anchored))
  (format #t "~T~Twaiting-for-player: ~A~%" (-> obj waiting-for-player))
  (format #t "~T~Tplayer-riding: ~A~%" (-> obj player-riding))
  (format #t "~T~Tboat-path: #<vehicle-path @ #x~X>~%" (-> obj boat-path))
  (format #t "~T~Tcam-tracker: ~D~%" (-> obj cam-tracker))
  (format #t "~T~Tplayer-attack-id: ~D~%" (-> obj player-attack-id))
  (format #t "~T~Tkill-player: ~A~%" (-> obj kill-player))
  (format #t "~T~Tengine-sound-id: ~D~%" (-> obj engine-sound-id))
  (format #t "~T~Tengine-sound-envelope: ~f~%" (-> obj engine-sound-envelope))
  (format #t "~T~Tdebug-draw: ~A~%" (-> obj debug-draw))
  (format #t "~T~Tdebug-path-record: ~A~%" (-> obj debug-path-record))
  (format #t "~T~Tdebug-path-playback: ~A~%" (-> obj debug-path-playback))
  (format #t "~T~Tmeasure-parameters: ~A~%" (-> obj measure-parameters))
  (format #t "~T~Tcontroller: #<vehicle-controller @ #x~X>~%" (-> obj controller))
  (format #t "~T~Tanim: ~A~%" (-> obj anim))
  (format #t "~T~Told-target-pos: #<transformq @ #x~X>~%" (-> obj old-target-pos))
  (format #t "~T~Tevilbro: ~D~%" (-> obj evilbro))
  (format #t "~T~Tevilsis: ~D~%" (-> obj evilsis))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *fishermans-boat-sg* fishermans-boat fishermans-boat-lod0-jg fishermans-boat-idle-ja
              ((fishermans-boat-lod0-mg (meters 20)) (fishermans-boat-lod1-mg (meters 999999)))
              :bounds (static-spherem 0 3 0 15)
              :longest-edge (meters 7.3)
              )

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

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

;; definition for method 23 of type fishermans-boat
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defmethod TODO-RENAME-23 fishermans-boat ((obj fishermans-boat) (arg0 float))
  (local-vars (sv-128 int) (sv-144 rigid-body-control-point) (sv-160 int) (sv-176 vector))
  (let ((s4-0 (new 'stack-no-clear 'vector))
        (s1-0 (new 'stack-no-clear 'vector))
        (s5-0 (new 'stack-no-clear 'vector))
        (s0-0 (new 'stack-no-clear 'vector))
        (s2-0 (new 'stack-no-clear 'vector))
        (s3-0 (-> obj rbody matrix))
        )
    (set! (-> s2-0 quad) (-> s3-0 vector 2 quad))
    (set! sv-128 0)
    (while (< sv-128 6)
      (set! sv-144 (-> obj control-point-array data sv-128))
      (vector-matrix*! s5-0 (-> sv-144 local-pos) s3-0)
      (set! (-> sv-144 world-pos quad) (-> s5-0 quad))
      (TODO-RENAME-17 (-> obj rbody) s5-0 s1-0)
      (set! (-> sv-144 velocity quad) (-> s1-0 quad))
      (set! (-> sv-144 world-pos w) (ocean-get-height s5-0))
      (let* ((f0-2 (- (-> sv-144 world-pos w) (-> s5-0 y)))
             (f30-0 (fmin 1.0 (/ f0-2 (-> obj info max-buoyancy-depth))))
             )
        (when (< 0.0 f0-2)
          (vector-float*! s4-0 *y-vector* (* 20.0 f0-2 (-> obj rbody mass)))
          (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
          (vector-float*! s4-0 *y-vector* (* 1.6 f30-0 (fmax 0.0 (vector-dot s2-0 s1-0))))
          (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
          (vector-float*! s4-0 s1-0 (* -1.0 (-> obj info drag-factor) f30-0))
          (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
          (vector-float*!
            s4-0
            (the-as vector (-> s3-0 vector))
            (* -0.5 (vector-dot (the-as vector (-> s3-0 vector)) s1-0))
            )
          (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
          )
        )
      0
      (set! sv-128 (+ sv-128 1))
      )
    (set! sv-160 0)
    (while (< sv-160 2)
      (set! sv-176 (-> obj stabilizer-array sv-160 local-pos))
      (vector-matrix*! s5-0 (the-as vector (&-> sv-176 x)) s3-0)
      (vector-rotate*! s0-0 (&+ sv-176 16) s3-0)
      (TODO-RENAME-17 (-> obj rbody) s5-0 s1-0)
      (vector-float*! s4-0 s0-0 (* -1.0 (vector-dot s0-0 s1-0)))
      (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
      0
      (set! sv-160 (+ sv-160 1))
      )
    (when (-> obj anchored)
      (let ((s1-1 (new 'stack-no-clear 'vector)))
        (vector+*! s5-0 (-> s3-0 vector 3) s2-0 24576.0)
        (vector+*! s1-1 (-> obj dock-point) (-> obj dest-dir) 24576.0)
        (vector-! s4-0 s1-1 s5-0)
        (set! (-> s4-0 y) 0.0)
        (vector-float*! s4-0 s4-0 10.0)
        (if (< 81920.0 (vector-length s4-0))
            (vector-normalize! s4-0 81920.0)
            )
        (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
        (vector+*! s5-0 (-> s3-0 vector 3) s2-0 -24576.0)
        (vector+*! s1-1 (-> obj dock-point) (-> obj dest-dir) -24576.0)
        (vector-! s4-0 s1-1 s5-0)
        )
      (set! (-> s4-0 y) 0.0)
      (vector-float*! s4-0 s4-0 10.0)
      (if (< 81920.0 (vector-length s4-0))
          (vector-normalize! s4-0 81920.0)
          )
      (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
      )
    (when (-> obj ignition)
      (let ((s2-1 (new 'stack-no-clear 'vector)))
        (vector-matrix*! s5-0 (-> obj engine-thrust-local-pos) s3-0)
        (set-vector! s2-1 (- (-> obj controller steering)) 0.0 2.0 1.0)
        (vector-rotate*! s2-1 s2-1 s3-0)
        (vector-normalize! s2-1 1.0)
        (vector-float*! s4-0 s2-1 (-> obj engine-thrust))
        )
      (TODO-RENAME-13 (-> obj rbody) s5-0 s4-0)
      )
    )
  (TODO-RENAME-26 obj)
  (TODO-RENAME-25 obj)
  0
  (none)
  )

;; definition for function fishermans-boat-set-dock-point
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-set-dock-point fishermans-boat ((arg0 int))
  (set! (-> self dock-point-index) arg0)
  (nth-point (-> self boat-path) arg0 (-> self dock-point))
  0
  (none)
  )

;; definition for function fishermans-boat-set-path-point
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-set-path-point fishermans-boat ((arg0 int))
  (TODO-RENAME-12 (-> self controller) arg0 (-> self root-overlay trans))
  (vector-normalize-copy! (-> self dest-dir) (-> self controller path-dest-velocity) 1.0)
  0
  (none)
  )

;; definition for function fishermans-boat-next-path-point
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-next-path-point fishermans-boat ()
  (move-to-next-point (-> self controller) (-> self root-overlay trans))
  (vector-normalize-copy! (-> self dest-dir) (-> self controller path-dest-velocity) 1.0)
  0
  (none)
  )

;; failed to figure out what this is:
(defpart 2896
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xa :page #x2))
    (sp-flt spt-num 0.06)
    (sp-flt spt-x (meters 10))
    (sp-rnd-flt spt-scale-x (meters 1.5) (meters 3) 1.0)
    (sp-flt spt-rot-y (degrees 0.0))
    (sp-rnd-flt spt-scale-y (meters 1.5) (meters 3) 1.0)
    (sp-flt spt-r 128.0)
    (sp-flt spt-g 128.0)
    (sp-flt spt-b 128.0)
    (sp-flt spt-a 0.0)
    (sp-rnd-flt spt-vel-x (meters 0.01) (meters 0.006666667) 1.0)
    (sp-rnd-flt spt-scalevel-x (meters 0.006666667) (meters 0.008666666) 1.0)
    (sp-rnd-flt spt-scalevel-y (meters 0.006666667) (meters 0.008666666) 1.0)
    (sp-flt spt-fade-a 0.7111111)
    (sp-flt spt-friction 0.94)
    (sp-int spt-timer 600)
    (sp-cpuinfo-flags bit2 bit3 left-multiply-quat)
    (sp-int spt-next-time 90)
    (sp-launcher-by-id spt-next-launcher 119)
    (sp-flt spt-rotate-y (degrees 0.0))
    )
  )

;; definition for function fishermans-boat-wave
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defbehavior fishermans-boat-wave fishermans-boat ((arg0 vector) (arg1 float) (arg2 float))
  (let ((gp-0 (new 'stack-no-clear 'vector)))
    (set! (-> gp-0 quad) (-> arg0 quad))
    (set! (-> gp-0 y) (ocean-get-height arg0))
    (set! (-> *part-id-table* 2896 init-specs 4 initial-valuef) (+ 24576.0 arg1))
    (set! (-> *part-id-table* 2896 init-specs 19 initial-valuef) (+ 49152.0 arg1))
    (set! (-> *part-id-table* 2896 init-specs 1 initial-valuef) (* 0.0000036621095 arg2))
    (set! (-> *part-id-table* 2896 init-specs 2 initial-valuef) (* 0.1 arg2))
    (sp-launch-particles-var
      *sp-particle-system-3d*
      (-> *part-id-table* 2896)
      gp-0
      (the-as sparticle-launch-state #f)
      (the-as sparticle-launch-control #f)
      1.0
      )
    )
  0
  (none)
  )

;; definition for function fishermans-boat-spawn-particles
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-spawn-particles fishermans-boat ((arg0 float))
  (let* ((s5-0 (-> self node-list data 3 bone transform))
         (s4-0 (new 'stack-no-clear 'vector))
         (f30-0 (vector-y-angle (-> s5-0 vector 2)))
         )
    (vector-matrix*! s4-0 (new 'static 'vector :z 40960.0 :w 1.0) s5-0)
    (fishermans-boat-wave s4-0 f30-0 arg0)
    (vector-matrix*! s4-0 (new 'static 'vector :x 20480.0 :z -8192.0 :w 1.0) s5-0)
    (fishermans-boat-wave s4-0 f30-0 arg0)
    (vector-matrix*! s4-0 (new 'static 'vector :x -20480.0 :z -8192.0 :w 1.0) s5-0)
    (fishermans-boat-wave s4-0 f30-0 arg0)
    )
  0
  (none)
  )

;; definition for function fishermans-boat-play-sounds
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-play-sounds fishermans-boat ()
  (if (-> self ignition)
      (seek! (-> self engine-sound-envelope) 1.0 (* 2.0 (-> *display* seconds-per-frame)))
      (seek! (-> self engine-sound-envelope) 0.0 (-> *display* seconds-per-frame))
      )
  (cond
    ((< 0.0 (-> self engine-sound-envelope))
     (if (zero? (-> self engine-sound-id))
         (set! (-> self engine-sound-id) (new-sound-id))
         )
     (* 0.0000008138021 (-> self engine-thrust))
     (let ((f30-0 (* 100.0 (-> self engine-sound-envelope)))
           (f28-0 (+ -1.0 (* 2.0 (-> self engine-sound-envelope))))
           (gp-0 (new 'stack-no-clear 'vector))
           )
       (vector<-cspace! gp-0 (-> self node-list data 4))
       (sound-play
         "boat-engine"
         :id (-> self engine-sound-id)
         :vol f30-0
         :pitch f28-0
         :position (the-as symbol gp-0)
         )
       )
     )
    (else
      (when (nonzero? (-> self engine-sound-id))
        (sound-stop (-> self engine-sound-id))
        (set! (-> self engine-sound-id) (new 'static 'sound-id))
        0
        )
      )
    )
  (none)
  )

;; definition for function fishermans-boat-post
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-post fishermans-boat ()
  (when (and *target* (-> self kill-player))
    (set! (-> self kill-player) #f)
    (when (send-event *target* 'attack #f (static-attack-info ((mode 'endlessfall))))
      )
    )
  (when (and *target* (-> self ignition))
    (cond
      ((-> self auto-pilot)
       (dummy-15 (-> self controller) (-> self root-overlay))
       (vector-normalize-copy! (-> self dest-dir) (-> self controller path-dest-velocity) 1.0)
       )
      (else
        (when (not (-> self measure-parameters))
          (let ((f0-0 (analog-input (the-as int (-> *cpad-list* cpads 0 leftx)) 128.0 48.0 110.0 -1.0)))
            (seek! (-> self controller steering) (fmax -1.0 (fmin 1.0 f0-0)) (-> *display* seconds-per-frame))
            )
          (if (cpad-hold? 0 x)
              (seek! (-> self controller throttle) 0.8 (-> *display* seconds-per-frame))
              (seek! (-> self controller throttle) 0.0 (* 0.25 (-> *display* seconds-per-frame)))
              )
          0
          )
        )
      )
    (when (and (-> self player-riding)
               (and (zero? (-> self root-overlay riders num-riders))
                    (or (not *target*)
                        (< 32768.0 (vector-vector-distance (-> self root-overlay trans) (-> *target* control trans)))
                        )
                    )
               )
      (if (process-release? *target*)
          (set! (-> self kill-player) #t)
          )
      (set! (-> self controller throttle) 0.0)
      (set! (-> self controller steering) 0.0)
      )
    )
  (if (-> self ignition)
      (seek! (-> self engine-thrust) (* 1228800.0 (-> self controller throttle)) 6144.0)
      (set! (-> self engine-thrust) 0.0)
      )
  (cond
    ((-> self ignition)
     (let ((f0-20 60.0)
           (f1-4 1820.4445)
           (f2-1 6735.6445)
           (f3-0 1228800.0)
           )
       (set! (-> self propeller spin-rate) (* f0-20 (+ f1-4 (* f2-1 (/ 1.0 f3-0) (-> self engine-thrust)))))
       )
     )
    (else
      (seek! (-> self propeller spin-rate) 0.0 218.45334)
      )
    )
  (TODO-RENAME-28 self)
  (quaternion-copy! (-> self root-overlay quat) (-> self rbody rotation))
  (TODO-RENAME-18 (-> self rbody) (-> self root-overlay trans))
  (when (-> self debug-draw)
    (dummy-16 (-> self controller))
    (add-debug-sphere
      #t
      (bucket-id debug-no-zbuf)
      (the-as vector (-> self boat-path))
      614400.0
      (new 'static 'rgba :b #xff :a #x80)
      )
    (add-debug-sphere
      #t
      (bucket-id debug-no-zbuf)
      (the-as vector (&-> self stack 848))
      409600.0
      (new 'static 'rgba :b #xff :a #x80)
      )
    )
  (fishermans-boat-spawn-particles 8192.0)
  (fishermans-boat-play-sounds)
  (rider-post)
  (none)
  )

;; definition for function fishermans-boat-leave-dock?
(defbehavior fishermans-boat-leave-dock? fishermans-boat ()
  (let ((gp-0 #f))
    (when (and (< (vector-vector-distance (target-pos 0) (-> self rbody position)) 6144.0)
               (or (task-complete? *game-info* (game-task jungle-fishgame)) (and *cheat-mode* (cpad-hold? 0 l3)))
               (not (level-hint-displayed?))
               (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 3))
               (file-status *art-control* (-> self anim name) 0)
               )
      (hide-hud)
      (level-hint-surpress!)
      (kill-current-level-hint '() '(sidekick voicebox) 'exit)
      (when (and (hud-hidden?) (can-grab-display? self) (= *kernel-boot-message* 'play))
        (let ((s5-1
                (new 'stack 'font-context *font-default-matrix* 32 160 0.0 (font-color default) (font-flags shadow kerning))
                )
              )
          (let ((v1-17 s5-1))
            (set! (-> v1-17 width) (the float 440))
            )
          (let ((v1-18 s5-1))
            (set! (-> v1-18 height) (the float 80))
            )
          (set! (-> s5-1 flags) (font-flags shadow kerning large))
          (print-game-text (lookup-text! *common-text* (game-text-id press-to-use) #f) s5-1 #f 128 22)
          )
        (when (and (cpad-pressed? 0 circle) (process-grab? *target*))
          (set! (-> self waiting-for-player) #f)
          (set! (-> self player-riding) #t)
          (set! (-> self auto-pilot) #t)
          (set! (-> self ignition) #t)
          (set! (-> self anchored) #f)
          (set! gp-0 #t)
          )
        )
      )
    gp-0
    )
  )

;; definition for function fishermans-boat-enter-dock?
(defbehavior fishermans-boat-enter-dock? fishermans-boat ()
  (when (and (-> self player-riding) (= (-> self controller path-dest-index) (-> self dock-point-index)))
    (if (process-release? *target*)
        (set! (-> self player-riding) #f)
        )
    )
  (let ((f0-0 (vector-vector-xz-distance (-> self root-overlay trans) (-> self dock-point))))
    (when (and (= (-> self controller path-dest-index) (-> self dock-point-index))
               (not (-> self anchored))
               (< f0-0 81920.0)
               )
      (set! (-> self ignition) #f)
      (set! (-> self anchored) #t)
      )
    (< f0-0 28672.0)
    )
  )

;; failed to figure out what this is:
(defstate fishermans-boat-docked-village (fishermans-boat)
  :event (the-as
    (function process int symbol event-message-block object :behavior fishermans-boat)
    rigid-body-platform-event-handler
    )
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (none)
    )
  :trans (behavior ()
    (if (fishermans-boat-leave-dock?)
        (go fishermans-boat-ride-to-misty)
        )
    (rider-trans)
    (if (nonzero? (-> self anim))
        (spool-push *art-control* (-> self anim name) 0 self -99.0)
        )
    (none)
    )
  :code (behavior ()
    (set! (-> self anim) (new 'static 'spool-anim
                           :name "fishermans-boat-ride-to-misty"
                           :index 15
                           :parts 3
                           :command-list '((0 want-levels village1 misty)
                             (0 shadow target #f)
                             (0 shadow sidekick #f)
                             (250 display-level misty display)
                             (250 display-level village1 special)
                             (250 want-vis mis)
                             (250 want-force-vis misty #t)
                             (459 want-force-vis misty #f)
                             (459 save)
                             (459 blackout 20)
                             (459 shadow target #t)
                             )
                           )
          )
    (fishermans-boat-set-dock-point 0)
    (fishermans-boat-set-path-point 0)
    (anim-loop)
    (none)
    )
  :post fishermans-boat-post
  )

;; failed to figure out what this is:
(defstate fishermans-boat-leaving-village (fishermans-boat)
  :trans (behavior ()
    (when (< 614400.0 (vector-vector-xz-distance (-> self root-overlay trans) (-> self dock-point)))
      (load-state-want-display-level 'village1 'special)
      (load-state-want-display-level 'misty 'display)
      (load-state-want-vis 'mis)
      (load-state-want-force-vis 'misty #t)
      (go fishermans-boat-player-control)
      )
    (rider-trans)
    (none)
    )
  :code (behavior ()
    (load-state-want-levels 'village1 'misty)
    (set! (-> self cam-tracker)
          (ppointer->handle (process-spawn
                              camera-tracker
                              :init camera-tracker-init
                              (lambda :behavior fishermans-boat
                                ()
                                (camera-change-to "camera-282" 0 #f)
                                (while (!= (-> self rbody lin-momentum-damping-factor) 'release)
                                  (suspend)
                                  )
                                (set! (-> self rbody lin-momentum-damping-factor) (the-as float #f))
                                (camera-change-to (the-as string 'base) 0 #f)
                                (none)
                                )
                              :to self
                              )
                            )
          )
    (send-event (handle->process (-> self cam-tracker)) 'border #t)
    (send-event (handle->process (-> self cam-tracker)) 'mask #x20800)
    (fishermans-boat-set-path-point 0)
    (fishermans-boat-next-path-point)
    (loop
      (suspend)
      )
    (none)
    )
  :post fishermans-boat-post
  )

;; failed to figure out what this is:
(defstate fishermans-boat-entering-village (fishermans-boat)
  :trans (behavior ()
    (when (fishermans-boat-enter-dock?)
      (set! (-> self waiting-for-player) #f)
      (when #t
        (set! (-> *camera* cam-entity) (the-as entity #t))
        (send-event *camera* 'clear-entity)
        (load-commands-set! *level* '())
        (load-state-want-display-level 'village1 'display)
        (load-state-want-force-vis 'village1 #f)
        (go fishermans-boat-docked-village)
        )
      )
    (rider-trans)
    (none)
    )
  :code (behavior ()
    (load-state-want-levels 'village1 'beach)
    (load-state-want-vis 'vi1)
    (fishermans-boat-set-dock-point 0)
    (fishermans-boat-set-path-point 5)
    (anim-loop)
    (none)
    )
  :post fishermans-boat-post
  )

;; failed to figure out what this is:
(defstate fishermans-boat-docked-misty (fishermans-boat)
  :event (the-as
    (function process int symbol event-message-block object :behavior fishermans-boat)
    rigid-body-platform-event-handler
    )
  :enter (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (none)
    )
  :trans (behavior ()
    (if (fishermans-boat-leave-dock?)
        (go fishermans-boat-ride-to-village1)
        )
    (rider-trans)
    (if (nonzero? (-> self anim))
        (spool-push *art-control* (-> self anim name) 0 self -99.0)
        )
    (none)
    )
  :code (behavior ()
    (if #t
        (set! (-> self anim) (new 'static 'spool-anim
                               :name "fishermans-boat-ride-to-village1"
                               :index 16
                               :parts 3
                               :command-list '((0 want-levels village1 misty)
                                 (0 shadow target #f)
                                 (0 shadow sidekick #f)
                                 (250 display-level village1 display)
                                 (250 display-level misty #f)
                                 (250 want-vis vi1)
                                 (250 want-force-vis village1 #t)
                                 (459 want-force-vis village1 #f)
                                 (459 save)
                                 (459 blackout 20)
                                 (459 shadow target #t)
                                 )
                               )
              )
        (set! (-> self anim) (new 'static 'spool-anim
                               :name "fishermans-boat-ride-to-village1-alt"
                               :index 17
                               :parts 12
                               :command-list '((0 want-levels village1 misty)
                                 (105 want-levels village1 intro)
                                 (150 display-level intro display)
                                 (150 want-vis int)
                                 (150 kill "med-res-level-3")
                                 (150 want-force-vis intro #t)
                                 (151 send-event self evilbro)
                                 (1199 send-event self evilsis)
                                 (1200 want-force-vis intro #f)
                                 (1200 want-levels village1 beach)
                                 (1200 display-level village1 display)
                                 (1200 want-vis vi1)
                                 (1200 want-force-vis village1 #t)
                                 (1349 want-force-vis village1 #f)
                                 (1349 save)
                                 (1349 blackout 20)
                                 )
                               )
              )
        )
    (load-state-want-force-vis 'misty #f)
    (fishermans-boat-set-dock-point 4)
    (fishermans-boat-set-path-point 4)
    (anim-loop)
    (none)
    )
  :post fishermans-boat-post
  )

;; failed to figure out what this is:
(defstate fishermans-boat-leaving-misty (fishermans-boat)
  :trans (behavior ()
    (when (< 409600.0 (vector-vector-xz-distance (-> self root-overlay trans) (-> self dock-point)))
      (load-state-want-force-vis 'village1 #t)
      (load-state-want-display-level 'village1 'display)
      (set-continue! *game-info* "village1-hut")
      (load-commands-set! *level* (load-command-get-index *level* 'village1 2))
      (go fishermans-boat-player-control)
      )
    (rider-trans)
    (none)
    )
  :code (behavior ()
    (set! (-> self cam-tracker)
          (ppointer->handle (process-spawn
                              camera-tracker
                              :init camera-tracker-init
                              (lambda :behavior fishermans-boat
                                ()
                                (camera-change-to "camera-287" 0 #f)
                                (while (!= (-> self rbody lin-momentum-damping-factor) 'release)
                                  (suspend)
                                  )
                                (set! (-> self rbody lin-momentum-damping-factor) (the-as float #f))
                                (camera-change-to (the-as string 'base) 0 #f)
                                (none)
                                )
                              :to self
                              )
                            )
          )
    (send-event (handle->process (-> self cam-tracker)) 'border #t)
    (send-event (handle->process (-> self cam-tracker)) 'mask #x20800)
    (fishermans-boat-set-path-point 4)
    (fishermans-boat-next-path-point)
    (loop
      (suspend)
      )
    (none)
    )
  :post fishermans-boat-post
  )

;; failed to figure out what this is:
(defstate fishermans-boat-entering-misty (fishermans-boat)
  :trans (behavior ()
    (when (fishermans-boat-enter-dock?)
      (set! (-> self waiting-for-player) #f)
      (level-hint-spawn (game-text-id sidekick-misty) "sksp0060" (the-as entity #f) *entity-pool* (game-task none))
      (when #t
        (set! (-> *camera* cam-entity) (the-as entity #t))
        (send-event *camera* 'clear-entity)
        (go fishermans-boat-docked-misty)
        )
      )
    (rider-trans)
    (none)
    )
  :code (behavior ()
    (set-continue! *game-info* "misty-start")
    (fishermans-boat-set-dock-point 4)
    (fishermans-boat-set-path-point 2)
    (loop
      (suspend)
      )
    (none)
    )
  :post fishermans-boat-post
  )

;; failed to figure out what this is:
(defstate fishermans-boat-player-control (fishermans-boat)
  :exit (behavior ()
    (send-event *camera* 'change-state *camera-base-mode* 0)
    (set! (-> self auto-pilot) #t)
    (none)
    )
  :trans (behavior ()
    (let ((gp-0 (new 'stack-no-clear 'vector)))
      (nth-point (-> self boat-path) 0 gp-0)
      (if (< (vector-vector-xz-distance (-> self root-overlay trans) gp-0) 614400.0)
          (go fishermans-boat-entering-village)
          )
      (nth-point (-> self boat-path) 4 gp-0)
      (if (< (vector-vector-xz-distance (-> self root-overlay trans) gp-0) 409600.0)
          (go fishermans-boat-entering-misty)
          )
      )
    0
    (none)
    )
  :code (behavior ()
    (send-event (handle->process (-> self cam-tracker)) 'message 'release)
    (suspend)
    (send-event *camera* 'change-state cam-stick 0)
    (loop
      (if (and (= *cheat-mode* 'debug) (cpad-pressed? 0 triangle))
          (set! (-> self auto-pilot) #f)
          )
      (suspend)
      )
    (none)
    )
  :post fishermans-boat-post
  )

;; definition for function fishermans-boat-set-throttle-by-speed
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-set-throttle-by-speed fishermans-boat ((arg0 float))
  (let* ((f0-0 (vector-xz-length (-> self rbody lin-velocity)))
         (f1-2 (/ (- arg0 f0-0) arg0))
         (f30-0 (* 0.005 f1-2))
         )
    (format *stdcon* "current ~M target ~M throttle ~f~%" f0-0 arg0 (-> self controller throttle))
    (set! (-> self controller throttle) (fmax 0.0 (fmin 1.0 (+ (-> self controller throttle) f30-0))))
    )
  0
  (none)
  )

;; failed to figure out what this is:
(defstate fishermans-boat-measurements (fishermans-boat)
  :exit (behavior ()
    (set! (-> self measure-parameters) #f)
    (none)
    )
  :trans (behavior ()
    (if (cpad-pressed? 1 square)
        (go fishermans-boat-player-control)
        )
    (none)
    )
  :code (behavior ()
    (set! (-> self auto-pilot) #f)
    (let ((gp-0 (new 'stack-no-clear 'vector))
          (s5-0 1)
          (s4-0 (+ (-> self controller table-length) -1))
          )
      (while (>= s4-0 s5-0)
        (let ((f30-0 (* (the float s5-0) (-> self controller table-step))))
          (set! (-> self measure-parameters) #t)
          (set! (-> self controller steering) 1.0)
          (set! (-> self state-time) (-> *display* base-frame-counter))
          (until (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 1))
            (let ((f0-6 (/ (fabs (- f30-0 (vector-xz-length (-> self rbody lin-velocity)))) f30-0)))
              (if (< 0.05 f0-6)
                  (set! (-> self state-time) (-> *display* base-frame-counter))
                  )
              )
            (fishermans-boat-set-throttle-by-speed f30-0)
            (suspend)
            )
          (vector-z-quaternion! gp-0 (-> self root-overlay quat))
          (TODO-RENAME-10 (-> self controller) gp-0 (-> self controller throttle) s5-0)
          (let ((s3-0 (-> *display* base-frame-counter)))
            (until (>= (- (-> *display* base-frame-counter) s3-0) (seconds 1))
              (fishermans-boat-set-throttle-by-speed f30-0)
              (suspend)
              (suspend)
              )
            )
          )
        (vector-z-quaternion! gp-0 (-> self root-overlay quat))
        (TODO-RENAME-10 (-> self controller) gp-0 (-> self controller throttle) s5-0)
        (+! s5-0 1)
        )
      )
    (go fishermans-boat-player-control)
    (none)
    )
  :post fishermans-boat-post
  )

;; definition for method 7 of type fishermans-boat
;; INFO: Return type mismatch rigid-body-platform vs fishermans-boat.
(defmethod relocate fishermans-boat ((obj fishermans-boat) (arg0 int))
  (relocate (-> obj controller) arg0)
  (if (nonzero? (-> obj propeller))
      (&+! (-> obj propeller) arg0)
      )
  (the-as
    fishermans-boat
    ((the-as (function rigid-body-platform int rigid-body-platform) (find-parent-method fishermans-boat 7))
     obj
     arg0
     )
    )
  )

;; definition for method 30 of type fishermans-boat
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-30 fishermans-boat ((obj fishermans-boat))
  (let ((s5-0 (new 'process 'collide-shape-moving obj (collide-list-enum hit-by-others))))
    (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-group s5-0 (the-as uint 1) 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-vector! (-> s4-0 local-sphere) 0.0 8192.0 0.0 61440.0)
      (set-root-prim! s5-0 s4-0)
      (let ((s3-0 (new 'process 'collide-shape-prim-mesh s5-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 8192.0 0.0 61440.0)
        (append-prim s4-0 s3-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 method 31 of type fishermans-boat
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defmethod TODO-RENAME-31 fishermans-boat ((obj fishermans-boat))
  (initialize-skeleton obj *fishermans-boat-sg* '())
  (logclear! (-> obj mask) (process-mask actor-pause movie))
  (logior! (-> obj skel status) (janim-status inited))
  (process-entity-status! obj (entity-perm-status bit-3) #t)
  (process-entity-status! obj (entity-perm-status bit-7) #t)
  (set! (-> obj path) (new 'process 'path-control obj 'path 0.0))
  (logior! (-> obj path flags) (path-control-flag display draw-line draw-point draw-text))
  (set! (-> obj boat-path point-count) 0)
  (add-point! (-> obj boat-path) -88473.6 28672.0 425984.0 16384.0)
  (add-point! (-> obj boat-path) 18432.0 69632.0 1014169.6 14563.556)
  (add-point! (-> obj boat-path) 292864.0 122880.0 2875801.5 18204.445)
  (add-point! (-> obj boat-path) 167936.0 40960.0 3069952.0 32768.0)
  (add-point! (-> obj boat-path) 49971.2 28672.0 2924544.0 -16384.0)
  (add-point! (-> obj boat-path) 175718.4 122880.0 626688.0 -18204.445)
  (add-point! (-> obj boat-path) 50790.4 40960.0 197427.2 32768.0)
  (init!
    (-> obj controller)
    (-> obj boat-path)
    *boat-turning-radius-table*
    *boat-throttle-control-table*
    30
    4096.0
    )
  (set! (-> obj propeller) (new 'process 'joint-mod-spinner obj 4 (new 'static 'vector :z -1.0 :w 1.0) 0.0))
  (set! (-> obj ignition) #f)
  (set! (-> obj anchored) #t)
  (set! (-> obj player-riding) #f)
  (set! (-> obj kill-player) #f)
  (set! (-> obj debug-draw) #f)
  (set! (-> obj cam-tracker) (the-as handle #f))
  (set! (-> obj auto-pilot) #f)
  (if (= (-> *game-info* current-continue level) 'misty)
      (fishermans-boat-set-dock-point 4)
      (fishermans-boat-set-dock-point 0)
      )
  (fishermans-boat-set-path-point (-> obj dock-point-index))
  (fishermans-boat-next-path-point)
  (set! (-> obj root-overlay trans quad) (-> obj dock-point quad))
  (set! (-> obj root-overlay trans y) 0.0)
  (forward-up-nopitch->quaternion (-> obj root-overlay quat) (-> obj dest-dir) *up-vector*)
  (TODO-RENAME-29 obj *fishermans-boat-constants*)
  (let ((v1-39 (-> obj control-point-array data)))
    (set! (-> v1-39 0 local-pos x) 0.0)
    (set! (-> v1-39 0 local-pos y) 0.0)
    (set! (-> v1-39 0 local-pos z) 24576.0)
    (set! (-> v1-39 0 local-pos w) 1.0)
    )
  (let ((v1-41 (-> obj control-point-array data 1)))
    (set! (-> v1-41 local-pos x) 22528.0)
    (set! (-> v1-41 local-pos y) 0.0)
    (set! (-> v1-41 local-pos z) -20480.0)
    (set! (-> v1-41 local-pos w) 1.0)
    )
  (let ((v1-43 (-> obj control-point-array data 2)))
    (set! (-> v1-43 local-pos x) -22528.0)
    (set! (-> v1-43 local-pos y) 0.0)
    (set! (-> v1-43 local-pos z) -20480.0)
    (set! (-> v1-43 local-pos w) 1.0)
    )
  (let ((v1-45 (-> obj control-point-array data 3)))
    (set! (-> v1-45 local-pos x) 0.0)
    (set! (-> v1-45 local-pos y) 0.0)
    (set! (-> v1-45 local-pos z) 49152.0)
    (set! (-> v1-45 local-pos w) 1.0)
    )
  (let ((v1-47 (-> obj control-point-array data 4)))
    (set! (-> v1-47 local-pos x) 22528.0)
    (set! (-> v1-47 local-pos y) 0.0)
    (set! (-> v1-47 local-pos z) 12288.0)
    (set! (-> v1-47 local-pos w) 1.0)
    )
  (let ((v1-49 (-> obj control-point-array data 5)))
    (set! (-> v1-49 local-pos x) -22528.0)
    (set! (-> v1-49 local-pos y) 0.0)
    (set! (-> v1-49 local-pos z) 12288.0)
    (set! (-> v1-49 local-pos w) 1.0)
    )
  (let ((v1-50 (-> obj stabilizer-array)))
    (set! (-> v1-50 0 local-pos x) 16384.0)
    (set! (-> v1-50 0 local-pos y) 20480.0)
    (set! (-> v1-50 0 local-pos z) -32768.0)
    (set! (-> v1-50 0 local-pos w) 1.0)
    )
  (set-vector! (-> obj stabilizer-array 1 local-pos) -16384.0 20480.0 -32768.0 1.0)
  (set-vector! (-> obj stabilizer-array 0 normal) 0.0 0.75 0.2 1.0)
  (set-vector! (-> obj stabilizer-array 1 normal) 0.0 0.75 0.2 1.0)
  (set-vector! (-> obj engine-thrust-local-pos) 0.0 12288.0 -20480.0 1.0)
  (set! (-> obj root-overlay nav-radius) 53248.0)
  (nav-mesh-connect obj (-> obj root-overlay) (the-as nav-control #f))
  (set! (-> obj engine-sound-id) (new 'static 'sound-id))
  (set! (-> obj debug-path-record) #f)
  (set! (-> obj debug-path-playback) #f)
  (set! (-> obj measure-parameters) #f)
  (set! (-> obj draw origin-joint-index) (the-as uint 3))
  (let ((a0-29 (-> obj entity)))
    (if (when a0-29
          (let ((a0-30 (-> a0-29 extra perm task)))
            (if a0-30
                (= a0-30 (game-task none))
                )
            )
          )
        (set! (-> obj entity extra perm task) (game-task complete))
        )
    )
  (none)
  )

;; definition for method 11 of type fishermans-boat
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! fishermans-boat ((obj fishermans-boat) (arg0 entity-actor))
  (stack-size-set! (-> obj main-thread) 512)
  (set! (-> obj mask) (logior (process-mask platform) (-> obj mask)))
  (TODO-RENAME-30 obj)
  (process-drawable-from-entity! obj arg0)
  (TODO-RENAME-31 obj)
  (if (= (-> *game-info* current-continue level) 'misty)
      (go fishermans-boat-docked-misty)
      (go fishermans-boat-docked-village)
      )
  (none)
  )

;; definition for function fishermans-boat-reset-physics
;; INFO: Return type mismatch int vs none.
(defbehavior fishermans-boat-reset-physics fishermans-boat ()
  (TODO-RENAME-22
    (-> self rbody)
    (-> self root-overlay trans)
    (-> self root-overlay quat)
    (-> self info linear-damping)
    (-> self info angular-damping)
    )
  (vector-reset! (-> self player-force))
  (set! (-> self player-impulse) #f)
  (set! (-> self player-contact) #f)
  0
  (none)
  )

;; failed to figure out what this is:
(defstate fishermans-boat-ride-to-misty (fishermans-boat)
  :code (behavior ()
    (set! (-> self propeller enable) #f)
    (quaternion-identity! (-> self root-overlay quat))
    (set! (-> self root-overlay trans quad) (-> self entity extra trans quad))
    (set! (-> self player-riding) #f)
    (set! (-> self auto-pilot) #f)
    (when (send-event *target* 'clone-anim self)
      (send-event (ppointer->process (-> *target* sidekick)) 'matrix 'play-anim)
      (send-event *target* 'blend-shape #t)
      (let ((v1-20 (process-spawn othercam self 5 #f #t :to self)))
        (send-event (ppointer->process v1-20) 'mask 2048)
        )
      (set! (-> self draw force-lod) 0)
      (ja-play-spooled-anim
        (-> self anim)
        (the-as art-joint-anim fishermans-boat-idle-ja)
        (the-as art-joint-anim #f)
        (the-as (function process-drawable symbol) false-func)
        )
      (set! (-> self draw force-lod) -1)
      (send-event *target* 'blend-shape #f)
      (ja-channel-set! 1)
      (ja :group! fishermans-boat-idle-ja)
      (vector<-cspace! (-> self root-overlay trans) (-> self node-list data 3))
      (matrix->quaternion (-> self root-overlay quat) (-> self node-list data 3 bone transform))
      (fishermans-boat-reset-physics)
      (transform-post)
      (when *target*
        (vector<-cspace! (the-as vector (-> self old-target-pos)) (-> *target* node-list data 3))
        (send-event *target* 'trans 'restore (-> self old-target-pos))
        (send-event *target* 'end-mode)
        (update-transforms! (-> self root-overlay))
        (move-to-ground (-> *target* control) 4096.0 40960.0 #t (-> *target* control root-prim collide-with))
        (logior! (-> *target* control status) (cshape-moving-flags onsurf onground tsurf))
        (suspend)
        (send-event *camera* 'teleport-to-other-start-string)
        )
      (set-continue! *game-info* "misty-start")
      )
    (set! (-> self waiting-for-player) #t)
    (set! (-> self ignition) #f)
    (set! (-> self anchored) #t)
    (set! (-> self propeller enable) #t)
    (fishermans-boat-play-sounds)
    (apply-settings *setting-control*)
    (process-spawn-function
      process
      (lambda :behavior fishermans-boat
        ()
        (let ((gp-0 (-> *display* base-frame-counter)))
          (until (>= (- (-> *display* base-frame-counter) gp-0) (seconds 1))
            (suspend)
            )
          )
        (while (or (-> *setting-control* current ambient)
                   (-> *setting-control* current hint)
                   (-> *setting-control* current movie)
                   )
          (suspend)
          )
        (suspend)
        (level-hint-spawn (game-text-id sidekick-misty) "sksp0060" (the-as entity #f) *entity-pool* (game-task none))
        (none)
        )
      :to self
      )
    (go fishermans-boat-docked-misty)
    (none)
    )
  :post (behavior ()
    (ja-post)
    (fishermans-boat-spawn-particles 81920.0)
    (fishermans-boat-play-sounds)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate fishermans-boat-ride-to-village1 (fishermans-boat)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as
        object
        (cond
          ((= v1-0 'evilbro)
           (when (= (level-status *level* 'intro) 'active)
             (let ((gp-1 (entity-by-name "evilbro-2")))
               (when gp-1
                 (set! (-> self evilbro)
                       (ppointer->handle (manipy-spawn (-> self root-overlay trans) gp-1 *fb-evilbro-sg* #f :to self))
                       )
                 (send-event (handle->process (-> self evilbro)) 'anim-mode 'clone-anim)
                 (send-event (handle->process (-> self evilbro)) 'blend-shape #t)
                 (send-event (handle->process (-> self evilbro)) 'center-joint 3)
                 )
               )
             (let ((gp-2 (entity-by-name "evilsis-2")))
               (when gp-2
                 (set! (-> self evilsis)
                       (ppointer->handle (manipy-spawn (-> self root-overlay trans) gp-2 *fb-evilsis-sg* #f :to self))
                       )
                 (send-event (handle->process (-> self evilsis)) 'anim-mode 'clone-anim)
                 (send-event (handle->process (-> self evilsis)) 'blend-shape #t)
                 (send-event (handle->process (-> self evilsis)) 'center-joint 3)
                 )
               )
             )
           )
          ((= v1-0 'evilsis)
           (let ((a0-44 (handle->process (-> self evilbro))))
             (if a0-44
                 (deactivate a0-44)
                 )
             )
           (let ((a0-48 (handle->process (-> self evilsis))))
             (if a0-48
                 (deactivate a0-48)
                 )
             )
           )
          )
        )
      )
    )
  :code (behavior ()
    (set! (-> self propeller enable) #f)
    (set! (-> self evilbro) (the-as handle #f))
    (set! (-> self evilsis) (the-as handle #f))
    (quaternion-identity! (-> self root-overlay quat))
    (set! (-> self root-overlay trans quad) (-> self entity extra trans quad))
    (set! (-> self player-riding) #f)
    (set! (-> self auto-pilot) #f)
    (when (send-event *target* 'clone-anim self)
      (send-event (ppointer->process (-> *target* sidekick)) 'matrix 'play-anim)
      (send-event *target* 'blend-shape #t)
      (let ((v1-20 (process-spawn othercam self 5 #f #t :to self)))
        (send-event (ppointer->process v1-20) 'mask 2048)
        )
      (set! (-> self draw force-lod) 0)
      (ja-play-spooled-anim
        (-> self anim)
        (the-as art-joint-anim fishermans-boat-idle-ja)
        (the-as art-joint-anim #f)
        (the-as (function process-drawable symbol) false-func)
        )
      (set! (-> self draw force-lod) -1)
      (send-event *target* 'blend-shape #f)
      (ja-channel-set! 1)
      (ja :group! fishermans-boat-idle-ja)
      (vector<-cspace! (-> self root-overlay trans) (-> self node-list data 3))
      (matrix->quaternion (-> self root-overlay quat) (-> self node-list data 3 bone transform))
      (fishermans-boat-reset-physics)
      (transform-post)
      (when *target*
        (vector<-cspace! (the-as vector (-> self old-target-pos)) (-> *target* node-list data 3))
        (send-event *target* 'trans 'restore (-> self old-target-pos))
        (send-event *target* 'end-mode)
        (update-transforms! (-> self root-overlay))
        (move-to-ground (-> *target* control) 4096.0 40960.0 #t (-> *target* control root-prim collide-with))
        (logior! (-> *target* control status) (cshape-moving-flags onsurf onground tsurf))
        (suspend)
        (send-event *camera* 'teleport-to-other-start-string)
        )
      (set-continue! *game-info* "village1-hut")
      )
    (set! (-> self waiting-for-player) #t)
    (set! (-> self ignition) #f)
    (set! (-> self anchored) #t)
    (set! (-> self propeller enable) #t)
    (fishermans-boat-play-sounds)
    (process-entity-status! self (entity-perm-status complete) #t)
    (go fishermans-boat-docked-village)
    (none)
    )
  :post (behavior ()
    (ja-post)
    (fishermans-boat-spawn-particles 81920.0)
    (fishermans-boat-play-sounds)
    (none)
    )
  )
