@adatechnology/game-terrain 0.5.2 → 0.7.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.d.ts +35 -9
- package/dist/index.global.js +121 -14
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +121 -14
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { GroundLayout, Hit, DestructibleImpl } from '@adatechnology/game-contracts';
|
|
1
|
+
import { GroundLayout, Hit, GroundLoss, DestructibleImpl } from '@adatechnology/game-contracts';
|
|
2
2
|
export { GroundLayout, GroundZone } from '@adatechnology/game-contracts';
|
|
3
3
|
|
|
4
4
|
/** The blows that remove ground. Fire and heat char it instead (`TerrainMaterial.fire`). */
|
|
5
5
|
type TerrainBlow = 'ballistic' | 'blunt' | 'slash' | 'explosive';
|
|
6
|
+
/** A blow at (x, z): `energy` in joules, `direction` where it travels, `contactRadius` of a blunt tool, `caliber` (mm) of a round, which shapes its crater. */
|
|
7
|
+
type TerrainStrike = {
|
|
8
|
+
x: number;
|
|
9
|
+
z: number;
|
|
10
|
+
energy: number;
|
|
11
|
+
direction?: readonly number[];
|
|
12
|
+
contactRadius?: number;
|
|
13
|
+
caliber?: number;
|
|
14
|
+
};
|
|
6
15
|
/** What one kind of blow does to a material. */
|
|
7
16
|
interface TerrainBlowResponse {
|
|
8
17
|
/** Joules it takes to remove one cubic metre. */
|
|
@@ -175,6 +184,20 @@ interface TerrainOptions {
|
|
|
175
184
|
/** Metres per second squared. */
|
|
176
185
|
readonly gravity?: number;
|
|
177
186
|
readonly seed?: number;
|
|
187
|
+
/**
|
|
188
|
+
* Ground taken away from under the surface: a crater (`crater`), a slab that gave way into the void under it (`slab`), sand that slid off a slope
|
|
189
|
+
* (`slide`). The host hands it to what stands there (`DestructionWorld.groundLoss`), so foundations over it settle or lose their support.
|
|
190
|
+
*/
|
|
191
|
+
readonly onGroundLoss?: (loss: GroundLoss) => void;
|
|
192
|
+
}
|
|
193
|
+
/** What is missing under a disc of the ground (`Terrain.voidUnder`). */
|
|
194
|
+
interface TerrainVoid {
|
|
195
|
+
/** Metres under the untouched surface at the deepest vertex. */
|
|
196
|
+
readonly depth: number;
|
|
197
|
+
/** Metres under the untouched surface, averaged over the disc. */
|
|
198
|
+
readonly mean: number;
|
|
199
|
+
/** 0..1, the share of the disc's vertices that are void (dug at least `VOID_MIN_DEPTH`). */
|
|
200
|
+
readonly fraction: number;
|
|
178
201
|
}
|
|
179
202
|
/** A fine mark: a bullet pock or a chip, smaller than a cell. It grows with the blows on it until it is dug into the height field. */
|
|
180
203
|
interface TerrainMark {
|
|
@@ -346,13 +369,7 @@ interface Terrain {
|
|
|
346
369
|
normal: [number, number, number];
|
|
347
370
|
} | null;
|
|
348
371
|
/** A blow at (x, z). `energy` in joules, `direction` where it travels (it throws the pieces back along it). */
|
|
349
|
-
strike(blow: TerrainBlow, spec:
|
|
350
|
-
x: number;
|
|
351
|
-
z: number;
|
|
352
|
-
energy: number;
|
|
353
|
-
direction?: readonly number[];
|
|
354
|
-
contactRadius?: number;
|
|
355
|
-
}): TerrainBlowResult;
|
|
372
|
+
strike(blow: TerrainBlow, spec: TerrainStrike): TerrainBlowResult;
|
|
356
373
|
/** A flame over a disc for `seconds`. */
|
|
357
374
|
burn(spec: {
|
|
358
375
|
x: number;
|
|
@@ -365,6 +382,8 @@ interface Terrain {
|
|
|
365
382
|
applyHit(hit: Hit): TerrainBlowResult | null;
|
|
366
383
|
/** What stands still on the ground now. Where it stands over bare bars they sag under it, and past what they hold they give way; a slab over a void then opens. True when it opened. */
|
|
367
384
|
bear(loads: readonly TerrainLoad[]): boolean;
|
|
385
|
+
/** How much ground is missing under the disc (x, z, radius), measured from the untouched surface. */
|
|
386
|
+
voidUnder(x: number, z: number, radius: number): TerrainVoid;
|
|
368
387
|
/** Height a foot stands at: the ground less what it sinks in. */
|
|
369
388
|
footAt(x: number, z: number): number;
|
|
370
389
|
/** What is left of the walking speed here, 0..1. */
|
|
@@ -434,6 +453,13 @@ interface TerrainImplOptions {
|
|
|
434
453
|
*/
|
|
435
454
|
declare function createTerrainImpl(terrain: Terrain, options: TerrainImplOptions): DestructibleImpl;
|
|
436
455
|
|
|
456
|
+
/** A loss shallower than this (m below the untouched surface) is a scuff, not a void anything bears over. */
|
|
457
|
+
declare const GROUND_LOSS_MIN_DEPTH = 0.02;
|
|
458
|
+
/** Sand that slid tells the host only where it lowered the ground by at least this much (m). */
|
|
459
|
+
declare const SLIDE_LOSS_MIN_LOWERING = 0.05;
|
|
460
|
+
/** Under this depth (m) a vertex still counts as ground in `voidUnder`. */
|
|
461
|
+
declare const VOID_MIN_DEPTH = 0.02;
|
|
462
|
+
|
|
437
463
|
declare const TERRAIN_MATERIALS: readonly TerrainMaterial[];
|
|
438
464
|
declare const TERRAIN_PROFILES: readonly TerrainProfile[];
|
|
439
465
|
/** About twelve grenades (200 kJ) on the same spot of bare bars. */
|
|
@@ -494,4 +520,4 @@ interface WaterLift {
|
|
|
494
520
|
/** Archimedes on a body in a liquid: what it displaces lifts it, so a light log floats and a concrete block goes to the bed. */
|
|
495
521
|
declare function waterLift(params: WaterLiftParams): WaterLift;
|
|
496
522
|
|
|
497
|
-
export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_DIAMETER, DEFAULT_BAR_YIELD_JOULES, DEFAULT_BAR_YIELD_PA, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, type Footprints, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainDecal, type TerrainDecalKind, type TerrainFireResponse, type TerrainFooting, type TerrainImplOptions, type TerrainLoad, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, type TerrainUnits, type TerrainWater, type TerrainWaterHere, type WaterLift, type WaterLiftParams, crackLines, createFootprints, createTerrain, createTerrainImpl, waterLift };
|
|
523
|
+
export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_DIAMETER, DEFAULT_BAR_YIELD_JOULES, DEFAULT_BAR_YIELD_PA, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, type Footprints, GROUND_LOSS_MIN_DEPTH, SLIDE_LOSS_MIN_LOWERING, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainDecal, type TerrainDecalKind, type TerrainFireResponse, type TerrainFooting, type TerrainImplOptions, type TerrainLoad, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, type TerrainStrike, type TerrainUnits, type TerrainVoid, type TerrainWater, type TerrainWaterHere, VOID_MIN_DEPTH, type WaterLift, type WaterLiftParams, crackLines, createFootprints, createTerrain, createTerrainImpl, waterLift };
|
package/dist/index.global.js
CHANGED
|
@@ -27,9 +27,12 @@ var GameTerrain = (() => {
|
|
|
27
27
|
DEFAULT_BAR_YIELD_PA: () => DEFAULT_BAR_YIELD_PA,
|
|
28
28
|
DEFAULT_PROFILE: () => DEFAULT_PROFILE,
|
|
29
29
|
DEFAULT_TERRAIN_BUDGET: () => DEFAULT_TERRAIN_BUDGET,
|
|
30
|
+
GROUND_LOSS_MIN_DEPTH: () => GROUND_LOSS_MIN_DEPTH,
|
|
31
|
+
SLIDE_LOSS_MIN_LOWERING: () => SLIDE_LOSS_MIN_LOWERING,
|
|
30
32
|
TERRAIN_MATERIALS: () => TERRAIN_MATERIALS,
|
|
31
33
|
TERRAIN_PATTERNS: () => TERRAIN_PATTERNS,
|
|
32
34
|
TERRAIN_PROFILES: () => TERRAIN_PROFILES,
|
|
35
|
+
VOID_MIN_DEPTH: () => VOID_MIN_DEPTH,
|
|
33
36
|
crackLines: () => crackLines,
|
|
34
37
|
createFootprints: () => createFootprints,
|
|
35
38
|
createTerrain: () => createTerrain,
|
|
@@ -444,6 +447,72 @@ var GameTerrain = (() => {
|
|
|
444
447
|
};
|
|
445
448
|
}
|
|
446
449
|
|
|
450
|
+
// src/ground-loss.ts
|
|
451
|
+
var GROUND_LOSS_MIN_DEPTH = 0.02;
|
|
452
|
+
var SLIDE_LOSS_MIN_LOWERING = 0.05;
|
|
453
|
+
var VOID_MIN_DEPTH = 0.02;
|
|
454
|
+
function tallyLowered(tally, index, amount) {
|
|
455
|
+
if (amount !== 0) tally.set(index, (tally.get(index) ?? 0) + amount);
|
|
456
|
+
}
|
|
457
|
+
function lossOf(grid, tally, spec) {
|
|
458
|
+
let weight = 0;
|
|
459
|
+
let centerX = 0;
|
|
460
|
+
let centerZ = 0;
|
|
461
|
+
let depth = 0;
|
|
462
|
+
let deepest = 0;
|
|
463
|
+
const kept = [];
|
|
464
|
+
for (const [index, amount] of tally) {
|
|
465
|
+
if (amount < spec.minLowering || amount <= 0) continue;
|
|
466
|
+
const column = index % grid.stride;
|
|
467
|
+
const row = (index - column) / grid.stride;
|
|
468
|
+
weight += amount;
|
|
469
|
+
centerX += (grid.x0 + column * grid.cellSize) * amount;
|
|
470
|
+
centerZ += (grid.z0 + row * grid.cellSize) * amount;
|
|
471
|
+
depth = Math.max(depth, grid.dug[index]);
|
|
472
|
+
deepest = Math.max(deepest, amount);
|
|
473
|
+
kept.push(index);
|
|
474
|
+
}
|
|
475
|
+
if (weight <= 0 || depth < GROUND_LOSS_MIN_DEPTH || deepest < GROUND_LOSS_MIN_DEPTH) return null;
|
|
476
|
+
centerX /= weight;
|
|
477
|
+
centerZ /= weight;
|
|
478
|
+
let radius = 0;
|
|
479
|
+
for (const index of kept) {
|
|
480
|
+
if (spec.shape === "bowl" && grid.dug[index] < depth / 2) continue;
|
|
481
|
+
const column = index % grid.stride;
|
|
482
|
+
const row = (index - column) / grid.stride;
|
|
483
|
+
radius = Math.max(radius, Math.hypot(grid.x0 + column * grid.cellSize - centerX, grid.z0 + row * grid.cellSize - centerZ));
|
|
484
|
+
}
|
|
485
|
+
const reach = spec.shape === "bowl" ? Math.SQRT2 * (radius + grid.cellSize / 2) : radius + grid.cellSize / 2;
|
|
486
|
+
return { x: centerX, z: centerZ, radius: reach, depth, removed: weight * grid.cellSize * grid.cellSize, source: spec.source };
|
|
487
|
+
}
|
|
488
|
+
function voidUnder(grid, spec) {
|
|
489
|
+
const { x, z, radius } = spec;
|
|
490
|
+
const clamp = (value, top) => Math.max(0, Math.min(top, value));
|
|
491
|
+
const column0 = clamp(Math.ceil((x - radius - grid.x0) / grid.cellSize), grid.columns);
|
|
492
|
+
const column1 = clamp(Math.floor((x + radius - grid.x0) / grid.cellSize), grid.columns);
|
|
493
|
+
const row0 = clamp(Math.ceil((z - radius - grid.z0) / grid.cellSize), grid.rows);
|
|
494
|
+
const row1 = clamp(Math.floor((z + radius - grid.z0) / grid.cellSize), grid.rows);
|
|
495
|
+
let count = 0;
|
|
496
|
+
let sum = 0;
|
|
497
|
+
let depth = 0;
|
|
498
|
+
let open = 0;
|
|
499
|
+
for (let row = row0; row <= row1; row++) {
|
|
500
|
+
for (let column = column0; column <= column1; column++) {
|
|
501
|
+
if (Math.hypot(grid.x0 + column * grid.cellSize - x, grid.z0 + row * grid.cellSize - z) > radius) continue;
|
|
502
|
+
const here = grid.dug[row * grid.stride + column];
|
|
503
|
+
count++;
|
|
504
|
+
sum += here;
|
|
505
|
+
depth = Math.max(depth, here);
|
|
506
|
+
if (here >= VOID_MIN_DEPTH) open++;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (count === 0) {
|
|
510
|
+
const here = grid.dug[clamp(Math.round((z - grid.z0) / grid.cellSize), grid.rows) * grid.stride + clamp(Math.round((x - grid.x0) / grid.cellSize), grid.columns)];
|
|
511
|
+
return { depth: here, mean: here, fraction: here >= VOID_MIN_DEPTH ? 1 : 0 };
|
|
512
|
+
}
|
|
513
|
+
return { depth, mean: sum / count, fraction: open / count };
|
|
514
|
+
}
|
|
515
|
+
|
|
447
516
|
// src/marks.ts
|
|
448
517
|
var SAME_HOLE = 0.75;
|
|
449
518
|
function createMarkStore(budget) {
|
|
@@ -573,6 +642,12 @@ var GameTerrain = (() => {
|
|
|
573
642
|
var FINE_CELLS = 1.5;
|
|
574
643
|
var FINE_DEPTH_CELLS = 0.4;
|
|
575
644
|
var RIGID_WIDENING = 2.5;
|
|
645
|
+
var REFERENCE_CALIBER = 7.62;
|
|
646
|
+
var CALIBER_ASPECT_POWER = 0.5;
|
|
647
|
+
var CALIBER_ASPECT_RANGE = [0.6, 1.6];
|
|
648
|
+
var CALIBERS_ACROSS = 2.5;
|
|
649
|
+
var caliberAspect = (caliber) => caliber && caliber > 0 ? Math.min(CALIBER_ASPECT_RANGE[1], Math.max(CALIBER_ASPECT_RANGE[0], (REFERENCE_CALIBER / caliber) ** CALIBER_ASPECT_POWER)) : 1;
|
|
650
|
+
var caliberRadius = (caliber) => caliber && caliber > 0 ? caliber / 1e3 * CALIBERS_ACROSS / 2 : 0;
|
|
576
651
|
var COLLAPSE_DEPTH_SHARE = 0.75;
|
|
577
652
|
var COLLAPSE_SPREAD_BEND = 0.5;
|
|
578
653
|
var BARS_SHARE_REACH = 0.6;
|
|
@@ -678,6 +753,17 @@ var GameTerrain = (() => {
|
|
|
678
753
|
const emitDeform = (x, z, radius) => {
|
|
679
754
|
for (const listener of deformListeners) listener({ x, z, radius });
|
|
680
755
|
};
|
|
756
|
+
const grid = { x0, z0, cellSize, stride, columns, rows, dug };
|
|
757
|
+
const slideTally = /* @__PURE__ */ new Map();
|
|
758
|
+
const emitGroundLoss = (tally, source, minLowering) => {
|
|
759
|
+
if (!options.onGroundLoss) return;
|
|
760
|
+
const loss = lossOf(grid, tally, { source, minLowering, shape: source === "slab" ? "flat" : "bowl" });
|
|
761
|
+
if (loss) options.onGroundLoss(loss);
|
|
762
|
+
};
|
|
763
|
+
const dropVertex = (index, depth, tally) => {
|
|
764
|
+
tallyLowered(tally, index, depth - dug[index]);
|
|
765
|
+
dug[index] = depth;
|
|
766
|
+
};
|
|
681
767
|
const chunkOfVertex = (column, row) => Math.min(chunksZ - 1, Math.floor(row / chunkCells)) * chunksX + Math.min(chunksX - 1, Math.floor(column / chunkCells));
|
|
682
768
|
function touchVertex(column, row) {
|
|
683
769
|
const chunk2 = chunkOfVertex(column, row);
|
|
@@ -837,7 +923,7 @@ var GameTerrain = (() => {
|
|
|
837
923
|
loose[index] = loose[index] + amount - filled;
|
|
838
924
|
}
|
|
839
925
|
const isSoftExposed = (index) => materials.get(stratumAtDepth(profileList[profileIndex[index]], dug[index]).stratum.material).reposeDegrees !== void 0;
|
|
840
|
-
function stampBowl(x, z, radius, depth, rimVolume) {
|
|
926
|
+
function stampBowl(x, z, radius, depth, rimVolume, lossSource = "crater") {
|
|
841
927
|
const reach = radius * RIM_REACH;
|
|
842
928
|
const column0 = clampIndex(Math.floor((x - reach - x0) / cellSize), columns);
|
|
843
929
|
const column1 = clampIndex(Math.ceil((x + reach - x0) / cellSize), columns);
|
|
@@ -859,12 +945,15 @@ var GameTerrain = (() => {
|
|
|
859
945
|
}
|
|
860
946
|
}
|
|
861
947
|
const cellArea = cellSize * cellSize;
|
|
948
|
+
const tally = /* @__PURE__ */ new Map();
|
|
862
949
|
for (let row = row0; row <= row1; row++) {
|
|
863
950
|
for (let column = column0; column <= column1; column++) {
|
|
864
951
|
const q = shapeOf(x0 + column * cellSize, z0 + row * cellSize);
|
|
865
952
|
const index = row * stride + column;
|
|
866
953
|
if (q < 1) {
|
|
954
|
+
const before = dug[index];
|
|
867
955
|
removeFromVertex(index, depth * (1 - q * q) * (0.92 + random() * 0.16));
|
|
956
|
+
tallyLowered(tally, index, dug[index] - before);
|
|
868
957
|
sliding.add(index);
|
|
869
958
|
touchVertex(column, row);
|
|
870
959
|
} else if (q < RIM_REACH && rimWeight > 0) {
|
|
@@ -877,6 +966,7 @@ var GameTerrain = (() => {
|
|
|
877
966
|
marks.removeInside(x, z, radius);
|
|
878
967
|
clearDecalsInside(x, z, radius);
|
|
879
968
|
emitDeform(x, z, reach);
|
|
969
|
+
if (lossSource) emitGroundLoss(tally, lossSource, 0);
|
|
880
970
|
}
|
|
881
971
|
function throwPieces(spec) {
|
|
882
972
|
const radius = PIECE_RADIUS[spec.material.debris];
|
|
@@ -945,16 +1035,17 @@ var GameTerrain = (() => {
|
|
|
945
1035
|
const pastCover = bars !== void 0 && depth - layer.top >= bars.cover - 1e-6;
|
|
946
1036
|
const specificEnergy = response.specificEnergy * (pastCover ? bars.resistance : 1);
|
|
947
1037
|
const limit = bars && !pastCover ? Math.min(room, layer.top + bars.cover - depth) : room;
|
|
1038
|
+
const aspect = response.aspect * caliberAspect(spec.caliber);
|
|
948
1039
|
const volume = energy / specificEnergy;
|
|
949
|
-
const wanted = Math.cbrt(2 * volume / (Math.PI *
|
|
950
|
-
const wantedDepth = wanted *
|
|
1040
|
+
const wanted = Math.cbrt(2 * volume / (Math.PI * aspect));
|
|
1041
|
+
const wantedDepth = wanted * aspect;
|
|
951
1042
|
const takenDepth = Math.min(wantedDepth, limit);
|
|
952
|
-
const takenRadius = takenDepth < wantedDepth ? takenDepth /
|
|
1043
|
+
const takenRadius = takenDepth < wantedDepth ? takenDepth / aspect : wanted;
|
|
953
1044
|
const takenVolume = Math.PI * takenRadius * takenRadius * takenDepth / 2;
|
|
954
1045
|
energy -= takenVolume * specificEnergy;
|
|
955
1046
|
depth += takenDepth;
|
|
956
1047
|
carved += takenDepth;
|
|
957
|
-
radius = Math.max(radius, takenRadius, response.minRadius ?? 0, spec.contactRadius ?? 0);
|
|
1048
|
+
radius = Math.max(radius, takenRadius, response.minRadius ?? 0, spec.contactRadius ?? 0, caliberRadius(spec.caliber));
|
|
958
1049
|
const last = removed[removed.length - 1];
|
|
959
1050
|
if (last?.material === material.id) last.volume += takenVolume;
|
|
960
1051
|
else removed.push({ material: material.id, volume: takenVolume });
|
|
@@ -972,6 +1063,7 @@ var GameTerrain = (() => {
|
|
|
972
1063
|
let collapsed = loadBars(blow, spec.energy, x, z, profile);
|
|
973
1064
|
const crack = crackAround(blow, spec.energy, x, z, start.loose > 0 ? void 0 : firstMaterial);
|
|
974
1065
|
const extra = { ...crack ? { crack } : {}, ...breached ? { breached } : {}, ...waterResult };
|
|
1066
|
+
const pressed = spec.contactRadius !== void 0 && spec.contactRadius >= radius;
|
|
975
1067
|
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 };
|
|
976
1068
|
if (firstMaterial.reposeDegrees === void 0 && start.loose <= 0) radius *= 1 + RIGID_WIDENING * (start.depth / maxDepthOfProfile(profile));
|
|
977
1069
|
const volumeTotal = removed.reduce((sum, entry) => sum + entry.volume, 0);
|
|
@@ -979,7 +1071,7 @@ var GameTerrain = (() => {
|
|
|
979
1071
|
if (fine) depositMark({ x, z, radius, depth: carved, blow, profile, cap: maxDepthOfProfile(profile) });
|
|
980
1072
|
else {
|
|
981
1073
|
const rimShare = materials.get(removed[0].material).rimShare ?? 0;
|
|
982
|
-
stampBowl(x, z, radius, carved, volumeTotal * rimShare);
|
|
1074
|
+
stampBowl(x, z, radius, carved, volumeTotal * rimShare, pressed ? null : "crater");
|
|
983
1075
|
}
|
|
984
1076
|
if (firstMaterial.cracks) addDecal({ kind: "crack", x, z, radius: Math.max(CRACK_MIN_RADIUS, radius * firstMaterial.cracks), angle: random() * 6.283, material: firstMaterial.id });
|
|
985
1077
|
let quota = waterHere && blow !== "explosive" ? 0 : budget.maxDebrisPerBlow;
|
|
@@ -1010,7 +1102,7 @@ var GameTerrain = (() => {
|
|
|
1010
1102
|
const bottom = layer.top + layer.stratum.thickness;
|
|
1011
1103
|
const miss = { point, radius: 0, depth: 0, totalDepth: layer.top, removed: [], exposed: material.id, atLimit: false, rebarExposed: false, collapsed: false, fine: true };
|
|
1012
1104
|
if (!response || energy < (response.thresholdJoules ?? 0)) return miss;
|
|
1013
|
-
const reach = Math.max(spec.contactRadius ?? 0, response.minRadius ?? 0, Math.cbrt(2 * energy / response.specificEnergy / (Math.PI * response.aspect)));
|
|
1105
|
+
const reach = Math.max(spec.contactRadius ?? 0, response.minRadius ?? 0, caliberRadius(spec.caliber), Math.cbrt(2 * energy / response.specificEnergy / (Math.PI * response.aspect * caliberAspect(spec.caliber))));
|
|
1014
1106
|
const rowFirst = Math.floor((z - reach) / units.width);
|
|
1015
1107
|
const rowLast = Math.floor((z + reach) / units.width);
|
|
1016
1108
|
let loosened = 0;
|
|
@@ -1081,6 +1173,7 @@ var GameTerrain = (() => {
|
|
|
1081
1173
|
const row1 = clampIndex(Math.ceil((z + reach - z0) / cellSize), rows);
|
|
1082
1174
|
const limit = maxDepthOfProfile(profile);
|
|
1083
1175
|
let collapsed = false;
|
|
1176
|
+
const tally = /* @__PURE__ */ new Map();
|
|
1084
1177
|
for (let row = row0; row <= row1; row++) {
|
|
1085
1178
|
for (let column = column0; column <= column1; column++) {
|
|
1086
1179
|
const index = row * stride + column;
|
|
@@ -1090,16 +1183,17 @@ var GameTerrain = (() => {
|
|
|
1090
1183
|
barBend[index] = barBend[index] + energy / yieldJoules * (1 - q * q);
|
|
1091
1184
|
touchVertex(column, row);
|
|
1092
1185
|
if (barBend[index] >= 1 && profile.drop !== void 0 && dug[index] >= limit * COLLAPSE_DEPTH_SHARE && dug[index] < limit + profile.drop) {
|
|
1093
|
-
|
|
1186
|
+
dropVertex(index, limit + profile.drop, tally);
|
|
1094
1187
|
collapsed = true;
|
|
1095
1188
|
}
|
|
1096
1189
|
}
|
|
1097
1190
|
}
|
|
1098
|
-
if (collapsed) giveWay({ x, z, reach, profile });
|
|
1191
|
+
if (collapsed) giveWay({ x, z, reach, profile, tally });
|
|
1192
|
+
emitGroundLoss(tally, "slab", 0);
|
|
1099
1193
|
return collapsed;
|
|
1100
1194
|
}
|
|
1101
1195
|
function giveWay(spec) {
|
|
1102
|
-
const { x, z, reach, profile } = spec;
|
|
1196
|
+
const { x, z, reach, profile, tally } = spec;
|
|
1103
1197
|
emitDeform(x, z, reach);
|
|
1104
1198
|
if (profile.drop === void 0) return;
|
|
1105
1199
|
const limit = maxDepthOfProfile(profile);
|
|
@@ -1111,7 +1205,7 @@ var GameTerrain = (() => {
|
|
|
1111
1205
|
for (let column = column0; column <= column1; column++) {
|
|
1112
1206
|
const index = row * stride + column;
|
|
1113
1207
|
if (barBend[index] >= COLLAPSE_SPREAD_BEND && dug[index] < limit + profile.drop) {
|
|
1114
|
-
|
|
1208
|
+
dropVertex(index, limit + profile.drop, tally);
|
|
1115
1209
|
touchVertex(column, row);
|
|
1116
1210
|
}
|
|
1117
1211
|
}
|
|
@@ -1135,6 +1229,7 @@ var GameTerrain = (() => {
|
|
|
1135
1229
|
if (spread) touched2.push({ load, ...spread });
|
|
1136
1230
|
}
|
|
1137
1231
|
let opened = false;
|
|
1232
|
+
const tally = /* @__PURE__ */ new Map();
|
|
1138
1233
|
for (const [index, bend] of bends) {
|
|
1139
1234
|
if (barBend[index] >= bend) continue;
|
|
1140
1235
|
barBend[index] = bend;
|
|
@@ -1144,11 +1239,12 @@ var GameTerrain = (() => {
|
|
|
1144
1239
|
const profile = profileList[profileIndex[index]];
|
|
1145
1240
|
const limit = maxDepthOfProfile(profile);
|
|
1146
1241
|
if (bend >= 1 && profile.drop !== void 0 && dug[index] >= limit * COLLAPSE_DEPTH_SHARE && dug[index] < limit + profile.drop) {
|
|
1147
|
-
|
|
1242
|
+
dropVertex(index, limit + profile.drop, tally);
|
|
1148
1243
|
opened = true;
|
|
1149
1244
|
}
|
|
1150
1245
|
}
|
|
1151
|
-
if (opened) for (const { load, reach, profile } of touched2) giveWay({ x: load.x, z: load.z, reach, profile });
|
|
1246
|
+
if (opened) for (const { load, reach, profile } of touched2) giveWay({ x: load.x, z: load.z, reach, profile, tally });
|
|
1247
|
+
emitGroundLoss(tally, "slab", 0);
|
|
1152
1248
|
return opened;
|
|
1153
1249
|
}
|
|
1154
1250
|
function spreadLoad(load, bends) {
|
|
@@ -1307,10 +1403,14 @@ var GameTerrain = (() => {
|
|
|
1307
1403
|
if (nextColumn < 0 || nextRow < 0 || nextColumn > columns || nextRow > rows) continue;
|
|
1308
1404
|
const excess = height - vertexHeight(nextColumn, nextRow) - slope;
|
|
1309
1405
|
if (excess <= SLIDE_EPSILON) continue;
|
|
1406
|
+
const before = dug[index];
|
|
1310
1407
|
const moved = removeFromVertex(index, excess * SLIDE_SHARE);
|
|
1311
1408
|
if (moved <= 0) continue;
|
|
1409
|
+
tallyLowered(slideTally, index, dug[index] - before);
|
|
1312
1410
|
const next = nextRow * stride + nextColumn;
|
|
1411
|
+
const nextBefore = dug[next];
|
|
1313
1412
|
addToVertex(next, moved, isSoftExposed(next));
|
|
1413
|
+
tallyLowered(slideTally, next, dug[next] - nextBefore);
|
|
1314
1414
|
sliding.add(index);
|
|
1315
1415
|
sliding.add(next);
|
|
1316
1416
|
touchVertex(column, row);
|
|
@@ -1324,6 +1424,10 @@ var GameTerrain = (() => {
|
|
|
1324
1424
|
}
|
|
1325
1425
|
}
|
|
1326
1426
|
if (minX <= maxX) emitDeform((minX + maxX) / 2, (minZ + maxZ) / 2, Math.hypot(maxX - minX, maxZ - minZ) / 2 + cellSize * 2);
|
|
1427
|
+
if (sliding.size === 0 && slideTally.size > 0) {
|
|
1428
|
+
emitGroundLoss(slideTally, "slide", SLIDE_LOSS_MIN_LOWERING);
|
|
1429
|
+
slideTally.clear();
|
|
1430
|
+
}
|
|
1327
1431
|
}
|
|
1328
1432
|
function settle(piece) {
|
|
1329
1433
|
const material = materials.get(piece.material);
|
|
@@ -1344,7 +1448,8 @@ var GameTerrain = (() => {
|
|
|
1344
1448
|
case "slash": {
|
|
1345
1449
|
if (!hit.energy) return null;
|
|
1346
1450
|
const contactRadius = hit.type === "blunt" ? hit.radius : void 0;
|
|
1347
|
-
|
|
1451
|
+
const caliber = hit.type === "ballistic" ? hit.caliber : void 0;
|
|
1452
|
+
return strike(hit.type, { x, z, energy: hit.energy, ...hit.direction ? { direction: hit.direction } : {}, ...contactRadius !== void 0 ? { contactRadius } : {}, ...caliber !== void 0 ? { caliber } : {} });
|
|
1348
1453
|
}
|
|
1349
1454
|
case "explosive": {
|
|
1350
1455
|
if (!hit.energy) return null;
|
|
@@ -1409,6 +1514,7 @@ var GameTerrain = (() => {
|
|
|
1409
1514
|
unitDamage.clear();
|
|
1410
1515
|
debrisStore.clear();
|
|
1411
1516
|
sliding.clear();
|
|
1517
|
+
slideTally.clear();
|
|
1412
1518
|
burning.clear();
|
|
1413
1519
|
random = createRandom(seed);
|
|
1414
1520
|
applyLayout(currentLayout);
|
|
@@ -1459,6 +1565,7 @@ var GameTerrain = (() => {
|
|
|
1459
1565
|
burn,
|
|
1460
1566
|
applyHit,
|
|
1461
1567
|
bear: bearAll,
|
|
1568
|
+
voidUnder: (x, z, radius) => voidUnder(grid, { x, z, radius }),
|
|
1462
1569
|
onDeform(listener) {
|
|
1463
1570
|
deformListeners.add(listener);
|
|
1464
1571
|
return () => deformListeners.delete(listener);
|