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

;; name: nest-obs.gc
;; name in dgo: nest-obs
;; dgos: NESTT, NES

;; DECOMP BEGINS

(deftype nest-switch (process-drawable)
  ((set-camera    symbol)
   (notify-actor  entity-actor)
   (y-start       float)
   (y-delta       float)
   (y-rot-rate    float)
   )
  (:state-methods
    up
    down
    )
  )


(defskelgroup skel-nest-switch cas-switch cas-switch-lod0-jg cas-switch-idle-ja
              ((cas-switch-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 2 0 3.5)
              :origin-joint-index 3
              )

(defstate up (nest-switch)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('attack)
       (let ((v1-1 (the-as attack-info (-> block param 1))))
         (when (or (= (-> v1-1 mode) 'spin) (= (-> v1-1 mode) 'spin-air))
           (let ((a1-3 (new 'stack-no-clear 'event-message-block)))
             (set! (-> a1-3 from) (process->ppointer self))
             (set! (-> a1-3 num-params) 0)
             (set! (-> a1-3 message) 'trigger)
             (let ((t9-0 send-event-function)
                   (v1-6 (-> self notify-actor))
                   )
               (t9-0
                 (if v1-6
                     (-> v1-6 extra process)
                     )
                 a1-3
                 )
               )
             )
           (go-virtual down)
           )
         )
       )
      )
    )
  :trans rider-trans
  :code sleep-code
  :post rider-post
  )

(defstate down (nest-switch)
  :virtual #t
  :enter (behavior ()
    (set-time! (-> self state-time))
    (set! (-> self set-camera) #f)
    )
  :trans (behavior ()
    (when (and (not (-> self set-camera)) (time-elapsed? (-> self state-time) (seconds 0.6)))
      (process-grab? *target* #f)
      (hide-hud-quick #f)
      (set-setting! 'process-mask 'set 0.0 (process-mask movie enemy))
      (set-setting! 'entity-name "camera-253" 0.0 0)
      (set! (-> self set-camera) #t)
      )
    (rider-trans)
    )
  :code (behavior ()
    (set! (-> self y-rot-rate) 0.0)
    (logclear! (-> self mask) (process-mask actor-pause))
    (while (< 0.0 (-> self y-delta))
      (seek! (-> self y-rot-rate) 500.0 (* 1000.0 (seconds-per-frame)))
      (quaternion-rotate-y!
        (-> self root quat)
        (-> self root quat)
        (* 182.04445 (seconds-per-frame) (-> self y-rot-rate))
        )
      (seek! (-> self y-delta) 0.0 (* 4096.0 (seconds-per-frame) (* 0.006 (-> self y-rot-rate))))
      (set! (-> self root trans y) (+ (-> self y-start) (-> self y-delta)))
      (suspend)
      )
    (suspend-for
      (seconds 1)
      (seek! (-> self y-rot-rate) 0.0 (* 4000.0 (seconds-per-frame)))
      (quaternion-rotate-y!
        (-> self root quat)
        (-> self root quat)
        (* 182.04445 (seconds-per-frame) (-> self y-rot-rate))
        )
      )
    (suspend-for (seconds 1))
    (remove-setting! 'entity-name)
    (remove-setting! 'process-mask)
    (process-release? *target*)
    (logior! (-> self mask) (process-mask actor-pause))
    (sleep-code)
    )
  :post rider-post
  )

;; WARN: Return type mismatch object vs none.
(defmethod init-from-entity! ((this nest-switch) (arg0 entity-actor))
  "Typically the method that does the initial setup on the process, potentially using the [[entity-actor]] provided as part of that.
   This commonly includes things such as:
   - stack size
   - collision information
   - loading the skeleton group / bones
   - sounds"
  (let ((s4-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (let ((s3-0 (new 'process 'collide-shape-prim-group s4-0 (the-as uint 3) 0)))
      (set! (-> s4-0 total-prims) (the-as uint 4))
      (set! (-> s3-0 prim-core collide-as) (collide-spec obstacle))
      (set! (-> s3-0 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> s3-0 prim-core action) (collide-action solid no-standon))
      (set-vector! (-> s3-0 local-sphere) 0.0 4096.0 0.0 20480.0)
      (set! (-> s4-0 root-prim) s3-0)
      )
    (let ((v1-8 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-8 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-8 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-8 prim-core action) (collide-action solid))
      (set! (-> v1-8 transform-index) 3)
      (set-vector! (-> v1-8 local-sphere) 0.0 8192.0 0.0 14336.0)
      )
    (let ((v1-10 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 1) (the-as uint 1))))
      (set! (-> v1-10 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-10 prim-core collide-with) (collide-spec jak hit-by-others-list player-list))
      (set! (-> v1-10 prim-core action) (collide-action solid rideable))
      (set! (-> v1-10 transform-index) 3)
      (set-vector! (-> v1-10 local-sphere) 0.0 8192.0 0.0 14336.0)
      )
    (let ((v1-12 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> v1-12 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-12 prim-core action) (collide-action solid no-standon))
      (set! (-> v1-12 transform-index) 3)
      (set-vector! (-> v1-12 local-sphere) 0.0 8192.0 0.0 8192.0)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-15 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-15 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-15 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-nest-switch" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (set! (-> this notify-actor) (entity-actor-lookup arg0 'alt-actor 0))
  (set! (-> this y-start) (+ -12288.0 (-> this root trans y)))
  (set! (-> this y-delta) 12288.0)
  (go (method-of-object this up))
  (none)
  )

(deftype nest-piston (process-drawable)
  ((y-level   float)
   (y-offset  float)
   )
  (:state-methods
    idle
    up
    )
  )


(defskelgroup skel-nest-piston piston piston-lod0-jg piston-idle-ja
              ((piston-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 4)
              )

(defstate idle (nest-piston)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('trigger)
       (go-virtual up)
       )
      )
    )
  :code sleep-code
  )

(defstate up (nest-piston)
  :virtual #t
  :trans rider-trans
  :code (behavior ()
    (suspend-for (seconds 1))
    (while (< (-> self y-offset) 16384.0)
      (seek! (-> self y-offset) 16384.0 (* 8192.0 (seconds-per-frame)))
      (set! (-> self root trans y) (+ (-> self y-level) (-> self y-offset)))
      (suspend)
      )
    (logior! (-> self mask) (process-mask actor-pause))
    (sleep-code)
    )
  :post rider-post
  )

;; WARN: Return type mismatch object vs none.
(defmethod init-from-entity! ((this nest-piston) (arg0 entity-actor))
  "Typically the method that does the initial setup on the process, potentially using the [[entity-actor]] provided as part of that.
   This commonly includes things such as:
   - stack size
   - collision information
   - loading the skeleton group / bones
   - sounds"
  (let ((s4-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (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-spec obstacle pusher))
      (set! (-> s3-0 prim-core collide-with) (collide-spec jak bot player-list))
      (set! (-> s3-0 prim-core action) (collide-action solid rideable))
      (set! (-> s3-0 transform-index) 3)
      (set-vector! (-> s3-0 local-sphere) 0.0 29081.6 0.0 31948.8)
      (set! (-> s4-0 total-prims) (the-as uint 1))
      (set! (-> s4-0 root-prim) s3-0)
      )
    (pusher-init s4-0)
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-12 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-12 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-12 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-nest-piston" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (logclear! (-> this mask) (process-mask actor-pause))
  (+! (-> this root trans y) 8192.0)
  (set! (-> this y-level) (-> this root trans y))
  (set! (-> this y-offset) 0.0)
  (transform-post)
  (go (method-of-object this idle))
  (none)
  )
