@adatechnology/game-weapons 0.13.1 → 0.13.3

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 CHANGED
@@ -276,7 +276,7 @@ it goes back off when another tool is taken. The laser measures its distance at
276
276
  `rules.hands` says how many hands each weapon takes and where on the body it goes when the hands are wanted for something else: `twoHanded` (by category: the SMGs, rifles, carbines,
277
277
  shotguns, launchers, bows, the extinguisher; by id: the flamethrower; or a `two_handed` tag) unless it goes one in each hand (`dualWield`), `slots` by category (`hip`: a holster for the
278
278
  handguns, knives, tools and throwables; `back`: a sling for the long guns), `weaponSlots` by id over it, and `bare` (the kick, the shove, the fists: nothing in the hand).
279
- `weaponHandsOf(arsenal, id)` answers `{ hands: 0 | 1 | 2, slot }`; `planHands` of `@adatechnology/game-player` turns it into what happens to the weapon (decision of the owner, 2026-11-24).
279
+ `weaponHandsOf(arsenal, id)` answers `{ hands: 0 | 1 | 2, slot }`; `planHands` of `@adatechnology/game-player` turns it into what happens to the weapon (decision of the owner, 2026-11-24). Rifles, carbines, SMGs, sniper and hunting rifles and shotguns hang on their own `sling` (owner, 2026-11-25); `createSlingSwing(rules?)` is the pendulum a slung gun swings on, in the body's frame: `step(dt, [right, up, forward] acceleration of the sling point)` answers how far it swings `forward` off the chest (never back into it) and to the `side`, damped (`SLING_SWING_DEFAULTS`). Visual only: it moves nothing of the simulation.
280
280
 
281
281
  ### A weapon in each hand
282
282
 
