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

;; definition for function sky-make-sun-data
;; INFO: Return type mismatch symbol vs none.
(defun sky-make-sun-data ((arg0 sky-parms) (arg1 int) (arg2 float))
  (let* ((s4-0 (-> arg0 orbit arg1))
         (s3-0 (-> arg0 upload-data sun arg1))
         (f0-1 (- arg2 (-> s4-0 high-noon)))
         (f30-0 (* 2730.6667 f0-1))
         (f28-0 (* (sin f30-0) (-> s4-0 dist)))
         (f30-1 (cos f30-0))
         )
    (let* ((f24-0 (* f30-1 (-> s4-0 dist)))
           (f26-0 (* f24-0 (cos-rad (-> s4-0 tilt))))
           (f24-1 (* f24-0 (sin-rad (-> s4-0 tilt))))
           (f22-0 (sin-rad (-> s4-0 rise)))
           (f0-10 (cos-rad (-> s4-0 rise)))
           )
      (set! (-> s3-0 pos z) (- (+ (* f28-0 f0-10) (* f24-1 f22-0))))
      (set! (-> s3-0 pos y) f26-0)
      (set! (-> s3-0 pos x) (- (* f24-1 f0-10) (* f28-0 f22-0)))
      )
    (let ((f0-14 (if (< f30-1 0.0)
                     0.0
                     f30-1
                     )
                 )
          )
      (set! (-> arg0 upload-data sun arg1 r-aurora)
            (+ (* (-> s4-0 min-halo) (- 1.0 f0-14)) (* (-> s4-0 max-halo) f0-14))
            )
      )
    )
  (none)
  )

;; definition for function sky-make-moon-data
;; INFO: Return type mismatch symbol vs none.
(defun sky-make-moon-data ((arg0 sky-parms) (arg1 float))
  (let* ((s5-0 (-> arg0 orbit 2))
         (gp-0 (-> arg0 upload-data moon))
         (f0-1 (- arg1 (-> s5-0 high-noon)))
         (f28-0 (* 2730.6667 f0-1))
         (f30-0 (* (sin f28-0) (-> s5-0 dist)))
         (f26-0 (* (cos f28-0) (-> s5-0 dist)))
         (f28-1 (* f26-0 (cos-rad (-> s5-0 tilt))))
         (f26-1 (* f26-0 (sin-rad (-> s5-0 tilt))))
         (f24-0 (sin-rad (-> s5-0 rise)))
         (f0-10 (cos-rad (-> s5-0 rise)))
         )
    (set! (-> gp-0 pos z) (- (+ (* f30-0 f0-10) (* f26-1 f24-0))))
    (set! (-> gp-0 pos y) f28-1)
    (set! (-> gp-0 pos x) (- (* f26-1 f0-10) (* f30-0 f24-0)))
    )
  (none)
  )

;; definition for function sky-make-light
;; INFO: Return type mismatch light vs none.
(defun sky-make-light ((arg0 sky-parms) (arg1 light) (arg2 int) (arg3 rgba))
  (let* ((v1-2 (-> arg0 orbit arg2))
         (a0-1 (if (= arg2 2)
                   (-> arg0 upload-data moon)
                   (-> arg0 upload-data sun arg2)
                   )
               )
         (f0-0 0.003921569)
         (f1-1 (/ 1.0 (-> v1-2 dist)))
         (v1-3 arg1)
         )
    (set! (-> v1-3 direction x) (* (-> (the-as sky-sun-data a0-1) pos x) f1-1))
    (set! (-> v1-3 direction y) (* (-> (the-as sky-sun-data a0-1) pos y) f1-1))
    (set! (-> v1-3 direction z) (* (-> (the-as sky-sun-data a0-1) pos z) f1-1))
    (set! (-> v1-3 color x) (* (the float (-> arg3 r)) f0-0))
    (set! (-> v1-3 color y) (* (the float (-> arg3 g)) f0-0))
    (set! (-> v1-3 color z) (* (the float (-> arg3 b)) f0-0))
    (set! (-> v1-3 color w) 1.0)
    (set! (-> v1-3 levels x) 1.0)
    )
  (none)
  )

;; definition of type sky-frame-data
(deftype sky-frame-data (structure)
  ((data              uint128 18      :offset-assert   0)
   (world-homo-matrix matrix  :inline :offset          0)
   (hmge-scale        vector  :inline :offset         64)
   (hvdf-offset       vector  :inline :offset         80)
   (consts            vector  :inline :offset         96)
   (pfog0             float           :offset         96)
   (radius            float           :offset        100)
   (nokick            float           :offset        108)
   (strip-giftag      qword   :inline :offset        112)
   (col-adgif         qword   :inline :offset        128)
   (save              uint128 5       :offset        144)
   (sun-fan-giftag    qword   :inline :offset        224)
   (sun-strip-giftag  qword   :inline :offset        240)
   (sun-alpha         qword   :inline :offset        256)
   (sun-alpha-giftag  qword   :inline :offset        272)
   )
  :method-count-assert 9
  :size-assert         #x120
  :flag-assert         #x900000120
  )

