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

;; name: searchlight.gc
;; name in dgo: searchlight
;; dgos: IPF, CWI

;; DECOMP BEGINS

(deftype searchlight (process-drawable)
  ((sync  sync-eased  :inline)
   )
  (:state-methods
    idle
    )
  )


(defskelgroup skel-searchlight searchlight searchlight-lod0-jg searchlight-idle-ja
              ((searchlight-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 60 0 120)
              :origin-joint-index 3
              )

(defstate idle (searchlight)
  :virtual #t
  :code (behavior ()
    (until #f
      (let ((gp-1 (quaternion-vector-angle!
                    (new 'stack-no-clear 'quaternion)
                    (new 'static 'vector :z 1.0 :w 1.0)
                    (+ -4004.9778 (* 8192.0 (get-norm! (-> self sync) 0)))
                    )
                  )
            (s5-2 (quaternion-axis-angle!
                    (new 'stack-no-clear 'quaternion)
                    0.0
                    1.0
                    0.0
                    (vector-y-angle (-> (math-camera-matrix) fvec))
                    )
                  )
            )
        (let ((f0-3 (calc-fade-from-fog (-> self root trans))))
          (set-vector! (-> self draw color-emissive) f0-3 f0-3 f0-3 1.0)
          )
        (quaternion-normalize! (quaternion*! (-> self root quat) s5-2 gp-1))
        )
      (when (rand-vu-percent? 0.05)
        (let ((a1-4 (new 'stack-no-clear 'event-message-block)))
          (set! (-> a1-4 from) (process->ppointer self))
          (set! (-> a1-4 num-params) 0)
          (set! (-> a1-4 message) 'hour)
          (let ((v1-13 (send-event-function (ppointer->process *time-of-day*) a1-4)))
            (if (and v1-13 (>= (the-as int v1-13) 7) (>= 18 (the-as int v1-13)))
                (logior! (-> self draw status) (draw-control-status no-draw))
                (logclear! (-> self draw status) (draw-control-status no-draw))
                )
            )
          )
        )
      (suspend)
      )
    #f
    )
  :post ja-post
  )

(defmethod init-from-entity! ((this searchlight) (arg0 entity-actor))
  "Set up a newly created process from the entity that created it."
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (logclear! (-> this mask) (process-mask actor-pause))
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-searchlight" (the-as (pointer level) #f)))
    (the-as pair 0)
    )
  (logior! (-> this draw status) (draw-control-status disable-fog))
  (set! (-> this root scale y) (rand-vu-float-range 1.8 2.0))
  (set-vector! (-> this draw color-mult) 0.0 0.0 0.0 0.0)
  (let ((s4-1 (new 'stack-no-clear 'sync-info-params)))
    (let ((v1-12 0))
      (if #t
          (set! v1-12 (logior v1-12 1))
          )
      (set! (-> s4-1 sync-type) 'sync-eased)
      (set! (-> s4-1 sync-flags) (the-as sync-flags v1-12))
      )
    (set! (-> s4-1 period) (the-as uint (rand-vu-int-range 3000 6000)))
    (set! (-> s4-1 entity) arg0)
    (set! (-> s4-1 percent) 0.0)
    (set! (-> s4-1 ease-in) 0.15)
    (set! (-> s4-1 ease-out) 0.15)
    (set! (-> s4-1 pause-in) 0.0)
    (set! (-> s4-1 pause-out) 0.0)
    (initialize! (-> this sync) s4-1)
    )
  (go (method-of-object this idle))
  )
