@adatechnology/game-vfx 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5164,9 +5164,17 @@ function createEffectPlayer(options) {
5164
5164
  });
5165
5165
  }
5166
5166
  function placementOf(entry) {
5167
+ const carrier = entry.carrier;
5168
+ if (carrier) return { origin: carrier.origin, anchor: entry.anchor, yaw: entry.yaw, carrier, ...carrier.orientation ? { orientation: carrier.orientation } : {} };
5167
5169
  const origin = entry.follow ? [entry.origin[0] + positionOf2(entry.follow)[0], entry.origin[1] + positionOf2(entry.follow)[1], entry.origin[2] + positionOf2(entry.follow)[2]] : entry.origin;
5168
5170
  return { origin, anchor: entry.anchor, yaw: entry.yaw, ...entry.orientation ? { orientation: entry.orientation } : {} };
5169
5171
  }
5172
+ function moveCarrier(entry) {
5173
+ const pose = entry.track?.();
5174
+ if (!pose || !entry.carrier) return;
5175
+ entry.carrier.origin = [pose.point[0], pose.point[1], pose.point[2]];
5176
+ if (pose.orientation) entry.carrier.orientation = pose.orientation;
5177
+ }
5170
5178
  function drawing(entry, action) {
5171
5179
  const context = engine.context;
5172
5180
  const shared = context.random;
@@ -5192,7 +5200,9 @@ function createEffectPlayer(options) {
5192
5200
  anchor: def.anchor ?? ORIGIN5,
5193
5201
  yaw: yawOf(heading, playOptions.direction),
5194
5202
  orientation: playOptions.orientation,
5195
- seconds: playOptions.seconds ?? (def.loop && def.loop > 0 ? def.loop : ENDLESS_SECONDS)
5203
+ seconds: playOptions.seconds ?? (def.loop && def.loop > 0 ? def.loop : ENDLESS_SECONDS),
5204
+ track: playOptions.track,
5205
+ carrier: playOptions.track ? { origin: point, orientation: playOptions.orientation } : void 0
5196
5206
  };
5197
5207
  playing.push(entry);
5198
5208
  drawing(
@@ -5214,11 +5224,21 @@ function createEffectPlayer(options) {
5214
5224
  for (let index = playing.length - 1; index >= 0; index--) {
5215
5225
  const entry = playing[index];
5216
5226
  const instance = entry.instance;
5227
+ moveCarrier(entry);
5217
5228
  instance.setup = { ...instance.setup, placement: placementOf(entry) };
5218
5229
  drawing(entry, () => instance.step(dt));
5219
5230
  if (instance.time >= entry.seconds) playing.splice(index, 1);
5220
5231
  }
5221
5232
  },
5233
+ retrack() {
5234
+ let tracked = false;
5235
+ for (const entry of playing) {
5236
+ if (!entry.carrier) continue;
5237
+ moveCarrier(entry);
5238
+ tracked = true;
5239
+ }
5240
+ return tracked;
5241
+ },
5222
5242
  clear() {
5223
5243
  playing.length = 0;
5224
5244
  },
@@ -6871,6 +6891,21 @@ var DecalPool = class {
6871
6891
  }
6872
6892
  };
6873
6893
 
6894
+ // src/workshop/carrier.ts
6895
+ function rotate(q, v) {
6896
+ const [qx, qy, qz, qw] = q;
6897
+ const ix = qw * v[0] + qy * v[2] - qz * v[1];
6898
+ const iy = qw * v[1] + qz * v[0] - qx * v[2];
6899
+ const iz = qw * v[2] + qx * v[1] - qy * v[0];
6900
+ const iw = -qx * v[0] - qy * v[1] - qz * v[2];
6901
+ return [ix * qw + iw * -qx + iy * -qz - iz * -qy, iy * qw + iw * -qy + iz * -qx - ix * -qz, iz * qw + iw * -qz + ix * -qy - iy * -qx];
6902
+ }
6903
+ function carriedPoint(carried) {
6904
+ const { carrier, local: local2 } = carried;
6905
+ const turned = carrier.orientation ? rotate(carrier.orientation, local2) : local2;
6906
+ return [carrier.origin[0] + turned[0], carrier.origin[1] + turned[1], carrier.origin[2] + turned[2]];
6907
+ }
6908
+
6874
6909
  // src/workshop/meshes.ts
6875
6910
  var CAPACITY3 = 400;
6876
6911
  var IDENTITY = [0, 0, 0, 1];
@@ -6889,7 +6924,7 @@ var MeshPool = class {
6889
6924
  get count() {
6890
6925
  return this.particles.length;
6891
6926
  }
6892
- spawn(options, frame = IDENTITY) {
6927
+ spawn(options, frame = IDENTITY, carried) {
6893
6928
  const velocity = options.v ?? [0, 0, 0];
6894
6929
  const world = options.wv ?? [0, 0, 0];
6895
6930
  const particle = {
@@ -6906,6 +6941,9 @@ var MeshPool = class {
6906
6941
  y: options.p[1],
6907
6942
  z: options.p[2],
6908
6943
  frame: options.roll ? multiply(frame, aboutX(options.roll)) : frame,
6944
+ roll: options.roll ? aboutX(options.roll) : void 0,
6945
+ carried,
6946
+ drift: [0, 0, 0],
6909
6947
  at: options.at ?? [0, 0, 0],
6910
6948
  rx: options.rot?.[0] ?? 0,
6911
6949
  ry: options.rot?.[1] ?? 0,
@@ -6946,9 +6984,12 @@ var MeshPool = class {
6946
6984
  particle.vy *= keep;
6947
6985
  particle.vz *= keep;
6948
6986
  }
6949
- particle.x += particle.vx * dt;
6950
- particle.y += particle.vy * dt;
6951
- particle.z += particle.vz * dt;
6987
+ if (particle.carried) this.ride(particle, dt);
6988
+ else {
6989
+ particle.x += particle.vx * dt;
6990
+ particle.y += particle.vy * dt;
6991
+ particle.z += particle.vz * dt;
6992
+ }
6952
6993
  particle.rx += particle.spin[0] * dt;
6953
6994
  particle.ry += particle.spin[1] * dt;
6954
6995
  particle.rz += particle.spin[2] * dt;
@@ -6959,6 +7000,30 @@ var MeshPool = class {
6959
7000
  clear() {
6960
7001
  this.particles.length = 0;
6961
7002
  }
7003
+ /** Puts every carried piece where its carrier is now (after the frame moved the thing it belongs to). */
7004
+ follow() {
7005
+ for (const particle of this.particles) if (particle.carried) this.place(particle);
7006
+ }
7007
+ /** A carried piece: how far its own velocity took it, then its place on the carrier. */
7008
+ ride(particle, dt) {
7009
+ const drift = particle.drift;
7010
+ drift[0] += particle.vx * dt;
7011
+ drift[1] += particle.vy * dt;
7012
+ drift[2] += particle.vz * dt;
7013
+ this.place(particle);
7014
+ }
7015
+ /** A carried piece's place on the carrier now plus its drift, turned with the carrier. */
7016
+ place(particle) {
7017
+ const carried = particle.carried;
7018
+ if (!carried) return;
7019
+ const drift = particle.drift;
7020
+ const [x, y, z] = carriedPoint(carried);
7021
+ particle.x = x + drift[0];
7022
+ particle.y = y + drift[1];
7023
+ particle.z = z + drift[2];
7024
+ const turn = carried.carrier.orientation;
7025
+ if (turn) particle.frame = particle.roll ? multiply(turn, particle.roll) : turn;
7026
+ }
6962
7027
  };
6963
7028
 
6964
7029
  // src/workshop/sprites.ts
@@ -7327,8 +7392,8 @@ var FlashLightPool = class {
7327
7392
  }
7328
7393
  flash(point, color, intensity, duration, distance, force, steady) {
7329
7394
  const { level } = this.context.quality;
7330
- if (level >= 1 && !force) return;
7331
- if (level >= 2 && force !== "boom") return;
7395
+ if (level >= 1 && !force) return void 0;
7396
+ if (level >= 2 && force !== "boom") return void 0;
7332
7397
  const light = this.lights[this.next++ % LIGHT_CAPACITY];
7333
7398
  light.x = point[0];
7334
7399
  light.y = point[1];
@@ -7340,17 +7405,24 @@ var FlashLightPool = class {
7340
7405
  light.t = 0;
7341
7406
  light.steady = steady === true;
7342
7407
  light.intensity = intensity;
7408
+ light.carried = void 0;
7409
+ return light;
7343
7410
  }
7344
7411
  clear() {
7345
7412
  for (const light of this.lights) light.intensity = 0;
7346
7413
  for (const light of this.fire) light.intensity = 0;
7347
7414
  }
7415
+ /** Puts every carried light that burns where its carrier is now. */
7416
+ follow() {
7417
+ for (const light of this.lights) if (light.intensity > 0 && light.carried) [light.x, light.y, light.z] = carriedPoint(light.carried);
7418
+ }
7348
7419
  update(dt) {
7349
7420
  for (const light of this.lights) {
7350
7421
  if (light.intensity <= 0) continue;
7351
7422
  light.t += dt;
7352
7423
  const age = light.t / light.duration;
7353
7424
  light.intensity = age >= 1 ? 0 : light.steady ? light.peak : light.peak * (1 - age) * (1 - age);
7425
+ if (light.carried) [light.x, light.y, light.z] = carriedPoint(light.carried);
7354
7426
  }
7355
7427
  }
7356
7428
  };
@@ -7360,7 +7432,7 @@ var QUALITY_MULTIPLIERS = [1, 0.5, 0.2];
7360
7432
  var FIRE_FLICKER_SWAY = 0.25;
7361
7433
  var FIRE_FLICKER_JITTER = 0.08;
7362
7434
  var LENS_FADE = 0.16;
7363
- function rotate(q, v) {
7435
+ function rotate2(q, v) {
7364
7436
  const [qx, qy, qz, qw] = q;
7365
7437
  const ix = qw * v[0] + qy * v[2] - qz * v[1];
7366
7438
  const iy = qw * v[1] + qz * v[0] - qx * v[2];
@@ -7418,7 +7490,7 @@ var WorkshopEngine = class {
7418
7490
  if (!placement) return point;
7419
7491
  const { anchor, origin, yaw, orientation } = placement;
7420
7492
  if (orientation) {
7421
- const turned = rotate(orientation, [point[0] - anchor[0], point[1] - anchor[1], point[2] - anchor[2]]);
7493
+ const turned = rotate2(orientation, [point[0] - anchor[0], point[1] - anchor[1], point[2] - anchor[2]]);
7422
7494
  return [origin[0] + turned[0], origin[1] + turned[1], origin[2] + turned[2]];
7423
7495
  }
7424
7496
  const x = point[0] - anchor[0];
@@ -7427,11 +7499,20 @@ var WorkshopEngine = class {
7427
7499
  const sin2 = Math.sin(yaw);
7428
7500
  return [origin[0] + cos2 * x + sin2 * z, origin[1] + point[1] - anchor[1], origin[2] - sin2 * x + cos2 * z];
7429
7501
  }
7502
+ /** A point of the recipe's space from the anchor, turned by the placement's yaw when it has no orientation (the carrier turns the rest). */
7503
+ local(point) {
7504
+ const placement = this.placement;
7505
+ if (!placement) return point;
7506
+ const offset = [point[0] - placement.anchor[0], point[1] - placement.anchor[1], point[2] - placement.anchor[2]];
7507
+ if (placement.carrier?.orientation) return offset;
7508
+ const turned = this.place(point);
7509
+ return [turned[0] - placement.origin[0], turned[1] - placement.origin[1], turned[2] - placement.origin[2]];
7510
+ }
7430
7511
  /** A direction or velocity of the recipe's space in the world. */
7431
7512
  turn(vector2) {
7432
7513
  const placement = this.placement;
7433
7514
  if (!placement) return vector2;
7434
- if (placement.orientation) return rotate(placement.orientation, vector2);
7515
+ if (placement.orientation) return rotate2(placement.orientation, vector2);
7435
7516
  const cos2 = Math.cos(placement.yaw);
7436
7517
  const sin2 = Math.sin(placement.yaw);
7437
7518
  return [cos2 * vector2[0] + sin2 * vector2[2], vector2[1], -sin2 * vector2[0] + cos2 * vector2[2]];
@@ -7466,7 +7547,8 @@ var WorkshopEngine = class {
7466
7547
  const options = placement ? { ...recipe, p: this.place(recipe.p), ...recipe.v ? { v: this.turn(recipe.v) } : {} } : recipe;
7467
7548
  this.context.trace?.("mesh", [options]);
7468
7549
  const grouped = recipe.at !== void 0 || recipe.roll !== void 0;
7469
- return this.meshes.spawn(options, placement && grouped ? placement.orientation ?? [0, Math.sin(placement.yaw / 2), 0, Math.cos(placement.yaw / 2)] : void 0);
7550
+ const carried = placement?.carrier && grouped ? { carrier: placement.carrier, local: this.local(recipe.p) } : void 0;
7551
+ return this.meshes.spawn(options, placement && grouped ? placement.orientation ?? [0, Math.sin(placement.yaw / 2), 0, Math.cos(placement.yaw / 2)] : void 0, carried);
7470
7552
  }
7471
7553
  debrisPiece(recipe) {
7472
7554
  const options = this.placed(recipe);
@@ -7490,9 +7572,11 @@ var WorkshopEngine = class {
7490
7572
  }
7491
7573
  /** `steady` (a seventh number): the light holds its intensity for its duration and goes out, where the Workshop's fades with the square of its age. */
7492
7574
  flash(recipe) {
7493
- const args = this.placement ? [this.place(recipe[0]), recipe[1], recipe[2], recipe[3], recipe[4], recipe[5], recipe[6]] : recipe;
7575
+ const placement = this.placement;
7576
+ const args = placement ? [this.place(recipe[0]), recipe[1], recipe[2], recipe[3], recipe[4], recipe[5], recipe[6]] : recipe;
7494
7577
  this.context.trace?.("flash", args.slice(0, 6));
7495
- this.lights.flash(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
7578
+ const light = this.lights.flash(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
7579
+ if (light && placement?.carrier) light.carried = { carrier: placement.carrier, local: this.local(recipe[0]) };
7496
7580
  }
7497
7581
  /** `fireLight` (W400): sways with the clock and flickers with one draw. */
7498
7582
  fireLight(slot, recipe, intensity, time) {
@@ -7655,6 +7739,12 @@ function createVfx(options = {}) {
7655
7739
  const seed = playOptions.seed ?? (randomMode === "shared" ? void 0 : Math.imul(++handles.events, AUTO_SEED) + (options.seed ?? 0));
7656
7740
  return effectPlayer().play(id, [point[0], point[1], point[2]], { ...playOptions, ...seed !== void 0 ? { seed } : {} });
7657
7741
  },
7742
+ follow() {
7743
+ if (!engine || !player?.retrack()) return false;
7744
+ engine.meshes.follow();
7745
+ engine.lights.follow();
7746
+ return true;
7747
+ },
7658
7748
  burst: (kind, point, normal, count, speed, spriteOptions) => spriteSystem.burst(kind, point, normal, count, speed, spriteOptions),
7659
7749
  spawn: (kind, point, velocity, spriteOptions) => spriteSystem.spawn(kind, point, velocity, spriteOptions),
7660
7750
  onLand: (owner, listener) => spriteSystem.onLand(owner, listener),
@@ -8661,7 +8751,7 @@ function ease3(value) {
8661
8751
  function mix(from, to, amount) {
8662
8752
  return [from[0] + (to[0] - from[0]) * amount, from[1] + (to[1] - from[1]) * amount, from[2] + (to[2] - from[2]) * amount];
8663
8753
  }
8664
- function rotate2(local2, x, y, z, w) {
8754
+ function rotate3(local2, x, y, z, w) {
8665
8755
  const [vx2, vy2, vz2] = local2;
8666
8756
  const ix = w * vx2 + y * vz2 - z * vy2;
8667
8757
  const iy = w * vy2 + z * vx2 - x * vz2;
@@ -8719,7 +8809,7 @@ var EffectCamera = class {
8719
8809
  /** A direction given in the camera's own axes, in world axes. */
8720
8810
  forward(local2) {
8721
8811
  const [x, y, z, w] = lookAtQuaternion(this.position, this.target);
8722
- return rotate2(local2, x, y, z, w);
8812
+ return rotate3(local2, x, y, z, w);
8723
8813
  }
8724
8814
  };
8725
8815
 
@@ -8868,6 +8958,674 @@ function createGroundField(options = {}) {
8868
8958
  reset
8869
8959
  };
8870
8960
  }
8961
+
8962
+ // src/water/motion.ts
8963
+ var WATER_GRAVITY = 9.81;
8964
+ var DROP_DRAG = 0.25;
8965
+ var MIST_DRAG = 1.2;
8966
+ function moveDrop(drop, context) {
8967
+ const { dt } = context;
8968
+ drop.age += dt;
8969
+ const keep = Math.exp(-DROP_DRAG * dt);
8970
+ drop.vx *= keep;
8971
+ drop.vz *= keep;
8972
+ drop.vy = drop.vy * keep - WATER_GRAVITY * dt;
8973
+ drop.x += drop.vx * dt;
8974
+ drop.y += drop.vy * dt;
8975
+ drop.z += drop.vz * dt;
8976
+ if (drop.vy < 0 && drop.y <= drop.level) {
8977
+ context.landed(drop);
8978
+ return false;
8979
+ }
8980
+ return drop.age < drop.life;
8981
+ }
8982
+ function ageRing(ring2, dt) {
8983
+ if (ring2.delay > 0) {
8984
+ ring2.delay -= dt;
8985
+ ring2.alpha = 0;
8986
+ return true;
8987
+ }
8988
+ ring2.age += dt;
8989
+ const t = Math.min(1, ring2.age / ring2.life);
8990
+ const spread = ring2.kind === 2 ? t : ring2.kind === 1 ? 1 - (1 - t) ** 4 : 1 - (1 - t) ** 2;
8991
+ ring2.radius = ring2.startRadius + (ring2.maxRadius - ring2.startRadius) * spread;
8992
+ ring2.alpha = ring2.strength * (1 - t) * (ring2.kind === 1 ? 1 - t : 1);
8993
+ return ring2.age < ring2.life;
8994
+ }
8995
+ function ageFoam(foam, dt) {
8996
+ foam.age += dt;
8997
+ const t = Math.min(1, foam.age / foam.life);
8998
+ foam.radius = foam.startRadius + (foam.maxRadius - foam.startRadius) * (1 - (1 - t) ** 3);
8999
+ foam.alpha = t < 0.5 ? 0.85 : 0.85 * (1 - (t - 0.5) / 0.5);
9000
+ return foam.age < foam.life;
9001
+ }
9002
+ function ageColumn(column, dt) {
9003
+ if (column.delay > 0) {
9004
+ column.delay -= dt;
9005
+ column.height = 0;
9006
+ column.alpha = 0;
9007
+ return true;
9008
+ }
9009
+ column.age += dt;
9010
+ const t = column.age;
9011
+ const fall = Math.max(1e-3, column.life - column.rise);
9012
+ column.height = t < column.rise ? column.peak * (1 - (1 - t / column.rise) ** 2) : column.peak * Math.max(0, 1 - ((t - column.rise) / fall) ** 1.6);
9013
+ column.radius = column.baseRadius * (1 + (column.dome ? 0.4 : 1.2) * Math.min(1, t / column.life));
9014
+ const share = t / column.life;
9015
+ column.alpha = share < 0.6 ? 0.9 : 0.9 * Math.max(0, 1 - (share - 0.6) / 0.4);
9016
+ return t < column.life;
9017
+ }
9018
+ function ageBubble(bubble, dt) {
9019
+ if (bubble.delay > 0) {
9020
+ bubble.delay -= dt;
9021
+ bubble.alpha = 0;
9022
+ return true;
9023
+ }
9024
+ bubble.age += dt;
9025
+ bubble.y += bubble.rise * dt;
9026
+ bubble.size *= 1 + 0.15 * dt;
9027
+ bubble.alpha = 0.7 * (1 - bubble.age / bubble.life);
9028
+ return bubble.age < bubble.life && bubble.y < bubble.level - bubble.size;
9029
+ }
9030
+ function ageMist(mist, dt) {
9031
+ mist.age += dt;
9032
+ const keep = Math.exp(-MIST_DRAG * dt);
9033
+ mist.vx *= keep;
9034
+ mist.vy = mist.vy * keep - 0.15 * dt;
9035
+ mist.vz *= keep;
9036
+ mist.x += mist.vx * dt;
9037
+ mist.y += mist.vy * dt;
9038
+ mist.z += mist.vz * dt;
9039
+ mist.size *= 1 + 0.35 * dt;
9040
+ const t = mist.age / mist.life;
9041
+ mist.alpha = t < 0.15 ? t / 0.15 * 0.45 : 0.45 * (1 - (t - 0.15) / 0.85);
9042
+ return mist.age < mist.life;
9043
+ }
9044
+ function ageWave(wave, dt) {
9045
+ if (wave.delay > 0) {
9046
+ wave.delay -= dt;
9047
+ return true;
9048
+ }
9049
+ wave.age += dt;
9050
+ return wave.age < wave.life && wave.speed * wave.age < wave.reach + wave.width;
9051
+ }
9052
+ function stepWaterPools(pools, context) {
9053
+ const { dt } = context;
9054
+ pools.drops.compact(moveDrop, context);
9055
+ pools.rings.compact(ageRing, dt);
9056
+ pools.foam.compact(ageFoam, dt);
9057
+ pools.columns.compact(ageColumn, dt);
9058
+ pools.bubbles.compact(ageBubble, dt);
9059
+ pools.mist.compact(ageMist, dt);
9060
+ pools.waves.compact(ageWave, dt);
9061
+ }
9062
+
9063
+ // src/water/profiles.ts
9064
+ var WATER_SHOT_PROFILES = {
9065
+ rimfire: { speed: 350, columnHeight: 0.25, columnRadius: 0.02, drops: 8, dropSpeed: [0.9, 1.8], dropSize: 9e-3, ringRadius: 0.32, rings: 1, ringLife: 1.2, foamRadius: 0.06, foamLife: 0.7, slowing: 0.35, bubblesPerMetre: 20, ricochetBelowDeg: 9 },
9066
+ pistol: { speed: 360, columnHeight: 0.45, columnRadius: 0.035, drops: 14, dropSpeed: [1.2, 2.6], dropSize: 0.012, ringRadius: 0.45, rings: 2, ringLife: 1.4, foamRadius: 0.09, foamLife: 0.9, slowing: 0.55, bubblesPerMetre: 30, ricochetBelowDeg: 8 },
9067
+ magnum: { speed: 450, columnHeight: 0.7, columnRadius: 0.045, drops: 20, dropSpeed: [1.5, 3.2], dropSize: 0.014, ringRadius: 0.6, rings: 2, ringLife: 1.6, foamRadius: 0.12, foamLife: 1.1, slowing: 0.7, bubblesPerMetre: 30, ricochetBelowDeg: 7 },
9068
+ rifle: { speed: 800, columnHeight: 1.1, columnRadius: 0.03, drops: 26, dropSpeed: [2.5, 4.5], dropSize: 0.011, ringRadius: 0.7, rings: 3, ringLife: 1.6, foamRadius: 0.11, foamLife: 1, slowing: 0.35, bubblesPerMetre: 45, ricochetBelowDeg: 6 },
9069
+ battle_rifle: { speed: 850, columnHeight: 1.4, columnRadius: 0.035, drops: 30, dropSpeed: [2.8, 5], dropSize: 0.012, ringRadius: 0.85, rings: 3, ringLife: 1.8, foamRadius: 0.13, foamLife: 1.1, slowing: 0.45, bubblesPerMetre: 45, ricochetBelowDeg: 6 },
9070
+ sniper: { speed: 900, columnHeight: 2.2, columnRadius: 0.06, drops: 48, dropSpeed: [3.5, 6.5], dropSize: 0.016, ringRadius: 1.4, rings: 4, ringLife: 2.2, foamRadius: 0.22, foamLife: 1.6, slowing: 0.9, bubblesPerMetre: 50, ricochetBelowDeg: 5 },
9071
+ buckshot: { speed: 400, columnHeight: 0.28, columnRadius: 0.025, drops: 7, dropSpeed: [1, 2], dropSize: 0.01, ringRadius: 0.3, rings: 1, ringLife: 1.1, foamRadius: 0.13, foamLife: 1.3, slowing: 0.3, bubblesPerMetre: 25, ricochetBelowDeg: 9 },
9072
+ birdshot: { speed: 400, columnHeight: 0.1, columnRadius: 0.012, drops: 2, dropSpeed: [0.6, 1.2], dropSize: 6e-3, ringRadius: 0.14, rings: 1, ringLife: 0.8, foamRadius: 0.06, foamLife: 0.9, slowing: 0.08, bubblesPerMetre: 10, ricochetBelowDeg: 10 },
9073
+ slug: { speed: 460, columnHeight: 0.8, columnRadius: 0.07, drops: 24, dropSpeed: [1.6, 3], dropSize: 0.016, ringRadius: 0.75, rings: 2, ringLife: 1.7, foamRadius: 0.18, foamLife: 1.3, slowing: 0.8, bubblesPerMetre: 35, ricochetBelowDeg: 8 },
9074
+ arrow: { speed: 100, columnHeight: 0.18, columnRadius: 0.02, drops: 5, dropSpeed: [0.6, 1.2], dropSize: 0.01, ringRadius: 0.3, rings: 1, ringLife: 1.2, foamRadius: 0.05, foamLife: 0.6, slowing: 2.5, bubblesPerMetre: 6, ricochetBelowDeg: 4 },
9075
+ // a thrown thing the size of a grenade or a can falling in: a plop, a crown and wide rings, and it sinks
9076
+ object: { speed: 12, columnHeight: 0.5, columnRadius: 0.07, drops: 18, dropSpeed: [1, 2.4], dropSize: 0.015, ringRadius: 0.9, rings: 3, ringLife: 2, foamRadius: 0.14, foamLife: 1.2, slowing: 0.5, bubblesPerMetre: 25, ricochetBelowDeg: 3 },
9077
+ fragment: { speed: 600, columnHeight: 0.35, columnRadius: 0.02, drops: 6, dropSpeed: [1, 2.4], dropSize: 0.01, ringRadius: 0.3, rings: 1, ringLife: 1, foamRadius: 0.05, foamLife: 0.6, slowing: 0.15, bubblesPerMetre: 15, ricochetBelowDeg: 7 }
9078
+ };
9079
+ var WATER_SHOT_BY_CALIBER = {
9080
+ "22lr": "rimfire",
9081
+ "380acp": "pistol",
9082
+ "9x18": "pistol",
9083
+ "9x19": "pistol",
9084
+ "40sw": "pistol",
9085
+ "45acp": "pistol",
9086
+ "5_7x28": "pistol",
9087
+ "38spl": "pistol",
9088
+ "32acp": "pistol",
9089
+ "7_62x25": "pistol",
9090
+ "4_6x30": "pistol",
9091
+ "357mag": "magnum",
9092
+ "44mag": "magnum",
9093
+ "50ae": "magnum",
9094
+ "45_70_bp": "magnum",
9095
+ "12ga_00buck": "buckshot",
9096
+ "20ga_buck": "buckshot",
9097
+ "12ga_birdshot": "birdshot",
9098
+ "12ga_slug": "slug",
9099
+ "5_56x45": "rifle",
9100
+ "5_45x39": "rifle",
9101
+ "7_62x39": "rifle",
9102
+ "30_30": "rifle",
9103
+ "9x39": "rifle",
9104
+ "7_62x51": "battle_rifle",
9105
+ "7_62x54r": "battle_rifle",
9106
+ "30_06": "battle_rifle",
9107
+ "7_92x57": "battle_rifle",
9108
+ "300wm": "battle_rifle",
9109
+ "338lapua": "sniper",
9110
+ "408cheytac": "sniper",
9111
+ "50bmg": "sniper",
9112
+ arrow: "arrow",
9113
+ crossbow_bolt: "arrow"
9114
+ };
9115
+ function waterShotClassOf(round2) {
9116
+ const joules = 0.5 * (round2.grams / 1e3) * round2.speed * round2.speed;
9117
+ if (round2.speed < 150) return "arrow";
9118
+ if (round2.pellet) return round2.grams < 0.5 ? "birdshot" : "buckshot";
9119
+ if ((round2.diameter ?? 0) >= 15) return "slug";
9120
+ if (joules >= 6e3) return "sniper";
9121
+ if (joules >= 2800) return "battle_rifle";
9122
+ if (joules >= 1200) return "rifle";
9123
+ if (joules >= 900) return "magnum";
9124
+ return joules < 200 ? "rimfire" : "pistol";
9125
+ }
9126
+ var WATER_BLAST_KINDS = {
9127
+ blast: { brisance: 1, columnWidth: 1, fragments: 0, mist: 1, fireballUnderwater: false },
9128
+ fragmentation: { brisance: 0.9, columnWidth: 1, fragments: 16, mist: 1, fireballUnderwater: false },
9129
+ shaped_charge: { brisance: 0.8, columnWidth: 0.6, fragments: 6, mist: 0.8, fireballUnderwater: false },
9130
+ directional: { brisance: 0.7, columnWidth: 0.9, fragments: 24, mist: 0.8, fireballUnderwater: false },
9131
+ fuel: { brisance: 0.25, columnWidth: 1.4, fragments: 4, mist: 2.2, fireballUnderwater: false },
9132
+ incendiary: { brisance: 0.05, columnWidth: 1.2, fragments: 0, mist: 1.5, fireballUnderwater: false },
9133
+ flash: { brisance: 0.1, columnWidth: 1, fragments: 0, mist: 0.6, fireballUnderwater: false }
9134
+ };
9135
+ var WATER_BLASTS = {
9136
+ m67: { tnt: 0.24, kind: "fragmentation" },
9137
+ pipe_bomb: { tnt: 0.15, kind: "fragmentation" },
9138
+ m79_40mm: { tnt: 0.045, kind: "fragmentation" },
9139
+ vog_25: { tnt: 0.045, kind: "fragmentation" },
9140
+ dynamite: { tnt: 0.25, kind: "blast" },
9141
+ c4: { tnt: 0.76, kind: "blast" },
9142
+ semtex: { tnt: 0.83, kind: "blast" },
9143
+ claymore: { tnt: 0.9, kind: "directional" },
9144
+ m72_66mm: { tnt: 0.45, kind: "shaped_charge" },
9145
+ at4_84mm: { tnt: 0.7, kind: "shaped_charge" },
9146
+ pg7v: { tnt: 0.45, kind: "shaped_charge" },
9147
+ carl_gustaf_84mm: { tnt: 0.7, kind: "shaped_charge" },
9148
+ propane_p13: { tnt: 1.5, kind: "fuel" },
9149
+ fuel_barrel: { tnt: 1, kind: "fuel" },
9150
+ car_fuel_tank: { tnt: 0.5, kind: "fuel" },
9151
+ fuel_pump: { tnt: 0.5, kind: "fuel" },
9152
+ fuel_station_tank: { tnt: 20, kind: "fuel" },
9153
+ molotov: { tnt: 0.02, kind: "incendiary" },
9154
+ flashbang: { tnt: 0.01, kind: "flash" }
9155
+ };
9156
+ function resolveWaterShotProfile(profile, table = WATER_SHOT_PROFILES) {
9157
+ if (typeof profile !== "string") return profile;
9158
+ return table[profile] ?? WATER_SHOT_PROFILES.pistol;
9159
+ }
9160
+ function patchWaterShotProfiles(base, changes) {
9161
+ const out = { ...base };
9162
+ for (const [id, change] of Object.entries(changes)) {
9163
+ if (change === null) delete out[id];
9164
+ else out[id] = { ...base[id] ?? WATER_SHOT_PROFILES.pistol, ...change };
9165
+ }
9166
+ return out;
9167
+ }
9168
+
9169
+ // src/water/plan.ts
9170
+ var DEGREES = 180 / Math.PI;
9171
+ var SPENT_SPEED = 15;
9172
+ var DEFAULT_DEPTH = 2;
9173
+ var RICOCHET_SPEED_SHARE = 0.6;
9174
+ var RICOCHET_YAW_DEG = 6;
9175
+ var BLAST_COLUMN_PER_QUARTIC_KG = 10;
9176
+ var AIRBURST_SCALED_HEIGHT = 2.5;
9177
+ var BEST_SCALED_DEPTH = 0.6;
9178
+ var DEEP_FALL = 1.6;
9179
+ var UNDERWATER_SCALED_DEPTH = 0.15;
9180
+ var clamp5 = (value, low, high) => Math.min(high, Math.max(low, value));
9181
+ function planWaterShot(params, random, table) {
9182
+ const profile = resolveWaterShotProfile(params.profile, table);
9183
+ const [dx, dy, dz] = params.direction;
9184
+ const sine = clamp5(-dy, 0, 1);
9185
+ const angleDeg = Math.asin(sine) * DEGREES;
9186
+ const speed = params.speed ?? profile.speed;
9187
+ const strength = clamp5(speed / profile.speed, 0.3, 1.25);
9188
+ const flat = Math.hypot(dx, dz) || 1;
9189
+ const forward = [dx / flat, dz / flat];
9190
+ const ricochet = angleDeg < profile.ricochetBelowDeg ? skipOff(params.direction, angleDeg, random) : null;
9191
+ const lean = (1 - sine) * (ricochet ? 1.2 : 0.6);
9192
+ const columnHeight = profile.columnHeight * strength * (ricochet ? 0.35 : 0.35 + 0.65 * sine);
9193
+ const depth = params.depth ?? DEFAULT_DEPTH;
9194
+ const trail = ricochet ? null : trailUnder(params, profile, speed, depth, sine);
9195
+ return {
9196
+ profile,
9197
+ angleDeg,
9198
+ ricochet,
9199
+ columnHeight,
9200
+ columnRadius: profile.columnRadius * Math.sqrt(strength),
9201
+ tilt: [forward[0] * lean, forward[1] * lean],
9202
+ drops: Math.round(profile.drops * strength),
9203
+ ringRadius: profile.ringRadius * Math.sqrt(strength),
9204
+ rings: profile.rings,
9205
+ foamRadius: profile.foamRadius * (ricochet ? 1.4 : 1),
9206
+ trailEnd: trail?.end ?? params.point,
9207
+ trailLength: trail?.length ?? 0,
9208
+ bedSpeed: trail?.bedSpeed ?? 0
9209
+ };
9210
+ }
9211
+ function skipOff(direction, angleDeg, random) {
9212
+ const yaw = random.between(-RICOCHET_YAW_DEG, RICOCHET_YAW_DEG) / DEGREES;
9213
+ const cos2 = Math.cos(yaw);
9214
+ const sin2 = Math.sin(yaw);
9215
+ const [dx, dy, dz] = direction;
9216
+ const up = Math.abs(dy) * (0.5 + 0.3 * random.next());
9217
+ const x = dx * cos2 - dz * sin2;
9218
+ const z = dx * sin2 + dz * cos2;
9219
+ const length = Math.hypot(x, up, z) || 1;
9220
+ return { direction: [x / length, up / length, z / length], speedShare: RICOCHET_SPEED_SHARE * (1 - angleDeg / 30) };
9221
+ }
9222
+ function trailUnder(params, profile, speed, depth, sine) {
9223
+ const spentAfter = profile.slowing * Math.log(Math.max(1, speed / SPENT_SPEED));
9224
+ const toBed = sine > 1e-3 ? depth / sine : Infinity;
9225
+ const length = Math.min(spentAfter, toBed);
9226
+ const [px, py, pz] = params.point;
9227
+ const [dx, dy, dz] = params.direction;
9228
+ const bedSpeed = toBed <= spentAfter ? speed * Math.exp(-toBed / profile.slowing) : 0;
9229
+ return { end: [px + dx * length, py + dy * length, pz + dz * length], length, bedSpeed };
9230
+ }
9231
+ function resolveWaterBlast(params) {
9232
+ const known = params.explosive ? WATER_BLASTS[params.explosive] : void 0;
9233
+ const tnt = Math.max(1e-3, params.tnt ?? known?.tnt ?? 0.25);
9234
+ const kindId = params.kind ?? known?.kind ?? "blast";
9235
+ const kind = WATER_BLAST_KINDS[kindId] ?? WATER_BLAST_KINDS.blast;
9236
+ return { tnt, kind };
9237
+ }
9238
+ function planWaterBlast(params) {
9239
+ const { tnt, kind } = resolveWaterBlast(params);
9240
+ const scale = Math.cbrt(tnt);
9241
+ const quartic = Math.sqrt(Math.sqrt(tnt));
9242
+ const burstDepth = params.level - params.point[1];
9243
+ const scaledDepth = burstDepth / scale;
9244
+ const airburst = -scaledDepth > AIRBURST_SCALED_HEIGHT;
9245
+ const underwater = scaledDepth > UNDERWATER_SCALED_DEPTH && !kind.fireballUnderwater;
9246
+ const surface = scaledDepth <= 0 ? Math.max(0, 1 + scaledDepth / AIRBURST_SCALED_HEIGHT) : 1;
9247
+ const depthShape = scaledDepth <= 0 ? 0.6 * surface : scaledDepth <= BEST_SCALED_DEPTH ? 0.6 + 0.4 * (scaledDepth / BEST_SCALED_DEPTH) : Math.exp(-(scaledDepth - BEST_SCALED_DEPTH) / DEEP_FALL);
9248
+ const shallow = clamp5(0.35 + params.depth / (1.2 * scale), 0.35, 1);
9249
+ const power = kind.brisance;
9250
+ const columnHeight = airburst ? 0 : BLAST_COLUMN_PER_QUARTIC_KG * quartic * power * depthShape * shallow;
9251
+ const domed = scaledDepth > 0 && !airburst;
9252
+ const domeRadius = domed ? 1.6 * scale * Math.cbrt(power) : 0;
9253
+ const fragments = scaledDepth < UNDERWATER_SCALED_DEPTH ? kind.fragments : 0;
9254
+ return {
9255
+ tnt,
9256
+ kind,
9257
+ burstDepth,
9258
+ underwater,
9259
+ airburst,
9260
+ columnHeight,
9261
+ columnRadius: 0.35 * scale * kind.columnWidth * (1 + 0.5 * clamp5(scaledDepth, 0, 1)),
9262
+ domeRadius,
9263
+ domeHeight: domed ? domeRadius * 0.6 * (scaledDepth < 1 ? 1 : Math.exp(1 - scaledDepth)) : 0,
9264
+ shockRadius: (scaledDepth >= 0 ? 5 : 4 * surface) * scale,
9265
+ waveAmplitude: 0.12 * scale * power * (scaledDepth >= 0 ? 1 : surface) * shallow,
9266
+ waveSpeed: 2.5 + 1.5 * scale,
9267
+ drops: airburst ? Math.round(20 * scale) : Math.round((60 + 140 * scale) * Math.max(0.3, depthShape) * Math.max(0.3, power)),
9268
+ mist: Math.round((6 + 10 * scale) * kind.mist * (airburst ? 0.4 : 1)),
9269
+ fragments,
9270
+ foamRadius: 2.5 * scale * Math.max(0.4, Math.cbrt(power)) * (airburst ? 0.3 : 1),
9271
+ bubbles: scaledDepth > 0 ? Math.round(30 + 50 * scale) : 0
9272
+ };
9273
+ }
9274
+
9275
+ // src/water/records.ts
9276
+ var WATER_LIMITS = { drops: 700, rings: 220, foam: 60, columns: 32, bubbles: 500, mist: 90, waves: 16 };
9277
+ function createWaterPools(limits) {
9278
+ return {
9279
+ drops: new OrderedPool(limits.drops, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, size: 0, age: 0, life: 0, level: 0 })),
9280
+ rings: new OrderedPool(limits.rings, () => ({ x: 0, y: 0, z: 0, kind: 0, radius: 0, startRadius: 0, maxRadius: 0, delay: 0, age: 0, life: 0, strength: 0, alpha: 0 })),
9281
+ foam: new OrderedPool(limits.foam, () => ({ x: 0, y: 0, z: 0, radius: 0, startRadius: 0, maxRadius: 0, age: 0, life: 0, alpha: 0 })),
9282
+ columns: new OrderedPool(limits.columns, () => ({ x: 0, y: 0, z: 0, dome: false, peak: 0, baseRadius: 0, tiltX: 0, tiltZ: 0, rise: 0, delay: 0, age: 0, life: 0, height: 0, radius: 0, alpha: 0 })),
9283
+ bubbles: new OrderedPool(limits.bubbles, () => ({ x: 0, y: 0, z: 0, size: 0, rise: 0, delay: 0, age: 0, life: 0, level: 0, alpha: 0 })),
9284
+ mist: new OrderedPool(limits.mist, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, size: 0, age: 0, life: 0, alpha: 0 })),
9285
+ waves: new OrderedPool(limits.waves, () => ({ x: 0, z: 0, speed: 0, amplitude: 0, width: 0, reach: 0, delay: 0, age: 0, life: 0 }))
9286
+ };
9287
+ }
9288
+
9289
+ // src/water/spawn.ts
9290
+ var TRAIL_BUBBLES_MAX = 40;
9291
+ var BLAST_FOAM_LIFE = 8;
9292
+ var BLAST_WAVE_CRESTS = 3;
9293
+ var BLAST_WAVE_GAP = 0.35;
9294
+ var BLAST_WAVE_LIFE = 6;
9295
+ var BLAST_SIDE_JETS = 4;
9296
+ function addRing(context, spec) {
9297
+ const ring2 = context.pools.rings.acquire();
9298
+ ring2.x = spec.x;
9299
+ ring2.y = spec.y;
9300
+ ring2.z = spec.z;
9301
+ ring2.kind = spec.kind;
9302
+ ring2.startRadius = spec.start;
9303
+ ring2.radius = spec.start;
9304
+ ring2.maxRadius = Math.max(spec.start, Math.min(spec.max, context.reach(spec.x, spec.z, spec.max)));
9305
+ ring2.delay = spec.delay;
9306
+ ring2.age = 0;
9307
+ ring2.life = spec.life;
9308
+ ring2.strength = spec.strength;
9309
+ ring2.alpha = 0;
9310
+ }
9311
+ function addFoam(context, at3, radius, life) {
9312
+ const foam = context.pools.foam.acquire();
9313
+ foam.x = at3[0];
9314
+ foam.y = at3[1];
9315
+ foam.z = at3[2];
9316
+ foam.maxRadius = Math.min(radius, Math.max(0.05, context.reach(at3[0], at3[2], radius)));
9317
+ foam.startRadius = foam.maxRadius * 0.35;
9318
+ foam.radius = foam.startRadius;
9319
+ foam.age = 0;
9320
+ foam.life = life;
9321
+ foam.alpha = 0.85;
9322
+ }
9323
+ function addColumn(context, spec) {
9324
+ if (spec.peak < 0.02) return;
9325
+ const column = context.pools.columns.acquire();
9326
+ column.x = spec.at[0];
9327
+ column.y = spec.at[1];
9328
+ column.z = spec.at[2];
9329
+ column.dome = spec.dome;
9330
+ column.peak = spec.peak;
9331
+ column.baseRadius = spec.radius;
9332
+ column.tiltX = spec.tilt[0];
9333
+ column.tiltZ = spec.tilt[1];
9334
+ const flight = Math.sqrt(2 * spec.peak / WATER_GRAVITY);
9335
+ column.rise = spec.rise ?? Math.max(0.06, flight * 0.6);
9336
+ column.life = column.rise + Math.max(0.2, flight * 1.3) + 0.15;
9337
+ column.delay = spec.delay;
9338
+ column.age = 0;
9339
+ column.height = 0;
9340
+ column.radius = spec.radius;
9341
+ column.alpha = 0;
9342
+ }
9343
+ function addDrop(context, spec) {
9344
+ const drop = context.pools.drops.acquire();
9345
+ drop.x = spec.at[0];
9346
+ drop.y = spec.at[1];
9347
+ drop.z = spec.at[2];
9348
+ drop.vx = spec.velocity[0];
9349
+ drop.vy = spec.velocity[1];
9350
+ drop.vz = spec.velocity[2];
9351
+ drop.size = spec.size;
9352
+ drop.level = spec.level;
9353
+ drop.age = 0;
9354
+ drop.life = 6;
9355
+ }
9356
+ function addBubble(context, at3, level, delay, size) {
9357
+ const { random } = context;
9358
+ const bubble = context.pools.bubbles.acquire();
9359
+ bubble.x = at3[0];
9360
+ bubble.y = at3[1];
9361
+ bubble.z = at3[2];
9362
+ bubble.size = size;
9363
+ bubble.rise = random.between(0.2, 0.45);
9364
+ bubble.delay = delay;
9365
+ bubble.age = 0;
9366
+ bubble.life = random.between(0.8, 2.2);
9367
+ bubble.level = level;
9368
+ bubble.alpha = 0;
9369
+ }
9370
+ function spawnShot(context, point, plan) {
9371
+ const { random, detail } = context;
9372
+ const [x, y, z] = point;
9373
+ const profile = plan.profile;
9374
+ addColumn(context, { at: point, peak: plan.columnHeight, radius: plan.columnRadius, tilt: plan.tilt, dome: false, delay: 0 });
9375
+ const drops = Math.round(plan.drops * detail);
9376
+ const steep = plan.ricochet ? 0.3 : 0.4 + 0.6 * Math.sin(plan.angleDeg * Math.PI / 180);
9377
+ for (let index = 0; index < drops; index++) {
9378
+ const angle = random.next() * Math.PI * 2;
9379
+ const speed = random.between(profile.dropSpeed[0], profile.dropSpeed[1]);
9380
+ const out = speed * random.between(0.2, 0.55);
9381
+ const lean = speed * random.between(0.3, 0.9);
9382
+ addDrop(context, {
9383
+ at: [x + Math.cos(angle) * plan.columnRadius, y, z + Math.sin(angle) * plan.columnRadius],
9384
+ velocity: [Math.cos(angle) * out + plan.tilt[0] * lean, speed * steep * random.between(0.7, 1), Math.sin(angle) * out + plan.tilt[1] * lean],
9385
+ size: profile.dropSize * random.between(0.6, 1.4),
9386
+ level: y
9387
+ });
9388
+ }
9389
+ for (let index = 0; index < plan.rings; index++) {
9390
+ addRing(context, { x, y, z, kind: 0, start: plan.columnRadius, max: plan.ringRadius * (1 - index * 0.22), life: profile.ringLife * (1 - index * 0.15), delay: index * 0.12, strength: 0.6 });
9391
+ }
9392
+ if (plan.ricochet) {
9393
+ for (let step = 1; step <= 2; step++) {
9394
+ const sx = x + plan.tilt[0] * 0.3 * step;
9395
+ const sz = z + plan.tilt[1] * 0.3 * step;
9396
+ addRing(context, { x: sx, y, z: sz, kind: 0, start: plan.columnRadius, max: plan.ringRadius * 0.6, life: profile.ringLife * 0.8, delay: 0.02 * step, strength: 0.45 });
9397
+ }
9398
+ }
9399
+ addFoam(context, point, plan.foamRadius, profile.foamLife);
9400
+ spawnTrail(context, point, plan);
9401
+ }
9402
+ function spawnTrail(context, point, plan) {
9403
+ if (plan.trailLength <= 0) return;
9404
+ const { random } = context;
9405
+ const count = Math.min(TRAIL_BUBBLES_MAX, Math.round(plan.profile.bubblesPerMetre * plan.trailLength * context.detail));
9406
+ const [ex, ey, ez] = plan.trailEnd;
9407
+ for (let index = 0; index < count; index++) {
9408
+ const along = random.next() ** 1.6;
9409
+ const jitter = 0.01 + 0.02 * along;
9410
+ const at3 = [point[0] + (ex - point[0]) * along + random.between(-jitter, jitter), point[1] + (ey - point[1]) * along, point[2] + (ez - point[2]) * along + random.between(-jitter, jitter)];
9411
+ addBubble(context, at3, point[1], along * 0.05, random.between(3e-3, 0.01));
9412
+ }
9413
+ }
9414
+ function spawnBlast(context, point, level, plan) {
9415
+ const { random, detail } = context;
9416
+ const surface = [point[0], level, point[2]];
9417
+ const scale = Math.cbrt(plan.tnt);
9418
+ addColumn(context, { at: surface, peak: plan.columnHeight, radius: plan.columnRadius, tilt: [0, 0], dome: false, delay: plan.domeRadius > 0 ? 0.08 : 0 });
9419
+ for (let index = 0; index < BLAST_SIDE_JETS && plan.columnHeight > 0; index++) {
9420
+ const angle = index / BLAST_SIDE_JETS * Math.PI * 2 + random.next();
9421
+ const off = plan.columnRadius * random.between(0.6, 1.1);
9422
+ const lean = random.between(0.1, 0.25);
9423
+ addColumn(context, { at: [surface[0] + Math.cos(angle) * off, level, surface[2] + Math.sin(angle) * off], peak: plan.columnHeight * random.between(0.45, 0.75), radius: plan.columnRadius * 0.45, tilt: [Math.cos(angle) * lean, Math.sin(angle) * lean], dome: false, delay: 0.05 + random.next() * 0.08 });
9424
+ }
9425
+ if (plan.domeRadius > 0) addColumn(context, { at: surface, peak: plan.domeHeight, radius: plan.domeRadius, tilt: [0, 0], dome: true, delay: 0, rise: 0.25 });
9426
+ addRing(context, { x: surface[0], y: level, z: surface[2], kind: 1, start: 0.2, max: plan.shockRadius, life: 0.45, delay: 0, strength: 0.95 });
9427
+ spawnWaves(context, surface, plan);
9428
+ spawnRain(context, surface, plan, detail);
9429
+ spawnSpray(context, surface, plan, scale);
9430
+ addFoam(context, surface, plan.foamRadius, BLAST_FOAM_LIFE);
9431
+ const bubbles = Math.round(plan.bubbles * detail);
9432
+ for (let index = 0; index < bubbles; index++) {
9433
+ const at3 = [point[0] + random.between(-0.5, 0.5) * scale, Math.min(level - 0.02, point[1] + random.between(-0.2, 0.3) * scale), point[2] + random.between(-0.5, 0.5) * scale];
9434
+ addBubble(context, at3, level, random.next() * 1.2, random.between(0.01, 0.04) * Math.max(1, scale));
9435
+ }
9436
+ }
9437
+ function spawnWaves(context, surface, plan) {
9438
+ if (plan.waveAmplitude <= 0) return;
9439
+ const reach = context.reach(surface[0], surface[2], plan.waveSpeed * BLAST_WAVE_LIFE);
9440
+ for (let crest = 0; crest < BLAST_WAVE_CRESTS; crest++) {
9441
+ const wave = context.pools.waves.acquire();
9442
+ wave.x = surface[0];
9443
+ wave.z = surface[2];
9444
+ wave.speed = plan.waveSpeed;
9445
+ wave.amplitude = plan.waveAmplitude * (1 - crest * 0.3);
9446
+ wave.width = 0.25 + 0.3 * Math.cbrt(plan.tnt);
9447
+ wave.reach = reach;
9448
+ wave.delay = crest * BLAST_WAVE_GAP;
9449
+ wave.age = 0;
9450
+ wave.life = BLAST_WAVE_LIFE;
9451
+ addRing(context, { x: surface[0], y: surface[1], z: surface[2], kind: 2, start: 0.1, max: plan.waveSpeed * BLAST_WAVE_LIFE, life: BLAST_WAVE_LIFE, delay: wave.delay, strength: 0.5 * (1 - crest * 0.3) });
9452
+ }
9453
+ }
9454
+ function spawnRain(context, surface, plan, detail) {
9455
+ const { random } = context;
9456
+ const drops = Math.round(plan.drops * detail);
9457
+ const top = Math.max(0.5, plan.columnHeight);
9458
+ const launch = Math.sqrt(2 * WATER_GRAVITY * top);
9459
+ const scale = Math.cbrt(plan.tnt);
9460
+ for (let index = 0; index < drops; index++) {
9461
+ const angle = random.next() * Math.PI * 2;
9462
+ const out = random.between(0.4, 3) * scale;
9463
+ const r = random.next() * plan.columnRadius;
9464
+ addDrop(context, {
9465
+ at: [surface[0] + Math.cos(angle) * r, surface[1] + random.next() * top * 0.2, surface[2] + Math.sin(angle) * r],
9466
+ velocity: [Math.cos(angle) * out, launch * random.between(0.45, 1.02), Math.sin(angle) * out],
9467
+ size: random.between(0.012, 0.035),
9468
+ level: surface[1]
9469
+ });
9470
+ }
9471
+ }
9472
+ function spawnSpray(context, surface, plan, scale) {
9473
+ const { random } = context;
9474
+ const top = Math.max(0.4, plan.columnHeight);
9475
+ for (let index = 0; index < plan.mist; index++) {
9476
+ const mist = context.pools.mist.acquire();
9477
+ const angle = random.next() * Math.PI * 2;
9478
+ const r = random.next() * (plan.columnRadius + 0.5 * scale);
9479
+ mist.x = surface[0] + Math.cos(angle) * r;
9480
+ mist.y = surface[1] + random.next() * top * 0.6;
9481
+ mist.z = surface[2] + Math.sin(angle) * r;
9482
+ const out = random.between(0.5, 1.8) * scale;
9483
+ mist.vx = Math.cos(angle) * out;
9484
+ mist.vy = random.between(0.3, 1);
9485
+ mist.vz = Math.sin(angle) * out;
9486
+ mist.size = random.between(0.4, 1.2) * scale;
9487
+ mist.age = 0;
9488
+ mist.life = random.between(2.5, 4.5);
9489
+ mist.alpha = 0;
9490
+ }
9491
+ }
9492
+
9493
+ // src/water/effects.ts
9494
+ var STEP_LIMIT = 0.05;
9495
+ var SHORE_DIRECTIONS = 8;
9496
+ var SHORE_HALVINGS = 5;
9497
+ var SAME_WATER = 0.2;
9498
+ var DROP_RING_SHARE = 0.75;
9499
+ var WAVE_PUSH = 2;
9500
+ function createWaterEffects(options = {}) {
9501
+ const limits = { ...WATER_LIMITS, ...options.limits };
9502
+ const pools = createWaterPools(limits);
9503
+ const random = lehmer(options.seed ?? 1);
9504
+ const lod = options.lod ?? LOD_GAME;
9505
+ const camera2 = [0, 0, 0];
9506
+ let hasCamera = false;
9507
+ const reach = (x, z, limit) => {
9508
+ const levelAt = options.levelAt;
9509
+ if (!levelAt) return limit;
9510
+ const here = levelAt(x, z);
9511
+ if (here === null) return 0;
9512
+ const step = Math.max(0.05, limit / 10);
9513
+ const isWater = (cos2, sin2, distance) => {
9514
+ const level = levelAt(x + cos2 * distance, z + sin2 * distance);
9515
+ return level !== null && Math.abs(level - here) <= SAME_WATER;
9516
+ };
9517
+ let nearest = limit;
9518
+ for (let index = 0; index < SHORE_DIRECTIONS; index++) {
9519
+ const angle = index / SHORE_DIRECTIONS * Math.PI * 2;
9520
+ const cos2 = Math.cos(angle);
9521
+ const sin2 = Math.sin(angle);
9522
+ for (let distance = step; distance < nearest; distance += step) {
9523
+ if (isWater(cos2, sin2, distance)) continue;
9524
+ let wet = distance - step;
9525
+ let dry = distance;
9526
+ for (let halving = 0; halving < SHORE_HALVINGS; halving++) {
9527
+ const middle = (wet + dry) / 2;
9528
+ if (isWater(cos2, sin2, middle)) wet = middle;
9529
+ else dry = middle;
9530
+ }
9531
+ nearest = Math.min(nearest, wet);
9532
+ break;
9533
+ }
9534
+ }
9535
+ return nearest;
9536
+ };
9537
+ const detailAt = (point, radius) => hasCamera ? lodScale(lod, Math.hypot(point[0] - camera2[0], point[1] - camera2[1], point[2] - camera2[2]), radius) : 1;
9538
+ const contextAt = (point, radius) => ({ pools, random, detail: detailAt(point, radius), reach });
9539
+ const motion = {
9540
+ dt: 0,
9541
+ landed: (drop) => {
9542
+ if (pools.rings.count >= limits.rings * DROP_RING_SHARE) return;
9543
+ const level = options.levelAt ? options.levelAt(drop.x, drop.z) : drop.level;
9544
+ if (level === null || Math.abs(level - drop.level) > SAME_WATER) return;
9545
+ addRing({ pools, random, detail: 1, reach }, { x: drop.x, y: level, z: drop.z, kind: 0, start: drop.size, max: 0.04 + drop.size * 6, life: 0.5, delay: 0, strength: 0.35 });
9546
+ }
9547
+ };
9548
+ const shot = (params) => {
9549
+ const plan = planWaterShot(params, random, options.profiles);
9550
+ spawnShot(contextAt(params.point, plan.ringRadius), params.point, plan);
9551
+ return plan;
9552
+ };
9553
+ const pepper = (params, plan) => {
9554
+ const spread = 1.5 + 3 * Math.cbrt(plan.tnt);
9555
+ for (let index = 0; index < plan.fragments; index++) {
9556
+ const angle = random.next() * Math.PI * 2;
9557
+ const distance = random.between(0.6, spread);
9558
+ const x = params.point[0] + Math.cos(angle) * distance;
9559
+ const z = params.point[2] + Math.sin(angle) * distance;
9560
+ const level = options.levelAt ? options.levelAt(x, z) : params.level;
9561
+ if (level === null || Math.abs(level - params.level) > SAME_WATER) continue;
9562
+ const fall = random.between(0.4, 1);
9563
+ const length = Math.hypot(Math.cos(angle), fall, Math.sin(angle));
9564
+ const point = [x, level, z];
9565
+ const fragment = planWaterShot({ point, direction: [Math.cos(angle) / length, -fall / length, Math.sin(angle) / length], profile: "fragment", depth: params.depth }, random, options.profiles);
9566
+ spawnShot(contextAt(point, fragment.ringRadius), point, fragment);
9567
+ }
9568
+ };
9569
+ const blast = (params) => {
9570
+ const plan = planWaterBlast(params);
9571
+ spawnBlast(contextAt(params.point, plan.shockRadius), params.point, params.level, plan);
9572
+ pepper(params, plan);
9573
+ return plan;
9574
+ };
9575
+ const waveAt = (x, z) => {
9576
+ let height = 0;
9577
+ let pushX = 0;
9578
+ let pushZ = 0;
9579
+ for (const wave of pools.waves.items) {
9580
+ if (wave.delay > 0) continue;
9581
+ const dx = x - wave.x;
9582
+ const dz = z - wave.z;
9583
+ const r = Math.hypot(dx, dz);
9584
+ if (r > wave.reach) continue;
9585
+ const off = (r - wave.speed * wave.age) / wave.width;
9586
+ if (Math.abs(off) > 3) continue;
9587
+ const crest = wave.amplitude * Math.exp(-off * off) * (1 - wave.age / wave.life) / Math.sqrt(Math.max(1, r));
9588
+ height += crest;
9589
+ if (r > 1e-3) {
9590
+ const push = crest * wave.speed * WAVE_PUSH;
9591
+ pushX += dx / r * push;
9592
+ pushZ += dz / r * push;
9593
+ }
9594
+ }
9595
+ return { height, push: [pushX, pushZ] };
9596
+ };
9597
+ return {
9598
+ shot,
9599
+ blast,
9600
+ update(dt) {
9601
+ let left = Math.max(0, dt);
9602
+ while (left > 1e-6) {
9603
+ motion.dt = Math.min(STEP_LIMIT, left);
9604
+ stepWaterPools(pools, motion);
9605
+ left -= motion.dt;
9606
+ }
9607
+ },
9608
+ setCamera(position) {
9609
+ camera2[0] = position[0];
9610
+ camera2[1] = position[1];
9611
+ camera2[2] = position[2];
9612
+ hasCamera = true;
9613
+ },
9614
+ waveAt,
9615
+ drops: pools.drops.items,
9616
+ rings: pools.rings.items,
9617
+ foam: pools.foam.items,
9618
+ columns: pools.columns.items,
9619
+ bubbles: pools.bubbles.items,
9620
+ mist: pools.mist.items,
9621
+ waves: pools.waves.items,
9622
+ limits,
9623
+ stats: () => ({ drops: pools.drops.count, rings: pools.rings.count, foam: pools.foam.count, columns: pools.columns.count, bubbles: pools.bubbles.count, mist: pools.mist.count, waves: pools.waves.count }),
9624
+ clear() {
9625
+ for (const pool of Object.values(pools)) pool.clear();
9626
+ }
9627
+ };
9628
+ }
8871
9629
  export {
8872
9630
  AREA_CAP_GAME,
8873
9631
  EVENT_BUDGET,
@@ -8894,6 +9652,11 @@ export {
8894
9652
  SpriteKindSystem,
8895
9653
  VFX_LAYERS,
8896
9654
  VIEWMODEL_EFFECTS,
9655
+ WATER_BLASTS,
9656
+ WATER_BLAST_KINDS,
9657
+ WATER_LIMITS,
9658
+ WATER_SHOT_BY_CALIBER,
9659
+ WATER_SHOT_PROFILES,
8897
9660
  WORKSHOP_BEHAVIORS,
8898
9661
  WORKSHOP_EFFECTS,
8899
9662
  WORKSHOP_PUDDLES,
@@ -8906,6 +9669,7 @@ export {
8906
9669
  createSchedule,
8907
9670
  createScreenState,
8908
9671
  createVfx,
9672
+ createWaterEffects,
8909
9673
  createWorkshopBehaviors,
8910
9674
  effectForEvent,
8911
9675
  estimateCost,
@@ -8919,10 +9683,16 @@ export {
8919
9683
  patchEffects,
8920
9684
  patchExplosions,
8921
9685
  patchSpriteKinds,
9686
+ patchWaterShotProfiles,
9687
+ planWaterBlast,
9688
+ planWaterShot,
8922
9689
  resolveStrings,
9690
+ resolveWaterBlast,
9691
+ resolveWaterShotProfile,
8923
9692
  slideAlong,
8924
9693
  streamFor,
8925
9694
  updateScreen,
9695
+ waterShotClassOf,
8926
9696
  workshopGround
8927
9697
  };
8928
9698
  //# sourceMappingURL=index.js.map