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

(import "goal_src/jak1/import/rollingcam-ag.gc")
(import "goal_src/jak1/import/pusher-ag.gc")
(import "goal_src/jak1/import/happy-plant-ag.gc")
(import "goal_src/jak1/import/dark-plant-ag.gc")
(import "goal_src/jak1/import/rolling-start-ag.gc")

;; definition of type rolling-part
(deftype rolling-part (part-spawner)
  ((root-override basic  :offset 112)
   )
  :heap-base #x60
  :method-count-assert 21
  :size-assert         #xd0
  :flag-assert         #x15006000d0
  )

;; definition for method 3 of type rolling-part
(defmethod inspect rolling-part ((obj rolling-part))
  (let ((t9-0 (method-of-type part-spawner inspect)))
    (t9-0 obj)
    )
  obj
  )

;; definition of type rollingcam
(deftype rollingcam (process-hidden)
  ()
  :method-count-assert 15
  :size-assert         #x70
  :flag-assert         #xf00000070
  )

;; definition for method 3 of type rollingcam
(defmethod inspect rollingcam ((obj rollingcam))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tname: ~A~%" (-> obj name))
  (format #t "~Tmask: ~D~%" (-> obj mask))
  (format #t "~Tparent: #x~X~%" (-> obj parent))
  (format #t "~Tbrother: #x~X~%" (-> obj brother))
  (format #t "~Tchild: #x~X~%" (-> obj child))
  (format #t "~Tppointer: #x~X~%" (-> obj ppointer))
  (format #t "~Tself: ~A~%" (-> obj self))
  (format #t "~Tpool: ~A~%" (-> obj pool))
  (format #t "~Tstatus: ~A~%" (-> obj status))
  (format #t "~Tpid: ~D~%" (-> obj pid))
  (format #t "~Tmain-thread: ~A~%" (-> obj main-thread))
  (format #t "~Ttop-thread: ~A~%" (-> obj top-thread))
  (format #t "~Tentity: ~A~%" (-> obj entity))
  (format #t "~Tstate: ~A~%" (-> obj state))
  (format #t "~Ttrans-hook: ~A~%" (-> obj trans-hook))
  (format #t "~Tpost-hook: ~A~%" (-> obj post-hook))
  (format #t "~Tevent-hook: ~A~%" (-> obj event-hook))
  (format #t "~Tallocated-length: ~D~%" (-> obj allocated-length))
  (format #t "~Tnext-state: ~A~%" (-> obj next-state))
  (format #t "~Theap-base: #x~X~%" (-> obj heap-base))
  (format #t "~Theap-top: #x~X~%" (-> obj heap-top))
  (format #t "~Theap-cur: #x~X~%" (-> obj heap-cur))
  (format #t "~Tstack-frame-top: ~A~%" (-> obj stack-frame-top))
  (format #t "~Theap: #<kheap @ #x~X>~%" (&-> obj heap-base))
  (format #t "~Tconnection-list: ~`'connectable`P~%" (-> obj connection-list))
  (format #t "~Tstack[0] @ #x~X~%" (-> obj stack))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *rollingcam-sg* rollingcam rollingcam-lod0-jg rollingcam-anim-ja
              ((rollingcam-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 30)
              )

;; definition of type pusher-base
(deftype pusher-base (process-drawable)
  ((root-override collide-shape-moving  :offset        112)
   (max-frame     float                 :offset-assert 176)
   )
  :heap-base #x50
  :method-count-assert 20
  :size-assert         #xb4
  :flag-assert         #x14005000b4
  )

;; definition for method 3 of type pusher-base
(defmethod inspect pusher-base ((obj pusher-base))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tmax-frame: ~f~%" (-> obj max-frame))
  obj
  )

;; definition of type pusher
(deftype pusher (pusher-base)
  ((sync sync-info-paused :inline :offset-assert 180)
   (cyl  cylinder         :inline :offset-assert 208)
   )
  :heap-base #x90
  :method-count-assert 20
  :size-assert         #xf8
  :flag-assert         #x14009000f8
  (:states
    pusher-idle
    )
  )

;; definition for method 3 of type pusher
(defmethod inspect pusher ((obj pusher))
  (let ((t9-0 (method-of-type pusher-base inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tsync: #<sync-info-paused @ #x~X>~%" (-> obj sync))
  (format #t "~T~Tcyl: #<cylinder @ #x~X>~%" (-> obj cyl))
  obj
  )

;; definition of type gorge-pusher
(deftype gorge-pusher (pusher-base)
  ((min-frame float  :offset-assert 180)
   )
  :heap-base #x50
  :method-count-assert 20
  :size-assert         #xb8
  :flag-assert         #x14005000b8
  (:states
    gorge-pusher-idle
    )
  )

;; definition for method 3 of type gorge-pusher
(defmethod inspect gorge-pusher ((obj gorge-pusher))
  (let ((t9-0 (method-of-type pusher-base inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tmin-frame: ~f~%" (-> obj min-frame))
  obj
  )

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

;; definition for function pusher-base-init
(defbehavior pusher-base-init pusher-base ()
  (set! (-> self mask) (logior (process-mask enemy platform) (-> self mask)))
  (let ((gp-0 (new 'process 'collide-shape-moving self (collide-list-enum hit-by-others))))
    (set! (-> gp-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> gp-0 reaction) default-collision-reaction)
    (set! (-> gp-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (let ((s5-0 (new 'process 'collide-shape-prim-group gp-0 (the-as uint 1) 0)))
      (set! (-> s5-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s5-0 collide-with) (collide-kind target))
      (set! (-> s5-0 prim-core action) (collide-action solid ca-1))
      (set! (-> s5-0 transform-index) 0)
      (set-vector! (-> s5-0 local-sphere) -8192.0 0.0 0.0 40960.0)
      (set-root-prim! gp-0 s5-0)
      (let ((s4-0 (new 'process 'collide-shape-prim-mesh gp-0 (the-as uint 0) (the-as uint 0))))
        (set! (-> s4-0 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s4-0 collide-with) (collide-kind target))
        (set! (-> s4-0 prim-core action) (collide-action solid ca-1))
        (set! (-> s4-0 prim-core offense) (collide-offense indestructible))
        (set! (-> s4-0 transform-index) 4)
        (set-vector! (-> s4-0 local-sphere) 8192.0 0.0 0.0 28672.0)
        (append-prim s5-0 s4-0)
        )
      )
    (set! (-> gp-0 nav-radius) (* 0.75 (-> gp-0 root-prim local-sphere w)))
    (backup-collide-with-as gp-0)
    (set! (-> self root-override) gp-0)
    gp-0
    )
  )

;; failed to figure out what this is:
(defstate pusher-idle (pusher)
  :trans (the-as (function none :behavior pusher) rider-trans)
  :code (behavior ()
    (loop
      (let ((f0-0 -1.0))
        (when (and *target* *camera*)
          (let ((gp-0 (new 'stack-no-clear 'vector)))
            (vector-! gp-0 (target-pos 0) (camera-pos))
            (set! f0-0 (ray-capsule-intersect (-> self cyl) (camera-pos) gp-0))
            )
          )
        (if (< f0-0 0.0)
            (ja :num! (seek! (get-current-value-with-mirror (-> self sync) (-> self max-frame))))
            (ja :num! (seek! 0.0))
            )
        )
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior pusher) rider-post)
  )

;; definition for method 11 of type pusher
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! pusher ((obj pusher) (arg0 entity-actor))
  (pusher-base-init)
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *pusher-sg* '())
  (load-params! (-> obj sync) obj (the-as uint 1500) 0.0 0.15 0.15)
  (set! (-> obj max-frame) (res-lump-float arg0 'max-frame :default (the float (ja-num-frames 0))))
  (set! (-> obj cyl origin quad) (-> obj root-override trans quad))
  (vector-x-quaternion! (-> obj cyl axis) (-> obj root-override quat))
  (vector-negate! (-> obj cyl axis) (-> obj cyl axis))
  (set! (-> obj cyl length) 36864.0)
  (set! (-> obj cyl radius) 20480.0)
  (go pusher-idle)
  (none)
  )

;; failed to figure out what this is:
(defstate gorge-pusher-idle (gorge-pusher)
  :trans (the-as (function none :behavior gorge-pusher) rider-trans)
  :code (behavior ()
    (loop
      (if (task-closed? (game-task rolling-race) (task-status need-introduction))
          (ja :num! (seek! (-> self min-frame)))
          (ja :num! (seek! (-> self max-frame)))
          )
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior gorge-pusher) rider-post)
  )

;; definition for method 11 of type gorge-pusher
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! gorge-pusher ((obj gorge-pusher) (arg0 entity-actor))
  (pusher-base-init)
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *pusher-sg* '())
  (set! (-> obj max-frame) (res-lump-float arg0 'max-frame :default 1.0))
  (set! (-> obj max-frame) (* (-> obj max-frame) (the float (ja-num-frames 0))))
  (set! (-> obj min-frame) (res-lump-float arg0 'min-frame))
  (set! (-> obj min-frame) (* (-> obj min-frame) (the float (ja-num-frames 0))))
  (cond
    ((task-closed? (game-task rolling-race) (task-status need-introduction))
     (let ((v1-6 (-> obj skel root-channel 0)))
       (set! (-> v1-6 num-func) num-func-identity)
       (set! (-> v1-6 frame-num) (-> obj min-frame))
       )
     )
    (else
      (let ((v1-10 (-> obj skel root-channel 0)))
        (set! (-> v1-10 num-func) num-func-identity)
        (set! (-> v1-10 frame-num) (-> obj max-frame))
        )
      )
    )
  (go gorge-pusher-idle)
  (none)
  )

;; definition of type dark-plant
(deftype dark-plant (process-drawable)
  ((num-alts int32          :offset-assert 176)
   (alts     entity-actor 4 :offset-assert 180)
   )
  :heap-base #x60
  :method-count-assert 20
  :size-assert         #xc4
  :flag-assert         #x14006000c4
  (:states
    dark-plant-death
    dark-plant-gone
    dark-plant-idle
    dark-plant-sprout
    dark-plant-startup
    )
  )

;; definition for method 3 of type dark-plant
(defmethod inspect dark-plant ((obj dark-plant))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tnum-alts: ~D~%" (-> obj num-alts))
  (format #t "~T~Talts[4] @ #x~X~%" (-> obj alts))
  obj
  )

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

;; definition for function dark-plant-check-target
;; INFO: Return type mismatch object vs symbol.
(defun dark-plant-check-target ((arg0 dark-plant))
  (the-as symbol (and *target* (and (< (vector-vector-distance (-> arg0 root trans) (target-pos 0)) 16384.0)
                                    (send-event *target* 'query 'powerup (pickup-type eco-green))
                                    )
                      )
          )
  )

;; definition for function dark-plant-randomize
(defun dark-plant-randomize ((arg0 dark-plant))
  (quaternion-axis-angle! (-> arg0 root quat) 0.0 1.0 0.0 (rand-vu-float-range 0.0 65536.0))
  (let ((s5-1 (new 'stack-no-clear 'vector)))
    (set-vector! s5-1 (rand-vu-float-range -1024.0 1024.0) 0.0 (rand-vu-float-range -1024.0 1024.0) 1.0)
    (vector+! (-> arg0 root trans) (-> arg0 entity extra trans) s5-1)
    )
  )

;; definition for function dark-plants-all-done
(defun dark-plants-all-done ((arg0 dark-plant))
  (loop
    (if (!= (-> arg0 state) dark-plant-gone)
        (return #f)
        )
    (if (zero? (-> arg0 num-alts))
        (return #t)
        )
    (let ((v1-9 (-> arg0 alts 0 extra process)))
      (if (not v1-9)
          (return #t)
          )
      (if (= v1-9 arg0)
          (return #t)
          )
      (set! arg0 (the-as dark-plant v1-9))
      )
    )
  (the-as symbol #f)
  )

;; definition for function dark-plant-has-bad-neighbor
(defun dark-plant-has-bad-neighbor ((arg0 dark-plant))
  (dotimes (v1-0 (-> arg0 num-alts))
    (let ((a1-4 (-> arg0 alts v1-0 extra process)))
      (if (and a1-4 (!= (-> a1-4 state) dark-plant-gone))
          (return #t)
          )
      )
    )
  #f
  )

;; definition for function dark-plant-trans
;; INFO: Return type mismatch object vs none.
(defbehavior dark-plant-trans dark-plant ()
  (if (dark-plant-check-target self)
      (go dark-plant-death)
      )
  (none)
  )

;; failed to figure out what this is:
(defstate dark-plant-sprout (dark-plant)
  :trans dark-plant-trans
  :code (behavior ()
    (dark-plant-randomize self)
    (logclear! (-> self draw status) (draw-status hidden))
    (sound-play "darkvine-grow")
    (ja-no-eval :group! (-> self draw art-group data 4) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (go dark-plant-idle)
    (none)
    )
  :post (the-as (function none :behavior dark-plant) ja-post)
  )

;; failed to figure out what this is:
(defstate dark-plant-gone (dark-plant)
  :code (behavior ()
    (logior! (-> self draw status) (draw-status hidden))
    (let* ((f30-0 1500.0)
           (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
           (v1-5 (the-as number (logior #x3f800000 v1-4)))
           (gp-0 (+ (the int (* f30-0 (+ -1.0 (the-as float v1-5)))) 3000))
           )
      (set! (-> self state-time) (-> *display* base-frame-counter))
      (loop
        (when (and (!= (get-task-status (game-task rolling-plants)) (task-status invalid))
                   (!= (get-task-status (game-task rolling-plants)) 7)
                   )
          (cond
            ((>= (- (-> *display* base-frame-counter) (-> self state-time)) gp-0)
             (go dark-plant-sprout)
             )
            ((dark-plant-check-target self)
             (set! (-> self state-time) (-> *display* base-frame-counter))
             )
            ((not (dark-plant-has-bad-neighbor self))
             (set! (-> self state-time) (-> *display* base-frame-counter))
             )
            (else
              )
            )
          )
        (suspend)
        )
      )
    (none)
    )
  :post (the-as (function none :behavior dark-plant) ja-post)
  )

;; failed to figure out what this is:
(defstate dark-plant-death (dark-plant)
  :code (behavior ()
    (spawn (-> self part) (-> self root trans))
    (ja-channel-push! 1 (seconds 0.2))
    (sound-play "darkvine-kill")
    (ja-no-eval :group! (-> self draw art-group data 3) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (go dark-plant-gone)
    (none)
    )
  :post (the-as (function none :behavior dark-plant) ja-post)
  )

;; failed to figure out what this is:
(defstate dark-plant-idle (dark-plant)
  :trans dark-plant-trans
  :code (behavior ()
    (loop
      (when (and (logtest? (-> self draw status) (draw-status was-drawn))
                 *target*
                 (>= 81920.0 (vector-vector-distance (-> self root trans) (-> *target* control trans)))
                 )
        (if (rand-vu-percent? 0.3)
            (sound-play "darkvine-move")
            )
        (when (task-closed? (game-task rolling-plants) (task-status need-hint))
          (level-hint-spawn
            (game-text-id rolling-plants-hint)
            "sksp0113"
            (the-as entity #f)
            *entity-pool*
            (game-task none)
            )
          (if (not (send-event *target* 'query 'powerup (pickup-type eco-green)))
              (level-hint-spawn
                (game-text-id rolling-plants-hint-eco-green)
                "sksp0114"
                (the-as entity #f)
                *entity-pool*
                (game-task none)
                )
              )
          )
        )
      (let ((gp-1 (-> self skel root-channel 0)))
        (set! (-> gp-1 frame-group) (the-as art-joint-anim (-> self draw art-group data 2)))
        (set! (-> gp-1 param 0)
              (the float (+ (-> (the-as art-joint-anim (-> self draw art-group data 2)) data 0 length) -1))
              )
        (let ((f30-1 0.9)
              (f28-0 0.25)
              )
          (set! (-> gp-1 param 1) (+ f30-1 (* f28-0 (rand-float-gen))))
          )
        (set! (-> gp-1 frame-num) 0.0)
        (joint-control-channel-group! gp-1 (the-as art-joint-anim (-> self draw art-group data 2)) num-func-seek!)
        )
      (until (ja-done? 0)
        (suspend)
        (let ((gp-2 (-> self skel root-channel 0)))
          (set! (-> gp-2 param 0) (the float (+ (-> gp-2 frame-group data 0 length) -1)))
          (let ((f30-2 0.9)
                (f28-1 0.25)
                )
            (set! (-> gp-2 param 1) (+ f30-2 (* f28-1 (rand-float-gen))))
            )
          (joint-control-channel-group-eval! gp-2 (the-as art-joint-anim #f) num-func-seek!)
          )
        )
      )
    (none)
    )
  :post (the-as (function none :behavior dark-plant) ja-post)
  )

;; failed to figure out what this is:
(defstate dark-plant-startup (dark-plant)
  :trans dark-plant-trans
  :code (behavior ()
    (let ((gp-0 (-> self skel root-channel 0)))
      (set! (-> gp-0 frame-group) (the-as art-joint-anim (-> self draw art-group data 2)))
      (set! (-> gp-0 param 0)
            (the float (+ (-> (the-as art-joint-anim (-> self draw art-group data 2)) data 0 length) -1))
            )
      (set! (-> gp-0 param 1) 1.0)
      (set! (-> gp-0 frame-num) (* (rand-float-gen) (the float (ja-num-frames 0))))
      (joint-control-channel-group! gp-0 (the-as art-joint-anim (-> self draw art-group data 2)) num-func-seek!)
      )
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (go dark-plant-idle)
    (none)
    )
  :post (the-as (function none :behavior dark-plant) ja-post)
  )

;; failed to figure out what this is:
(defpartgroup group-dark-plant
  :id 455
  :duration 42
  :flags (use-local-clock)
  :bounds (static-bspherem 0 0 0 15)
  :parts ((sp-item 1764) (sp-item 2356))
  )

;; failed to figure out what this is:
(defpart 2356
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x12 :page #x2))
    (sp-flt spt-num 1.0)
    (sp-flt spt-y (meters 2))
    (sp-flt spt-scale-x (meters 12))
    (sp-rnd-flt spt-rot-z (degrees 0.0) (degrees 360.0) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 0.0 64.0 1.0)
    (sp-rnd-flt spt-g 192.0 64.0 1.0)
    (sp-rnd-flt spt-b 0.0 32.0 1.0)
    (sp-flt spt-a 96.0)
    (sp-flt spt-fade-g -3.0)
    (sp-flt spt-fade-a -2.4)
    (sp-int spt-timer 42)
    (sp-cpuinfo-flags bit2 bit3 bit14)
    )
  )

;; failed to figure out what this is:
(defpart 1764
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 128.0)
    (sp-rnd-flt spt-scale-x (meters 0.2) (meters 0.4) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-r 0.0 128.0 1.0)
    (sp-rnd-flt spt-g 192.0 64.0 1.0)
    (sp-flt spt-b 0.0)
    (sp-rnd-flt spt-a 32.0 96.0 1.0)
    (sp-rnd-flt spt-vel-y (meters 0) (meters 0.02) 1.0)
    (sp-flt spt-scalevel-x (meters -0.00066666666))
    (sp-copy-from-other spt-scalevel-y -4)
    (sp-flt spt-fade-a -0.42666668)
    (sp-rnd-flt spt-accel-y 0.0 5.4613333 1.0)
    (sp-flt spt-friction 0.95)
    (sp-int spt-timer 300)
    (sp-cpuinfo-flags bit2 bit3)
    (sp-flt spt-conerot-x (degrees 45.0))
    (sp-rnd-flt spt-conerot-y (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-conerot-radius (meters 0) (meters 4.5) 1.0)
    (sp-rnd-flt spt-rotate-y (degrees -15.0) (degrees 30.0) 1.0)
    )
  )

;; definition for method 11 of type dark-plant
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! dark-plant ((obj dark-plant) (arg0 entity-actor))
  (set! (-> obj root) (new 'process 'trsqv))
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *dark-plant-sg* '())
  (set! (-> obj part) (create-launch-control (-> *part-group-id-table* 455) obj))
  (set! (-> obj num-alts) (min 4 (entity-actor-count (-> obj entity) 'alt-actor)))
  (dotimes (s5-3 (-> obj num-alts))
    (set! (-> obj alts s5-3) (entity-actor-lookup (-> obj entity) 'alt-actor s5-3))
    )
  (if (zero? (-> obj num-alts))
      (format 0 "ERROR<GMJ>: ~S has no alternates~%" (-> obj name))
      )
  (dark-plant-randomize obj)
  (case (get-task-status (game-task rolling-plants))
    (((task-status invalid) (task-status need-resolution))
     (go dark-plant-gone)
     )
    (else
      (go dark-plant-startup)
      )
    )
  (none)
  )

;; definition of type happy-plant
(deftype happy-plant (process-drawable)
  ((root-override collide-shape  :offset        112)
   (alt-actor     entity-actor   :offset-assert 176)
   )
  :heap-base #x50
  :method-count-assert 20
  :size-assert         #xb4
  :flag-assert         #x14005000b4
  (:states
    happy-plant-init
    happy-plant-opened
    happy-plant-opening
    )
  )

;; definition for method 3 of type happy-plant
(defmethod inspect happy-plant ((obj happy-plant))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Talt-actor: ~A~%" (-> obj alt-actor))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *happy-plant-sg* happy-plant happy-plant-lod0-jg happy-plant-init-ja
              ((happy-plant-lod0-mg (meters 20)) (happy-plant-lod1-mg (meters 999999)))
              :bounds (static-spherem 0 2.25 0 6)
              )

;; failed to figure out what this is:
(defstate happy-plant-opened (happy-plant)
  :code (behavior ()
    (loop
      (ja-no-eval :group! (-> self draw art-group data 4) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (none)
    )
  :post (the-as (function none :behavior happy-plant) ja-post)
  )

;; failed to figure out what this is:
(defstate happy-plant-opening (happy-plant)
  :exit (behavior ()
    (when *target*
      (logclear! (-> *target* mask) (process-mask sleep))
      (process-entity-status! self (entity-perm-status bit-3) #f)
      (logior! (-> self mask) (process-mask actor-pause))
      )
    (none)
    )
  :code (behavior ()
    (close-specific-task! (game-task rolling-plants) (task-status need-reminder))
    (process-entity-status! self (entity-perm-status bit-3) #t)
    (logclear! (-> self mask) (process-mask actor-pause))
    (while (and *target* (< (vector-vector-distance (-> self root-override trans) (target-pos 0)) 24576.0))
      (suspend)
      )
    (let ((gp-2
            (ppointer->handle (manipy-spawn (-> self entity extra trans) (-> self entity) *rollingcam-sg* #f :to self))
            )
          )
      (let ((s5-1 (get-process *default-dead-pool* othercam #x4000)))
        (ppointer->handle (when s5-1
                            (let ((t9-8 (method-of-type othercam activate)))
                              (t9-8 (the-as othercam s5-1) (-> gp-2 process 0) 'othercam (the-as pointer #x70004000))
                              )
                            (run-now-in-process s5-1 othercam-init-by-other (-> gp-2 process 0) 4 #f #t)
                            (-> s5-1 ppointer)
                            )
                          )
        )
      (let ((s5-3
              (ppointer->handle (process-spawn fuel-cell :init fuel-cell-init-as-clone (process->handle self) 55 :to self))
              )
            )
        (if *target*
            (logior! (-> *target* mask) (process-mask sleep))
            )
        (send-event (-> gp-2 process 0) 'anim-mode 'clone-anim)
        (ja-play-spooled-anim
          (new 'static 'spool-anim
            :name "happy-plant-open"
            :index 5
            :parts 2
            :command-list '((0 send-event target draw #f) (10000 send-event target draw #t))
            )
          (the-as art-joint-anim #f)
          (the-as art-joint-anim (-> self draw art-group data 4))
          (the-as (function process-drawable symbol) false-func)
          )
        (ja-channel-set! 1)
        (ja :group! (-> self draw art-group data 4))
        (if (handle->process (the-as int gp-2))
            (deactivate (-> gp-2 process 0))
            )
        (let ((gp-3 (handle->process s5-3)))
          (when gp-3
            (send-event gp-3 'stop-cloning)
            (let ((s5-4 (new-stack-vector0)))
              (vector<-cspace! s5-4 (-> self node-list data 25))
              (send-event gp-3 'trans s5-4)
              )
            )
          )
        )
      )
    (restore-collide-with-as (-> self root-override))
    (go happy-plant-opened)
    (none)
    )
  :post (the-as (function none :behavior happy-plant) transform-post)
  )

;; failed to figure out what this is:
(defstate happy-plant-init (happy-plant)
  :trans (behavior ()
    (when (-> self alt-actor)
      (spool-push *art-control* "happy-plant-open" 0 self -99.0)
      (let* ((gp-0 (-> self alt-actor extra process))
             (a0-2 (if (and (nonzero? gp-0) (type-type? (-> gp-0 type) dark-plant))
                       gp-0
                       )
                   )
             )
        (when a0-2
          (if (dark-plants-all-done (the-as dark-plant a0-2))
              (go happy-plant-opening)
              )
          )
        )
      )
    (none)
    )
  :code (behavior ()
    (clear-collide-with-as (-> self root-override))
    (loop
      (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (none)
    )
  :post (the-as (function none :behavior happy-plant) ja-post)
  )

;; definition for method 11 of type happy-plant
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! happy-plant ((obj happy-plant) (arg0 entity-actor))
  (stack-size-set! (-> obj main-thread) 512)
  (let ((s4-0 (new 'process 'collide-shape obj (collide-list-enum hit-by-player))))
    (let ((s3-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 8192.0)
      (set-root-prim! s4-0 s3-0)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> obj root-override) s4-0)
    )
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *happy-plant-sg* '())
  (set! (-> obj alt-actor) (entity-actor-lookup (-> obj entity) 'alt-actor 0))
  (case (get-task-status (game-task rolling-plants))
    (((task-status invalid))
     (let ((v1-19 (-> obj skel root-channel 0)))
       (set! (-> v1-19 frame-group) (the-as art-joint-anim (-> obj draw art-group data 4)))
       )
     (go happy-plant-opened)
     )
    (((task-status need-resolution))
     (let ((s5-1 (new 'stack-no-clear 'vector)))
       (let ((v1-23 (-> obj skel root-channel 0)))
         (set! (-> v1-23 frame-group) (the-as art-joint-anim (-> obj draw art-group data 4)))
         )
       (logior! (-> obj skel status) (janim-status inited))
       (ja-post)
       (logclear! (-> obj skel status) (janim-status inited))
       (vector<-cspace! s5-1 (-> obj node-list data 25))
       (birth-pickup-at-point s5-1 (pickup-type fuel-cell) 55.0 #f obj (the-as fact-info #f))
       )
     (go happy-plant-opened)
     )
    (else
      (go happy-plant-init)
      )
    )
  (none)
  )

;; definition of type race-time
(deftype race-time (structure)
  ((digit int8 5 :offset-assert   0)
   )
  :pack-me
  :method-count-assert 9
  :size-assert         #x5
  :flag-assert         #x900000005
  )

;; definition for method 3 of type race-time
(defmethod inspect race-time ((obj race-time))
  (format #t "[~8x] ~A~%" obj 'race-time)
  (format #t "~Tdigit[5] @ #x~X~%" (-> obj digit))
  obj
  )

;; definition for function race-time-copy!
(defun race-time-copy! ((arg0 race-time) (arg1 race-time))
  (dotimes (v1-0 5)
    (set! (-> arg0 digit v1-0) (-> arg1 digit v1-0))
    )
  #f
  )

;; definition for function seconds->race-time
;; INFO: Return type mismatch int vs none.
(defun seconds->race-time ((arg0 race-time) (arg1 time-frame))
  (let* ((v1-1 (max 0 (min #x2bf1d arg1)))
         (f0-1 (* 0.0033333334 (the float v1-1)))
         )
    (set! (-> arg0 digit 0) (the int (* 0.016666668 f0-1)))
    (let ((f0-2 (- f0-1 (* 60.0 (the float (-> arg0 digit 0))))))
      (set! (-> arg0 digit 1) (the int (* 0.1 f0-2)))
      (let ((f0-3 (- f0-2 (* 10.0 (the float (-> arg0 digit 1))))))
        (set! (-> arg0 digit 2) (the int f0-3))
        (let ((f0-4 (- f0-3 (the float (-> arg0 digit 2)))))
          (set! (-> arg0 digit 3) (the int (* 10.0 f0-4)))
          (let ((f0-5 (- f0-4 (* 0.1 (the float (-> arg0 digit 3))))))
            (set! (-> arg0 digit 4) (the int (* 100.0 f0-5)))
            )
          )
        )
      )
    )
  (none)
  )

;; definition for function race-time->seconds
(defun race-time->seconds ((arg0 race-time))
  (let ((f0-5 (+ (the float (* 60 (-> arg0 digit 0)))
                 (the float (* 10 (-> arg0 digit 1)))
                 (the float (-> arg0 digit 2))
                 (* 0.1 (the float (-> arg0 digit 3)))
                 (* 0.01 (the float (-> arg0 digit 4)))
                 )
              )
        )
    (the int (* 300.0 f0-5))
    )
  )

;; definition for function race-time-less-than
(defun race-time-less-than ((arg0 race-time) (arg1 race-time))
  (dotimes (v1-0 5)
    (cond
      ((< (-> arg0 digit v1-0) (-> arg1 digit v1-0))
       (return #t)
       )
      ((< (-> arg1 digit v1-0) (-> arg0 digit v1-0))
       (return #f)
       )
      )
    )
  #f
  )

;; definition for function race-time-save
;; ERROR: Type Propagation failed: Failed type prop at op 6 ((set! v1 (l.wu (+ a0 -4)))): Could not get type of load: (set! v1 (l.wu (+ a0 -4))). 
;; ERROR: Type Propagation failed: Type analysis failed
;; ERROR: Function may read a register that is not set: a2
(defun race-time-save ((a0-0 race-time) (a1-0 task-control))
  (local-vars
    (v0-0 none)
    (v0-1 symbol)
    (v1-0 none)
    (v1-1 none)
    (a0-1 none)
    (a1-1 none)
    (a2-0 none)
    (a2-1 none)
    (s3-0 int)
    (t9-0 none)
    )
  (set! s3-0 0)
  (while (<.si s3-0 5)
    (set! a0-1 a2-0)
    (set! v1-0 (the-as none (l.wu (+ a0-1 -4))))
    (set! t9-0 (the-as none (l.wu (+ v1-0 84))))
    (set! v1-1 (the-as none (+ s3-0 a0-0)))
    (set! a1-1 (the-as none (l.b v1-1)))
    (set! a2-1 (the-as none (+ a1-0 s3-0)))
    (call!)
    (set! v1-2 (the-as none v0-0))
    (set! s3-0 (the-as int (+ s3-0 1)))
    )
  (set! v0-1 #f)
  (ret-value v0-1)
  )

;; definition for function race-time-read
;; ERROR: function was not converted to expressions. Cannot decompile.

;; failed to figure out what this is:
(defskelgroup *rolling-start-whole-sg* rolling-start rolling-start-whole-lod0-jg rolling-start-idle-ja
              ((rolling-start-whole-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 30)
              )

;; failed to figure out what this is:
(defskelgroup *rolling-start-broken-sg* rolling-start rolling-start-broken-lod0-jg rolling-start-idle-ja
              ((rolling-start-broken-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 30)
              )

;; definition of type rolling-start
(deftype rolling-start (process-drawable)
  ((whole-look  lod-set :inline :offset-assert 176)
   (broken-look lod-set :inline :offset-assert 212)
   )
  :heap-base #x90
  :method-count-assert 20
  :size-assert         #xf5
  :flag-assert         #x14009000f5
  (:states
    (rolling-start-break symbol)
    rolling-start-whole
    )
  )

;; definition for method 3 of type rolling-start
(defmethod inspect rolling-start ((obj rolling-start))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Twhole-look: #<lod-set @ #x~X>~%" (-> obj whole-look))
  (format #t "~T~Tbroken-look: #<lod-set @ #x~X>~%" (-> obj broken-look))
  obj
  )

;; failed to figure out what this is:
(defstate rolling-start-break (rolling-start)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('unbreak)
       (go rolling-start-whole)
       )
      )
    )
  :code (behavior ((arg0 symbol))
    (ja-no-eval :group! (-> self draw art-group data 5) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (lods-assign! (-> self draw) (-> self broken-look))
    (ja-no-eval :group! (-> self draw art-group data 6) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (loop
      (ja-no-eval :group! (-> self draw art-group data 7) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      (if arg0
          (deactivate self)
          )
      )
    (none)
    )
  :post (the-as (function none :behavior rolling-start) ja-post)
  )

;; failed to figure out what this is:
(defstate rolling-start-whole (rolling-start)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('break)
       (sound-play "cool-rolling-st")
       (go rolling-start-break #f)
       )
      (('break-and-die)
       (go rolling-start-break #t)
       )
      )
    )
  :code (behavior ()
    (lods-assign! (-> self draw) (-> self whole-look))
    (loop
      (ja-no-eval :group! (-> self draw art-group data 4) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (none)
    )
  :post (the-as (function none :behavior rolling-start) ja-post)
  )

;; definition for function rolling-start-init-by-other
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defbehavior rolling-start-init-by-other rolling-start ((arg0 vector) (arg1 float))
  (set! (-> self root) (new 'process 'trsqv))
  (set! (-> self root trans quad) (-> arg0 quad))
  (initialize-skeleton self *rolling-start-whole-sg* '())
  (setup-lods! (-> self whole-look) *rolling-start-whole-sg* (-> self draw art-group) (-> self entity))
  (setup-lods! (-> self broken-look) *rolling-start-broken-sg* (-> self draw art-group) (-> self entity))
  (let ((s5-1 (new 'stack-no-clear 'matrix)))
    (matrix-rotate-y! s5-1 arg1)
    (matrix->quaternion (-> self root quat) s5-1)
    )
  (go rolling-start-whole)
  (none)
  )

;; definition of type gorge
(deftype gorge (process-drawable)
  ((root-override collide-shape-moving         :offset        112)
   (coord         matrix               :inline :offset-assert 176)
   (radius        float                        :offset-assert 240)
   (thickness     float                        :offset-assert 244)
   )
  :heap-base #x90
  :method-count-assert 20
  :size-assert         #xf8
  :flag-assert         #x14009000f8
  )

;; definition for method 3 of type gorge
(defmethod inspect gorge ((obj gorge))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tcoord: #<matrix @ #x~X>~%" (-> obj coord))
  (format #t "~T~Tradius: ~f~%" (-> obj radius))
  (format #t "~T~Tthickness: ~f~%" (-> obj thickness))
  obj
  )

;; definition for function gorge-init
(defbehavior gorge-init gorge ((arg0 vector) (arg1 vector) (arg2 float) (arg3 float))
  (forward-down->inv-matrix (-> self coord) arg1 (new 'static 'vector :y -1.0))
  (matrix-transpose! (-> self coord) (-> self coord))
  (let ((s3-0 (new 'stack-no-clear 'vector)))
    (vector-matrix*! s3-0 arg0 (-> self coord))
    (vector-negate! (-> self coord vector 3) s3-0)
    )
  (set! (-> self coord vector 3 w) 1.0)
  (set! (-> self radius) arg2)
  (let ((f0-2 arg3))
    (set! (-> self thickness) f0-2)
    f0-2
    )
  )

;; definition of type gorge-start
(deftype gorge-start (gorge)
  ((tasks            task-control         :offset-assert 248)
   (record-time      race-time    :inline :offset-assert 252)
   (this-time        race-time    :inline :offset-assert 257)
   (start-banner     handle               :offset-assert 264)
   (end-banner       handle               :offset-assert 272)
   (timer-pos-offset int32                :offset-assert 280)
   (ticker           ticky        :inline :offset-assert 288)
   )
  :heap-base #xd0
  :method-count-assert 20
  :size-assert         #x140
  :flag-assert         #x1400d00140
  (:states
    gorge-start-idle
    gorge-start-race-aborted
    gorge-start-race-finished
    gorge-start-racing
    gorge-start-ready
    )
  )

;; definition for method 3 of type gorge-start
(defmethod inspect gorge-start ((obj gorge-start))
  (let ((t9-0 (method-of-type gorge inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Ttasks: ~A~%" (-> obj tasks))
  (format #t "~T~Trecord-time: #<race-time @ #x~X>~%" (-> obj record-time))
  (format #t "~T~Tthis-time: #<race-time @ #x~X>~%" (-> obj this-time))
  (format #t "~T~Tstart-banner: ~D~%" (-> obj start-banner))
  (format #t "~T~Tend-banner: ~D~%" (-> obj end-banner))
  (format #t "~T~Ttimer-pos-offset: ~D~%" (-> obj timer-pos-offset))
  (format #t "~T~Tticker: #<ticky @ #x~X>~%" (-> obj ticker))
  obj
  )

;; definition of type gorge-finish
(deftype gorge-finish (gorge)
  ((alt-actor entity-actor  :offset-assert 248)
   )
  :heap-base #x90
  :method-count-assert 20
  :size-assert         #xfc
  :flag-assert         #x14009000fc
  (:states
    gorge-finish-idle
    )
  )

;; definition for method 3 of type gorge-finish
(defmethod inspect gorge-finish ((obj gorge-finish))
  (let ((t9-0 (method-of-type gorge inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Talt-actor: ~A~%" (-> obj alt-actor))
  obj
  )

;; definition of type gorge-abort
(deftype gorge-abort (gorge)
  ()
  :heap-base #x90
  :method-count-assert 20
  :size-assert         #xf8
  :flag-assert         #x14009000f8
  (:states
    gorge-abort-idle
    )
  )

;; definition for method 3 of type gorge-abort
(defmethod inspect gorge-abort ((obj gorge-abort))
  (let ((t9-0 (method-of-type gorge inspect)))
    (t9-0 obj)
    )
  obj
  )

;; definition for function gorge-behind
;; INFO: Used lq/sq
(defun gorge-behind ((arg0 gorge))
  (if (not *target*)
      (return #f)
      )
  (let ((gp-0 (new-stack-vector0)))
    (vector-matrix*! gp-0 (target-pos 0) (-> arg0 coord))
    (and (< (fabs (-> gp-0 x)) (-> arg0 radius))
         (< (-> gp-0 y) (-> arg0 radius))
         (< 0.0 (-> gp-0 y))
         (< (-> gp-0 z) 0.0)
         )
    )
  )

;; definition for function gorge-in-front
;; INFO: Used lq/sq
(defun gorge-in-front ((arg0 gorge))
  (if (not *target*)
      (return #f)
      )
  (let ((s5-0 (new-stack-vector0)))
    (vector-matrix*! s5-0 (target-pos 0) (-> arg0 coord))
    (and (< (fabs (-> s5-0 x)) (-> arg0 radius))
         (< (-> s5-0 y) (-> arg0 radius))
         (< 0.0 (-> s5-0 y))
         (< 0.0 (-> s5-0 z))
         (< (-> s5-0 z) (-> arg0 thickness))
         )
    )
  )

;; definition for function gorge-trans
;; INFO: Return type mismatch symbol vs none.
(defun gorge-trans ()
  (none)
  )

;; failed to figure out what this is:
(defstate gorge-abort-idle (gorge-abort)
  :trans (the-as (function none :behavior gorge-abort) gorge-trans)
  :code (behavior ()
    (loop
      (suspend)
      (if (gorge-behind self)
          (send-event (ppointer->process (-> self parent)) 'aborted)
          )
      )
    (none)
    )
  )

;; definition for function gorge-abort-init-by-other
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defbehavior gorge-abort-init-by-other gorge-abort ((arg0 vector) (arg1 vector) (arg2 float))
  (set! (-> self root-override) (the-as collide-shape-moving (new 'process 'trsqv)))
  (set! (-> self root-override trans quad) (-> arg0 quad))
  (gorge-init arg0 arg1 arg2 8192.0)
  (go gorge-abort-idle)
  (none)
  )

;; failed to figure out what this is:
(defstate gorge-finish-idle (gorge-finish)
  :trans (the-as (function none :behavior gorge-finish) gorge-trans)
  :code (behavior ()
    (loop
      (suspend)
      (if (gorge-in-front self)
          (send-event (ppointer->process (-> self parent)) 'finished)
          )
      )
    (none)
    )
  )

;; definition for function gorge-finish-init-by-other
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defbehavior gorge-finish-init-by-other gorge-finish ((arg0 vector) (arg1 vector) (arg2 float))
  (set! (-> self root-override) (the-as collide-shape-moving (new 'process 'trsqv)))
  (set! (-> self root-override trans quad) (-> arg0 quad))
  (gorge-init arg0 arg1 arg2 20480.0)
  (go gorge-finish-idle)
  (none)
  )

;; definition for function race-time->string
(defun race-time->string ((arg0 race-time))
  (cond
    ((zero? (-> arg0 digit 0))
     (format
       (clear *temp-string*)
       "~D~D.~D~D"
       (-> arg0 digit 1)
       (-> arg0 digit 2)
       (-> arg0 digit 3)
       (-> arg0 digit 4)
       )
     *temp-string*
     )
    (else
      (format
        (clear *temp-string*)
        "~D:~D~D.~D~D"
        (-> arg0 digit 0)
        (-> arg0 digit 1)
        (-> arg0 digit 2)
        (-> arg0 digit 3)
        (-> arg0 digit 4)
        )
      *temp-string*
      )
    )
  )

;; definition for function gorge-start-draw-time
;; INFO: Return type mismatch object vs none.
(defbehavior gorge-start-draw-time gorge-start ((arg0 symbol) (arg1 symbol))
  (let ((gp-0 (new
                'stack
                'font-context
                *font-default-matrix*
                0
                0
                0.0
                (font-color yellow-orange)
                (font-flags shadow kerning)
                )
              )
        )
    (let ((v1-1 gp-0))
      (set! (-> v1-1 width) (the float 200))
      )
    (let ((v1-2 gp-0))
      (set! (-> v1-2 height) (the float 50))
      )
    (let ((v1-3 gp-0))
      (set! (-> v1-3 scale) 0.7)
      )
    (set! (-> gp-0 origin x) (the float (+ (-> self timer-pos-offset) 392)))
    (set! (-> gp-0 origin y) (the float (- 10 (-> self timer-pos-offset))))
    (set! (-> gp-0 flags) (font-flags shadow kerning right large))
    (print-game-text (lookup-text! *common-text* (game-text-id time) #f) gp-0 #f 128 22)
    (set! (-> gp-0 origin x) (+ 10.0 (-> gp-0 origin x)))
    (set! (-> gp-0 flags) (font-flags shadow kerning large))
    (print-game-text (race-time->string (-> self this-time)) gp-0 #f 128 22)
    (set! (-> gp-0 origin x) (+ -10.0 (-> gp-0 origin x)))
    (set! (-> gp-0 origin y) (+ 15.0 (-> gp-0 origin y)))
    (set! (-> gp-0 flags) (font-flags shadow kerning right large))
    (print-game-text (lookup-text! *common-text* (game-text-id record) #f) gp-0 #f 128 22)
    (set! (-> gp-0 origin x) (+ 10.0 (-> gp-0 origin x)))
    (set! (-> gp-0 flags) (font-flags shadow kerning large))
    (print-game-text (race-time->string (-> self record-time)) gp-0 #f 128 22)
    (cond
      ((not arg0)
       )
      ((race-time-less-than (-> self this-time) (-> self record-time))
       (when (< (mod (-> *display* real-frame-counter) 90) 60)
         (let ((v1-18 gp-0))
           (set! (-> v1-18 scale) 1.0)
           )
         (set! (-> gp-0 origin x) 156.0)
         (set! (-> gp-0 origin y) 80.0)
         (set! (-> gp-0 flags) (font-flags shadow kerning middle left large))
         (let ((a0-15 gp-0))
           (set! (-> a0-15 color) (font-color orange-red))
           )
         (print-game-text (lookup-text! *common-text* (game-text-id new-record) #f) gp-0 #f 128 22)
         )
       (when arg1
         (close-specific-task! (-> self entity extra perm task) (task-status need-reminder))
         (level-hint-spawn
           (game-text-id rolling-race-beat-record)
           "sksp0109"
           (the-as entity #f)
           *entity-pool*
           (game-task none)
           )
         (let ((t9-14 race-time-save)
               (a0-20 (-> self this-time))
               (a1-13 1)
               )
           (-> self tasks)
           (t9-14 a0-20 (the-as task-control a1-13))
           )
         )
       )
      (else
        (if arg1
            (ambient-hint-spawn "st-lose" (the-as vector #f) *entity-pool* 'stinger)
            )
        (when (< (mod (-> *display* real-frame-counter) 90) 60)
          (let ((v1-30 gp-0))
            (set! (-> v1-30 scale) 1.0)
            )
          (set! (-> gp-0 origin x) 156.0)
          (set! (-> gp-0 origin y) 80.0)
          (set! (-> gp-0 flags) (font-flags shadow kerning middle left large))
          (let ((a0-23 gp-0))
            (set! (-> a0-23 color) (font-color orange-red))
            )
          (print-game-text (lookup-text! *common-text* (game-text-id try-again) #f) gp-0 #f 128 22)
          )
        )
      )
    )
  (none)
  )

;; definition for function gorge-start-launch-start-banner
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs handle.
(defbehavior gorge-start-launch-start-banner gorge-start ()
  (the-as handle (when (task-closed? (game-task rolling-race) (task-status need-introduction))
                   (when (not (handle->process (-> self start-banner)))
                     (let ((gp-0 (new 'stack-no-clear 'vector)))
                       (set! (-> gp-0 quad) (-> self root-override trans quad))
                       (let ((v0-1 (ppointer->handle (process-spawn rolling-start gp-0 0.0 :to self))))
                         (set! (-> self start-banner) (the-as handle v0-1))
                         v0-1
                         )
                       )
                     )
                   )
          )
  )

;; failed to figure out what this is:
(defstate gorge-start-race-finished (gorge-start)
  :trans (behavior ()
    (gorge-trans)
    (none)
    )
  :code (behavior ()
    (gorge-start-draw-time #t #t)
    (suspend)
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (until (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 3))
      (seekl! (-> self timer-pos-offset) 100 (the int (* 3.0 (-> *display* time-adjust-ratio))))
      (when (= (-> self timer-pos-offset) 100)
        (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'enable)
        (send-event (ppointer->process (-> *hud-parts* money)) 'enable)
        )
      (gorge-start-draw-time #t #f)
      (suspend)
      (if (gorge-in-front self)
          (go gorge-start-ready)
          )
      )
    (go gorge-start-idle)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate gorge-start-race-aborted (gorge-start)
  :trans (behavior ()
    (gorge-trans)
    (none)
    )
  :code (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (until (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 3))
      (seekl! (-> self timer-pos-offset) 100 (the int (* 5.0 (-> *display* time-adjust-ratio))))
      (when (= (-> self timer-pos-offset) 100)
        (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'enable)
        (send-event (ppointer->process (-> *hud-parts* money)) 'enable)
        )
      (when (< (mod (-> *display* real-frame-counter) 90) 60)
        (let ((gp-0 (new
                      'stack
                      'font-context
                      *font-default-matrix*
                      156
                      80
                      0.0
                      (font-color orange-red)
                      (font-flags shadow kerning)
                      )
                    )
              )
          (let ((v1-20 gp-0))
            (set! (-> v1-20 width) (the float 200))
            )
          (let ((v1-21 gp-0))
            (set! (-> v1-21 height) (the float 50))
            )
          (set! (-> gp-0 flags) (font-flags shadow kerning middle left large))
          (print-game-text (lookup-text! *common-text* (game-text-id race-aborted) #f) gp-0 #f 128 22)
          )
        )
      (suspend)
      (if (gorge-in-front self)
          (go gorge-start-ready)
          )
      )
    (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'enable)
    (send-event (ppointer->process (-> *hud-parts* money)) 'enable)
    (go gorge-start-idle)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate gorge-start-racing (gorge-start)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('finished)
       (go gorge-start-race-finished)
       )
      (('aborted)
       (go gorge-start-race-aborted)
       )
      )
    )
  :enter (behavior ()
    (send-event (handle->process (-> self start-banner)) 'break)
    (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'disable)
    (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'hide)
    (send-event (ppointer->process (-> *hud-parts* money)) 'disable)
    (send-event (ppointer->process (-> *hud-parts* money)) 'hide)
    (let ((t9-5 race-time-read)
          (a0-8 (-> self record-time))
          (a1-5 1)
          (a2-1 (-> self tasks))
          )
      #x34bc
      (t9-5 a0-8 (the-as task-control a1-5) (the-as time-frame a2-1))
      )
    (set! (-> self end-banner)
          (ppointer->handle
            (process-spawn rolling-start (new 'static 'vector :x -86016.0 :y 112640.0 :z -6309888.0) 16384.0 :to self)
            )
          )
    (process-spawn
      gorge-finish
      (new 'static 'vector :x -86016.0 :y 114688.0 :z -6303744.0)
      (new 'static 'vector :x -1.0)
      57344.0
      :to self
      )
    (process-spawn
      gorge-abort
      (new 'static 'vector :x -696320.0 :y 122880.0 :z -6828032.0)
      (new 'static 'vector :x -0.707 :y 0.707)
      163840.0
      :to self
      )
    (process-spawn
      gorge-abort
      (new 'static 'vector :x -847872.0 :y 143360.0 :z -6828032.0)
      (new 'static 'vector :x 0.707 :y 0.707)
      163840.0
      :to self
      )
    (process-spawn
      gorge-abort
      (new 'static 'vector :x -417792.0 :y 143360.0 :z -6004736.0)
      (new 'static 'vector :x -0.5 :y 0.707 :z 0.3)
      266240.0
      :to self
      )
    (process-spawn
      gorge-abort
      (new 'static 'vector :x -647168.0 :y 143360.0 :z -6025216.0)
      (new 'static 'vector :x 0.5 :y 0.707 :z -0.3)
      163840.0
      :to self
      )
    (sleep (-> self ticker) (seconds 6000))
    (set-setting! 'sound-flava #f 40.0 (music-flava rolling-gorge))
    (none)
    )
  :exit (behavior ()
    (let* ((v1-0 (-> self child))
           (gp-0 (-> v1-0 0 brother))
           )
      (while v1-0
        (if (not (or (= v1-0 (-> self start-banner process)) (= v1-0 (-> self end-banner process))))
            (deactivate (-> v1-0 0))
            )
        (set! v1-0 gp-0)
        (set! gp-0 (-> v1-0 0 brother))
        )
      )
    (send-event (handle->process (-> self end-banner)) 'break-and-die)
    (send-event (handle->process (-> self start-banner)) 'unbreak)
    (remove-setting! 'sound-flava)
    (none)
    )
  :trans (the-as (function none :behavior gorge-start) gorge-trans)
  :code (behavior ()
    (set! (-> self state-time) (-> *display* game-frame-counter))
    (loop
      (seconds->race-time (-> self this-time) (- (-> *display* game-frame-counter) (-> self state-time)))
      (seekl! (-> self timer-pos-offset) 0 (the int (* 5.0 (-> *display* time-adjust-ratio))))
      (completed? (-> self ticker))
      (gorge-start-draw-time #f #f)
      (suspend)
      (if (or (not *target*) (gorge-in-front self))
          (go gorge-start-ready)
          )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate gorge-start-ready (gorge-start)
  :trans (the-as (function none :behavior gorge-start) gorge-trans)
  :code (behavior ()
    (loop
      (suspend)
      (seekl! (-> self timer-pos-offset) 100 (the int (* 5.0 (-> *display* time-adjust-ratio))))
      (when (= (-> self timer-pos-offset) 100)
        (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'enable)
        (send-event (ppointer->process (-> *hud-parts* money)) 'enable)
        )
      (gorge-start-draw-time #f #f)
      (cond
        ((gorge-in-front self)
         )
        ((gorge-behind self)
         (go gorge-start-racing)
         )
        (else
          (go gorge-start-idle)
          )
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate gorge-start-idle (gorge-start)
  :enter (behavior ()
    (logior! (-> self mask) (process-mask actor-pause))
    (process-entity-status! self (entity-perm-status bit-3) #f)
    (none)
    )
  :exit (behavior ()
    (logclear! (-> self mask) (process-mask actor-pause))
    (process-entity-status! self (entity-perm-status bit-3) #t)
    (none)
    )
  :trans (behavior ()
    (gorge-start-launch-start-banner)
    (gorge-trans)
    (none)
    )
  :code (behavior ()
    (loop
      (suspend)
      (seekl! (-> self timer-pos-offset) 100 (the int (* 5.0 (-> *display* time-adjust-ratio))))
      (when (= (-> self timer-pos-offset) 100)
        (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'enable)
        (send-event (ppointer->process (-> *hud-parts* money)) 'enable)
        )
      (if (gorge-in-front self)
          (go gorge-start-ready)
          )
      )
    (none)
    )
  )

;; definition for method 11 of type gorge-start
;; INFO: Used lq/sq
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! gorge-start ((obj gorge-start) (arg0 entity-actor))
  (set! (-> obj root-override) (the-as collide-shape-moving (new 'process 'trsqv)))
  (process-drawable-from-entity! obj arg0)
  (let ((a0-3 (new 'stack-no-clear 'vector)))
    (set! (-> a0-3 quad) (-> obj root-override trans quad))
    (set! (-> a0-3 y) (+ -8192.0 (-> a0-3 y)))
    (gorge-init a0-3 (new 'static 'vector :z 1.0) 102400.0 40960.0)
    )
  (set! (-> obj tasks) (get-task-control (-> obj entity extra perm task)))
  (set! (-> obj start-banner) (the-as handle #f))
  (set! (-> obj end-banner) (the-as handle #f))
  (set! (-> obj timer-pos-offset) 100)
  (go gorge-start-idle)
  (none)
  )

;; definition of type rolling-water
(deftype rolling-water (water-anim)
  ()
  :heap-base #x70
  :method-count-assert 30
  :size-assert         #xdc
  :flag-assert         #x1e007000dc
  )

;; definition for method 3 of type rolling-water
(defmethod inspect rolling-water ((obj rolling-water))
  (let ((t9-0 (method-of-type water-anim inspect)))
    (t9-0 obj)
    )
  obj
  )

;; definition for symbol ripple-for-rolling-water, type object
(define ripple-for-rolling-water
  (the-as object (new 'static 'ripple-wave-set
                   :count 3
                   :converted #f
                   :normal-scale 1.0
                   :wave (new 'static 'inline-array ripple-wave 4
                     (new 'static 'ripple-wave :scale 40.0 :xdiv 1 :speed 1.5)
                     (new 'static 'ripple-wave :scale 40.0 :xdiv -1 :zdiv 1 :speed 1.5)
                     (new 'static 'ripple-wave :scale 20.0 :xdiv 5 :zdiv 3 :speed 0.75)
                     (new 'static 'ripple-wave)
                     )
                   )
                 )
  )

;; definition for method 22 of type rolling-water
;; INFO: Return type mismatch water-flags vs none.
(defmethod TODO-RENAME-22 rolling-water ((obj rolling-water))
  (let ((t9-0 (method-of-type water-anim TODO-RENAME-22)))
    (t9-0 obj)
    )
  (let ((v1-2 (new 'process 'ripple-control)))
    (set! (-> obj draw ripple) v1-2)
    (set-vector! (-> obj draw color-mult) 0.01 0.45 0.5 0.75)
    (set! (-> v1-2 global-scale) 3072.0)
    (set! (-> v1-2 close-fade-dist) 163840.0)
    (set! (-> v1-2 far-fade-dist) 245760.0)
    (set! (-> v1-2 waveform) (the-as ripple-wave-set ripple-for-rolling-water))
    )
  (logclear! (-> obj flags) (water-flags wt23))
  (none)
  )
