;;-*-Lisp-*-
(in-package goal)
(bundles "LAV.DGO")
(require "engine/geometry/path.gc")
(require "engine/util/sync-info.gc")
(require "engine/common-obs/generic-obs.gc")
(require "engine/common-obs/water-anim.gc")

;; DECOMP BEGINS

(deftype lavabase (process-drawable) ()
  (:states
   lavabase-idle))


(defskelgroup *lavabase-sg*
  lavabase
  lavabase-lod0-jg
  lavabase-idle-ja
  ((lavabase-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 0 0 22)
  :longest-edge (meters 9.4))

(defstate lavabase-idle (lavabase)
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post ja-post)

(defmethod init-from-entity! ((this lavabase) (arg0 entity-actor))
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *lavabase-sg* '())
  (go lavabase-idle)
  (none))

(deftype lavafall (process-drawable) ()
  (:states
   lavafall-idle))


(defskelgroup *lavafall-sg*
  lavafall
  lavafall-lod0-jg
  lavafall-idle-ja
  ((lavafall-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 10 0 13)
  :longest-edge (meters 5.4))

(defstate lavafall-idle (lavafall)
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post ja-post)

(defmethod init-from-entity! ((this lavafall) (arg0 entity-actor))
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *lavafall-sg* '())
  (go lavafall-idle)
  (none))

(deftype lavashortcut (process-drawable) ()
  (:states
   lavashortcut-idle))


(defskelgroup *lavashortcut-sg*
  lavashortcut
  lavashortcut-lod0-jg
  lavashortcut-idle-ja
  ((lavashortcut-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 -34 0 105)
  :longest-edge (meters 11.9))

(defstate lavashortcut-idle (lavashortcut)
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post ja-post)

(defmethod init-from-entity! ((this lavashortcut) (arg0 entity-actor))
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *lavashortcut-sg* '())
  (go lavashortcut-idle)
  (none))

(defpartgroup group-darkecobarrel-hit
  :id 540
  :flags (use-local-clock)
  :bounds (static-bspherem 0 0 0 8)
  :parts ((sp-item 1932 :period (seconds 0.05) :length (seconds 0.017))))

(defpart 1932
  :init-specs
  ((:texture (bigpuff effects))
   (:num 1.0)
   (:x (meters -2) (meters 4))
   (:y (meters 4) (meters 2))
   (:z (meters -2) (meters 4))
   (:scale-x (meters 4) (meters 2))
   (: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 32.0 32.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.14222223)
   (:accel-y (meters -0.00008333333) (meters -0.00008333333))
   (:friction 0.9)
   (:timer (seconds 1.7))
   (:flags (bit2 bit14))))

(defpartgroup group-darkecobarrel-explode
  :id 541
  :flags (use-local-clock)
  :bounds (static-bspherem 0 0 0 8)
  :parts
  ((sp-item 2125 :period (seconds 2) :length (seconds 0.017))
   (sp-item 2126 :period (seconds 2) :length (seconds 0.135))
   (sp-item 2127 :period (seconds 2) :length (seconds 0.067))
   (sp-item 2128 :period (seconds 2) :length (seconds 0.067))
   (sp-item 2166 :fade-after (meters 100) :period (seconds 2) :length (seconds 0.067) :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))))

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

(defpart 2126
  :init-specs
  ((:texture (hotdot effects))
   (:num 8.0)
   (:y (meters 0))
   (:scale-x (meters 0.4) (meters 0.8))
   (:scale-y :copy scale-x)
   (:r 64.0 128.0)
   (:g 0.0 32.0)
   (:b 96.0 64.0)
   (:a 32.0 96.0)
   (:vel-y (meters 0.053333335) (meters 0.21333334))
   (: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 2129)
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 2) (meters 4))))

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

