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

;; name: wcar-marauder-b.gc
;; name in dgo: wcar-marauder-b
;; dgos: DESCHASE

;; DECOMP BEGINS

(defskelgroup skel-v-marauder-b interceptor-b interceptor-b-lod0-jg interceptor-b-idle-ja
              ((interceptor-b-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 5.5)
              :shadow interceptor-b-shadow-mg
              :origin-joint-index 3
              )

(defskelgroup skel-v-marauder-b-wheel interceptor-b interceptor-b-wheel-lod0-jg interceptor-b-wheel-idle-ja
              ((interceptor-b-wheel-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 1.5)
              :longest-edge (meters 1.07)
              :shadow interceptor-b-wheel-shadow-mg
              )

(defskelgroup skel-v-marauder-b-wheel-blur interceptor-b interceptor-b-wheel-blur-lod0-jg interceptor-b-wheel-blur-idle-ja
              ((interceptor-b-wheel-blur-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 1.5)
              :longest-edge (meters 1.07)
              :shadow interceptor-b-wheel-blur-shadow-mg
              )

(define *v-marauder-b-turret-control-info* (new 'static 'turret-control-info
                                             :joint-index 8
                                             :barrel-count 1
                                             :shot-speed 819200.0
                                             :attack-range 819200.0
                                             :damage 2.0
                                             :vehicle-damage-factor 1.0
                                             :vehicle-impulse-factor 1.0
                                             :rot-min (new 'static 'array float 2 -1820.4445 -32768.0)
                                             :rot-max (new 'static 'array float 2 16384.0 32768.0)
                                             :local-pos (new 'static 'vector :z 4096.0 :w 1.0)
                                             :local-dir (new 'static 'vector :z 1.0 :w 1.0)
                                             :barrel-array (new 'static 'inline-array turret-barrel-info 4
                                               (new 'static 'turret-barrel-info
                                                 :local-pos (new 'static 'vector :w 1.0)
                                                 :local-dir (new 'static 'vector :z 1.0 :w 1.0)
                                                 )
                                               (new 'static 'turret-barrel-info)
                                               (new 'static 'turret-barrel-info)
                                               (new 'static 'turret-barrel-info)
                                               )
                                             )
        )

(set! (-> *v-marauder-b-turret-control-info* shot-type) v-marauder-shot)

(define *v-marauder-b-turret-guard-settings* (new 'static 'squad-unit-settings
                                               :shot-count 2
                                               :rand-shot-count 2
                                               :inaccuracy 0.25
                                               :acquire-delay (seconds 0.2)
                                               :shot-delay (seconds 0.15)
                                               :burst-delay (seconds 0.5)
                                               :rand-burst-delay (seconds 1)
                                               :rand-shot-delay (seconds 0.2)
                                               )
        )

(define *v-marauder-b-constants* (new 'static 'rigid-body-vehicle-constants))

(mem-copy! (the-as pointer *v-marauder-b-constants*) (the-as pointer *v-marauder-constants*) 2584)

(set! (-> *v-marauder-b-constants* name) '*v-marauder-b-constants*)

(mem-copy!
  (the-as pointer (-> *v-marauder-b-constants* damage))
  (the-as pointer (new 'static 'vehicle-damage-info
                    :inv-toughness-factor 1.0
                    :hit-points 30.0
                    :inv-hit-points 0.033333335
                    :hit-threshold 8192.0
                    :hit-small 102400.0
                    :hit-big 131072.0
                    :hit-deadly 286720.0
                    :impact-damage-factor 1.0
                    )
          )
  168
  )

(mem-copy!
  (the-as pointer (-> *v-marauder-b-constants* setup))
  (the-as pointer (new 'static 'vehicle-setup-info
                    :settle-height 5488.64
                    :settle-rot-x 728.1778
                    :shadow-bot-clip -32768.0
                    :shadow-locus-dist 204800.0
                    :color-option-count 1
                    :color (new 'static 'inline-array vector 1 (new 'static 'vector :x 1.0 :y 1.0 :z 1.0 :w 1.0))
                    :gun-yaw-min -65536.0
                    :gun-yaw-max 65536.0
                    :gun-pitch-min -16384.0
                    :gun-pitch-max 16384.0
                    )
          )
  44
  )

(set! (-> *v-marauder-b-constants* debris)
      (new 'static 'debris-static-params
        :joints (new 'static 'boxed-array :type debris-static-joint-params
          (new 'static 'debris-static-joint-params :parent-joint-index 4 :group "skel-v-marauder-debris-ring")
          (new 'static 'debris-static-joint-params :parent-joint-index 5 :group "skel-v-marauder-debris-ring")
          (new 'static 'debris-static-joint-params :parent-joint-index 10 :group "skel-v-marauder-debris-ring")
          (new 'static 'debris-static-joint-params :parent-joint-index 9 :group "skel-v-marauder-debris-ring")
          (new 'static 'debris-static-joint-params :parent-joint-index 4 :group "skel-v-marauder-debris-nut")
          (new 'static 'debris-static-joint-params :parent-joint-index 5 :group "skel-v-marauder-debris-nut")
          (new 'static 'debris-static-joint-params :parent-joint-index 10 :group "skel-v-marauder-debris-nut")
          (new 'static 'debris-static-joint-params :parent-joint-index 9 :group "skel-v-marauder-debris-nut")
          (new 'static 'debris-static-joint-params :parent-joint-index 4 :group "skel-v-marauder-debris-rod")
          (new 'static 'debris-static-joint-params :parent-joint-index 5 :group "skel-v-marauder-debris-rod")
          (new 'static 'debris-static-joint-params :parent-joint-index 10 :group "skel-v-marauder-debris-rod")
          (new 'static 'debris-static-joint-params :parent-joint-index 9 :group "skel-v-marauder-debris-rod")
          (new 'static 'debris-static-joint-params :parent-joint-index 4 :group "skel-v-marauder-debris-panel")
          (new 'static 'debris-static-joint-params :parent-joint-index 5 :group "skel-v-marauder-debris-panel")
          (new 'static 'debris-static-joint-params :parent-joint-index 10 :group "skel-v-marauder-debris-panel")
          (new 'static 'debris-static-joint-params :parent-joint-index 9 :group "skel-v-marauder-debris-panel")
          )
        :collide-spec (collide-spec backgnd)
        :sound-hit (static-sound-name "inter-pieces")
        :art-level 'wasall
        )
      )

(deftype v-marauder-b (wcar-base)
  ((jmod-axles      joint-mod-rotate-local  4 :inline)
   (jmod-gun-x      joint-mod-rotate-local  :inline)
   (jmod-gun-y      joint-mod-rotate-local  :inline)
   (turret-control  turret-control          :inline)
   )
  )


(defmethod control-hook-ai ((this v-marauder-b) (arg0 vehicle-controls))
  (let ((t9-0 (method-of-type wcar-base control-hook-ai)))
    (t9-0 this arg0)
    )
  (let ((s5-0 (-> this target-status)))
    (when (< 122880.0 (vector-vector-distance (-> s5-0 position) (-> this root trans)))
      (let ((f0-1 (vector-length (-> s5-0 velocity))))
        (set! (-> this turret-control inaccuracy) (* 0.000012207031 (+ 40960.0 f0-1)))
        )
      (turret-control-method-11 (-> this turret-control) this (-> s5-0 position) (-> s5-0 velocity))
      )
    )
  0
  (none)
  )

(defmethod init-collision! ((this v-marauder-b))
  (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 9) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 10))
      (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 ((a0-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 144))))
      (set! (-> a0-15 prim-core action) (collide-action solid))
      (set! (-> a0-15 transform-index) 0)
      )
    (let ((a0-17 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 10))))
      (set! (-> a0-17 prim-core action) (collide-action solid))
      (set! (-> a0-17 transform-index) 0)
      )
    (let ((a0-19 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 3))))
      (set! (-> a0-19 prim-core action) (collide-action solid))
      (set! (-> a0-19 transform-index) 0)
      )
    (let ((a0-21 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 12))))
      (set! (-> a0-21 prim-core action) (collide-action solid))
      (set! (-> a0-21 transform-index) 0)
      )
    (set! (-> s5-0 nav-radius) 143360.0)
    (let ((v1-28 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-28 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-28 prim-core collide-with))
      )
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod vehicle-method-62 ((this v-marauder-b))
  (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 1638.4 :z 7864.32 :w 3276.8))
      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 1638.4 :z 7864.32 :w 3276.8))
      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 9011.2 :y 2048.0 :z -11878.4 :w 4915.2))
      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 -9011.2 :y 2048.0 :z -11878.4 :w 4915.2))
      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 3276.8 :z 9011.2 :w 4505.6))
      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 3686.4 :z -1638.4 :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 :y 3276.8 :z -11878.4 :w 5734.4))
      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 8192.0 :y 3276.8 :z -1638.4 :w 5324.8))
      16
      )
    (mem-copy!
      (the-as pointer (-> (the-as collide-shape-prim-group s5-0) child 8 local-sphere))
      (the-as pointer (new 'static 'vector :x -8192.0 :y 3276.8 :z -1638.4 :w 5324.8))
      16
      )
    )
  ((method-of-type wcar-base vehicle-method-62) this)
  0
  (none)
  )

