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

(local-vars (gp-0 game-info))

;; definition of type game-bank
(deftype game-bank (basic)
  ((life-max-default   float  :offset-assert   4)
   (life-start-default float  :offset-assert   8)
   (life-single-inc    float  :offset-assert  12)
   (money-task-inc     float  :offset-assert  16)
   (money-oracle-inc   float  :offset-assert  20)
   )
  :method-count-assert 9
  :size-assert         #x18
  :flag-assert         #x900000018
  )

;; definition for method 3 of type game-bank
(defmethod inspect game-bank ((obj game-bank))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tlife-max-default: ~f~%" (-> obj life-max-default))
  (format #t "~Tlife-start-default: ~f~%" (-> obj life-start-default))
  (format #t "~Tlife-single-inc: ~f~%" (-> obj life-single-inc))
  (format #t "~Tmoney-task-inc: ~f~%" (-> obj money-task-inc))
  (format #t "~Tmoney-oracle-inc: ~f~%" (-> obj money-oracle-inc))
  obj
  )

;; definition for symbol *GAME-bank*, type game-bank
(define *GAME-bank* (new 'static 'game-bank
                      :life-max-default 99.0
                      :life-start-default 5.0
                      :life-single-inc 1.0
                      :money-task-inc 90.0
                      :money-oracle-inc 120.0
                      )
        )

;; definition of type actor-id
(deftype actor-id (uint32)
  ()
  :method-count-assert 9
  :size-assert         #x4
  :flag-assert         #x900000004
  )

;; definition of type level-buffer-state
(deftype level-buffer-state (structure)
  ((name          symbol  :offset-assert   0)
   (display?      symbol  :offset-assert   4)
   (force-vis?    symbol  :offset-assert   8)
   (force-inside? symbol  :offset-assert  12)
   )
  :pack-me
  :method-count-assert 9
  :size-assert         #x10
  :flag-assert         #x900000010
  )

;; definition for method 3 of type level-buffer-state
(defmethod inspect level-buffer-state ((obj level-buffer-state))
  (format #t "[~8x] ~A~%" obj 'level-buffer-state)
  (format #t "~Tname: ~A~%" (-> obj name))
  (format #t "~Tdisplay?: ~A~%" (-> obj display?))
  (format #t "~Tforce-vis?: ~A~%" (-> obj force-vis?))
  (format #t "~Tforce-inside?: ~A~%" (-> obj force-inside?))
  obj
  )

;; definition of type load-state
(deftype load-state (basic)
  ((want          level-buffer-state 2 :inline :offset-assert   4)
   (vis-nick      symbol                       :offset-assert  36)
   (command-list  pair                         :offset-assert  40)
   (object-name   symbol             256       :offset-assert  44)
   (object-status basic              256       :offset-assert 1068)
   )
  :method-count-assert 21
  :size-assert         #x82c
  :flag-assert         #x150000082c
  (:methods
    (new (symbol type) _type_ 0)
    (reset! (_type_) _type_ 9)
    (update! (_type_) int 10)
    (want-levels (_type_ symbol symbol) int 11)
    (want-display-level (_type_ symbol symbol) int 12)
    (want-vis (_type_ symbol) int 13)
    (want-force-vis (_type_ symbol symbol) int 14)
    (execute-command (_type_ pair) none 15)
    (execute-commands-up-to (_type_ float) int 16)
    (backup-load-state-and-set-cmds (_type_ pair) int 17)
    (restore-load-state-and-cleanup (_type_) int 18)
    (restore-load-state (_type_) int 19)
    (set-force-inside! (_type_ symbol symbol) none 20)
    )
  )

;; definition for method 3 of type load-state
(defmethod inspect load-state ((obj load-state))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Twant[2] @ #x~X~%" (-> obj want))
  (format #t "~Tvis-nick: ~A~%" (-> obj vis-nick))
  (format #t "~Tcommand-list: ~A~%" (-> obj command-list))
  (format #t "~Tobject-name[256] @ #x~X~%" (-> obj object-name))
  (format #t "~Tobject-status[256] @ #x~X~%" (-> obj object-status))
  obj
  )

;; definition for method 0 of type load-state
(defmethod new load-state ((allocation symbol) (type-to-make type))
  (reset! (object-new allocation type-to-make (the-as int (-> type-to-make size))))
  )

;; definition of type continue-point
(deftype continue-point (basic)
  ((name          string                 :offset-assert   4)
   (level         symbol                 :offset-assert   8)
   (flags         continue-flags         :offset-assert  12)
   (trans         vector         :inline :offset-assert  16)
   (quat          quaternion     :inline :offset-assert  32)
   (camera-trans  vector         :inline :offset-assert  48)
   (camera-rot    float          9       :offset-assert  64)
   (load-commands pair                   :offset-assert 100)
   (vis-nick      symbol                 :offset-assert 104)
   (lev0          symbol                 :offset-assert 108)
   (disp0         symbol                 :offset-assert 112)
   (lev1          symbol                 :offset-assert 116)
   (disp1         symbol                 :offset-assert 120)
   )
  :method-count-assert 10
  :size-assert         #x7c
  :flag-assert         #xa0000007c
  (:methods
    (debug-draw! (_type_) none 9)
    )
  )

;; definition for method 3 of type continue-point
(defmethod inspect continue-point ((obj continue-point))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tname: ~A~%" (-> obj name))
  (format #t "~Tlevel: ~A~%" (-> obj level))
  (format #t "~Tflags: ~D~%" (-> obj flags))
  (format #t "~Ttrans: ~`vector`P~%" (-> obj trans))
  (format #t "~Tquat: ~`vector`P~%" (-> obj quat))
  (format #t "~Tcamera-trans: ~`vector`P~%" (-> obj camera-trans))
  (format #t "~Tcamera-rot[9] @ #x~X~%" (-> obj camera-rot))
  (format #t "~Tload-commands: ~A~%" (-> obj load-commands))
  (format #t "~Tvis-nick: ~A~%" (-> obj vis-nick))
  (format #t "~Tlev0: ~A~%" (-> obj lev0))
  (format #t "~Tdisp0: ~A~%" (-> obj disp0))
  (format #t "~Tlev1: ~A~%" (-> obj lev1))
  (format #t "~Tdisp1: ~A~%" (-> obj disp1))
  obj
  )

;; definition of type game-info
(deftype game-info (basic)
  ((mode                  symbol                             :offset-assert   4)
   (save-name             basic                              :offset-assert   8)
   (life                  float                              :offset-assert  12)
   (life-max              float                              :offset-assert  16)
   (money                 float                              :offset-assert  20)
   (money-total           float                              :offset-assert  24)
   (money-per-level       uint8                           32 :offset-assert  28)
   (deaths-per-level      uint8                           32 :offset-assert  60)
   (buzzer-total          float                              :offset-assert  92)
   (fuel                  float                              :offset-assert  96)
   (perm-list             entity-perm-array                  :offset-assert 100)
   (task-perm-list        entity-perm-array                  :offset-assert 104)
   (current-continue      continue-point                     :offset-assert 108)
   (text-ids-seen         bit-array                          :offset-assert 112)
   (level-opened          uint8                           32 :offset-assert 116)
   (hint-control          (array level-hint-control)         :offset-assert 148)
   (task-hint-control     (array task-hint-control-group)    :offset-assert 152)
   (total-deaths          int32                              :offset-assert 156)
   (continue-deaths       int32                              :offset-assert 160)
   (fuel-cell-deaths      int32                              :offset-assert 164)
   (game-start-time       time-frame                         :offset-assert 168)
   (continue-time         time-frame                         :offset-assert 176)
   (death-time            time-frame                         :offset-assert 184)
   (hit-time              time-frame                         :offset-assert 192)
   (fuel-cell-pickup-time time-frame                         :offset-assert 200)
   (fuel-cell-time        (array time-frame)                 :offset-assert 208)
   (enter-level-time      (array time-frame)                 :offset-assert 212)
   (in-level-time         (array time-frame)                 :offset-assert 216)
   (blackout-time         time-frame                         :offset-assert 224)
   (letterbox-time        time-frame                         :offset-assert 232)
   (hint-play-time        time-frame                         :offset-assert 240)
   (display-text-time     time-frame                         :offset-assert 248)
   (display-text-handle   handle                             :offset-assert 256)
   (death-movie-tick      int32                              :offset-assert 264)
   (want-auto-save        symbol                             :offset-assert 268)
   (auto-save-proc        handle                             :offset-assert 272)
   (auto-save-status      mc-status-code                     :offset-assert 280)
   (auto-save-card        int32                              :offset-assert 284)
   (auto-save-which       int32                              :offset-assert 288)
   (pov-camera-handle     handle                             :offset-assert 296)
   (other-camera-handle   handle                             :offset-assert 304)
   (death-pos             vector-array                       :offset-assert 312)
   (dummy                 basic                              :offset-assert 316)
   (auto-save-count       int32                              :offset-assert 320)
   )
  :method-count-assert 29
  :size-assert         #x144
  :flag-assert         #x1d00000144
  (:methods
    (initialize! (_type_ symbol game-save string) _type_ 9)
    (adjust (_type_ symbol float handle) float 10)
    (task-complete? (_type_ game-task) symbol 11)
    (lookup-entity-perm-by-aid (_type_ actor-id) entity-perm 12)
    (get-entity-task-perm (_type_ game-task) entity-perm 13)
    (copy-perms-from-level! (_type_ level) none 14)
    (copy-perms-to-level! (_type_ level) none 15)
    (debug-print (_type_ symbol) _type_ 16)
    (get-or-create-continue! (_type_) continue-point 17)
    (get-continue-by-name (_type_ string) continue-point 18)
    (set-continue! (_type_ basic) continue-point 19)
    (buzzer-count (_type_ game-task) int 20)
    (seen-text? (_type_ game-text-id) symbol 21)
    (mark-text-as-seen (_type_ game-text-id) none 22)
    (got-buzzer? (_type_ game-task int) symbol 23)
    (save-game! (_type_ game-save string) none 24)
    (load-game! (_type_ game-save) game-save 25)
    (clear-text-seen! (_type_ game-text-id) none 26)
    (get-death-count (_type_ symbol) int 27)
    (get-health-percent-lost (_type_ symbol) float 28)
    )
  )

;; definition for method 3 of type game-info
(defmethod inspect game-info ((obj game-info))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tmode: ~A~%" (-> obj mode))
  (format #t "~Tsave-name: ~A~%" (-> obj save-name))
  (format #t "~Tlife: ~f~%" (-> obj life))
  (format #t "~Tlife-max: ~f~%" (-> obj life-max))
  (format #t "~Tmoney: ~f~%" (-> obj money))
  (format #t "~Tmoney-total: ~f~%" (-> obj money-total))
  (format #t "~Tmoney-per-level[32] @ #x~X~%" (-> obj money-per-level))
  (format #t "~Tdeaths-per-level[32] @ #x~X~%" (-> obj deaths-per-level))
  (format #t "~Tbuzzer-total: ~f~%" (-> obj buzzer-total))
  (format #t "~Tfuel: ~f~%" (-> obj fuel))
  (format #t "~Tperm-list: ~A~%" (-> obj perm-list))
  (format #t "~Ttask-perm-list: ~A~%" (-> obj task-perm-list))
  (format #t "~Tcurrent-continue: ~A~%" (-> obj current-continue))
  (format #t "~Ttext-ids-seen: ~A~%" (-> obj text-ids-seen))
  (format #t "~Tlevel-opened[32] @ #x~X~%" (-> obj level-opened))
  (format #t "~Thint-control: ~A~%" (-> obj hint-control))
  (format #t "~Ttask-hint-control: ~A~%" (-> obj task-hint-control))
  (format #t "~Ttotal-deaths: ~D~%" (-> obj total-deaths))
  (format #t "~Tcontinue-deaths: ~D~%" (-> obj continue-deaths))
  (format #t "~Tfuel-cell-deaths: ~D~%" (-> obj fuel-cell-deaths))
  (format #t "~Tgame-start-time: ~D~%" (-> obj game-start-time))
  (format #t "~Tcontinue-time: ~D~%" (-> obj continue-time))
  (format #t "~Tdeath-time: ~D~%" (-> obj death-time))
  (format #t "~Thit-time: ~D~%" (-> obj hit-time))
  (format #t "~Tfuel-cell-pickup-time: ~D~%" (-> obj fuel-cell-pickup-time))
  (format #t "~Tfuel-cell-time: ~A~%" (-> obj fuel-cell-time))
  (format #t "~Tenter-level-time: ~A~%" (-> obj enter-level-time))
  (format #t "~Tin-level-time: ~A~%" (-> obj in-level-time))
  (format #t "~Tblackout-time: ~D~%" (-> obj blackout-time))
  (format #t "~Tletterbox-time: ~D~%" (-> obj letterbox-time))
  (format #t "~Thint-play-time: ~D~%" (-> obj hint-play-time))
  (format #t "~Tdisplay-text-time: ~D~%" (-> obj display-text-time))
  (format #t "~Tdisplay-text-handle: ~D~%" (-> obj display-text-handle))
  (format #t "~Tdeath-movie-tick: ~D~%" (-> obj death-movie-tick))
  (format #t "~Twant-auto-save: ~A~%" (-> obj want-auto-save))
  (format #t "~Tauto-save-proc: ~D~%" (-> obj auto-save-proc))
  (format #t "~Tauto-save-status: ~D~%" (-> obj auto-save-status))
  (format #t "~Tauto-save-card: ~D~%" (-> obj auto-save-card))
  (format #t "~Tauto-save-which: ~D~%" (-> obj auto-save-which))
  (format #t "~Tpov-camera-handle: ~D~%" (-> obj pov-camera-handle))
  (format #t "~Tother-camera-handle: ~D~%" (-> obj other-camera-handle))
  (format #t "~Tdeath-pos: ~A~%" (-> obj death-pos))
  (format #t "~Tdummy: ~A~%" (-> obj dummy))
  (format #t "~Tauto-save-count: ~D~%" (-> obj auto-save-count))
  obj
  )

;; failed to figure out what this is:
(set! gp-0
      (when (or (not *game-info*) (zero? *game-info*))
        (set! gp-0 (new 'static 'game-info :mode 'debug :current-continue #f))
        (set! (-> gp-0 fuel-cell-time) (the-as (array time-frame) (new 'global 'boxed-array uint64 116)))
        (set! (-> gp-0 enter-level-time) (the-as (array time-frame) (new 'global 'boxed-array uint64 32)))
        (set! (-> gp-0 in-level-time) (the-as (array time-frame) (new 'global 'boxed-array uint64 32)))
        (set! *game-info* gp-0)
        gp-0
        )
      )
