@adatechnology/game-terrain 0.2.3 → 0.3.1

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.
@@ -29,8 +29,10 @@ var GameTerrain = (() => {
29
29
  TERRAIN_PATTERNS: () => TERRAIN_PATTERNS,
30
30
  TERRAIN_PROFILES: () => TERRAIN_PROFILES,
31
31
  crackLines: () => crackLines,
32
+ createFootprints: () => createFootprints,
32
33
  createTerrain: () => createTerrain,
33
- createTerrainImpl: () => createTerrainImpl
34
+ createTerrainImpl: () => createTerrainImpl,
35
+ waterLift: () => waterLift
34
36
  });
35
37
 
36
38
  // src/catalog.ts
@@ -83,17 +85,18 @@ var GameTerrain = (() => {
83
85
  {
84
86
  id: "gravel",
85
87
  debris: "chips",
86
- rimShare: 0.3,
88
+ rimShare: 0.15,
87
89
  reposeDegrees: 38,
88
90
  color: [0.27, 0.25, 0.22],
89
- pattern: "stone",
91
+ pattern: "gravel",
90
92
  hits: {
91
93
  ballistic: { specificEnergy: 8e6, aspect: 0.4 },
92
94
  blunt: { specificEnergy: 8e6, aspect: 0.2, thresholdJoules: 200 },
93
95
  slash: { specificEnergy: 3e7, aspect: 0.3, thresholdJoules: 400 },
94
96
  explosive: { specificEnergy: 1e7, aspect: 0.35 }
95
97
  },
96
- fire: { maxScorch: 0.3, scorchPerSecond: 0.06 }
98
+ fire: { maxScorch: 0.3, scorchPerSecond: 0.06 },
99
+ scatters: true
97
100
  },
98
101
  {
99
102
  id: "asphalt",
@@ -177,8 +180,85 @@ var GameTerrain = (() => {
177
180
  explosive: { specificEnergy: 4e9, aspect: 0.14 }
178
181
  },
179
182
  fire: { maxScorch: 0.4, scorchPerSecond: 0.06 }
183
+ },
184
+ {
185
+ id: "mud",
186
+ debris: "clods",
187
+ rimShare: 0.15,
188
+ reposeDegrees: 18,
189
+ color: [0.11, 0.075, 0.04],
190
+ pattern: "mud",
191
+ hits: {
192
+ ballistic: { specificEnergy: 12e5, aspect: 0.7 },
193
+ blunt: { specificEnergy: 3e5, aspect: 0.3, thresholdJoules: 15 },
194
+ slash: { specificEnergy: 5e4, aspect: 0.5 },
195
+ explosive: { specificEnergy: 15e5, aspect: 0.4 }
196
+ },
197
+ fire: { maxScorch: 0.15, scorchPerSecond: 0.03 },
198
+ footing: { sink: 0.07, drag: 0.6, prints: true },
199
+ splash: "mud",
200
+ splats: true
201
+ },
202
+ {
203
+ id: "clay",
204
+ debris: "chips",
205
+ color: [0.47, 0.27, 0.14],
206
+ pattern: "clay",
207
+ hits: {
208
+ ballistic: { specificEnergy: 1e7, aspect: 0.2, minRadius: 0.03 },
209
+ blunt: { specificEnergy: 15e6, aspect: 0.15, thresholdJoules: 100 },
210
+ slash: { specificEnergy: 6e7, aspect: 0.3, thresholdJoules: 30 },
211
+ explosive: { specificEnergy: 8e6, aspect: 0.25 }
212
+ },
213
+ fire: { maxScorch: 0.35, scorchPerSecond: 0.05 },
214
+ cracks: 4
215
+ },
216
+ {
217
+ id: "snow",
218
+ debris: "dust",
219
+ rimShare: 0.4,
220
+ reposeDegrees: 38,
221
+ color: [0.82, 0.85, 0.88],
222
+ pattern: "snow",
223
+ hits: {
224
+ ballistic: { specificEnergy: 15e5, aspect: 1 },
225
+ blunt: { specificEnergy: 3e5, aspect: 0.3, thresholdJoules: 10 },
226
+ slash: { specificEnergy: 5e4, aspect: 0.6 },
227
+ explosive: { specificEnergy: 15e5, aspect: 0.5 }
228
+ },
229
+ fire: { maxScorch: 0, scorchPerSecond: 0, burnsAway: 0.015 },
230
+ footing: { sink: 0.08, drag: 0.7, prints: true }
231
+ },
232
+ {
233
+ id: "cobble",
234
+ debris: "blocks",
235
+ color: [0.2, 0.19, 0.18],
236
+ pattern: "cobble",
237
+ hits: {
238
+ ballistic: { specificEnergy: 25e7, aspect: 0.12, minRadius: 0.015 },
239
+ blunt: { specificEnergy: 5e7, aspect: 0.12, thresholdJoules: 250 },
240
+ slash: { specificEnergy: 2e9, aspect: 0.2, thresholdJoules: 1500 },
241
+ explosive: { specificEnergy: 15e6, aspect: 0.2 }
242
+ },
243
+ fire: { maxScorch: 0.4, scorchPerSecond: 0.06 },
244
+ units: { length: 0.3, width: 0.2, looseJoules: 4e3 }
245
+ },
246
+ {
247
+ id: "paver",
248
+ debris: "blocks",
249
+ color: [0.36, 0.33, 0.3],
250
+ pattern: "paver",
251
+ hits: {
252
+ ballistic: { specificEnergy: 15e7, aspect: 0.14, minRadius: 0.018 },
253
+ blunt: { specificEnergy: 4e7, aspect: 0.12, thresholdJoules: 150 },
254
+ slash: { specificEnergy: 1e9, aspect: 0.2, thresholdJoules: 800 },
255
+ explosive: { specificEnergy: 12e6, aspect: 0.2 }
256
+ },
257
+ fire: { maxScorch: 0.45, scorchPerSecond: 0.08 },
258
+ units: { length: 0.2, width: 0.2, looseJoules: 2500 }
180
259
  }
181
260
  ];
261
+ var WATER_BLOW_SHARE = { ballistic: 0.5, slash: 0.3, blunt: 0.5, explosive: 1 };
182
262
  var TERRAIN_PROFILES = [
183
263
  { id: "lawn", strata: [{ material: "turf", thickness: 0.05 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
184
264
  { id: "dirt", strata: [{ material: "soil", thickness: 1.8 }, { material: "stone", thickness: 0.5 }] },
@@ -188,7 +268,14 @@ var GameTerrain = (() => {
188
268
  { id: "suspended_slab", drop: 3, strata: [{ material: "concrete", thickness: 0.12, reinforcement: { material: "steel", cover: 0.03, spacing: 0.15, resistance: 4 } }] },
189
269
  { id: "tile_floor", strata: [{ material: "ceramic", thickness: 8e-3 }, { material: "mortar", thickness: 0.03 }, { material: "concrete", thickness: 0.1, reinforcement: { material: "steel", cover: 0.03, spacing: 0.15, resistance: 4 } }] },
190
270
  { id: "wood_floor", strata: [{ material: "wood_hard", thickness: 0.022 }, { material: "mortar", thickness: 0.03 }, { material: "concrete", thickness: 0.1, reinforcement: { material: "steel", cover: 0.03, spacing: 0.15, resistance: 4 } }] },
191
- { id: "stone_paving", strata: [{ material: "stone", thickness: 0.08 }, { material: "gravel", thickness: 0.2 }, { material: "soil", thickness: 1.2 }] }
271
+ { id: "stone_paving", strata: [{ material: "stone", thickness: 0.08 }, { material: "gravel", thickness: 0.2 }, { material: "soil", thickness: 1.2 }] },
272
+ { id: "mud", strata: [{ material: "mud", thickness: 0.5 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
273
+ { id: "gravel_bed", strata: [{ material: "gravel", thickness: 0.3 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
274
+ { id: "dry_clay", strata: [{ material: "clay", thickness: 0.35 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
275
+ { id: "snow", strata: [{ material: "snow", thickness: 0.3 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
276
+ { id: "cobblestone", strata: [{ material: "cobble", thickness: 0.12 }, { material: "sand", thickness: 0.06 }, { material: "gravel", thickness: 0.2 }, { material: "soil", thickness: 1.2 }] },
277
+ { id: "paver_floor", strata: [{ material: "paver", thickness: 0.08 }, { material: "sand", thickness: 0.05 }, { material: "gravel", thickness: 0.15 }, { material: "soil", thickness: 1.2 }] },
278
+ { id: "shallow_water", water: { liquid: "water", depth: 0.3, drag: 0.65, blowShare: WATER_BLOW_SHARE }, strata: [{ material: "mud", thickness: 0.15 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] }
192
279
  ];
193
280
  var DEFAULT_BAR_YIELD_JOULES = 24e5;
194
281
  var DEFAULT_PROFILE = "concrete_slab";
@@ -473,7 +560,8 @@ var GameTerrain = (() => {
473
560
  maxDebrisPerBlow: 36,
474
561
  maxSlideCellsPerFrame: 2500,
475
562
  maxBurningCells: 300,
476
- maxCracks: 120
563
+ maxCracks: 120,
564
+ maxDecals: 300
477
565
  };
478
566
  var GRAVITY = 9.81;
479
567
  var FINE_CELLS = 1.5;
@@ -485,14 +573,20 @@ var GameTerrain = (() => {
485
573
  var FLAME_MINIMUM = 200;
486
574
  var FLAME_REACH = 0.6;
487
575
  var BLAST_HEIGHT_REACH = 0.35;
576
+ var BLAST_SOOT_REACH = 1.2;
577
+ var BLAST_SOOT = 0.9;
488
578
  var THROW_SHARE = 0.02;
489
579
  var FIRE_CELL = 0.5;
490
580
  var FIRE_SECONDS = 7;
491
581
  var FIRE_SPREAD_PER_SECOND = 0.35;
492
582
  var SLIDE_SHARE = 0.4;
493
583
  var SLIDE_EPSILON = 2e-3;
494
- var PIECE_RADIUS = { clods: 0.045, chips: 0.022, shards: 0.028, splinters: 0.02, dust: 0.012 };
584
+ var PIECE_RADIUS = { clods: 0.045, chips: 0.022, shards: 0.028, splinters: 0.02, dust: 0.012, blocks: 0.08 };
495
585
  var MAX_PIECE_SPEED = { explosive: 14, ballistic: 5, blunt: 2.5, slash: 1.5 };
586
+ var BANK_CELLS = 6;
587
+ var CRACK_MIN_RADIUS = 0.18;
588
+ var RIPPLE_SECONDS = 1.6;
589
+ var WATER_MINIMUM = 0.02;
496
590
  var clampIndex = (value, max) => Math.max(0, Math.min(max, value));
497
591
  var sparse = (array) => {
498
592
  const entries = [];
@@ -547,10 +641,12 @@ var GameTerrain = (() => {
547
641
  }
548
642
  const indexOfProfile = new Map(profileList.map((profile, index) => [profile.id, index]));
549
643
  const maxDepthOf = profileList.map(totalThickness);
550
- const base = new Float32Array(vertexCount);
644
+ const surface = new Float32Array(vertexCount);
551
645
  if (options.baseHeight) {
552
- for (let row = 0; row <= rows; row++) for (let column = 0; column <= columns; column++) base[row * stride + column] = options.baseHeight(x0 + column * cellSize, z0 + row * cellSize);
646
+ for (let row = 0; row <= rows; row++) for (let column = 0; column <= columns; column++) surface[row * stride + column] = options.baseHeight(x0 + column * cellSize, z0 + row * cellSize);
553
647
  }
648
+ const base = Float32Array.from(surface);
649
+ const hasWater = profileList.some((profile) => profile.water);
554
650
  const dug = new Float32Array(vertexCount);
555
651
  const loose = new Float32Array(vertexCount);
556
652
  const scorch = new Float32Array(vertexCount);
@@ -561,6 +657,10 @@ var GameTerrain = (() => {
561
657
  const dirty = /* @__PURE__ */ new Set();
562
658
  const marks = createMarkStore(budget);
563
659
  const cracks = createCrackStore();
660
+ const decalList = [];
661
+ let decalSerial = 0;
662
+ let decalsVersion = 0;
663
+ const unitDamage = /* @__PURE__ */ new Map();
564
664
  const debrisStore = createDebrisStore(() => budget.maxDebris);
565
665
  const sliding = /* @__PURE__ */ new Set();
566
666
  const burning = /* @__PURE__ */ new Map();
@@ -597,16 +697,18 @@ var GameTerrain = (() => {
597
697
  const row1 = clampIndex(Math.round((zz1 - z0) / cellSize), rows);
598
698
  for (let row = row0; row <= row1; row++) profileIndex.fill(index, row * stride + column0, row * stride + column1 + 1);
599
699
  }
700
+ if (hasWater) layBeds();
600
701
  for (let chunkZ = 0; chunkZ < chunksZ; chunkZ++) {
601
702
  for (let chunkX = 0; chunkX < chunksX; chunkX++) {
602
703
  const chunk2 = chunkZ * chunksX + chunkX;
603
704
  const first = profileIndex[chunkZ * chunkCells * stride + chunkX * chunkCells];
705
+ const firstDrop = surface[chunkZ * chunkCells * stride + chunkX * chunkCells] - base[chunkZ * chunkCells * stride + chunkX * chunkCells];
604
706
  let isMixed = 0;
605
707
  const lastRow = Math.min(rows, (chunkZ + 1) * chunkCells);
606
708
  const lastColumn = Math.min(columns, (chunkX + 1) * chunkCells);
607
709
  for (let row = chunkZ * chunkCells; row <= lastRow && !isMixed; row++) {
608
710
  for (let column = chunkX * chunkCells; column <= lastColumn; column++) {
609
- if (profileIndex[row * stride + column] !== first) {
711
+ if (profileIndex[row * stride + column] !== first || surface[row * stride + column] - base[row * stride + column] !== firstDrop) {
610
712
  isMixed = 1;
611
713
  break;
612
714
  }
@@ -617,11 +719,39 @@ var GameTerrain = (() => {
617
719
  }
618
720
  }
619
721
  }
722
+ function layBeds() {
723
+ const steps = new Uint8Array(vertexCount);
724
+ for (let index = 0; index < vertexCount; index++) steps[index] = profileList[profileIndex[index]].water ? BANK_CELLS : 0;
725
+ for (let pass = 0; pass < BANK_CELLS; pass++) {
726
+ for (let row = 0; row <= rows; row++) {
727
+ for (let column = 0; column <= columns; column++) {
728
+ const index = row * stride + column;
729
+ if (steps[index] === 0) continue;
730
+ const lowest = Math.min(column > 0 ? steps[index - 1] : BANK_CELLS, column < columns ? steps[index + 1] : BANK_CELLS, row > 0 ? steps[index - stride] : BANK_CELLS, row < rows ? steps[index + stride] : BANK_CELLS);
731
+ steps[index] = Math.min(steps[index], lowest + 1);
732
+ }
733
+ }
734
+ }
735
+ for (let index = 0; index < vertexCount; index++) base[index] = surface[index] - (profileList[profileIndex[index]].water?.depth ?? 0) * (steps[index] / BANK_CELLS);
736
+ }
620
737
  const vertexHeight = (column, row) => {
621
738
  const index = row * stride + column;
622
739
  return base[index] - dug[index] + loose[index];
623
740
  };
624
741
  const contains = (x, z) => x >= x0 && x <= x1 && z >= z0 && z <= z1;
742
+ function addDecal(spec) {
743
+ if (decalList.length >= budget.maxDecals) decalList.shift();
744
+ decalList.push({ ...spec, id: ++decalSerial, age: 0 });
745
+ decalsVersion++;
746
+ }
747
+ function clearDecalsInside(x, z, radius) {
748
+ const before = decalList.length;
749
+ for (let i = before - 1; i >= 0; i--) {
750
+ const decal = decalList[i];
751
+ if (decal.kind !== "ripple" && decal.kind !== "splat" && decal.kind !== "crack" && Math.hypot(decal.x - x, decal.z - z) < radius) decalList.splice(i, 1);
752
+ }
753
+ if (decalList.length !== before) decalsVersion++;
754
+ }
625
755
  function heightAt(x, z) {
626
756
  if (!contains(x, z)) return options.baseHeight?.(x, z) ?? 0;
627
757
  const fx = Math.max(0, Math.min(columns - 1e-6, (x - x0) / cellSize));
@@ -639,6 +769,42 @@ var GameTerrain = (() => {
639
769
  const row = clampIndex(Math.round((z - z0) / cellSize), rows);
640
770
  return { column, row, index: row * stride + column };
641
771
  };
772
+ function waterAt(x, z) {
773
+ if (!hasWater || !contains(x, z)) return null;
774
+ const { index } = vertexOf(x, z);
775
+ const water = profileList[profileIndex[index]].water;
776
+ if (!water) return null;
777
+ const level = surface[index];
778
+ const depth = level - heightAt(x, z);
779
+ return depth > WATER_MINIMUM ? { liquid: water.liquid, level, depth } : null;
780
+ }
781
+ const exposedAt = (x, z) => {
782
+ const { column, row } = vertexOf(x, z);
783
+ return vertexMaterial(column, row);
784
+ };
785
+ const footAt = (x, z) => {
786
+ if (!contains(x, z)) return heightAt(x, z);
787
+ return heightAt(x, z) - (exposedAt(x, z).footing?.sink ?? 0);
788
+ };
789
+ function walkFactorAt(x, z) {
790
+ if (!contains(x, z)) return 1;
791
+ const water = waterAt(x, z) ? profileList[profileIndex[vertexOf(x, z).index]].water : null;
792
+ return Math.min(water?.drag ?? 1, exposedAt(x, z).footing?.drag ?? 1);
793
+ }
794
+ function ripple(x, z, radius) {
795
+ addDecal({ kind: "ripple", x, z, radius, angle: 0, material: exposedAt(x, z).id });
796
+ }
797
+ function press(spec) {
798
+ if (!contains(spec.x, spec.z)) return false;
799
+ if (waterAt(spec.x, spec.z)) {
800
+ ripple(spec.x, spec.z, spec.radius * 2);
801
+ return true;
802
+ }
803
+ const material = exposedAt(spec.x, spec.z);
804
+ if (!material.footing?.prints) return false;
805
+ addDecal({ kind: spec.kind ?? "print", x: spec.x, z: spec.z, radius: spec.radius, angle: spec.angle ?? 0, material: material.id });
806
+ return true;
807
+ }
642
808
  function vertexMaterial(column, row) {
643
809
  const index = row * stride + column;
644
810
  return materials.get(stratumMaterialAtDepth(profileList[profileIndex[index]], dug[index]));
@@ -702,6 +868,7 @@ var GameTerrain = (() => {
702
868
  }
703
869
  }
704
870
  marks.removeInside(x, z, radius);
871
+ clearDecalsInside(x, z, radius);
705
872
  emitDeform(x, z, reach);
706
873
  }
707
874
  function throwPieces(spec) {
@@ -731,9 +898,15 @@ var GameTerrain = (() => {
731
898
  const { x, z } = spec;
732
899
  const start = columnAt(x, z);
733
900
  const profile = profileMap.get(start.profile);
901
+ const waterHere = waterAt(x, z);
902
+ const waterResult = waterHere ? { water: { liquid: waterHere.liquid, level: waterHere.level } } : {};
903
+ if (waterHere) ripple(x, z, Math.min(1.5, 0.15 + Math.cbrt(spec.energy) / 40));
734
904
  const removed = [];
735
905
  const point = [x, heightAt(x, z), z];
736
- let energy = spec.energy;
906
+ const startLayer = stratumAtDepth(profile, start.depth);
907
+ if (start.loose <= 0 && materials.get(startLayer.stratum.material).units) return strikeUnits(blow, spec, startLayer, profile, point);
908
+ const blowEnergy = spec.energy * (waterHere ? profile.water?.blowShare[blow] ?? 1 : 1);
909
+ let energy = blowEnergy;
737
910
  let depth = start.depth;
738
911
  let radius = 0;
739
912
  let carved = 0;
@@ -791,7 +964,7 @@ var GameTerrain = (() => {
791
964
  }
792
965
  let collapsed = loadBars(blow, spec.energy, x, z, profile);
793
966
  const crack = crackAround(blow, spec.energy, x, z, start.loose > 0 ? void 0 : firstMaterial);
794
- const extra = { ...crack ? { crack } : {}, ...breached ? { breached } : {} };
967
+ const extra = { ...crack ? { crack } : {}, ...breached ? { breached } : {}, ...waterResult };
795
968
  if (radius <= 0) return { point, radius: 0, depth: 0, totalDepth: columnAt(x, z).depth, removed: [], exposed: start.material, atLimit: start.remaining <= 1e-6, rebarExposed: rebarShowing(profile, start.depth), collapsed, fine: true, ...extra };
796
969
  if (firstMaterial.reposeDegrees === void 0 && start.loose <= 0) radius *= 1 + RIGID_WIDENING * (start.depth / maxDepthOfProfile(profile));
797
970
  const volumeTotal = removed.reduce((sum, entry) => sum + entry.volume, 0);
@@ -801,7 +974,8 @@ var GameTerrain = (() => {
801
974
  const rimShare = materials.get(removed[0].material).rimShare ?? 0;
802
975
  stampBowl(x, z, radius, carved, volumeTotal * rimShare);
803
976
  }
804
- let quota = budget.maxDebrisPerBlow;
977
+ if (firstMaterial.cracks) addDecal({ kind: "crack", x, z, radius: Math.max(CRACK_MIN_RADIUS, radius * firstMaterial.cracks), angle: random() * 6.283, material: firstMaterial.id });
978
+ let quota = waterHere && blow !== "explosive" ? 0 : budget.maxDebrisPerBlow;
805
979
  for (const entry of removed) {
806
980
  const material = materials.get(entry.material);
807
981
  const thrown = entry.volume * (1 - (fine ? 0 : material.rimShare ?? 0));
@@ -821,6 +995,67 @@ var GameTerrain = (() => {
821
995
  const scale = Math.cbrt(energy / CRACK_REFERENCE_JOULES);
822
996
  return cracks.add({ x, z, reach: response.reach * scale, width: response.width * scale, material: material.id, seed: Math.floor(random() * 2 ** 31) }, budget.maxCracks);
823
997
  }
998
+ function strikeUnits(blow, spec, layer, profile, point) {
999
+ const { x, z, energy } = spec;
1000
+ const material = materials.get(layer.stratum.material);
1001
+ const units = material.units;
1002
+ const response = material.hits[blow];
1003
+ const bottom = layer.top + layer.stratum.thickness;
1004
+ const miss = { point, radius: 0, depth: 0, totalDepth: layer.top, removed: [], exposed: material.id, atLimit: false, rebarExposed: false, collapsed: false, fine: true };
1005
+ if (!response || energy < (response.thresholdJoules ?? 0)) return miss;
1006
+ const reach = Math.max(spec.contactRadius ?? 0, response.minRadius ?? 0, Math.cbrt(2 * energy / response.specificEnergy / (Math.PI * response.aspect)));
1007
+ const rowFirst = Math.floor((z - reach) / units.width);
1008
+ const rowLast = Math.floor((z + reach) / units.width);
1009
+ let loosened = 0;
1010
+ for (let row = rowFirst; row <= rowLast; row++) {
1011
+ const shift = Math.abs(row % 2) * cellSize;
1012
+ const unitFirst = Math.floor((x - reach - shift) / units.length);
1013
+ const unitLast = Math.floor((x + reach - shift) / units.length);
1014
+ for (let unit = unitFirst; unit <= unitLast; unit++) {
1015
+ const minX = unit * units.length + shift;
1016
+ const minZ = row * units.width;
1017
+ const near = Math.hypot(Math.max(minX - x, 0, x - minX - units.length), Math.max(minZ - z, 0, z - minZ - units.width));
1018
+ if (near > reach) continue;
1019
+ const key = `${unit}:${row}`;
1020
+ const taken = (unitDamage.get(key) ?? 0) + energy * (1 - (near / (reach + 1e-6)) ** 2);
1021
+ unitDamage.set(key, taken);
1022
+ if (taken >= units.looseJoules && liftUnit(minX, minZ, units, bottom, material, profile)) {
1023
+ loosened++;
1024
+ const speed = Math.min(MAX_PIECE_SPEED[blow], Math.sqrt(2 * energy * THROW_SHARE / Math.max(1, loosened * 15)));
1025
+ const angle = random() * 6.283;
1026
+ debrisStore.throwPiece({ material: material.id, kind: "blocks", radius: units.length / 2, position: [minX + units.length / 2, point[1] + 0.05, minZ + units.width / 2], velocity: [Math.cos(angle) * speed * 0.6, speed * (0.5 + random() * 0.5), Math.sin(angle) * speed * 0.6], spin: [(random() - 0.5) * 8, (random() - 0.5) * 8, (random() - 0.5) * 8] });
1027
+ }
1028
+ }
1029
+ }
1030
+ if (loosened === 0) {
1031
+ addDecal({ kind: "crack", x, z, radius: Math.max(0.05, reach * 2), angle: random() * 6.283, material: material.id });
1032
+ throwPieces({ x, y: point[1], z, volume: 1e-5, material: { ...material, debris: "chips" }, energy, ...spec.direction ? { direction: spec.direction } : {}, quota: 3, bowlRadius: 0.02, blow });
1033
+ return { ...miss, radius: Math.max(0.02, Math.min(reach, 0.06)) };
1034
+ }
1035
+ emitDeform(x, z, reach + units.length);
1036
+ clearDecalsInside(x, z, reach);
1037
+ const volume = loosened * units.length * units.width * layer.stratum.thickness;
1038
+ const after = columnAt(x, z);
1039
+ return { point, radius: reach, depth: layer.stratum.thickness, totalDepth: after.depth, removed: [{ material: material.id, volume }], exposed: after.material, atLimit: false, rebarExposed: false, collapsed: false, fine: false };
1040
+ }
1041
+ function liftUnit(minX, minZ, units, bottom, material, profile) {
1042
+ const column0 = clampIndex(Math.round((minX - x0) / cellSize), columns);
1043
+ const column1 = clampIndex(Math.round((minX + units.length - x0) / cellSize), columns);
1044
+ const row0 = clampIndex(Math.round((minZ - z0) / cellSize), rows);
1045
+ const row1 = clampIndex(Math.round((minZ + units.width - z0) / cellSize), rows);
1046
+ let lifted = false;
1047
+ for (let row = row0; row <= row1; row++) {
1048
+ for (let column = column0; column <= column1; column++) {
1049
+ const index = row * stride + column;
1050
+ if (profileList[profileIndex[index]].id !== profile.id || dug[index] >= bottom) continue;
1051
+ if (materials.get(stratumAtDepth(profile, dug[index]).stratum.material) !== material) continue;
1052
+ dug[index] = bottom;
1053
+ lifted = true;
1054
+ touchVertex(column, row);
1055
+ }
1056
+ }
1057
+ return lifted;
1058
+ }
824
1059
  function loadBars(blow, energy, x, z, profile) {
825
1060
  const bars = profile.strata.find((stratum) => stratum.reinforcement);
826
1061
  if (!bars?.reinforcement) return false;
@@ -900,10 +1135,31 @@ var GameTerrain = (() => {
900
1135
  const column1 = clampIndex(Math.ceil((spec.x + spec.radius - x0) / cellSize), columns);
901
1136
  const row0 = clampIndex(Math.floor((spec.z - spec.radius - z0) / cellSize), rows);
902
1137
  const row1 = clampIndex(Math.ceil((spec.z + spec.radius - z0) / cellSize), rows);
1138
+ let melted = false;
903
1139
  for (let row = row0; row <= row1; row++) {
904
1140
  for (let column = column0; column <= column1; column++) {
905
1141
  if (Math.hypot(x0 + column * cellSize - spec.x, z0 + row * cellSize - spec.z) > spec.radius) continue;
906
- burnVertex(column, row, spec.seconds);
1142
+ if (hasWater && base[row * stride + column] < surface[row * stride + column]) continue;
1143
+ melted = burnVertex(column, row, spec.seconds) || melted;
1144
+ }
1145
+ }
1146
+ if (melted) emitDeform(spec.x, spec.z, spec.radius);
1147
+ }
1148
+ function soot(x, z, radius) {
1149
+ if (radius <= 0) return;
1150
+ const column0 = clampIndex(Math.floor((x - radius - x0) / cellSize), columns);
1151
+ const column1 = clampIndex(Math.ceil((x + radius - x0) / cellSize), columns);
1152
+ const row0 = clampIndex(Math.floor((z - radius - z0) / cellSize), rows);
1153
+ const row1 = clampIndex(Math.ceil((z + radius - z0) / cellSize), rows);
1154
+ for (let row = row0; row <= row1; row++) {
1155
+ for (let column = column0; column <= column1; column++) {
1156
+ const distance = Math.hypot(x0 + column * cellSize - x, z0 + row * cellSize - z);
1157
+ const response = distance < radius ? vertexMaterial(column, row).fire : void 0;
1158
+ if (!response) continue;
1159
+ const index = row * stride + column;
1160
+ const before = scorch[index];
1161
+ scorch[index] = Math.max(before, response.maxScorch * BLAST_SOOT * Math.sqrt(1 - distance / radius));
1162
+ if (scorch[index] !== before) touchVertex(column, row);
907
1163
  }
908
1164
  }
909
1165
  }
@@ -911,12 +1167,13 @@ var GameTerrain = (() => {
911
1167
  const index = row * stride + column;
912
1168
  const material = vertexMaterial(column, row);
913
1169
  const response = material.fire;
914
- if (!response) return;
1170
+ if (!response) return false;
915
1171
  const before = scorch[index];
916
1172
  scorch[index] = Math.max(before, Math.min(response.maxScorch, before + response.scorchPerSecond * seconds));
917
1173
  if (response.burnsAway) removeFromVertex(index, response.burnsAway * seconds);
918
1174
  if (scorch[index] !== before || response.burnsAway) touchVertex(column, row);
919
1175
  if (response.flammable) ignite(x0 + column * cellSize, z0 + row * cellSize);
1176
+ return (response.burnsAway ?? 0) > 0;
920
1177
  }
921
1178
  const fireKey = (x, z) => Math.floor((z - z0) / FIRE_CELL) * 65536 + Math.floor((x - x0) / FIRE_CELL);
922
1179
  function ignite(x, z) {
@@ -987,7 +1244,8 @@ var GameTerrain = (() => {
987
1244
  }
988
1245
  function settle(piece) {
989
1246
  const material = materials.get(piece.material);
990
- if (!material || material.reposeDegrees === void 0) return false;
1247
+ if (!material || material.reposeDegrees === void 0 || material.scatters) return false;
1248
+ if (material.splats && contains(piece.position[0], piece.position[2]) && !waterAt(piece.position[0], piece.position[2])) addDecal({ kind: "splat", x: piece.position[0], z: piece.position[2], radius: piece.radius * 2.6, angle: piece.id * 2.399, material: material.id });
991
1249
  if (!contains(piece.position[0], piece.position[2])) return true;
992
1250
  const { index, column, row } = vertexOf(piece.position[0], piece.position[2]);
993
1251
  addToVertex(index, 4 / 3 * Math.PI * piece.radius ** 3 / (cellSize * cellSize), false);
@@ -1010,7 +1268,9 @@ var GameTerrain = (() => {
1010
1268
  const above = Math.max(0, y - heightAt(x, z));
1011
1269
  const reach = (hit.radius ?? 1) * BLAST_HEIGHT_REACH;
1012
1270
  if (above >= reach) return null;
1013
- return strike("explosive", { x, z, energy: hit.energy * (1 - above / reach) ** 2 });
1271
+ const share = (1 - above / reach) ** 2;
1272
+ soot(x, z, BLAST_SOOT_REACH * Math.cbrt(hit.energy * share / 1e6));
1273
+ return strike("explosive", { x, z, energy: hit.energy * share });
1014
1274
  }
1015
1275
  case "fire":
1016
1276
  case "heat":
@@ -1061,6 +1321,9 @@ var GameTerrain = (() => {
1061
1321
  touched.fill(0);
1062
1322
  marks.clear();
1063
1323
  cracks.clear();
1324
+ decalList.length = 0;
1325
+ decalsVersion++;
1326
+ unitDamage.clear();
1064
1327
  debrisStore.clear();
1065
1328
  sliding.clear();
1066
1329
  burning.clear();
@@ -1095,6 +1358,15 @@ var GameTerrain = (() => {
1095
1358
  reset();
1096
1359
  },
1097
1360
  heightAt,
1361
+ footAt,
1362
+ walkFactorAt,
1363
+ waterAt,
1364
+ press,
1365
+ ripple,
1366
+ decals: () => decalList,
1367
+ get decalsVersion() {
1368
+ return decalsVersion;
1369
+ },
1098
1370
  vertexHeight,
1099
1371
  vertexMaterial,
1100
1372
  columnAt,
@@ -1111,6 +1383,14 @@ var GameTerrain = (() => {
1111
1383
  debrisStore.update(dt, { heightAt, gravity, settle });
1112
1384
  updateSlides();
1113
1385
  updateFire(dt);
1386
+ for (let i = decalList.length - 1; i >= 0; i--) {
1387
+ const decal = decalList[i];
1388
+ decal.age += dt;
1389
+ if (decal.kind === "ripple" && decal.age > RIPPLE_SECONDS) {
1390
+ decalList.splice(i, 1);
1391
+ decalsVersion++;
1392
+ }
1393
+ }
1114
1394
  },
1115
1395
  get dirtyChunkCount() {
1116
1396
  return dirty.size;
@@ -1142,7 +1422,7 @@ var GameTerrain = (() => {
1142
1422
  stats: () => ({ marks: marks.list.length, debris: debrisStore.list.length, debrisMoving: debrisStore.list.filter((piece) => !piece.atRest).length, dirtyChunks: dirty.size, burning: burning.size }),
1143
1423
  reset,
1144
1424
  serialize() {
1145
- return { layout: currentLayout, dug: sparse(dug), loose: sparse(loose), scorch: sparse(scorch), barBend: sparse(barBend), marks: marks.list.map((mark) => ({ ...mark })), cracks: cracks.list.map((crack) => ({ ...crack })) };
1425
+ return { layout: currentLayout, dug: sparse(dug), loose: sparse(loose), scorch: sparse(scorch), barBend: sparse(barBend), marks: marks.list.map((mark) => ({ ...mark })), cracks: cracks.list.map((crack) => ({ ...crack })), decals: decalList.filter((decal) => decal.kind !== "ripple").map((decal) => ({ ...decal })) };
1146
1426
  },
1147
1427
  load(snapshot) {
1148
1428
  currentLayout = snapshot.layout;
@@ -1153,6 +1433,8 @@ var GameTerrain = (() => {
1153
1433
  fillSparse(barBend, snapshot.barBend ?? []);
1154
1434
  marks.load(snapshot.marks);
1155
1435
  cracks.load(snapshot.cracks ?? []);
1436
+ decalList.push(...(snapshot.decals ?? []).map((decal) => ({ ...decal })));
1437
+ decalSerial = decalList.reduce((highest, decal) => Math.max(highest, decal.id), decalSerial);
1156
1438
  for (let chunkIndex = 0; chunkIndex < touched.length; chunkIndex++) markChunk(chunkIndex);
1157
1439
  }
1158
1440
  };
@@ -1240,7 +1522,57 @@ var GameTerrain = (() => {
1240
1522
  }
1241
1523
 
1242
1524
  // src/types.ts
1243
- var TERRAIN_PATTERNS = ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone"];
1525
+ var TERRAIN_PATTERNS = ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone", "mud", "gravel", "clay", "snow", "cobble", "paver"];
1526
+
1527
+ // src/footprints.ts
1528
+ var STRIDE = 0.72;
1529
+ var FOOT_LENGTH = 0.15;
1530
+ var FOOT_APART = 0.11;
1531
+ function createFootprints(terrain, options = {}) {
1532
+ const stride = options.stride ?? STRIDE;
1533
+ const footLength = options.footLength ?? FOOT_LENGTH;
1534
+ let lastX = null;
1535
+ let lastZ = 0;
1536
+ let side = 1;
1537
+ return {
1538
+ update(x, z) {
1539
+ if (lastX === null) {
1540
+ lastX = x;
1541
+ lastZ = z;
1542
+ return;
1543
+ }
1544
+ const dx = x - lastX;
1545
+ const dz = z - lastZ;
1546
+ const walked = Math.hypot(dx, dz);
1547
+ if (walked < stride) return;
1548
+ lastX = x;
1549
+ lastZ = z;
1550
+ if (walked > stride * 3) return;
1551
+ const angle = Math.atan2(dx, dz);
1552
+ side = -side;
1553
+ terrain.press({ x: x + Math.cos(angle) * FOOT_APART * side, z: z - Math.sin(angle) * FOOT_APART * side, radius: footLength, angle });
1554
+ },
1555
+ reset() {
1556
+ lastX = null;
1557
+ }
1558
+ };
1559
+ }
1560
+
1561
+ // src/buoyancy.ts
1562
+ var GRAVITY2 = 9.81;
1563
+ var WATER_DRAG = 9;
1564
+ var MAX_LIFT_WEIGHTS = 1.6;
1565
+ function waterLift(params) {
1566
+ const density = params.liquidDensity ?? 1e3;
1567
+ const submerged = Math.max(0, Math.min(1, params.submerged));
1568
+ const mass = Math.max(1e-6, params.mass);
1569
+ const gravity = params.gravity ?? GRAVITY2;
1570
+ return {
1571
+ acceleration: Math.min(MAX_LIFT_WEIGHTS * gravity, density * params.volume * submerged * gravity / mass),
1572
+ drag: WATER_DRAG * submerged,
1573
+ floats: mass / Math.max(1e-9, params.volume) < density
1574
+ };
1575
+ }
1244
1576
  return __toCommonJS(index_exports);
1245
1577
  })();
1246
1578
  //# sourceMappingURL=index.global.js.map