(defpart 2128
  :init-specs
  ((:texture (hotdot effects))
   (:num 6.0)
   (:y (meters 0))
   (:scale-x (meters 0.4))
   (:rot-z (degrees 0) (degrees 180))
   (:scale-y (meters 16))
   (: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 2125
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:y (meters 0))
   (:scale-x (meters 32))
   (:scale-y :copy scale-x)
   (:r 64.0 192.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 2127
  :init-specs
  ((:texture (bigpuff effects))
   (:num 16.0)
   (:x (meters -1) (meters 2))
   (:y (meters -1) (meters 2))
   (:z (meters -1) (meters 2))
   (:scale-x (meters 4) (meters 2))
   (: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 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0) (meters 6))))

(deftype darkecobarrel-leak (structure)
  ((offset      vector :inline)
   (first-frame basic)))


(deftype darkecobarrel-base (process-drawable)
  ((root  collide-shape-moving :override)
   (speed float)
   (sync  time-frame)))


(deftype darkecobarrel-mover (darkecobarrel-base)
  ((start-time   time-frame)
   (hits         int32)
   (leak         darkecobarrel-leak 1 :inline)
   (y-offset     bouncing-float :inline)
   (y-offset-tgt delayed-rand-float :inline)
   (down         oscillating-vector :inline)
   (down-tgt     delayed-rand-vector :inline))
  (:states
   darkecobarrel-mover-die
   darkecobarrel-mover-move))


(deftype darkecobarrel (darkecobarrel-base)
  ((self-override darkecobarrel :overlay-at self)
   (spawn-array   (array int64))
   (cur-spawn     int32))
  (:states
   darkecobarrel-spawner))


(defmethod relocate ((this darkecobarrel) (offset int))
  (if (nonzero? (-> this spawn-array)) (&+! (-> this spawn-array) offset))
  (call-parent-method this offset))

(defskelgroup *darkecobarrel-sg*
  darkecobarrel
  darkecobarrel-lod0-jg
  darkecobarrel-idle-ja
  ((darkecobarrel-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 -7.75 0 8.6)
  :longest-edge (meters 2.8))

(defbehavior darkecobarrel-base-time darkecobarrel-base ()
  (+ (current-time) (-> self sync)))

(defbehavior darkecobarrel-base-pos darkecobarrel-base ((arg0 time-frame))
  (if (< 0.0 (-> self speed))
    (* (-> self speed) (the float (- (darkecobarrel-base-time) arg0)))
    (+ 1.0 (* (-> self speed) (the float (- (darkecobarrel-base-time) arg0))))))

(defbehavior darkecobarrel-base-done? darkecobarrel-base ((arg0 float))
  (or (and (< 0.0 (-> self speed)) (< 1.0 arg0)) (and (< (-> self speed) 0.0) (< arg0 0.0))))

(defbehavior darkecobarrel-base-init darkecobarrel-base ((arg0 res-lump))
  (process-drawable-from-entity! self (the-as entity-actor arg0))
  (initialize-skeleton self *darkecobarrel-sg* '())
  (set! (-> self path) (new 'process 'path-control self 'path 0.0))
  (let ((v0-3 (logior (-> self path flags) (path-control-flag display draw-line draw-point draw-text))))
    (set! (-> self path flags) v0-3)
    v0-3))

(defbehavior darkecobarrel-mover-pos darkecobarrel-mover ()
  (let ((f30-0 (darkecobarrel-base-pos (-> self start-time))))
    (if (darkecobarrel-base-done? f30-0) (deactivate self))
    (eval-path-curve! (-> self path) (-> self root trans) f30-0 'interp)
    (+! (-> self root trans y) (* 4096.0 (-> self y-offset osc value)))
    (+! (-> self root trans y) -4096.0)
    (let ((s5-0 (new 'stack-no-clear 'vector))
          (gp-0 (new 'stack-no-clear 'matrix)))
      (let ((s4-0 (new 'stack-no-clear 'vector)))
        (path-control-method-14 (-> self path) s5-0 f30-0)
        (set! (-> s4-0 quad) (-> self down value quad))
        (set! (-> s4-0 y) -1.0)
        (vector-normalize! s4-0 1.0)
        (forward-down-nopitch->inv-matrix gp-0 s5-0 s4-0))
      (matrix->quaternion (-> self root quat) gp-0)
      (dotimes (s5-1 (-> self hits))
        (when (-> self leak s5-1 first-frame)
          (set! (-> self leak s5-1 first-frame) #f)
          (let ((s4-1 (new 'stack-no-clear 'matrix)))
            (matrix-transpose! s4-1 gp-0)
            (vector-matrix*! (the-as vector (-> self leak s5-1)) (the-as vector (-> self leak s5-1)) s4-1)))
        (let ((s4-2 (new 'stack-no-clear 'vector)))
          (vector-matrix*! s4-2 (the-as vector (-> self leak s5-1)) gp-0)
          (vector+! s4-2 s4-2 (-> self root trans))
          (spawn (-> self part) s4-2)))))
  (if (< (vector-vector-xz-distance-squared (-> self root trans) (camera-pos)) 1073741800.0)
    (logior! (-> self draw status) (draw-status skip-bones))
    (set! (-> self draw status) (the-as draw-status (logclear (-> self draw status) (draw-status skip-bones)))))
  (none))

(defstate darkecobarrel-mover-die (darkecobarrel-mover)
  :code
    (behavior ()
      (ja-channel-set! 0)
      (clear-collide-with-as (-> self root))
      (ja-post)
      (sound-play "dcrate-break")
      (let ((gp-1 (new 'stack-no-clear 'vector)))
        (set! (-> gp-1 quad) (-> self root trans quad))
        (+! (-> gp-1 y) -49152.0)
        (process-spawn part-tracker :init part-tracker-init (-> *part-group-id-table* 541) 600 #f #f #f gp-1 :to *entity-pool*))
      (suspend)
      (set-time! (-> self state-time))
      (until (time-elapsed? (-> self state-time) (seconds 1))
        (suspend))
      (cleanup-for-death self)
      (deactivate self)))

(defstate darkecobarrel-mover-move (darkecobarrel-mover)
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('touch 'attack)
         (cond
           ((= proc *target*)
            (let ((s5-0 (-> block param 0)))
              (if (and s5-0
                       ((method-of-type touching-shapes-entry prims-touching?)
                        (the-as touching-shapes-entry s5-0)
                        (-> self root)
                        (the-as uint 1))
                       (send-event proc 'attack-invinc s5-0 (static-attack-info ((mode 'death)))))
                (go darkecobarrel-mover-die))))
           ((>= argc 2)
            (case (-> block param 1)
              (('eco-yellow)
               (+! (-> self hits) 1)
               (cond
                 ((>= (-> self hits) 2) (go darkecobarrel-mover-die))
                 (else
                  (let ((v1-17 (if (and (nonzero? proc) (type-type? (-> proc type) process-drawable)) proc))
                        (gp-1 (new 'stack-no-clear 'vector)))
                    (set! (-> self leak (+ (-> self hits) -1) first-frame) #t)
                    (cond
                      (v1-17
                       (vector-! gp-1 (-> (the-as process-drawable v1-17) root trans) (-> self root trans))
                       (set! (-> self leak (+ (-> self hits) -1) offset quad) (-> gp-1 quad))
                       (vector-normalize! gp-1 -0.04)
                       (let ((v0-0 (the-as object (-> self down vel)))) (set! (-> (the-as vector v0-0) quad) (-> gp-1 quad)) v0-0))
                      (else
                       (set! (-> self leak (+ (-> self hits) -1) offset quad) (-> self root trans quad))
                       (set! (-> self leak (+ (-> self hits) -1) offset y) (+ -49152.0 (-> self leak (+ (-> self hits) -1) offset y)))))))))))))))
  :trans
    (behavior ()
      (update! (-> self y-offset) 0.0)
      (if (and (at-min? (-> self y-offset)) (< (-> self y-offset osc vel) 0.03))
        (set! (-> self y-offset osc vel) (fabs (update! (-> self y-offset-tgt)))))
      (update! (-> self down) (update-with-delay! (-> self down-tgt)))
      (darkecobarrel-mover-pos))
  :code
    (behavior ()
      (let ((f30-0 0.9)
            (f28-0 0.25))
        (+ f30-0 (* f28-0 (rand-float-gen))))
      (let ((gp-0 (-> self skel root-channel 0)))
        (set! (-> gp-0 num-func) num-func-identity)
        (set! (-> gp-0 frame-num) (* (rand-float-gen) (the float (ja-num-frames 0)))))
      (loop
        (ja :num-func num-func-identity :frame-num 0.0)
        (suspend)))
  :post pusher-post)

(defbehavior darkecobarrel-mover-init-by-other darkecobarrel-mover ((arg0 res-lump) (arg1 float) (arg2 time-frame) (arg3 time-frame))
  (let ((s2-0 (new 'process 'collide-shape-moving self (collide-list-enum usually-hit-by-player))))
    (set! (-> s2-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s2-0 reaction) default-collision-reaction)
    (set! (-> s2-0 no-reaction) (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing))
    (let ((s1-0 (new 'process 'collide-shape-prim-group s2-0 (the-as uint 2) 0)))
      (set! (-> s1-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s1-0 collide-with) (collide-kind target))
      (set! (-> s1-0 prim-core action) (collide-action solid))
      (set! (-> s1-0 transform-index) 3)
      (set-vector! (-> s1-0 local-sphere) 0.0 -32768.0 0.0 32768.0)
      (set-root-prim! s2-0 s1-0)
      (let ((s0-0 (new 'process 'collide-shape-prim-mesh s2-0 (the-as uint 0) (the-as uint 1))))
        (set! (-> s0-0 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s0-0 collide-with) (collide-kind target))
        (set! (-> s0-0 prim-core action) (collide-action solid))
        (set! (-> s0-0 prim-core offense) (collide-offense indestructible))
        (set! (-> s0-0 transform-index) 3)
        (set-vector! (-> s0-0 local-sphere) 0.0 -32768.0 0.0 32768.0)
        (append-prim s1-0 s0-0))
      (let ((s0-1 (new 'process 'collide-shape-prim-mesh s2-0 (the-as uint 1) (the-as uint 0))))
        (set! (-> s0-1 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s0-1 collide-with) (collide-kind target))
        (set! (-> s0-1 prim-core action) (collide-action solid))
        (set! (-> s0-1 prim-core offense) (collide-offense indestructible))
        (set! (-> s0-1 transform-index) 3)
        (set-vector! (-> s0-1 local-sphere) 0.0 -32768.0 0.0 32768.0)
        (append-prim s1-0 s0-1)))
    (set! (-> s2-0 nav-radius) (* 0.75 (-> s2-0 root-prim local-sphere w)))
    (backup-collide-with-as s2-0)
    (set! (-> self root) s2-0))
  (darkecobarrel-base-init arg0)
  (set! (-> self part) (create-launch-control (-> *part-group-id-table* 540) self))
  (set! (-> self speed) arg1)
  (set! (-> self start-time) arg2)
  (set! (-> self sync) arg3)
  (set! (-> self hits) 0)
  (set-params! (-> self y-offset-tgt) 300 900 0.5)
  (set-params! (-> self y-offset) 0.0 1.0 0.0 0.7 0.08 0.1 0.97)
  (set-params! (-> self down) (the-as vector #f) 0.005 0.05 0.999)
  (set-params! (-> self down-tgt) 300 600 0.05 0.9)
  (darkecobarrel-mover-pos)
  (logclear! (-> self mask) (process-mask actor-pause))
  (logior! (-> self mask) (process-mask attackable))
  (go darkecobarrel-mover-move)
  (none))

(defbehavior darkecobarrel-advance-curspawn darkecobarrel ()
  (+! (-> self cur-spawn) 1)
  (when (>= (-> self cur-spawn) (-> self spawn-array length))
    (set! (-> self self-override cur-spawn) 0)
    0)
  (none))

(defbehavior darkecobarrel-cycle-time darkecobarrel ()
  (-> self spawn-array (+ (-> self spawn-array length) -1)))

(defstate darkecobarrel-spawner (darkecobarrel)
  :trans
    (behavior ()
      (let ((gp-1 (mod (darkecobarrel-base-time) (darkecobarrel-cycle-time))))
        (if (and (> (-> self cur-spawn) 0) (< gp-1 (-> self spawn-array (+ (-> self cur-spawn) -1))))
          (+! gp-1 (darkecobarrel-cycle-time)))
        (let ((gp-2 (- gp-1 (-> self spawn-array (-> self cur-spawn)))))
          (when (>= gp-2 0)
            (process-spawn darkecobarrel-mover
                           (-> self entity)
                           (-> self speed)
                           (- (darkecobarrel-base-time) (the-as time-frame gp-2))
                           (-> self sync)
                           :to
                           self)
            (darkecobarrel-advance-curspawn))))
      (if (nonzero? (-> self sound)) (update! (-> self sound))))
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!))))))

(defmethod init-from-entity! ((this darkecobarrel) (arg0 entity-actor))
  (local-vars (sv-16 res-tag))
  (set! (-> this root) (the-as collide-shape-moving (new 'process 'trsqv)))
  (darkecobarrel-base-init arg0)
  (set! (-> this sound) (new 'process 'ambient-sound (static-sound-spec "lav-dark-eco" :fo-max 30) (-> this root trans)))
  (logior! (-> this draw status) (draw-status hidden))
  (set! (-> this speed) (/ 300.0 (res-lump-float (-> this entity) 'speed :default 61440.0)))
  (set! sv-16 (new 'static 'res-tag))
  (let ((s5-1 (res-lump-data arg0 'delay pointer :tag-ptr (& sv-16))))
    (cond
      (s5-1
       (set! (-> this spawn-array) (new 'process 'boxed-array time-frame (the-as int (-> sv-16 elt-count))))
       (dotimes (v1-12 (the-as int (-> sv-16 elt-count)))
         (set! (-> this spawn-array v1-12)
               (the int (* (fabs (-> this speed)) (-> (the-as (pointer float) (&+ s5-1 (* v1-12 4)))))))))
      (else
       (set! (-> this spawn-array) (new 'process 'boxed-array time-frame 4))
       (set! (-> this spawn-array 0) (the int (* 45056.0 (fabs (-> this speed)))))
       (set! (-> this spawn-array 1) (the int (* 90112.0 (fabs (-> this speed)))))
       (set! (-> this spawn-array 2) (the int (* 45056.0 (fabs (-> this speed)))))
       (set! (-> this spawn-array 3) (the int (* 135168.0 (fabs (-> this speed))))))))
  (dotimes (v1-19 (+ (-> this spawn-array length) -1))
    (+! (-> this spawn-array (+ v1-19 1)) (-> this spawn-array v1-19)))
  (set! (-> this sync) (the-as time-frame (the int (* (fabs (-> this speed)) (res-lump-float (-> this entity) 'sync)))))
  (set! (-> this speed) (/ 1.0 (* (-> this speed) (path-distance (-> this path)))))
  (let ((s5-3 (mod (darkecobarrel-base-time) (darkecobarrel-cycle-time))))
    (set! (-> this cur-spawn) 0)
    (while (>= s5-3 (-> this spawn-array (-> this cur-spawn)))
      (darkecobarrel-advance-curspawn))
    (+! (-> this cur-spawn) -1)
    (when (< (-> this cur-spawn) 0)
      (set! (-> this cur-spawn) (+ (-> this spawn-array length) -1))
      (+! s5-3 (-> this spawn-array (-> this cur-spawn))))
    (let ((s4-0 (-> this cur-spawn))
          (s5-4 (- (darkecobarrel-base-time) (the-as time-frame (- s5-3 (-> this spawn-array (-> this cur-spawn)))))))
      (until (darkecobarrel-base-done? (darkecobarrel-base-pos s5-4))
        (process-spawn darkecobarrel-mover (-> this entity) (-> this speed) s5-4 (-> this sync) :to this)
        (set! s5-4 (- s5-4 (the-as time-frame (-> this spawn-array s4-0))))
        (+! s4-0 -1)
        (if (< s4-0 0) (set! s4-0 (+ (-> this spawn-array length) -1)) (+! s5-4 (-> this spawn-array s4-0))))))
  (darkecobarrel-advance-curspawn)
  (go darkecobarrel-spawner)
  (none))

(deftype lavafallsewera (process-drawable) ()
  (:states
   lavafallsewera-idle))


(defskelgroup *lavafallsewera-sg*
  lavafallsewera
  lavafallsewera-lod0-jg
  lavafallsewera-idle-ja
  ((lavafallsewera-lod0-mg (meters 999999)))
  :bounds (static-spherem -15 0 -5 185))

(defstate lavafallsewera-idle (lavafallsewera)
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post ja-post)

(defmethod init-from-entity! ((this lavafallsewera) (arg0 entity-actor))
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *lavafallsewera-sg* '())
  (go lavafallsewera-idle)
  (none))

(deftype lavafallsewerb (process-drawable) ()
  (:states
   lavafallsewerb-idle))


(defskelgroup *lavafallsewerb-sg*
  lavafallsewerb
  lavafallsewerb-lod0-jg
  lavafallsewerb-idle-ja
  ((lavafallsewerb-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 0 0 120))

(defstate lavafallsewerb-idle (lavafallsewerb)
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post ja-post)

(defmethod init-from-entity! ((this lavafallsewerb) (arg0 entity-actor))
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *lavafallsewerb-sg* '())
  (go lavafallsewerb-idle)
  (none))

(deftype chainmine (process-drawable)
  ((root collide-shape-moving :override))
  (:state-methods
   die
   idle))


(defpartgroup group-chainmine-explode
  :id 542
  :flags (use-local-clock)
  :bounds (static-bspherem 0 0 0 8)
  :parts
  ((sp-item 2132 :period (seconds 2) :length (seconds 0.017))
   (sp-item 2133 :period (seconds 2) :length (seconds 0.135))
   (sp-item 2134 :period (seconds 2) :length (seconds 0.067))
   (sp-item 2135 :period (seconds 2) :length (seconds 0.067))))

(defpart 2133
  :init-specs
  ((:texture (hotdot effects))
   (:num 8.0)
   (:y (meters 0))
   (:scale-x (meters 0.4) (meters 0.8))
   (:scale-y :copy scale-x)
   (:r 192.0 64.0)
   (:g 192.0 64.0)
   (:b 128.0)
   (:a 32.0 96.0)
   (:vel-y (meters 0.053333335) (meters 0.21333334))
   (:scalevel-x (meters -0.0026666666))
   (:scalevel-y :copy scalevel-x)
   (:fade-g -2.1333334)
   (:fade-b -1.4222223)
   (: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 2136)
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 2) (meters 4))))

(defpart 2136
  :init-specs ((:fade-r 0.0) (:fade-g 0.0) (:fade-b 0.0) (:fade-a -1.0666667)))

(defpart 2135
  :init-specs
  ((:texture (hotdot effects))
   (:num 6.0)
   (:y (meters 0))
   (:scale-x (meters 0.4))
   (:rot-z (degrees 0) (degrees 180))
   (:scale-y (meters 16))
   (:r 255.0)
   (:g 196.0)
   (:b 64.0)
   (:a 32.0 64.0)
   (:scalevel-y (meters 1.04))
   (:fade-g -3.2666667)
   (:fade-b -1.0666667)
   (:fade-a -1.6)
   (:timer (seconds 0.2))
   (:flags (bit2 bit3 bit14))))

(defpart 2132
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:y (meters 0))
   (:scale-x (meters 32))
   (:scale-y :copy scale-x)
   (:r 255.0)
   (:g 192.0 32.0)
   (:b 128.0)
   (:a 128.0)
   (:fade-a -2.3272727)
   (:timer (seconds 0.18))
   (:flags (bit2 bit3 bit14))))

(defpart 2134
  :init-specs
  ((:texture (bigpuff effects))
   (:num 16.0)
   (:scale-x (meters 4) (meters 2))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 255.0)
   (:g 128.0 64.0)
   (:b 128.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))
   (:next-time (seconds 0.14))
   (:next-launcher 2137)
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 0) (meters 2))))

(defpart 2137
  :init-specs ((:fade-r -1.0666667) (:fade-g -1.0666667) (:fade-b -2.1166666) (:next-time (seconds 0.2)) (:next-launcher 2138)))

(defpart 2138
  :init-specs
  ((:fade-r -0.5688889)
   (:fade-g -0.28444445)
   (:fade-b 0.0)
   (:fade-a -0.21333334)
   (:next-time (seconds 0.75))
   (:next-launcher 2139)))

(defpart 2139
  :init-specs ((:fade-r 0.0) (:fade-g 0.0) (:fade-b 0.0)))

(defskelgroup *chainmine-sg*
  chainmine
  chainmine-lod0-jg
  chainmine-idle-ja
  ((chainmine-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 -10.75 0 12.75)
  :longest-edge (meters 2.4))

(defstate die (chainmine)
  :virtual #t
  :code
    (behavior ()
      (ja-channel-set! 0)
      (clear-collide-with-as (-> self root))
      (ja-post)
      (sound-play "dcrate-break")
      (let ((gp-1 (new 'stack-no-clear 'vector)))
        (set! (-> gp-1 quad) (-> self root trans quad))
        (+! (-> gp-1 y) -73728.0)
        (process-spawn part-tracker :init part-tracker-init (-> *part-group-id-table* 542) 600 #f #f #f gp-1 :to *entity-pool*))
      (suspend)
      (set-time! (-> self state-time))
      (until (time-elapsed? (-> self state-time) (seconds 1))
        (suspend))
      (cleanup-for-death self)
      (deactivate self)))

(defstate idle (chainmine)
  :virtual #t
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('attack 'touch) (send-event proc 'attack (-> block param 0) (static-attack-info ((mode 'deadly)))) (go-virtual die))))
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (if (nonzero? (-> self sound)) (update! (-> self sound)))
          (suspend)
          (ja :num! (seek!)))))
  :post ja-post)

