@adatechnology/game-vfx 0.16.0 → 0.18.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.
@@ -1492,8 +1492,61 @@ var GameVfx = (() => {
1492
1492
  return lehmer(mixEventSeed(eventSeed));
1493
1493
  }
1494
1494
 
1495
- // src/enclosures.ts
1495
+ // src/solids.ts
1496
1496
  var SKIN = 5e-3;
1497
+ var Solids = class {
1498
+ constructor() {
1499
+ __publicField(this, "queries", /* @__PURE__ */ new Map());
1500
+ __publicField(this, "list", []);
1501
+ __publicField(this, "hit", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
1502
+ }
1503
+ get empty() {
1504
+ return this.list.length === 0;
1505
+ }
1506
+ /** Declares or (with `null`) ends the solids `id` answers for. */
1507
+ set(id, query2) {
1508
+ if (query2) this.queries.set(id, query2);
1509
+ else this.queries.delete(id);
1510
+ this.list = [...this.queries.values()];
1511
+ }
1512
+ clear() {
1513
+ this.queries.clear();
1514
+ this.list = [];
1515
+ }
1516
+ /**
1517
+ * Stops a step that goes into a solid: `out` gets the nearest hit, put back `pad` metres off the surface (never behind where the step began) and
1518
+ * the surface's normal. Answers whether the step was stopped.
1519
+ */
1520
+ stop(move, pad, out) {
1521
+ const dx = move.x1 - move.x0;
1522
+ const dy = move.y1 - move.y0;
1523
+ const dz = move.z1 - move.z0;
1524
+ const length = Math.hypot(dx, dy, dz);
1525
+ if (!(length > 0)) return false;
1526
+ let nearest = Infinity;
1527
+ for (const query2 of this.list) {
1528
+ if (!query2(move, this.hit)) continue;
1529
+ const reached = ((this.hit.x - move.x0) * dx + (this.hit.y - move.y0) * dy + (this.hit.z - move.z0) * dz) / length;
1530
+ if (reached >= nearest) continue;
1531
+ nearest = reached;
1532
+ out.x = this.hit.x;
1533
+ out.y = this.hit.y;
1534
+ out.z = this.hit.z;
1535
+ out.nx = this.hit.nx;
1536
+ out.ny = this.hit.ny;
1537
+ out.nz = this.hit.nz;
1538
+ }
1539
+ if (nearest === Infinity) return false;
1540
+ const back = Math.min(Math.max(pad, 0) + SKIN, Math.max(nearest, 0));
1541
+ out.x -= dx / length * back;
1542
+ out.y -= dy / length * back;
1543
+ out.z -= dz / length * back;
1544
+ return true;
1545
+ }
1546
+ };
1547
+
1548
+ // src/enclosures.ts
1549
+ var SKIN2 = 5e-3;
1497
1550
  var MAX_PAD = 0.45;
1498
1551
  function rotation(q) {
1499
1552
  const [x, y, z, w] = q ?? [0, 0, 0, 1];
@@ -1525,10 +1578,15 @@ var GameVfx = (() => {
1525
1578
  __publicField(this, "q", new Float64Array(3));
1526
1579
  __publicField(this, "h", new Float64Array(3));
1527
1580
  __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
1581
+ __publicField(this, "solids", new Solids());
1528
1582
  this.random = lehmer(seed);
1529
1583
  }
1530
1584
  get empty() {
1531
- return this.list.length === 0;
1585
+ return this.list.length === 0 && this.solids.empty;
1586
+ }
1587
+ /** Declares or (with `null`) ends the host solids `id` answers for (a destruction world's walls): what is carried stops at them and passes only their holes. */
1588
+ solid(id, query2) {
1589
+ this.solids.set(id, query2);
1532
1590
  }
1533
1591
  get size() {
1534
1592
  return this.list.length;
@@ -1611,6 +1669,10 @@ var GameVfx = (() => {
1611
1669
  return this.confineMove(move, dt);
1612
1670
  }
1613
1671
  confineMove(move, dt) {
1672
+ if (this.confineSpaces(move, dt)) return true;
1673
+ return !this.solids.empty && this.solids.stop(move, Math.min(Math.max(0, move.pad), MAX_PAD), this.out);
1674
+ }
1675
+ confineSpaces(move, dt) {
1614
1676
  const list = this.list;
1615
1677
  if (list.length === 0) return false;
1616
1678
  const { x0, y0, z0, x1, y1, z1 } = move;
@@ -1651,7 +1713,7 @@ var GameVfx = (() => {
1651
1713
  }
1652
1714
  }
1653
1715
  sign = l1[axis2] < 0 ? -1 : 1;
1654
- for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN, Math.max(-(h[a] - SKIN), l1[a]));
1716
+ for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN2, Math.max(-(h[a] - SKIN2), l1[a]));
1655
1717
  sign = -sign;
1656
1718
  } else {
1657
1719
  const padded0 = Math.abs(l0[0]) <= s.hx + p && Math.abs(l0[1]) <= s.hy + p && Math.abs(l0[2]) <= s.hz + p;
@@ -1668,7 +1730,7 @@ var GameVfx = (() => {
1668
1730
  }
1669
1731
  }
1670
1732
  sign = l0[axis2] < 0 ? -1 : 1;
1671
- l1[axis2] = sign * (h[axis2] + bound + SKIN);
1733
+ l1[axis2] = sign * (h[axis2] + bound + SKIN2);
1672
1734
  }
1673
1735
  const r = s.r;
1674
1736
  const out = this.out;
@@ -1927,6 +1989,7 @@ var GameVfx = (() => {
1927
1989
  y: 0,
1928
1990
  z: 0,
1929
1991
  r: 0.6,
1992
+ h: 0,
1930
1993
  r0: 0.6,
1931
1994
  grow: 0,
1932
1995
  life: 6,
@@ -1952,6 +2015,7 @@ var GameVfx = (() => {
1952
2015
  fire.y = init.y ?? 0;
1953
2016
  fire.z = init.z ?? 0;
1954
2017
  fire.r = init.r ?? 0.6;
2018
+ fire.h = init.h ?? 0;
1955
2019
  fire.r0 = init.startRadius ?? fire.r;
1956
2020
  fire.grow = init.grow ?? 0;
1957
2021
  fire.life = init.life ?? 6;
@@ -1976,19 +2040,23 @@ var GameVfx = (() => {
1976
2040
  core.trace?.fire?.(fire);
1977
2041
  return fire;
1978
2042
  }
2043
+ var FLAMES_PER_HEIGHT = 1.5;
2044
+ var SMOKE_PER_HEIGHT = 2;
1979
2045
  function positionOf(follow) {
1980
2046
  return "position" in follow ? follow.position : follow;
1981
2047
  }
2048
+ var heightOf = (fire) => fire.h > 0 ? fire.rng.next() * fire.h : 0;
2049
+ var isBody = (follow) => "radius" in follow && "height" in follow;
1982
2050
  function emitFlames(core, fire, radius, dt) {
1983
2051
  const random = fire.rng;
1984
- fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * fire.fade * core.clock.lod;
2052
+ fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * (1 + fire.h * FLAMES_PER_HEIGHT) * fire.fade * core.clock.lod;
1985
2053
  while (fire.acc >= 1) {
1986
2054
  fire.acc -= 1;
1987
2055
  const angle = random.next() * Math.PI * 2;
1988
2056
  const distance = Math.sqrt(random.next()) * radius;
1989
2057
  addPuff(core, random, {
1990
2058
  x: fire.x + Math.cos(angle) * distance,
1991
- y: fire.y + 0.05,
2059
+ y: fire.y + 0.05 + heightOf(fire),
1992
2060
  z: fire.z + Math.sin(angle) * distance,
1993
2061
  vx: random.between(-0.2, 0.2),
1994
2062
  vy: random.between(0.6, 1.4),
@@ -2010,12 +2078,12 @@ var GameVfx = (() => {
2010
2078
  }
2011
2079
  function emitSmoke(core, fire, radius, dt) {
2012
2080
  const random = fire.rng;
2013
- fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * fire.fade * core.clock.lod;
2081
+ fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * (1 + fire.h * SMOKE_PER_HEIGHT) * fire.fade * core.clock.lod;
2014
2082
  while (fire.smokeAcc >= 1 && core.layers.smoke) {
2015
2083
  fire.smokeAcc -= 1;
2016
2084
  addPuff(core, random, {
2017
2085
  x: fire.x + random.between(-radius, radius) * 0.5,
2018
- y: fire.y + 0.6 + radius * 0.3,
2086
+ y: fire.y + fire.h + 0.6 + radius * 0.3,
2019
2087
  z: fire.z + random.between(-radius, radius) * 0.5,
2020
2088
  vy: random.between(0.8, 1.5),
2021
2089
  s0: 0.25,
@@ -2037,7 +2105,7 @@ var GameVfx = (() => {
2037
2105
  if (!(random.next() < dt * 6 * fire.fade && core.layers.shrapnel)) return;
2038
2106
  addSpark(core, {
2039
2107
  x: fire.x + random.between(-radius, radius) * 0.6,
2040
- y: fire.y + 0.4,
2108
+ y: fire.y + 0.4 + heightOf(fire),
2041
2109
  z: fire.z + random.between(-radius, radius) * 0.6,
2042
2110
  vx: random.between(-0.4, 0.4),
2043
2111
  vy: random.between(1.5, 3.2),
@@ -2061,6 +2129,10 @@ var GameVfx = (() => {
2061
2129
  fire.x = point.x + fire.fx;
2062
2130
  fire.y = point.y + fire.fy;
2063
2131
  fire.z = point.z + fire.fz;
2132
+ if (isBody(fire.follow)) {
2133
+ fire.r = fire.follow.radius;
2134
+ fire.h = fire.follow.height;
2135
+ }
2064
2136
  }
2065
2137
  const radius = fire.grow ? lerp(fire.r0, fire.r, Math.min(1, fire.t / fire.grow)) : fire.r;
2066
2138
  fire.fade = fire.t < fire.life - 1.5 ? Math.min(1, fire.t * 3) : Math.max(0, (fire.life - fire.t) / 1.5);
@@ -2135,6 +2207,7 @@ var GameVfx = (() => {
2135
2207
  var QUALITY = { $: "quality" };
2136
2208
  var FRESH = { $: "fresh" };
2137
2209
  var DIRECTION = { $: "direction" };
2210
+ var NORMAL = { $: "normal" };
2138
2211
  var CAMERA_POSITION = { $: "cameraPosition" };
2139
2212
 
2140
2213
  // src/effects/steps.ts
@@ -2690,7 +2763,7 @@ var GameVfx = (() => {
2690
2763
  var TIP2 = [-0.8, 1.38, 3.4 - 0.78];
2691
2764
  var PORT2 = [-0.76, 1.4, 3.32];
2692
2765
  var FORWARD3 = [0, 0, -1];
2693
- var NORMAL = [0, 0, 1];
2766
+ var NORMAL2 = [0, 0, 1];
2694
2767
  var WALL_Z2 = -4.45;
2695
2768
  var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
2696
2769
  var SHOT_TIME = pick(pick(SHOTS, PARAM), INDEX);
@@ -2715,8 +2788,8 @@ var GameVfx = (() => {
2715
2788
  set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
2716
2789
  when(
2717
2790
  eq(PARAM, SHOTGUN),
2718
- [repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL, 0.35))],
2719
- [call2("impact", "concrete", variable("target"), NORMAL, ite(eq(PARAM, BARRETT), 2, 1))]
2791
+ [repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL2, 0.35))],
2792
+ [call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
2720
2793
  ),
2721
2794
  when(and(eq(PARAM, AK), eq(mod(round(mul(SHOT_TIME, 10)), 3), 0)), [spawn("streak", { p: TIP2, dir: FORWARD3, cone: 0, sp: 90, life: 0.09, len: 0.025, c0: 16752704, a: 1 })])
2722
2795
  )
@@ -3274,6 +3347,8 @@ var GameVfx = (() => {
3274
3347
  __publicField(this, "puddles", WORKSHOP_PUDDLES);
3275
3348
  /** Replaces the puddle test (a game knows its own wet spots). */
3276
3349
  __publicField(this, "puddleAt");
3350
+ /** Top (world y) of the roof or slab over (x, z), `undefined` for open sky: a streak that falls under it is gone, with no splash and no ring. Unset: nothing is roofed. */
3351
+ __publicField(this, "coverTopAt");
3277
3352
  }
3278
3353
  /** `initRain` (W321): `count` streaks (thinned by the quality), each drawn at a random place in the box. */
3279
3354
  init(count, wind) {
@@ -3319,6 +3394,13 @@ var GameVfx = (() => {
3319
3394
  positions[o + 3] += slant;
3320
3395
  positions[o + 1] -= fall;
3321
3396
  positions[o + 4] -= fall;
3397
+ if (this.coverTopAt) {
3398
+ const top = this.coverTopAt(positions[o], positions[o + 2]);
3399
+ if (top !== void 0 && positions[o + 4] < top) {
3400
+ this.restart(o);
3401
+ continue;
3402
+ }
3403
+ }
3322
3404
  const ground = context.groundAt(positions[o], positions[o + 2]);
3323
3405
  if (positions[o + 4] < ground) {
3324
3406
  const x = positions[o];
@@ -3334,10 +3416,7 @@ var GameVfx = (() => {
3334
3416
  }
3335
3417
  }
3336
3418
  }
3337
- const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
3338
- const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
3339
- const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
3340
- this.set(o, nx, ny, nz);
3419
+ this.restart(o);
3341
3420
  }
3342
3421
  }
3343
3422
  }
@@ -3345,6 +3424,13 @@ var GameVfx = (() => {
3345
3424
  clear() {
3346
3425
  this.on = false;
3347
3426
  }
3427
+ restart(offset) {
3428
+ const { random } = this.engine;
3429
+ const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
3430
+ const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
3431
+ const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
3432
+ this.set(offset, nx, ny, nz);
3433
+ }
3348
3434
  set(offset, x, y, z) {
3349
3435
  const positions = this.positions;
3350
3436
  positions[offset] = x;
@@ -3954,7 +4040,6 @@ var GameVfx = (() => {
3954
4040
  ];
3955
4041
 
3956
4042
  // src/effects/events.ts
3957
- var FACING5 = [0, 0, 1];
3958
4043
  var ORIGIN2 = [0, 0, 0];
3959
4044
  var FORWARD4 = [0, 0, -1];
3960
4045
  var IMPACT_MATERIALS = ["concrete", "metal", "wood", "glass", "flesh", "water"];
@@ -3964,7 +4049,7 @@ var GameVfx = (() => {
3964
4049
  team: "weapons",
3965
4050
  budget: { particles: 40, decals: 1 },
3966
4051
  loop: 2,
3967
- timeline: [call2("impact", material, ORIGIN2, FACING5, 1, 0)]
4052
+ timeline: [call2("impact", material, ORIGIN2, NORMAL, 1, 0)]
3968
4053
  });
3969
4054
  var muzzleEffect = (weapon) => ({
3970
4055
  id: `muzzle_${weapon}`,
@@ -4170,13 +4255,25 @@ var GameVfx = (() => {
4170
4255
 
4171
4256
  // src/effects/vehicles/game-effects.ts
4172
4257
  var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
4258
+ var BODYWORK_IMPACT = {
4259
+ id: "impact_bodywork",
4260
+ pageId: "vehicle:impact_bodywork",
4261
+ team: "vehicles",
4262
+ budget: { particles: 80, debris: 20, lights: 1 },
4263
+ loop: 2,
4264
+ timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
4265
+ };
4173
4266
  var VEHICLE_EFFECTS = [
4267
+ BODYWORK_IMPACT,
4174
4268
  /** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
4175
4269
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
4176
4270
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
4177
4271
  aliasOf(ENGINE_SMOKE, "vehicle_exhaust", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 0 }, loop: 0.5 }),
4178
- /** A hole in the tank: the page's petrol leak without the fire and the blast (the pool and the drips). A normal bullet does only this. */
4179
- aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", {}),
4272
+ /**
4273
+ * A hole in a tank: the page's drips, falling from the point it is played at (the hole). No pool of its own: the pool is the liquid that came out, laid by the
4274
+ * host's fluid world as it leaks (it grows with the volume and spreads by the liquid's own kind), not a drawing of a size the page chose.
4275
+ */
4276
+ aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", { anchor: TANK, timeline: [] }),
4180
4277
  /** The leak caught fire (an incendiary or tracer round, a spark, a fire near): the page's whole sequence, the fire running along the pool to the tank and the blast. */
4181
4278
  aliasOf(FUEL_LEAK, "vehicle_leak_ignited", {})
4182
4279
  ];
@@ -4914,6 +5011,48 @@ var GameVfx = (() => {
4914
5011
  }
4915
5012
  }
4916
5013
 
5014
+ // src/effects/builders/bodywork.ts
5015
+ var PISTOL_BORE = 9e-3;
5016
+ var BARE_STEEL = 11778236;
5017
+ var DEFAULT_PAINT = 9147290;
5018
+ var DEFAULT_DIRECTION = [0, 0, -1];
5019
+ var MAX_SCALE = 3;
5020
+ var MIN_SCALE = 0.6;
5021
+ function reflected(direction, normal) {
5022
+ const along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
5023
+ const out = [direction[0] - 2 * along * normal[0], direction[1] - 2 * along * normal[1], direction[2] - 2 * along * normal[2]];
5024
+ const length = Math.hypot(out[0], out[1], out[2]);
5025
+ if (length < 1e-6 || Math.abs(along) > 0.98) return normal;
5026
+ return [out[0] / length, out[1] / length, out[2] / length];
5027
+ }
5028
+ var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
5029
+ function bodyworkHitOf(values) {
5030
+ const raw = Array.isArray(values.direction) ? values.direction : [];
5031
+ const direction = raw.length === 3 && raw.every((entry) => typeof entry === "number" && Number.isFinite(entry)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
5032
+ return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
5033
+ }
5034
+ function bodyworkScale(bore) {
5035
+ return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
5036
+ }
5037
+ function bodyworkImpact(engine, point, normal, hit) {
5038
+ const scale = bodyworkScale(hit.bore);
5039
+ const off = reflected(hit.direction, normal);
5040
+ if (engine.quality < 2) {
5041
+ engine.burst("streak", Math.round(14 * scale), { p: point, dir: off, cone: 0.75, sp: [4, 12], life: [0.08, 0.3], len: 0.03, c0: 16774352, c1: 16738840, g: 9.8, gnd: 2 });
5042
+ engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
5043
+ engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
5044
+ }
5045
+ const flakes = engine.scaled(Math.round(5 * scale));
5046
+ for (let index = 0; index < flakes; index++) {
5047
+ engine.debrisPiece({ p: point, dir: normal, cone: 0.9, sp: [1.2, 3.5], size: [8e-3 * scale, 12e-4, 6e-3 * scale], k: [0.5, 1.4], c: hit.paint, life: 6, bounce: 0.2 });
5048
+ }
5049
+ const slivers = engine.scaled(Math.round(2 * scale));
5050
+ for (let index = 0; index < slivers; index++) {
5051
+ engine.debrisPiece({ p: point, dir: off, cone: 0.6, sp: [2.5, 6], size: [25e-4, 15e-4, 0.01 * scale], k: [0.6, 1.3], c: hit.metal, life: 6, bounce: 0.35 });
5052
+ }
5053
+ engine.burst("normal", Math.round(6 * scale), { p: point, dir: normal, cone: 0.7, sp: [0.4, 1.4], drag: 2.5, life: [0.4, 0.9], size: [0.03, 0.07], grow: 3, c0: hit.paint, a: 0.45, g: -0.05 });
5054
+ }
5055
+
4917
5056
  // src/effects/builders/fire.ts
4918
5057
  var UP12 = [0, 1, 0];
4919
5058
  var ZERO = [0, 0, 0];
@@ -5068,11 +5207,12 @@ var GameVfx = (() => {
5068
5207
  casing: ({ engine }, [port, type]) => casing(engine, port, type),
5069
5208
  chips: ({ engine }, [point, direction, count, spread]) => chips(engine, point, direction, count, spread),
5070
5209
  spark_at: ({ engine }, [point, direction, count, spread]) => sparkAt(engine, point, direction, count, spread),
5071
- rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
5210
+ rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
5211
+ bodywork_impact: ({ engine }, [point, normal, direction, bore, paint, metal]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint, metal }))
5072
5212
  };
5073
5213
 
5074
5214
  // src/effects/instance.ts
5075
- var DEFAULT_DIRECTION = [0, 0, -1];
5215
+ var DEFAULT_DIRECTION2 = [0, 0, -1];
5076
5216
  var DEFAULT_NORMAL = [0, 1, 0];
5077
5217
  var SCREEN_FIELDS = {
5078
5218
  shake: "shake",
@@ -5141,7 +5281,7 @@ var GameVfx = (() => {
5141
5281
  return instance().fresh;
5142
5282
  },
5143
5283
  get direction() {
5144
- return instance().setup.direction ?? DEFAULT_DIRECTION;
5284
+ return instance().setup.direction ?? DEFAULT_DIRECTION2;
5145
5285
  },
5146
5286
  get normal() {
5147
5287
  return instance().setup.normal ?? DEFAULT_NORMAL;
@@ -5761,6 +5901,24 @@ var GameVfx = (() => {
5761
5901
  screen2.flashDecay = 0.5;
5762
5902
  }
5763
5903
  }
5904
+ var BIRTH = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
5905
+ function bornFrom(core, puff3, ox, oy, oz) {
5906
+ const confiner = core.confiner;
5907
+ if (confiner.empty) return;
5908
+ BIRTH.x0 = ox;
5909
+ BIRTH.y0 = oy;
5910
+ BIRTH.z0 = oz;
5911
+ BIRTH.x1 = puff3.x;
5912
+ BIRTH.y1 = puff3.y;
5913
+ BIRTH.z1 = puff3.z;
5914
+ BIRTH.pad = puff3.s0 * PAD_OF_SIZE;
5915
+ if (!confiner.confineMove(BIRTH, 0)) return;
5916
+ const out = confiner.out;
5917
+ puff3.x = out.x;
5918
+ puff3.y = out.y;
5919
+ puff3.z = out.z;
5920
+ slideInto(out, puff3);
5921
+ }
5764
5922
  function composeFireballs(context) {
5765
5923
  const { core, def, random, x, y, z, size, scale, direction } = context;
5766
5924
  if (!core.layers.fire || !def.fireballs) return;
@@ -5777,7 +5935,7 @@ var GameVfx = (() => {
5777
5935
  const life = random.between(def.smoke.life * 0.7, def.smoke.life);
5778
5936
  const h0 = random.between(1.05, 1.35) * heat;
5779
5937
  const hl = fuel ? random.between(0.8, 1.4) * (def.heatLifeScale ?? 1) : random.between(0.22, 0.42);
5780
- addPuff(core, random, {
5938
+ const fireball = addPuff(core, random, {
5781
5939
  x: x + d.x * size * 0.15,
5782
5940
  y: y + size * 0.25 + d.y * size * 0.1,
5783
5941
  z: z + d.z * size * 0.15,
@@ -5796,6 +5954,7 @@ var GameVfx = (() => {
5796
5954
  color: context.smokeColor,
5797
5955
  kind: 0
5798
5956
  });
5957
+ bornFrom(core, fireball, x, y, z);
5799
5958
  }
5800
5959
  }
5801
5960
  function composeSmoke(context) {
@@ -5809,7 +5968,7 @@ var GameVfx = (() => {
5809
5968
  const s1 = size * random.between(0.55, 0.85);
5810
5969
  const sg = size * random.between(0.18, 0.3);
5811
5970
  const life = random.between(def.smoke.life * 0.7, def.smoke.life * 1.1);
5812
- addPuff(core, random, {
5971
+ const smoke = addPuff(core, random, {
5813
5972
  x: x + d.x * size * 0.6,
5814
5973
  y: y + size * 0.4 + d.y * size * 0.5,
5815
5974
  z: z + d.z * size * 0.6,
@@ -5828,6 +5987,7 @@ var GameVfx = (() => {
5828
5987
  color: context.smokeColor,
5829
5988
  kind: def.smoke.kind ?? 0
5830
5989
  });
5990
+ bornFrom(core, smoke, x, y, z);
5831
5991
  }
5832
5992
  }
5833
5993
  function composeShock(context) {
@@ -5852,7 +6012,7 @@ var GameVfx = (() => {
5852
6012
  const s1 = size * random.between(0.5, 0.8);
5853
6013
  const sg = size * random.between(0.2, 0.35);
5854
6014
  const life = random.between(2.2, 4);
5855
- addPuff(core, random, {
6015
+ const dust = addPuff(core, random, {
5856
6016
  x: x + Math.cos(angle) * 0.3,
5857
6017
  y: 0.15,
5858
6018
  z: z + Math.sin(angle) * 0.3,
@@ -5869,6 +6029,7 @@ var GameVfx = (() => {
5869
6029
  color,
5870
6030
  kind: 1
5871
6031
  });
6032
+ bornFrom(core, dust, x, 0.15, z);
5872
6033
  }
5873
6034
  }
5874
6035
  function coneAngle(context) {
@@ -6938,6 +7099,71 @@ var GameVfx = (() => {
6938
7099
  return out;
6939
7100
  }
6940
7101
 
7102
+ // src/workshop/debris-contact.ts
7103
+ var CELL = 0.12;
7104
+ var OBSTACLE_BOUNCE = 0.3;
7105
+ var radiusOf = (piece) => Math.max(piece.sx, piece.sz) * 0.5;
7106
+ var thicknessOf = (piece) => Math.min(piece.sx, piece.sy, piece.sz);
7107
+ var cellKey = (i, k) => (i + 4096) * 8192 + (k + 4096);
7108
+ var RestingGrid = class {
7109
+ constructor() {
7110
+ __publicField(this, "cells", /* @__PURE__ */ new Map());
7111
+ }
7112
+ clear() {
7113
+ for (const list of this.cells.values()) list.length = 0;
7114
+ }
7115
+ rebuild(pieces) {
7116
+ this.clear();
7117
+ for (const piece of pieces) {
7118
+ if (!piece.on || !piece.rest) continue;
7119
+ const key = cellKey(Math.floor(piece.x / CELL), Math.floor(piece.z / CELL));
7120
+ const list = this.cells.get(key);
7121
+ if (list) list.push(piece);
7122
+ else this.cells.set(key, [piece]);
7123
+ }
7124
+ }
7125
+ /** The height a piece at `piece`'s place lands at on the pieces under it (the top of the highest one it overlaps), or `-Infinity` over none. */
7126
+ supportUnder(piece) {
7127
+ const i = Math.floor(piece.x / CELL);
7128
+ const k = Math.floor(piece.z / CELL);
7129
+ const reach = radiusOf(piece);
7130
+ let top = -Infinity;
7131
+ for (let di = -1; di <= 1; di++) {
7132
+ for (let dk = -1; dk <= 1; dk++) {
7133
+ for (const other of this.cells.get(cellKey(i + di, k + dk)) ?? []) {
7134
+ if (other === piece) continue;
7135
+ if (Math.hypot(other.x - piece.x, other.z - piece.z) > reach + radiusOf(other)) continue;
7136
+ const otherTop = other.y + thicknessOf(other) * 0.5;
7137
+ if (otherTop <= piece.y + thicknessOf(piece) * 0.5) top = Math.max(top, otherTop + thicknessOf(piece) * 0.5);
7138
+ }
7139
+ }
7140
+ }
7141
+ return top;
7142
+ }
7143
+ };
7144
+ function pushOutOfObstacles(piece, obstacles) {
7145
+ let moved = false;
7146
+ for (const body of obstacles) {
7147
+ if (piece.y < body.bottom || piece.y > body.top) continue;
7148
+ const dx = piece.x - body.x;
7149
+ const dz = piece.z - body.z;
7150
+ const distance = Math.hypot(dx, dz);
7151
+ const reach = body.radius + radiusOf(piece);
7152
+ if (distance >= reach) continue;
7153
+ const nx = distance > 1e-6 ? dx / distance : 1;
7154
+ const nz = distance > 1e-6 ? dz / distance : 0;
7155
+ piece.x = body.x + nx * reach;
7156
+ piece.z = body.z + nz * reach;
7157
+ const into = piece.vx * nx + piece.vz * nz;
7158
+ if (into < 0) {
7159
+ piece.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
7160
+ piece.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
7161
+ }
7162
+ moved = true;
7163
+ }
7164
+ return moved;
7165
+ }
7166
+
6941
7167
  // src/workshop/debris.ts
6942
7168
  var CAPACITY = 500;
6943
7169
  var GRAVITY2 = 9.8;
@@ -6959,6 +7185,7 @@ var GameVfx = (() => {
6959
7185
  __publicField(this, "count", 0);
6960
7186
  __publicField(this, "next", 0);
6961
7187
  __publicField(this, "direction", { x: 0, y: 0, z: 0 });
7188
+ __publicField(this, "resting", new RestingGrid());
6962
7189
  }
6963
7190
  spawn(options) {
6964
7191
  const random = this.context.random;
@@ -6996,14 +7223,21 @@ var GameVfx = (() => {
6996
7223
  }
6997
7224
  update(dt) {
6998
7225
  this.count = 0;
7226
+ const contacts = this.context.debrisContacts;
7227
+ const obstacles = contacts?.obstacles() ?? [];
7228
+ let moving = false;
6999
7229
  for (const piece of this.pieces) {
7000
7230
  if (!piece.on) continue;
7001
- this.count++;
7002
7231
  piece.life -= dt;
7003
- if (piece.life <= 0) {
7004
- piece.on = false;
7005
- continue;
7006
- }
7232
+ if (piece.life <= 0) piece.on = false;
7233
+ else if (!piece.rest) moving = true;
7234
+ }
7235
+ if (moving && contacts) this.resting.rebuild(this.pieces);
7236
+ else this.resting.clear();
7237
+ for (const piece of this.pieces) {
7238
+ if (!piece.on) continue;
7239
+ this.count++;
7240
+ if (obstacles.length > 0 && pushOutOfObstacles(piece, obstacles)) piece.rest = false;
7007
7241
  if (!piece.rest) this.move(piece, dt);
7008
7242
  }
7009
7243
  }
@@ -7019,7 +7253,7 @@ var GameVfx = (() => {
7019
7253
  piece.rx += piece.ax * dt;
7020
7254
  piece.ry += piece.ay * dt;
7021
7255
  piece.rz += piece.az * dt;
7022
- const groundHeight = this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5;
7256
+ const groundHeight = Math.max(this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5, this.resting.supportUnder(piece));
7023
7257
  if (piece.y >= groundHeight) return;
7024
7258
  piece.y = groundHeight;
7025
7259
  piece.vy *= -piece.bounce;
@@ -7657,7 +7891,6 @@ var GameVfx = (() => {
7657
7891
  var FIRE_FLICKER_SWAY = 0.25;
7658
7892
  var FIRE_FLICKER_JITTER = 0.08;
7659
7893
  var LENS_FADE = 0.16;
7660
- var FLOOR_NORMAL_Y = 0.9;
7661
7894
  function rotate2(q, v) {
7662
7895
  const [qx, qy, qz, qw] = q;
7663
7896
  const ix = qw * v[0] + qy * v[2] - qz * v[1];
@@ -7696,6 +7929,14 @@ var GameVfx = (() => {
7696
7929
  this.decals = new DecalPool(this.context);
7697
7930
  this.lights = new FlashLightPool(this.context);
7698
7931
  }
7932
+ /**
7933
+ * Turns on the touch of the debris pieces (a game's world; the Workshop page's recording has none): they pile on the pieces at rest under them, and the
7934
+ * upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
7935
+ */
7936
+ setDebrisContacts(obstacles) {
7937
+ if (obstacles) this.context.debrisContacts = { obstacles };
7938
+ else delete this.context.debrisContacts;
7939
+ }
7699
7940
  get random() {
7700
7941
  return this.context.random;
7701
7942
  }
@@ -7787,7 +8028,7 @@ var GameVfx = (() => {
7787
8028
  const [x, y, z] = this.place([recipe[0], recipe[1], recipe[2]]);
7788
8029
  const options = recipe[5];
7789
8030
  const normal = options?.n ? this.turn(options.n) : void 0;
7790
- const onFloor = !normal || normal[1] > FLOOR_NORMAL_Y;
8031
+ const onFloor = !normal;
7791
8032
  args = [x, onFloor ? this.context.groundAt(x, z) : y, z, recipe[3], recipe[4], normal ? { ...options, n: normal } : options];
7792
8033
  }
7793
8034
  this.context.trace?.("decal", args);
@@ -7908,6 +8149,7 @@ var GameVfx = (() => {
7908
8149
  });
7909
8150
  const core = {
7910
8151
  profile,
8152
+ confiner: enclosures,
7911
8153
  puffs: createPuffPool(profile.puffs),
7912
8154
  sparks: createSparkPool(profile.sparks),
7913
8155
  glows: createGlowPool(profile.glows),
@@ -8016,10 +8258,11 @@ var GameVfx = (() => {
8016
8258
  },
8017
8259
  fire(fireOptions) {
8018
8260
  const handle = ++handles.next;
8019
- const { point, offset, seed, radius, smokeColor, ...rest } = fireOptions;
8261
+ const { point, offset, seed, radius, height, smokeColor, ...rest } = fireOptions;
8020
8262
  addFire(core, streamOf(seed), {
8021
8263
  ...rest,
8022
8264
  r: radius,
8265
+ ...height !== void 0 ? { h: height } : {},
8023
8266
  x: point[0],
8024
8267
  y: point[1],
8025
8268
  z: point[2],
@@ -8047,6 +8290,9 @@ var GameVfx = (() => {
8047
8290
  enclose(id, enclosure) {
8048
8291
  enclosures.set(id, enclosure);
8049
8292
  },
8293
+ solid(id, query2) {
8294
+ enclosures.solid(id, query2);
8295
+ },
8050
8296
  enclosures: () => enclosures,
8051
8297
  stop(handle) {
8052
8298
  player?.stop(handle);