;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/game/effect-control.gc")
(require "engine/common-obs/generic-obs.gc")
(require "engine/gfx/foreground/ripple.gc")
(require "engine/common-obs/water-h.gc")
(require "engine/geometry/vol.gc")

;; DECOMP BEGINS

(defpart 108
  :init-specs
  ((:texture (water-ring effects))
   (:num 1.0)
   (:scale-x (meters 0.5) (meters 0.6))
   (:rot-y (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 64.0 64.0)
   (:scalevel-x (meters 0.0016666667) (meters 0.001))
   (:scalevel-y :copy scalevel-x)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.5))
   (:next-launcher 109)))

(defpart 109
  :init-specs ((:fade-a -0.2)))

(defun birth-func-y->userdata ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 matrix))
  (+! (-> arg1 user-float) (-> arg2 vector 0 y))
  0
  (none))

(defun birth-func-ocean-height ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 matrix))
  (set! (-> arg2 vector 0 y) (+ (ocean-get-height (the-as vector (-> arg2 vector))) (-> arg1 user-float)))
  0
  (none))

(defun check-water-level-drop ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 vector))
  (when (and (< (-> arg2 y) (-> arg1 user-float)) (< (-> arg1 vel-sxvel y) 0.0))
    (let ((s5-0 (new 'stack-no-clear 'vector)))
      (sp-kill-particle arg0 arg1)
      (set-vector! s5-0 (-> arg2 x) (-> arg1 user-float) (-> arg2 z) 1.0)
      (sound-play "water-drop" :position (the-as symbol s5-0))
      (launch-particles :system *sp-particle-system-3d* (-> *part-id-table* 108) s5-0)))
  0
  (none))

(defun check-water-level-drop-and-die ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 vector))
  (if (and (< (-> arg2 y) (-> arg1 user-float)) (< (-> arg1 vel-sxvel y) 0.0)) (sp-kill-particle arg0 arg1))
  (none))

(defun check-water-level-above-and-die ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 vector))
  (if (>= (-> arg2 y) (-> arg1 user-float)) (sp-kill-particle arg0 arg1))
  (none))

(defpart 110
  :init-specs
  ((:texture (lakedrop effects))
   (:num 12.0)
   (:x (meters -0.25) (meters 0.5))
   (:y (meters -0.05) (meters 0.1))
   (:z (meters -0.25) (meters 0.5))
   (:scale-x (meters 0.1) (meters 0.1))
   (:scale-y (meters 0.05) (meters 0.05))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 24.0 40.0)
   (:vel-y (meters 0) (meters 0.006666667))
   (:accel-y (meters 0.00016666666) (meters 0.00016666666))
   (:friction 0.96)
   (:timer (seconds 5))
   (:flags (bit2 bit3))
   (:userdata 0.0)
   (:func 'check-water-level-above-and-die)
   (:conerot-x (degrees 90))
   (:conerot-y (degrees 0) (degrees 360))))

(defpart 111
  :init-specs
  ((:texture (lakedrop effects))
   (:num 0.1)
   (:x (meters -0.25) (meters 0.5))
   (:y (meters 0.15))
   (:z (meters -0.25) (meters 0.5))
   (:scale-x (meters 0.3) (meters 0.1))
   (:scale-y (meters 0.15) (meters 0.05))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 40.0 24.0)
   (:vel-y (meters 0) (meters 0.006666667))
   (:accel-y (meters 0.00033333333))
   (:friction 0.96)
   (:timer (seconds 5))
   (:flags (bit2 bit3))
   (:userdata 0.0)
   (:func 'check-water-level-above-and-die)
   (:conerot-x (degrees 90))
   (:conerot-y (degrees 0) (degrees 360))))

(defpart 112
  :init-specs
  ((:texture (water-ring effects))
   (:num 0.05)
   (:x (meters -1) (meters 2))
   (:z (meters -1) (meters 2))
   (:scale-x (meters 0.2) (meters 0.5))
   (:rot-y (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 0.0)
   (:scalevel-x (meters 0.0016666667) (meters 0.001))
   (:scalevel-y :copy scalevel-x)
   (:fade-a 0.42666668)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.5))
   (:next-launcher 113)))

(defpart 113
  :init-specs ((:fade-a 0.0) (:next-time (seconds 1.2)) (:next-launcher 114)))

(defpart 114
  :init-specs ((:fade-a -0.7111111)))

(defpart 115
  :init-specs
  ((:texture (water-ring effects))
   (:num 0.04 0.03)
   (:x (meters -0.2) (meters 0.4))
   (:z (meters -0.2) (meters 0.4))
   (:scale-x (meters 0.5))
   (:rot-y (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 0.0)
   (:scalevel-x (meters 0.008333334))
   (:scalevel-y :copy scalevel-x)
   (:fade-a 0.64)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.5))
   (:next-launcher 116)))

(defpart 116
  :init-specs
  ((:scalevel-x (meters 0.006666667))
   (:scalevel-y :copy scalevel-x)
   (:fade-a 0.0)
   (:next-time (seconds 0.5))
   (:next-launcher 117)))

(defpart 117
  :init-specs ((:scalevel-x (meters 0.005)) (:scalevel-y :copy scalevel-x) (:fade-a -0.32)))

(defpart 118
  :init-specs
  ((:texture (water-wave effects))
   (:num 0.06)
   (:x (meters 10))
   (:scale-x (meters 0.75) (meters 1.5))
   (:rot-y (degrees 0))
   (:scale-y (meters 0.75) (meters 1.5))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 0.0)
   (:vel-x (meters 0.01) (meters 0.006666667))
   (:scalevel-x (meters 0.0033333334) (meters 0.004333333))
   (:scalevel-y (meters 0.0033333334) (meters 0.004333333))
   (:fade-a 0.7111111)
   (:friction 0.94)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.3))
   (:next-launcher 119)
   (:rotate-y (degrees 0))))

(defpart 119
  :init-specs ((:fade-a 0.0) (:next-time (seconds 0.3) (seconds 0.397)) (:next-launcher 120)))

(defpart 120
  :init-specs ((:fade-a -0.21333334)))

(defpart 121
  :init-specs
  ((:texture (water-ring effects))
   (:num 0.05 0.4)
   (:x (meters -0.5) (meters 1))
   (:z (meters 0.5) (meters 1.5))
   (:scale-x (meters 0.2) (meters 0.7))
   (:rot-y (degrees 0) (degrees 360))
   (:scale-y :copy scale-x)
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 0.0)
   (:scalevel-x (meters 0.0016666667) (meters 0.003))
   (:scalevel-y :copy scalevel-x)
   (:fade-a 0.42666668)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.5))
   (:next-launcher 122)
   (:rotate-y (degrees 0))))

