;;-*-Lisp-*-
(in-package goal)
(bundles "MAI.DGO")
(require "engine/common-obs/generic-obs.gc")
(require "engine/anim/joint-exploder.gc")
(require "engine/game/task/task-control.gc")

;; DECOMP BEGINS

(deftype dark-crystal (process-drawable)
  ((root                  collide-shape :override)
   (crystal-num           int32)
   (underwater?           symbol)
   (explode-danger-radius float)
   (lit-color-mult        vector :inline)
   (lit-color-emissive    vector :inline)
   (unlit-color-mult      vector :inline)
   (unlit-color-emissive  vector :inline))
  (:methods
   (dark-crystal-method-20 (_type_) none)
   (dark-crystal-method-21 (_type_) symbol))
  (:states
   dark-crystal-activate
   dark-crystal-explode
   dark-crystal-idle
   dark-crystal-spawn-fuel-cell))


(defskelgroup *dark-crystal-sg*
  dark-crystal
  dark-crystal-lod0-jg
  -1
  ((dark-crystal-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 3.4 0 3.8))

(defskelgroup *dark-crystal-explode-sg*
  dark-crystal
  dark-crystal-explode-lod0-jg
  -1
  ((dark-crystal-explode-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 -15 0 50))

(define *dark-crystal-flash-delays* (new 'static 'boxed-array :type int32 #xb4 #x96 #x78 90 60 30 15 7 3))

(define *dark-crystal-exploder-params*
  (new 'static
       'joint-exploder-static-params
       :joints
       (new 'static
            'boxed-array
            :type
            joint-exploder-static-joint-params
            (new 'static 'joint-exploder-static-joint-params :joint-index 3 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 4 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 5 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 6 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 7 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 8 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 9 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 10 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 11 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 12 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 13 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 14 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 15 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 16 :parent-joint-index -1)
            (new 'static 'joint-exploder-static-joint-params :joint-index 17 :parent-joint-index -1))))

(defpartgroup group-dark-crystal-gnd-explode
  :id 322
  :duration (seconds 0.25)
  :flags (use-local-clock)
  :bounds (static-bspherem 0 0 0 16)
  :parts
  ((sp-item 2153 :fade-after (meters 100) :period (seconds 2) :length (seconds 0.017) :binding 296)
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 296 :flags (start-dead launch-asap) :binding 297)
   (sp-item 297 :fade-after (meters 80) :falloff-to (meters 100) :flags (start-dead))
   (sp-item 2154 :period (seconds 2) :length (seconds 0.017))
   (sp-item 2155 :period (seconds 2) :length (seconds 0.135))
   (sp-item 2156 :period (seconds 2) :length (seconds 0.067))
   (sp-item 2157 :period (seconds 2) :length (seconds 0.067))))

(defpart 2153
  :init-specs
  ((:texture (starflash effects))
   (:num 32.0)
   (:x (meters -2) (meters 4))
   (:y (meters 1) (meters 2))
   (:z (meters -2) (meters 4))
   (:scale-x (meters 0.1))
   (:scale-y :copy scale-x)
   (:a 0.0)
   (:vel-y (meters 0.053333335) (meters 0.026666667))
   (:accel-y (meters -0.00033333333))
   (:friction 0.94)
   (:timer (seconds 0.8))
   (:flags (bit3))
   (:conerot-x (degrees 0) (degrees 140))
   (:conerot-y (degrees 0) (degrees 360))))

(defpart 2155
  :init-specs
  ((:texture (hotdot effects))
   (:num 24.0)
   (:y (meters 1) (meters 3))
   (:scale-x (meters 0.4) (meters 0.8))
   (:scale-y :copy scale-x)
   (:r 128.0 128.0)
   (:g 0.0 32.0)
   (:b 128.0 64.0)
   (:a 32.0 96.0)
   (:vel-y (meters 0.04) (meters 0.16))
   (:scalevel-x (meters -0.0026666666))
   (:scalevel-y :copy scalevel-x)
   (:accel-y (meters -0.00016666666) (meters -0.00016666666))
   (:friction 0.9)
   (:timer (seconds 1))
   (:flags (bit2 bit14))
   (:next-time (seconds 0.1) (seconds 0.297))
   (:next-launcher 2158)
   (:conerot-x (degrees 0) (degrees 120))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 2) (meters 4))))

(defpart 2158
  :init-specs ((:fade-a -1.0666667)))

(defpart 2157
  :init-specs
  ((:texture (hotdot effects))
   (:num 12.0)
   (:y (meters 1) (meters 3))
   (:scale-x (meters 0.3))
   (:rot-z (degrees 0) (degrees 180))
   (:scale-y (meters 12))
   (:r 64.0 192.0)
   (:g 0.0 32.0)
   (:b 128.0 64.0)
   (:a 32.0 64.0)
   (:scalevel-y (meters 1.04))
   (:fade-a -1.6)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3 bit14))))