(defmethod vehicle-method-79 ((this v-marauder-b))
  (logior! (-> this v-flags) (vehicle-flag nav-spheres))
  (let ((s5-0 (new 'stack-no-clear 'inline-array 'quaternion 3)))
    (set-vector! (-> s5-0 2) 1092.2667 1092.2667 0.0 0.0)
    (dotimes (s4-0 (-> this info physics-model wheel-count))
      (let ((s3-0 (-> this wheel s4-0)))
        (-> s3-0 info)
        (quaternion-set!
          (-> s5-0 0)
          0.0
          0.0
          (* (-> s3-0 sin-susp-ang) (-> s3-0 x-scale))
          (+ 1.0 (-> s3-0 cos-susp-ang))
          )
        (quaternion-normalize! (-> s5-0 0))
        (quaternion-axis-angle! (-> s5-0 1) 0.0 0.0 (-> s3-0 x-scale) (-> (&-> s5-0 0 data s4-0) 8))
        )
      (let ((v1-12 (-> this jmod-axles s4-0)))
        (quaternion*! (-> v1-12 rotation) (-> s5-0 0) (-> s5-0 1))
        )
      0
      )
    )
  (quaternion-axis-angle! (-> this jmod-gun-x rotation) 1.0 0.0 0.0 (- (-> this turret-control aim-rot-x)))
  (quaternion-axis-angle! (-> this jmod-gun-y rotation) 0.0 1.0 0.0 (-> this turret-control aim-rot-y))
  0
  (none)
  )

(defmethod init-rbody-control! ((this v-marauder-b))
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-marauder-b" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (alloc-rbody-control! this *v-marauder-b-constants*)
  (set! (-> this draw lod-set lod 0 dist) 1105920.0)
  (set! (-> this rider-hand-joint-array 0) 3)
  ((method-of-type joint-mod-rotate-local init)
   (-> this jmod-axles 0)
   this
   (the-as uint 5)
   (joint-mod-base-flags attached)
   )
  (init (-> this jmod-axles 1) this (the-as uint 9) (joint-mod-base-flags attached))
  (init (-> this jmod-axles 2) this (the-as uint 4) (joint-mod-base-flags attached))
  (init (-> this jmod-axles 3) this (the-as uint 10) (joint-mod-base-flags attached))
  (init (-> this jmod-gun-x) this (the-as uint 7) (joint-mod-base-flags attached))
  (init (-> this jmod-gun-y) this (the-as uint 6) (joint-mod-base-flags attached))
  (set-info (-> this turret-control) *v-marauder-b-turret-control-info*)
  (logior! (-> this turret-control flags) (turret-flag no-rot-y-clamp))
  (set! (-> this turret-control ignore-handle) (process->handle this))
  (set! (-> this turret-control guard-settings) *v-marauder-b-turret-guard-settings*)
  (spawn-wheels!
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-marauder-b-wheel" (the-as (pointer level) #f)))
    (the-as
      skeleton-group
      (art-group-get-by-name *level* "skel-v-marauder-b-wheel-blur" (the-as (pointer level) #f))
      )
    (the-as skeleton-group #f)
    (the-as skeleton-group #f)
    )
  (set! (-> this eng-pitch-offset) (rand-vu-float-range -0.5 0.5))
  (if (-> this info debris)
      (set! (-> this info debris art-level) (-> this level name))
      )
  0
  (none)
  )

(defstate explode (v-marauder-b)
  :virtual #t
  :enter (behavior ()
    (if (and *target* (focus-test? *target* pilot-riding) (not (logtest? (vehicle-flag vf55) (-> self v-flags))))
        (turbo-pickup-spawn (-> self root trans))
        )
    (call-parent-state-handler enter)
    )
  )