(defpart 122
  :init-specs ((:fade-a 0.0) (:next-time (seconds 1.2)) (:next-launcher 123)))

(defpart 123
  :init-specs ((:fade-a -0.7111111)))

(defpartgroup group-part-water-splash
  :id 40
  :duration (seconds 3)
  :flags (use-local-clock)
  :bounds (static-bspherem 0 -12 0 14)
  :parts
  ((sp-item 124 :flags (is-3d) :period (seconds 3) :length (seconds 0.21))
   (sp-item 125 :period (seconds 3) :length (seconds 0.05))
   (sp-item 126 :flags (is-3d) :period (seconds 3) :length (seconds 0.05))
   (sp-item 127 :flags (is-3d) :period (seconds 3) :length (seconds 0.05))
   (sp-item 128 :period (seconds 3) :length (seconds 0.05) :binding 129)
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 130 :flags (is-3d) :period (seconds 3) :length (seconds 0.05) :offset 840)
   (sp-item 131 :flags (is-3d) :period (seconds 3) :length (seconds 0.2) :offset 840)
   (sp-item 132 :period (seconds 3) :length (seconds 0.035) :offset 840 :binding 133)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)
   (sp-item 133 :flags (start-dead) :period (seconds 3) :length (seconds 0.4) :offset 840)))

(defpartgroup group-part-water-splash-small
  :id 41
  :duration (seconds 3)
  :flags (use-local-clock)
  :bounds (static-bspherem 0 -12 0 14)
  :parts
  ((sp-item 124 :flags (is-3d) :period (seconds 3) :length (seconds 0.21))
   (sp-item 125 :period (seconds 3) :length (seconds 0.05))
   (sp-item 126 :flags (is-3d) :period (seconds 3) :length (seconds 0.05))
   (sp-item 127 :flags (is-3d) :period (seconds 3) :length (seconds 0.05))
   (sp-item 128 :period (seconds 3) :length (seconds 0.035) :binding 129)
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))
   (sp-item 129 :flags (start-dead) :period (seconds 3) :length (seconds 0.4))))

(defpart 129
  :init-specs
  ((:texture (lakedrop effects))
   (:num 0.4)
   (:x (meters -0.2) (meters 0.4))
   (:y (meters -0.2) (meters 0.4))
   (:scale-x (meters 0.05) (meters 0.15))
   (:scale-y :copy scale-x)
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 40.0 24.0)
   (:scalevel-x (meters 0.000033333334))
   (:scalevel-y :copy scalevel-x)
   (:accel-y (meters -0.00040000002) (meters -0.00020000001))
   (:timer (seconds 1.5))
   (:flags (bit3))
   (:userdata 0.0)
   (:func 'check-water-level-drop-and-die)))

(defpart 133
  :init-specs
  ((:texture (lakedrop effects))
   (:num 0.4)
   (:x (meters -0.2) (meters 0.4))
   (:y (meters -0.2) (meters 0.4))
   (:scale-x (meters 0.05) (meters 0.15))
   (:scale-y :copy scale-x)
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 40.0 24.0)
   (:scalevel-x (meters 0.000033333334))
   (:scalevel-y :copy scalevel-x)
   (:accel-y (meters -0.00040000002) (meters -0.00020000001))
   (:timer (seconds 1.5))
   (:flags (bit3))
   (:userdata 0.0)
   (:func 'check-water-level-drop-and-die)))

(defpart 131
  :init-specs
  ((:texture (water-ring effects))
   (:num 0.3)
   (:scale-x (meters 0.080000006) (meters 0.32000002))
   (:rot-y (degrees 0) (degrees 360))
   (:scale-y (meters 0.080000006) (meters 0.32000002))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 0.0)
   (:scalevel-x (meters 0.004) (meters 0.0090666665))
   (:scalevel-y (meters 0.004) (meters 0.0090666665))
   (:fade-a 0.32)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.5))
   (:next-launcher 134)))

(defpart 132
  :init-specs
  ((:texture (lakedrop effects))
   (:num 3.2)
   (:x (meters -0.2) (meters 0.4))
   (:y (meters -0.2) (meters 0.4))
   (:scale-x (meters 0.35) (meters 0.075))
   (:scale-y (meters 0.2) (meters 0.075))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 40.0 24.0)
   (:vel-x (meters -0.002) (meters 0.004))
   (:vel-y (meters 0.018666666) (meters 0.0053333333))
   (:vel-z (meters -0.002) (meters 0.004))
   (:scalevel-x (meters -0.00066666666))
   (:scalevel-y :copy scalevel-x)
   (:accel-y (meters -0.00080000004) (meters -0.00020000001))
   (:timer (seconds 3))
   (:flags (bit3))
   (:userdata 0.0)
   (:func 'check-water-level-drop)
   (:next-time (seconds 0.4))
   (:next-launcher 135)))

(defpart 130
  :init-specs
  ((:texture (water-splash effects))
   (:num 1.0)
   (:scale-x (meters 0.24000001) (meters 0.71999997))
   (:rot-x (degrees 90))
   (:rot-y (degrees 0) (degrees 360))
   (:rot-z (degrees 0))
   (:scale-y (meters 0.8) (meters 1.7600001))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 32.0 32.0)
   (:scalevel-y (meters 0.053333335) (meters 0.013333334))
   (:timer (seconds 0.8))
   (:flags (bit2 bit3 left-multiply-quat set-conerot))
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 136)))

(defpart 136
  :init-specs ((:scalevel-y (meters 0.026666667)) (:next-time (seconds 0.067)) (:next-launcher 137)))

(defpart 137
  :init-specs ((:scalevel-y (meters 0)) (:fade-a -0.64) (:next-time (seconds 0.067)) (:next-launcher 138)))

(defpart 138
  :init-specs
  ((:scalevel-x (meters 0.0016666667))
   (:scalevel-y (meters -0.026666667))
   (:next-time (seconds 0.067))
   (:next-launcher 139)))

(defpart 139
  :init-specs ((:scalevel-x (meters 0.0033333334)) (:scalevel-y (meters -0.053333335))))

(defpart 126
  :init-specs
  ((:texture (water-ring effects))
   (:num 1.0)
   (:scale-x (meters 2.4) (meters 1.6))
   (:rot-y (degrees 0) (degrees 360))
   (:scale-y (meters 2.4) (meters 1.6))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 0.0)
   (:scalevel-x (meters 0.004) (meters 0.0037333334))
   (:scalevel-y (meters 0.004) (meters 0.0037333334))
   (:fade-a 0.32)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.5))
   (:next-launcher 134)))

