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

;; definition of type level-vis-info
(deftype level-vis-info (basic)
  ((level              symbol              :offset-assert   4)
   (from-level         symbol              :offset-assert   8)
   (from-bsp           bsp-header          :offset-assert  12)
   (flags              uint32              :offset-assert  16)
   (length             uint32              :offset-assert  20)
   (allocated-length   uint32              :offset-assert  24)
   (dictionary-length  uint32              :offset-assert  28)
   (dictionary         uint32              :offset-assert  32)
   (string-block       uint32              :offset-assert  36)
   (ramdisk            uint32              :offset-assert  40)
   (vis-bits           pointer             :offset-assert  44)
   (current-vis-string uint32              :offset-assert  48)
   (vis-string         uint32     :dynamic :offset-assert  52)
   )
  :method-count-assert 9
  :size-assert         #x34
  :flag-assert         #x900000034
  )

;; definition for method 3 of type level-vis-info
(defmethod inspect level-vis-info ((obj level-vis-info))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tlevel: ~A~%" (-> obj level))
  (format #t "~Tfrom-level: ~A~%" (-> obj from-level))
  (format #t "~Tfrom-bsp: ~A~%" (-> obj from-bsp))
  (format #t "~Tflags: #x~X~%" (-> obj flags))
  (format #t "~Tlength: ~D~%" (-> obj length))
  (format #t "~Tallocated-length: ~D~%" (-> obj allocated-length))
  (format #t "~Tdictionary-length: ~D~%" (-> obj dictionary-length))
  (format #t "~Tdictionary: #x~X~%" (-> obj dictionary))
  (format #t "~Tstring-block: #x~X~%" (-> obj string-block))
  (format #t "~Tramdisk: ~D~%" (-> obj ramdisk))
  (format #t "~Tvis-bits: #x~X~%" (-> obj vis-bits))
  (format #t "~Tcurrent-vis-string: ~D~%" (-> obj current-vis-string))
  (format #t "~Tvis-string[0] @ #x~X~%" (-> obj vis-string))
  obj
  )

;; definition for method 5 of type level-vis-info
;; INFO: Return type mismatch uint vs int.
(defmethod asize-of level-vis-info ((obj level-vis-info))
  (the-as int (+ (-> level-vis-info size) (-> obj dictionary-length)))
  )

;; definition of type level-load-info
(deftype level-load-info (basic)
  ((name-list         symbol 3 :offset-assert   4)
   (index             int32    :offset-assert  16)
   (name              symbol   :offset          4)
   (visname           symbol   :offset          8)
   (nickname          symbol   :offset         12)
   (packages          pair     :offset-assert  20)
   (sound-banks       pair     :offset-assert  24)
   (music-bank        symbol   :offset-assert  28)
   (ambient-sounds    pair     :offset-assert  32)
   (mood              symbol   :offset-assert  36)
   (mood-func         symbol   :offset-assert  40)
   (ocean             symbol   :offset-assert  44)
   (sky               symbol   :offset-assert  48)
   (sun-fade          float    :offset-assert  52)
   (continues         pair     :offset-assert  56)
   (tasks             pair     :offset-assert  60)
   (priority          int32    :offset-assert  64)
   (load-commands     pair     :offset-assert  68)
   (alt-load-commands pair     :offset-assert  72)
   (bsp-mask          uint64   :offset-assert  80)
   (bsphere           sphere   :offset-assert  88)
   (buzzer            int32    :offset-assert  92)
   (bottom-height     meters   :offset-assert  96)
   (run-packages      pair     :offset-assert 100)
   (prev-level        basic    :offset-assert 104)
   (next-level        basic    :offset-assert 108)
   (wait-for-load     symbol   :offset-assert 112)
   )
  :method-count-assert 9
  :size-assert         #x74
  :flag-assert         #x900000074
  )

;; definition for method 3 of type level-load-info
(defmethod inspect level-load-info ((obj level-load-info))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tname-list[3] @ #x~X~%" (&-> obj name))
  (format #t "~Tindex: ~D~%" (-> obj index))
  (format #t "~Tname: ~A~%" (-> obj name))
  (format #t "~Tvisname: ~A~%" (-> obj visname))
  (format #t "~Tnickname: ~A~%" (-> obj nickname))
  (format #t "~Tpackages: ~A~%" (-> obj packages))
  (format #t "~Tsound-banks: ~A~%" (-> obj sound-banks))
  (format #t "~Tmusic-bank: ~A~%" (-> obj music-bank))
  (format #t "~Tambient-sounds: ~A~%" (-> obj ambient-sounds))
  (format #t "~Tmood: ~A~%" (-> obj mood))
  (format #t "~Tmood-func: ~A~%" (-> obj mood-func))
  (format #t "~Tocean: ~A~%" (-> obj ocean))
  (format #t "~Tsky: ~A~%" (-> obj sky))
  (format #t "~Tsun-fade: ~f~%" (-> obj sun-fade))
  (format #t "~Tcontinues: ~A~%" (-> obj continues))
  (format #t "~Ttasks: ~A~%" (-> obj tasks))
  (format #t "~Tpriority: ~D~%" (-> obj priority))
  (format #t "~Tload-commands: ~A~%" (-> obj load-commands))
  (format #t "~Talt-load-commands: ~A~%" (-> obj alt-load-commands))
  (format #t "~Tbsp-mask: ~D~%" (-> obj bsp-mask))
  (format #t "~Tbsphere: #<sphere @ #x~X>~%" (-> obj bsphere))
  (format #t "~Tbuzzer: ~D~%" (-> obj buzzer))
  (format #t "~Tbottom-height: (meters ~m)~%" (-> obj bottom-height))
  (format #t "~Trun-packages: ~A~%" (-> obj run-packages))
  (format #t "~Tprev-level: ~A~%" (-> obj prev-level))
  (format #t "~Tnext-level: ~A~%" (-> obj next-level))
  (format #t "~Twait-for-load: ~A~%" (-> obj wait-for-load))
  obj
  )

;; definition of type login-state
(deftype login-state (basic)
  ((state int32       :offset-assert   4)
   (pos   uint32      :offset-assert   8)
   (elts  uint32      :offset-assert  12)
   (elt   drawable 16 :offset-assert  16)
   )
  :method-count-assert 9
  :size-assert         #x50
  :flag-assert         #x900000050
  )

;; definition for method 3 of type login-state
(defmethod inspect login-state ((obj login-state))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tstate: ~D~%" (-> obj state))
  (format #t "~Tpos: ~D~%" (-> obj pos))
  (format #t "~Telts: ~D~%" (-> obj elts))
  (format #t "~Telt[16] @ #x~X~%" (-> obj elt))
  obj
  )

;; definition of type level
(deftype level (basic)
  ((name                            symbol                                           :offset-assert   4)
   (load-name                       symbol                                           :offset-assert   8)
   (nickname                        symbol                                           :offset-assert  12)
   (index                           int32                                            :offset-assert  16)
   (status                          symbol                                           :offset-assert  20)
   (other                           level                                            :offset-assert  24)
   (heap                            kheap                                  :inline   :offset-assert  32)
   (bsp                             bsp-header                                       :offset-assert  48)
   (art-group                       load-dir-art-group                               :offset-assert  52)
   (info                            level-load-info                                  :offset-assert  56)
   (texture-page                    texture-page                           9         :offset-assert  60)
   (loaded-texture-page             texture-page                           16        :offset-assert  96)
   (loaded-texture-page-count       int32                                            :offset-assert 160)
   (tfrag-tex-foreground-sink-group dma-foreground-sink-group              :inline   :offset-assert 176)
   (pris-tex-foreground-sink-group  dma-foreground-sink-group              :inline   :offset-assert 208)
   (water-tex-foreground-sink-group dma-foreground-sink-group              :inline   :offset-assert 240)
   (foreground-sink-group           dma-foreground-sink-group              3 :inline :offset        176)
   (foreground-draw-engine          engine                                 3         :offset-assert 272)
   (entity                          entity-links-array                               :offset-assert 284)
   (ambient                         entity-ambient-data-array                        :offset-assert 288)
   (closest-object                  float                                  9         :offset-assert 292)
   (upload-size                     int32                                  9         :offset-assert 328)
   (level-distance                  meters                                           :offset-assert 364)
   (inside-sphere?                  symbol                                           :offset-assert 368)
   (inside-boxes?                   symbol                                           :offset-assert 372)
   (display?                        symbol                                           :offset-assert 376)
   (meta-inside?                    symbol                                           :offset-assert 380)
   (mood                            mood-context                                     :offset-assert 384)
   (mood-func                       (function mood-context float int none)           :offset-assert 388)
   (vis-bits                        pointer                                          :offset-assert 392)
   (all-visible?                    symbol                                           :offset-assert 396)
   (force-all-visible?              symbol                                           :offset-assert 400)
   (linking                         basic                                            :offset-assert 404)
   (vis-info                        level-vis-info                         8         :offset-assert 408)
   (vis-self-index                  int32                                            :offset-assert 440)
   (vis-adj-index                   int32                                            :offset-assert 444)
   (vis-buffer                      uint8                                  2048      :offset-assert 448)
   (mem-usage-block                 memory-usage-block                               :offset-assert 2496)
   (mem-usage                       int32                                            :offset-assert 2500)
   (code-memory-start               pointer                                          :offset-assert 2504)
   (code-memory-end                 pointer                                          :offset-assert 2508)
   (texture-mask                    uint32                                 9         :offset-assert 2512)
   (force-inside?                   symbol                                           :offset-assert 2548)
   (pad                             uint8                                  56        :offset-assert 2552)
   )
  :method-count-assert 29
  :size-assert         #xa30
  :flag-assert         #x1d00000a30
  (:methods
    (deactivate (_type_) _type_ 9)
    (is-object-visible? (_type_ int) symbol 10)
    (add-irq-to-tex-buckets! (_type_) none 11)
    (unload! (_type_) _type_ 12)
    (bsp-name (_type_) symbol 13)
    (compute-memory-usage (_type_ object) memory-usage-block 14)
    (point-in-boxes? (_type_ vector) symbol 15)
    (update-vis! (_type_ level-vis-info uint uint) symbol 16)
    (load-continue (_type_) _type_ 17)
    (load-begin (_type_) _type_ 18)
    (login-begin (_type_) _type_ 19)
    (vis-load (_type_) uint 20)
    (unused-21 (_type_) none 21)
    (birth (_type_) _type_ 22)
    (level-status-set! (_type_ symbol) _type_ 23)
    (load-required-packages (_type_) _type_ 24)
    (init-vis (_type_) int 25)
    (vis-clear (_type_) int 26)
    (debug-print-splitbox (_type_ vector string) none 27)
    (art-group-get-by-name (_type_ string) art-group 28)
    )
  )

;; definition for method 3 of type level
(defmethod inspect level ((obj level))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tname: ~A~%" (-> obj name))
  (format #t "~Tload-name: ~A~%" (-> obj load-name))
  (format #t "~Tnickname: ~A~%" (-> obj nickname))
  (format #t "~Tindex: ~D~%" (-> obj index))
  (format #t "~Tstatus: ~A~%" (-> obj status))
  (format #t "~Tother: ~A~%" (-> obj other))
  (format #t "~Theap: #<kheap @ #x~X>~%" (-> obj heap))
  (format #t "~Tbsp: ~A~%" (-> obj bsp))
  (format #t "~Tart-group: ~A~%" (-> obj art-group))
  (format #t "~Tinfo: ~A~%" (-> obj info))
  (format #t "~Ttexture-page[9] @ #x~X~%" (-> obj texture-page))
  (format #t "~Tloaded-texture-page[16] @ #x~X~%" (-> obj loaded-texture-page))
  (format #t "~Tloaded-texture-page-count: ~D~%" (-> obj loaded-texture-page-count))
  (format #t "~Tforeground-sink-group[3] @ #x~X~%" (-> obj tfrag-tex-foreground-sink-group))
  (format #t "~Tforeground-draw-engine[3] @ #x~X~%" (-> obj foreground-draw-engine))
  (format #t "~Tentity: ~A~%" (-> obj entity))
  (format #t "~Tambient: ~A~%" (-> obj ambient))
  (format #t "~Tclosest-object[9] @ #x~X~%" (-> obj closest-object))
  (format #t "~Tupload-size[9] @ #x~X~%" (-> obj upload-size))
  (format #t "~Tlevel-distance: (meters ~m)~%" (-> obj level-distance))
  (format #t "~Tinside-sphere?: ~A~%" (-> obj inside-sphere?))
  (format #t "~Tinside-boxes?: ~A~%" (-> obj inside-boxes?))
  (format #t "~Tdisplay?: ~A~%" (-> obj display?))
  (format #t "~Tmeta-inside?: ~A~%" (-> obj meta-inside?))
  (format #t "~Tmood: ~A~%" (-> obj mood))
  (format #t "~Tmood-func: ~A~%" (-> obj mood-func))
  (format #t "~Tvis-bits: #x~X~%" (-> obj vis-bits))
  (format #t "~Tall-visible?: ~A~%" (-> obj all-visible?))
  (format #t "~Tforce-all-visible?: ~A~%" (-> obj force-all-visible?))
  (format #t "~Tlinking: ~A~%" (-> obj linking))
  (format #t "~Tvis-info[8] @ #x~X~%" (-> obj vis-info))
  (format #t "~Tvis-self-index: ~D~%" (-> obj vis-self-index))
  (format #t "~Tvis-adj-index: ~D~%" (-> obj vis-adj-index))
  (format #t "~Tvis-buffer[2048] @ #x~X~%" (-> obj vis-buffer))
  (format #t "~Tmem-usage-block: ~A~%" (-> obj mem-usage-block))
  (format #t "~Tmem-usage: ~D~%" (-> obj mem-usage))
  (format #t "~Tcode-memory-start: #x~X~%" (-> obj code-memory-start))
  (format #t "~Tcode-memory-end: #x~X~%" (-> obj code-memory-end))
  (format #t "~Ttexture-mask[9] @ #x~X~%" (-> obj texture-mask))
  (format #t "~Tforce-inside?: ~A~%" (-> obj force-inside?))
  obj
  )

;; definition of type level-group
(deftype level-group (basic)
  ((length           int32                  :offset-assert   4)
   (log-in-level-bsp bsp-header             :offset-assert   8)
   (loading-level    level                  :offset-assert  12)
   (entity-link      entity-links           :offset-assert  16)
   (border?          basic                  :offset-assert  20)
   (vis?             basic                  :offset-assert  24)
   (want-level       basic                  :offset-assert  28)
   (receiving-level  basic                  :offset-assert  32)
   (load-commands    pair                   :offset-assert  36)
   (play?            symbol                 :offset-assert  40)
   (_hack-pad        uint8                  :offset         90)
   (level0           level        :inline   :offset-assert  96)
   (level1           level        :inline   :offset-assert 2704)
   (level-default    level        :inline   :offset-assert 5312)
   (level            level        3 :inline :offset         96)
   (data             level        3 :inline :offset         96)
   (pad              uint32                 :offset-assert 7920)
   )
  :method-count-assert 27
  :size-assert         #x1ef4
  :flag-assert         #x1b00001ef4
  (:methods
    (level-get (_type_ symbol) level 9)
    (level-get-with-status (_type_ symbol) level 10)
    (level-get-for-use (_type_ symbol symbol) level 11)
    (activate-levels! (_type_) int 12)
    (debug-print-entities (_type_ symbol type) none 13)
    (debug-draw-actors (_type_ symbol) none 14)
    (actors-update (_type_) object 15)
    (level-update (_type_) int 16)
    (level-get-target-inside (_type_) level 17)
    (alloc-levels! (_type_ symbol) int 18)
    (load-commands-set! (_type_ pair) pair 19)
    (art-group-get-by-name (_type_ string) art-group 20)
    (load-command-get-index (_type_ symbol int) pair 21)
    (update-vis-volumes (_type_) none 22)
    (update-vis-volumes-from-nav-mesh (_type_) none 23)
    (print-volume-sizes (_type_) none 24)
    (level-status (_type_ symbol) symbol 25)
    (level-get-most-disposable (_type_) level 26)
    )
  )

;; definition for method 3 of type level-group
(defmethod inspect level-group ((obj level-group))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tlength: ~D~%" (-> obj length))
  (format #t "~Tentity-link: ~`entity-links`P~%" (-> obj entity-link))
  (format #t "~Tborder?: ~A~%" (-> obj border?))
  (format #t "~Tvis?: ~A~%" (-> obj vis?))
  (format #t "~Twant-level: ~A~%" (-> obj want-level))
  (format #t "~Treceiving-level: ~A~%" (-> obj receiving-level))
  (format #t "~Tload-commands: ~A~%" (-> obj load-commands))
  (format #t "~Tplay?: ~A~%" (-> obj play?))
  (format #t "~Tlevel[3] @ #x~X~%" (-> obj level0))
  (format #t "~Tdata[3] @ #x~X~%" (-> obj level0))
  (format #t "~Tlevel0: ~`level`P~%" (-> obj level0))
  (format #t "~Tlevel1: ~`level`P~%" (-> obj level1))
  (format #t "~Tlevel-default: ~`level`P~%" (-> obj level-default))
  obj
  )

;; failed to figure out what this is:
(if (zero? *level*)
    (set! *level*
          (new 'static 'level-group
            :length 2
            :log-in-level-bsp #f
            :loading-level #f
            :entity-link #f
            :border? #f
            :want-level #f
            :load-commands '()
            :play? #f
            :level0 (new 'static 'level
              :name #f
              :status 'inactive
              :tfrag-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group
                :sink (new 'static 'array dma-foreground-sink 3
                  (new 'static 'dma-foreground-sink :bucket (bucket-id merc-tfrag-tex0))
                  (new 'static 'generic-dma-foreground-sink :bucket (bucket-id generic-tfrag-tex0) :foreground-output-bucket 1)
                  )
                )
              :pris-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group
                :sink (new 'static 'array dma-foreground-sink 3
                  (new 'static 'dma-foreground-sink :bucket (bucket-id merc-pris0) :foreground-texture-page 1)
                  (new 'static 'generic-dma-foreground-sink
                    :bucket (bucket-id generic-pris0)
                    :foreground-texture-page 1
                    :foreground-output-bucket 1
                    )
                  )
                )
              :water-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group
                :sink (new 'static 'array dma-foreground-sink 3
                  (new 'static 'dma-foreground-sink :bucket (bucket-id merc-water0) :foreground-texture-page 2)
                  (new 'static 'generic-dma-foreground-sink
                    :bucket (bucket-id generic-water0)
                    :foreground-texture-page 2
                    :foreground-output-bucket 1
                    )
                  )
                )
              :inside-sphere? #f
              :inside-boxes? #f
              :force-inside? #f
              )
            :level1 (new 'static 'level
              :name #f
              :index 1
              :status 'inactive
              :tfrag-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group
                :sink (new 'static 'array dma-foreground-sink 3
                  (new 'static 'dma-foreground-sink :bucket (bucket-id merc-tfrag-tex1) :foreground-texture-level 1)
                  (new 'static 'generic-dma-foreground-sink
                    :bucket (bucket-id generic-tfrag-tex1)
                    :foreground-texture-level 1
                    :foreground-output-bucket 1
                    )
                  )
                )
              :pris-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group :sink (new 'static 'array dma-foreground-sink 3
                                                              (new 'static 'dma-foreground-sink
                                                                :bucket (bucket-id merc-pris1)
                                                                :foreground-texture-page 1
                                                                :foreground-texture-level 1
                                                                )
                                                              (new 'static 'generic-dma-foreground-sink
                                                                :bucket (bucket-id generic-pris1)
                                                                :foreground-texture-page 1
                                                                :foreground-texture-level 1
                                                                :foreground-output-bucket 1
                                                                )
                                                              )
                                                      )
              :water-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group :sink (new 'static 'array dma-foreground-sink 3
                                                              (new 'static 'dma-foreground-sink
                                                                :bucket (bucket-id merc-water1)
                                                                :foreground-texture-page 2
                                                                :foreground-texture-level 1
                                                                )
                                                              (new 'static 'generic-dma-foreground-sink
                                                                :bucket (bucket-id generic-water1)
                                                                :foreground-texture-page 2
                                                                :foreground-texture-level 1
                                                                :foreground-output-bucket 1
                                                                )
                                                              )
                                                      )
              :inside-sphere? #f
              :inside-boxes? #f
              :force-inside? #f
              )
            :level-default (new 'static 'level
              :name 'default
              :index 2
              :status 'reserved
              :tfrag-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group
                :sink (new 'static 'array dma-foreground-sink 3
                  (new 'static 'dma-foreground-sink :bucket (bucket-id merc-alpha-tex) :foreground-texture-level 2)
                  (new 'static 'generic-dma-foreground-sink
                    :bucket (bucket-id generic-alpha-tex)
                    :foreground-texture-level 2
                    :foreground-output-bucket 1
                    )
                  )
                )
              :pris-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group :sink (new 'static 'array dma-foreground-sink 3
                                                              (new 'static 'dma-foreground-sink
                                                                :bucket (bucket-id merc-pris-common)
                                                                :foreground-texture-page 1
                                                                :foreground-texture-level 2
                                                                )
                                                              (new 'static 'generic-dma-foreground-sink
                                                                :bucket (bucket-id generic-pris-common)
                                                                :foreground-texture-page 1
                                                                :foreground-texture-level 2
                                                                :foreground-output-bucket 1
                                                                )
                                                              )
                                                      )
              :water-tex-foreground-sink-group (new 'static 'dma-foreground-sink-group :sink (new 'static 'array dma-foreground-sink 3
                                                              (new 'static 'dma-foreground-sink
                                                                :bucket (bucket-id merc-water0)
                                                                :foreground-texture-page 2
                                                                :foreground-texture-level 2
                                                                )
                                                              (new 'static 'generic-dma-foreground-sink
                                                                :bucket (bucket-id generic-water0)
                                                                :foreground-texture-page 2
                                                                :foreground-texture-level 2
                                                                :foreground-output-bucket 1
                                                                )
                                                              )
                                                      )
              :inside-sphere? #f
              :inside-boxes? #f
              :force-inside? #f
              )
            )
          )
    )
