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

;; name: wcar-faccar.gc
;; name in dgo: wcar-faccar
;; dgos: LFACCAR

;; DECOMP BEGINS

(defskelgroup skel-v-faccar faccar faccar-lod0-jg faccar-idle-ja
              ((faccar-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 3.5)
              :shadow faccar-shadow-mg
              :origin-joint-index 3
              )

(defskelgroup skel-v-faccar-wheel faccar faccar-wheel-lod0-jg faccar-wheel-idle-ja
              ((faccar-wheel-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 1.2)
              :shadow faccar-wheel-shadow-mg
              )

(defskelgroup skel-v-faccar-wheel-blur faccar faccar-wheel-blur-lod0-jg faccar-wheel-blur-idle-ja
              ((faccar-wheel-blur-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 1.2)
              :shadow faccar-wheel-blur-shadow-mg
              )

(deftype v-faccar (wcar-base)
  ((jmod-axles       joint-mod-rotate-local  4 :inline)
   (jmod-shock-tops  joint-mod-rotate-local  4 :inline)
   (jmod-shock-mids  joint-mod-set-local     4 :inline)
   (jmod-antenna     joint-mod-rotate-local  4 :inline)
   )
  (:methods
    (v-faccar-method-203 (_type_ vector) (pointer process))
    )
  )


(defmethod v-faccar-method-203 ((this v-faccar) (arg0 vector))
  (let* ((gp-0 6)
         (s5-0 6)
         (f30-0 (vector-vector-distance-squared (-> this node-list data gp-0 bone transform trans) arg0))
         (f28-0 (vector-vector-distance-squared (-> this node-list data s5-0 bone transform trans) arg0))
         )
    (let* ((s2-0 8)
           (f0-0 (vector-vector-distance-squared arg0 (-> this node-list data s2-0 bone transform trans)))
           )
      (cond
        ((< f0-0 f30-0)
         (set! s5-0 gp-0)
         (set! f28-0 f30-0)
         (set! gp-0 s2-0)
         (set! f30-0 f0-0)
         )
        ((< f0-0 f28-0)
         (set! s5-0 s2-0)
         (set! f28-0 f0-0)
         )
        )
      )
    (let* ((s2-1 10)
           (f0-1 (vector-vector-distance-squared arg0 (-> this node-list data s2-1 bone transform trans)))
           )
      (cond
        ((< f0-1 f30-0)
         (set! s5-0 gp-0)
         (set! f28-0 f30-0)
         (set! gp-0 s2-1)
         (set! f30-0 f0-1)
         )
        ((< f0-1 f28-0)
         (set! s5-0 s2-1)
         (set! f28-0 f0-1)
         )
        )
      )
    (let* ((s2-2 12)
           (f0-2 (vector-vector-distance-squared arg0 (-> this node-list data s2-2 bone transform trans)))
           )
      (cond
        ((< f0-2 f30-0)
         (set! s5-0 gp-0)
         (set! f28-0 f30-0)
         (set! gp-0 s2-2)
         (set! f30-0 f0-2)
         )
        ((< f0-2 f28-0)
         (set! s5-0 s2-2)
         (set! f28-0 f0-2)
         )
        )
      )
    (let* ((s2-3 14)
           (f0-3 (vector-vector-distance-squared arg0 (-> this node-list data s2-3 bone transform trans)))
           )
      (cond
        ((< f0-3 f30-0)
         (set! s5-0 gp-0)
         (set! f28-0 f30-0)
         (set! gp-0 s2-3)
         (set! f30-0 f0-3)
         )
        ((< f0-3 f28-0)
         (set! s5-0 s2-3)
         (set! f28-0 f0-3)
         )
        )
      )
    (let* ((s2-4 15)
           (f0-4 (vector-vector-distance-squared arg0 (-> this node-list data s2-4 bone transform trans)))
           )
      (cond
        ((< f0-4 f30-0)
         (set! s5-0 gp-0)
         (set! f28-0 f30-0)
         (set! gp-0 s2-4)
         (set! f30-0 f0-4)
         )
        ((< f0-4 f28-0)
         (set! s5-0 s2-4)
         (set! f28-0 f0-4)
         )
        )
      )
    (let* ((s2-5 16)
           (f0-5 (vector-vector-distance-squared arg0 (-> this node-list data s2-5 bone transform trans)))
           )
      (cond
        ((< f0-5 f30-0)
         (set! s5-0 gp-0)
         (set! f28-0 f30-0)
         (set! gp-0 s2-5)
         (set! f30-0 f0-5)
         )
        ((< f0-5 f28-0)
         (set! s5-0 s2-5)
         (set! f28-0 f0-5)
         )
        )
      )
    (let* ((s2-6 17)
           (f0-6 (vector-vector-distance-squared arg0 (-> this node-list data s2-6 bone transform trans)))
           )
      (cond
        ((< f0-6 f30-0)
         (set! s5-0 gp-0)
         (set! gp-0 s2-6)
         )
        ((< f0-6 f28-0)
         (set! s5-0 s2-6)
         )
        )
      )
    )
  (process-spawn-function
    process
    (lambda :behavior process
      ((arg0 handle))
      (let ((s5-0 (current-time)))
        (suspend-for (seconds 0.65)
          (when (time-elapsed? s5-0 (seconds 0.06))
            (set! s5-0 (current-time))
            (let ((s3-0 (handle->process arg0)))
              (process-drawable-shock-effect
                (the-as process-drawable s3-0)
                (-> *lightning-spec-id-table* 1)
                lightning-probe-callback
                (-> *part-id-table* 160)
                0
                0
                40960.0
                )
              (process-drawable-shock-effect
                (the-as process-drawable s3-0)
                (-> *lightning-spec-id-table* 1)
                lightning-probe-callback
                (-> *part-id-table* 160)
                0
                0
                40960.0
                )
              )
            )
          )
        )
      #f
      )
    (process->handle this)
    :to this
    )
  )

(defmethod init-collision! ((this v-faccar))
  (let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrate-using) (penetrate vehicle))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 10) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 11))
      (set! (-> s4-0 prim-core action) (collide-action solid rideable))
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((a0-5 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 1))))
      (set! (-> a0-5 prim-core action) (collide-action solid))
      (set! (-> a0-5 transform-index) 0)
      )
    (let ((a0-7 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 4))))
      (set! (-> a0-7 prim-core action) (collide-action solid))
      (set! (-> a0-7 transform-index) 0)
      )
    (let ((a0-9 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 2))))
      (set! (-> a0-9 prim-core action) (collide-action solid))
      (set! (-> a0-9 transform-index) 0)
      )
    (let ((a0-11 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 8))))
      (set! (-> a0-11 prim-core action) (collide-action solid))
      (set! (-> a0-11 transform-index) 0)
      )
    (let ((a0-13 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 5))))
      (set! (-> a0-13 prim-core action) (collide-action solid))
      (set! (-> a0-13 transform-index) 0)
      )
    (let ((v1-20 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 16))))
      (set! (-> v1-20 prim-core action) (collide-action solid nav-sphere))
      (set! (-> v1-20 transform-index) 0)
      (set! (-> v1-20 nav-radius) 20480.0)
      )
    (let ((a0-18 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 16))))
      (set! (-> a0-18 prim-core action) (collide-action solid))
      (set! (-> a0-18 transform-index) 0)
      )
    (let ((a0-20 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 16))))
      (set! (-> a0-20 prim-core action) (collide-action solid))
      (set! (-> a0-20 transform-index) 0)
      )
    (let ((v1-26 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 10))))
      (set! (-> v1-26 prim-core action) (collide-action solid nav-sphere))
      (set! (-> v1-26 transform-index) 0)
      )
    (let ((v1-28 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-28 prim-core action) (collide-action solid rideable))
      (set! (-> v1-28 transform-index) 3)
      (set-vector! (-> v1-28 local-sphere) 0.0 0.0 0.0 16384.0)
      )
    (set! (-> s5-0 nav-radius) 20480.0)
    (let ((v1-30 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-30 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-30 prim-core collide-with))
      )
    (set! (-> s5-0 nav-flags) (nav-flags has-child-spheres))
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod vehicle-method-62 ((this v-faccar))
  (let ((s5-0 (-> this root root-prim)))
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 0 local-sphere))
      (the-as pointer (new 'static 'vector :x 8192.0 :y 409.6 :z 7987.2 :w 3686.4))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 1 local-sphere))
      (the-as pointer (new 'static 'vector :x -8192.0 :y 409.6 :z 7987.2 :w 3686.4))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 2 local-sphere))
      (the-as pointer (new 'static 'vector :x 8192.0 :y 1638.4 :z -12083.2 :w 4505.6))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 3 local-sphere))
      (the-as pointer (new 'static 'vector :x -8192.0 :y 1638.4 :z -12083.2 :w 4505.6))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 4 local-sphere))
      (the-as pointer (new 'static 'vector :y 2048.0 :z 9011.2 :w 5324.8))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 5 local-sphere))
      (the-as pointer (new 'static 'vector :y 3276.8 :z -409.6 :w 6144.0))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 6 local-sphere))
      (the-as pointer (new 'static 'vector :x 7782.4 :y 2048.0 :z -1638.4 :w 4915.2))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 7 local-sphere))
      (the-as pointer (new 'static 'vector :x -7782.4 :y 2048.0 :z -1638.4 :w 4915.2))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 8 local-sphere))
      (the-as pointer (new 'static 'vector :y 3276.8 :z -10240.0 :w 6144.0))
      16
      )
    )
  ((method-of-type wcar-base vehicle-method-62) this)
  (none)
  )

