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

;; name: formations.gc
;; name in dgo: formations
;; dgos: DESRESC, WWD, CWI

;; DECOMP BEGINS

(deftype formation-info (structure)
  ((composition  (array uint8))
   (layout       (array vector))
   )
  )


(deftype formation-layout (basic)
  ((formation-points      vector  10 :inline)
   (num-formation-points  int8)
   (leader-index          int8)
   (__pad                 int16)
   (scale-factor          float)
   (estimated-radius      float)
   (composition           (array uint8))
   )
  (:methods
    (init! (_type_ formation-info) none)
    )
  )


;; WARN: Return type mismatch (array uint8) vs none.
(defmethod init! ((this formation-layout) (arg0 formation-info))
  (let* ((s4-0 (-> arg0 layout))
         (v1-1 (length s4-0))
         (f0-0 0.0)
         )
    (dotimes (a0-2 v1-1)
      (vector-copy! (-> this formation-points a0-2) (-> s4-0 a0-2))
      (let* ((a1-6 (-> this formation-points a0-2))
             (f1-3 (+ (* (-> a1-6 x) (-> a1-6 x)) (* (-> a1-6 z) (-> a1-6 z))))
             )
        (if (< f0-0 f1-3)
            (set! f0-0 f1-3)
            )
        )
      )
    (set! (-> this num-formation-points) v1-1)
    (if (> v1-1 0)
        (set! (-> this estimated-radius) (sqrtf f0-0))
        )
    )
  (set! (-> this composition) (-> arg0 composition))
  (none)
  )

(define *formation-layout-cross* (new 'static 'boxed-array :type vector
                                   (new 'static 'vector :x 1.0 :w 1.0)
                                   (new 'static 'vector :z 1.0 :w 1.0)
                                   (new 'static 'vector :x -1.0 :w 1.0)
                                   (new 'static 'vector :z -1.0 :w 1.0)
                                   )
        )

(define *formation-composition-cross* (new 'static 'boxed-array :type uint8 #x1 #x2 #x1 #x1))

(define *formation-layout-wedge* (new 'static 'boxed-array :type vector
                                   (new 'static 'vector :z 1.0 :w 1.0)
                                   (new 'static 'vector :x 1.0 :w 1.0)
                                   (new 'static 'vector :x -1.0 :w 1.0)
                                   )
        )

(define *formation-composition-wedge* (new 'static 'boxed-array :type uint8 #x2 #x1 #x1))

(define *formation-list*
  (new 'static 'inline-array formation-info 2 (new 'static 'formation-info) (new 'static 'formation-info))
  )

(set! (-> *formation-list* 0 composition) *formation-composition-cross*)

(set! (-> *formation-list* 0 layout) *formation-layout-cross*)

(set! (-> *formation-list* 1 composition) *formation-composition-wedge*)

(set! (-> *formation-list* 1 layout) *formation-layout-wedge*)
