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

;; name: board-h.gc
;; name in dgo: board-h
;; dgos: GAME

;; +++board-tricks
(defenum board-tricks
  :type uint32
  :bitfield #f
  (none 0)
  (board-spin 1)
  (board-boost 2)
  (board-flip 3)
  (board-rail 4)
  (board-rail-jump 5)
  (board-nosegrab 6)
  (board-board-spin 7)
  (board-board-flip 8)
  (board-noseflip 9)
  (board-kickflip 10)
  (board-kickspin 11)
  (board-method 12)
  (board-method-cross 13)
  (board-backgrab 14)
  (board-airwalk 15)
  (board-jump 16)
  (board-duck-jump 17)
  (board-quick-jump 18)
  (darkjak 19)
  (darkjak-bomb0 20)
  (darkjak-bomb1 21)
  (darkjak-smack 22)
  (darkjak-tracking 23)
  (lightjak 24)
  (lightjak-regen 25)
  (lightjak-swoop 26)
  (lightjak-freeze 27)
  (lightjak-shield 28)
  )
;; ---board-tricks


;; DECOMP BEGINS

(deftype board (process-drawable)
  ((self           board            :override)
   (parent         (pointer target) :override)
   (control        control-info      :overlay-at root)
   (shadow-backup  shadow-geo        :offset 208)
   (main           joint-mod)
   (in-head-time   time-frame)
   )
  (:state-methods
    (idle symbol)
    use
    hidden
    )
  )


