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

;; definition for method 7 of type hud
;; INFO: Return type mismatch process vs hud.
(defmethod relocate hud ((obj hud) (arg0 int))
  (dotimes (v1-0 (-> obj nb-of-particles))
    (if (nonzero? (-> obj particles v1-0 part))
        (&+! (-> obj particles v1-0 part) arg0)
        )
    )
  (the-as hud ((method-of-type process relocate) obj arg0))
  )

;; definition for method 10 of type hud
(defmethod deactivate hud ((obj hud))
  (dotimes (v1-0 9)
    (if (and (-> *hud-parts* parts v1-0) (= (ppointer->process (-> *hud-parts* parts v1-0)) obj))
        (set! (-> *hud-parts* parts v1-0) (the-as (pointer hud) #f))
        )
    )
  (dotimes (s5-0 (-> obj nb-of-particles))
    (kill-and-free-particles (-> obj particles s5-0 part))
    (set! (-> obj particles s5-0 part matrix) -1)
    )
  ((method-of-type process deactivate) obj)
  (none)
  )

;; definition for method 15 of type hud
;; INFO: Return type mismatch int vs none.
(defmethod draw-hud hud ((obj hud))
  (when (and (not (hidden? obj)) (not (paused?)))
    (dotimes (s5-0 (-> obj nb-of-particles))
      (when (!= s5-0 (-> obj skip-particle))
        (if (or (!= (-> obj particles 0 pos x) 0.0) (!= (-> obj particles 0 pos y) 0.0))
            (spawn (-> obj particles s5-0 part) *null-vector*)
            )
        )
      )
    )
  0
  (none)
  )

;; definition for method 16 of type hud
;; INFO: Return type mismatch int vs none.
(defmethod tally-value hud ((obj hud) (arg0 int) (arg1 int))
  (if (= arg0 (-> obj target-value))
      (set! (-> obj last-target-equal-time) (-> *display* base-frame-counter))
      )
  (when (and (not *progress-process*)
             (and (!= (-> obj last-hide-time) (-> *display* base-frame-counter))
                  (not (movie?))
                  (>= (- (-> *display* base-frame-counter) (-> *game-info* letterbox-time)) (seconds 0.1))
                  (>= (- (-> *display* base-frame-counter) (-> *game-info* blackout-time)) (seconds 0.1))
                  (not (and *target* (logtest? (-> *target* state-flags) (state-flags grabbed))))
                  )
             )
    (when (or (!= (-> obj value) arg0)
              (!= (-> obj value2) arg1)
              (-> obj force-on-screen)
              (or (and (cpad-hold? 0 l2) (not (-> obj disable)))
                  (and (not *cheat-mode*) (cpad-hold? 0 r2))
                  (-> obj first-init)
                  )
              )
      (cond
        ((and (-> obj increment-on-event)
              (< (-> obj value) arg0)
              (not (-> obj first-init))
              (< (- (-> *display* base-frame-counter) (-> obj last-target-equal-time)) (seconds 1.5))
              )
         (when (and (!= (-> obj value) (-> obj target-value))
                    (>= (- (-> *display* base-frame-counter) (-> obj last-increment-time)) (seconds 0.1))
                    )
           (sound-play "cursor-options")
           (+! (-> obj value) 1)
           (set! (-> obj last-increment-time) (-> *display* base-frame-counter))
           )
         )
        (else
          (if (not (and (not (-> obj first-init))
                        (>= (- (-> *display* base-frame-counter) (-> obj last-target-equal-time)) (seconds 1.5))
                        )
                   )
              (set! (-> obj value) arg0)
              )
          (set! (-> obj target-value) arg0)
          (set! (-> obj last-target-equal-time) (-> *display* base-frame-counter))
          )
        )
      (set! (-> obj value2) arg1)
      (when (and (not (movie?)) (= *master-mode* 'game) (not (-> obj first-init)) (not (-> obj disable)))
        (if (>= (-> obj friend) 0)
            (send-event (ppointer->process (-> *hud-parts* parts (-> obj friend))) 'show)
            )
        (go hud-arriving)
        )
      (set! (-> obj trigger-time) (-> *display* base-frame-counter))
      (set! (-> obj first-init) #f)
      )
    )
  0
  (none)
  )

;; definition for method 17 of type hud
;; INFO: Return type mismatch int vs none.
(defmethod draw-icons hud ((obj hud))
  (dotimes (v1-0 (-> obj nb-of-icons))
    (set-vector!
      (-> obj icons v1-0 icon 0 root scale)
      (* (-> obj icons v1-0 scale-x) (-> *video-parms* relative-x-scale))
      (* (-> obj icons v1-0 scale-y) (-> *video-parms* relative-y-scale))
      (* (-> obj icons v1-0 scale-x) (-> *video-parms* relative-x-scale))
      1.0
      )
    (set! (-> obj icons v1-0 icon 0 root trans x)
          (the float (+ (-> obj icons v1-0 icon-x) -256 (* (-> obj x-sgn) (-> obj offset))))
          )
    (set! (-> obj icons v1-0 icon 0 root trans y)
          (- (+ (the float (-> obj icons v1-0 icon-y))
                (* (the float (-> obj y-sgn))
                   (the float (-> obj offset))
                   (-> *video-parms* relative-y-scale)
                   (-> *video-parms* relative-y-scale)
                   )
                (* (the float (-> obj y-offset)) (-> *video-parms* relative-x-scale-reciprical))
                )
             (the float (-> *video-parms* screen-sy))
             )
          )
    )
  0
  (none)
  )

;; definition for method 18 of type hud
;; INFO: Return type mismatch int vs none.
(defmethod draw-particles hud ((obj hud))
  (dotimes (s5-0 (-> obj nb-of-particles))
    (when (!= (-> obj skip-particle) -2)
      (set! (-> obj particles s5-0 pos x)
            (+ -256.0 (the float (* (-> obj x-sgn) (-> obj offset))) (-> obj particles s5-0 init-pos x))
            )
      (set! (-> obj particles s5-0 pos y)
            (* 0.5 (- (* (-> *video-parms* relative-y-scale)
                         (+ (-> obj particles s5-0 init-pos y)
                            (the float (* (-> obj y-sgn) (-> obj offset)))
                            (* (the float (-> obj y-offset)) (-> *video-parms* relative-x-scale-reciprical))
                            )
                         )
                      (the float (-> *video-parms* screen-sy))
                      )
               )
            )
      (set! (-> obj particles s5-0 pos z) (-> obj particles s5-0 init-pos z))
      )
    (if (> (-> obj particles s5-0 part matrix) 0)
        (set-vector!
          (sprite-get-user-hvdf (-> obj particles s5-0 part matrix))
          (the float (+ (the int (-> obj particles s5-0 pos x)) 2048))
          (the float (+ (the int (-> obj particles s5-0 pos y)) 2048))
          (- (-> *math-camera* hvdf-off z) (* 1024.0 (-> obj particles s5-0 pos z)))
          (-> *math-camera* hvdf-off w)
          )
        )
    )
  0
  (none)
  )

;; definition for method 19 of type hud
;; INFO: Return type mismatch int vs none.
(defmethod hud-update hud ((obj hud))
  0
  (none)
  )

;; definition for method 20 of type hud
;; INFO: Return type mismatch int vs none.
(defmethod init-particles! hud ((obj hud) (arg0 int))
  0
  (none)
  )

;; definition for method 21 of type hud
(defmethod get-icon-pos-x hud ((obj hud))
  0
  )

;; definition for method 22 of type hud
(defmethod get-icon-pos-y hud ((obj hud))
  0
  )

;; definition for method 25 of type hud
(defmethod get-icon-scale-x hud ((obj hud))
  0.0
  )

;; definition for method 26 of type hud
(defmethod get-icon-scale-y hud ((obj hud))
  0.0
  )

;; definition for method 24 of type hud
;; INFO: Return type mismatch int vs none.
(defmethod set-pos-and-scale hud ((obj hud) (arg0 symbol) (arg1 symbol))
  0
  (none)
  )

;; definition for method 14 of type hud
(defmethod hidden? hud ((obj hud))
  (= (-> obj next-state name) 'hud-hidden)
  )

;; failed to figure out what this is:
(defstate hud-hidden (hud)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (local-vars (v0-0 object))
    (case arg2
      (('show)
       (if (and (not *progress-process*) (!= (-> self last-hide-time) (-> *display* base-frame-counter)))
           (go hud-arriving)
           )
       )
      (('hide)
       (set! v0-0 (-> *display* base-frame-counter))
       (set! (-> self last-hide-time) (the-as time-frame v0-0))
       v0-0
       )
      (('hide-quick)
       (set! v0-0 (-> *display* base-frame-counter))
       (set! (-> self last-hide-time) (the-as time-frame v0-0))
       v0-0
       )
      (('increment)
       (set! v0-0 (+ (-> self target-value) 1))
       (set! (-> self target-value) (the-as int v0-0))
       v0-0
       )
      (('sync)
       (set! v0-0 #t)
       (set! (-> self first-init) (the-as symbol v0-0))
       v0-0
       )
      (('disable)
       (set! v0-0 #t)
       (set! (-> self disable) (the-as symbol v0-0))
       v0-0
       )
      (('enable)
       (set! (-> self disable) #f)
       #f
       )
      )
    )
  :enter (behavior ()
    (set! (-> self offset) 128)
    (draw-icons self)
    (draw-particles self)
    (let ((gp-0 (-> self child)))
      (while gp-0
        (send-event (ppointer->process gp-0) 'draw #f)
        (set! gp-0 (-> gp-0 0 brother))
        )
      )
    (dotimes (gp-1 (-> self nb-of-particles))
      (kill-and-free-particles (-> self particles gp-1 part))
      (set! (-> self particles gp-1 part matrix) -1)
      )
    (none)
    )
  :exit (behavior ()
    (set! (-> self y-offset) (-> self next-y-offset))
    (none)
    )
  :code (behavior ()
    (logior! (-> self mask) (process-mask sleep-code))
    (loop
      (suspend)
      )
    (none)
    )
  :post (behavior ()
    (if (-> self deactivate-when-hidden)
        (deactivate self)
        )
    (hud-update self)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate hud-arriving (hud)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (local-vars (v0-3 object))
    (case arg2
      (('hide-quick)
       (set! (-> self last-hide-time) (-> *display* base-frame-counter))
       (set! (-> self force-on-screen) #f)
       (set! (-> self offset) 128)
       (draw-particles self)
       (draw-icons self)
       (hud-update self)
       (go hud-hidden)
       )
      (('hide)
       (set! (-> self last-hide-time) (-> *display* base-frame-counter))
       (set! (-> self force-on-screen) #f)
       (go hud-leaving 10)
       )
      (('show)
       (if (and (not *progress-process*) (!= (-> self last-hide-time) (-> *display* base-frame-counter)))
           (go hud-arriving)
           )
       )
      (('increment)
       (set! v0-3 (+ (-> self target-value) 1))
       (set! (-> self target-value) (the-as int v0-3))
       v0-3
       )
      (('sync)
       (set! v0-3 #t)
       (set! (-> self first-init) (the-as symbol v0-3))
       v0-3
       )
      (('disable)
       (set! v0-3 #t)
       (set! (-> self disable) (the-as symbol v0-3))
       v0-3
       )
      (('enable)
       (set! (-> self disable) #f)
       #f
       )
      )
    )
  :enter (behavior ()
    (let ((gp-0 (-> self child)))
      (while gp-0
        (send-event (ppointer->process gp-0) 'draw #t)
        (set! gp-0 (-> gp-0 0 brother))
        )
      )
    (dotimes (gp-1 (-> self nb-of-particles))
      (if (= (-> self particles gp-1 part matrix) -1)
          (set! (-> self particles gp-1 part matrix) (sprite-allocate-user-hvdf))
          )
      )
    (none)
    )
  :code (behavior ()
    (loop
      (if (not (paused?))
          (seekl! (-> self offset) 0 (the int (* 15.0 (-> *display* time-adjust-ratio))))
          )
      (draw-icons self)
      (if (<= (-> self offset) 0)
          (go hud-in)
          )
      (when (movie?)
        (set! (-> self last-hide-time) (-> *display* base-frame-counter))
        (set! (-> self force-on-screen) #f)
        (set! (-> self offset) 128)
        (draw-particles self)
        (draw-icons self)
        (hud-update self)
        (go hud-hidden)
        )
      (suspend)
      )
    (none)
    )
  :post (behavior ()
    (hud-update self)
    (draw-particles self)
    (draw-hud self)
    (none)
    )
  )

;; failed to figure out what this is:
(defstate hud-in (hud)
  :event (-> hud-arriving event)
  :code (behavior ()
    (set! (-> self trigger-time) (-> *display* base-frame-counter))
    (while (and (< (- (-> *display* base-frame-counter) (-> self trigger-time)) (seconds 2)) (not (movie?)))
      (set! (-> self offset) 0)
      (draw-icons self)
      (suspend)
      )
    (when (movie?)
      (set! (-> self last-hide-time) (-> *display* base-frame-counter))
      (set! (-> self force-on-screen) #f)
      (set! (-> self offset) 128)
      (draw-particles self)
      (draw-icons self)
      (hud-update self)
      (go hud-hidden)
      )
    (go hud-leaving 5)
    (none)
    )
  :post (-> hud-arriving post)
  )

;; failed to figure out what this is:
(defstate hud-leaving (hud)
  :event (-> hud-arriving event)
  :code (behavior ((arg0 int))
    (loop
      (if (not (paused?))
          (seekl! (-> self offset) 128 (the int (* (the float arg0) (-> *display* time-adjust-ratio))))
          )
      (draw-icons self)
      (when (movie?)
        (set! (-> self last-hide-time) (-> *display* base-frame-counter))
        (set! (-> self force-on-screen) #f)
        (set! (-> self offset) 128)
        (draw-particles self)
        (draw-icons self)
        (hud-update self)
        (go hud-hidden)
        )
      (if (>= (-> self offset) 128)
          (go hud-hidden)
          )
      (suspend)
      )
    (none)
    )
  :post (-> hud-arriving post)
  )

;; definition for function hud-init-by-other
;; INFO: Return type mismatch object vs none.
(defbehavior hud-init-by-other hud ((arg0 int))
  (set! (-> self nb-of-icons) 0)
  (set! (-> self nb-of-particles) 0)
  (set! (-> self max-nb-of-particles) 7)
  (set! (-> self first-init) #t)
  (set! (-> self friend) -1)
  (set! (-> self last-increment-time) (-> *display* base-frame-counter))
  (set! (-> self last-target-equal-time) (-> *display* base-frame-counter))
  (set! (-> self increment-on-event) #f)
  (set! (-> self skip-particle) -1)
  (set! (-> self disable) #f)
  (set! (-> self force-on-screen) #f)
  (set! (-> self deactivate-when-hidden) #f)
  (set! (-> self y-offset) 0)
  (set! (-> self next-y-offset) 0)
  (set! (-> self last-hide-time) (-> *display* base-frame-counter))
  (logior! (-> self mask) (process-mask menu))
  (logclear! (-> self mask) (process-mask pause progress))
  (init-particles! self arg0)
  (draw-icons self)
  (draw-particles self)
  (go hud-hidden)
  (none)
  )

;; definition for function send-hud-increment-event
(defun send-hud-increment-event ((arg0 hud))
  (if (-> arg0 increment-on-event)
      (send-event arg0 'increment)
      )
  )

;; failed to figure out what this is:
(defstate hud-collecting (process-drawable)
  :trans (behavior ()
    (case (-> self type)
      ((fuel-cell)
       (fuel-cell-animate)
       )
      )
    (none)
    )
  :code (behavior ((arg0 handle))
    (let ((s5-0 (new 'stack-no-clear 'vector)))
      (let ((s4-0 (handle->process arg0)))
        (set! (-> s5-0 x) (- (the float (+ (get-icon-pos-x (the-as hud s4-0)) -256)) (-> self root trans x)))
        (set! (-> s5-0 y)
              (- (the float (- (get-icon-pos-y (the-as hud s4-0)) (-> *video-parms* screen-sy))) (-> self root trans y))
              )
        )
      (let ((f30-0 4.0)
            (f26-0 0.0)
            (f28-0 (-> self root scale x))
            (f24-0 (-> self root scale y))
            (f22-0 (-> self root scale z))
            )
        (loop
          (let ((f0-7 (* f30-0 (-> *display* seconds-per-frame))))
            (+! f26-0 f0-7)
            (when (< 1.0 f26-0)
              (let ((f0-8 (- f26-0 f0-7)))
                (set! f0-7 (- 1.0 f0-8))
                )
              (set! f26-0 1.0)
              )
            (+! (-> self root trans x) (* f0-7 (-> s5-0 x)))
            (+! (-> self root trans y) (* f0-7 (-> s5-0 y)))
            )
          (set-vector!
            (-> self root scale)
            (* f28-0 (-> *video-parms* relative-x-scale))
            (* f24-0 (-> *video-parms* relative-y-scale) (-> *video-parms* relative-y-scale))
            (* f22-0 (-> *video-parms* relative-x-scale))
            1.0
            )
          (let ((a0-12 (-> self root)))
            (set-yaw-angle-clear-roll-pitch!
              a0-12
              (- (y-angle a0-12) (* 182.04445 (* 8.0 (-> *display* time-adjust-ratio))))
              )
            )
          (suspend)
          (when (>= f26-0 1.0)
            (send-hud-increment-event (the-as hud (handle->process arg0)))
            (deactivate self)
            )
          )
        )
      )
    (none)
    )
  :post ja-post
  )
