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

(import "goal_src/jak1/import/plat-sunken-ag.gc")
(import "goal_src/jak1/import/plat-ag.gc")
(import "goal_src/jak1/import/plat-jungleb-ag.gc")

;; failed to figure out what this is:
(defpartgroup group-standard-plat
  :id 107
  :bounds (static-bspherem 0 -12 0 14)
  :parts ((sp-item 363 :fade-after (meters 60) :falloff-to (meters 60))
    (sp-item 364 :fade-after (meters 160) :falloff-to (meters 160))
    )
  )

;; failed to figure out what this is:
(defpart 363
  :init-specs ((sp-flt spt-num 1.5)
    (sp-flt spt-y (meters 1))
    (sp-int spt-rot-x 5)
    (sp-flt spt-r 5324.8)
    (sp-flt spt-g 4096.0)
    (sp-flt spt-b 3686.4)
    (sp-flt spt-vel-y (meters 0.0033333334))
    (sp-flt spt-fade-b -16.383999)
    (sp-int spt-timer 25)
    (sp-cpuinfo-flags aux-list)
    (sp-rnd-flt spt-conerot-x (degrees 140.0) (degrees 40.0) 1.0)
    (sp-rnd-flt spt-conerot-y (degrees 0.0) (degrees 360.0) 1.0)
    (sp-flt spt-conerot-radius (meters 3))
    )
  )

;; failed to figure out what this is:
(defpart 364
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 2.0)
    (sp-flt spt-y (meters 1.5))
    (sp-rnd-flt spt-scale-x (meters 2) (meters 1) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-rnd-flt spt-g 0.0 64.0 1.0)
    (sp-rnd-flt spt-b 128.0 128.0 1.0)
    (sp-rnd-flt spt-a 16.0 32.0 1.0)
    (sp-flt spt-vel-y (meters 0.01))
    (sp-flt spt-fade-g -0.42666668)
    (sp-flt spt-fade-a -0.32)
    (sp-flt spt-accel-y -0.13653333)
    (sp-flt spt-friction 0.96)
    (sp-int spt-timer 150)
    (sp-cpuinfo-flags bit2 bit3)
    (sp-rnd-flt spt-conerot-x (degrees 130.0) (degrees 100.00001) 1.0)
    (sp-rnd-flt spt-conerot-y (degrees 0.0) (degrees 360.0) 1.0)
    (sp-flt spt-conerot-radius (meters 3))
    )
  )

;; definition of type plat
(deftype plat (baseplat)
  ((path-pos float                   :offset-assert 228)
   (sync     sync-info-eased :inline :offset-assert 232)
   (sound-id sound-id                :offset-assert 260)
   )
  :heap-base #xa0
  :method-count-assert 33
  :size-assert         #x108
  :flag-assert         #x2100a00108
  (:methods
    (get-lit-skel (_type_) skeleton-group 27)
    (dummy-28 () none 28)
    (wad () _type_ :state 29)
    (plat-startup (plat) _type_ :state 30)
    (plat-idle () _type_ :state 31)
    (plat-path-active (plat) _type_ :state 32)
    )
  )