(defpart 2154
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:y (meters 2))
   (:scale-x (meters 24))
   (:scale-y :copy scale-x)
   (:r 192.0 64.0)
   (:g 0.0 32.0)
   (:b 128.0 64.0)
   (:a 128.0)
   (:fade-a -2.3272727)
   (:timer (seconds 0.18))
   (:flags (bit2 bit3 bit14))))

(defpart 2156
  :init-specs
  ((:texture (bigpuff effects))
   (:num 16.0)
   (:y (meters 1) (meters 3))
   (:scale-x (meters 3) (meters 1.5))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 0.0 96.0)
   (:g 0.0 32.0)
   (:b 64.0 32.0)
   (:a 64.0 64.0)
   (:vel-y (meters 0.08) (meters 0.04))
   (:scalevel-x (meters 0.02))
   (:rotvel-z (degrees -0.6) (degrees 1.2))
   (:scalevel-y :copy scalevel-x)
   (:fade-a -0.28444445)
   (:accel-y (meters 0.00016666666) (meters 0.00016666666))
   (:friction 0.8)
   (:timer (seconds 1.7))
   (:flags (bit2 bit14))
   (:conerot-x (degrees 0) (degrees 120))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0) (meters 4))))

(defpartgroup group-dark-crystal-water-explode
  :id 323
  :duration (seconds 0.25)
  :linger-duration (seconds 40)
  :flags (use-local-clock)
  :bounds (static-bspherem 0 0 0 16)
  :parts
  ((sp-item 2159 :period (seconds 2) :length (seconds 0.017))
   (sp-item 2160 :period (seconds 2) :length (seconds 0.135))
   (sp-item 2161 :period (seconds 2) :length (seconds 0.067))
   (sp-item 2162 :period (seconds 2) :length (seconds 0.067))
   (sp-item 2163 :period (seconds 2) :length (seconds 0.25))
   (sp-item 2164 :period (seconds 2) :length (seconds 0.25))))

(defpart 2160
  :init-specs
  ((:texture (hotdot effects))
   (:num 24.0)
   (:y (meters 1) (meters 3))
   (:scale-x (meters 0.4) (meters 0.8))
   (:scale-y :copy scale-x)
   (:r 128.0 128.0)
   (:g 128.0 32.0)
   (:b 128.0 64.0)
   (:a 32.0 96.0)
   (:vel-y (meters 0.04) (meters 0.16))
   (:scalevel-x (meters -0.0026666666))
   (:scalevel-y :copy scalevel-x)
   (:fade-g -0.4)
   (:accel-y (meters -0.00016666666) (meters -0.00016666666))
   (:friction 0.9)
   (:timer (seconds 1))
   (:flags (bit2 bit14))
   (:next-time (seconds 0.1) (seconds 0.297))
   (:next-launcher 2158)
   (:conerot-x (degrees 0) (degrees 120))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 2) (meters 4))))

