@adatechnology/game-vehicles 0.2.0 → 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
@@ -2,6 +2,9 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
 
5
+ // src/kit.ts
6
+ import { shapeGeometries } from "@adatechnology/game-shapes-three";
7
+
5
8
  // src/locales/en.json
6
9
  var en_default = {
7
10
  plate: {
@@ -9915,7 +9918,7 @@ function createVehicleKit(options) {
9915
9918
  const opts = options || {};
9916
9919
  if (!opts.THREE || !opts.THREE.Vector3) throw new Error("createVehicleKit: options.THREE (the three.js namespace) is required");
9917
9920
  const lod = createLod(opts.lod);
9918
- const THREE = wrapThreeForLod(opts.THREE, lod);
9921
+ const THREE = wrapThreeForLod(shapeGeometries(opts.THREE), lod);
9919
9922
  const strings = resolveStrings(opts.locale);
9920
9923
  const t = createTranslate(strings);
9921
9924
  const doc = opts.document || (typeof document !== "undefined" ? document : void 0);
@@ -10176,6 +10179,9 @@ function createVehicleKit(options) {
10176
10179
  return kit;
10177
10180
  }
10178
10181
 
10182
+ // src/destructible/impl.ts
10183
+ import { ignitionChance, resolveIgnitionRules, sparkTargetFactor } from "@adatechnology/game-contracts";
10184
+
10179
10185
  // src/destructible/model.ts
10180
10186
  var JOINT_RULES = {
10181
10187
  hinge: { strength: 5e3, tools: ["wrench", "screwdriver"], seconds: 3 },
@@ -11288,6 +11294,9 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
11288
11294
  const headless = !!options.headless;
11289
11295
  const seedBase = strHash(`${c.key}|${id}|${options.seed ?? 0}`);
11290
11296
  let rand = rng(seedBase);
11297
+ const ignitionRules = resolveIgnitionRules(options.ignition);
11298
+ const fuelFraction = clamp(options.fuel ?? 1, 0, 1);
11299
+ let igniteRand = rng(strHash(`${c.key}|${id}|ignition|${options.seed ?? 0}`));
11291
11300
  let clock = 0;
11292
11301
  let model;
11293
11302
  let vis = null;
@@ -11355,7 +11364,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
11355
11364
  dents: [],
11356
11365
  holes: [],
11357
11366
  cracks: [],
11358
- liters: d.contains?.liters,
11367
+ liters: d.contains ? d.role === "fuel_tank" ? d.contains.liters * fuelFraction : d.contains.liters : void 0,
11359
11368
  lost: false,
11360
11369
  status: "intact",
11361
11370
  flat: false,
@@ -11373,6 +11382,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
11373
11382
  wasLit = true;
11374
11383
  deadEngine = false;
11375
11384
  rand = rng(seedBase);
11385
+ igniteRand = rng(strHash(`${c.key}|${id}|ignition|${options.seed ?? 0}`));
11376
11386
  steerSign = rand() < 0.5 ? -1 : 1;
11377
11387
  vis = headless ? null : new VehicleVisuals(kit, c, model);
11378
11388
  recomputeGroups();
@@ -11667,8 +11677,19 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
11667
11677
  if (!p.burning && p.temp > AMBIENT) p.temp = Math.max(AMBIENT, p.temp - dt * 6);
11668
11678
  }
11669
11679
  for (const f of flames) heat(centreOf(f.def), 0.8, 500, dt * 0.5, out, 0);
11680
+ fireNearLeak(flames, dt, out);
11670
11681
  thermal(out);
11671
11682
  };
11683
+ const fireNearLeak = (flames, dt, out) => {
11684
+ const tank = tankPart();
11685
+ const leak = tank ? leaks.get(tank.def.id) : void 0;
11686
+ if (!tank || !leak || tank.lost || tank.burning || exploded || leak.fluid !== "fuel" && leak.fluid !== "diesel") return;
11687
+ if (leak.pud?.fire) return light(tank, out);
11688
+ const { radius, chancePerSecond } = ignitionRules.fireNear;
11689
+ if (chancePerSecond <= 0) return;
11690
+ const near = flames.some((f) => f !== tank && distToBox(tank.def, centreOf(f.def)) - Math.max(...f.def.box.size) / 2 <= radius);
11691
+ if (near && igniteRand() < 1 - Math.exp(-chancePerSecond * dt)) light(tank, out);
11692
+ };
11672
11693
  const normalOf = (d, v) => faceNormal(d, v);
11673
11694
  const ballistic = (h, out) => {
11674
11695
  sync();
@@ -11736,10 +11757,21 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
11736
11757
  let amount = through ? E * 0.6 : E * 0.25;
11737
11758
  if (through && (d.role === "battery" || d.role === "alternator")) amount = Math.max(amount, p.hp * 0.65);
11738
11759
  damage(p, amount, "ballistic", h.source, out, worldPoint);
11739
- if (d.role === "fuel_tank" && E > 1500 && (p.liters ?? 0) > 1) p.temp = Math.max(p.temp, d.ignitionC ?? 260);
11760
+ if (through && d.role === "fuel_tank") rollIgnition(p, h, metal, out);
11740
11761
  }
11741
11762
  }
11742
11763
  };
11764
+ const light = (tank, out) => {
11765
+ tank.temp = Math.max(tank.temp, (tank.def.ignitionC ?? 260) + 1);
11766
+ if ((tank.liters ?? 0) > 0.5) ignite(tank, out);
11767
+ };
11768
+ const rollIgnition = (tank, h, metal, out) => {
11769
+ const d = tank.def;
11770
+ if (!d.contains || tank.burning || (tank.liters ?? 0) <= 0.05) return;
11771
+ const fill = d.contains.liters > 0 ? (tank.liters ?? 0) / d.contains.liters : 0;
11772
+ const chance = ignitionChance(h, { sparkTarget: sparkTargetFactor(d.material, metal, ignitionRules), fill, fluid: d.contains.fluid }, ignitionRules);
11773
+ if (chance > 0 && igniteRand() < chance) light(tank, out);
11774
+ };
11743
11775
  const blunt = (h, out) => {
11744
11776
  sync();
11745
11777
  const M = toFrameMatrix();
@@ -11803,7 +11835,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
11803
11835
  const verdict = kit.blastDamage(c, E / (1 + dist * dist * 4) / 50);
11804
11836
  if (verdict === "explosion") explode(tank, h.source, out);
11805
11837
  else if (verdict === "fire") {
11806
- tank.temp = Math.max(tank.temp, tank.def.ignitionC ?? 260);
11838
+ light(tank, out);
11807
11839
  startLeak(tank, centreOf(tank.def).setY(tank.def.box.center[1] - tank.def.box.size[1] / 2 + 0.05), 12, out, dir);
11808
11840
  }
11809
11841
  }