@adatechnology/game-terrain 0.5.2 → 0.6.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 CHANGED
@@ -3,6 +3,15 @@ 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. */
@@ -346,13 +355,7 @@ interface Terrain {
346
355
  normal: [number, number, number];
347
356
  } | null;
348
357
  /** 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;
358
+ strike(blow: TerrainBlow, spec: TerrainStrike): TerrainBlowResult;
356
359
  /** A flame over a disc for `seconds`. */
357
360
  burn(spec: {
358
361
  x: number;
@@ -494,4 +497,4 @@ interface WaterLift {
494
497
  /** 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
498
  declare function waterLift(params: WaterLiftParams): WaterLift;
496
499
 
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 };
500
+ 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 TerrainStrike, type TerrainUnits, type TerrainWater, type TerrainWaterHere, type WaterLift, type WaterLiftParams, crackLines, createFootprints, createTerrain, createTerrainImpl, waterLift };
@@ -573,6 +573,12 @@ var GameTerrain = (() => {
573
573
  var FINE_CELLS = 1.5;
574
574
  var FINE_DEPTH_CELLS = 0.4;
575
575
  var RIGID_WIDENING = 2.5;
576
+ var REFERENCE_CALIBER = 7.62;
577
+ var CALIBER_ASPECT_POWER = 0.5;
578
+ var CALIBER_ASPECT_RANGE = [0.6, 1.6];
579
+ var CALIBERS_ACROSS = 2.5;
580
+ 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;
581
+ var caliberRadius = (caliber) => caliber && caliber > 0 ? caliber / 1e3 * CALIBERS_ACROSS / 2 : 0;
576
582
  var COLLAPSE_DEPTH_SHARE = 0.75;
577
583
  var COLLAPSE_SPREAD_BEND = 0.5;
578
584
  var BARS_SHARE_REACH = 0.6;
@@ -945,16 +951,17 @@ var GameTerrain = (() => {
945
951
  const pastCover = bars !== void 0 && depth - layer.top >= bars.cover - 1e-6;
946
952
  const specificEnergy = response.specificEnergy * (pastCover ? bars.resistance : 1);
947
953
  const limit = bars && !pastCover ? Math.min(room, layer.top + bars.cover - depth) : room;
954
+ const aspect = response.aspect * caliberAspect(spec.caliber);
948
955
  const volume = energy / specificEnergy;
949
- const wanted = Math.cbrt(2 * volume / (Math.PI * response.aspect));
950
- const wantedDepth = wanted * response.aspect;
956
+ const wanted = Math.cbrt(2 * volume / (Math.PI * aspect));
957
+ const wantedDepth = wanted * aspect;
951
958
  const takenDepth = Math.min(wantedDepth, limit);
952
- const takenRadius = takenDepth < wantedDepth ? takenDepth / response.aspect : wanted;
959
+ const takenRadius = takenDepth < wantedDepth ? takenDepth / aspect : wanted;
953
960
  const takenVolume = Math.PI * takenRadius * takenRadius * takenDepth / 2;
954
961
  energy -= takenVolume * specificEnergy;
955
962
  depth += takenDepth;
956
963
  carved += takenDepth;
957
- radius = Math.max(radius, takenRadius, response.minRadius ?? 0, spec.contactRadius ?? 0);
964
+ radius = Math.max(radius, takenRadius, response.minRadius ?? 0, spec.contactRadius ?? 0, caliberRadius(spec.caliber));
958
965
  const last = removed[removed.length - 1];
959
966
  if (last?.material === material.id) last.volume += takenVolume;
960
967
  else removed.push({ material: material.id, volume: takenVolume });
@@ -1010,7 +1017,7 @@ var GameTerrain = (() => {
1010
1017
  const bottom = layer.top + layer.stratum.thickness;
1011
1018
  const miss = { point, radius: 0, depth: 0, totalDepth: layer.top, removed: [], exposed: material.id, atLimit: false, rebarExposed: false, collapsed: false, fine: true };
1012
1019
  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)));
1020
+ 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
1021
  const rowFirst = Math.floor((z - reach) / units.width);
1015
1022
  const rowLast = Math.floor((z + reach) / units.width);
1016
1023
  let loosened = 0;
@@ -1344,7 +1351,8 @@ var GameTerrain = (() => {
1344
1351
  case "slash": {
1345
1352
  if (!hit.energy) return null;
1346
1353
  const contactRadius = hit.type === "blunt" ? hit.radius : void 0;
1347
- return strike(hit.type, { x, z, energy: hit.energy, ...hit.direction ? { direction: hit.direction } : {}, ...contactRadius !== void 0 ? { contactRadius } : {} });
1354
+ const caliber = hit.type === "ballistic" ? hit.caliber : void 0;
1355
+ return strike(hit.type, { x, z, energy: hit.energy, ...hit.direction ? { direction: hit.direction } : {}, ...contactRadius !== void 0 ? { contactRadius } : {}, ...caliber !== void 0 ? { caliber } : {} });
1348
1356
  }
1349
1357
  case "explosive": {
1350
1358
  if (!hit.energy) return null;