@adatechnology/game-terrain 0.8.1 → 0.9.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.
@@ -33,10 +33,14 @@ var GameTerrain = (() => {
33
33
  TERRAIN_PATTERNS: () => TERRAIN_PATTERNS,
34
34
  TERRAIN_PROFILES: () => TERRAIN_PROFILES,
35
35
  VOID_MIN_DEPTH: () => VOID_MIN_DEPTH,
36
+ blendHeights: () => blendHeights,
37
+ cellCoordinate: () => cellCoordinate,
36
38
  crackLines: () => crackLines,
37
39
  createFootprints: () => createFootprints,
38
40
  createTerrain: () => createTerrain,
39
41
  createTerrainImpl: () => createTerrainImpl,
42
+ heightPatchGrid: () => heightPatchGrid,
43
+ samePatch: () => samePatch,
40
44
  waterLift: () => waterLift
41
45
  });
42
46
 
@@ -44,6 +48,9 @@ var GameTerrain = (() => {
44
48
  var TERRAIN_MATERIALS = [
45
49
  {
46
50
  id: "turf",
51
+ rolling: 0.15,
52
+ rollingDamping: 1.5,
53
+ dig: { effort: 1.3 },
47
54
  debris: "clods",
48
55
  rimShare: 0.25,
49
56
  reposeDegrees: 55,
@@ -59,6 +66,9 @@ var GameTerrain = (() => {
59
66
  },
60
67
  {
61
68
  id: "soil",
69
+ rolling: 0.08,
70
+ rollingDamping: 0.6,
71
+ dig: { effort: 1 },
62
72
  debris: "clods",
63
73
  rimShare: 0.35,
64
74
  reposeDegrees: 40,
@@ -74,6 +84,9 @@ var GameTerrain = (() => {
74
84
  },
75
85
  {
76
86
  id: "sand",
87
+ rolling: 0.3,
88
+ rollingDamping: 2,
89
+ dig: { effort: 0.8 },
77
90
  debris: "dust",
78
91
  rimShare: 0.5,
79
92
  reposeDegrees: 33,
@@ -89,6 +102,9 @@ var GameTerrain = (() => {
89
102
  },
90
103
  {
91
104
  id: "gravel",
105
+ rolling: 0.08,
106
+ rollingDamping: 1,
107
+ dig: { effort: 1.6 },
92
108
  debris: "chips",
93
109
  rimShare: 0.15,
94
110
  reposeDegrees: 38,
@@ -105,6 +121,8 @@ var GameTerrain = (() => {
105
121
  },
106
122
  {
107
123
  id: "asphalt",
124
+ rolling: 0.015,
125
+ rollingDamping: 0.35,
108
126
  debris: "chips",
109
127
  color: [0.05, 0.05, 0.055],
110
128
  pattern: "asphalt",
@@ -119,6 +137,8 @@ var GameTerrain = (() => {
119
137
  },
120
138
  {
121
139
  id: "concrete",
140
+ rolling: 0.015,
141
+ rollingDamping: 0.3,
122
142
  debris: "chips",
123
143
  color: [0.33, 0.33, 0.31],
124
144
  pattern: "concrete",
@@ -134,6 +154,7 @@ var GameTerrain = (() => {
134
154
  },
135
155
  {
136
156
  id: "mortar",
157
+ rollingDamping: 0.3,
137
158
  debris: "chips",
138
159
  color: [0.42, 0.4, 0.36],
139
160
  pattern: "plain",
@@ -147,6 +168,8 @@ var GameTerrain = (() => {
147
168
  },
148
169
  {
149
170
  id: "ceramic",
171
+ rolling: 8e-3,
172
+ rollingDamping: 0.1,
150
173
  debris: "shards",
151
174
  color: [0.72, 0.7, 0.66],
152
175
  pattern: "tile",
@@ -161,6 +184,8 @@ var GameTerrain = (() => {
161
184
  },
162
185
  {
163
186
  id: "wood_hard",
187
+ rolling: 0.01,
188
+ rollingDamping: 0.12,
164
189
  debris: "splinters",
165
190
  color: [0.3, 0.16, 0.07],
166
191
  pattern: "planks",
@@ -174,6 +199,8 @@ var GameTerrain = (() => {
174
199
  },
175
200
  {
176
201
  id: "stone",
202
+ rolling: 0.015,
203
+ rollingDamping: 0.3,
177
204
  debris: "chips",
178
205
  color: [0.23, 0.22, 0.2],
179
206
  pattern: "stone",
@@ -188,6 +215,10 @@ var GameTerrain = (() => {
188
215
  },
189
216
  {
190
217
  id: "mud",
218
+ rolling: 0.3,
219
+ rollingDamping: 3,
220
+ // the shovel lifts it, and the hole fills in behind the blade
221
+ dig: { effort: 1.4, closes: true },
191
222
  debris: "clods",
192
223
  rimShare: 0.15,
193
224
  reposeDegrees: 18,
@@ -206,6 +237,9 @@ var GameTerrain = (() => {
206
237
  },
207
238
  {
208
239
  id: "clay",
240
+ rolling: 0.05,
241
+ rollingDamping: 0.4,
242
+ dig: { effort: 2.2 },
209
243
  debris: "chips",
210
244
  color: [0.47, 0.27, 0.14],
211
245
  pattern: "clay",
@@ -218,8 +252,27 @@ var GameTerrain = (() => {
218
252
  fire: { maxScorch: 0.35, scorchPerSecond: 0.05 },
219
253
  cracks: 4
220
254
  },
255
+ {
256
+ // laterite, a soil baked hard (piçarra): no shovel goes in; only a heavy blow or a charge sinks or cracks it
257
+ id: "laterite",
258
+ rolling: 0.05,
259
+ rollingDamping: 0.4,
260
+ debris: "chips",
261
+ rimShare: 0.2,
262
+ color: [0.36, 0.17, 0.08],
263
+ pattern: "soil",
264
+ hits: {
265
+ ballistic: { specificEnergy: 5e7, aspect: 0.2, thresholdJoules: 200 },
266
+ blunt: { specificEnergy: 8e7, aspect: 0.1, thresholdJoules: 600 },
267
+ slash: { specificEnergy: 2e8, aspect: 0.1, thresholdJoules: 400 },
268
+ explosive: { specificEnergy: 3e8, aspect: 0.18 }
269
+ }
270
+ },
221
271
  {
222
272
  id: "snow",
273
+ rolling: 0.1,
274
+ rollingDamping: 1.2,
275
+ dig: { effort: 0.6 },
223
276
  debris: "dust",
224
277
  rimShare: 0.4,
225
278
  reposeDegrees: 38,
@@ -236,6 +289,8 @@ var GameTerrain = (() => {
236
289
  },
237
290
  {
238
291
  id: "cobble",
292
+ rolling: 0.03,
293
+ rollingDamping: 0.6,
239
294
  debris: "blocks",
240
295
  color: [0.2, 0.19, 0.18],
241
296
  pattern: "cobble",
@@ -250,6 +305,8 @@ var GameTerrain = (() => {
250
305
  },
251
306
  {
252
307
  id: "paver",
308
+ rolling: 0.015,
309
+ rollingDamping: 0.3,
253
310
  debris: "blocks",
254
311
  color: [0.36, 0.33, 0.3],
255
312
  pattern: "paver",
@@ -280,6 +337,10 @@ var GameTerrain = (() => {
280
337
  { id: "snow", strata: [{ material: "snow", thickness: 0.3 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
281
338
  { id: "cobblestone", strata: [{ material: "cobble", thickness: 0.12 }, { material: "sand", thickness: 0.06 }, { material: "gravel", thickness: 0.2 }, { material: "soil", thickness: 1.2 }] },
282
339
  // rock at the surface (an outcrop, a quarry floor): a blast only spalls it and a shot chips it
340
+ // a yard as it is dug: topsoil, the clay under it, rock deep down
341
+ { id: "yard", strata: [{ material: "soil", thickness: 0.35 }, { material: "clay", thickness: 1.6 }, { material: "stone", thickness: 1 }] },
342
+ // ground baked hard (laterite over rock): no shovel goes in
343
+ { id: "hardpan", strata: [{ material: "laterite", thickness: 0.8 }, { material: "stone", thickness: 1.5 }] },
283
344
  { id: "bedrock", surfacePattern: "rock", strata: [{ material: "stone", thickness: 3 }] },
284
345
  { id: "paver_floor", strata: [{ material: "paver", thickness: 0.08 }, { material: "sand", thickness: 0.05 }, { material: "gravel", thickness: 0.15 }, { material: "soil", thickness: 1.2 }] },
285
346
  // a pond deep enough to stand chest-high in: a charge on its bed goes off under the water
@@ -515,6 +576,58 @@ var GameTerrain = (() => {
515
576
  return { depth, mean: sum / count, fraction: open / count };
516
577
  }
517
578
 
579
+ // src/height-patch.ts
580
+ var cellCoordinate = (v, origin, count, cellSize) => Math.max(0, Math.min(count - 1e-6, (v - origin) / cellSize));
581
+ var blendHeights = (near, far, t) => near * (1 - t) + far * t;
582
+ var patchColumns = new Int32Array(0);
583
+ var patchBlendX = new Float64Array(0);
584
+ var patchNear = new Float64Array(0);
585
+ var patchFar = new Float64Array(0);
586
+ function heightPatchGrid(patch, xs, zs, out) {
587
+ const width = xs.length;
588
+ const depth = zs.length;
589
+ if (out.length < width * depth) throw new RangeError(`heightPatchGrid: out holds ${out.length} heights, the grid has ${width * depth}`);
590
+ const { cellSize, originX, originZ, columns, rows, column0, row0, heights } = patch;
591
+ const stride = patch.width;
592
+ if (patchColumns.length < width) {
593
+ patchColumns = new Int32Array(width);
594
+ patchBlendX = new Float64Array(width);
595
+ patchNear = new Float64Array(width);
596
+ patchFar = new Float64Array(width);
597
+ }
598
+ for (let i = 0; i < width; i++) {
599
+ const fx = cellCoordinate(xs[i], originX, columns, cellSize);
600
+ const column = (fx | 0) - column0;
601
+ if (column < 0 || column + 1 >= stride) throw new RangeError(`heightPatchGrid: x ${xs[i]} is past the patch`);
602
+ patchColumns[i] = column;
603
+ patchBlendX[i] = fx - (fx | 0);
604
+ }
605
+ let blended = -1;
606
+ for (let j = 0; j < depth; j++) {
607
+ const fz = cellCoordinate(zs[j], originZ, rows, cellSize);
608
+ const row = (fz | 0) - row0;
609
+ if (row < 0 || row + 1 >= patch.depth) throw new RangeError(`heightPatchGrid: z ${zs[j]} is past the patch`);
610
+ const tz = fz - (fz | 0);
611
+ if (row !== blended) {
612
+ blended = row;
613
+ for (let i = 0; i < width; i++) {
614
+ const index = row * stride + patchColumns[i];
615
+ const tx = patchBlendX[i];
616
+ patchNear[i] = blendHeights(heights[index], heights[index + 1], tx);
617
+ patchFar[i] = blendHeights(heights[index + stride], heights[index + stride + 1], tx);
618
+ }
619
+ }
620
+ for (let i = 0; i < width; i++) out[j * width + i] = blendHeights(patchNear[i], patchFar[i], tz);
621
+ }
622
+ }
623
+ var samePatch = (a, b) => {
624
+ if (a.cellSize !== b.cellSize || a.originX !== b.originX || a.originZ !== b.originZ || a.columns !== b.columns || a.rows !== b.rows) return false;
625
+ if (a.column0 !== b.column0 || a.row0 !== b.row0 || a.width !== b.width || a.depth !== b.depth) return false;
626
+ const count = a.width * a.depth;
627
+ for (let k = 0; k < count; k++) if (a.heights[k] !== b.heights[k]) return false;
628
+ return true;
629
+ };
630
+
518
631
  // src/marks.ts
519
632
  var SAME_HOLE = 0.75;
520
633
  function createMarkStore(budget) {
@@ -813,6 +926,28 @@ var GameTerrain = (() => {
813
926
  dirty.add(chunk2);
814
927
  }
815
928
  }
929
+ for (const excavation of layout.excavations ?? []) excavate(excavation);
930
+ }
931
+ function excavate(excavation) {
932
+ const [ex0, ez0, ex1, ez1] = excavation.rect;
933
+ const column0 = clampIndex(Math.floor((ex0 - x0) / cellSize + 1e-6), columns);
934
+ const column1 = clampIndex(Math.ceil((ex1 - x0) / cellSize - 1e-6), columns);
935
+ const row0 = clampIndex(Math.floor((ez0 - z0) / cellSize + 1e-6), rows);
936
+ const row1 = clampIndex(Math.ceil((ez1 - z0) / cellSize - 1e-6), rows);
937
+ const alongX = (excavation.along ?? (ex1 - ex0 >= ez1 - ez0 ? "x" : "z")) === "x";
938
+ const from = alongX ? ex0 : ez0, length = Math.max(1e-6, alongX ? ex1 - ex0 : ez1 - ez0);
939
+ const far = excavation.toDepth ?? excavation.depth;
940
+ for (let row = row0; row <= row1; row++) {
941
+ for (let column = column0; column <= column1; column++) {
942
+ const index = row * stride + column;
943
+ const at = alongX ? x0 + column * cellSize : z0 + row * cellSize;
944
+ const t = Math.max(0, Math.min(1, (at - from) / length));
945
+ const depth = excavation.depth + (far - excavation.depth) * t;
946
+ if (depth <= dug[index]) continue;
947
+ dug[index] = depth;
948
+ touchVertex(column, row);
949
+ }
950
+ }
816
951
  }
817
952
  function layBeds() {
818
953
  const steps = new Uint8Array(vertexCount);
@@ -847,17 +982,110 @@ var GameTerrain = (() => {
847
982
  }
848
983
  if (decalList.length !== before) decalsVersion++;
849
984
  }
985
+ const cellCoordinate2 = (v, origin, count) => cellCoordinate(v, origin, count, cellSize);
986
+ const heightOfVertex = (index) => base[index] - dug[index] + loose[index];
987
+ const blendCell = (index, tx, tz) => blendHeights(blendHeights(heightOfVertex(index), heightOfVertex(index + 1), tx), blendHeights(heightOfVertex(index + stride), heightOfVertex(index + stride + 1), tx), tz);
850
988
  function heightAt(x, z) {
851
989
  if (!contains(x, z)) return options.baseHeight?.(x, z) ?? 0;
852
- const fx = Math.max(0, Math.min(columns - 1e-6, (x - x0) / cellSize));
853
- const fz = Math.max(0, Math.min(rows - 1e-6, (z - z0) / cellSize));
990
+ const fx = cellCoordinate2(x, x0, columns);
991
+ const fz = cellCoordinate2(z, z0, rows);
854
992
  const column = fx | 0;
855
993
  const row = fz | 0;
856
- const tx = fx - column;
857
- const tz = fz - row;
858
- const index = row * stride + column;
859
- const h = (i) => base[i] - dug[i] + loose[i];
860
- return (h(index) * (1 - tx) + h(index + 1) * tx) * (1 - tz) + (h(index + stride) * (1 - tx) + h(index + stride + 1) * tx) * tz;
994
+ return blendCell(row * stride + column, fx - column, fz - row);
995
+ }
996
+ let gridColumns = new Int32Array(0);
997
+ let gridBlendX = new Float64Array(0);
998
+ let gridRows = new Int32Array(0);
999
+ let gridBlendZ = new Float64Array(0);
1000
+ let gridNear = new Float64Array(0);
1001
+ let gridFar = new Float64Array(0);
1002
+ function heightGrid(xs, zs, out) {
1003
+ const width = xs.length;
1004
+ const depth = zs.length;
1005
+ if (out.length < width * depth) throw new RangeError(`heightGrid: out holds ${out.length} heights, the grid has ${width * depth}`);
1006
+ if (gridColumns.length < width) {
1007
+ gridColumns = new Int32Array(width);
1008
+ gridBlendX = new Float64Array(width);
1009
+ }
1010
+ if (gridRows.length < depth) {
1011
+ gridRows = new Int32Array(depth);
1012
+ gridBlendZ = new Float64Array(depth);
1013
+ }
1014
+ for (let i = 0; i < width; i++) {
1015
+ const x = xs[i];
1016
+ const fx = cellCoordinate2(x, x0, columns);
1017
+ gridColumns[i] = x >= x0 && x <= x1 ? fx | 0 : -1;
1018
+ gridBlendX[i] = fx - (fx | 0);
1019
+ }
1020
+ for (let j = 0; j < depth; j++) {
1021
+ const z = zs[j];
1022
+ const fz = cellCoordinate2(z, z0, rows);
1023
+ gridRows[j] = z >= z0 && z <= z1 ? fz | 0 : -1;
1024
+ gridBlendZ[j] = fz - (fz | 0);
1025
+ }
1026
+ if (gridNear.length < width) {
1027
+ gridNear = new Float64Array(width);
1028
+ gridFar = new Float64Array(width);
1029
+ }
1030
+ let blended = -2;
1031
+ for (let j = 0; j < depth; j++) {
1032
+ const row = gridRows[j];
1033
+ const tz = gridBlendZ[j];
1034
+ if (row < 0) {
1035
+ for (let i = 0; i < width; i++) out[j * width + i] = options.baseHeight?.(xs[i], zs[j]) ?? 0;
1036
+ continue;
1037
+ }
1038
+ if (row !== blended) {
1039
+ blended = row;
1040
+ for (let i = 0; i < width; i++) {
1041
+ const column = gridColumns[i];
1042
+ if (column < 0) continue;
1043
+ const index = row * stride + column;
1044
+ const tx = gridBlendX[i];
1045
+ gridNear[i] = blendHeights(heightOfVertex(index), heightOfVertex(index + 1), tx);
1046
+ gridFar[i] = blendHeights(heightOfVertex(index + stride), heightOfVertex(index + stride + 1), tx);
1047
+ }
1048
+ }
1049
+ for (let i = 0; i < width; i++) {
1050
+ if (gridColumns[i] < 0) {
1051
+ out[j * width + i] = options.baseHeight?.(xs[i], zs[j]) ?? 0;
1052
+ continue;
1053
+ }
1054
+ out[j * width + i] = blendHeights(gridNear[i], gridFar[i], tz);
1055
+ }
1056
+ }
1057
+ }
1058
+ function heightPatch(minX, maxX, minZ, maxZ, into) {
1059
+ if (!(minX >= x0 && maxX <= x1 && minZ >= z0 && maxZ <= z1)) return null;
1060
+ const column0 = cellCoordinate2(minX, x0, columns) | 0;
1061
+ const row0 = cellCoordinate2(minZ, z0, rows) | 0;
1062
+ const width = (cellCoordinate2(maxX, x0, columns) | 0) + 2 - column0;
1063
+ const depth = (cellCoordinate2(maxZ, z0, rows) | 0) + 2 - row0;
1064
+ const heights = into && into.length >= width * depth ? into : new Float64Array(width * depth);
1065
+ for (let j = 0; j < depth; j++) {
1066
+ const from = (row0 + j) * stride + column0;
1067
+ for (let i = 0; i < width; i++) heights[j * width + i] = heightOfVertex(from + i);
1068
+ }
1069
+ return { cellSize, originX: x0, originZ: z0, columns, rows, column0, row0, width, depth, heights };
1070
+ }
1071
+ function heightRange(minX, maxX, minZ, maxZ) {
1072
+ if (!contains(minX, minZ) || !contains(maxX, maxZ)) return null;
1073
+ const cellOf = (v, origin, count) => Math.floor(Math.max(0, Math.min(count - 1e-6, (v - origin) / cellSize)));
1074
+ const column0 = cellOf(minX, x0, columns);
1075
+ const column1 = cellOf(maxX, x0, columns) + 1;
1076
+ const row0 = cellOf(minZ, z0, rows);
1077
+ const row1 = cellOf(maxZ, z0, rows) + 1;
1078
+ let low = Infinity;
1079
+ let high = -Infinity;
1080
+ for (let row = row0; row <= row1; row++) {
1081
+ for (let column = column0; column <= column1; column++) {
1082
+ const index = row * stride + column;
1083
+ const h = base[index] - dug[index] + loose[index];
1084
+ if (h < low) low = h;
1085
+ if (h > high) high = h;
1086
+ }
1087
+ }
1088
+ return { low, high };
861
1089
  }
862
1090
  const vertexOf = (x, z) => {
863
1091
  const column = clampIndex(Math.round((x - x0) / cellSize), columns);
@@ -904,6 +1132,20 @@ var GameTerrain = (() => {
904
1132
  const index = row * stride + column;
905
1133
  return materials.get(stratumMaterialAtDepth(profileList[profileIndex[index]], dug[index]));
906
1134
  }
1135
+ function surfaceMaterialAt(x, z) {
1136
+ const column = clampIndex(Math.round((x - x0) / cellSize), columns);
1137
+ const row = clampIndex(Math.round((z - z0) / cellSize), rows);
1138
+ const index = row * stride + column;
1139
+ const which = profileIndex[index];
1140
+ const depth = Math.min(maxDepthOf[which], dug[index] + marks.depthAt(x, z));
1141
+ return materials.get(stratumMaterialAtDepth(profileList[which], depth));
1142
+ }
1143
+ function rollingAt(x, z) {
1144
+ return surfaceMaterialAt(x, z).rolling;
1145
+ }
1146
+ function rollingDampingAt(x, z) {
1147
+ return surfaceMaterialAt(x, z).rollingDamping;
1148
+ }
907
1149
  function columnAt(x, z) {
908
1150
  const { index } = vertexOf(x, z);
909
1151
  const which = profileIndex[index];
@@ -925,6 +1167,109 @@ var GameTerrain = (() => {
925
1167
  loose[index] = loose[index] + amount - filled;
926
1168
  }
927
1169
  const isSoftExposed = (index) => materials.get(stratumAtDepth(profileList[profileIndex[index]], dug[index]).stratum.material).reposeDegrees !== void 0;
1170
+ function verticesUnder(x, z, size) {
1171
+ const nu = Math.max(1, Math.round(size[0] / cellSize)), nv = Math.max(1, Math.round(size[1] / cellSize));
1172
+ const column0 = clampIndex(Math.round((x - x0) / cellSize - (nu - 1) / 2), columns), column1 = clampIndex(column0 + nu - 1, columns);
1173
+ const row0 = clampIndex(Math.round((z - z0) / cellSize - (nv - 1) / 2), rows), row1 = clampIndex(row0 + nv - 1, rows);
1174
+ const out = [];
1175
+ for (let row = row0; row <= row1; row++) for (let column = column0; column <= column1; column++) out.push(row * stride + column);
1176
+ return out;
1177
+ }
1178
+ const touchIndex = (index) => touchVertex(index % stride, Math.floor(index / stride));
1179
+ const materialAtVertex = (index) => loose[index] > 1e-4 ? materials.get("soil") : materials.get(stratumAtDepth(profileList[profileIndex[index]], dug[index]).stratum.material);
1180
+ function digVertex(index, depth) {
1181
+ let left = depth;
1182
+ while (left > 1e-6) {
1183
+ if (loose[index] > 1e-6) {
1184
+ const take2 = Math.min(loose[index], left);
1185
+ loose[index] = loose[index] - take2;
1186
+ left -= take2;
1187
+ continue;
1188
+ }
1189
+ const profile = profileList[profileIndex[index]];
1190
+ const layer = stratumAtDepth(profile, dug[index]);
1191
+ if (!materials.get(layer.stratum.material)?.dig || dug[index] >= maxDepthOf[profileIndex[index]] - 1e-6) break;
1192
+ const take = Math.min(left, layer.top + layer.stratum.thickness - dug[index]);
1193
+ if (take <= 1e-6) break;
1194
+ dug[index] = dug[index] + take;
1195
+ left -= take;
1196
+ }
1197
+ return depth - left;
1198
+ }
1199
+ function heapAt(x, z, volume) {
1200
+ if (volume <= 0) return;
1201
+ const radius = Math.max(cellSize * 2, Math.cbrt(volume) * 1.6);
1202
+ const indices = verticesUnder(x, z, [2 * radius, 2 * radius]);
1203
+ const weight = (index) => {
1204
+ const px = x0 + index % stride * cellSize, pz = z0 + Math.floor(index / stride) * cellSize;
1205
+ const q = Math.hypot(px - x, pz - z) / radius;
1206
+ return q < 1 ? 1 - q * q : 0;
1207
+ };
1208
+ const total = indices.reduce((sum, i) => sum + weight(i), 0);
1209
+ if (total <= 0) return;
1210
+ const cellArea = cellSize * cellSize;
1211
+ for (const index of indices) {
1212
+ const w = weight(index);
1213
+ if (w <= 0) continue;
1214
+ loose[index] = loose[index] + volume * w / (total * cellArea);
1215
+ sliding.add(index);
1216
+ touchIndex(index);
1217
+ }
1218
+ emitDeform(x, z, radius);
1219
+ }
1220
+ function dig(spec) {
1221
+ const size = spec.size ?? [0.3, 0.3], depth = spec.depth ?? 0.2;
1222
+ const centre = vertexOf(spec.x, spec.z).index;
1223
+ if (profileList[profileIndex[centre]].water) return { volume: 0, material: "water", effort: 0, refused: "water" };
1224
+ const met = materialAtVertex(centre);
1225
+ if (!met.dig) return { volume: 0, material: met.id, effort: 0, refused: met.id };
1226
+ if (met.dig.closes) return { volume: 0, material: met.id, effort: met.dig.effort, closes: true };
1227
+ const cellArea = cellSize * cellSize;
1228
+ const tally = /* @__PURE__ */ new Map();
1229
+ let volume = 0;
1230
+ for (const index of verticesUnder(spec.x, spec.z, size)) {
1231
+ const before = dug[index];
1232
+ const went = digVertex(index, depth);
1233
+ if (went <= 0) continue;
1234
+ tallyLowered(tally, index, dug[index] - before);
1235
+ volume += went * cellArea;
1236
+ sliding.add(index);
1237
+ touchIndex(index);
1238
+ }
1239
+ marks.removeInside(spec.x, spec.z, Math.max(size[0], size[1]) / 2);
1240
+ emitDeform(spec.x, spec.z, Math.max(size[0], size[1]));
1241
+ emitGroundLoss(tally, "dig", 0);
1242
+ if (spec.dump) heapAt(spec.dump.x, spec.dump.z, volume);
1243
+ return { volume, material: met.id, effort: volume > 0 ? met.dig.effort : 0 };
1244
+ }
1245
+ function fill(spec) {
1246
+ const cellArea = cellSize * cellSize;
1247
+ let taken = 0;
1248
+ const source = verticesUnder(spec.from.x, spec.from.z, [2 * spec.from.radius, 2 * spec.from.radius]).filter((i) => loose[i] > 1e-6);
1249
+ for (const index of source) {
1250
+ if (taken >= spec.volume) break;
1251
+ const take = Math.min(loose[index], (spec.volume - taken) / cellArea);
1252
+ loose[index] = loose[index] - take;
1253
+ taken += take * cellArea;
1254
+ sliding.add(index);
1255
+ touchIndex(index);
1256
+ }
1257
+ if (taken <= 0) return 0;
1258
+ emitDeform(spec.from.x, spec.from.z, spec.from.radius);
1259
+ const target = verticesUnder(spec.x, spec.z, spec.size ?? [0.3, 0.3]).sort((a, b) => dug[b] - dug[a]);
1260
+ let left = taken;
1261
+ for (const index of target) {
1262
+ if (left <= 1e-9) break;
1263
+ const amount = Math.min(left / cellArea, Math.max(dug[index], left / cellArea / target.length));
1264
+ addToVertex(index, amount, true);
1265
+ left -= amount * cellArea;
1266
+ sliding.add(index);
1267
+ touchIndex(index);
1268
+ }
1269
+ if (left > 1e-9) heapAt(spec.x, spec.z, left);
1270
+ emitDeform(spec.x, spec.z, Math.max(...spec.size ?? [0.3, 0.3]));
1271
+ return taken;
1272
+ }
928
1273
  function stampBowl(x, z, radius, depth, rimVolume, lossSource = "crater") {
929
1274
  const reach = radius * RIM_REACH;
930
1275
  const column0 = clampIndex(Math.floor((x - reach - x0) / cellSize), columns);
@@ -1431,6 +1776,14 @@ var GameTerrain = (() => {
1431
1776
  slideTally.clear();
1432
1777
  }
1433
1778
  }
1779
+ const settledArea = { minX: Infinity, minZ: Infinity, maxX: -Infinity, maxZ: -Infinity };
1780
+ function emitSettledArea() {
1781
+ if (settledArea.minX > settledArea.maxX) return;
1782
+ const { minX, minZ, maxX, maxZ } = settledArea;
1783
+ settledArea.minX = settledArea.minZ = Infinity;
1784
+ settledArea.maxX = settledArea.maxZ = -Infinity;
1785
+ emitDeform((minX + maxX) / 2, (minZ + maxZ) / 2, Math.hypot(maxX - minX, maxZ - minZ) / 2 + cellSize * 2);
1786
+ }
1434
1787
  function settle(piece) {
1435
1788
  const material = materials.get(piece.material);
1436
1789
  if (!material || material.reposeDegrees === void 0 || material.scatters) return false;
@@ -1440,6 +1793,11 @@ var GameTerrain = (() => {
1440
1793
  addToVertex(index, 4 / 3 * Math.PI * piece.radius ** 3 / (cellSize * cellSize), false);
1441
1794
  sliding.add(index);
1442
1795
  touchVertex(column, row);
1796
+ const px = x0 + column * cellSize, pz = z0 + row * cellSize;
1797
+ settledArea.minX = Math.min(settledArea.minX, px);
1798
+ settledArea.maxX = Math.max(settledArea.maxX, px);
1799
+ settledArea.minZ = Math.min(settledArea.minZ, pz);
1800
+ settledArea.maxZ = Math.max(settledArea.maxZ, pz);
1443
1801
  return true;
1444
1802
  }
1445
1803
  function applyHit(hit) {
@@ -1520,6 +1878,7 @@ var GameTerrain = (() => {
1520
1878
  burning.clear();
1521
1879
  random = createRandom(seed);
1522
1880
  applyLayout(currentLayout);
1881
+ emitDeform((x0 + x1) / 2, (z0 + z1) / 2, Math.hypot(x1 - x0, z1 - z0) / 2);
1523
1882
  }
1524
1883
  applyLayout(currentLayout);
1525
1884
  return {
@@ -1549,6 +1908,9 @@ var GameTerrain = (() => {
1549
1908
  reset();
1550
1909
  },
1551
1910
  heightAt,
1911
+ heightGrid,
1912
+ heightPatch,
1913
+ heightRange,
1552
1914
  footAt,
1553
1915
  walkFactorAt,
1554
1916
  waterAt,
@@ -1561,10 +1923,14 @@ var GameTerrain = (() => {
1561
1923
  vertexHeight,
1562
1924
  vertexMaterial,
1563
1925
  columnAt,
1926
+ rollingAt,
1927
+ rollingDampingAt,
1564
1928
  contains,
1565
1929
  raycast,
1566
1930
  strike,
1567
1931
  burn,
1932
+ dig,
1933
+ fill,
1568
1934
  applyHit,
1569
1935
  bear: bearAll,
1570
1936
  voidUnder: (x, z, radius) => voidUnder(grid, { x, z, radius }),
@@ -1574,6 +1940,7 @@ var GameTerrain = (() => {
1574
1940
  },
1575
1941
  update(dt) {
1576
1942
  debrisStore.update(dt, { heightAt, gravity, settle });
1943
+ emitSettledArea();
1577
1944
  updateSlides();
1578
1945
  updateFire(dt);
1579
1946
  for (let i = decalList.length - 1; i >= 0; i--) {
@@ -1629,6 +1996,7 @@ var GameTerrain = (() => {
1629
1996
  decalList.push(...(snapshot.decals ?? []).map((decal) => ({ ...decal })));
1630
1997
  decalSerial = decalList.reduce((highest, decal) => Math.max(highest, decal.id), decalSerial);
1631
1998
  for (let chunkIndex = 0; chunkIndex < touched.length; chunkIndex++) markChunk(chunkIndex);
1999
+ emitDeform((x0 + x1) / 2, (z0 + z1) / 2, Math.hypot(x1 - x0, z1 - z0) / 2);
1632
2000
  }
1633
2001
  };
1634
2002
  }