;; definition for method 3 of type plat
(defmethod inspect plat ((obj plat))
  (let ((t9-0 (method-of-type baseplat inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tpath-pos: ~f~%" (-> obj path-pos))
  (format #t "~T~Tsync: #<sync-info-eased @ #x~X>~%" (-> obj sync))
  (format #t "~T~Tsound-id: ~D~%" (-> obj sound-id))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *plat-sg* plat plat-lod0-jg plat-idle-ja
              ((plat-lod0-mg (meters 20)) (plat-lod1-mg (meters 40)) (plat-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 -0.5 0 3)
              )

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

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

;; definition for method 23 of type plat
(defmethod get-unlit-skel plat ((obj plat))
  (cond
    ((= (-> (if (-> obj entity)
                (-> obj entity extra level)
                (-> *level* level-default)
                )
            name
            )
        'jungleb
        )
     *plat-jungleb-sg*
     )
    ((or (= (-> (if (-> obj entity)
                    (-> obj entity extra level)
                    (-> *level* level-default)
                    )
                name
                )
            'sunken
            )
         (= (-> (if (-> obj entity)
                    (-> obj entity extra level)
                    (-> *level* level-default)
                    )
                name
                )
            'sunkenb
            )
         )
     *plat-sunken-sg*
     )
    (else
      *plat-sg*
      )
    )
  )

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

;; definition for method 26 of type plat
;; INFO: Return type mismatch int vs none.
(defmethod dummy-26 plat ((obj plat))
  0
  (none)
  )

;; definition for method 25 of type plat
;; INFO: Return type mismatch sparticle-launch-control vs sparticle-launch-group.
(defmethod TODO-RENAME-25 plat ((obj plat))
  (the-as sparticle-launch-group (when (!= (-> (if (-> obj entity)
                                                   (-> obj entity extra level)
                                                   (-> *level* level-default)
                                                   )
                                               name
                                               )
                                           'maincave
                                           )
                                   (let ((v0-0 (create-launch-control (-> *part-group-id-table* 107) obj)))
                                     (set! (-> obj part) v0-0)
                                     v0-0
                                     )
                                   )
          )
  )

;; failed to figure out what this is:
(defstate plat-startup (plat)
  :virtual #t
  :code (behavior ((arg0 plat))
    (cond
      ((logtest? (-> self path flags) (path-control-flag not-found))
       (go-virtual plat-idle)
       )
      ((> (-> self sync period) 0)
       (go-virtual plat-path-active arg0)
       )
      (else
        (go-virtual plat-idle)
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate plat-idle (plat)
  :virtual #t
  :event (the-as (function process int symbol event-message-block object :behavior plat) plat-event)
  :trans (behavior ()
    (dummy-20 self)
    (none)
    )
  :code (behavior ()
    (plat-trans)
    (rider-post)
    (suspend)
    (loop
      (when (not (-> self bouncing))
        (plat-trans)
        (rider-post)
        (logior! (-> self mask) (process-mask sleep-code))
        (suspend)
        0
        )
      (while (-> self bouncing)
        (plat-trans)
        (rider-post)
        (suspend)
        )
      )
    (none)
    )
  )

;; failed to figure out what this is:
(defstate plat-path-active (plat)
  :virtual #t
  :event (the-as (function process int symbol event-message-block object :behavior plat) plat-event)
  :exit (behavior ()
    (sound-stop (-> self sound-id))
    (none)
    )
  :trans (behavior ()
    (set! (-> self path-pos) (if (logtest? (-> self fact options) (fact-options wrap-phase))
                                 (get-current-phase (-> self sync))
                                 (get-current-phase-with-mirror (-> self sync))
                                 )
          )
    (eval-path-curve! (-> self path) (-> self basetrans) (-> self path-pos) 'interp)
    (if (< (vector-vector-distance (-> self root-override trans) (ear-trans)) 81920.0)
        (sound-play "eco-plat-hover" :id (-> self sound-id) :position (the-as symbol (-> self root-override trans)))
        )
    (plat-trans)
    (none)
    )
  :code (the-as (function plat none :behavior plat) anim-loop)
  :post (the-as (function none :behavior plat) plat-post)
  )

;; definition for method 11 of type plat
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! plat ((obj plat) (arg0 entity-actor))
  (set! (-> obj mask) (logior (process-mask platform) (-> obj mask)))
  (dummy-24 obj)
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj (get-unlit-skel obj) '())
  (logior! (-> obj skel status) (janim-status inited))
  (update-transforms! (-> obj root-override))
  (dummy-21 obj)
  (TODO-RENAME-25 obj)
  (load-params! (-> obj sync) obj (the-as uint 0) 0.0 0.15 0.15)
  (set! (-> obj fact)
        (new 'process 'fact-info obj (pickup-type eco-pill-random) (-> *FACT-bank* default-pill-inc))
        )
  (set! (-> obj path) (new 'process 'curve-control obj 'path -1000000000.0))
  (logior! (-> obj path flags) (path-control-flag display draw-line draw-point draw-text))
  (set! (-> obj sound-id) (new-sound-id))
  (cond
    ((logtest? (-> obj path flags) (path-control-flag not-found))
     (set! (-> obj path-pos) 0.0)
     (let ((a0-14 obj))
       (dummy-26 a0-14)
       (go (method-of-object obj plat-startup) a0-14)
       )
     )
    ((> (-> obj sync period) 0)
     (set! (-> obj path-pos) (if (logtest? (-> obj fact options) (fact-options wrap-phase))
                                 (get-current-phase (-> obj sync))
                                 (get-current-phase-with-mirror (-> obj sync))
                                 )
           )
     (eval-path-curve! (-> obj path) (-> obj root-override trans) (-> obj path-pos) 'interp)
     (let ((a0-18 obj))
       (dummy-26 a0-18)
       (go (method-of-object obj plat-startup) a0-18)
       )
     )
    (else
      (set! (-> obj path-pos) 0.0)
      (eval-path-curve! (-> obj path) (-> obj root-override trans) (-> obj path-pos) 'interp)
      (let ((a0-20 obj))
        (dummy-26 a0-20)
        (go (method-of-object obj plat-startup) a0-20)
        )
      )
    )
  (none)
  )