(deftype board-info (basic)
  ((board                   (pointer board))
   (camera-interp           float)
   (process                 (pointer target))
   (board-trans             vector             :inline)
   (board-quat              vector             :inline)
   (board-scale             vector             :inline)
   (main                    joint-mod)
   (upper-body              joint-mod)
   (mode-sound-bank         connection)
   (sound-bank-knob         float)
   (sound-air-knob          float)
   (wind-sound-id           sound-id)
   (wind-sound-pitch        float)
   (wind-sound-volume       float)
   (engine-sound-id         sound-id)
   (engine-sound-pitch      float)
   (engine-sound-volume     float)
   (bank-sound-id           sound-id)
   (bank-sound-pitch        float)
   (bank-sound-volume       float)
   (ride-sound-id           sound-id)
   (spin-sound-id           sound-id)
   (spin-sound-volume       float)
   (spin-sound-pitch        float)
   (turn-sound-id           sound-id)
   (trick-sound-id          sound-id)
   (jump-sound-id           sound-id)
   (eco-sound-id            sound-id)
   (eco-sound-volume        float)
   (charge-sound-id         sound-id)
   (adjust-time             time-frame)
   (up-vector               vector             2 :inline)
   (slow-transv             vector             :inline)
   (board-time              time-frame)
   (board-get-on-time       time-frame)
   (in-air-time             time-frame)
   (last-jump-time          time-frame)
   (jump-end-time           time-frame)
   (unk-time-frame01        time-frame)
   (stick-lock              symbol)
   (stick-off               symbol)
   (stance-info             ground-tween-info  :inline)
   (mods-backup             surface)
   (attack-id               uint32)
   (latch?                  symbol)
   (probe-intersect         vector             :inline)
   (probe-normal            vector             :inline)
   (probe-pat               pat-surface)
   (probe                   symbol)
   (unstuck-time            time-frame)
   (stuck-count             int32)
   (thrust-scale            float)
   (flip-time               time-frame)
   (transv-max              meters)
   (turn-anim-tilt?         symbol)
   (turn-anim-mag           float)
   (turn-anim-targ          float)
   (turn-anim-frame         float)
   (unk-float000            float)
   (unk-float001            float)
   (turn-anim-vel           float)
   (turn-anim-duck          float)
   (turn-anim-duck-vel      float)
   (tilt-anim-frame         vector             :inline)
   (tilt-anim-targ          vector             :inline)
   (smack-surface-time      time-frame)
   (smack-speed             meters)
   (smack-normal            vector             :inline)
   (glance-time             time-frame)
   (glance-speed            meters)
   (glance-in-transv        vector             :inline)
   (glance-out-transv       vector             :inline)
   (glance-normal           vector             :inline)
   (on-flat-time            time-frame)
   (jump-land-time          time-frame)
   (slip-factor             float)
   (ground-on-dir           vector             :inline)
   (ride-time               time-frame)
   (ride-start-time         time-frame)
   (ride-button-time        time-frame)
   (ride-lean-targ          float)
   (ride-lean               float)
   (ride-leanv              float)
   (ride-lean-mag           float)
   (ride-tilt-targ          float)
   (ride-tilt               float)
   (ride-tiltv              float)
   (ride-tilt-mag           float)
   (ride-lock               symbol)
   (ride-lock-on            symbol)
   (ride-speed              meters)
   (ride-mode               uint32)
   (ride-rot                degrees)
   (ride-rot-old            degrees)
   (ride-rot-abs            degrees            2)
   (ride-rotv-abs           degrees)
   (ride-touch-segment      vector             2 :inline)
   (ride-dir                vector             :inline)
   (ride-vertex-length      int16)
   (ride-vertex-length-old  int16)
   (ride-vertex-base        int16)
   (ride-vertex-base2       int16)
   (ride-vertex-index       float)
   (ride-vertex-index2      float)
   (ride-vertex-index-old   float)
   (ride-vertex             vector             3 :inline)
   (ride-segment            vector             :inline)
   (ride-dir-lean           vector             :inline)
   (ride-pad-vector         vector             1 :inline)
   (ride-vertex-old         vector             3 :inline)
   (ride-segment-old        vector             :inline)
   (ride-vertex-trail       vector             128 :inline)
   (halfpipe-side-time      time-frame)
   (halfpipe-jump-time      time-frame)
   (halfpipe-lip-time       time-frame)
   (halfpipe-time           time-frame)
   (halfpipe-gspot-time     time-frame)
   (halfpipe-lip-event      symbol)
   (spin-check-time         time-frame)
   (spin-time               time-frame)
   (spin-start-time         time-frame)
   (spin-start-dir          vector             :inline)
   (spin-control            float)
   (spin-ground-start-time  time-frame)
   (spin-ground-time        time-frame)
   (spin-ground-press-time  time-frame)
   (flip-control            float)
   (flip-count              int32)
   (unk-time000             time-frame            :offset 3152)
   (tricky-time             time-frame)
   (tricky-exit-time        time-frame)
   (duck-start-time         time-frame)
   (unk-float005            float)
   (unk-float006            float)
   (unk-float007            float)
   (trickx-count            int32)
   (unk-time001             time-frame            :offset 3208)
   (hold-start-time         time-frame)
   (hold-exit-time          time-frame)
   (l2-start-time           time-frame)
   (rotyv-max               degrees)
   (rotyv                   degrees)
   (roty                    degrees)
   (roty-cum                degrees)
   (unk-deg00               degrees)
   (upper-body-rotyv-max    degrees               :offset 3260)
   (upper-body-rotyv        degrees)
   (upper-body-roty         degrees)
   (cushion-base            meters)
   (cushion-offset          meters)
   (shock-offset            meters)
   (shock-offsetv           meters)
   (shock-rotx              meters)
   (effect-part             sparticle-launch-control)
   (charge-part             sparticle-launch-control)
   (trick-count             int32)
   (trick-array             board-tricks       16)
   (trick-points-array      float              16 :offset 3368)
   (trick-list              board-tricks       16 :offset 3432)
   (charge-start-time       time-frame            :offset 3496)
   (charge-time             time-frame)
   (charge-progress         float)
   (zap-start-time          time-frame            :offset 3520)
   )
  (:methods
    (add-to-trick-list (_type_ board-tricks float) none)
    (flush-trick-list (_type_) none)
    )
  )


(deftype target-board-bank (basic)
  ((jump-height-min         meters)
   (jump-height-max         meters)
   (duck-jump-height-min    meters)
   (duck-jump-height-max    meters)
   (turn-frames             float)
   (wall-kick-window        time-frame)
   (cushion                 meters)
   (trickx-jump-height-min  meters)
   (trickx-jump-height-max  meters)
   (tricky-jump-height-min  meters)
   (tricky-jump-height-max  meters)
   (trickz-jump-height-min  meters)
   (trickz-jump-height-max  meters)
   (charge-jump-time        time-frame)
   (charge-jump-fade-time   time-frame)
   (charge-jump-height      meters)
   (zap-duration            time-frame)
   (zap-reset-time          time-frame)
   )
  )


(define *TARGET_BOARD-bank* (new 'static 'target-board-bank
                              :jump-height-min (meters 1.01)
                              :jump-height-max (meters 3.5)
                              :duck-jump-height-min (meters 2.5)
                              :duck-jump-height-max (meters 5)
                              :turn-frames 10.0
                              :wall-kick-window (seconds 0.05)
                              :cushion (meters 1)
                              :trickx-jump-height-min (meters 0.9)
                              :trickx-jump-height-max (meters 1.2)
                              :tricky-jump-height-min (meters 0.9)
                              :tricky-jump-height-max (meters 1.2)
                              :trickz-jump-height-min (meters 0.9)
                              :trickz-jump-height-max (meters 1.2)
                              :charge-jump-time (seconds 0.7)
                              :charge-jump-fade-time (seconds 0.25)
                              :charge-jump-height (meters 3.5)
                              :zap-duration (seconds 0.25)
                              :zap-reset-time (seconds 0.25)
                              )
        )

