@adatechnology/game-crowd 0.3.0 → 0.4.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
@@ -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 = {
@@ -1873,6 +1873,7 @@ var GameCrowd = (() => {
1873
1873
 
1874
1874
  // src/physics/blast.ts
1875
1875
  var CENTRE_HEIGHT = 1;
1876
+ var SHELTERED = 0.5;
1876
1877
  var DISMEMBER_SHARE = 0.5;
1877
1878
  var LIMB_CHANCE = 0.5;
1878
1879
  var STUN_BASE = 0.45;
@@ -1911,22 +1912,23 @@ var GameCrowd = (() => {
1911
1912
  emitBlood(tally, i);
1912
1913
  ctx.deferKill(i);
1913
1914
  };
1914
- const hurt = (i, blast, distance, index) => {
1915
- const falloff = (1 - distance / blast.radius) ** 2;
1915
+ const hurt = (i, blast, distance, index, reach = 1) => {
1916
+ const falloff = (1 - distance / blast.radius) ** 2 * reach;
1916
1917
  const amount = blast.energy / 1e3 * options.pointsPerKilojoule * falloff;
1917
1918
  const draw = (salt) => () => unit(store.identity[i], ctx.step, salt);
1918
1919
  if (ctx.damage(i, { region: 1, amount, distance, cut: falloff }, draw(SALT.JAW + index)).died) return true;
1919
1920
  const region = Math.floor(unit(store.identity[i], ctx.step, SALT.REGION + index) * 6);
1920
1921
  return ctx.damage(i, { region, amount: amount / 2, distance, cut: falloff }, draw(SALT.JAW + 8 + index)).died;
1921
1922
  };
1922
- const shoveOf = (i, blasts) => {
1923
+ const shoveOf = (i, blasts, reaches) => {
1923
1924
  const position = [store.x[i], store.y[i] + CENTRE_HEIGHT * store.height[i], store.z[i]];
1924
1925
  let vx = 0;
1925
1926
  let vy = 0;
1926
1927
  let vz = 0;
1927
1928
  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);
1929
+ for (let b = 0; b < blasts.length; b++) {
1930
+ const blast = blasts[b];
1931
+ const shove = blastShove({ point: blast.point, energy: blast.energy, radius: blast.radius, reach: reaches?.[b] ?? 1 }, { position, mass: store.mass[i] }, options.shove);
1930
1932
  if (!shove) continue;
1931
1933
  vx += shove.speed * shove.direction[0];
1932
1934
  vy += shove.speed * shove.direction[1];
@@ -1961,16 +1963,19 @@ var GameCrowd = (() => {
1961
1963
  };
1962
1964
  const affect = (i, blasts, tallies, candidates) => {
1963
1965
  let dead = store.hp[i] <= 0;
1966
+ const reaches = blasts.map(
1967
+ (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
1968
+ );
1964
1969
  for (let b = 0; b < blasts.length && !dead; b++) {
1965
1970
  const blast = blasts[b];
1966
1971
  const distance = distanceTo(i, blast);
1967
1972
  if (distance > blast.radius) continue;
1968
1973
  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++;
1974
+ if (blast.lethalRadius !== void 0 && distance < blast.lethalRadius && reaches[b] >= SHELTERED) kill(i, blast, distance, tallies[b]);
1975
+ else if (hurt(i, blast, distance, b, reaches[b])) tallies[b].killed++;
1971
1976
  dead = store.hp[i] <= 0 || dead;
1972
1977
  }
1973
- const shove = shoveOf(i, blasts);
1978
+ const shove = shoveOf(i, blasts, reaches);
1974
1979
  if (shove) applyShove(i, shove, candidates, tallies, blasts);
1975
1980
  };
1976
1981
  const resolve = () => {