(defpart 134
  :init-specs ((:fade-a 0.0) (:next-time (seconds 1.2)) (:next-launcher 140)))

(defpart 140
  :init-specs ((:fade-a -0.53333336)))

(defpart 127
  :init-specs
  ((:texture (water-ring effects))
   (:num 0.5 1.0)
   (:x (meters -0.4) (meters 0.8))
   (:y (meters -0.4) (meters 0.8))
   (:scale-x (meters 0.4) (meters 0.8))
   (:rot-y (degrees 0) (degrees 360))
   (:scale-y (meters 0.4) (meters 0.8))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 0.0)
   (:scalevel-x (meters 0.004) (meters 0.0026666666))
   (:scalevel-y (meters 0.004) (meters 0.0026666666))
   (:fade-a 0.32)
   (:timer (seconds 2))
   (:flags (bit2 bit3 left-multiply-quat))
   (:next-time (seconds 0.5))
   (:next-launcher 134)))

(defpart 128
  :init-specs
  ((:texture (lakedrop effects))
   (:num 3.2)
   (:x (meters 0.96000004))
   (:scale-x (meters 0.35) (meters 0.075))
   (:scale-y (meters 0.2) (meters 0.075))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 40.0 24.0)
   (:vel-x (meters 0.0026666666) (meters 0.0053333333))
   (:vel-y (meters 0.016) (meters 0.0053333333))
   (:scalevel-x (meters -0.00066666666))
   (:scalevel-y :copy scalevel-x)
   (:accel-y (meters -0.00080000004) (meters -0.00020000001))
   (:timer (seconds 3))
   (:flags (bit3))
   (:userdata 0.0)
   (:func 'check-water-level-drop)
   (:next-time (seconds 0.4))
   (:next-launcher 135)
   (:rotate-y (degrees 0) (degrees 360))))

(defpart 135
  :init-specs ((:scalevel-x (meters 0)) (:scalevel-y :copy scalevel-x)))

(defpart 125
  :init-specs
  ((:texture (lakedrop effects))
   (:num 8.0)
   (:x (meters 0.8))
   (:scale-x (meters 0.15) (meters 0.05))
   (:scale-y (meters 0.15) (meters 0.05))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 40.0 24.0)
   (:vel-x (meters 0.0026666666) (meters 0.0053333333))
   (:vel-y (meters 0.0053333333) (meters 0.0053333333))
   (:scalevel-x (meters -0.00033333333))
   (:scalevel-y (meters -0.00033333333))
   (:accel-y (meters -0.0005333334) (meters -0.00013333335))
   (:timer (seconds 1.25))
   (:flags (bit2 bit3))
   (:userdata 0.0)
   (:func 'check-water-level-drop-and-die)
   (:rotate-y (degrees 0) (degrees 360))))

(defpart 124
  :init-specs
  ((:texture (water-splash effects))
   (:num 1.5)
   (:x (meters 0.96000004) (meters 0.16000001))
   (:scale-x (meters 0.32000002) (meters 0.96000004))
   (:rot-x (degrees 90))
   (:rot-y (degrees 90))
   (:rot-z (degrees 0))
   (:scale-y (meters 0.16000001) (meters 1.7600001))
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 48.0 24.0)
   (:vel-x (meters 0.0026666666))
   (:scalevel-x (meters 0) (meters 0.0016666667))
   (:rotvel-x (degrees 0.2))
   (:scalevel-y (meters 0.04))
   (:timer (seconds 0.8))
   (:flags (bit2 bit3 left-multiply-quat set-conerot))
   (:next-time (seconds 0.067) (seconds 0.065))
   (:next-launcher 141)
   (:rotate-y (degrees 0) (degrees 360))))

(defpart 141
  :init-specs
  ((:scalevel-x (meters 0))
   (:rotvel-x (degrees 0.16666667))
   (:scalevel-y (meters 0.016666668))
   (:next-time (seconds 0.067))
   (:next-launcher 142)))

(defpart 142
  :init-specs
  ((:rotvel-x (degrees 0.13333334))
   (:scalevel-y (meters 0))
   (:fade-a -0.64)
   (:next-time (seconds 0.067))
   (:next-launcher 143)))

(defpart 143
  :init-specs ((:rotvel-x (degrees 0.1)) (:scalevel-y (meters -0.016666668)) (:next-time (seconds 0.067)) (:next-launcher 144)))

(defpart 144
  :init-specs ((:rotvel-x (degrees 0.06666667)) (:scalevel-y (meters -0.033333335))))

