@adatechnology/game-weapons 0.7.0 → 0.8.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/README.md CHANGED
@@ -63,14 +63,25 @@ result.rounds // cartridges spent: a shell is one, a burst is several
63
63
  result.roundTimes // seconds after the start of the call at which each round left the barrel
64
64
  if (result.fault) rifle.clearFault() // 1.2 s; `rifle.fault` stays set until it ends
65
65
  rifle.setSafety(true) // the trigger answers `safe`
66
- rifle.heatLevel // 0..1, from the barrel heat (`rifle.heat`, up to 140)
66
+ rifle.heat // barrel temperature above ambient in °C (up to `rules.heat.cap`, 900)
67
+ rifle.heatLevel // 0..1: that temperature over `rules.heat.displayMax` (750 °C)
67
68
  for (const event of rifle.drain()) animate(event) // draw, shot, misfire, cycle, reload (+ stages, feed), empty, mode, fault, clear, safety
68
69
  ```
69
70
 
70
71
  Each cartridge rolls its own fault from a second generator (`seed ^ 0x6a09e667`), so the spread of a seed does not change when faults are on. The chance is
71
- `condition × faultFactor × (1 + max(0, heat − 60) / 40)` (new 0.3%, used 1.5%, worn 5%, rusty 12%), and reloaded ammunition adds a misfire chance of 8%.
72
+ `condition × faultFactor × (1 + max(0, heat − 350) / 200)` (new 0.3%, used 1.5%, worn 5%, rusty 12%), and reloaded ammunition adds a misfire chance of 8%.
72
73
  A revolver or break-action only misfires (the round is spent, no jam); a pump, bolt or lever fails to extract; the rest stovepipe or double feed.
73
- A bow or crossbow has no cartridge: it adds no heat and never jams. Everything is a number you can change with `rules` (`faults: false` turns jams off,
74
+ A bow or crossbow has no cartridge: it adds no heat and never jams.
75
+
76
+ **Barrel heat is physical** (`rules.heat`): a round adds `share × E / (m × c)` °C, with `E` the muzzle energy of the whole round (every pellet of a shell), `c` = 490 J/(kg·K)
77
+ (steel), `share` the fraction of that energy that ends in the barrel (`barrelShare`, by case type: 0.48 rifle, shell and big, 0.3 pistol and tiny) and `m` the barrel mass: its
78
+ length (`dimensions.barrel`) × kg per metre of the category (`barrelKilogramsPerMetre`: pistol 1, revolver 1.4, smg 1.2, carbine and rifle 1.6, dmr, sniper and hunting 2.4,
79
+ machine gun 3, shotgun 1.1) × `dimensions.barrels` (a rotary gun shares the heat: the M134 has 6). `dimensions.barrelMass` replaces length × kg per metre for a heavy or
80
+ quick-change barrel. The barrel cools by Newton's law, `dT/dt = −T/τ` with `τ = 30 s + 250 s/kg × m`, integrated exactly. From cold an M4 reaches the warning
81
+ (`faultFrom`, 350 °C) after about 130 rounds of rapid fire, an FN MAG or PKM after 200 to 300 at 100 rounds a minute, an M134 after more than 1100, and a pistol or a bolt
82
+ rifle at a bolt pace never does. Past it the fault chance grows to double at 550 °C (`faultSpan` 200); smoke starts at 250 °C and the red glow at 450 °C
83
+ (`rules.heat.visual`). `roundsToWarningOf(arsenal, weaponId)` gives the rounds to the warning at the weapon's listed rate (the test room bench shows it). `GALLERY_HEAT`
84
+ keeps the abstract units of the Galeria 3D do Arsenal (`rules.heat.gallery`) for the recorded runs. Everything is a number you can change with `rules` (`faults: false` turns jams off,
74
85
  `faultChance` takes a function), and the order of the reload steps is in `RELOAD_STAGES`.
75
86
 
76
87
  Real models point to a generic `archetype` for the handling numbers (spread, bloom, range, recoil); `patch`, `remove` and `include` change the shipped
package/dist/index.d.ts CHANGED
@@ -368,7 +368,7 @@ interface AmmoQualityDef {
368
368
  interface FaultContext {
369
369
  readonly def: WeaponDef;
370
370
  readonly condition: ConditionDef;
371
- /** Heat of the weapon, 0 to `rules.heat.cap`. */
371
+ /** Barrel temperature above ambient in °C. */
372
372
  readonly heat: number;
373
373
  }
374
374
  /** Numbers that rule how weapons behave in a game; override any of them with `ArsenalOptions.rules`. */
@@ -379,22 +379,47 @@ interface WeaponRules {
379
379
  readonly ammoQualities: readonly AmmoQualityDef[];
380
380
  readonly defaultAmmoQuality: string;
381
381
  readonly faultChance: (context: FaultContext) => number;
382
+ /** Barrel temperature above ambient, in °C. A round adds `share x muzzle energy / (barrel mass x specificHeat)`; the barrel cools by Newton's law with a time constant that grows with its mass. */
382
383
  readonly heat: {
384
+ /** Highest temperature above ambient the barrel can reach. */
383
385
  readonly cap: number;
386
+ /** The temperature the display shows as full (`heatLevel` 1). */
384
387
  readonly displayMax: number;
385
- readonly decayBase: number;
386
- readonly decayPerPoint: number;
388
+ /** The warning: from here the weapon is hot enough to fail (the fault chance grows by `1 / faultSpan` per °C). */
387
389
  readonly faultFrom: number;
388
390
  readonly faultSpan: number;
389
- readonly perShot: Readonly<Record<CaseType, number>>;
391
+ /** J/(kg·K) of the barrel steel. */
392
+ readonly specificHeat: number;
393
+ /** Fraction of the muzzle energy of a round that ends as heat in the barrel, by cartridge case. */
394
+ readonly barrelShare: Readonly<Record<CaseType, number>>;
395
+ /** Barrel kg per metre of barrel length, by category. */
396
+ readonly barrelKilogramsPerMetre: Readonly<Partial<Record<WeaponCategory, number>>>;
397
+ /** What a weapon with no barrel length or no listed category is given. */
398
+ readonly barrelFallback: {
399
+ readonly metres: number;
400
+ readonly kilogramsPerMetre: number;
401
+ };
402
+ /** Cooling time constant in seconds: `baseSeconds + secondsPerKilogram x barrel mass`. */
403
+ readonly cooling: {
404
+ readonly baseSeconds: number;
405
+ readonly secondsPerKilogram: number;
406
+ };
407
+ /** °C a rocket launch adds to the tube. */
390
408
  readonly perRocket: number;
391
- /** What the player sees of the heat: wisps of smoke only while the barrel is above `smokeFrom` and for `smokeSeconds` after the last shot; the red glow from `glowFrom` over `glowSpan` points. */
409
+ /** What the player sees of the heat: wisps of smoke only while the barrel is above `smokeFrom` and for `smokeSeconds` after the last shot, thicker over `smokeSpan` °C; the red glow from `glowFrom` over `glowSpan` °C. */
392
410
  readonly visual: {
393
411
  readonly smokeFrom: number;
412
+ readonly smokeSpan: number;
394
413
  readonly smokeSeconds: number;
395
414
  readonly glowFrom: number;
396
415
  readonly glowSpan: number;
397
416
  };
417
+ /** The abstract units the Galeria 3D do Arsenal recorded (a fixed amount per case and linear cooling); when present they replace the physical model, so the recorded runs stay reproducible. */
418
+ readonly gallery?: {
419
+ readonly perShot: Readonly<Record<CaseType, number>>;
420
+ readonly decayBase: number;
421
+ readonly decayPerPoint: number;
422
+ };
398
423
  };
399
424
  /** Each shot in the last `window` seconds raises the noise radius by `step`, up to `cap`. */
400
425
  readonly noiseBurst: {
@@ -693,6 +718,10 @@ interface WeaponDimensions {
693
718
  readonly barrel: number;
694
719
  readonly emptyMass: number;
695
720
  readonly lengthCollapsed?: number;
721
+ /** Barrels that share the heat (a rotary gun: 6). Default 1. */
722
+ readonly barrels?: number;
723
+ /** Mass in kg of one barrel; replaces barrel length times the kg per metre of the category (a heavy or quick-change barrel). */
724
+ readonly barrelMass?: number;
696
725
  }
697
726
  /** What using the item does. Firearms produce ballistic shots; the rest produce one `Use` of their kind. */
698
727
  type WeaponAction = {
@@ -910,9 +939,9 @@ interface WeaponState {
910
939
  readonly clearing: boolean;
911
940
  /** With the safety on the trigger does nothing. */
912
941
  readonly safety: boolean;
913
- /** Heat of the barrel, 0 to `rules.heat.cap`. */
942
+ /** Barrel temperature above ambient in °C, 0 to `rules.heat.cap`. */
914
943
  readonly heat: number;
915
- /** 0 to 1: the heat against what the display shows as full. */
944
+ /** 0 to 1: the temperature against `rules.heat.displayMax`. */
916
945
  readonly heatLevel: number;
917
946
  readonly condition: string;
918
947
  readonly ammoQuality: string;
@@ -1149,11 +1178,31 @@ declare const DEFAULT_LOADOUT: WeaponId[];
1149
1178
  */
1150
1179
  declare const createArsenal: (options?: ArsenalOptions) => Arsenal;
1151
1180
 
1152
- /** The heat the Galeria 3D do Arsenal recorded (hotter per round: a magazine was enough to glow); kept so the recorded runs stay reproducible. */
1181
+ /** The heat the Galeria 3D do Arsenal recorded (abstract units, hotter per round: a magazine was enough to glow); kept so the recorded runs stay reproducible. */
1153
1182
  declare const GALLERY_HEAT: WeaponRules['heat'];
1154
1183
  /** The rules the kit ships with; a game overrides any of them through `ArsenalOptions.rules`. */
1155
1184
  declare const DEFAULT_RULES: WeaponRules;
1156
1185
 
1186
+ type HeatRules = WeaponRules['heat'];
1187
+ /** Kg of steel that heat up with the shots: barrel length times kg per metre of the category (or the weapon's own `barrelMass`), times the barrels a rotary gun shares. */
1188
+ declare const barrelMassOf: (def: WeaponDef, rules: HeatRules) => number;
1189
+ /** Seconds in which the barrel loses 1/e of its excess temperature. */
1190
+ declare const coolingTimeConstant: (barrelMass: number, rules: HeatRules) => number;
1191
+ /** Cools a barrel: Newton's law, dT/dt = -T/tau, integrated exactly (the Galeria's linear Euler steps when `rules.gallery` is set). */
1192
+ declare const decayHeat: (heat: number, seconds: number, barrelMass: number, rules: HeatRules) => number;
1193
+ type RoundsToWarningParams = {
1194
+ readonly def: WeaponDef;
1195
+ readonly caliber: CaliberDef;
1196
+ /** Muzzle energy of one round in joules (one pellet when `caliber.pellets` says more). */
1197
+ readonly energy: number;
1198
+ readonly rpm: number;
1199
+ readonly rules: HeatRules;
1200
+ };
1201
+ /** Rounds fired from cold at `rpm`, with no pause for reloads, before the barrel reaches the warning; Infinity when the cooling holds it below. */
1202
+ declare const roundsToWarning: ({ def, caliber, energy, rpm, rules }: RoundsToWarningParams) => number;
1203
+ /** `roundsToWarning` for a weapon of the arsenal, from the muzzle energy of its own calibre and barrel at its listed rate of fire; Infinity for what has no cartridge or never heats up that far. */
1204
+ declare const roundsToWarningOf: (arsenal: Pick<Arsenal, "weapons" | "calibers" | "rules">, weaponId: string) => number;
1205
+
1157
1206
  interface BlastEffect {
1158
1207
  /** `lethal` kills and dismembers, `injury` wounds, `none` is out of reach (or behind a directional charge). */
1159
1208
  readonly zone: 'lethal' | 'injury' | 'none';
@@ -1311,4 +1360,4 @@ declare function genericWeapons(arsenal: Arsenal): ReadonlyMap<WeaponId, WeaponI
1311
1360
  /** A loadout with each generic gun swapped for the real weapon that stands for it (dropped when none does), and no id twice. */
1312
1361
  declare function realLoadout(arsenal: Arsenal, loadout: readonly WeaponId[]): WeaponId[];
1313
1362
 
1314
- 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 ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, type FitOptions, type FitRefusal, type FitResult, type FittedAttachment, GALLERY_HEAT, 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 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 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, blastEffect, canFit, canInstallWith, checkArsenal, createArsenal, createExplosiveBody, createRng, genericWeapons, locales, muzzleEnergy, muzzleSmokeOf, nominalFuse, realLoadout, resolveLoad, resolveLoadout, resolveStrings, sampleFuse, tripwireSegment, weaponMenu };
1363
+ 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 ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, type FitOptions, type FitRefusal, type FitResult, type FittedAttachment, GALLERY_HEAT, 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 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, canFit, canInstallWith, checkArsenal, coolingTimeConstant, createArsenal, createExplosiveBody, createRng, decayHeat, genericWeapons, locales, muzzleEnergy, muzzleSmokeOf, nominalFuse, realLoadout, resolveLoad, resolveLoadout, resolveStrings, roundsToWarning, roundsToWarningOf, sampleFuse, tripwireSegment, weaponMenu };
@@ -40,13 +40,16 @@ var GameWeapons = (() => {
40
40
  ammoId: () => ammoId,
41
41
  ammoIgnition: () => ammoIgnition,
42
42
  backblastEffect: () => backblastEffect,
43
+ barrelMassOf: () => barrelMassOf,
43
44
  blastEffect: () => blastEffect,
44
45
  canFit: () => canFit,
45
46
  canInstallWith: () => canInstallWith,
46
47
  checkArsenal: () => checkArsenal,
48
+ coolingTimeConstant: () => coolingTimeConstant,
47
49
  createArsenal: () => createArsenal,
48
50
  createExplosiveBody: () => createExplosiveBody,
49
51
  createRng: () => createRng,
52
+ decayHeat: () => decayHeat,
50
53
  genericWeapons: () => genericWeapons,
51
54
  locales: () => locales,
52
55
  muzzleEnergy: () => muzzleEnergy,
@@ -56,6 +59,8 @@ var GameWeapons = (() => {
56
59
  resolveLoad: () => resolveLoad,
57
60
  resolveLoadout: () => resolveLoadout,
58
61
  resolveStrings: () => resolveStrings,
62
+ roundsToWarning: () => roundsToWarning,
63
+ roundsToWarningOf: () => roundsToWarningOf,
59
64
  sampleFuse: () => sampleFuse,
60
65
  tripwireSegment: () => tripwireSegment,
61
66
  weaponMenu: () => weaponMenu
@@ -11885,7 +11890,9 @@ var GameWeapons = (() => {
11885
11890
  dimensions: {
11886
11891
  length: 0.801,
11887
11892
  barrel: 0.559,
11888
- emptyMass: 39
11893
+ emptyMass: 39,
11894
+ barrels: 6,
11895
+ barrelMass: 2
11889
11896
  },
11890
11897
  archetype: "rifle_7_62x39",
11891
11898
  sources: [
@@ -12881,19 +12888,41 @@ var GameWeapons = (() => {
12881
12888
 
12882
12889
  // src/rules.ts
12883
12890
  var DEFAULT_HEAT = {
12884
- cap: 140,
12885
- displayMax: 120,
12886
- decayBase: 1.6,
12887
- decayPerPoint: 0.03,
12888
- faultFrom: 60,
12889
- faultSpan: 40,
12890
- perShot: { shell: 3, big: 6, tiny: 0.5, pistol: 1.2, rifle: 2 },
12891
+ cap: 900,
12892
+ displayMax: 750,
12893
+ faultFrom: 350,
12894
+ faultSpan: 200,
12895
+ specificHeat: 490,
12896
+ barrelShare: { shell: 0.48, big: 0.48, tiny: 0.3, pistol: 0.3, rifle: 0.48 },
12897
+ barrelKilogramsPerMetre: {
12898
+ pistol: 1,
12899
+ revolver: 1.4,
12900
+ smg: 1.2,
12901
+ carbine: 1.6,
12902
+ rifle: 1.6,
12903
+ dmr: 2.4,
12904
+ sniper: 2.4,
12905
+ hunting: 2.4,
12906
+ machine_gun: 3,
12907
+ shotgun: 1.1
12908
+ },
12909
+ barrelFallback: { metres: 0.4, kilogramsPerMetre: 1.6 },
12910
+ cooling: { baseSeconds: 30, secondsPerKilogram: 250 },
12891
12911
  perRocket: 35,
12892
- visual: { smokeFrom: 70, smokeSeconds: 2.5, glowFrom: 80, glowSpan: 40 }
12912
+ visual: { smokeFrom: 250, smokeSpan: 300, smokeSeconds: 2.5, glowFrom: 450, glowSpan: 300 }
12893
12913
  };
12894
12914
  var GALLERY_HEAT = {
12895
12915
  ...DEFAULT_HEAT,
12896
- perShot: { shell: 6, big: 9, tiny: 1.2, pistol: 3, rifle: 4.5 }
12916
+ cap: 140,
12917
+ displayMax: 120,
12918
+ faultFrom: 60,
12919
+ faultSpan: 40,
12920
+ visual: { smokeFrom: 70, smokeSpan: 100, smokeSeconds: 2.5, glowFrom: 80, glowSpan: 40 },
12921
+ gallery: {
12922
+ perShot: { shell: 6, big: 9, tiny: 1.2, pistol: 3, rifle: 4.5 },
12923
+ decayBase: 1.6,
12924
+ decayPerPoint: 0.03
12925
+ }
12897
12926
  };
12898
12927
  var defaultFaultChance = (context) => {
12899
12928
  const factor = context.def.action.kind === "firearm" ? context.def.action.faultFactor ?? 1 : 1;
@@ -13183,18 +13212,79 @@ var GameWeapons = (() => {
13183
13212
  };
13184
13213
  };
13185
13214
 
13215
+ // src/fire.ts
13216
+ var EPS2 = 1e-9;
13217
+ var MANUAL_MODES = /* @__PURE__ */ new Set(["pump", "bolt", "lever"]);
13218
+ var weaponSpeed = (action, caliber) => action.muzzleSpeed ?? caliber.muzzleSpeed * (action.barrel ?? 1);
13219
+ var weaponNoise = (action, caliber) => action.noise ?? caliber.noise ?? 0;
13220
+ var timingsOf = (action) => "timings" in action ? action.timings : void 0;
13221
+ var drawSeconds = (action, rules) => timingsOf(action)?.draw ?? rules.draw;
13222
+ var clearSeconds = (action, rules) => timingsOf(action)?.clear ?? rules.clear;
13223
+ var manualCycleSeconds = (action, mode) => MANUAL_MODES.has(mode) ? action.timings?.cycle ?? 0 : 0;
13224
+ var planRounds = (action, mode, ammo, firstAt, frameEnd) => {
13225
+ const interval = 60 / action.rpm;
13226
+ const times = [];
13227
+ if (mode === "auto") {
13228
+ for (let t = firstAt; times.length < ammo && (times.length === 0 ? t <= frameEnd + EPS2 : t < frameEnd - EPS2); t += interval) times.push(t);
13229
+ return times;
13230
+ }
13231
+ if (mode === "burst") {
13232
+ const count = Math.min(action.burst ?? 3, ammo);
13233
+ for (let k = 0; k < count; k++) times.push(firstAt + k * interval);
13234
+ return times;
13235
+ }
13236
+ if (mode === "volley") return Array.from({ length: Math.min(action.magazine, ammo) }, () => firstAt);
13237
+ return [firstAt];
13238
+ };
13239
+
13186
13240
  // src/heat.ts
13187
13241
  var SUBSTEP_SECONDS = 1 / 60;
13188
- var decayHeat = (heat, seconds, rules) => {
13242
+ var MAX_ROUNDS_SEARCHED = 1e5;
13243
+ var barrelMassOf = (def, rules) => {
13244
+ const dimensions = def.dimensions;
13245
+ const kilogramsPerMetre = rules.barrelKilogramsPerMetre[def.category] ?? rules.barrelFallback.kilogramsPerMetre;
13246
+ const single = dimensions?.barrelMass ?? (dimensions?.barrel ?? rules.barrelFallback.metres) * kilogramsPerMetre;
13247
+ return single * (dimensions?.barrels ?? 1);
13248
+ };
13249
+ var coolingTimeConstant = (barrelMass, rules) => rules.cooling.baseSeconds + rules.cooling.secondsPerKilogram * barrelMass;
13250
+ var decayHeat = (heat, seconds, barrelMass, rules) => {
13251
+ if (heat <= 0) return 0;
13252
+ if (rules.gallery) return decayGallery(heat, seconds, rules.gallery);
13253
+ return heat * Math.exp(-seconds / coolingTimeConstant(barrelMass, rules));
13254
+ };
13255
+ var decayGallery = (heat, seconds, gallery) => {
13189
13256
  const steps = Math.max(1, Math.ceil(seconds / SUBSTEP_SECONDS - 1e-9));
13190
13257
  const step = seconds / steps;
13191
13258
  let current = heat;
13192
- for (let i = 0; i < steps && current > 0; i++) current = Math.max(0, current - step * (rules.decayBase + current * rules.decayPerPoint));
13259
+ for (let i = 0; i < steps && current > 0; i++) current = Math.max(0, current - step * (gallery.decayBase + current * gallery.decayPerPoint));
13193
13260
  return current;
13194
13261
  };
13195
- var heatPerRound = (action, caliber, rules) => {
13262
+ var heatPerRound = ({ action, caliber, energy, barrelMass, rules }) => {
13196
13263
  if (action.kind === "launcher") return rules.perRocket;
13197
- return caliber?.caseType ? rules.perShot[caliber.caseType] : 0;
13264
+ const caseType = caliber?.caseType;
13265
+ if (!caseType) return 0;
13266
+ if (rules.gallery) return rules.gallery.perShot[caseType];
13267
+ return rules.barrelShare[caseType] * energy / (barrelMass * rules.specificHeat);
13268
+ };
13269
+ var roundsToWarning = ({ def, caliber, energy, rpm, rules }) => {
13270
+ if (def.action.kind !== "firearm" || rpm <= 0) return Infinity;
13271
+ const barrelMass = barrelMassOf(def, rules);
13272
+ const perRound = heatPerRound({ action: def.action, caliber, energy: energy * (caliber.pellets ?? 1), barrelMass, rules });
13273
+ const interval = 60 / rpm;
13274
+ let heat = 0;
13275
+ for (let round = 1; round <= MAX_ROUNDS_SEARCHED; round++) {
13276
+ heat = decayHeat(heat, round === 1 ? 0 : interval, barrelMass, rules) + perRound;
13277
+ if (heat >= rules.faultFrom) return round;
13278
+ }
13279
+ return Infinity;
13280
+ };
13281
+ var roundsToWarningOf = (arsenal, weaponId) => {
13282
+ const def = arsenal.weapons.get(weaponId);
13283
+ if (!def || def.action.kind !== "firearm") return Infinity;
13284
+ const caliber = arsenal.calibers.get(def.action.caliber);
13285
+ if (!caliber) return Infinity;
13286
+ const energy = 0.5 * (caliber.bulletGrams / 1e3) * weaponSpeed(def.action, caliber) ** 2;
13287
+ return roundsToWarning({ def, caliber, energy, rpm: def.action.rpm, rules: arsenal.rules.heat });
13198
13288
  };
13199
13289
  var burstNoise = (base, recentShots, rules) => base * (1 + Math.min(rules.cap, rules.step * recentShots));
13200
13290
 
@@ -13328,31 +13418,6 @@ var GameWeapons = (() => {
13328
13418
  };
13329
13419
  var isDudWithoutJam = (action, fault) => fault === "misfire" && action.kind === "firearm" && MISFIRE_ONLY.has(action.family);
13330
13420
 
13331
- // src/fire.ts
13332
- var EPS2 = 1e-9;
13333
- var MANUAL_MODES = /* @__PURE__ */ new Set(["pump", "bolt", "lever"]);
13334
- var weaponSpeed = (action, caliber) => action.muzzleSpeed ?? caliber.muzzleSpeed * (action.barrel ?? 1);
13335
- var weaponNoise = (action, caliber) => action.noise ?? caliber.noise ?? 0;
13336
- var timingsOf = (action) => "timings" in action ? action.timings : void 0;
13337
- var drawSeconds = (action, rules) => timingsOf(action)?.draw ?? rules.draw;
13338
- var clearSeconds = (action, rules) => timingsOf(action)?.clear ?? rules.clear;
13339
- var manualCycleSeconds = (action, mode) => MANUAL_MODES.has(mode) ? action.timings?.cycle ?? 0 : 0;
13340
- var planRounds = (action, mode, ammo, firstAt, frameEnd) => {
13341
- const interval = 60 / action.rpm;
13342
- const times = [];
13343
- if (mode === "auto") {
13344
- for (let t = firstAt; times.length < ammo && (times.length === 0 ? t <= frameEnd + EPS2 : t < frameEnd - EPS2); t += interval) times.push(t);
13345
- return times;
13346
- }
13347
- if (mode === "burst") {
13348
- const count = Math.min(action.burst ?? 3, ammo);
13349
- for (let k = 0; k < count; k++) times.push(firstAt + k * interval);
13350
- return times;
13351
- }
13352
- if (mode === "volley") return Array.from({ length: Math.min(action.magazine, ammo) }, () => firstAt);
13353
- return [firstAt];
13354
- };
13355
-
13356
13421
  // src/attachment-effects.ts
13357
13422
  var activeParts = (fitted, catalogue) => fitted.flatMap((part) => {
13358
13423
  const def = catalogue.get(part.id);
@@ -13599,6 +13664,10 @@ var GameWeapons = (() => {
13599
13664
  get safety() {
13600
13665
  return this._safety;
13601
13666
  }
13667
+ /** Kg of steel that heat up with the shots. */
13668
+ get barrelMass() {
13669
+ return barrelMassOf(this.def, this.rules.heat);
13670
+ }
13602
13671
  get heat() {
13603
13672
  return this._heat;
13604
13673
  }
@@ -13651,7 +13720,7 @@ var GameWeapons = (() => {
13651
13720
  }
13652
13721
  advance(seconds) {
13653
13722
  if (seconds <= 0) return;
13654
- this._heat = decayHeat(this._heat, seconds, this.rules.heat);
13723
+ this._heat = decayHeat(this._heat, seconds, this.barrelMass, this.rules.heat);
13655
13724
  this.clock += seconds;
13656
13725
  }
13657
13726
  /** Complete what falls at or before `t`: scheduled events and the reload steps. */
@@ -14214,7 +14283,7 @@ var GameWeapons = (() => {
14214
14283
  res.shots.push(shot);
14215
14284
  }
14216
14285
  this._ammo -= 1;
14217
- this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound(a, cal, this.rules.heat) * this.load.heatFactor);
14286
+ this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound({ action: a, caliber: cal, energy: energy * pellets, barrelMass: this.barrelMass, rules: this.rules.heat }) * this.load.heatFactor);
14218
14287
  this.readyAt = t + 60 / a.rpm;
14219
14288
  this.extra = Math.min(bloomNow + (a.bloomDeg ?? 0), a.spreadDeg * (BLOOM_CAP - 1));
14220
14289
  this.extraClock = t;
@@ -14305,7 +14374,7 @@ var GameWeapons = (() => {
14305
14374
  }
14306
14375
  const t = Math.max(start, this.readyAt);
14307
14376
  this._ammo -= 1;
14308
- this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound(a, null, this.rules.heat));
14377
+ this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound({ action: a, caliber: null, energy: 0, barrelMass: this.barrelMass, rules: this.rules.heat }));
14309
14378
  this.emit({ type: "shot", shots: 0, rounds: 1, mode: this.mode, at: t });
14310
14379
  return result("ok", { uses: launcherUses(a, this.explosive, origin, dir), recoil: [a.recoil[0], a.recoil[1]], noise: a.noise ?? 0, rounds: 1, roundTimes: [t - start] });
14311
14380
  }