(defmethod init-from-entity! ((this chainmine) (arg0 entity-actor))
  (logior! (-> this mask) (process-mask attackable))
  (let ((s4-0 (new 'process 'collide-shape-moving this (collide-list-enum usually-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))
    (let ((s3-0 (new 'process 'collide-shape-prim-sphere s4-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))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set! (-> s3-0 transform-index) 0)
      (set-vector! (-> s3-0 local-sphere) 0.0 -73728.0 0.0 18432.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! (-> this root) s4-0))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *chainmine-sg* '())
  (set! (-> this sound) (new 'process 'ambient-sound (static-sound-spec "lava-mine-chain" :fo-max 30) (-> this root trans)))
  (go (method-of-object this idle))
  (none))

(defskelgroup *lavaballoon-sg*
  lavaballoon
  lavaballoon-lod0-jg
  lavaballoon-idle-ja
  ((lavaballoon-lod0-mg (meters 20)) (lavaballoon-lod1-mg (meters 999999)))
  :bounds (static-spherem 0 0.8 0 3.8))

(deftype lavaballoon (process-drawable)
  ((root          collide-shape :override)
   (move-per-tick float))
  (:state-methods
   idle
   die))


(defpartgroup group-lavaballoon
  :id 543
  :duration (seconds 0.017)
  :bounds (static-bspherem 0 0 0 15)
  :parts ((sp-item 1987) (sp-item 1988) (sp-item 1989)))

(defpart 1988
  :init-specs
  ((:texture (bigpuff effects))
   (:num 8.0)
   (:x (meters -1) (meters 2))
   (:y (meters 1) (meters 2))
   (:z (meters -1) (meters 2))
   (:scale-x (meters 3) (meters 3))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 96.0)
   (:g 96.0)
   (:b 255.0)
   (:a 32.0 32.0)
   (:rotvel-z (degrees -1.2) (degrees 2.4))
   (:fade-a -0.42666668)
   (:timer (seconds 0.5))
   (:flags (bit2 bit3))))

(defpart 1989
  :init-specs
  ((:texture (bigpuff effects))
   (:num 16.0)
   (:y (meters 2))
   (:scale-x (meters 0.5) (meters 1))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 96.0)
   (:g 96.0)
   (:b 255.0)
   (:a 32.0 32.0)
   (:vel-y (meters 0.04) (meters 0.08))
   (:rotvel-z (degrees -1.2) (degrees 2.4))
   (:fade-a -0.85333335)
   (:friction 0.98)
   (:timer (seconds 0.25))
   (:flags (bit2 bit3))
   (:conerot-x (degrees 0) (degrees 180))
   (:conerot-y (degrees 0) (degrees 360))
   (:conerot-radius (meters 1.5))))

(defpart 1987
  :init-specs
  ((:texture (starflash effects))
   (:num 1.0)
   (:y (meters 2))
   (:scale-x (meters 12))
   (:rot-z (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 100.0 28.0)
   (:g 100.0)
   (:b 80.0)
   (:a 96.0)
   (:fade-a -0.08)
   (:timer (seconds 0.05))
   (:flags (bit2 bit3))))

(defstate die (lavaballoon)
  :virtual #t
  :code
    (behavior ()
      (ja-channel-set! 0)
      (clear-collide-with-as (-> self root))
      (ja-post)
      (sound-play "cool-balloon")
      (process-spawn part-tracker
                     :init
                     part-tracker-init
                     (-> *part-group-id-table* 543)
                     -1
                     #f
                     #f
                     #f
                     (-> self root trans)
                     :to
                     *entity-pool*)
      (suspend)
      (cleanup-for-death self)
      (deactivate self)))

(defstate idle (lavaballoon)
  :virtual #t
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('attack) (send-event proc 'heat -10.0) (go-virtual die))))
  :trans
    (behavior ()
      (when (not (logtest? (-> self path flags) (path-control-flag not-found)))
        (let ((f0-4 (* 0.5 (+ 1.0 (sin (* (-> self move-per-tick) (the float (current-time))))))))
          (eval-path-curve! (-> self path) (-> self root trans) f0-4 'interp))))
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post transform-post)

(defmethod init-from-entity! ((this lavaballoon) (arg0 entity-actor))
  (let ((s4-0 (new 'process 'collide-shape this (collide-list-enum hit-by-player))))
    (let ((s3-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0))))
      (set! (-> s3-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
      (set-vector! (-> s3-0 local-sphere) 0.0 8192.0 0.0 8192.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! (-> this root) s4-0))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *lavaballoon-sg* '())
  (set! (-> this part) (create-launch-control (-> *part-group-id-table* 543) this))
  (set! (-> this root pause-adjust-distance) 122880.0)
  (set! (-> this path) (new 'process 'path-control this 'path 0.0))
  (logior! (-> this path flags) (path-control-flag display draw-line draw-point draw-text))
  (when (not (logtest? (-> this path flags) (path-control-flag not-found)))
    (let ((f30-0 (res-lump-float (-> this entity) 'speed :default 12288.0)))
      (set! (-> this move-per-tick) (* 32768.0 (/ 1.0 (* 300.0 (path-distance (-> this path)))) f30-0))))
  (go (method-of-object this idle))
  (none))

(deftype lavatube-lava (water-anim) ())


(define ripple-for-lavatube-lava
  (new 'static
       'ripple-wave-set
       :count 2
       :converted #f
       :wave
       (new 'static
            'inline-array
            ripple-wave
            4
            (new 'static 'ripple-wave :scale 40.0 :xdiv 2 :speed 3.0)
            (new 'static 'ripple-wave :scale 40.0 :xdiv -2 :zdiv 2 :speed 1.8)
            (new 'static 'ripple-wave)
            (new 'static 'ripple-wave))))

(defstate water-vol-idle (lavatube-lava)
  :virtual #t
  :post
    (behavior ()
      (let ((t9-0 (-> (method-of-type water-anim water-vol-idle) post)))
        (if t9-0 ((the-as (function none :behavior lavatube-lava) t9-0))))
      (ja-post)))

(defmethod water-vol-method-22 ((this lavatube-lava))
  (let ((t9-0 (method-of-type water-anim water-vol-method-22))) (t9-0 this))
  (let ((v1-2 (new 'process 'ripple-control)))
    (set! (-> this draw ripple) v1-2)
    (set! (-> v1-2 global-scale) 2048.0)
    (set! (-> v1-2 waveform) ripple-for-lavatube-lava))
  (logclear! (-> this flags) (water-flags wt23))
  (logior! (-> this flags) (water-flags wt25))
  (set! (-> this attack-event) 'heat)
  (none))

(deftype lavayellowtarp (process-drawable) ()
  (:states
   lavayellowtarp-idle))


(defskelgroup *lavayellowtarp-sg*
  lavayellowtarp
  lavayellowtarp-lod0-jg
  lavayellowtarp-idle-ja
  ((lavayellowtarp-lod0-mg (meters 999999)))
  :bounds (static-spherem 0 0 0 5))

(defstate lavayellowtarp-idle (lavayellowtarp)
  :code
    (behavior ()
      (loop
        (ja-no-eval :group! (ja-group) :num! (seek!) :frame-num 0.0)
        (until (ja-done? 0)
          (suspend)
          (ja :num! (seek!)))))
  :post ja-post)

(defmethod init-from-entity! ((this lavayellowtarp) (arg0 entity-actor))
  (set! (-> this root) (new 'process 'trsqv))
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton this *lavayellowtarp-sg* '())
  (go lavayellowtarp-idle)
  (none))
