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

;; definition for method 8 of type drawable-ambient
;; INFO: Return type mismatch int vs drawable-ambient.
(defmethod mem-usage drawable-ambient ((obj drawable-ambient) (arg0 memory-usage-block) (arg1 int))
  (set! (-> arg0 length) (max 50 (-> arg0 length)))
  (set! (-> arg0 data 49 name) "ambient")
  (+! (-> arg0 data 49 count) 1)
  (let ((v1-6 (asize-of obj)))
    (+! (-> arg0 data 49 used) v1-6)
    (+! (-> arg0 data 49 total) (logand -16 (+ v1-6 15)))
    )
  (mem-usage (-> obj ambient) arg0 (logior arg1 128))
  (the-as drawable-ambient 0)
  )

;; definition for method 8 of type drawable-inline-array-ambient
;; INFO: Return type mismatch int vs drawable-inline-array-ambient.
(defmethod mem-usage drawable-inline-array-ambient ((obj drawable-inline-array-ambient) (arg0 memory-usage-block) (arg1 int))
  (set! (-> arg0 length) (max 1 (-> arg0 length)))
  (set! (-> arg0 data 0 name) (symbol->string 'drawable-group))
  (+! (-> arg0 data 0 count) 1)
  (let ((v1-7 32))
    (+! (-> arg0 data 0 used) v1-7)
    (+! (-> arg0 data 0 total) (logand -16 (+ v1-7 15)))
    )
  (dotimes (s3-0 (-> obj length))
    (mem-usage (-> obj data s3-0) arg0 arg1)
    )
  (the-as drawable-inline-array-ambient 0)
  )

;; definition for symbol *hint-semaphore*, type (pointer level-hint)
(define *hint-semaphore* (the-as (pointer level-hint) #f))

;; definition for function level-hint-process-cmd
(defun level-hint-process-cmd ((arg0 (pointer int32)) (arg1 int) (arg2 int))
  (let ((v1-2 (-> arg0 arg1))
        (gp-0 (+ arg1 1))
        )
    (cond
      ((< gp-0 arg2)
       (let ((a0-2 (-> arg0 gp-0))
             (a1-2 v1-2)
             )
         (cond
           ((zero? a1-2)
            (if (task-known? (the-as game-task a0-2))
                (set! gp-0 -1)
                )
            )
           ((= a1-2 1)
            (if (not (task-known? (the-as game-task a0-2)))
                (set! gp-0 -1)
                )
            )
           ((= a1-2 2)
            (if (nonzero? (get-task-status (the-as game-task a0-2)))
                (set! gp-0 -1)
                )
            )
           ((= a1-2 3)
            (if (!= (get-task-status (the-as game-task a0-2)) (task-status need-introduction))
                (set! gp-0 -1)
                )
            )
           ((= a1-2 4)
            (if (!= (get-task-status (the-as game-task a0-2)) (task-status need-reminder))
                (set! gp-0 -1)
                )
            )
           ((= a1-2 5)
            (if (!= (get-task-status (the-as game-task a0-2)) (task-status need-reminder-a))
                (set! gp-0 -1)
                )
            )
           ((= a1-2 13)
            (let ((v1-15 (get-task-status (the-as game-task a0-2))))
              (if (or (< (the-as int v1-15) 2) (< 4 (the-as int v1-15)))
                  (set! gp-0 -1)
                  )
              )
            )
           ((= a1-2 6)
            (if (!= (get-task-status (the-as game-task a0-2)) (task-status need-reward-speech))
                (set! gp-0 -1)
                )
            )
           ((= a1-2 7)
            (close-specific-task! (the-as game-task a0-2) (task-status need-hint))
            )
           ((= a1-2 8)
            (close-specific-task! (the-as game-task a0-2) (task-status need-introduction))
            )
           ((= a1-2 9)
            (close-specific-task! (the-as game-task a0-2) (task-status need-reminder))
            )
           ((= a1-2 10)
            (close-specific-task! (the-as game-task a0-2) (task-status need-reminder-a))
            )
           ((= a1-2 11)
            (close-specific-task! (the-as game-task a0-2) (task-status need-reward-speech))
            )
           ((= a1-2 12)
            (close-specific-task! (the-as game-task a0-2) (task-status need-resolution))
            )
           (else
             (format #t "Unknown hint command ~D~%" v1-2)
             )
           )
         )
       )
      (else
        (format #t "Missing task ID for hint command ~S~%" (cond
                                                             ((= v1-2 13)
                                                              "if-at-most-need-reminder-a"
                                                              )
                                                             ((= v1-2 12)
                                                              "close-need-resolution"
                                                              )
                                                             ((= v1-2 11)
                                                              "close-need-reward-speech"
                                                              )
                                                             ((= v1-2 10)
                                                              "close-need-reminder-a"
                                                              )
                                                             ((= v1-2 9)
                                                              "close-need-reminder"
                                                              )
                                                             ((= v1-2 8)
                                                              "close-need-introduction"
                                                              )
                                                             ((= v1-2 7)
                                                              "close-need-hint"
                                                              )
                                                             ((= v1-2 6)
                                                              "if-need-reward-speech"
                                                              )
                                                             ((= v1-2 5)
                                                              "if-need-reminder-a"
                                                              )
                                                             ((= v1-2 4)
                                                              "if-need-reminder"
                                                              )
                                                             ((= v1-2 3)
                                                              "if-need-introduction"
                                                              )
                                                             ((= v1-2 2)
                                                              "if-resolved"
                                                              )
                                                             ((= v1-2 1)
                                                              "if-known"
                                                              )
                                                             ((zero? v1-2)
                                                              "if-unknown"
                                                              )
                                                             (else
                                                               "*unknown*"
                                                               )
                                                             )
                )
        )
      )
    gp-0
    )
  )

;; definition for function level-hint-task-process
;; INFO: Used lq/sq
(defun level-hint-task-process ((arg0 entity) (arg1 uint128) (arg2 string))
  (local-vars (sv-16 res-tag))
  (let ((gp-0 (res-lump-value arg0 'text-id int :default arg1))
        (s5-0 0)
        )
    (cond
      ((can-hint-be-played? (the-as game-text-id gp-0) arg0 arg2)
       (set! sv-16 (new 'static 'res-tag))
       (let ((s4-1 ((method-of-type res-lump get-property-data)
                    arg0
                    'cmds
                    'exact
                    -1000000000.0
                    (the-as pointer #f)
                    (& sv-16)
                    *res-static-buf*
                    )
                   )
             )
         (when s4-1
           (while (and (>= s5-0 0) (< s5-0 (the-as int (-> sv-16 elt-count))))
             (set! s5-0 (level-hint-process-cmd (the-as (pointer int32) s4-1) s5-0 (the-as int (-> sv-16 elt-count))))
             (if (>= s5-0 0)
                 (set! s5-0 (+ s5-0 1))
                 )
             )
           )
         )
       0
       )
      (else
        (set! s5-0 -1)
        )
      )
    (cond
      ((>= s5-0 0)
       (empty)
       gp-0
       )
      (else
        -1
        )
      )
    )
  )

;; definition for function level-hint-surpress!
;; INFO: Return type mismatch int vs none.
(defun level-hint-surpress! ()
  (set! (-> *game-info* hint-play-time) (-> *display* base-frame-counter))
  0
  (none)
  )

;; definition for function can-grab-display?
(defun can-grab-display? ((arg0 process))
  (let ((v1-2 (handle->process (-> *game-info* display-text-handle))))
    (when (and (or (not v1-2)
                   (= v1-2 arg0)
                   (>= (- (-> *display* base-frame-counter) (-> *game-info* display-text-time)) (seconds 0.1))
                   )
               (and *target*
                    (!= (-> *target* next-state name) 'target-look-around)
                    (zero? (logand (-> *target* state-flags) (state-flags being-attacked dying)))
                    (= *master-mode* 'game)
                    )
               )
      (set! (-> *game-info* display-text-handle) (process->handle arg0))
      (set! (-> *game-info* display-text-time) (-> *display* base-frame-counter))
      #t
      )
    )
  )

;; definition for function level-hint-displayed?
;; INFO: Return type mismatch basic vs symbol.
(defun level-hint-displayed? ()
  (let ((a0-0 (ppointer->process *hint-semaphore*)))
    (the-as
      symbol
      (and (the-as level-hint a0-0) (and (= (-> (the-as level-hint a0-0) next-state name) 'level-hint-normal)
                                         (not (appeared-for-long-enough? (the-as level-hint a0-0)))
                                         )
           )
      )
    )
  )

;; definition for function level-hint-spawn
;; INFO: Return type mismatch int vs none.
(defun level-hint-spawn ((arg0 game-text-id) (arg1 string) (arg2 entity) (arg3 process-tree) (arg4 game-task))
  (if (< (the-as uint 1) (the-as uint arg4))
      (close-specific-task! arg4 (task-status need-hint))
      )
  (let ((s3-1 (level-hint-task-process arg2 (the-as uint128 arg0) arg1)))
    (when (!= s3-1 -1)
      (kill-current-level-hint '() '() 'exit)
      (process-spawn level-hint s3-1 arg1 arg2 :to arg3)
      )
    )
  0
  (none)
  )

;; definition for function ambient-hint-spawn
;; INFO: Return type mismatch (pointer process) vs object.
(defun ambient-hint-spawn ((arg0 string) (arg1 vector) (arg2 process-tree) (arg3 symbol))
  (case arg3
    (('camera)
     (kill-current-level-hint '() '() 'exit)
     )
    )
  (the-as object (and (not *hint-semaphore*)
                      (process-spawn level-hint :init ambient-hint-init-by-other arg0 arg1 arg3 :to arg2)
                      )
          )
  )

;; definition for function kill-current-level-hint
;; INFO: Return type mismatch int vs none.
(defun kill-current-level-hint ((arg0 pair) (arg1 pair) (arg2 symbol))
  (when *hint-semaphore*
    (let ((s4-0 (ppointer->process *hint-semaphore*)))
      (if (and (or (null? arg0) (member (-> (the-as level-hint s4-0) mode) arg0))
               (not (member (-> (the-as level-hint s4-0) mode) arg1))
               )
          (send-event (the-as level-hint s4-0) arg2)
          )
      )
    )
  0
  (none)
  )

;; definition for function level-hint-init-by-other
;; INFO: Return type mismatch int vs none.
(defbehavior level-hint-init-by-other level-hint ((arg0 game-text-id) (arg1 string) (arg2 entity))
  (mark-text-as-seen *game-info* arg0)
  (set! (-> self text-id-to-display) arg0)
  (set! (-> self sound-to-play) arg1)
  (set! (-> self total-time) 0)
  (set! (-> self total-off-time) 0)
  (set! (-> self last-time) (-> *display* base-frame-counter))
  (set! *hint-semaphore* (the-as (pointer level-hint) (process->ppointer self)))
  (add-setting! 'hint (process->ppointer self) 0.0 0)
  (set! (-> self voicebox) (the-as handle #f))
  (let ((s5-1 (res-lump-struct arg2 'play-mode structure))
        (a0-6 (the-as string ((method-of-type res-lump get-property-struct)
                              arg2
                              'sound-name
                              'interp
                              -1000000000.0
                              (-> self sound-to-play)
                              (the-as (pointer res-tag) #f)
                              *res-static-buf*
                              )
                      )
              )
        )
    (if (and (not s5-1) a0-6)
        (set! s5-1 (if (or (and (= (-> a0-6 data 0) 115) (= (-> a0-6 data 1) 97))
                           (and (= (-> a0-6 data 0) 97) (= (-> a0-6 data 1) 115))
                           )
                       'voicebox
                       'sidekick
                       )
              )
        )
    (set! (-> self mode) (the-as symbol s5-1))
    (if (or (= s5-1 'sidekick) (= s5-1 'voicebox))
        (go level-hint-sidekick a0-6)
        )
    )
  (go level-hint-normal)
  0
  (none)
  )

;; definition for function ambient-hint-init-by-other
;; INFO: Return type mismatch int vs none.
(defbehavior ambient-hint-init-by-other level-hint ((arg0 string) (arg1 vector) (arg2 symbol))
  (set! (-> self sound-to-play) arg0)
  (set! (-> self total-time) 0)
  (set! (-> self total-off-time) 0)
  (set! (-> self last-time) (-> *display* base-frame-counter))
  (set! (-> self trans) arg1)
  (set! *hint-semaphore* (the-as (pointer level-hint) (process->ppointer self)))
  (add-setting! 'hint (process->ppointer self) 0.0 0)
  (set! (-> self mode) arg2)
  (if (or (= arg2 'camera) (= arg2 'ambient) (= arg2 'stinger))
      (add-setting! 'ambient (process->ppointer self) 0.0 0)
      )
  (apply-settings *setting-control*)
  (set! (-> self event-hook) (lambda :behavior level-hint
                               ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
                               (let ((v1-0 arg2))
                                 (the-as object (when (or (= v1-0 'die) (= v1-0 'exit))
                                                  (if (= (ppointer->process *hint-semaphore*) self)
                                                      (set! *hint-semaphore* (the-as (pointer level-hint) #f))
                                                      )
                                                  (deactivate self)
                                                  )
                                         )
                                 )
                               )
        )
  (go level-hint-ambient-sound arg0)
  0
  (none)
  )

;; definition for method 14 of type level-hint
;; INFO: Return type mismatch int vs none.
(defmethod print-text level-hint ((obj level-hint))
  (when (!= *common-text* #f)
    (let ((s5-0
            (new 'stack 'font-context *font-default-matrix* 56 160 0.0 (font-color default) (font-flags shadow kerning))
            )
          )
      (let ((v1-3 s5-0))
        (set! (-> v1-3 width) (the float 400))
        )
      (let ((v1-4 s5-0))
        (set! (-> v1-4 height) (the float 96))
        )
      (set! (-> s5-0 flags) (font-flags shadow kerning middle large))
      (print-game-text (lookup-text! *common-text* (-> obj text-id-to-display) #f) s5-0 #f 128 22)
      )
    )
  0
  (none)
  )

;; definition for method 15 of type level-hint
(defmethod appeared-for-long-enough? level-hint ((obj level-hint))
  (and (!= (-> obj next-state name) 'level-hint-sidekick) (< (seconds 5) (-> obj total-time)))
  )

;; failed to figure out what this is:
(defstate level-hint-normal (level-hint)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (cond
                       ((= v1-0 'exit)
                        (go level-hint-exit)
                        )
                       ((= v1-0 'die)
                        (deactivate self)
                        )
                       )
              )
      )
    )
  :exit (behavior ()
    (if (= (ppointer->process *hint-semaphore*) self)
        (set! *hint-semaphore* (the-as (pointer level-hint) #f))
        )
    (none)
    )
  :code (behavior ()
    (cond
      ((= (-> self text-id-to-display) (game-text-id zero))
       (if *debug-segment*
           (go level-hint-error "UNKNOWN TEXT ID" "")
           )
       )
      (else
        (while (>= (seconds 8) (-> self total-time))
          (hide-bottom-hud)
          (suspend)
          (cond
            ((and (bottom-hud-hidden?)
                  (not (paused?))
                  (not (movie?))
                  (= *master-mode* 'game)
                  (or (not *target*) (!= (-> *target* cam-user-mode) 'look-around))
                  (not (-> *hud-parts* money-all))
                  )
             (print-text self)
             (+! (-> self total-time) (- (-> *display* base-frame-counter) (-> self last-time)))
             (set! (-> self last-time) (-> *display* base-frame-counter))
             )
            (else
              (+! (-> self total-off-time) (- (-> *display* base-frame-counter) (-> self last-time)))
              (if (or (< (seconds 6) (-> self total-time)) (< (seconds 10) (-> self total-off-time)))
                  (go level-hint-exit)
                  )
              )
            )
          (set! (-> self last-time) (-> *display* base-frame-counter))
          )
        )
      )
    (go level-hint-exit)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate level-hint-sidekick (level-hint)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (cond
                       ((= v1-0 'exit)
                        (when (nonzero? (-> self sound-id))
                          (sound-stop (-> self sound-id))
                          (set! (-> self sound-id) (new 'static 'sound-id))
                          0
                          )
                        (go level-hint-exit)
                        )
                       ((= v1-0 'die)
                        (deactivate self)
                        )
                       )
              )
      )
    )
  :exit (behavior ()
    (if (nonzero? (-> self sound-id))
        (sound-stop (-> self sound-id))
        )
    (remove-setting! 'music-volume)
    (remove-setting! 'sfx-volume)
    (remove-setting! 'dialog-volume)
    (if (= (ppointer->process *hint-semaphore*) self)
        (set! *hint-semaphore* (the-as (pointer level-hint) #f))
        )
    (send-event (handle->process (-> self voicebox)) 'die)
    (none)
    )
  :code (behavior ((arg0 string))
    (when (and (-> *setting-control* current play-hints) (< 0.0 (-> *setting-control* current dialog-volume)))
      (case (-> self mode)
        (('voicebox)
         (if *target*
             (set! (-> self voicebox) (ppointer->handle (voicebox-spawn *target* (target-pos 0))))
             )
         )
        )
      (while (handle->process (-> *game-info* auto-save-proc))
        (suspend)
        )
      (while (not *sound-player-enable*)
        (suspend)
        )
      (let ((s5-1 sound-play-by-name)
            (s4-1 string->sound-name)
            )
        (format (clear *temp-string*) "spool-~S" arg0)
        (let ((s5-2 (s5-1 (s4-1 *temp-string*) (new-sound-id) 1024 0 0 (sound-group sfx) #t)))
          (set! (-> self sound-id) s5-2)
          (let ((s4-3 (-> *display* base-frame-counter)))
            (while (and (!= (current-str-id) s5-2) (< (- (-> *display* base-frame-counter) s4-3) (seconds 5)))
              (suspend)
              )
            )
          (cond
            ((= (current-str-id) s5-2)
             (add-setting! 'music-volume 'rel (-> *setting-control* current music-volume-movie) 0)
             (add-setting! 'sfx-volume 'rel (-> *setting-control* current sfx-volume-movie) 0)
             (add-setting! 'dialog-volume 'rel (-> *setting-control* current dialog-volume-hint) 0)
             (while (= (current-str-id) s5-2)
               (suspend)
               )
             )
            (else
              (go level-hint-error "NO SOUND " arg0)
              )
            )
          )
        )
      )
    (go level-hint-exit)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate level-hint-ambient-sound (level-hint)
  :event (-> level-hint-sidekick event)
  :exit (behavior ()
    (if (nonzero? (-> self sound-id))
        (sound-stop (-> self sound-id))
        )
    (remove-setting! 'music-volume)
    (remove-setting! 'sfx-volume)
    (if (= (ppointer->process *hint-semaphore*) self)
        (set! *hint-semaphore* (the-as (pointer level-hint) #f))
        )
    (none)
    )
  :code (behavior ((arg0 string))
    (while (not *sound-player-enable*)
      (suspend)
      )
    (cond
      ((-> self trans)
       (let ((s5-0 sound-play-by-name)
             (s4-0 string->sound-name)
             )
         (format (clear *temp-string*) "spool-~S" arg0)
         (set! (-> self sound-id)
               (s5-0 (s4-0 *temp-string*) (new-sound-id) 1024 1 0 (sound-group sfx) (the-as symbol (-> self trans)))
               )
         )
       )
      (else
        (let ((s5-1 sound-play-by-name)
              (s4-2 string->sound-name)
              )
          (format (clear *temp-string*) "spool-~S" arg0)
          (set! (-> self sound-id) (s5-1 (s4-2 *temp-string*) (new-sound-id) 1024 0 0 (sound-group sfx) #t))
          )
        )
      )
    (let ((s5-2 (-> *display* base-frame-counter)))
      (while (and (!= (current-str-id) (-> self sound-id)) (< (- (-> *display* base-frame-counter) s5-2) (seconds 5)))
        (suspend)
        )
      )
    (cond
      ((= (current-str-id) (-> self sound-id))
       (when (or (= (-> self mode) 'stinger) (= (-> self mode) 'camera))
         (add-setting! 'music-volume 'rel (-> *setting-control* current music-volume-movie) 0)
         (add-setting! 'sfx-volume 'rel (-> *setting-control* current sfx-volume-movie) 0)
         )
       (while (= (current-str-id) (-> self sound-id))
         (suspend)
         )
       )
      (else
        (go level-hint-error "NO SOUND " arg0)
        )
      )
    (go level-hint-exit)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate level-hint-error (level-hint)
  :event (-> level-hint-normal event)
  :code (behavior ((arg0 string) (arg1 string))
    (remove-setting! 'hint)
    (let ((s4-0 (-> *display* base-frame-counter)))
      (until (>= (- (-> *display* base-frame-counter) s4-0) (seconds 1))
        (when (and *debug-segment* (not (paused?)) (not (str-is-playing?)) (bottom-hud-hidden?))
          (let ((s3-0
                  (new 'stack 'font-context *font-default-matrix* 56 160 0.0 (font-color default) (font-flags shadow kerning))
                  )
                )
            (let ((v1-7 s3-0))
              (set! (-> v1-7 width) (the float 400))
              )
            (let ((v1-8 s3-0))
              (set! (-> v1-8 height) (the float 96))
              )
            (set! (-> s3-0 flags) (font-flags shadow kerning middle))
            (let ((s2-0 print-game-text))
              (format (clear *temp-string*) "~S~S" arg0 arg1)
              (s2-0 *temp-string* s3-0 #f 128 22)
              )
            )
          )
        (suspend)
        )
      )
    (go level-hint-exit)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate level-hint-exit (level-hint)
  :code (behavior ()
    (if (= (ppointer->process *hint-semaphore*) self)
        (set! *hint-semaphore* (the-as (pointer level-hint) #f))
        )
    (none)
    )
  )

;; definition for function ambient-type-error
;; INFO: Return type mismatch int vs none.
(defun ambient-type-error ((arg0 drawable-ambient) (arg1 vector))
  (when *display-entity-errors*
    (let ((s2-0 (-> arg0 ambient)))
      (format
        (clear *temp-string*)
        "~2j~s art error for ~s ~s"
        (res-lump-struct s2-0 'effect-name structure :time 0.0)
        (res-lump-struct s2-0 'type structure)
        (res-lump-struct s2-0 'name structure)
        )
      )
    *temp-string*
    (add-debug-text-3d
      #t
      (bucket-id debug-no-zbuf)
      *temp-string*
      (-> arg0 bsphere)
      (font-color orange-red)
      (the-as vector2h #f)
      )
    )
  0
  (none)
  )

;; definition for function ambient-type-poi
;; INFO: Return type mismatch int vs none.
(defun ambient-type-poi ((arg0 drawable-ambient) (arg1 vector))
  0
  (none)
  )

;; definition for function ambient-type-hint
;; INFO: Return type mismatch int vs none.
(defun ambient-type-hint ((arg0 drawable-ambient) (arg1 vector))
  (with-pp
    (let ((s5-0 (level-hint-task-process (-> arg0 ambient) (the-as uint128 0) (the-as string #f))))
      (cond
        ((zero? s5-0)
         (when (and *debug-segment* (not (paused?)) (not (str-is-playing?)) (bottom-hud-hidden?))
           (let ((a1-3
                   (new 'stack 'font-context *font-default-matrix* 56 160 0.0 (font-color default) (font-flags shadow kerning))
                   )
                 )
             (let ((v1-5 a1-3))
               (set! (-> v1-5 width) (the float 400))
               )
             (let ((v1-6 a1-3))
               (set! (-> v1-6 height) (the float 96))
               )
             (set! (-> a1-3 flags) (font-flags shadow kerning middle large))
             (print-game-text "AS: UNKNOWN ID" a1-3 #f 128 22)
             )
           )
         )
        ((!= s5-0 -1)
         (kill-current-level-hint '() '() 'exit)
         (process-spawn level-hint s5-0 #f (-> arg0 ambient) :to pp)
         )
        )
      )
    0
    (none)
    )
  )

;; definition for function ambient-type-sound
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defun ambient-type-sound ((arg0 drawable-ambient) (arg1 vector))
  (local-vars (sv-16 string) (sv-112 res-tag))
  (let* ((s5-0 (-> arg0 ambient))
         (s4-0 (-> s5-0 ambient-data user-uint64 0))
         )
    (when (>= (-> *display* base-frame-counter) (the-as time-frame s4-0))
      (let ((v1-5 (res-lump-data s5-0 'cycle-speed pointer)))
        (set! (-> s5-0 ambient-data user-uint64 0)
              (the-as uint (+ (-> *display* base-frame-counter)
                              (the int (* 300.0 (-> (the-as (pointer float) v1-5) 0)))
                              (rand-vu-int-count (the int (* 300.0 (-> (the-as (pointer float) v1-5) 1))))
                              )
                      )
              )
        )
      (when (< (the-as uint (- (-> *display* base-frame-counter) (the-as int s4-0))) (the-as uint 300))
        (let ((f30-0 (the float (rand-vu-int-count (the-as int (-> s5-0 ambient-data user-float 2))))))
          (set! sv-16 (symbol->string (res-lump-struct s5-0 'effect-name symbol :time f30-0)))
          (let ((s4-2 (new 'stack 'sound-spec)))
            (set! (-> s4-2 sound-name) (string->sound-name sv-16))
            (logior! (-> s4-2 mask) (sound-mask volume))
            (set! (-> s4-2 volume) 1024)
            (logior! (-> s4-2 mask) (sound-mask bend))
            (set! (-> s4-2 bend) (the int (* 327.66998 (rand-vu-float-range -100.0 100.0))))
            (set! sv-112 (new 'static 'res-tag))
            (let ((a1-7 ((method-of-type res-lump get-property-data)
                         s5-0
                         'effect-param
                         'exact
                         f30-0
                         (the-as pointer #f)
                         (& sv-112)
                         *res-static-buf*
                         )
                        )
                  )
              (if a1-7
                  (effect-param->sound-spec s4-2 (the-as (pointer float) a1-7) (the-as int (-> sv-112 elt-count)))
                  )
              )
            (when *debug-effect-control*
              (format
                #t
                "(~5D) effect sound ~A ~S "
                (-> *display* base-frame-counter)
                (res-lump-struct s5-0 'name structure)
                sv-16
                )
              (format
                #t
                "volume: ~f  pitch-mod: ~f~%"
                (* 0.09765625 (the float (-> s4-2 volume)))
                (* 0.000656168 (the float (-> s4-2 pitch-mod)))
                )
              )
            (sound-play-by-spec s4-2 (new-sound-id) (-> arg0 bsphere))
            )
          )
        )
      )
    )
  0
  (none)
  )

;; definition for function ambient-type-sound-loop
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defun ambient-type-sound-loop ((arg0 drawable-ambient) (arg1 vector))
  (let* ((s5-0 (-> arg0 ambient))
         (s2-0 (symbol->string (the-as symbol (-> s5-0 ambient-data user-float 2))))
         (s3-0 (the-as object (-> s5-0 ambient-data user-float 1)))
         (s4-0 (new 'stack 'sound-spec))
         )
    (set! (-> s4-0 sound-name) (string->sound-name s2-0))
    (logior! (-> s4-0 mask) (sound-mask volume))
    (set! (-> s4-0 volume) 1024)
    (when (the-as (pointer res-tag) s3-0)
      (let ((t9-2 effect-param->sound-spec)
            (a0-5 s4-0)
            (v1-8 (-> arg0 ambient))
            (a1-2 (-> (the-as (pointer res-tag) s3-0) 0))
            )
        (t9-2
          a0-5
          (the-as (pointer float) (&+ (-> v1-8 data-base) (-> a1-2 data-offset)))
          (the-as int (-> (the-as (pointer res-tag) s3-0) 0 elt-count))
          )
        )
      )
    (sound-play-by-spec s4-0 (the-as sound-id (-> s5-0 ambient-data user-float 0)) (-> arg0 bsphere))
    )
  0
  (none)
  )

;; definition for function ambient-type-light
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defun ambient-type-light ((arg0 drawable-ambient) (arg1 vector))
  (when *target*
    (let ((s4-0 (-> arg0 ambient))
          (s5-0 #t)
          )
      (let ((s3-0 (-> ((method-of-type res-lump lookup-tag-idx) s4-0 'vol 'exact 0.0) lo)))
        (when (>= (the-as int s3-0) 0)
          (let ((s2-0 (the-as int s3-0))
                (s1-0 (-> s4-0 tag s3-0))
                )
            0
            (while (= (-> s1-0 name) (-> s4-0 tag s3-0 name))
              (let ((v1-8 (the-as object (make-property-data s4-0 0.0 (the-as res-tag-pair s2-0) (the-as pointer #f)))))
                (set! s5-0 #t)
                (countdown (a0-6 (-> s1-0 elt-count))
                  (when (< (-> arg1 w) (- (vector-dot arg1 (-> (the-as (inline-array vector) v1-8) a0-6))
                                          (-> (the-as (inline-array vector) v1-8) a0-6 w)
                                          )
                           )
                    (set! s5-0 #f)
                    (goto cfg-9)
                    )
                  )
                )
              (label cfg-9)
              (if s5-0
                  (goto cfg-15)
                  )
              (+! s2-0 1)
              (set! s1-0 (-> s4-0 tag s2-0))
              )
            )
          )
        )
      (label cfg-15)
      (when s5-0
        )
      )
    )
  0
  (none)
  )

;; definition for function ambient-type-dark
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defun ambient-type-dark ((arg0 drawable-ambient) (arg1 vector))
  (when *target*
    (let ((s4-0 (-> arg0 ambient))
          (s5-0 #t)
          )
      (let ((s3-0 (-> ((method-of-type res-lump lookup-tag-idx) s4-0 'vol 'exact 0.0) lo)))
        (when (>= (the-as int s3-0) 0)
          (let ((s2-0 (the-as int s3-0))
                (s1-0 (-> s4-0 tag s3-0))
                )
            0
            (while (= (-> s1-0 name) (-> s4-0 tag s3-0 name))
              (let ((v1-8 (the-as object (make-property-data s4-0 0.0 (the-as res-tag-pair s2-0) (the-as pointer #f)))))
                (set! s5-0 #t)
                (countdown (a0-6 (-> s1-0 elt-count))
                  (when (< (-> arg1 w) (- (vector-dot arg1 (-> (the-as (inline-array vector) v1-8) a0-6))
                                          (-> (the-as (inline-array vector) v1-8) a0-6 w)
                                          )
                           )
                    (set! s5-0 #f)
                    (goto cfg-9)
                    )
                  )
                )
              (label cfg-9)
              (if s5-0
                  (goto cfg-15)
                  )
              (+! s2-0 1)
              (set! s1-0 (-> s4-0 tag s2-0))
              )
            )
          )
        )
      (label cfg-15)
      (if s5-0
          (set! (-> *target* draw secondary-interp) 1.0)
          )
      )
    )
  0
  (none)
  )

;; definition for function ambient-type-weather-off
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defun ambient-type-weather-off ((arg0 drawable-ambient) (arg1 vector))
  (when *target*
    (let ((s4-0 (-> arg0 ambient))
          (s5-0 #t)
          )
      (let ((s3-0 (-> ((method-of-type res-lump lookup-tag-idx) s4-0 'vol 'exact 0.0) lo)))
        (when (>= (the-as int s3-0) 0)
          (let ((s2-0 (the-as int s3-0))
                (s1-0 (-> s4-0 tag s3-0))
                )
            0
            (while (= (-> s1-0 name) (-> s4-0 tag s3-0 name))
              (let ((v1-8 (the-as object (make-property-data s4-0 0.0 (the-as res-tag-pair s2-0) (the-as pointer #f)))))
                (set! s5-0 #t)
                (countdown (a0-6 (-> s1-0 elt-count))
                  (when (< (-> arg1 w) (- (vector-dot arg1 (-> (the-as (inline-array vector) v1-8) a0-6))
                                          (-> (the-as (inline-array vector) v1-8) a0-6 w)
                                          )
                           )
                    (set! s5-0 #f)
                    (goto cfg-9)
                    )
                  )
                )
              (label cfg-9)
              (if s5-0
                  (goto cfg-15)
                  )
              (+! s2-0 1)
              (set! s1-0 (-> s4-0 tag s2-0))
              )
            )
          )
        )
      (label cfg-15)
      (if s5-0
          (set! *weather-off* #t)
          )
      )
    )
  0
  (none)
  )

;; definition for function ambient-type-ocean-off
;; INFO: Return type mismatch int vs none.
(defun ambient-type-ocean-off ((arg0 drawable-ambient) (arg1 vector))
  (set! *ocean-off* #t)
  0
  (none)
  )

;; definition for function ambient-type-ocean-near-off
;; INFO: Return type mismatch int vs none.
(defun ambient-type-ocean-near-off ((arg0 drawable-ambient) (arg1 vector))
  (set! *ocean-near-off* #t)
  0
  (none)
  )

;; definition for function ambient-type-music
;; INFO: Return type mismatch int vs none.
(defun ambient-type-music ((arg0 drawable-ambient) (arg1 vector))
  (let ((gp-0 (-> arg0 ambient)))
    (if (-> gp-0 ambient-data user-float 0)
        (set! (-> *setting-control* default music) (the-as symbol (-> gp-0 ambient-data user-float 0)))
        )
    (when (nonzero? (-> gp-0 ambient-data user-float 1))
      (let ((f0-0 (res-lump-float gp-0 'priority :default 10.0)))
        (when (>= f0-0 (-> *setting-control* default sound-flava-priority))
          (set! (-> *setting-control* default sound-flava) (the-as uint (-> gp-0 ambient-data user-float 1)))
          (set! (-> *setting-control* default sound-flava-priority) f0-0)
          )
        )
      )
    )
  0
  (none)
  )

;; definition for method 17 of type drawable-ambient
;; INFO: Return type mismatch int vs none.
(defmethod collect-ambients drawable-ambient ((obj drawable-ambient) (arg0 sphere) (arg1 int) (arg2 ambient-list))
  (dotimes (s2-0 arg1)
    (when (spheres-overlap? arg0 (the-as sphere (-> obj bsphere)))
      (set! (-> arg2 items (-> arg2 num-items)) obj)
      (+! (-> arg2 num-items) 1)
      )
    (&+! obj 32)
    )
  0
  (none)
  )

;; definition for method 17 of type drawable-inline-array-ambient
;; INFO: Return type mismatch int vs none.
(defmethod collect-ambients drawable-inline-array-ambient ((obj drawable-inline-array-ambient) (arg0 sphere) (arg1 int) (arg2 ambient-list))
  (collect-ambients (the-as drawable-ambient (-> obj data)) arg0 (-> obj length) arg2)
  0
  (none)
  )

;; definition for method 17 of type drawable-tree-ambient
;; INFO: Return type mismatch int vs none.
(defmethod collect-ambients drawable-tree-ambient ((obj drawable-tree-ambient) (arg0 sphere) (arg1 int) (arg2 ambient-list))
  (collect-ambients (-> obj data 0) arg0 (-> obj length) arg2)
  0
  (none)
  )

;; definition for method 28 of type entity-ambient
;; INFO: Used lq/sq
;; INFO: Return type mismatch entity-ambient vs none.
(defmethod birth-ambient! entity-ambient ((obj entity-ambient))
  (set! (-> obj ambient-data quad) (the-as uint128 0))
  (set! (-> obj ambient-data function) ambient-type-error)
  (case (res-lump-struct obj 'type structure)
    (('sound)
     (let ((s5-0 (res-lump-struct obj 'effect-name structure :time 0.0))
           (a0-7 (res-lump-data obj 'cycle-speed pointer))
           )
       (when (and s5-0 a0-7)
         (cond
           ((>= (-> (the-as (pointer float) a0-7)) 0.0)
            (set! (-> obj ambient-data function) ambient-type-sound)
            (set! (-> obj ambient-data user-float 2) (the-as float 0))
            (let ((s5-1 (-> ((method-of-type res-lump lookup-tag-idx) obj 'effect-name 'exact 0.0) lo)))
              (when (>= (the-as int s5-1) 0)
                (let ((s4-0 (the-as int s5-1))
                      (v1-14 (-> obj tag s5-1))
                      )
                  0
                  (while (= (-> v1-14 name) (-> obj tag s5-1 name))
                    (make-property-data obj 0.0 (the-as res-tag-pair s4-0) (the-as pointer #f))
                    (set! (-> obj ambient-data user-float 2) (the-as float (+ (the-as int (-> obj ambient-data user-float 2)) 1)))
                    (+! s4-0 1)
                    (set! v1-14 (-> obj tag s4-0))
                    )
                  )
                )
              )
            )
           (else
             (set! (-> obj ambient-data user-float 0) (the-as float (new-sound-id)))
             (let ((v1-28 ((method-of-type res-lump lookup-tag-idx) obj 'effect-param 'exact 0.0)))
               (set! (-> obj ambient-data user-float 1) (the-as float (if (< (the-as int v1-28) 0)
                                                                          (the-as (pointer res-tag) #f)
                                                                          (&-> (-> obj tag) (-> v1-28 lo))
                                                                          )
                                                                )
                     )
               )
             (set! (-> obj ambient-data user-float 2) (the-as float s5-0))
             (set! (-> obj ambient-data function) ambient-type-sound-loop)
             )
           )
         )
       )
     )
    (('poi)
     (let ((s5-2 (res-lump-struct obj 'effect-name structure :time 0.0)))
       (when (res-lump-value obj 'loc-name-id uint128)
         (set! (-> obj ambient-data user-float 2) (the-as float s5-2))
         (set! (-> obj ambient-data function) ambient-type-poi)
         )
       )
     )
    (('hint)
     (let ((s5-3 (res-lump-struct obj 'effect-name structure :time 0.0)))
       (when (res-lump-value obj 'text-id uint128)
         (set! (-> obj ambient-data user-float 2) (the-as float s5-3))
         (set! (-> obj ambient-data function) ambient-type-hint)
         )
       )
     )
    (('light)
     (set! (-> obj ambient-data user-float 2) (res-lump-struct obj 'effect-name float :time 0.0))
     (set! (-> obj ambient-data function) ambient-type-light)
     )
    (('dark)
     (set! (-> obj ambient-data user-float 2) (res-lump-struct obj 'effect-name float :time 0.0))
     (set! (-> obj ambient-data function) ambient-type-dark)
     )
    (('weather-off)
     (set! (-> obj ambient-data user-float 2) (res-lump-struct obj 'effect-name float :time 0.0))
     (set! (-> obj ambient-data function) ambient-type-weather-off)
     )
    (('ocean-off)
     (set! (-> obj ambient-data user-float 2) (res-lump-struct obj 'effect-name float :time 0.0))
     (set! (-> obj ambient-data function) ambient-type-ocean-off)
     )
    (('ocean-near-off)
     (set! (-> obj ambient-data user-float 2) (res-lump-struct obj 'effect-name float :time 0.0))
     (set! (-> obj ambient-data function) ambient-type-ocean-near-off)
     )
    (('music)
     (set! (-> obj ambient-data user-float 2) (res-lump-struct obj 'effect-name float :time 0.0))
     (set! (-> obj ambient-data user-float 0) (res-lump-struct obj 'music float))
     (set! (-> obj ambient-data user-float 1) (res-lump-value obj 'flava float))
     (set! (-> obj ambient-data function) ambient-type-music)
     )
    )
  (none)
  )

;; definition for symbol *execute-ambients*, type symbol
(define *execute-ambients* #t)

;; definition for method 18 of type drawable-ambient
;; INFO: Return type mismatch int vs none.
(defmethod execute-ambient drawable-ambient ((obj drawable-ambient) (arg0 vector))
  ((-> obj ambient ambient-data function) obj arg0)
  0
  (none)
  )

;; definition (debug) for function ambient-inspect
;; ERROR: function was not converted to expressions. Cannot decompile.

;; definition for method 27 of type entity-ambient
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod draw-debug entity-ambient ((obj entity-ambient))
  (local-vars (sv-16 uint128))
  (let ((gp-0 (-> obj trans))
        (s5-0 (res-lump-struct obj 'type symbol))
        (s3-0 #f)
        )
    (cond
      ((= s5-0 'sound)
       (when *display-ambient-sound-marks*
         (add-debug-text-3d
           #t
           (bucket-id debug-no-zbuf)
           (symbol->string (res-lump-struct obj 'effect-name symbol :time 0.0))
           gp-0
           (font-color white)
           (new 'static 'vector2h :y 24)
           )
         (set! s3-0 #t)
         )
       )
      ((= s5-0 'hint)
       (when *display-ambient-hint-marks*
         (set! sv-16 (res-lump-value obj 'text-id uint128))
         (let ((s3-2 add-debug-text-3d)
               (s2-1 #t)
               (s1-1 68)
               )
           (format (clear *temp-string*) "TEXT ID #x~X" sv-16)
           (s3-2 s2-1 (the-as bucket-id s1-1) *temp-string* gp-0 (font-color white) (new 'static 'vector2h :y 24))
           )
         (set! s3-0 #t)
         )
       )
      ((= s5-0 'poi)
       (when *display-ambient-poi-marks*
         (let ((a1-7 (res-lump-value obj 'loc-name-id uint128)))
           (when (and (nonzero? a1-7) *common-text*)
             (add-debug-text-3d
               #t
               (bucket-id debug-no-zbuf)
               (lookup-text! *common-text* (the-as game-text-id a1-7) #f)
               gp-0
               (font-color white)
               (new 'static 'vector2h :y 24)
               )
             (set! s3-0 #t)
             )
           )
         )
       )
      ((= s5-0 'light)
       (if *display-ambient-light-marks*
           (set! s3-0 #t)
           )
       )
      ((= s5-0 'dark)
       (if *display-ambient-dark-marks*
           (set! s3-0 #t)
           )
       )
      ((= s5-0 'weather-off)
       (if *display-ambient-weather-off-marks*
           (set! s3-0 #t)
           )
       )
      ((= s5-0 'ocean-off)
       (if *display-ambient-ocean-off-marks*
           (set! s3-0 #t)
           )
       )
      ((= s5-0 'ocean-near-off)
       (if *display-ambient-ocean-near-off-marks*
           (set! s3-0 #t)
           )
       )
      ((= s5-0 'music)
       (if *display-ambient-music-marks*
           (set! s3-0 #t)
           )
       )
      )
    (when s3-0
      (let ((t9-10 add-debug-sphere)
            (a0-11 #t)
            (a1-9 67)
            (a2-9 gp-0)
            (a3-7 (-> gp-0 w))
            (v1-53 s5-0)
            )
        (t9-10 a0-11 (the-as bucket-id a1-9) a2-9 a3-7 (the-as rgba (cond
                                                                      ((= v1-53 'sound)
                                                                       (the-as uint #x8000ffff)
                                                                       )
                                                                      ((= v1-53 'poi)
                                                                       (the-as uint #x80ff8000)
                                                                       )
                                                                      (else
                                                                        (the-as uint #x800000ff)
                                                                        )
                                                                      )
                                                               )
               )
        )
      (add-debug-text-3d
        #t
        (bucket-id debug-no-zbuf)
        (res-lump-struct obj 'name string)
        gp-0
        (font-color white)
        (new 'static 'vector2h :y 8)
        )
      (add-debug-text-3d
        #t
        (bucket-id debug-no-zbuf)
        (symbol->string s5-0)
        gp-0
        (font-color white)
        (new 'static 'vector2h :y 16)
        )
      )
    )
  0
  (none)
  )
