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

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

(declare-type nav-control structure)
(declare-type path-control basic)
(declare-type vol-control basic)
(declare-type fact-info basic)
(declare-type actor-link-info basic)
(declare-type water-control basic)
(declare-type carry-info basic)
(declare-type rigid-body-control basic)
(declare-type touching-shapes-entry structure)

(defenum state-flags
  :bitfield #t
  :type uint32
  (sf0 0)
  (sf1 1)
  (sf2 2)
  (sf3 3)
  (sf4 4)
  (sf5 5)
  (sf6 6)
  (sf7 7)
  (sf8 8)
  (sf9 9)
  (sf10 10)
  (sf11 11)
  (sf12 12)
  (sf13 13)
  (sf14 14)
  (sf15 15)
  (sf16 16)
  (sf17 17)
  (sf18 18)
  (sf19 19)
  (sf20 20)
  (sf21 21)
  (sf22 22)
  (sf23 23)
  (sf24 24)
  (sf25 25)
  (hang 26)
  (sf27 27)
  (invisible 28)
  (sf29 29)
  (sf30 30)
  (sf31 31)
  )

(defenum attack-mask
  :bitfield #t
  :type uint32
  (trans        0) ;; 1
  (vector       1) ;; 2
  (intersection 2) ;; 4
  (attacker     3) ;; 8
  (attack-time  4) ;; 16
  (invinc-time  5) ;; 32
  (mode         6) ;; 64
  (shove-back   7) ;; 128
  (shove-up     8) ;; 256
  (speed        9) ;; 512
  (dist        10) ;; 1024
  (control     11) ;; 2048
  (angle       12) ;; 4096
  (rotate-to   13) ;; 8192
  (prev-state  14) ;; 16384
  (id          15) ;; 32768
  (count       16) ;; hi 1
  (penetrate-using 17) ;; hi 2
  (attacker-velocity 18);; hi 4
  (damage      19) ;; hi 8
  (shield-damage 20) ;; hi16
  (vehicle-damage-factor        21) ;; hi 32
  (vehicle-impulse-factor         22) ;; hi 64
  (knock 23)
  (test 24)
  )

