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

;; name: wcar-rhino.gc
;; name in dgo: wcar-rhino
;; dgos: LPATK, LFACCAR, WASALL

;; DECOMP BEGINS

(deftype v-rhino (wcar-base)
  ((jmod-axles     joint-mod-rotate-local  4 :inline)
   (jmod-gun-kick  joint-mod-add-local     :inline)
   (jmod-gun-turn  joint-mod-rotate-local  :inline)
   )
  )


(defmethod wvehicle-method-169 ((this v-rhino))
  (set! (-> this shoot-time) (the-as uint (current-time)))
  (set! (-> this gun-kick) 1638.4)
  (let ((gp-0 (new 'stack-no-clear 'wcar-rhino-proj-params)))
    (matrix-copy! (-> gp-0 mat) (-> this node-list data 0 bone transform))
    (vector-matrix*! (-> gp-0 gun-local-pos) (-> this gun-local-pos) (-> gp-0 mat))
    (vector-rotate*! (-> gp-0 gun-local-dir) (-> this gun-local-dir) (-> gp-0 mat))
    (vector-float*! (-> gp-0 gun-dir) (-> gp-0 gun-local-dir) 409600.0)
    (set! (-> gp-0 params ent) (-> this entity))
    (set! (-> gp-0 params charge) 1.0)
    (set! (-> gp-0 params options) (projectile-options))
    (logclear! (-> gp-0 params options) (projectile-options po14 po15 po16))
    (set! (-> gp-0 params pos quad) (-> gp-0 gun-local-pos quad))
    (vector-copy! (-> gp-0 params vel) (-> gp-0 gun-dir))
    (set! (-> gp-0 params notify-handle) (the-as handle #f))
    (set! (-> gp-0 params owner-handle) (process->handle this))
    (set! (-> gp-0 params target-handle) (the-as handle #f))
    (set! (-> gp-0 params target-pos quad) (the-as uint128 0))
    (set! (-> gp-0 params ignore-handle) (process->handle this))
    (let* ((v1-19 *game-info*)
           (a0-20 (+ (-> v1-19 attack-id) 1))
           )
      (set! (-> v1-19 attack-id) a0-20)
      (set! (-> gp-0 params attack-id) a0-20)
      )
    (set! (-> gp-0 params timeout) (seconds 4))
    (spawn-projectile v-rhino-shot (-> gp-0 params) *rigid-body-queue-manager* *default-dead-pool*)
    )
  0
  (none)
  )

(defmethod init-collision! ((this v-rhino))
  (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 8) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 9))
      (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 2305))))
      (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 2308))))
      (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 2309))))
      (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 1040))))
      (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 10))))
      (set! (-> a0-18 prim-core action) (collide-action solid))
      (set! (-> a0-18 transform-index) 0)
      )
    (let ((v1-24 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-24 prim-core action) (collide-action solid rideable))
      (set! (-> v1-24 transform-index) 3)
      (set-vector! (-> v1-24 local-sphere) 0.0 0.0 0.0 28262.4)
      )
    (set! (-> s5-0 nav-radius) 20480.0)
    (let ((v1-26 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-26 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-26 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-rhino))
  (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 14336.0 :y -2867.2 :z 15769.6 :w 7372.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 -14336.0 :y -2867.2 :z 15769.6 :w 7372.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 15155.2 :y -2867.2 :z -12902.4 :w 7372.8))
      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 -15155.2 :y -2867.2 :z -12902.4 :w 7372.8))
      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 1638.4 :z 15769.6 :w 9830.4))
      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 4505.6 :w 11878.4))
      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 2457.6 :z -13516.8 :w 9830.4))
      16
      )
    )
  (vector-copy! (-> this turret-local-pos) (new 'static 'vector :y 6553.6 :z 14745.6 :w 1.0))
  ((method-of-type wcar-base vehicle-method-62) this)
  0
  (none)
  )

