@adatechnology/game-destruction 0.1.1 → 0.3.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.js CHANGED
@@ -1408,9 +1408,12 @@ var fragility = (ductility, thickness) => {
1408
1408
  var DMG_PER_J = 0.02;
1409
1409
  var BLAST_COUPLING = 0.1;
1410
1410
  var FLAMMABLE_FLUIDS = ["gas", "fuel"];
1411
+ var CUT_SLICE = 1;
1412
+ var cutFactorOf = (shape) => clamp2(Math.max(...shapeDims(shape)) / CUT_SLICE, 1, 50);
1411
1413
  var clamp2 = (v, a, b) => Math.max(a, Math.min(b, v));
1412
1414
  var isLost = (p) => p.st.status === "broken" || p.st.status === "melted" || p.st.status === "ashes";
1413
1415
  var clone = (v) => structuredClone(v);
1416
+ var overloadRate = (stress) => Math.min(0.6, 0.12 + 0.8 * (stress - 1));
1414
1417
  var updateBound = (o) => {
1415
1418
  if (!o.parts.length) return;
1416
1419
  const c = [0, 0, 0];
@@ -1560,6 +1563,7 @@ var createDestruction = (options = {}) => {
1560
1563
  fuel0,
1561
1564
  area: shapeArea(ps.shape),
1562
1565
  thickness: partThickness(ps),
1566
+ cutFactor: cutFactorOf(ps.shape),
1563
1567
  dims: shapeDims(ps.shape),
1564
1568
  bound: shapeBound(ps.shape),
1565
1569
  rt: c?.rt ?? { ...freshRuntime(), prevTemp: pst.temperature },
@@ -1720,7 +1724,10 @@ var createDestruction = (options = {}) => {
1720
1724
  for (const g of o.st.groups) {
1721
1725
  const ps = g.map((id) => o.byId.get(id)).filter((p) => !isLost(p) && !o.collapsed.has(p.spec.id));
1722
1726
  if (ps.length === 0 || g.some((id) => o.byId.get(id).anchored) || !ps.some((p) => p.structural)) continue;
1723
- for (const p of ps) o.collapsed.add(p.spec.id);
1727
+ for (const p of ps) {
1728
+ o.collapsed.add(p.spec.id);
1729
+ p.st.status = "collapsed";
1730
+ }
1724
1731
  emit({ ...base(o, src), type: "collapse", parts: ps.map((p) => p.spec.id), mass: ps.reduce((sum, p) => sum + p.st.mass, 0) });
1725
1732
  }
1726
1733
  }
@@ -2020,7 +2027,7 @@ var createDestruction = (options = {}) => {
2020
2027
  const effM = p.thickness / Math.max(sin, 0.3);
2021
2028
  const thr = mat.penetration * effM * 1e3;
2022
2029
  const penetrated = E > thr;
2023
- const scale = mat.damageScale?.ballistic ?? 1;
2030
+ const scale = (mat.damageScale?.ballistic ?? 1) * (mat.fracture === "shatter" ? fragility(mat.ductility, p.thickness) : 1);
2024
2031
  const id = p.spec.id;
2025
2032
  if (!penetrated && mat.ricochetDeg && angle < mat.ricochetDeg) {
2026
2033
  const r = vec.sub(d, vec.scale(n, 2 * vec.dot(d, n)));
@@ -2081,7 +2088,7 @@ var createDestruction = (options = {}) => {
2081
2088
  if (kind === "blunt") wearJoints(o, p, E * 0.3, void 0, 0, src);
2082
2089
  else wearJoints(o, p, E * 0.3, point, 0.06, src);
2083
2090
  const scale = mat.damageScale?.[kind] ?? 1;
2084
- return applyDamage(o, p, Ec * DMG_PER_J * scale, kind, point, d, E * 0.1, 12, src);
2091
+ return applyDamage(o, p, Ec * DMG_PER_J * scale * (kind === "slash" ? p.cutFactor : 1), kind, point, d, E * 0.1, 12, src);
2085
2092
  };
2086
2093
  const blastObject = (o, point, energy, radius, src) => {
2087
2094
  const start = cur.length;
@@ -2370,7 +2377,7 @@ var createDestruction = (options = {}) => {
2370
2377
  p.rt.stressT = 0.5;
2371
2378
  emit({ ...base(o), type: "stress", part: p.spec.id, stress, load: p.st.load ?? 0 });
2372
2379
  }
2373
- applyDamage(o, p, (stress - 1) * p.st.maxHp * 0.5 * dt, "blunt", null, null, 5, 3);
2380
+ applyDamage(o, p, overloadRate(stress) * p.st.maxHp * dt, "blunt", null, null, 5, 3);
2374
2381
  } else if (stress > 0.8 && p.mat.ductility < 0.3 && p.rt.stressT <= 0 && p.st.cracks.length < 6) {
2375
2382
  p.rt.stressT = 0.5;
2376
2383
  const { c, q } = partXf(o, p);
@@ -2832,6 +2839,47 @@ var buildFrame = (o = {}) => {
2832
2839
  return { name: "frame", parts, joints, tags: ["structure"] };
2833
2840
  };
2834
2841
 
2842
+ // src/size.ts
2843
+ var sizeStructure = (spec, options = {}) => {
2844
+ const safety = options.safety ?? 0.65;
2845
+ const redundancy = options.redundancy;
2846
+ const loads = (s) => {
2847
+ const w = createDestruction(options.materials ? { materials: options.materials } : {});
2848
+ const id = w.add(s);
2849
+ return new Map(w.state(id).parts.map((p) => [p.id, { load: p.load ?? 0, stress: p.stress ?? 0 }]));
2850
+ };
2851
+ const out = structuredClone(spec);
2852
+ const base = loads(out);
2853
+ const need = /* @__PURE__ */ new Map();
2854
+ for (const p of out.parts) {
2855
+ if (!p.structure || p.structure.role === "none") continue;
2856
+ const b = base.get(p.id);
2857
+ if (!b || b.stress <= 0) continue;
2858
+ need.set(p.id, b.load / safety);
2859
+ }
2860
+ if (redundancy !== void 0) {
2861
+ for (const col of out.parts) {
2862
+ if (col.structure?.role !== "column") continue;
2863
+ const reduced = {
2864
+ ...out,
2865
+ parts: out.parts.filter((p) => p.id !== col.id),
2866
+ joints: (out.joints ?? []).filter((j) => j.a !== col.id && j.b !== col.id)
2867
+ };
2868
+ if (!out.joints) delete reduced.joints;
2869
+ const l = loads(reduced);
2870
+ for (const [id, n] of need) {
2871
+ const r = l.get(id);
2872
+ if (r && r.stress > 0) need.set(id, Math.max(n, r.load / redundancy));
2873
+ }
2874
+ }
2875
+ }
2876
+ for (const p of out.parts) {
2877
+ const n = need.get(p.id);
2878
+ if (n !== void 0) p.structure = { ...p.structure, capacity: n };
2879
+ }
2880
+ return out;
2881
+ };
2882
+
2835
2883
  // src/locale.ts
2836
2884
  var locales = {
2837
2885
  en: {
@@ -2864,7 +2912,7 @@ var locales = {
2864
2912
  wax: "wax",
2865
2913
  soil: "soil"
2866
2914
  },
2867
- partStatus: { intact: "intact", damaged: "damaged", broken: "broken", melted: "melted", ashes: "ashes" },
2915
+ partStatus: { intact: "intact", damaged: "damaged", collapsed: "collapsed", broken: "broken", melted: "melted", ashes: "ashes" },
2868
2916
  jointKinds: {
2869
2917
  screw: "screw",
2870
2918
  bolt: "nut and bolt",
@@ -2945,7 +2993,7 @@ var locales = {
2945
2993
  wax: "cera",
2946
2994
  soil: "terra"
2947
2995
  },
2948
- partStatus: { intact: "intacto", damaged: "danificado", broken: "quebrado", melted: "derretido", ashes: "cinzas" },
2996
+ partStatus: { intact: "intacto", damaged: "danificado", collapsed: "desabado", broken: "quebrado", melted: "derretido", ashes: "cinzas" },
2949
2997
  jointKinds: {
2950
2998
  screw: "parafuso",
2951
2999
  bolt: "porca e parafuso",
@@ -3027,6 +3075,7 @@ export {
3027
3075
  quatFromEuler,
3028
3076
  resolveStrings,
3029
3077
  rotateVec,
3078
+ sizeStructure,
3030
3079
  toLocal,
3031
3080
  toWorld,
3032
3081
  vec