(defpart 145
  :init-specs
  ((:texture (lakedrop effects))
   (:num 1.0)
   (:scale-x (meters 0.15) (meters 0.05))
   (:scale-y :copy scale-x)
   (:r 128.0)
   (:g 128.0)
   (:b 128.0)
   (:a 40.0 24.0)
   (:vel-x (meters -0.016666668) (meters 0.0016666667))
   (:vel-y (meters 0.016666668))
   (:vel-z (meters -0.016666668) (meters 0.0016666667))
   (:scalevel-x (meters -0.00016666666))
   (:scalevel-y :copy scalevel-x)
   (:accel-y (meters -0.00066666666))
   (:timer (seconds 1))
   (:flags (bit2 bit3))
   (:userdata 0.0)
   (:func 'check-water-level-drop-and-die)
   (:next-time (seconds 0.75))
   (:next-launcher 114)))

(defmethod water-control-method-9 ((this water-control))
  0
  (none))

(defmethod water-control-method-10 ((this water-control))
  (with-pp
    (let ((s5-0 (-> this flags)))
      (cond
        ((not (logtest? (-> this flags) (water-flags wt01)))
         (logclear! (-> this flags) (water-flags wt09 wt10 wt11 wt12 wt13 wt14 wt16)))
        ((and (logtest? (water-flags wt21) (-> this flags)) (logtest? (-> this process state-flags) (state-flags grabbed)))
         (logior! (-> this flags) (water-flags wt16)))
        ((begin
           (set! (-> this top 1 quad) (-> this top 0 quad))
           (vector<-cspace! (the-as vector (-> this top)) (-> this process node-list data (-> this joint-index)))
           (+! (-> this top 0 y) (-> this top-y-offset))
           (set! (-> this bottom 1 quad) (-> this bottom 0 quad))
           (set! (-> this bottom 0 quad) (-> this process root trans quad))
           (logclear! (-> this flags) (water-flags wt10 wt11 wt12 wt13 wt14))
           (set! (-> this bob-offset) (update! (-> this bob)))
           (cond
             ((and (logtest? (-> this flags) (water-flags wt08))
                   (not (logtest? (-> (the-as collide-shape-moving (-> this process root)) root-prim prim-core action) (collide-action racer))))
              (set! (-> this real-ocean-offset) (- (ocean-get-height (the-as vector (-> this bottom))) (-> this base-height)))
              (if (not (logtest? (-> this flags) (water-flags wt09)))
                (set! (-> this ocean-offset) (-> this real-ocean-offset))
                (set! (-> this ocean-offset) (lerp (-> this ocean-offset) (-> this real-ocean-offset) 0.2))))
             ((logtest? (water-flags wt20) (-> this flags))
              (let* ((a0-26 (-> this volume process 0))
                     (f30-0 (ripple-find-height (the-as process-drawable a0-26) 0 (the-as vector (-> this bottom)))))
                (set! (-> this real-ocean-offset) (- f30-0 (-> this base-height)))
                (if (not (logtest? (-> this flags) (water-flags wt09)))
                  (set! (-> this ocean-offset) (-> this real-ocean-offset))
                  (set! (-> this ocean-offset) (lerp (-> this ocean-offset) (-> this real-ocean-offset) 0.2)))
                (let ((v1-36 (new 'stack-no-clear 'vector))) (set! (-> v1-36 quad) (-> this bottom 0 quad)) (set! (-> v1-36 y) f30-0))))
             (else (set! (-> this real-ocean-offset) 0.0) (set! (-> this ocean-offset) 0.0)))
           (if (logtest? (-> (the-as collide-shape-moving (-> this process root)) root-prim prim-core action) (collide-action racer))
             (set! (-> this bob-offset) 0.0))
           (set! (-> this height) (+ (-> this base-height) (-> this ocean-offset) (-> this bob-offset) (-> this align-offset)))
           (set! (-> this surface-height) (+ (-> this base-height) (-> this real-ocean-offset)))
           (set! (-> this swim-depth) (fmax 0.0 (- (- (-> this surface-height) (-> this swim-height)) (-> this bottom 0 y))))
           (>= (-> this height) (-> this bottom 0 y)))
         (if (logtest? (-> (the-as collide-shape-moving (-> this process root)) status) (cshape-moving-flags on-water))
           (set-time! (-> this on-water-time)))
         (set! (-> this drip-wetness) 1.0)
         (set! (-> this drip-height) (fmax (- (-> this surface-height) (-> this bottom 0 y)) (-> this drip-height)))
         (set! (-> this drip-speed) 15.0)
         (if (not (logtest? (-> this flags) (water-flags wt09))) (water-control-method-15 this))
         (cond
           ((>= (-> this top 0 y) (-> this height))
            (let ((s4-0 (new 'stack-no-clear 'vector)))
              (set! (-> s4-0 quad) (-> this bottom 0 quad))
              (vector-xz-length (-> this process root transv))
              (set! (-> s4-0 y) (-> this surface-height))
              (when (and (logtest? (-> this process draw status) (draw-status was-drawn))
                         (zero? (-> this process draw cur-lod))
                         (logtest? (water-flags wt22) (-> this flags))
                         (logtest? (water-flags wt23) (-> this flags)))
                (let ((f30-1 (y-angle (-> this process root)))
                      (f28-0 (vector-xz-length (-> this process root transv))))
                  (set! (-> *part-id-table* 118 init-specs 4 initial-valuef) (+ 24576.0 f30-1))
                  (set! (-> *part-id-table* 118 init-specs 19 initial-valuef) (+ 49152.0 f30-1))
                  (set! (-> *part-id-table* 118 init-specs 1 initial-valuef) (* 0.0000036621095 f28-0))
                  (set! (-> *part-id-table* 118 init-specs 2 initial-valuef) (/ f28-0 10))
                  (set! (-> *part-id-table* 118 init-specs 13 initial-valuef) 0.7111111)
                  (launch-particles :system *sp-particle-system-3d* (-> *part-id-table* 118) s4-0)
                  (set! (-> *part-id-table* 121 init-specs 1 initial-valuef) (* 0.000004150391 f28-0))
                  (set! (-> *part-id-table* 121 init-specs 18 initial-valuef) f30-1)
                  (launch-particles :system *sp-particle-system-3d* (-> *part-id-table* 121) s4-0)
                  (when (< f28-0 4096.0)
                    (set! (-> *part-id-table* 112 init-specs 4 random-rangef) (-> this ripple-size))
                    (launch-particles :system *sp-particle-system-3d* (-> *part-id-table* 112) s4-0)
                    (launch-particles :system *sp-particle-system-3d* (-> *part-id-table* 115) s4-0))))
              (if (< (-> this top 1 y) (-> this height)) (create-splash this 0.2 s4-0 1 (-> this process root transv)))))
           (else (logior! (-> this flags) (water-flags wt13))))
         (when (and (logtest? (-> this flags) (water-flags wt05)) (logtest? (water-flags wt23) (-> this flags)))
           (let* ((v1-124 (rand-vu-int-range 3 (+ (-> this process node-list length) -1)))
                  (s4-1 (vector<-cspace! (new 'stack-no-clear 'vector) (-> this process node-list data v1-124))))
             (set! (-> *part-id-table* 110 init-specs 16 initial-valuef) (-> this surface-height))
             (set! (-> *part-id-table* 110 init-specs 1 initial-valuef)
                   (+ (lerp-scale 12.0 0.4 (the float (- (current-time) (-> this enter-water-time))) 0.0 600.0)
                      (* 0.00012207031 (vector-xz-length (-> this process root transv)))))
             (launch-particles (-> *part-id-table* 110) s4-1)
             (set! (-> *part-id-table* 111 init-specs 16 initial-valuef) (-> this surface-height))
             (launch-particles (-> *part-id-table* 111) s4-1)))
         (let ((f30-3 (- (+ (-> this base-height) (-> this ocean-offset) (-> this bob-offset) (-> this align-offset)) (-> this swim-height))))
           (let* ((s4-2 (-> this process root))
                  (v1-146 (if (and (nonzero? s4-2) (type-type? (-> s4-2 type) control-info)) s4-2))
                  (s4-3 (and v1-146 (not (time-elapsed? (-> (the-as control-info v1-146) unknown-dword11) (seconds 0.5))))))
             (if (and (logtest? (-> this flags) (water-flags wt04))
                      (and s4-3
                           (not (logtest? (-> (the-as collide-shape-moving (-> this process root)) status) (cshape-moving-flags on-water)))))
               (set! (-> this bob amp) (* 0.8 (-> this bob amp))))
             (cond
               ((and (logtest? (-> this flags) (water-flags wt03))
                     (or (logtest? (-> (the-as collide-shape-moving (-> this process root)) status) (cshape-moving-flags on-water))
                         (>= f30-3 (-> this bottom 0 y))
                         (and (logtest? s5-0 (water-flags wt11))
                              (logtest? (-> (the-as collide-shape-moving (-> this process root)) status) (cshape-moving-flags tsurf))
                              (not (logtest? (-> (the-as collide-shape-moving (-> this process root)) status) (cshape-moving-flags onsurf)))
                              (>= (+ 204.8 f30-3) (-> this bottom 0 y))))
                     (or (logtest? s5-0 (water-flags wt11))
                         (< 12288.0 (vector-xz-length (-> this process root transv)))
                         (< (+ (current-time) (seconds -0.2)) (-> this enter-water-time))
                         (>= (+ (- 204.8 (fmin 6144.0 (+ (-> this ocean-offset) (-> this bob-offset) (-> this align-offset)))) f30-3)
                             (-> this bottom 0 y))))
                (set-time! (-> this swim-time))
                (send-event (-> this process) 'swim)
                (logior! (-> this flags) (water-flags wt11))
                (if (not (logtest? s5-0 (water-flags wt11))) (set-time! (-> this enter-swim-time)))
                (cond
                  ((and (logtest? (-> this flags) (water-flags wt04))
                        (logtest? (-> (the-as collide-shape-moving (-> this process root)) status) (cshape-moving-flags tsurf))
                        (not (logtest? (water-flags wt16) (-> this flags))))
                   (let ((v1-200 (new 'stack-no-clear 'vector)))
                     (set! (-> v1-200 quad) (-> this bottom 0 quad))
                     (set! (-> v1-200 y) (- (-> this height) (-> this swim-height)))
                     (let ((s4-4 (-> this process root)))
                       (when (and (not (logtest? (-> (the-as collide-shape-moving s4-4) status) (cshape-moving-flags csmf12)))
                                  (logtest? (-> this flags) (water-flags wt11))
                                  (not (logtest? (-> (the-as collide-shape-moving s4-4) root-prim prim-core action) (collide-action racer))))
                         (let ((a1-27 (vector-! (new 'stack-no-clear 'vector) v1-200 (-> s4-4 trans))))
                           (vector-float*! a1-27 a1-27 (-> *display* frames-per-second))
                           (integrate-and-collide! (the-as collide-shape-moving s4-4) a1-27))
                         (logior! (-> (the-as collide-shape-moving s4-4) status) (cshape-moving-flags onsurf onground tsurf on-water))))))
                  ((and (< (-> this bottom 0 y) f30-3) (not (logtest? (water-flags wt16) (-> this flags))))
                   (logior! (-> this flags) (water-flags wt12)))))
               ((begin
                  (set! s4-3
                        (and (logtest? (-> this flags) (water-flags wt02))
                             (or (not (!= (-> this bob amp) 0.0)) (time-elapsed? (-> this swim-time) (seconds 0.05)))
                             (and (>= (- (-> this height) (-> this wade-height)) (-> this bottom 0 y)) s4-3)))
                  s4-3)
                (set-time! (-> this wade-time))
                (send-event (-> this process) 'wade)
                (logior! (-> this flags) (water-flags wt10)))))
           (when (and (logtest? (-> this flags) (water-flags wt03))
                      (< (-> this bottom 1 y) f30-3)
                      (and (< f30-3 (-> this bottom 0 y)) (logtest? s5-0 (water-flags wt12))))
             (logior! (-> this flags) (water-flags wt11))
             (let ((a1-30 (new 'stack-no-clear 'vector)))
               (set! (-> a1-30 quad) (-> this bottom 0 quad))
               (let ((s5-1 (-> this process root)))
                 (set! (-> a1-30 y) f30-3)
                 (when (not (logtest? (-> (the-as collide-shape-moving s5-1) root-prim prim-core action) (collide-action racer)))
                   (let ((f30-4 (-> (the-as collide-shape-moving s5-1) ground-impact-vel)))
                     (move-to-ground-point! (the-as collide-shape-moving s5-1) a1-30 (-> s5-1 transv) *up-vector*)
                     (logior! (-> (the-as collide-shape-moving s5-1) status) (cshape-moving-flags on-water))
                     (set! (-> (the-as collide-shape-moving s5-1) ground-impact-vel) f30-4)))))))
         (when (and (logtest? (water-flags wt17) (-> this flags)) (= (-> this process type) target))
           (when (and (logtest? (-> (the-as collide-shape-moving (-> this process root)) status) (cshape-moving-flags onsurf on-water))
                      (not (logtest? (-> (the-as collide-shape-moving (-> this process root)) root-prim prim-core action) (collide-action racer))))
             (when (< (-> this process root trans y) -409.6)
               (send-event (-> this process) 'no-look-around (seconds 1.5))
               (when (not (logtest? (-> (the-as collide-shape-moving (-> this process root)) root-prim prim-core action) (collide-action flut)))
                 (cond
                   ((= (-> this process type) target)
                    (send-event (-> this process)
                                'attack
                                #f
                                (static-attack-info ((shove-up (meters 0.5)) (shove-back (meters 0)) (mode 'tar)))))
                   (else
                    (let ((a1-33 (new 'stack-no-clear 'event-message-block)))
                      (set! (-> a1-33 from) pp)
                      (set! (-> a1-33 num-params) 4)
                      (set! (-> a1-33 message) 'attack)
                      (set! (-> a1-33 param 0) (the-as uint #f))
                      (set! (-> a1-33 param 1) (the-as uint 'tar))
                      (let ((v1-281 (+ *global-attack-id* 1)))
                        (set! *global-attack-id* v1-281)
                        (set! (-> a1-33 param 2) (the-as uint v1-281)))
                      (set! (-> a1-33 param 3) (the-as uint 0))
                      (send-event-function (-> this process) a1-33)))))
               (let ((v1-283 (-> this process)))
                 (set! (-> (the-as collide-shape-moving (-> v1-283 root)) surf) *tar-surface*)
                 (set! (-> (the-as collide-shape-moving (-> v1-283 root)) ground-pat material) 4)))
             (set! (-> this swim-height) (lerp (-> this swim-height) 7372.8 0.05)))))
        (else (if (logtest? (-> this flags) (water-flags wt09)) (water-control-method-16 this)))))
    (when (not (or (not (logtest? (-> this flags) (water-flags wt06)))
                   (not (logtest? (water-flags wt23) (-> this flags)))
                   (= (-> this drip-wetness) 0.0)))
      (cond
        ((logtest? (-> this flags) (water-flags wt15))
         (let ((a2-15 (vector<-cspace! (new 'stack-no-clear 'vector) (-> this process node-list data (-> this drip-joint-index)))))
           (set! (-> *part-id-table* 145 init-specs 16 initial-valuef) (fmax (-> this surface-height) (-> this bottom 0 y)))
           (set! (-> *part-id-table* 145 init-specs 8 initial-valuef) (* 0.05 (- (-> a2-15 x) (-> this drip-old-pos x))))
           (set! (-> *part-id-table* 145 init-specs 9 initial-valuef) (* 0.05 (- (-> a2-15 y) (-> this drip-old-pos y))))
           (set! (-> *part-id-table* 145 init-specs 10 initial-valuef) (* 0.05 (- (-> a2-15 z) (-> this drip-old-pos z))))
           (launch-particles (-> *part-id-table* 145) a2-15))
         (set-time! (-> this drip-time))
         (logclear! (-> this flags) (water-flags wt15))
         (seek! (-> this drip-wetness) 0.0 (/ (-> this drip-speed) 1000))
         (set! (-> this drip-speed) (* 1.05 (-> this drip-speed)))
         (if (= (-> this drip-wetness) 0.0) (set! (-> this drip-height) 0.0)))
        ((time-elapsed? (the-as time-frame (the int (/ (the float (-> this drip-time)) (-> this drip-mult))))
                        (the int (-> this drip-speed)))
         (let* ((s5-2 (rand-vu-int-range 3 (+ (-> this process node-list length) -1)))
                (v1-328 (vector<-cspace! (new 'stack-no-clear 'vector) (-> this process node-list data s5-2))))
           (when (and (< (- (-> v1-328 y) (-> this process root trans y)) (-> this drip-height)) (< (-> this height) (-> v1-328 y)))
             (set! (-> this drip-joint-index) s5-2)
             (set! (-> this drip-old-pos quad) (-> v1-328 quad))
             (logior! (-> this flags) (water-flags wt15)))))))
    0
    (none)))

(defmethod start-bobbing! ((this water-control) (arg0 float) (arg1 int) (arg2 int))
  (activate! (-> this bob) (- arg0) arg1 arg2 0.9 1.0)
  0
  (none))

(defun part-water-splash-callback ((arg0 part-tracker))
  (let ((f1-0 (-> arg0 root trans y))
        (f0-0 (the-as float (-> arg0 userdata))))
    (set! (-> *part-id-table* 128 init-specs 16 initial-valuef) f1-0)
    (set! (-> *part-id-table* 132 init-specs 18 initial-valuef) f1-0)
    (set! (-> *part-id-table* 125 init-specs 16 initial-valuef) f1-0)
    (set! (-> *part-id-table* 129 init-specs 15 initial-valuef) f1-0)
    (set! (-> *part-id-table* 133 init-specs 15 initial-valuef) f1-0)
    (set! (-> *part-id-table* 129 init-specs 12 initial-valuef) (* 13.653334 (* -0.15 f0-0)))
    (set! (-> *part-id-table* 129 init-specs 12 random-rangef) (* 13.653334 (* -0.075 f0-0)))
    (set! (-> *part-id-table* 133 init-specs 12 initial-valuef) (* 13.653334 (* -0.15 f0-0)))
    (set! (-> *part-id-table* 133 init-specs 12 random-rangef) (* 13.653334 (* -0.075 f0-0)))
    (set! (-> *part-id-table* 131 init-specs 2 initial-valuef) (* 4096.0 (/ f0-0 10)))
    (set! (-> *part-id-table* 131 init-specs 2 random-rangef) (* 4096.0 (* 0.4 f0-0)))
    (set! (-> *part-id-table* 131 init-specs 4 initial-valuef) (* 4096.0 (/ f0-0 10)))
    (set! (-> *part-id-table* 131 init-specs 4 random-rangef) (* 4096.0 (* 0.4 f0-0)))
    (set! (-> *part-id-table* 131 init-specs 9 initial-valuef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 131 init-specs 9 random-rangef) (* 13.653334 (* 3.4 f0-0)))
    (set! (-> *part-id-table* 131 init-specs 10 initial-valuef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 131 init-specs 10 random-rangef) (* 13.653334 (* 3.4 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 2 initial-valuef) (* 4096.0 (* 3.0 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 2 random-rangef) (* 4096.0 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 4 initial-valuef) (* 4096.0 (* 3.0 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 4 random-rangef) (* 4096.0 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 9 initial-valuef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 9 random-rangef) (* 13.653334 (* 1.4 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 10 initial-valuef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 126 init-specs 10 random-rangef) (* 13.653334 (* 1.4 f0-0)))
    (set! (-> *part-id-table* 127 init-specs 2 initial-valuef) (* 4096.0 (/ f0-0 -2)))
    (set! (-> *part-id-table* 127 init-specs 2 random-rangef) (* 4096.0 f0-0))
    (set! (-> *part-id-table* 127 init-specs 3 initial-valuef) (* 4096.0 (/ f0-0 -2)))
    (set! (-> *part-id-table* 127 init-specs 3 random-rangef) (* 4096.0 f0-0))
    (set! (-> *part-id-table* 127 init-specs 4 initial-valuef) (* 4096.0 (/ f0-0 2)))
    (set! (-> *part-id-table* 127 init-specs 4 random-rangef) (* 4096.0 f0-0))
    (set! (-> *part-id-table* 127 init-specs 6 initial-valuef) (* 4096.0 (/ f0-0 2)))
    (set! (-> *part-id-table* 127 init-specs 6 random-rangef) (* 4096.0 f0-0))
    (set! (-> *part-id-table* 127 init-specs 11 initial-valuef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 127 init-specs 11 random-rangef) (* 13.653334 f0-0))
    (set! (-> *part-id-table* 127 init-specs 12 initial-valuef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 127 init-specs 12 random-rangef) (* 13.653334 f0-0))
    (set! (-> *part-id-table* 132 init-specs 1 initial-valuef) (* 4.0 f0-0))
    (set! (-> *part-id-table* 132 init-specs 2 initial-valuef) (* 4096.0 (/ f0-0 -4)))
    (set! (-> *part-id-table* 132 init-specs 2 random-rangef) (* 4096.0 (/ f0-0 2)))
    (set! (-> *part-id-table* 132 init-specs 3 initial-valuef) (* 4096.0 (/ f0-0 -4)))
    (set! (-> *part-id-table* 132 init-specs 3 random-rangef) (* 4096.0 (/ f0-0 2)))
    (set! (-> *part-id-table* 132 init-specs 10 initial-valuef) (* 13.653334 (* -0.75 f0-0)))
    (set! (-> *part-id-table* 132 init-specs 10 random-rangef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 132 init-specs 12 initial-valuef) (* 13.653334 (* -0.75 f0-0)))
    (set! (-> *part-id-table* 132 init-specs 12 random-rangef) (* 13.653334 (* 1.5 f0-0)))
    (set! (-> *part-id-table* 132 init-specs 11 initial-valuef) (* 13.653334 (* 7.0 f0-0)))
    (set! (-> *part-id-table* 132 init-specs 11 random-rangef) (* 13.653334 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 132 init-specs 15 initial-valuef) (* 13.653334 (* -0.3 f0-0)))
    (set! (-> *part-id-table* 132 init-specs 15 random-rangef) (* 13.653334 (* -0.075 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 1 initial-valuef) (* 4.0 f0-0))
    (set! (-> *part-id-table* 128 init-specs 2 initial-valuef) (* 1.2 f0-0))
    (set! (-> *part-id-table* 128 init-specs 9 initial-valuef) (* 13.653334 f0-0))
    (set! (-> *part-id-table* 128 init-specs 9 random-rangef) (* 13.653334 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 10 initial-valuef) (* 13.653334 (* 6.0 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 10 random-rangef) (* 13.653334 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 13 initial-valuef) (* 13.653334 (* -0.3 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 13 random-rangef) (* 13.653334 (* -0.075 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 9 initial-valuef) (* 13.653334 f0-0))
    (set! (-> *part-id-table* 128 init-specs 9 random-rangef) (* 13.653334 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 10 initial-valuef) (* 13.653334 (* 6.0 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 10 random-rangef) (* 13.653334 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 13 initial-valuef) (* 13.653334 (* -0.3 f0-0)))
    (set! (-> *part-id-table* 128 init-specs 13 random-rangef) (* 13.653334 (* -0.075 f0-0)))
    (set! (-> *part-id-table* 125 init-specs 1 initial-valuef) (* 8.0 f0-0))
    (set! (-> *part-id-table* 125 init-specs 2 initial-valuef) (* 4096.0 f0-0))
    (set! (-> *part-id-table* 125 init-specs 9 initial-valuef) (* 13.653334 f0-0))
    (set! (-> *part-id-table* 125 init-specs 9 random-rangef) (* 13.653334 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 125 init-specs 10 initial-valuef) (* 13.653334 (* 6.0 f0-0)))
    (set! (-> *part-id-table* 125 init-specs 10 random-rangef) (* 13.653334 (* 2.0 f0-0)))
    (set! (-> *part-id-table* 125 init-specs 13 initial-valuef) (* 13.653334 (* -0.3 f0-0)))
    (set! (-> *part-id-table* 125 init-specs 13 random-rangef) (* 13.653334 (* -0.075 f0-0)))
    (set! (-> *part-id-table* 124 init-specs 2 initial-valuef) (* 4096.0 (* 1.2 f0-0)))
    (set! (-> *part-id-table* 124 init-specs 2 random-rangef) (* 4096.0 (/ f0-0 5)))
    (set! (-> *part-id-table* 124 init-specs 3 initial-valuef) (* 4096.0 (* 0.4 f0-0)))
    (set! (-> *part-id-table* 124 init-specs 3 random-rangef) (* 4096.0 (* 1.2 f0-0)))
    (set! (-> *part-id-table* 124 init-specs 7 initial-valuef) (* 4096.0 (/ f0-0 5)))
    (set! (-> *part-id-table* 124 init-specs 7 random-rangef) (* 4096.0 (* 2.2 f0-0)))
    (set! (-> *part-id-table* 130 init-specs 2 initial-valuef) (* 4096.0 (* 0.3 f0-0)))
    (set! (-> *part-id-table* 130 init-specs 2 random-rangef) (* 4096.0 (* 0.9 f0-0)))
    (set! (-> *part-id-table* 130 init-specs 6 initial-valuef) (* 4096.0 f0-0))
    (set! (-> *part-id-table* 130 init-specs 6 random-rangef) (* 4096.0 (* 2.2 f0-0))))
  0
  (none))

(defmethod water-control-method-15 ((this water-control))
  (with-pp
    (logior! (-> this flags) (water-flags wt09))
    (logclear! (-> this flags) (water-flags wt16))
    (set-time! (-> this enter-water-time))
    (set-vector! (-> this enter-water-pos) (-> this bottom 0 x) (-> this surface-height) (-> this bottom 0 z) 1.0)
    (when (and (logtest? (-> this flags) (water-flags wt05)) (logtest? (water-flags wt23) (-> this flags)))
      (let ((a1-1 (new 'stack-no-clear 'event-message-block)))
        (set! (-> a1-1 from) pp)
        (set! (-> a1-1 num-params) 1)
        (set! (-> a1-1 message) 'query)
        (set! (-> a1-1 param 0) (the-as uint 'ground-height))
        (let* ((f0-4 (the-as float (send-event-function (-> this process) a1-1)))
               (f30-0 (lerp-scale 0.3 1.0 f0-4 2048.0 24576.0)))
          (if (nonzero? (-> this process skel effect)) (effect-control-method-10 (-> this process skel effect) 'swim-stroke 0.0 -1))
          (create-splash this f30-0 (-> this enter-water-pos) 1 (-> this process root transv)))))
    (if (logtest? (water-flags wt17) (-> this flags)) (set! (-> this swim-height) 2867.2))
    0
    (none)))

(defmethod water-control-method-16 ((this water-control))
  (logclear! (-> this flags) (water-flags wt09))
  (set-zero! (-> this bob))
  (if (logtest? (water-flags wt17) (-> this flags)) (set! (-> this swim-height) 2867.2))
  0
  (none))

(defun splash-spawn ((arg0 basic) (arg1 basic) (arg2 int))
  (process-spawn part-tracker
                 :init
                 part-tracker-init
                 (if (zero? arg2) (-> *part-group-id-table* 41) (-> *part-group-id-table* 40))
                 -1
                 part-water-splash-callback
                 arg0
                 #f
                 arg1
                 :to
                 *entity-pool*)
  0
  (none))

(defmethod create-splash ((this water-control) (arg0 float) (arg1 vector) (arg2 int) (arg3 vector))
  (when (and (logtest? (-> this flags) (water-flags wt05)) (logtest? (water-flags wt23) (-> this flags)))
    (let ((a1-3 (vector+float*! (new 'stack-no-clear 'vector) arg1 arg3 0.05)))
      (set! (-> a1-3 y) (-> this surface-height))
      (splash-spawn (the-as basic arg0) (the-as basic a1-3) arg2)))
  0
  (none))

(defmethod on-exit-water ((this water-vol))
  (when (handle->process (-> this target))
    (let ((v1-7 (-> (the-as target (-> this target process 0)) water)))
      (logclear! (-> v1-7 flags) (water-flags wt01 wt02 wt03 wt08 wt17 wt18 wt19 wt20 wt21 wt23 wt24 wt25 wt26))
      (set! (-> v1-7 volume) (the-as handle #f)))
    (set! (-> this target) (the-as handle #f))
    (iterate-process-tree *entity-pool*
                          (lambda ((arg0 water-vol))
                            (with-pp
                              (if (and (type-type? (-> arg0 type) water-vol) (!= arg0 pp)) (send-event arg0 'update))))
                          *null-kernel-context*)
    (process-entity-status! this (entity-perm-status bit-3) #f))
  0
  (none))

(defmethod update! ((this water-vol))
  (cond
    ((handle->process (-> this target))
     (cond
       ((not (point-in-vol? (-> this vol) (-> (the-as target (-> this target process 0)) control trans))) (on-exit-water this))
       (else
        (let ((v1-15 (-> (the-as target (-> this target process 0)) water)))
          (when (and (logtest? (water-flags wt19) (-> this flags))
                     (logtest? (-> v1-15 flags) (water-flags wt09))
                     (>= (-> v1-15 surface-height) (-> v1-15 bottom 0 y)))
            (let ((v1-18 (-> this attack-event)))
              (case v1-18
                ((#f))
                (('heat) (send-event (handle->process (-> this target)) 'heat (* 10.0 (seconds-per-frame))))
                (('drown-death 'lava 'dark-eco-pool)
                 (if (send-event (handle->process (-> this target)) 'attack-invinc #f (static-attack-info ((mode v1-18))))
                   (send-event this 'notify 'attack)))
                (else
                 (if (send-event (handle->process (-> this target)) 'attack #f (static-attack-info ((mode v1-18))))
                   (send-event this 'notify 'attack))))))))))
    ((and *target*
          (and (not (handle->process (-> *target* water volume))) (point-in-vol? (-> this vol) (-> *target* control trans))))
     (let ((s5-0 (-> *target* water)))
       (process-entity-status! this (entity-perm-status bit-3) #t)
       (set! (-> s5-0 volume) (process->handle this))
       (set! (-> this target) (process->handle *target*))
       (logior! (-> s5-0 flags) (water-flags wt01))
       (set! (-> s5-0 base-height) (-> this water-height))
       (set! (-> s5-0 ocean-offset) 0.0)
       (logior! (-> s5-0 flags) (-> this flags))
       (if (< 0.0 (-> this wade-height)) (set! (-> s5-0 wade-height) (-> this wade-height)))
       (if (< 0.0 (-> this swim-height)) (set! (-> s5-0 swim-height) (-> this swim-height)))
       (if (< 0.0 (-> this bottom-height)) (set! (-> s5-0 bottom-height) (-> this bottom-height)))
       (set-zero! (-> s5-0 bob)))))
  0
  (none))

(defstate water-vol-startup (water-vol)
  :virtual #t
  :code
    (behavior ()
      (go-virtual water-vol-idle)))

(defstate water-vol-idle (water-vol)
  :virtual #t
  :event
    (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
      (case message
        (('update) (update! self))))
  :exit
    (behavior ()
      (on-exit-water self))
  :trans
    (behavior ()
      (update! self))
  :code anim-loop)

(defmethod set-stack-size! ((this water-vol))
  (stack-size-set! (-> this main-thread) 128)
  (none))

(defmethod reset-root! ((this water-vol))
  (set! (-> this root) (new 'process 'trsqv))
  (none))

(defmethod water-vol-method-25 ((this water-vol))
  0
  (none))

(defmethod init! ((this water-vol))
  (local-vars (sv-16 res-tag))
  (set! (-> this attack-event)
        (the-as symbol
                ((method-of-type res-lump get-property-struct)
                 (-> this entity)
                 'attack-event
                 'interp
                 -1000000000.0
                 'drown
                 (the-as (pointer res-tag) #f)
                 *res-static-buf*)))
  (process-drawable-from-entity! this (-> this entity))
  (logclear! (-> this mask) (process-mask actor-pause))
  (set! (-> this vol) (new 'process 'vol-control this))
  (logior! (-> this vol flags) 3)
  (set! (-> this bottom-height) 32768.0)
  (set! (-> this target) (the-as handle #f))
  (set! sv-16 (new 'static 'res-tag))
  (let ((v1-8 (the-as (pointer float)
                      ((method-of-type res-lump get-property-data)
                       (-> this entity)
                       'water-height
                       'exact
                       -1000000000.0
                       (the-as pointer #f)
                       (& sv-16)
                       *res-static-buf*))))
    (when v1-8
      (set! (-> this water-height) (-> v1-8 0))
      (set! (-> this wade-height) (-> v1-8 1))
      (set! (-> this swim-height) (-> v1-8 2))
      (if (>= (-> sv-16 elt-count) (the-as uint 4)) (set! (-> this flags) (the-as water-flags (the int (-> v1-8 3)))))
      (if (>= (-> sv-16 elt-count) (the-as uint 5)) (set! (-> this bottom-height) (-> v1-8 4)))))
  (logior! (-> this flags) (water-flags wt23))
  (cond
    ((zero? (-> this flags))
     (if (< 0.0 (-> this wade-height)) (logior! (-> this flags) (water-flags wt02)))
     (if (< 0.0 (-> this swim-height)) (logior! (-> this flags) (water-flags wt03))))
    (else))
  (none))

(defmethod water-vol-method-22 ((this water-vol))
  0
  (none))

(defbehavior water-vol-init-by-other water-vol ((arg0 entity-actor))
  (set! (-> self entity) arg0)
  (set-stack-size! self)
  (reset-root! self)
  (init! self)
  (water-vol-method-25 self)
  (water-vol-method-22 self)
  (go-virtual water-vol-startup)
  (none))

(defmethod init-from-entity! ((this water-vol) (arg0 entity-actor))
  (set-stack-size! this)
  (reset-root! this)
  (init! this)
  (water-vol-method-25 this)
  (water-vol-method-22 this)
  (go (method-of-object this water-vol-startup))
  (none))