(defmethod rbody-event-handler ((this v-faccar) (arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('lawsuit)
     (v-faccar-method-203 this (the-as vector (-> arg3 param 0)))
     )
    (else
      ((method-of-type wcar-base rbody-event-handler) this arg0 arg1 arg2 arg3)
      )
    )
  )

(defmethod vehicle-method-79 ((this v-faccar))
  (set! (-> this turbo-supply) 3.0)
  (let ((s5-0 (new 'stack-no-clear 'inline-array 'quaternion 1)))
    (dotimes (s4-0 (-> this info physics-model wheel-count))
      (let ((v1-4 (-> this wheel s4-0)))
        (-> v1-4 info)
        (let ((s3-0 (-> this jmod-axles s4-0)))
          (quaternion-set! (-> s5-0 0) 0.0 0.0 (-> v1-4 sin-susp-ang) (+ 1.0 (-> v1-4 cos-susp-ang)))
          (quaternion-normalize! (-> s5-0 0))
          (quaternion-copy! (-> s3-0 rotation) (-> s5-0 0))
          )
        )
      0
      )
    )
  0
  (none)
  )

(defmethod init-rbody-control! ((this v-faccar))
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-faccar" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (alloc-rbody-control! this *v-faccar-constants*)
  (set! (-> this rider-hand-joint-array 0) 5)
  (set! (-> this focus-status)
        (the-as focus-status (logior (focus-status gun-no-target) (-> this focus-status)))
        )
  ((method-of-type joint-mod-rotate-local init)
   (-> this jmod-axles 0)
   this
   (the-as uint 14)
   (joint-mod-base-flags attached)
   )
  (init (-> this jmod-axles 1) this (the-as uint 16) (joint-mod-base-flags attached))
  (init (-> this jmod-axles 2) this (the-as uint 15) (joint-mod-base-flags attached))
  (init (-> this jmod-axles 3) this (the-as uint 17) (joint-mod-base-flags attached))
  (spawn-wheels!
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-faccar-wheel" (the-as (pointer level) #f)))
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-faccar-wheel-blur" (the-as (pointer level) #f)))
    (the-as skeleton-group #f)
    (the-as skeleton-group #f)
    )
  0
  (none)
  )

;; WARN: Return type mismatch int vs search-info-flag.
(defmethod get-search-info-flag ((this v-faccar))
  "Get search-info-flag for this process."
  (the-as search-info-flag 0)
  )

(deftype faccar (w-parking-spot)
  ()
  )


(defmethod w-parking-spot-method-26 ((this faccar))
  21
  )

(defmethod attack-handler ((this v-faccar) (arg0 process-drawable) (arg1 attack-info) (arg2 touching-shapes-entry) (arg3 penetrate))
  (local-vars (v0-1 symbol))
  (cond
    ((not (task-node-closed? (game-task-node factory-assault-indax-3)))
     (return #f)
     v0-1
     )
    (else
      (call-parent-method this arg0 arg1 arg2 arg3)
      )
    )
  )
