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

(import "goal_src/jak1/import/eggtop-ag.gc")
(import "goal_src/jak1/import/jng-iris-door-ag.gc")

;; definition of type eggtop
(deftype eggtop (process-drawable)
  ((root-override collide-shape-moving  :offset        112)
   (cam-tracker   handle                :offset-assert 176)
   (sound-id      sound-id              :offset-assert 184)
   )
  :heap-base #x50
  :method-count-assert 20
  :size-assert         #xbc
  :flag-assert         #x14005000bc
  (:states
    (eggtop-close symbol)
    eggtop-idle
    )
  )

;; definition for method 3 of type eggtop
(defmethod inspect eggtop ((obj eggtop))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tcam-tracker: ~D~%" (-> obj cam-tracker))
  (format #t "~T~Tsound-id: ~D~%" (-> obj sound-id))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *eggtop-sg* eggtop eggtop-lod0-jg eggtop-idle-ja
              ((eggtop-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 -4.5 0 4.5)
              )

;; failed to figure out what this is:
(defpartgroup group-jungle-blue-eco-room-open
  :id 189
  :bounds (static-bspherem 0 -6 0 8)
  :parts ((sp-item 899 :fade-after (meters 110))
    (sp-item 900 :fade-after (meters 110))
    (sp-item 901 :fade-after (meters 110))
    (sp-item 902 :fade-after (meters 110))
    (sp-item 903 :fade-after (meters 110))
    )
  )

;; failed to figure out what this is:
(defpartgroup group-jungle-blue-eco-room-activate
  :id 190
  :duration 900
  :bounds (static-bspherem 0 -6 0 8)
  :parts ((sp-item 903) (sp-item 903) (sp-item 904 :flags (bit1) :period 1200 :length 15))
  )

;; failed to figure out what this is:
(defpart 904
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x2 :page #x2))
    (sp-flt spt-num 30.0)
    (sp-flt spt-y (meters -4))
    (sp-rnd-flt spt-scale-x (meters 20) (meters 10) 1.0)
    (sp-int spt-rot-x 4)
    (sp-rnd-flt spt-rot-z (degrees 0.0) (degrees 360.0) 1.0)
    (sp-rnd-flt spt-scale-y (meters 5) (meters 2) 1.0)
    (sp-rnd-flt spt-r 0.0 16.0 1.0)
    (sp-rnd-flt spt-g 16.0 32.0 1.0)
    (sp-flt spt-b 127.0)
    (sp-flt spt-a 0.0)
    (sp-rnd-flt spt-rotvel-z (degrees -0.05) (degrees 0.1) 1.0)
    (sp-flt spt-fade-a 0.85333335)
    (sp-int spt-timer 600)
    (sp-cpuinfo-flags bit2 bit3 left-multiply-quat)
    (sp-int spt-next-time 75)
    (sp-launcher-by-id spt-next-launcher 905)
    )
  )

;; failed to figure out what this is:
(defpart 905
  :init-specs ((sp-flt spt-fade-a 0.0) (sp-int spt-next-time 225) (sp-launcher-by-id spt-next-launcher 906))
  )

;; failed to figure out what this is:
(defpart 906
  :init-specs ((sp-flt spt-fade-a -0.14222223))
  )

;; failed to figure out what this is:
(defpart 899
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 1.0)
    (sp-flt spt-y (meters -4))
    (sp-rnd-flt spt-scale-x (meters 10) (meters 2) 1.0)
    (sp-rnd-flt spt-scale-y (meters 8) (meters 2) 1.0)
    (sp-rnd-flt spt-r 0.0 64.0 1.0)
    (sp-rnd-flt spt-g 0.0 64.0 1.0)
    (sp-flt spt-b 255.0)
    (sp-rnd-flt spt-a 128.0 128.0 1.0)
    (sp-int spt-timer 5)
    (sp-cpuinfo-flags bit2 bit3)
    )
  )

;; failed to figure out what this is:
(defpart 900
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #xf :page #x2))
    (sp-flt spt-num 1.0)
    (sp-flt spt-y (meters -4))
    (sp-rnd-flt spt-scale-x (meters 3) (meters 2) 1.0)
    (sp-copy-from-other spt-scale-y -4)
    (sp-flt spt-r 128.0)
    (sp-flt spt-g 128.0)
    (sp-flt spt-b 128.0)
    (sp-rnd-flt spt-a 128.0 128.0 1.0)
    (sp-int spt-timer 5)
    (sp-cpuinfo-flags bit2 bit3)
    )
  )

;; failed to figure out what this is:
(defpart 901
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x1f :page #x2))
    (sp-rnd-flt spt-num 0.5 1.0 1.0)
    (sp-flt spt-y (meters -4))
    (sp-rnd-flt spt-scale-x (meters 3) (meters 3) 1.0)
    (sp-int spt-rot-x 4)
    (sp-rnd-flt spt-rot-z (degrees -30.0) (degrees 60.0) 1.0)
    (sp-rnd-flt spt-scale-y (meters 0.7) (meters 0.4) 1.0)
    (sp-flt spt-r 64.0)
    (sp-flt spt-g 64.0)
    (sp-flt spt-b 128.0)
    (sp-flt spt-a 128.0)
    (sp-flt spt-fade-a -1.6)
    (sp-int spt-timer 90)
    (sp-cpuinfo-flags bit2 bit3)
    (sp-int spt-next-time 10)
    (sp-launcher-by-id spt-next-launcher 907)
    )
  )

