@adatechnology/game-terrain 0.3.2 → 0.5.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/README.md +1 -1
- package/dist/index.d.ts +21 -2
- package/dist/index.global.js +95 -11
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +95 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ terrain.heightAt(x, z) // what things stand on
|
|
|
12
12
|
|
|
13
13
|
## What it does
|
|
14
14
|
|
|
15
|
-
- **Profiles** (`TERRAIN_PROFILES`, replace or add through `profiles`): `lawn` (turf 5 cm, soil 1.5 m, rock), `dirt`, `sand`, `road` (asphalt 5 cm, gravel, soil), `concrete_slab` (12 cm with rebar at 3 cm), `tile_floor` (tile, mortar, slab), `wood_floor`, `stone_paving`, `mud`, `gravel_bed`, `dry_clay`, `snow`, `cobblestone`, `paver_floor`, `shallow_water
|
|
15
|
+
- **Profiles** (`TERRAIN_PROFILES`, replace or add through `profiles`): `lawn` (turf 5 cm, soil 1.5 m, rock), `dirt`, `sand`, `road` (asphalt 5 cm, gravel, soil), `concrete_slab` (12 cm with rebar at 3 cm), `tile_floor` (tile, mortar, slab), `wood_floor`, `stone_paving`, `mud`, `gravel_bed`, `dry_clay`, `snow`, `cobblestone`, `paver_floor`, `shallow_water`, `bedrock` (bare rock).
|
|
16
16
|
- **Digging**: a blow removes `energy / specificEnergy` cubic metres (`TERRAIN_MATERIALS`, per blow type: ballistic, blunt, slash, explosive) as a bowl with the shape of the material. It takes the top stratum and spends what is left on the next. The strata end at the digging limit: **a slab is never pierced**, and a crater has a floor.
|
|
17
17
|
- **Bars**: bare bars bend with each blow and give way at `yieldJoules`. A slab on the ground stays the floor; `suspended_slab` (`TerrainProfile.drop`) opens onto the floor below.
|
|
18
18
|
- **Fine marks**: a bowl under 1.5 cells stays a mark, not a change of the height field. Blows on the same mark grow it until it is dug in.
|
package/dist/index.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ interface TerrainFireResponse {
|
|
|
86
86
|
/** Catches and carries the fire to the next cells on its own. */
|
|
87
87
|
readonly flammable?: boolean;
|
|
88
88
|
}
|
|
89
|
-
declare const TERRAIN_PATTERNS: readonly ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone", "mud", "gravel", "clay", "snow", "cobble", "paver"];
|
|
89
|
+
declare const TERRAIN_PATTERNS: readonly ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone", "mud", "gravel", "clay", "snow", "cobble", "paver", "rock"];
|
|
90
90
|
type TerrainPattern = (typeof TERRAIN_PATTERNS)[number];
|
|
91
91
|
/** One layer of a column, from the top down. */
|
|
92
92
|
interface TerrainStratum {
|
|
@@ -102,14 +102,28 @@ interface TerrainStratum {
|
|
|
102
102
|
readonly resistance: number;
|
|
103
103
|
/** Joules on one spot of bare bars before they give way (default `DEFAULT_BAR_YIELD_JOULES`). */
|
|
104
104
|
readonly yieldJoules?: number;
|
|
105
|
+
/** Metres across one bar (default `DEFAULT_BAR_DIAMETER`): with `yieldPa` it says what weight bare bars hold. */
|
|
106
|
+
readonly diameter?: number;
|
|
107
|
+
/** Pascals at which the steel yields (default `DEFAULT_BAR_YIELD_PA`). */
|
|
108
|
+
readonly yieldPa?: number;
|
|
105
109
|
};
|
|
106
110
|
}
|
|
111
|
+
/** Weight standing still on the ground: a body, a fridge, a car. */
|
|
112
|
+
interface TerrainLoad {
|
|
113
|
+
readonly x: number;
|
|
114
|
+
readonly z: number;
|
|
115
|
+
/** Metres: half the side of the footprint it stands on. */
|
|
116
|
+
readonly radius: number;
|
|
117
|
+
readonly newtons: number;
|
|
118
|
+
}
|
|
107
119
|
/** What a column of ground is made of. The strata end at the digging limit: under them nothing is removed. */
|
|
108
120
|
interface TerrainProfile {
|
|
109
121
|
readonly id: string;
|
|
110
122
|
readonly strata: readonly TerrainStratum[];
|
|
111
123
|
/** A slab with nothing under it: where its bars give way the floor opens, and the ground is this many metres further down (the floor below). Without it the ground under the slab holds it up. */
|
|
112
124
|
readonly drop?: number;
|
|
125
|
+
/** How the untouched top layer is drawn when it is not its material's way: bare rock is stone, but not laid as paving. Dug, the material's own shows. */
|
|
126
|
+
readonly surfacePattern?: TerrainPattern;
|
|
113
127
|
/** Water standing over the column: the strata are its bed. */
|
|
114
128
|
readonly water?: TerrainWater;
|
|
115
129
|
}
|
|
@@ -349,6 +363,8 @@ interface Terrain {
|
|
|
349
363
|
}): void;
|
|
350
364
|
/** Applies a world hit (`Hit` of the destruction contract); null when it does nothing to the ground. */
|
|
351
365
|
applyHit(hit: Hit): TerrainBlowResult | null;
|
|
366
|
+
/** 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
|
+
bear(loads: readonly TerrainLoad[]): boolean;
|
|
352
368
|
/** Height a foot stands at: the ground less what it sinks in. */
|
|
353
369
|
footAt(x: number, z: number): number;
|
|
354
370
|
/** What is left of the walking speed here, 0..1. */
|
|
@@ -422,6 +438,9 @@ declare const TERRAIN_MATERIALS: readonly TerrainMaterial[];
|
|
|
422
438
|
declare const TERRAIN_PROFILES: readonly TerrainProfile[];
|
|
423
439
|
/** About twelve grenades (200 kJ) on the same spot of bare bars. */
|
|
424
440
|
declare const DEFAULT_BAR_YIELD_JOULES = 2400000;
|
|
441
|
+
/** A 10 mm bar of CA-50 steel: bare, a mesh of them at 15 cm holds about 450 kg on a spot. */
|
|
442
|
+
declare const DEFAULT_BAR_DIAMETER = 0.01;
|
|
443
|
+
declare const DEFAULT_BAR_YIELD_PA = 500000000;
|
|
425
444
|
/** The profile of a floor with nothing else said: a plain slab. */
|
|
426
445
|
declare const DEFAULT_PROFILE = "concrete_slab";
|
|
427
446
|
|
|
@@ -475,4 +494,4 @@ interface WaterLift {
|
|
|
475
494
|
/** 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. */
|
|
476
495
|
declare function waterLift(params: WaterLiftParams): WaterLift;
|
|
477
496
|
|
|
478
|
-
export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_YIELD_JOULES, 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 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 };
|
|
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 };
|
package/dist/index.global.js
CHANGED
|
@@ -22,7 +22,9 @@ var GameTerrain = (() => {
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
CRACK_REFERENCE_JOULES: () => CRACK_REFERENCE_JOULES,
|
|
25
|
+
DEFAULT_BAR_DIAMETER: () => DEFAULT_BAR_DIAMETER,
|
|
25
26
|
DEFAULT_BAR_YIELD_JOULES: () => DEFAULT_BAR_YIELD_JOULES,
|
|
27
|
+
DEFAULT_BAR_YIELD_PA: () => DEFAULT_BAR_YIELD_PA,
|
|
26
28
|
DEFAULT_PROFILE: () => DEFAULT_PROFILE,
|
|
27
29
|
DEFAULT_TERRAIN_BUDGET: () => DEFAULT_TERRAIN_BUDGET,
|
|
28
30
|
TERRAIN_MATERIALS: () => TERRAIN_MATERIALS,
|
|
@@ -274,10 +276,14 @@ var GameTerrain = (() => {
|
|
|
274
276
|
{ id: "dry_clay", strata: [{ material: "clay", thickness: 0.35 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
|
|
275
277
|
{ id: "snow", strata: [{ material: "snow", thickness: 0.3 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
|
|
276
278
|
{ id: "cobblestone", strata: [{ material: "cobble", thickness: 0.12 }, { material: "sand", thickness: 0.06 }, { material: "gravel", thickness: 0.2 }, { material: "soil", thickness: 1.2 }] },
|
|
279
|
+
// rock at the surface (an outcrop, a quarry floor): a blast only spalls it and a shot chips it
|
|
280
|
+
{ id: "bedrock", surfacePattern: "rock", strata: [{ material: "stone", thickness: 3 }] },
|
|
277
281
|
{ 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
282
|
{ 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 }] }
|
|
279
283
|
];
|
|
280
284
|
var DEFAULT_BAR_YIELD_JOULES = 24e5;
|
|
285
|
+
var DEFAULT_BAR_DIAMETER = 0.01;
|
|
286
|
+
var DEFAULT_BAR_YIELD_PA = 5e8;
|
|
281
287
|
var DEFAULT_PROFILE = "concrete_slab";
|
|
282
288
|
|
|
283
289
|
// src/random.ts
|
|
@@ -569,6 +575,7 @@ var GameTerrain = (() => {
|
|
|
569
575
|
var RIGID_WIDENING = 2.5;
|
|
570
576
|
var COLLAPSE_DEPTH_SHARE = 0.75;
|
|
571
577
|
var COLLAPSE_SPREAD_BEND = 0.5;
|
|
578
|
+
var BARS_SHARE_REACH = 0.6;
|
|
572
579
|
var RIM_REACH = 1.45;
|
|
573
580
|
var FLAME_MINIMUM = 200;
|
|
574
581
|
var FLAME_REACH = 0.6;
|
|
@@ -1088,19 +1095,95 @@ var GameTerrain = (() => {
|
|
|
1088
1095
|
}
|
|
1089
1096
|
}
|
|
1090
1097
|
}
|
|
1091
|
-
if (collapsed)
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1098
|
+
if (collapsed) giveWay({ x, z, reach, profile });
|
|
1099
|
+
return collapsed;
|
|
1100
|
+
}
|
|
1101
|
+
function giveWay(spec) {
|
|
1102
|
+
const { x, z, reach, profile } = spec;
|
|
1103
|
+
emitDeform(x, z, reach);
|
|
1104
|
+
if (profile.drop === void 0) return;
|
|
1105
|
+
const limit = maxDepthOfProfile(profile);
|
|
1106
|
+
const column0 = clampIndex(Math.floor((x - reach - x0) / cellSize), columns);
|
|
1107
|
+
const column1 = clampIndex(Math.ceil((x + reach - x0) / cellSize), columns);
|
|
1108
|
+
const row0 = clampIndex(Math.floor((z - reach - z0) / cellSize), rows);
|
|
1109
|
+
const row1 = clampIndex(Math.ceil((z + reach - z0) / cellSize), rows);
|
|
1110
|
+
for (let row = row0; row <= row1; row++) {
|
|
1111
|
+
for (let column = column0; column <= column1; column++) {
|
|
1112
|
+
const index = row * stride + column;
|
|
1113
|
+
if (barBend[index] >= COLLAPSE_SPREAD_BEND && dug[index] < limit + profile.drop) {
|
|
1114
|
+
dug[index] = limit + profile.drop;
|
|
1115
|
+
touchVertex(column, row);
|
|
1100
1116
|
}
|
|
1101
1117
|
}
|
|
1102
1118
|
}
|
|
1103
|
-
|
|
1119
|
+
}
|
|
1120
|
+
function barsOf(profile) {
|
|
1121
|
+
const bars = profile.strata.find((stratum) => stratum.reinforcement);
|
|
1122
|
+
if (!bars?.reinforcement) return null;
|
|
1123
|
+
let cover = bars.reinforcement.cover;
|
|
1124
|
+
for (const stratum of profile.strata) {
|
|
1125
|
+
if (stratum === bars) break;
|
|
1126
|
+
cover += stratum.thickness;
|
|
1127
|
+
}
|
|
1128
|
+
return { stratum: bars, cover };
|
|
1129
|
+
}
|
|
1130
|
+
function bearAll(loads) {
|
|
1131
|
+
const bends = /* @__PURE__ */ new Map();
|
|
1132
|
+
const touched2 = [];
|
|
1133
|
+
for (const load of loads) {
|
|
1134
|
+
const spread = spreadLoad(load, bends);
|
|
1135
|
+
if (spread) touched2.push({ load, ...spread });
|
|
1136
|
+
}
|
|
1137
|
+
let opened = false;
|
|
1138
|
+
for (const [index, bend] of bends) {
|
|
1139
|
+
if (barBend[index] >= bend) continue;
|
|
1140
|
+
barBend[index] = bend;
|
|
1141
|
+
const column = index % stride;
|
|
1142
|
+
const row = (index - column) / stride;
|
|
1143
|
+
touchVertex(column, row);
|
|
1144
|
+
const profile = profileList[profileIndex[index]];
|
|
1145
|
+
const limit = maxDepthOfProfile(profile);
|
|
1146
|
+
if (bend >= 1 && profile.drop !== void 0 && dug[index] >= limit * COLLAPSE_DEPTH_SHARE && dug[index] < limit + profile.drop) {
|
|
1147
|
+
dug[index] = limit + profile.drop;
|
|
1148
|
+
opened = true;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
if (opened) for (const { load, reach, profile } of touched2) giveWay({ x: load.x, z: load.z, reach, profile });
|
|
1152
|
+
return opened;
|
|
1153
|
+
}
|
|
1154
|
+
function spreadLoad(load, bends) {
|
|
1155
|
+
if (!contains(load.x, load.z) || load.newtons <= 0) return null;
|
|
1156
|
+
const profile = profileList[profileIndex[vertexOf(load.x, load.z).index]];
|
|
1157
|
+
const bars = barsOf(profile);
|
|
1158
|
+
if (!bars) return null;
|
|
1159
|
+
const reinforcement = bars.stratum.reinforcement;
|
|
1160
|
+
const moment = (reinforcement.yieldPa ?? DEFAULT_BAR_YIELD_PA) * (reinforcement.diameter ?? DEFAULT_BAR_DIAMETER) ** 3 / 6;
|
|
1161
|
+
const holds = 8 * moment / reinforcement.spacing;
|
|
1162
|
+
const footprint = load.radius * Math.SQRT2 + cellSize;
|
|
1163
|
+
const reach = Math.max(footprint, BARS_SHARE_REACH);
|
|
1164
|
+
const column0 = clampIndex(Math.floor((load.x - reach - x0) / cellSize), columns);
|
|
1165
|
+
const column1 = clampIndex(Math.ceil((load.x + reach - x0) / cellSize), columns);
|
|
1166
|
+
const row0 = clampIndex(Math.floor((load.z - reach - z0) / cellSize), rows);
|
|
1167
|
+
const row1 = clampIndex(Math.ceil((load.z + reach - z0) / cellSize), rows);
|
|
1168
|
+
const bare = [];
|
|
1169
|
+
let under = 0;
|
|
1170
|
+
let onBars = 0;
|
|
1171
|
+
for (let row = row0; row <= row1; row++) {
|
|
1172
|
+
for (let column = column0; column <= column1; column++) {
|
|
1173
|
+
const distance = Math.hypot(x0 + column * cellSize - load.x, z0 + row * cellSize - load.z);
|
|
1174
|
+
if (distance >= reach) continue;
|
|
1175
|
+
const index = row * stride + column;
|
|
1176
|
+
const isBare = dug[index] >= bars.cover;
|
|
1177
|
+
if (isBare) bare.push(index);
|
|
1178
|
+
if (distance >= footprint) continue;
|
|
1179
|
+
under++;
|
|
1180
|
+
if (isBare) onBars++;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (onBars === 0) return null;
|
|
1184
|
+
const bend = load.newtons * (onBars / under) / holds;
|
|
1185
|
+
for (const index of bare) bends.set(index, (bends.get(index) ?? 0) + bend);
|
|
1186
|
+
return { reach, profile };
|
|
1104
1187
|
}
|
|
1105
1188
|
const maxDepthOfProfile = (profile) => maxDepthOf[indexOfProfile.get(profile.id)];
|
|
1106
1189
|
function rebarShowing(profile, depth) {
|
|
@@ -1375,6 +1458,7 @@ var GameTerrain = (() => {
|
|
|
1375
1458
|
strike,
|
|
1376
1459
|
burn,
|
|
1377
1460
|
applyHit,
|
|
1461
|
+
bear: bearAll,
|
|
1378
1462
|
onDeform(listener) {
|
|
1379
1463
|
deformListeners.add(listener);
|
|
1380
1464
|
return () => deformListeners.delete(listener);
|
|
@@ -1522,7 +1606,7 @@ var GameTerrain = (() => {
|
|
|
1522
1606
|
}
|
|
1523
1607
|
|
|
1524
1608
|
// src/types.ts
|
|
1525
|
-
var TERRAIN_PATTERNS = ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone", "mud", "gravel", "clay", "snow", "cobble", "paver"];
|
|
1609
|
+
var TERRAIN_PATTERNS = ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone", "mud", "gravel", "clay", "snow", "cobble", "paver", "rock"];
|
|
1526
1610
|
|
|
1527
1611
|
// src/footprints.ts
|
|
1528
1612
|
var STRIDE = 0.72;
|