(defpart 2162
  :init-specs
  ((:texture (hotdot effects))
   (:num 12.0)
   (:y (meters 1) (meters 3))
   (:scale-x (meters 0.3))
   (:rot-z (degrees 0) (degrees 180))
   (:scale-y (meters 12))
   (:r 128.0 128.0)
   (:g 128.0 32.0)
   (:b 128.0 64.0)
   (:a 32.0 64.0)
   (:scalevel-y (meters 1.04))
   (:fade-r -1.0666667)
   (:fade-g -2.1333334)
   (:fade-a -1.6)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3 bit14))))

(defpart 2159
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:y (meters 2))
   (:scale-x (meters 24))
   (:scale-y :copy scale-x)
   (:r 192.0 64.0)
   (:g 128.0 32.0)
   (:b 128.0 64.0)
   (:a 128.0)
   (:fade-g -2.0)
   (:fade-a -2.3272727)
   (:timer (seconds 0.18))
   (:flags (bit2 bit3 bit14))))

(defpart 2161
  :init-specs
  ((:texture (bigpuff effects))
   (:num 16.0)
   (:y (meters 1) (meters 3))
   (:scale-x (meters 3) (meters 1.5))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 128.0 96.0)
   (:g 128.0 32.0)
   (:b 128.0 32.0)
   (:a 64.0 64.0)
   (:vel-y (meters 0.08) (meters 0.04))
   (:scalevel-x (meters 0.02))
   (:rotvel-z (degrees -0.6) (degrees 1.2))
   (:scalevel-y :copy scalevel-x)
   (:fade-r -0.2)
   (:fade-g -0.2)
   (:fade-b 0.0)
   (:fade-a -0.28444445)
   (:accel-y (meters 0.00016666666) (meters 0.00016666666))
   (:friction 0.8)
   (:timer (seconds 1.7))
   (:flags (bit2 bit14))
   (:conerot-x (degrees 0) (degrees 120))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0) (meters 4))))