package/dist/index.d.ts CHANGED
@@ -1419,6 +1419,45 @@ interface WeaponHands {
1419
1419
  /** What `rules.hands` of the arsenal says of a weapon; an unknown id is the bare hand. */
1420
1420
  declare function weaponHandsOf(arsenal: Pick<Arsenal, 'weapons' | 'rules'>, weaponId: WeaponId): WeaponHands;
1421
1421
 
1422
+ /**
1423
+ * A long gun hanging on its sling (decision of the owner, 2026-11-25: the rifle is not dropped, it hangs on the body and swings): a pendulum hung from the sling's point on the
1424
+ * chest, in the body's frame. It swings forward off the body and to the sides, never back into the body (`limits`), and settles under its own damping. Engine-agnostic and visual
1425
+ * only (it moves nothing of the simulation): the host gives the acceleration of the sling's point each frame and reads the two angles.
1426
+ */
1427
+ interface SlingSwingRules {
1428
+ /** From the sling's point to the gun's middle (m): the length of the pendulum. */
1429
+ readonly length: number;
1430
+ /** Damping of the swing, per second (a strap rubbing on cloth stops a swing in a second or two). */
1431
+ readonly damping: number;
1432
+ /** Forward off the body (+) is free up to `forward`; back into the body it stops at 0. Sideways up to `side` each way (radians). */
1433
+ readonly limits: {
1434
+ readonly forward: number;
1435
+ readonly side: number;
1436
+ };
1437
+ /** What is kept of the speed when the gun knocks against the body or the end of its swing. */
1438
+ readonly restitution: number;
1439
+ /** Longest step of the integration (s); a longer frame is cut in steps this long. */
1440
+ readonly maxStep: number;
1441
+ readonly gravity: number;
1442
+ }
1443
+ declare const SLING_SWING_DEFAULTS: SlingSwingRules;
1444
+ /** The swing now: `forward` the gun's bottom out from the body (radians about the body's side axis), `side` toward the body's right (about its forward axis). */
1445
+ interface SlingSwingState {
1446
+ readonly forward: number;
1447
+ readonly side: number;
1448
+ }
1449
+ interface SlingSwing {
1450
+ /**
1451
+ * Moves the swing on by `dt` with the sling's point accelerating by `acceleration` in the body's frame (`[right, up, forward]`, m/s²): a body that speeds up leaves the gun
1452
+ * behind (against the body), one that stops throws it forward, a turn swings it to the side.
1453
+ */
1454
+ step(dt: number, acceleration: readonly [number, number, number]): SlingSwingState;
1455
+ readonly state: SlingSwingState;
1456
+ /** Back to hanging still. */
1457
+ reset(): void;
1458
+ }
1459
+ declare function createSlingSwing(rules?: SlingSwingRules): SlingSwing;
1460
+
1422
1461
  /** One group of the weapon menu as a game declares it: the categories it lists, in order, each a section of its own. */
1423
1462
  interface WeaponMenuGroupDef {
1424
1463
  readonly id: string;
@@ -1470,4 +1509,4 @@ declare function genericWeapons(arsenal: Arsenal): ReadonlyMap<WeaponId, WeaponI
1470
1509
  /** A loadout with each generic gun swapped for the real weapon that stands for it (dropped when none does), and no id twice. */
1471
1510
  declare function realLoadout(arsenal: Arsenal, loadout: readonly WeaponId[]): WeaponId[];
1472
1511
 
1473
- export { AMMO, ARCHETYPE_IDS, ATTACHMENTS, type AmmoCore, type AmmoDef, type AmmoJacket, type AmmoKind, type AmmoLoad, type AmmoPenetration, type AmmoQualityDef, type Arsenal, type ArsenalOptions, type AttachmentDef, type AttachmentId, type AttachmentInstall, type AttachmentKind, type BlastEffect, CALIBERS, type CaliberDef, type CaliberId, type CanFit, type CanFitContext, type CartridgeDims, type CaseType, type ConditionDef, DEFAULT_LOADOUT, DEFAULT_RULES, type DataSource, type Detonation, EXPLOSIVES, type EffectCondition, ExplosiveBody, type ExplosiveBodyInit, type ExplosiveChain, type ExplosiveDef, type ExplosiveEvent, type ExplosiveId, type ExplosiveLeak, type ExplosiveShell, type ExplosiveSmoke, type ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, type FitOptions, type FitRefusal, type FitResult, type FittedAttachment, GALLERY_HEAT, type GroundHeight, type GroundSweepHit, type GroundSweepOptions, type IsCompatible, type Loadout, type LoadoutContext, MUZZLE_SMOKE, type MountDef, type MountKind, type MuzzleSmokeParams, type MuzzleSmokeProfile, type MuzzleSmokeProfileId, RELOAD_STAGES, type ReloadFamily, type ReloadKind, type ReloadRequest, type ReloadStage, type ReloadStageId, type RimType, type RoundsToWarningParams, type StatModifier, type StockDef, type StockState, type SurfaceProbe, type TriggerResult, type TripwireSegment, WEAPONS, WEAPON_MENU_GROUPS, type WeaponAction, type WeaponCategory, type WeaponDef, type WeaponDimensions, type WeaponEvent, type WeaponHands, type WeaponId, type WeaponMenuEntry, type WeaponMenuGroup, type WeaponMenuGroupDef, type WeaponMenuOptions, type WeaponMenuSection, type WeaponPatch, type WeaponPhase, type WeaponRules, type WeaponSnapshot, type WeaponStance, type WeaponStat, type WeaponState, type WeaponTimings, type WeaponsLocale, type WeaponsStrings, aimZoomOf, ammoId, ammoIgnition, backblastEffect, barrelMassOf, blastEffect, canDualWield, canFit, canInstallWith, checkArsenal, coolingTimeConstant, createArsenal, createExplosiveBody, createRng, decayHeat, genericWeapons, locales, muzzleEnergy, muzzleSmokeOf, nominalFuse, realLoadout, resolveLoad, resolveLoadout, resolveStrings, roundsToWarning, roundsToWarningOf, sampleFuse, sweepGround, tripwireSegment, weaponHandsOf, weaponMenu };
1512
+ export { AMMO, ARCHETYPE_IDS, ATTACHMENTS, type AmmoCore, type AmmoDef, type AmmoJacket, type AmmoKind, type AmmoLoad, type AmmoPenetration, type AmmoQualityDef, type Arsenal, type ArsenalOptions, type AttachmentDef, type AttachmentId, type AttachmentInstall, type AttachmentKind, type BlastEffect, CALIBERS, type CaliberDef, type CaliberId, type CanFit, type CanFitContext, type CartridgeDims, type CaseType, type ConditionDef, DEFAULT_LOADOUT, DEFAULT_RULES, type DataSource, type Detonation, EXPLOSIVES, type EffectCondition, ExplosiveBody, type ExplosiveBodyInit, type ExplosiveChain, type ExplosiveDef, type ExplosiveEvent, type ExplosiveId, type ExplosiveLeak, type ExplosiveShell, type ExplosiveSmoke, type ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, type FitOptions, type FitRefusal, type FitResult, type FittedAttachment, GALLERY_HEAT, type GroundHeight, type GroundSweepHit, type GroundSweepOptions, type IsCompatible, type Loadout, type LoadoutContext, MUZZLE_SMOKE, type MountDef, type MountKind, type MuzzleSmokeParams, type MuzzleSmokeProfile, type MuzzleSmokeProfileId, RELOAD_STAGES, type ReloadFamily, type ReloadKind, type ReloadRequest, type ReloadStage, type ReloadStageId, type RimType, type RoundsToWarningParams, SLING_SWING_DEFAULTS, type SlingSwing, type SlingSwingRules, type SlingSwingState, type StatModifier, type StockDef, type StockState, type SurfaceProbe, type TriggerResult, type TripwireSegment, WEAPONS, WEAPON_MENU_GROUPS, type WeaponAction, type WeaponCategory, type WeaponDef, type WeaponDimensions, type WeaponEvent, type WeaponHands, type WeaponId, type WeaponMenuEntry, type WeaponMenuGroup, type WeaponMenuGroupDef, type WeaponMenuOptions, type WeaponMenuSection, type WeaponPatch, type WeaponPhase, type WeaponRules, type WeaponSnapshot, type WeaponStance, type WeaponStat, type WeaponState, type WeaponTimings, type WeaponsLocale, type WeaponsStrings, aimZoomOf, ammoId, ammoIgnition, backblastEffect, barrelMassOf, blastEffect, canDualWield, canFit, canInstallWith, checkArsenal, coolingTimeConstant, createArsenal, createExplosiveBody, createRng, createSlingSwing, decayHeat, genericWeapons, locales, muzzleEnergy, muzzleSmokeOf, nominalFuse, realLoadout, resolveLoad, resolveLoadout, resolveStrings, roundsToWarning, roundsToWarningOf, sampleFuse, sweepGround, tripwireSegment, weaponHandsOf, weaponMenu };
@@ -34,6 +34,7 @@ var GameWeapons = (() => {
34
34
  GALLERY_HEAT: () => GALLERY_HEAT,
35
35
  MUZZLE_SMOKE: () => MUZZLE_SMOKE,
36
36
  RELOAD_STAGES: () => RELOAD_STAGES,
37
+ SLING_SWING_DEFAULTS: () => SLING_SWING_DEFAULTS,
37
38
  WEAPONS: () => WEAPONS,
38
39
  WEAPON_MENU_GROUPS: () => WEAPON_MENU_GROUPS,
39
40
  aimZoomOf: () => aimZoomOf,
@@ -50,6 +51,7 @@ var GameWeapons = (() => {
50
51
  createArsenal: () => createArsenal,
51
52
  createExplosiveBody: () => createExplosiveBody,
52
53
  createRng: () => createRng,
54
+ createSlingSwing: () => createSlingSwing,
53
55
  decayHeat: () => decayHeat,
54
56
  genericWeapons: () => genericWeapons,
55
57
  locales: () => locales,
@@ -14886,10 +14888,10 @@ var GameWeapons = (() => {
14886
14888
  // tucking a pistol in the belt and drawing it back is a short motion of one hand
14887
14889
  stowSeconds: 0.45
14888
14890
  },
14889
- // as mãos de cada arma e onde ela vai quando as mãos são pedidas (decisão do dono, 2026-11-24): arma longa pede as duas mãos; a de cinto vai no coldre, a longa na bandoleira ou nas costas
14891
+ // as mãos de cada arma e onde ela vai quando as mãos são pedidas (decisão do dono, 2026-11-24): arma longa pede as duas mãos; a de cinto vai no coldre, a longa na bandoleira ou nas costas; o fuzil e a espingarda pendem da bandoleira (dono, 2026-11-25): sem bandoleira vão para as costas (SLOT_FALLBACKS do game-player)
14890
14892
  hands: {
14891
14893
  twoHanded: { categories: ["smg", "rifle", "carbine", "sniper", "dmr", "hunting", "machine_gun", "launcher", "shotgun", "bow", "crossbow", "extinguisher"], weapons: ["flamethrower"] },
14892
- slots: { pistol: "hip", revolver: "hip", melee_blade: "hip", melee_blunt: "hip", tool: "hip", throwable: "hip", heat: "hip", smg: "back", rifle: "back", carbine: "back", sniper: "back", dmr: "back", hunting: "back", shotgun: "back", bow: "back", crossbow: "back", machine_gun: "back", launcher: "back" },
14894
+ slots: { pistol: "hip", revolver: "hip", melee_blade: "hip", melee_blunt: "hip", tool: "hip", throwable: "hip", heat: "hip", smg: "sling", rifle: "sling", carbine: "sling", sniper: "sling", dmr: "sling", hunting: "sling", shotgun: "sling", bow: "back", crossbow: "back", machine_gun: "back", launcher: "back" },
14893
14895
  // the long-handled tools and the long blade hang across the back; a chainsaw has no place on the body
14894
14896
  weaponSlots: { lighter: "hip", flamethrower: "back", axe: "back", sledgehammer: "back", pickaxe: "back", shovel: "back", katana: "back", chainsaw: null },
14895
14897
  bare: ["kick", "shove", "fists"]
@@ -16748,6 +16750,46 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
16748
16750
  return { hands: isTwoHanded ? 2 : 1, slot: slot ?? null };
16749
16751
  }
16750
16752
 
16753
+ // src/sling-swing.ts
16754
+ var SLING_SWING_DEFAULTS = { length: 0.34, damping: 2.6, limits: { forward: 0.9, side: 0.75 }, restitution: 0.25, maxStep: 1 / 240, gravity: 9.81 };
16755
+ function createSlingSwing(rules = SLING_SWING_DEFAULTS) {
16756
+ let forward = 0;
16757
+ let side = 0;
16758
+ let forwardSpeed = 0;
16759
+ let sideSpeed = 0;
16760
+ const bounce2 = (angle, speed, min, max) => {
16761
+ if (angle < min) return [min, speed < 0 ? -speed * rules.restitution : speed];
16762
+ if (angle > max) return [max, speed > 0 ? -speed * rules.restitution : speed];
16763
+ return [angle, speed];
16764
+ };
16765
+ const substep = (h, acceleration) => {
16766
+ const gravity = Math.max(0.5, rules.gravity + acceleration[1]);
16767
+ const forwardAccel = (-gravity * Math.sin(forward) - acceleration[2] * Math.cos(forward)) / rules.length - rules.damping * forwardSpeed;
16768
+ const sideAccel = (-gravity * Math.sin(side) - acceleration[0] * Math.cos(side)) / rules.length - rules.damping * sideSpeed;
16769
+ forwardSpeed += forwardAccel * h;
16770
+ sideSpeed += sideAccel * h;
16771
+ [forward, forwardSpeed] = bounce2(forward + forwardSpeed * h, forwardSpeed, 0, rules.limits.forward);
16772
+ [side, sideSpeed] = bounce2(side + sideSpeed * h, sideSpeed, -rules.limits.side, rules.limits.side);
16773
+ };
16774
+ return {
16775
+ step(dt, acceleration) {
16776
+ let left = Math.max(0, Math.min(dt, 0.25));
16777
+ while (left > 1e-9) {
16778
+ const h = Math.min(rules.maxStep, left);
16779
+ substep(h, acceleration);
16780
+ left -= h;
16781
+ }
16782
+ return { forward, side };
16783
+ },
16784
+ get state() {
16785
+ return { forward, side };
16786
+ },
16787
+ reset() {
16788
+ forward = side = forwardSpeed = sideSpeed = 0;
16789
+ }
16790
+ };
16791
+ }
16792
+
16751
16793
  // src/generics.ts
16752
16794
  var isGenericKind = (kind, category) => kind === "firearm" && category !== "bow" && category !== "crossbow" || kind === "flame";
16753
16795
  function genericWeapons(arsenal) {