;; definition for method 3 of type sky-frame-data
(defmethod inspect sky-frame-data ((obj sky-frame-data))
  (format #t "[~8x] ~A~%" obj 'sky-frame-data)
  (format #t "~Tdata[18] @ #x~X~%" (-> obj data))
  (format #t "~Tworld-homo-matrix: #<matrix @ #x~X>~%" (-> obj data))
  (format #t "~Thmge-scale: #<vector @ #x~X>~%" (-> obj hmge-scale))
  (format #t "~Thvdf-offset: #<vector @ #x~X>~%" (-> obj hvdf-offset))
  (format #t "~Tconsts: #<vector @ #x~X>~%" (-> obj consts))
  (format #t "~Tpfog0: ~f~%" (-> obj consts x))
  (format #t "~Tradius: ~f~%" (-> obj consts y))
  (format #t "~Tnokick: ~f~%" (-> obj consts w))
  (format #t "~Tstrip-giftag: #<qword @ #x~X>~%" (-> obj strip-giftag))
  (format #t "~Tcol-adgif: #<qword @ #x~X>~%" (-> obj col-adgif))
  (format #t "~Tsave[5] @ #x~X~%" (-> obj save))
  (format #t "~Tsun-fan-giftag: #<qword @ #x~X>~%" (-> obj sun-fan-giftag))
  (format #t "~Tsun-strip-giftag: #<qword @ #x~X>~%" (-> obj sun-strip-giftag))
  (format #t "~Tsun-alpha: #<qword @ #x~X>~%" (-> obj sun-alpha))
  (format #t "~Tsun-alpha-giftag: #<qword @ #x~X>~%" (-> obj sun-alpha-giftag))
  obj
  )

;; definition for symbol sky-vu1-block, type vu-function
(define sky-vu1-block (new 'static 'vu-function :length #xcd :qlength #x67))

;; definition for function sky-init-upload-data
;; ERROR: function has no type analysis. Cannot decompile.

;; definition for function sky-add-frame-data
;; ERROR: function has no type analysis. Cannot decompile.

;; definition for function sky-upload
;; ERROR: function has no type analysis. Cannot decompile.

;; definition for function sky-draw
;; ERROR: Type Propagation failed: Failed type prop at op 12 ((set! a0 (+ a0 16))): Cannot get_type_int2: (+ a0 16), args float and <integer 16>
;; ERROR: Type Propagation failed: Type analysis failed
(defun sky-draw ((a0-0 sky-parms))
  (local-vars
    (v0-0 none)
    (v1-0 sky-parms)
    (a0-1 float)
    (a0-2 none)
    (a1-0 int)
    (a1-1 int)
    (a1-2 int)
    (a1-3 int)
    (a2-0 int)
    (a2-1 int)
    (a2-2 int)
    )
  (set! v1-0 a0-0)
  (set! a0-1 (-> v1-0 orbit 0 tilt))
  (set! a1-0 #x10000000)
  (s.d! a0-1 a1-0)
  (set! a1-1 #x15000000)
  (set! a2-0 191)
  (set! a2-1 (sll a2-0 48))
  (set! a2-2 (srl a2-1 48))
  (set! a1-2 (logior a1-1 a2-2))
  (s.w! (+ a0-1 8) a1-2)
  (set! a1-3 #x10000000)
  (s.w! (+ a0-1 12) a1-3)
  (set! a0-2 (the-as none (+ a0-1 16)))
  (s.w! (+ v1-0 4) a0-2)
  (set! v0-0 (the-as none 0))
  (ret-none)
  )

;; failed to figure out what this is:
(sky-set-sun-radii *sky-parms* 0 60.0 200.0 300.0)

;; failed to figure out what this is:
(sky-set-sun-radii *sky-parms* 1 15.0 20.0 300.0)

;; failed to figure out what this is:
(sky-set-sun-colors
  *sky-parms*
  1
  (new 'static 'rgba :r #xc2 :g #xfe :b #x78 :a #x80)
  (new 'static 'rgba :r #xc2 :g #xfe :b #x78 :a #x80)
  (new 'static 'rgba :r #xc2 :g #xfe :b #x78 :a #x20)
  (new 'static 'rgba :r #xc2 :g #xfe :b #x78)
  )

;; failed to figure out what this is:
(sky-set-orbit *sky-parms* 0 12.5 -15.0 0.0 9950.0 300.0 300.0)

;; failed to figure out what this is:
(sky-set-orbit *sky-parms* 1 4.0 0.0 60.0 9950.0 120.0 120.0)

;; failed to figure out what this is:
(sky-set-orbit *sky-parms* 2 0.0 0.0 -10.0 9950.0 0.0 0.0)
