@adatechnology/game-vfx 0.12.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
@@ -8958,6 +8958,674 @@ function createGroundField(options = {}) {
8958
8958
  reset
8959
8959
  };
8960
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
+ }
8961
9629
  export {
8962
9630
  AREA_CAP_GAME,
8963
9631
  EVENT_BUDGET,
@@ -8984,6 +9652,11 @@ export {
8984
9652
  SpriteKindSystem,
8985
9653
  VFX_LAYERS,
8986
9654
  VIEWMODEL_EFFECTS,
9655
+ WATER_BLASTS,
9656
+ WATER_BLAST_KINDS,
9657
+ WATER_LIMITS,
9658
+ WATER_SHOT_BY_CALIBER,
9659
+ WATER_SHOT_PROFILES,
8987
9660
  WORKSHOP_BEHAVIORS,
8988
9661
  WORKSHOP_EFFECTS,
8989
9662
  WORKSHOP_PUDDLES,
@@ -8996,6 +9669,7 @@ export {
8996
9669
  createSchedule,
8997
9670
  createScreenState,
8998
9671
  createVfx,
9672
+ createWaterEffects,
8999
9673
  createWorkshopBehaviors,
9000
9674
  effectForEvent,
9001
9675
  estimateCost,
@@ -9009,10 +9683,16 @@ export {
9009
9683
  patchEffects,
9010
9684
  patchExplosions,
9011
9685
  patchSpriteKinds,
9686
+ patchWaterShotProfiles,
9687
+ planWaterBlast,
9688
+ planWaterShot,
9012
9689
  resolveStrings,
9690
+ resolveWaterBlast,
9691
+ resolveWaterShotProfile,
9013
9692
  slideAlong,
9014
9693
  streamFor,
9015
9694
  updateScreen,
9695
+ waterShotClassOf,
9016
9696
  workshopGround
9017
9697
  };
9018
9698
  //# sourceMappingURL=index.js.map