(defmethod vehicle-method-88 ((this v-rhino) (arg0 vehicle-controls))
  (let ((t9-0 (method-of-type wcar-base vehicle-method-88)))
    (t9-0 this arg0)
    )
  (wvehicle-method-199 this)
  0
  (none)
  )

(defmethod vehicle-method-94 ((this v-rhino))
  (let ((f0-0 (vector-length (-> this lin-acceleration))))
    (if (and (< 327680.0 f0-0) (and (not (logtest? (-> this controls flags) (vehicle-controls-flag vcf0)))
                                    (not (-> *setting-control* cam-current entity-name))
                                    )
             )
        (activate! *camera-smush-control* (fmin 1331.2 (/ f0-0 2)) 120 360 1.0 0.9 (-> *display* camera-clock))
        )
    )
  ((method-of-type wcar-base vehicle-method-94) this)
  (none)
  )

(defmethod vehicle-method-79 ((this v-rhino))
  (set! (-> this turbo-supply) 3.0)
  (seek! (-> this gun-kick) 0.0 (* 32768.0 (seconds-per-frame)))
  (let ((s5-0 (new 'stack-no-clear 'inline-array 'quaternion 3)))
    (set! (-> this jmod-gun-kick transform trans z) (-> this gun-kick))
    (quaternion-axis-angle! (-> s5-0 1) 1.0 0.0 0.0 (- (-> this gun-pitch)))
    (quaternion-axis-angle! (-> s5-0 2) 0.0 1.0 0.0 (-> this gun-yaw))
    (quaternion*! (-> this jmod-gun-turn rotation) (-> s5-0 2) (-> s5-0 1))
    )
  0
  (let ((s5-1 (new 'stack-no-clear 'inline-array 'quaternion 3)))
    (set-vector! (-> s5-1 2) 0.0 0.0 0.0 0.0)
    (dotimes (s4-0 (-> this info physics-model wheel-count))
      (let ((v1-8 (-> this wheel s4-0)))
        (-> v1-8 info)
        (quaternion-set! (-> s5-1 0) 0.0 0.0 (-> v1-8 sin-susp-ang) (+ 1.0 (-> v1-8 cos-susp-ang)))
        )
      (quaternion-normalize! (-> s5-1 0))
      (quaternion-axis-angle! (-> s5-1 1) 0.0 1.0 0.0 (-> (&-> s5-1 0 data s4-0) 8))
      (let ((v1-13 (-> this jmod-axles s4-0)))
        (quaternion*! (-> v1-13 rotation) (-> s5-1 0) (-> s5-1 1))
        )
      0
      )
    )
  0
  (none)
  )

(defmethod init-rbody-control! ((this v-rhino))
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-rhino" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (alloc-rbody-control! this *v-rhino-constants*)
  (set! (-> this rider-hand-joint-array 0) 8)
  (init (-> this jmod-gun-turn) this (the-as uint 9) (joint-mod-base-flags attached))
  (init (-> this jmod-gun-kick) this (the-as uint 10) (joint-mod-base-flags attached trans))
  (vector-copy! (-> this turret-local-pos) (new 'static 'vector :y 10485.76 :z 12288.0 :w 1.0))
  ((method-of-type joint-mod-rotate-local init)
   (-> this jmod-axles 0)
   this
   (the-as uint 4)
   (joint-mod-base-flags attached)
   )
  (init (-> this jmod-axles 1) this (the-as uint 6) (joint-mod-base-flags attached))
  (init (-> this jmod-axles 2) this (the-as uint 5) (joint-mod-base-flags attached))
  (init (-> this jmod-axles 3) this (the-as uint 7) (joint-mod-base-flags attached))
  (spawn-wheels!
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-rhino-wheel" (the-as (pointer level) #f)))
    (the-as skeleton-group (art-group-get-by-name *level* "skel-v-rhino-wheel" (the-as (pointer level) #f)))
    (the-as skeleton-group #f)
    (the-as skeleton-group #f)
    )
  0
  (none)
  )