(defpart 2163
  :init-specs
  ((:texture (lakedrop effects))
   (:num 32.0)
   (:x (meters -4) (meters 8))
   (:y (meters 1) (meters 6))
   (:z (meters -4) (meters 8))
   (:scale-x (meters 0.15) (meters 0.05))
   (:scale-y (meters 0.125) (meters 0.025))
   (:r 255.0)
   (:g 255.0)
   (:b 255.0)
   (:a 0.0)
   (:vel-y (meters 0.013333334) (meters 0.006666667))
   (:fade-a 0.8)
   (:timer (seconds 40))
   (:flags (bit2 bit3 bit14))
   (:userdata 143360.0)
   (:func 'check-water-level-above-and-die)
   (:next-time (seconds 0.1) (seconds 0.097))
   (:next-launcher 2165)
   (:rotate-y (degrees 0) (degrees 360))))

(defpart 2165
  :init-specs ((:fade-a 0.0)))

(defpart 2164
  :init-specs
  ((:texture (lakedrop effects))
   (:num 4.0)
   (:x (meters -4) (meters 8))
   (:y (meters 1) (meters 6))
   (:z (meters -4) (meters 8))
   (:scale-x (meters 0.3) (meters 0.15))
   (:scale-y (meters 0.2) (meters 0.1))
   (:r 255.0)
   (:g 255.0)
   (:b 255.0)
   (:a 0.0)
   (:vel-y (meters 0.013333334) (meters 0.006666667))
   (:fade-a 0.8)
   (:timer (seconds 40))
   (:flags (bit2 bit3 bit14))
   (:userdata 143360.0)
   (:func 'check-water-level-above-and-die)
   (:next-time (seconds 0.1) (seconds 0.097))
   (:next-launcher 2165)
   (:rotate-y (degrees 0) (degrees 360))))

(defstate dark-crystal-idle (dark-crystal)
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('touch 'attack)
         (if (= (-> proc type) target)
           (level-hint-spawn (text-id cave-dark-crystals-flee) "sksp0334" (the-as entity #f) *entity-pool* (game-task none)))
         (close-specific-task! (game-task cave-dark-crystals) (task-status need-hint))
         (go dark-crystal-activate))))
  :code
    (behavior ()
      (loop
        (logior! (-> self mask) (process-mask sleep-code))
        (suspend))))

(defstate dark-crystal-activate (dark-crystal)
  :code
    (behavior ()
      (logclear! (-> self mask) (process-mask actor-pause))
      (dotimes (gp-0 (-> *dark-crystal-flash-delays* length))
        (sound-play "warning")
        (set! (-> self draw color-mult quad) (-> self lit-color-mult quad))
        (set! (-> self draw color-emissive quad) (-> self lit-color-emissive quad))
        (set-time! (-> self state-time))
        (until (time-elapsed? (-> self state-time) (seconds 0.1))
          (suspend))
        (set! (-> self draw color-mult quad) (-> self unlit-color-mult quad))
        (set! (-> self draw color-emissive quad) (-> self unlit-color-emissive quad))
        (set-time! (-> self state-time))
        (let ((s5-1 (-> *dark-crystal-flash-delays* gp-0))) (until (time-elapsed? (-> self state-time) s5-1) (suspend))))
      (go dark-crystal-explode)))

(defstate dark-crystal-explode (dark-crystal)
  :code
    (behavior ()
      (set-time! (-> self state-time))
      (logclear! (-> self mask) (process-mask actor-pause))
      (clear-collide-with-as (-> self root))
      (let ((gp-0 (new 'stack 'joint-exploder-tuning 0)))
        (when (-> self underwater?)
          (set! (-> gp-0 duration) (seconds 4))
          (set! (-> gp-0 gravity) -20480.0)
          (set! (-> gp-0 rot-speed) 4.2)
          (set-vector! (-> gp-0 fountain-rand-transv-lo) -40960.0 20480.0 -40960.0 1.0)
          (set-vector! (-> gp-0 fountain-rand-transv-hi) 40960.0 49152.0 40960.0 1.0))
        (process-spawn joint-exploder *dark-crystal-explode-sg* 5 gp-0 *dark-crystal-exploder-params* :to self))
      (activate! *camera-smush-control* 819.2 37 210 1.0 0.995)
      (let ((gp-1 (dark-crystal-method-21 self)))
        (suspend)
        (ja-channel-set! 0)
        (ja-post)
        (logior! (-> self draw status) (draw-status hidden))
        (dark-crystal-method-20 self)
        (if (-> self underwater?) (sound-play "water-explosion") (sound-play "crystal-explode"))
        (process-spawn part-tracker
                       :init
                       part-tracker-init
                       (if (-> self underwater?) group-dark-crystal-water-explode group-dark-crystal-gnd-explode)
                       -1
                       #f
                       #f
                       #f
                       (-> self root trans)
                       :to
                       *entity-pool*)
        (suspend-for (seconds 0.25))
        (if gp-1 (go dark-crystal-spawn-fuel-cell)))
      (cleanup-for-death self)
      (until (not (-> self child))
        (suspend))))

(defstate dark-crystal-spawn-fuel-cell (dark-crystal)
  :event process-drawable-fuel-cell-handler
  :code
    (behavior ()
      (logclear! (-> self mask) (process-mask actor-pause))
      (clear-collide-with-as (-> self root))
      (level-hint-spawn (text-id cave-dark-crystals-resolution) "sksp0327" (the-as entity #f) *entity-pool* (game-task none))
      (ja-channel-set! 0)
      (ja-post)
      (logior! (-> self draw status) (draw-status hidden))
      (if (not (task-complete? *game-info* (-> self entity extra perm task)))
        (birth-pickup-at-point (-> self root trans)
                               (pickup-type fuel-cell)
                               (the float (-> self entity extra perm task))
                               #t
                               self
                               (the-as fact-info #f)))
      (suspend)
      (until (not (-> self child))
        (suspend))
      (aybabtu 2)
      (cleanup-for-death self)))

(defmethod dark-crystal-method-20 ((this dark-crystal))
  (when *target*
    (let ((s5-0 (new 'stack-no-clear 'vector))
          (s3-0 (new 'stack-no-clear 'vector))
          (s4-0 (new 'stack-no-clear 'vector)))
      (set! (-> s5-0 quad) (-> this root trans quad))
      (+! (-> s5-0 y) 6144.0)
      (set! (-> s3-0 quad) (-> (target-pos 0) quad))
      (+! (-> s3-0 y) 6144.0)
      (when (>= (-> this explode-danger-radius) (vector-vector-distance s5-0 s3-0))
        (vector-! s4-0 s3-0 s5-0)
        (let ((t2-0 (new 'stack-no-clear 'collide-tri-result)))
          (if (< (fill-and-probe-using-line-sphere *collide-cache*
                                                   s5-0
                                                   s4-0
                                                   819.2
                                                   (collide-kind background)
                                                   this
                                                   t2-0
                                                   (new 'static 'pat-surface :noentity #x1))
                 0.0)
            (send-event *target* 'attack #f (new 'static 'attack-info)))))))
  (none))

(defmethod dark-crystal-method-21 ((this dark-crystal))
  (let ((s5-0 #f))
    (when (nonzero? (-> this crystal-num))
      (let* ((s4-0 (get-task-control (game-task cave-dark-crystals)))
             (s3-0 (logior (get-reminder s4-0 3) (ash 1 (-> this crystal-num)))))
        (save-reminder s4-0 s3-0 3)
        (when (= s3-0 62)
          (set! s5-0 #t)
          (process-entity-status! this (entity-perm-status complete) #t))))
    s5-0))

(defmethod init-from-entity! ((this dark-crystal) (arg0 entity-actor))
  (set-vector! (-> this unlit-color-mult) 0.5 0.5 0.5 1.0)
  (set-vector! (-> this unlit-color-emissive) 0.0 0.0 0.0 0.0)
  (set-vector! (-> this lit-color-mult) 1.0 1.0 1.0 1.0)
  (set-vector! (-> this lit-color-emissive) 1.0 1.0 1.0 0.0)
  (logior! (-> this mask) (process-mask enemy))
  (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-kind wall-object))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set! (-> s3-0 transform-index) 0)
      (set-vector! (-> s3-0 local-sphere) 0.0 6963.2 0.0 15564.8)
      (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! (-> this root) s4-0))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *dark-crystal-sg* '())
  (logior! (-> this mask) (process-mask attackable))
  (set! (-> this draw color-mult quad) (-> this unlit-color-mult quad))
  (set! (-> this draw color-emissive quad) (-> this unlit-color-emissive quad))
  (set! (-> this underwater?) (= (res-lump-value arg0 'mode uint128) 1))
  (set! (-> this explode-danger-radius) (res-lump-float arg0 'extra-radius :default 28672.0))
  (set! (-> this crystal-num) (res-lump-value arg0 'extra-id int))
  (set-vector! (-> this root scale) 2.0 2.0 2.0 1.0)
  (ja-channel-push! 1 0)
  (let ((s5-1 (-> this skel root-channel 0)))
    (joint-control-channel-group-eval! s5-1 (the-as art-joint-anim (-> this draw art-group data 2)) num-func-identity)
    (set! (-> s5-1 frame-num) 0.0))
  (ja-post)
  (update-transforms! (-> this root))
  (if (and (-> this entity) (logtest? (-> this entity extra perm status) (entity-perm-status complete)))
    (go dark-crystal-spawn-fuel-cell)
    (go dark-crystal-idle))
  (none))