(defbehavior want-to-board? target ()
  (and (logtest? (logand (game-feature board) (-> *setting-control* user-current features)) (-> self game features))
       (or (and (cpad-pressed? (-> self control cpad number) r2)
                (or (!= *cheat-mode* 'debug)
                    (not (logtest? (-> *cpad-list* cpads (-> self control cpad number) button0-abs 0) (pad-buttons l2)))
                    )
                (not *pause-lock*)
                (time-elapsed? (-> self control time-of-last-debug-heal) (seconds 0.1))
                (>= (-> self control last-time-on-surface) (-> self control time-of-last-debug-float))
                )
           (or (-> self board latch?) (= (-> *setting-control* user-current board) 'force))
           )
       (not (focus-test? self dead hit grabbed in-head edge-grab pole flut tube board pilot mech indax teleporting))
       (or (zero? (-> self board)) (time-elapsed? (-> self board board-time) (seconds 0.5)))
       (not (logtest? (target-flags prevent-board invisible) (-> self target-flags)))
       (< (-> self board board-time) (-> self control list-time-on-ground))
       (not (logtest? (surface-flag no-board) (-> self control current-surface flags)))
       (or (not (logtest? (-> self control current-surface flags) (surface-flag duck))) (can-exit-duck? self))
       (not (and (logtest? (-> self water flags) (water-flag under-water))
                 (not (logtest? (-> self water flags) (water-flag swim-ground)))
                 )
            )
       (zero? (-> self lightjak shield-start-time))
       (not *artist-fix-visible*)
       (let ((gp-0 (new 'stack-no-clear 'collide-query)))
         (let ((s5-0 (new 'stack-no-clear 'inline-array 'sphere 3)))
           (dotimes (s4-0 3)
             ((method-of-type sphere new) (the-as symbol (-> s5-0 s4-0)) sphere)
             )
           (let ((v1-56 (new 'stack-no-clear 'vector)))
             (vector-copy! v1-56 (-> self control trans))
             (if (focus-test? self on-water)
                 (set! (-> v1-56 y) (-> self water height))
                 )
             (set! (-> s5-0 0 quad) (-> v1-56 quad))
             (+! (-> s5-0 0 y) 8192.0)
             (set! (-> s5-0 0 r) 2867.2)
             (set! (-> s5-0 1 quad) (-> v1-56 quad))
             (+! (-> s5-0 1 y) 12288.0)
             (set! (-> s5-0 1 r) 2867.2)
             (set! (-> s5-0 2 quad) (-> v1-56 quad))
             )
           (+! (-> s5-0 2 y) 16384.0)
           (set! (-> s5-0 2 r) 2867.2)
           (let ((v1-60 gp-0))
             (set! (-> v1-60 best-dist) (the-as float s5-0))
             (set! (-> v1-60 best-other-prim) (the-as collide-shape-prim 3))
             (set! (-> v1-60 collide-with)
                   (logclear
                     (-> self control root-prim prim-core collide-with)
                     (collide-spec civilian enemy vehicle-sphere projectile)
                     )
                   )
             (set! (-> v1-60 ignore-process0) #f)
             (set! (-> v1-60 ignore-process1) #f)
             (set! (-> v1-60 ignore-pat)
                   (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1)
                   )
             (set! (-> v1-60 best-my-prim) (the-as collide-shape-prim #t))
             (set! (-> v1-60 action-mask) (collide-action solid))
             )
           )
         (and (if (fill-and-probe-using-spheres *collide-cache* gp-0)
                  #f
                  #t
                  )
              (begin (set! (-> self board latch?) #t) (time-elapsed? (-> self gun gun-time) (seconds 0.4)))
              )
         )
       )
  )

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

(define *board-shadow-control*
  (new 'static 'shadow-control :settings (new 'static 'shadow-settings
                                           :center (new 'static 'vector :w (the-as float #xa))
                                           :shadow-dir (new 'static 'vector :y -1.0 :w 614400.0)
                                           :bot-plane (new 'static 'plane :y 1.0 :w 81920.0)
                                           :top-plane (new 'static 'plane :y 1.0 :w 2048.0)
                                           )
                               )
  )