(defmacro static-attack-info (&key (mask ()) args)
  (let ((mask-actual mask))
    (dolist (it args)
      (when (not (member (caar it) mask-actual))
        (cons! mask-actual (caar it))
        )
      )
    `(let ((atk (new 'static 'attack-info :mask (attack-mask ,@mask-actual))))
        ,@(apply (lambda (x) (if (or (eq? (car x) 'vector)
                                     (eq? (car x) 'intersection)
                                     (eq? (car x) 'attacker-velocity))
                                 `(vector-copy! (-> atk ,(car x)) ,(cadr x))
                                 `(set! (-> atk ,(car x)) ,(cadr x))
                                )) args)
        atk)
    )
  )

(defmacro new-attack-id ()
  "generate a new attack-id. TODO remove this, it's meant to be an inlined method"
  `(1+! (-> *game-info* attack-id))
  )

;; DECOMP BEGINS

(deftype process-drawable (process)
  "This is the main base class for in-game objects.
This handles drawing, collision, animation, navigation, particles, sounds, physics, etc.
The actual child classes will add most of the functionality, and this just serves as a common
container for references to the `-control` objects for this object."
  ((self         process-drawable           :override)
   (ppointer     (pointer process-drawable) :override)
   (root         trsqv)
   (node-list    cspace-array)
   (draw         draw-control)
   (skel         joint-control)
   (nav          nav-control)
   (align        align-control)
   (path         path-control)
   (vol          vol-control)
   (fact         fact-info)
   (link         actor-link-info)
   (part         sparticle-launch-control)
   (water        water-control)
   (sound        ambient-sound)
   (carry        carry-info)
   (rbody        rigid-body-control)
   (state-flags  state-flags)
   (state-time   time-frame)
   )
  (:methods
    (initialize-skeleton (_type_ skeleton-group pair) draw-control)
    (initialize-skeleton-by-name (_type_ string) draw-control)
    (apply-alignment (_type_ align-opts transformq vector) trsqv)
    (cleanup-for-death (_type_) none)
    (relocate-nav (_type_ int) none)
    (evaluate-joint-control (_type_) none)
    )
  (:states
    (process-drawable-art-error string)
    process-drawable-idle
    )
  )


(deftype process-drawable-reserved (process-drawable)
  "A process drawable with a lot of unused method slots.
GOAL cannot increase the number of methods at runtime, so, for interactive development, it is useful
to have a type with a large number of slots which can be turned into real methods without needed to reboot the PS2."
  ()
  (:methods
    (process-drawable-reserved-method-20 () none)
    (process-drawable-reserved-method-21 () none)
    (process-drawable-reserved-method-22 () none)
    (process-drawable-reserved-method-23 () none)
    (process-drawable-reserved-method-24 () none)
    (process-drawable-reserved-method-25 () none)
    (process-drawable-reserved-method-26 () none)
    (process-drawable-reserved-method-27 () none)
    (process-drawable-reserved-method-28 () none)
    (process-drawable-reserved-method-29 () none)
    (process-drawable-reserved-method-30 () none)
    (process-drawable-reserved-method-31 () none)
    (process-drawable-reserved-method-32 () none)
    (process-drawable-reserved-method-33 () none)
    (process-drawable-reserved-method-34 () none)
    (process-drawable-reserved-method-35 () none)
    (process-drawable-reserved-method-36 () none)
    (process-drawable-reserved-method-37 () none)
    (process-drawable-reserved-method-38 () none)
    (process-drawable-reserved-method-39 () none)
    (process-drawable-reserved-method-40 () none)
    (process-drawable-reserved-method-41 () none)
    (process-drawable-reserved-method-42 () none)
    (process-drawable-reserved-method-43 () none)
    (process-drawable-reserved-method-44 () none)
    (process-drawable-reserved-method-45 () none)
    (process-drawable-reserved-method-46 () none)
    (process-drawable-reserved-method-47 () none)
    (process-drawable-reserved-method-48 () none)
    (process-drawable-reserved-method-49 () none)
    (process-drawable-reserved-method-50 () none)
    (process-drawable-reserved-method-51 () none)
    (process-drawable-reserved-method-52 () none)
    (process-drawable-reserved-method-53 () none)
    (process-drawable-reserved-method-54 () none)
    (process-drawable-reserved-method-55 () none)
    (process-drawable-reserved-method-56 () none)
    (process-drawable-reserved-method-57 () none)
    (process-drawable-reserved-method-58 () none)
    (process-drawable-reserved-method-59 () none)
    (process-drawable-reserved-method-60 () none)
    (process-drawable-reserved-method-61 () none)
    (process-drawable-reserved-method-62 () none)
    (process-drawable-reserved-method-63 () none)
    (process-drawable-reserved-method-64 () none)
    (process-drawable-reserved-method-65 () none)
    (process-drawable-reserved-method-66 () none)
    (process-drawable-reserved-method-67 () none)
    (process-drawable-reserved-method-68 () none)
    (process-drawable-reserved-method-69 () none)
    (process-drawable-reserved-method-70 () none)
    (process-drawable-reserved-method-71 () none)
    (process-drawable-reserved-method-72 () none)
    (process-drawable-reserved-method-73 () none)
    (process-drawable-reserved-method-74 () none)
    (process-drawable-reserved-method-75 () none)
    (process-drawable-reserved-method-76 () none)
    (process-drawable-reserved-method-77 () none)
    (process-drawable-reserved-method-78 () none)
    (process-drawable-reserved-method-79 () none)
    (process-drawable-reserved-method-80 () none)
    (process-drawable-reserved-method-81 () none)
    (process-drawable-reserved-method-82 () none)
    (process-drawable-reserved-method-83 () none)
    (process-drawable-reserved-method-84 () none)
    (process-drawable-reserved-method-85 () none)
    (process-drawable-reserved-method-86 () none)
    (process-drawable-reserved-method-87 () none)
    (process-drawable-reserved-method-88 () none)
    (process-drawable-reserved-method-89 () none)
    (process-drawable-reserved-method-90 () none)
    (process-drawable-reserved-method-91 () none)
    (process-drawable-reserved-method-92 () none)
    (process-drawable-reserved-method-93 () none)
    (process-drawable-reserved-method-94 () none)
    (process-drawable-reserved-method-95 () none)
    (process-drawable-reserved-method-96 () none)
    (process-drawable-reserved-method-97 () none)
    (process-drawable-reserved-method-98 () none)
    (process-drawable-reserved-method-99 () none)
    (process-drawable-reserved-method-100 () none)
    (process-drawable-reserved-method-101 () none)
    (process-drawable-reserved-method-102 () none)
    (process-drawable-reserved-method-103 () none)
    (process-drawable-reserved-method-104 () none)
    (process-drawable-reserved-method-105 () none)
    (process-drawable-reserved-method-106 () none)
    (process-drawable-reserved-method-107 () none)
    (process-drawable-reserved-method-108 () none)
    (process-drawable-reserved-method-109 () none)
    (process-drawable-reserved-method-110 () none)
    (process-drawable-reserved-method-111 () none)
    (process-drawable-reserved-method-112 () none)
    (process-drawable-reserved-method-113 () none)
    (process-drawable-reserved-method-114 () none)
    (process-drawable-reserved-method-115 () none)
    (process-drawable-reserved-method-116 () none)
    (process-drawable-reserved-method-117 () none)
    (process-drawable-reserved-method-118 () none)
    (process-drawable-reserved-method-119 () none)
    (process-drawable-reserved-method-120 () none)
    (process-drawable-reserved-method-121 () none)
    (process-drawable-reserved-method-122 () none)
    (process-drawable-reserved-method-123 () none)
    (process-drawable-reserved-method-124 () none)
    (process-drawable-reserved-method-125 () none)
    (process-drawable-reserved-method-126 () none)
    (process-drawable-reserved-method-127 () none)
    (process-drawable-reserved-method-128 () none)
    (process-drawable-reserved-method-129 () none)
    (process-drawable-reserved-method-130 () none)
    (process-drawable-reserved-method-131 () none)
    (process-drawable-reserved-method-132 () none)
    (process-drawable-reserved-method-133 () none)
    (process-drawable-reserved-method-134 () none)
    (process-drawable-reserved-method-135 () none)
    (process-drawable-reserved-method-136 () none)
    (process-drawable-reserved-method-137 () none)
    (process-drawable-reserved-method-138 () none)
    (process-drawable-reserved-method-139 () none)
    (process-drawable-reserved-method-140 () none)
    (process-drawable-reserved-method-141 () none)
    (process-drawable-reserved-method-142 () none)
    (process-drawable-reserved-method-143 () none)
    (process-drawable-reserved-method-144 () none)
    (process-drawable-reserved-method-145 () none)
    (process-drawable-reserved-method-146 () none)
    (process-drawable-reserved-method-147 () none)
    (process-drawable-reserved-method-148 () none)
    (process-drawable-reserved-method-149 () none)
    (process-drawable-reserved-method-150 () none)
    (process-drawable-reserved-method-151 () none)
    (process-drawable-reserved-method-152 () none)
    (process-drawable-reserved-method-153 () none)
    (process-drawable-reserved-method-154 () none)
    (process-drawable-reserved-method-155 () none)
    (process-drawable-reserved-method-156 () none)
    (process-drawable-reserved-method-157 () none)
    (process-drawable-reserved-method-158 () none)
    (process-drawable-reserved-method-159 () none)
    (process-drawable-reserved-method-160 () none)
    (process-drawable-reserved-method-161 () none)
    (process-drawable-reserved-method-162 () none)
    (process-drawable-reserved-method-163 () none)
    (process-drawable-reserved-method-164 () none)
    (process-drawable-reserved-method-165 () none)
    (process-drawable-reserved-method-166 () none)
    (process-drawable-reserved-method-167 () none)
    (process-drawable-reserved-method-168 () none)
    (process-drawable-reserved-method-169 () none)
    (process-drawable-reserved-method-170 () none)
    (process-drawable-reserved-method-171 () none)
    (process-drawable-reserved-method-172 () none)
    (process-drawable-reserved-method-173 () none)
    (process-drawable-reserved-method-174 () none)
    (process-drawable-reserved-method-175 () none)
    (process-drawable-reserved-method-176 () none)
    (process-drawable-reserved-method-177 () none)
    (process-drawable-reserved-method-178 () none)
    (process-drawable-reserved-method-179 () none)
    (process-drawable-reserved-method-180 () none)
    (process-drawable-reserved-method-181 () none)
    (process-drawable-reserved-method-182 () none)
    (process-drawable-reserved-method-183 () none)
    (process-drawable-reserved-method-184 () none)
    (process-drawable-reserved-method-185 () none)
    (process-drawable-reserved-method-186 () none)
    (process-drawable-reserved-method-187 () none)
    (process-drawable-reserved-method-188 () none)
    (process-drawable-reserved-method-189 () none)
    (process-drawable-reserved-method-190 () none)
    (process-drawable-reserved-method-191 () none)
    (process-drawable-reserved-method-192 () none)
    (process-drawable-reserved-method-193 () none)
    (process-drawable-reserved-method-194 () none)
    (process-drawable-reserved-method-195 () none)
    (process-drawable-reserved-method-196 () none)
    (process-drawable-reserved-method-197 () none)
    (process-drawable-reserved-method-198 () none)
    (process-drawable-reserved-method-199 () none)
    (process-drawable-reserved-method-200 () none)
    (process-drawable-reserved-method-201 () none)
    (process-drawable-reserved-method-202 () none)
    (process-drawable-reserved-method-203 () none)
    (process-drawable-reserved-method-204 () none)
    (process-drawable-reserved-method-205 () none)
    (process-drawable-reserved-method-206 () none)
    (process-drawable-reserved-method-207 () none)
    (process-drawable-reserved-method-208 () none)
    (process-drawable-reserved-method-209 () none)
    (process-drawable-reserved-method-210 () none)
    (process-drawable-reserved-method-211 () none)
    (process-drawable-reserved-method-212 () none)
    (process-drawable-reserved-method-213 () none)
    (process-drawable-reserved-method-214 () none)
    (process-drawable-reserved-method-215 () none)
    (process-drawable-reserved-method-216 () none)
    (process-drawable-reserved-method-217 () none)
    )
  )


(deftype attack-dir-info (structure)
  "Information about the position/direction of an attack."
  ((dir                vector  :inline)
   (xz-dir             vector  :inline)
   (attacker-velocity  vector  :inline)
   (pos                vector  :inline)
   )
  )


(deftype attack-info (structure)
  "Information about an incoming attack."
  ((trans                   vector  :inline)
   (vector                  vector  :inline)
   (attacker-velocity       vector  :inline)
   (intersection            vector  :inline)
   (attacker                handle)
   (attack-time             time-frame)
   (invinc-time             time-frame)
   (mask                    attack-mask)
   (mode                    symbol)
   (shove-back              meters)
   (shove-up                meters)
   (speed                   meters)
   (dist                    meters)
   (control                 float)
   (angle                   symbol)
   (rotate-to               degrees)
   (prev-state              state)
   (id                      uint32)
   (count                   uint32)
   (penetrate-using         penetrate)
   (damage                  float)
   (shield-damage           float)
   (vehicle-damage-factor   float)
   (vehicle-impulse-factor  float)
   (knock                   knocked-type)
   (test                    symbol)
   )
  (:methods
    (attack-info-method-9 (_type_ attack-info process-drawable process-drawable) none)
    (compute-intersect-info (_type_ object process-drawable process touching-shapes-entry) attack-info)
    (combine! (_type_ attack-info process-drawable) attack-info)
    )
  )


(deftype ground-tween-info (structure)
  ((chan   uint8   3)
   (blend  float   3)
   (group  uint32  5)
   )
  :pack-me
  )