;; failed to figure out what this is:
(defpart 907
  :init-specs ((sp-flt spt-r 64.0)
    (sp-flt spt-g 64.0)
    (sp-flt spt-fade-r -1.0)
    (sp-flt spt-fade-g -1.0)
    (sp-flt spt-fade-a -2.0)
    )
  )

;; failed to figure out what this is:
(defpart 902
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x1f :page #x2))
    (sp-rnd-flt spt-num 0.5 1.0 1.0)
    (sp-flt spt-y (meters -4))
    (sp-rnd-flt spt-scale-x (meters 3) (meters 3) 1.0)
    (sp-int spt-rot-x 4)
    (sp-rnd-flt spt-rot-z (degrees 150.0) (degrees 60.0) 1.0)
    (sp-rnd-flt spt-scale-y (meters 0.7) (meters 0.4) 1.0)
    (sp-flt spt-r 64.0)
    (sp-flt spt-g 64.0)
    (sp-flt spt-b 128.0)
    (sp-flt spt-a 128.0)
    (sp-flt spt-fade-a -1.6)
    (sp-int spt-timer 90)
    (sp-cpuinfo-flags bit2 bit3)
    (sp-int spt-next-time 10)
    (sp-launcher-by-id spt-next-launcher 907)
    )
  )

;; failed to figure out what this is:
(defpart 903
  :init-specs ((sp-tex spt-texture (new 'static 'texture-id :index #x1f :page #x2))
    (sp-rnd-flt spt-num 1.0 1.0 1.0)
    (sp-rnd-flt spt-y (meters -6.5) (meters 1) 1.0)
    (sp-rnd-flt spt-scale-x (meters 6) (meters 2) 1.0)
    (sp-int spt-rot-x 4)
    (sp-rnd-flt spt-rot-z (degrees -140.0) (degrees 100.00001) 1.0)
    (sp-rnd-flt spt-scale-y (meters 0.7) (meters 0.4) 1.0)
    (sp-flt spt-r 64.0)
    (sp-flt spt-g 64.0)
    (sp-flt spt-b 128.0)
    (sp-flt spt-a 128.0)
    (sp-flt spt-fade-a -1.6)
    (sp-int spt-timer 90)
    (sp-cpuinfo-flags bit2 bit3)
    (sp-int spt-next-time 10)
    (sp-launcher-by-id spt-next-launcher 907)
    (sp-flt spt-conerot-x (degrees 90.0))
    (sp-rnd-flt spt-conerot-y (degrees 80.0) (degrees 200.00002) 1.0)
    (sp-flt spt-conerot-radius (meters 4))
    )
  )

;; failed to figure out what this is:
(defstate eggtop-idle (eggtop)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (let ((v1-0 arg2))
      (the-as object (when (= v1-0 'notify)
                       (case (-> arg3 param 0)
                         (('pickup)
                          (if (type-type? (-> arg0 type) fuel-cell)
                              (save-reminder (get-task-control (-> self entity extra perm task)) 1 0)
                              )
                          )
                         )
                       )
              )
      )
    )
  :exit (behavior ()
    (sound-stop (-> self sound-id))
    (none)
    )
  :trans (behavior ()
    (if (and (not (-> self child)) (task-complete? *game-info* (-> self entity extra perm task)))
        (go eggtop-close #f)
        )
    (spawn (-> self part) (-> self root-override trans))
    (sound-play "electric-loop" :id (-> self sound-id))
    (none)
    )
  :code (behavior ()
    (suspend)
    (update-transforms! (-> self root-override))
    (anim-loop)
    (none)
    )
  :post (the-as (function none :behavior eggtop) ja-post)
  )

;; failed to figure out what this is:
(defstate eggtop-close (eggtop)
  :trans (behavior ()
    (rider-trans)
    (hide-hud-quick)
    (none)
    )
  :code (behavior ((arg0 symbol))
    (when (not arg0)
      (sound-play "vent-switch" :vol 200)
      (process-spawn
        part-tracker
        :init part-tracker-init
        (-> *part-group-id-table* 190)
        -1
        #f
        #f
        #f
        (-> self root-override trans)
        :to *entity-pool*
        )
      (set! (-> self cam-tracker)
            (ppointer->handle (process-spawn
                                camera-tracker
                                :init camera-tracker-init
                                (lambda :behavior camera-tracker
                                  ()
                                  (while (not (process-grab? *target*))
                                    (suspend)
                                    )
                                  (let ((gp-0 (-> *display* base-frame-counter)))
                                    (until (>= (- (-> *display* base-frame-counter) gp-0) (seconds 1))
                                      (suspend)
                                      )
                                    )
                                  (send-event *camera* 'blend-from-as-fixed)
                                  (camera-look-at (the-as pair "ecovent-171") (the-as uint 0))
                                  (camera-change-to "camera-223" 0 #f)
                                  (let ((gp-1 (-> *display* base-frame-counter)))
                                    (until (>= (- (-> *display* base-frame-counter) gp-1) (seconds 3))
                                      (suspend)
                                      )
                                    )
                                  (while (not (process-release? (handle->process (-> self grab-target))))
                                    (suspend)
                                    )
                                  (send-event *camera* 'blend-from-as-fixed)
                                  (level-hint-spawn
                                    (game-text-id jungle-eggtop-resolution)
                                    "asstvb02"
                                    (the-as entity #f)
                                    *entity-pool*
                                    (game-task none)
                                    )
                                  (camera-look-at (the-as pair *target*) (the-as uint 0))
                                  (camera-change-to (the-as string 'base) 150 #f)
                                  (send-event (ppointer->process (-> *hud-parts* fuel-cell)) 'show)
                                  (none)
                                  )
                                :to self
                                )
                              )
            )
      (save-reminder (get-task-control (-> self entity extra perm task)) 2 0)
      (sound-play "jngb-eggtop-seq")
      (ja-no-eval :group! (-> self draw art-group data 2) :num! (seek!) :frame-num 0.0)
      (until (ja-done? 0)
        (suspend)
        (ja :num! (seek!))
        )
      )
    (process-entity-status! self (entity-perm-status complete) #t)
    (let ((a0-20 (-> self entity)))
      (if (and a0-20 (= self (-> a0-20 extra process)))
          (entity-task-complete-on a0-20)
          )
      )
    (ja :group! (-> self draw art-group data 2) :num! max)
    (suspend)
    (logior! (-> self mask) (process-mask sleep))
    (suspend)
    0
    (none)
    )
  :post (the-as (function none :behavior eggtop) rider-post)
  )

;; definition for method 11 of type eggtop
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! eggtop ((obj eggtop) (arg0 entity-actor))
  (let ((s4-0 (new 'process 'collide-shape-moving obj (collide-list-enum hit-by-player))))
    (set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s4-0 reaction) default-collision-reaction)
    (set! (-> s4-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (alloc-riders s4-0 1)
    (let ((s3-0 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid ca-1))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set! (-> s3-0 transform-index) 4)
      (set-vector! (-> s3-0 local-sphere) 0.0 0.0 -7372.8 16384.0)
      (set-root-prim! s4-0 s3-0)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> obj root-override) s4-0)
    )
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *eggtop-sg* '())
  (logior! (-> obj skel status) (janim-status inited))
  (update-transforms! (-> obj root-override))
  (set! (-> obj part) (create-launch-control (-> *part-group-id-table* 189) obj))
  (set! (-> obj sound-id) (new-sound-id))
  (cond
    ((task-complete? *game-info* (-> obj entity extra perm task))
     (go eggtop-close #t)
     )
    (else
      (birth-pickup-at-point
        (vector+! (new 'stack-no-clear 'vector) (-> obj root-override trans) (new 'static 'vector :y 6144.0 :w 1.0))
        (pickup-type fuel-cell)
        (the float (-> obj entity extra perm task))
        #f
        obj
        (the-as fact-info #f)
        )
      (go eggtop-idle)
      )
    )
  (none)
  )

;; definition of type jng-iris-door
(deftype jng-iris-door (eco-door)
  ()
  :heap-base #xa0
  :method-count-assert 27
  :size-assert         #x104
  :flag-assert         #x1b00a00104
  )

;; definition for method 3 of type jng-iris-door
(defmethod inspect jng-iris-door ((obj jng-iris-door))
  (let ((t9-0 (method-of-type eco-door inspect)))
    (t9-0 obj)
    )
  obj
  )

;; failed to figure out what this is:
(defskelgroup *jng-iris-door-sg* jng-iris-door jng-iris-door-lod0-jg jng-iris-door-idle-ja
              ((jng-iris-door-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 8)
              )

;; definition for method 24 of type jng-iris-door
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-24 jng-iris-door ((obj jng-iris-door))
  (let ((s5-0 (new 'process 'collide-shape obj (collide-list-enum hit-by-others))))
    (let ((s4-0 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> s4-0 prim-core collide-as) (collide-kind wall-object))
      (set! (-> s4-0 collide-with) (collide-kind target))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set! (-> s4-0 prim-core offense) (collide-offense indestructible))
      (set! (-> s4-0 transform-index) 0)
      (set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 16384.0)
      (set-root-prim! s5-0 s4-0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (backup-collide-with-as s5-0)
    (set! (-> obj root-override) s5-0)
    )
  0
  (none)
  )

;; definition for method 25 of type jng-iris-door
;; INFO: Return type mismatch int vs none.
(defmethod TODO-RENAME-25 jng-iris-door ((obj jng-iris-door))
  (initialize-skeleton obj *jng-iris-door-sg* '())
  (set! (-> obj open-distance) 32768.0)
  (set! (-> obj close-distance) 49152.0)
  (update-transforms! (-> obj root-override))
  0
  (none)
  )
