@adatechnology/game-crowd 0.3.0 → 0.4.1

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
@@ -706,6 +706,11 @@ type CrowdBlast = {
706
706
  readonly source?: string;
707
707
  /** Id of the chain this blast belongs to (game-destruction `chain`), for the counters. */
708
708
  readonly chain?: string;
709
+ /**
710
+ * The share (0..1) of the blast that gets to a point through the cover in the way (the host's `blastReach`): the shove and the damage of an agent behind a wall
711
+ * are cut by it. Without it the whole blast reaches every agent.
712
+ */
713
+ readonly reach?: (target: readonly [number, number, number]) => number;
709
714
  };
710
715
  /** The age of a body (G IDADES): its share, and what it does to speed, health, limbs and senses. */
711
716
  type CrowdAge = {
@@ -69,6 +69,7 @@ var GameCrowd = (() => {
69
69
  const length = Math.hypot(direction[0], direction[1], direction[2]);
70
70
  return { speed, direction: [direction[0] / length, direction[1] / length, direction[2] / length], distance, falloff };
71
71
  }
72
+ var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
72
73
  var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
73
74
  var MISSING_BITS = {
74
75
  head: 1,
@@ -1873,6 +1874,7 @@ var GameCrowd = (() => {
1873
1874
 
1874
1875
  // src/physics/blast.ts
1875
1876
  var CENTRE_HEIGHT = 1;
1877
+ var SHELTERED = 0.5;
1876
1878
  var DISMEMBER_SHARE = 0.5;
1877
1879
  var LIMB_CHANCE = 0.5;
1878
1880
  var STUN_BASE = 0.45;
@@ -1911,22 +1913,23 @@ var GameCrowd = (() => {
1911
1913
  emitBlood(tally, i);
1912
1914
  ctx.deferKill(i);
1913
1915
  };
1914
- const hurt = (i, blast, distance, index) => {
1915
- const falloff = (1 - distance / blast.radius) ** 2;
1916
+ const hurt = (i, blast, distance, index, reach = 1) => {
1917
+ const falloff = (1 - distance / blast.radius) ** 2 * reach;
1916
1918
  const amount = blast.energy / 1e3 * options.pointsPerKilojoule * falloff;
1917
1919
  const draw = (salt) => () => unit(store.identity[i], ctx.step, salt);
1918
1920
  if (ctx.damage(i, { region: 1, amount, distance, cut: falloff }, draw(SALT.JAW + index)).died) return true;
1919
1921
  const region = Math.floor(unit(store.identity[i], ctx.step, SALT.REGION + index) * 6);
1920
1922
  return ctx.damage(i, { region, amount: amount / 2, distance, cut: falloff }, draw(SALT.JAW + 8 + index)).died;
1921
1923
  };
1922
- const shoveOf = (i, blasts) => {
1924
+ const shoveOf = (i, blasts, reaches) => {
1923
1925
  const position = [store.x[i], store.y[i] + CENTRE_HEIGHT * store.height[i], store.z[i]];
1924
1926
  let vx = 0;
1925
1927
  let vy = 0;
1926
1928
  let vz = 0;
1927
1929
  let falloff = 0;
1928
- for (const blast of blasts) {
1929
- const shove = blastShove({ point: blast.point, energy: blast.energy, radius: blast.radius }, { position, mass: store.mass[i] }, options.shove);
1930
+ for (let b = 0; b < blasts.length; b++) {
1931
+ const blast = blasts[b];
1932
+ const shove = blastShove({ point: blast.point, energy: blast.energy, radius: blast.radius, reach: reaches?.[b] ?? 1 }, { position, mass: store.mass[i] }, options.shove);
1930
1933
  if (!shove) continue;
1931
1934
  vx += shove.speed * shove.direction[0];
1932
1935
  vy += shove.speed * shove.direction[1];
@@ -1961,16 +1964,19 @@ var GameCrowd = (() => {
1961
1964
  };
1962
1965
  const affect = (i, blasts, tallies, candidates) => {
1963
1966
  let dead = store.hp[i] <= 0;
1967
+ const reaches = blasts.map(
1968
+ (blast) => blast.reach && distanceTo(i, blast) <= blast.radius ? blast.reach([store.x[i], store.y[i] + CENTRE_HEIGHT * store.height[i], store.z[i]]) : 1
1969
+ );
1964
1970
  for (let b = 0; b < blasts.length && !dead; b++) {
1965
1971
  const blast = blasts[b];
1966
1972
  const distance = distanceTo(i, blast);
1967
1973
  if (distance > blast.radius) continue;
1968
1974
  tallies[b].reached++;
1969
- if (blast.lethalRadius !== void 0 && distance < blast.lethalRadius) kill(i, blast, distance, tallies[b]);
1970
- else if (hurt(i, blast, distance, b)) tallies[b].killed++;
1975
+ if (blast.lethalRadius !== void 0 && distance < blast.lethalRadius && reaches[b] >= SHELTERED) kill(i, blast, distance, tallies[b]);
1976
+ else if (hurt(i, blast, distance, b, reaches[b])) tallies[b].killed++;
1971
1977
  dead = store.hp[i] <= 0 || dead;
1972
1978
  }
1973
- const shove = shoveOf(i, blasts);
1979
+ const shove = shoveOf(i, blasts, reaches);
1974
1980
  if (shove) applyShove(i, shove, candidates, tallies, blasts);
1975
1981
  };
1976
1982
  const resolve = () => {