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

(import "goal_src/jak1/import/minecartsteel-ag.gc")

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

;; definition of type minecartsteel
(deftype minecartsteel (process-drawable)
  ((root-override collide-shape-moving         :offset        112)
   (index         int32                        :offset-assert 176)
   (anim          spool-anim                   :offset-assert 180)
   (sync          sync-info            :inline :offset-assert 184)
   )
  :heap-base #x50
  :method-count-assert 21
  :size-assert         #xc0
  :flag-assert         #x15005000c0
  (:methods
    (idle () _type_ :state 20)
    )
  )

;; definition for method 3 of type minecartsteel
(defmethod inspect minecartsteel ((obj minecartsteel))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tindex: ~D~%" (-> obj index))
  (format #t "~T~Tanim: ~A~%" (-> obj anim))
  (format #t "~T~Tsync: #<sync-info @ #x~X>~%" (-> obj sync))
  obj
  )

;; failed to figure out what this is:
(defstate idle (minecartsteel)
  :virtual #t
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (when (or (= v1-0 'touch) (= v1-0 'attack))
                       (when (= (-> arg0 type) target)
                         (let ((a2-1 (new 'stack 'collide-overlap-result)))
                           (if (not (on-platform (-> self root-override) (-> *target* control) a2-1))
                               (send-event arg0 'no-look-around (seconds 1.5))
                               )
                           )
                         )
                       #f
                       )
              )
      )
    )
  :trans (the-as (function none :behavior minecartsteel) rider-trans)
  :code (behavior ()
    (ja-channel-set! 1)
    (ja :group! (-> self anim))
    (loop
      (ja :num-func num-func-identity
          :frame-num (* (get-current-phase (-> self sync)) (the float (+ (-> (ja-group) data 0 length) -1)))
          )
      (let ((a1-1 (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data 4))))
        (update-trans! (-> self sound) a1-1)
        )
      (update! (-> self sound))
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior minecartsteel) rider-post)
  )

;; definition for function minecartsteel-initialize-by-other
(defbehavior minecartsteel-initialize-by-other minecartsteel ((arg0 entity-actor) (arg1 float))
  (let ((s4-0 (new 'process 'collide-shape-moving self (collide-list-enum usually-hit-by-player))))
    (set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s4-0 reaction) default-collision-reaction)
    (set! (-> s4-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (alloc-riders s4-0 1)
    (let ((s3-0 (new 'process 'collide-shape-prim-mesh s4-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) 4)
      (set-vector! (-> s3-0 local-sphere) 0.0 4915.2 0.0 13107.2)
      (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! (-> self root-override) s4-0)
    )
  (process-drawable-from-entity! self arg0)
  (logclear! (-> self mask) (process-mask actor-pause))
  (quaternion-identity! (-> self root-override quat))
  (initialize-skeleton self *minecartsteel-sg* '())
  (set! (-> self draw origin-joint-index) (the-as uint 3))
  (logior! (-> self skel status) (janim-status inited))
  (load-params! (-> self sync) self (the-as uint 9000) arg1 0.15 0.15)
  (set! (-> self sound)
        (new 'process 'ambient-sound (static-sound-spec "v3-cartride" :fo-max 30) (-> self root-override trans))
        )
  (set! (-> self index) (res-lump-value arg0 'index int))
  (let ((v1-33 (-> self index)))
    (set! (-> self anim)
          (the-as
            spool-anim
            (cond
              ((zero? v1-33)
               (-> self draw art-group data 5)
               )
              ((= v1-33 1)
               (let ((a0-17 (-> self sync))
                     (t9-12 (method-of-type sync-info setup-params!))
                     (a1-11 9000)
                     (f0-7 (+ 0.8 arg1))
                     )
                 (t9-12 a0-17 (the-as uint a1-11) (- f0-7 (* (the float (the int (/ f0-7 1.0))) 1.0)) 0.15 0.15)
                 )
               (-> self draw art-group data 6)
               )
              (else
                (let ((a0-18 (-> self sync))
                      (t9-13 (method-of-type sync-info setup-params!))
                      (a1-12 9000)
                      (f0-10 (+ 0.13 arg1))
                      )
                  (t9-13 a0-18 (the-as uint a1-12) (- f0-10 (* (the float (the int (/ f0-10 1.0))) 1.0)) 0.15 0.15)
                  )
                (-> self draw art-group data 7)
                )
              )
            )
          )
    )
  (go-virtual idle)
  )

;; definition for method 11 of type minecartsteel
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! minecartsteel ((obj minecartsteel) (arg0 entity-actor))
  (dotimes (s4-0 4)
    (process-spawn
      minecartsteel
      :init minecartsteel-initialize-by-other
      arg0
      (* 0.2 (the float (+ s4-0 1)))
      :to obj
      )
    )
  (minecartsteel-initialize-by-other arg0 0.0)
  (none)
  )
