quake2ts 0.0.294 → 0.0.296

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.
@@ -6305,7 +6305,7 @@ var FRAME_MACHINEGUN_ACTIVATE_LAST = 3;
6305
6305
  var FRAME_MACHINEGUN_FIRE_LAST = 23;
6306
6306
  var FRAME_MACHINEGUN_IDLE_LAST = 52;
6307
6307
  var FRAME_MACHINEGUN_DEACTIVATE_LAST = 61;
6308
- var FRAME_CHAINGUN_FIRE_FRAME = 5;
6308
+ var FRAME_CHAINGUN_ACTIVATE_LAST = 4;
6309
6309
  var FRAME_CHAINGUN_FIRE_LAST = 21;
6310
6310
  var FRAME_CHAINGUN_IDLE_LAST = 52;
6311
6311
  var FRAME_CHAINGUN_DEACTIVATE_LAST = 61;
@@ -6317,7 +6317,7 @@ var FRAME_ROCKET_ACTIVATE_LAST = 3;
6317
6317
  var FRAME_ROCKET_FIRE_LAST = 12;
6318
6318
  var FRAME_ROCKET_IDLE_LAST = 34;
6319
6319
  var FRAME_ROCKET_DEACTIVATE_LAST = 38;
6320
- var FRAME_HYPERBLASTER_FIRE_FRAME = 6;
6320
+ var FRAME_HYPERBLASTER_ACTIVATE_LAST = 5;
6321
6321
  var FRAME_HYPERBLASTER_FIRE_LAST = 9;
6322
6322
  var FRAME_HYPERBLASTER_IDLE_LAST = 28;
6323
6323
  var FRAME_HYPERBLASTER_DEACTIVATE_LAST = 32;
@@ -6716,7 +6716,7 @@ function Weapon_Generic(ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LA
6716
6716
  if (pause_frames) {
6717
6717
  for (const frame of pause_frames) {
6718
6718
  if (client.gun_frame === frame) {
6719
- if (random2.frandom() < 0.5) {
6719
+ if (random2.frandom() < 0.9375) {
6720
6720
  return;
6721
6721
  }
6722
6722
  }
@@ -6748,12 +6748,13 @@ function Weapon_Generic(ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LA
6748
6748
  return;
6749
6749
  }
6750
6750
  }
6751
- function Weapon_Repeating(ent, FRAME_FIRE_FRAME, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_PAUSE, FRAME_NOOP, fire, sys) {
6751
+ function Weapon_Repeating(ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause_frames, fire, sys) {
6752
6752
  if (!ent.client) return;
6753
6753
  const client = ent.client;
6754
+ const FRAME_FIRE_FIRST = FRAME_ACTIVATE_LAST + 1;
6754
6755
  if (client.weaponstate === 3 /* WEAPON_FIRING */) {
6755
6756
  if (client.gun_frame === FRAME_FIRE_LAST || client.gun_frame === FRAME_IDLE_LAST) {
6756
- client.gun_frame = FRAME_FIRE_FRAME;
6757
+ client.gun_frame = FRAME_FIRE_FIRST;
6757
6758
  } else {
6758
6759
  client.gun_frame++;
6759
6760
  }
@@ -6764,14 +6765,15 @@ function Weapon_Repeating(ent, FRAME_FIRE_FRAME, FRAME_FIRE_LAST, FRAME_IDLE_LAS
6764
6765
  client.gun_frame = FRAME_IDLE_LAST + 1;
6765
6766
  client.weaponstate = 0 /* WEAPON_READY */;
6766
6767
  }
6768
+ client.weapon_think_time = sys.timeSeconds + Weapon_AnimationTime(ent);
6767
6769
  } else {
6768
6770
  Weapon_Generic(
6769
6771
  ent,
6770
- FRAME_FIRE_FRAME - 1,
6772
+ FRAME_ACTIVATE_LAST,
6771
6773
  FRAME_FIRE_LAST,
6772
6774
  FRAME_IDLE_LAST,
6773
- FRAME_PAUSE,
6774
- null,
6775
+ FRAME_DEACTIVATE_LAST,
6776
+ pause_frames,
6775
6777
  null,
6776
6778
  fire,
6777
6779
  sys
@@ -6780,6 +6782,7 @@ function Weapon_Repeating(ent, FRAME_FIRE_FRAME, FRAME_FIRE_LAST, FRAME_IDLE_LAS
6780
6782
  }
6781
6783
 
6782
6784
  // src/combat/weapons/chaingun.ts
6785
+ var CHAINGUN_PAUSE_FRAMES = [38, 43, 51, 61];
6783
6786
  function chaingunThink(player, sys) {
6784
6787
  const weaponState = getWeaponState(player.client.weaponStates, WeaponId.Chaingun);
6785
6788
  if (!(player.client.buttons & BUTTON_ATTACK) && weaponState.spinupCount && weaponState.spinupCount > 0) {
@@ -6788,12 +6791,11 @@ function chaingunThink(player, sys) {
6788
6791
  }
6789
6792
  Weapon_Repeating(
6790
6793
  player,
6791
- FRAME_CHAINGUN_FIRE_FRAME,
6794
+ FRAME_CHAINGUN_ACTIVATE_LAST,
6792
6795
  FRAME_CHAINGUN_FIRE_LAST,
6793
6796
  FRAME_CHAINGUN_IDLE_LAST,
6794
6797
  FRAME_CHAINGUN_DEACTIVATE_LAST,
6795
- 0,
6796
- // FRAME_NOOP
6798
+ CHAINGUN_PAUSE_FRAMES,
6797
6799
  (ent) => fireChaingun(sys.game, ent),
6798
6800
  sys
6799
6801
  );
@@ -6871,12 +6873,12 @@ function rocketLauncherThink(player, sys) {
6871
6873
  function hyperBlasterThink(player, sys) {
6872
6874
  Weapon_Repeating(
6873
6875
  player,
6874
- FRAME_HYPERBLASTER_FIRE_FRAME,
6876
+ FRAME_HYPERBLASTER_ACTIVATE_LAST,
6875
6877
  FRAME_HYPERBLASTER_FIRE_LAST,
6876
6878
  FRAME_HYPERBLASTER_IDLE_LAST,
6877
6879
  FRAME_HYPERBLASTER_DEACTIVATE_LAST,
6878
- 0,
6879
- // FRAME_NOOP
6880
+ null,
6881
+ // No pause frames
6880
6882
  (ent) => fireHyperBlaster(sys.game, ent),
6881
6883
  sys
6882
6884
  );
@@ -6950,6 +6952,178 @@ function blasterThink(player, sys) {
6950
6952
  );
6951
6953
  }
6952
6954
 
6955
+ // src/combat/weapons/chainfist.ts
6956
+ init_esm();
6957
+
6958
+ // src/combat/weapons/common.ts
6959
+ function applyKick2(player, pitch, yaw = 0, kickOrigin = 0) {
6960
+ if (player.client) {
6961
+ player.client.kick_angles = { x: pitch, y: yaw, z: 0 };
6962
+ player.client.kick_origin = { x: kickOrigin, y: 0, z: 0 };
6963
+ }
6964
+ }
6965
+
6966
+ // src/combat/weapons/chainfist.ts
6967
+ var CHAINFIST_REACH = 24;
6968
+ function firePlayerMeleeBoxFilter(check, data) {
6969
+ if (!check.inUse || !check.takedamage || check === data.self) {
6970
+ return false;
6971
+ }
6972
+ const closestPointToBox2 = (p, min, max) => {
6973
+ return {
6974
+ x: Math.max(min.x, Math.min(p.x, max.x)),
6975
+ y: Math.max(min.y, Math.min(p.y, max.y)),
6976
+ z: Math.max(min.z, Math.min(p.z, max.z))
6977
+ };
6978
+ };
6979
+ const closestPointToCheck = closestPointToBox2(
6980
+ data.start,
6981
+ { x: check.origin.x + check.mins.x, y: check.origin.y + check.mins.y, z: check.origin.z + check.mins.z },
6982
+ { x: check.origin.x + check.maxs.x, y: check.origin.y + check.maxs.y, z: check.origin.z + check.maxs.z }
6983
+ );
6984
+ const closestPointToSelf = closestPointToBox2(
6985
+ closestPointToCheck,
6986
+ { x: data.self.origin.x + data.self.mins.x, y: data.self.origin.y + data.self.mins.y, z: data.self.origin.z + data.self.mins.z },
6987
+ { x: data.self.origin.x + data.self.maxs.x, y: data.self.origin.y + data.self.maxs.y, z: data.self.origin.z + data.self.maxs.z }
6988
+ );
6989
+ const dir = subtractVec3(closestPointToCheck, closestPointToSelf);
6990
+ const len = lengthVec3(dir);
6991
+ if (len > data.reach) {
6992
+ return false;
6993
+ }
6994
+ const checkCenter = {
6995
+ x: check.origin.x + (check.mins.x + check.maxs.x) * 0.5,
6996
+ y: check.origin.y + (check.mins.y + check.maxs.y) * 0.5,
6997
+ z: check.origin.z + (check.mins.z + check.maxs.z) * 0.5
6998
+ };
6999
+ const dirToTarget = normalizeVec3(subtractVec3(checkCenter, data.start));
7000
+ if (dotVec3(dirToTarget, data.aim) < 0.7) {
7001
+ if (len > 1) {
7002
+ return false;
7003
+ }
7004
+ }
7005
+ return true;
7006
+ }
7007
+ function firePlayerMelee(game, self, start, aim, reach, damage, kick, mod) {
7008
+ const reachVec = { x: reach, y: reach, z: reach };
7009
+ const absmin = {
7010
+ x: self.origin.x + self.mins.x - reach,
7011
+ y: self.origin.y + self.mins.y - reach,
7012
+ z: self.origin.z + self.mins.z - reach
7013
+ };
7014
+ const absmax = {
7015
+ x: self.origin.x + self.maxs.x + reach,
7016
+ y: self.origin.y + self.maxs.y + reach,
7017
+ z: self.origin.z + self.maxs.z + reach
7018
+ };
7019
+ const candidates = game.entities.findInBox(absmin, absmax);
7020
+ const data = { self, start, aim, reach };
7021
+ let wasHit = false;
7022
+ const closestPointToBox2 = (p, min, max) => {
7023
+ return {
7024
+ x: Math.max(min.x, Math.min(p.x, max.x)),
7025
+ y: Math.max(min.y, Math.min(p.y, max.y)),
7026
+ z: Math.max(min.z, Math.min(p.z, max.z))
7027
+ };
7028
+ };
7029
+ for (const hit of candidates) {
7030
+ if (!firePlayerMeleeBoxFilter(hit, data)) continue;
7031
+ const hitMins = { x: hit.origin.x + hit.mins.x, y: hit.origin.y + hit.mins.y, z: hit.origin.z + hit.mins.z };
7032
+ const hitMaxs = { x: hit.origin.x + hit.maxs.x, y: hit.origin.y + hit.maxs.y, z: hit.origin.z + hit.maxs.z };
7033
+ const closestPoint = closestPointToBox2(start, hitMins, hitMaxs);
7034
+ T_Damage(
7035
+ hit,
7036
+ self,
7037
+ self,
7038
+ aim,
7039
+ closestPoint,
7040
+ scaleVec3(aim, -1),
7041
+ damage,
7042
+ kick / 2,
7043
+ 8 /* NO_KNOCKBACK */,
7044
+ mod,
7045
+ game.time,
7046
+ game.multicast
7047
+ );
7048
+ wasHit = true;
7049
+ }
7050
+ return wasHit;
7051
+ }
7052
+ function chainfistSmoke(game, ent) {
7053
+ const forward = { x: 0, y: 0, z: 0 };
7054
+ const right = { x: 0, y: 0, z: 0 };
7055
+ const up = { x: 0, y: 0, z: 0 };
7056
+ const angles = ent.client ? ent.client.v_angle : ent.angles;
7057
+ const vectors = angleVectors(angles || { x: 0, y: 0, z: 0 });
7058
+ const offset = { x: 8, y: 8, z: -4 };
7059
+ const start = {
7060
+ x: ent.origin.x + ent.viewheight * 0 + vectors.forward.x * offset.x + vectors.right.x * offset.y + vectors.up.x * offset.z,
7061
+ y: ent.origin.y + ent.viewheight * 0 + vectors.forward.y * offset.x + vectors.right.y * offset.y + vectors.up.y * offset.z,
7062
+ z: ent.origin.z + ent.viewheight * 1 + vectors.forward.z * offset.x + vectors.right.z * offset.y + vectors.up.z * offset.z
7063
+ };
7064
+ game.multicast(start, 1 /* Pvs */, ServerCommand.temp_entity, TempEntity.CHAINFIST_SMOKE, start);
7065
+ }
7066
+ function fireChainfist(game, player, inventory, weaponState, start, forward) {
7067
+ let damage = 7;
7068
+ if (game.deathmatch) damage = 15;
7069
+ if (player.client && player.client.quad_time && player.client.quad_time > game.time) {
7070
+ damage *= 4;
7071
+ }
7072
+ const hit = firePlayerMelee(game, player, start, forward, CHAINFIST_REACH, damage, 100, 41 /* CHAINFIST */);
7073
+ if (hit) {
7074
+ }
7075
+ applyKick2(player, -0.5, 0, 0);
7076
+ }
7077
+ function Weapon_ChainFist(player, sys) {
7078
+ const game = sys.game;
7079
+ const pause_frames = [];
7080
+ const fireCallback = (ent) => {
7081
+ const angles = ent.client ? ent.client.v_angle : ent.angles;
7082
+ const vectors = angleVectors(angles || { x: 0, y: 0, z: 0 });
7083
+ const forward = vectors.forward;
7084
+ const start = {
7085
+ x: ent.origin.x,
7086
+ y: ent.origin.y,
7087
+ z: ent.origin.z + (ent.viewheight || 0)
7088
+ };
7089
+ const inventory = ent.client ? ent.client.inventory : { ammo: { counts: [] } };
7090
+ const weaponState = {};
7091
+ fireChainfist(game, ent, inventory, weaponState, start, forward);
7092
+ if (ent.client) {
7093
+ const client = ent.client;
7094
+ const BUTTON_ATTACK2 = 1;
7095
+ const buttons = client.buttons;
7096
+ if (buttons & BUTTON_ATTACK2) {
7097
+ if (client.gun_frame === 12) client.gun_frame = 14;
7098
+ else if (client.gun_frame === 22) client.gun_frame = 24;
7099
+ else if (client.gun_frame >= 32) client.gun_frame = 7;
7100
+ } else {
7101
+ if (client.gun_frame === 13 || client.gun_frame === 23 || client.gun_frame >= 32) {
7102
+ client.gun_frame = 33;
7103
+ }
7104
+ }
7105
+ }
7106
+ };
7107
+ Weapon_Repeating(
7108
+ player,
7109
+ 4,
7110
+ 32,
7111
+ 57,
7112
+ 60,
7113
+ pause_frames,
7114
+ fireCallback,
7115
+ sys
7116
+ );
7117
+ if (player.client) {
7118
+ const gunframe = player.client.gun_frame;
7119
+ if ((gunframe === 42 || gunframe === 51) && Math.random() < 0.125) {
7120
+ if (Math.random() < 0.4) {
7121
+ chainfistSmoke(game, player);
7122
+ }
7123
+ }
7124
+ }
7125
+ }
7126
+
6953
7127
  // src/inventory/items.ts
6954
7128
  var WEAPON_ITEMS = {
6955
7129
  "weapon_blaster": {
@@ -7073,6 +7247,18 @@ var WEAPON_ITEMS = {
7073
7247
  think: bfgThink2
7074
7248
  },
7075
7249
  // Rogue Weapons
7250
+ "weapon_chainfist": {
7251
+ type: "weapon",
7252
+ id: "weapon_chainfist",
7253
+ name: "Chainfist",
7254
+ weaponId: WeaponId.ChainFist,
7255
+ ammoType: null,
7256
+ initialAmmo: 0,
7257
+ pickupAmmo: 0,
7258
+ fireRate: 0.1,
7259
+ // Depends on animation
7260
+ think: Weapon_ChainFist
7261
+ },
7076
7262
  "weapon_boomer": {
7077
7263
  type: "weapon",
7078
7264
  id: "weapon_boomer",
@@ -19290,7 +19476,7 @@ var WEAPONS = {
19290
19476
  };
19291
19477
 
19292
19478
  // src/index.ts
19293
- var ZERO_VEC37 = { x: 0, y: 0, z: 0 };
19479
+ var ZERO_VEC38 = { x: 0, y: 0, z: 0 };
19294
19480
  function createGame(imports, engine, options) {
19295
19481
  const gravity = options.gravity;
19296
19482
  const deathmatch = options.deathmatch ?? false;
@@ -19369,8 +19555,8 @@ function createGame(imports, engine, options) {
19369
19555
  };
19370
19556
  entities.runFrame();
19371
19557
  });
19372
- let origin = { ...ZERO_VEC37 };
19373
- let velocity = { ...ZERO_VEC37 };
19558
+ let origin = { ...ZERO_VEC38 };
19559
+ let velocity = { ...ZERO_VEC38 };
19374
19560
  const calculateBlend = (player, time) => {
19375
19561
  const blend = [0, 0, 0, 0];
19376
19562
  if (!player || !player.client) return blend;
@@ -19452,10 +19638,10 @@ function createGame(imports, engine, options) {
19452
19638
  // TODO
19453
19639
  damageIndicators: [],
19454
19640
  stats: player ? populatePlayerStats(player, levelClock.current.timeSeconds) : [],
19455
- kick_angles: player?.client?.kick_angles ?? ZERO_VEC37,
19456
- kick_origin: player?.client?.kick_origin ?? ZERO_VEC37,
19457
- gunoffset: ZERO_VEC37,
19458
- gunangles: ZERO_VEC37,
19641
+ kick_angles: player?.client?.kick_angles ?? ZERO_VEC38,
19642
+ kick_origin: player?.client?.kick_origin ?? ZERO_VEC38,
19643
+ gunoffset: ZERO_VEC38,
19644
+ gunangles: ZERO_VEC38,
19459
19645
  gunindex: 0,
19460
19646
  gun_frame: player?.client?.gun_frame ?? 0,
19461
19647
  rdflags: player?.client?.rdflags ?? 0,
@@ -19469,8 +19655,8 @@ function createGame(imports, engine, options) {
19469
19655
  const resetState = (startTimeMs) => {
19470
19656
  frameLoop.reset(startTimeMs);
19471
19657
  levelClock.start(startTimeMs);
19472
- origin = { ...ZERO_VEC37 };
19473
- velocity = { ...ZERO_VEC37 };
19658
+ origin = { ...ZERO_VEC38 };
19659
+ velocity = { ...ZERO_VEC38 };
19474
19660
  entities.beginFrame(startTimeMs / 1e3);
19475
19661
  entities.runFrame();
19476
19662
  };
@@ -19498,10 +19684,10 @@ function createGame(imports, engine, options) {
19498
19684
  blend: [0, 0, 0, 0],
19499
19685
  // Stubs
19500
19686
  stats: populatePlayerStats(player, levelClock.current.timeSeconds),
19501
- kick_angles: ZERO_VEC37,
19502
- kick_origin: ZERO_VEC37,
19503
- gunoffset: ZERO_VEC37,
19504
- gunangles: ZERO_VEC37,
19687
+ kick_angles: ZERO_VEC38,
19688
+ kick_origin: ZERO_VEC38,
19689
+ gunoffset: ZERO_VEC38,
19690
+ gunangles: ZERO_VEC38,
19505
19691
  gunindex: 0,
19506
19692
  pm_type: 0,
19507
19693
  pm_time: 0,
@@ -19637,8 +19823,8 @@ function createGame(imports, engine, options) {
19637
19823
  rng,
19638
19824
  player: player?.client?.inventory
19639
19825
  });
19640
- origin = player ? { ...player.origin } : { ...ZERO_VEC37 };
19641
- velocity = player ? { ...player.velocity } : { ...ZERO_VEC37 };
19826
+ origin = player ? { ...player.origin } : { ...ZERO_VEC38 };
19827
+ velocity = player ? { ...player.velocity } : { ...ZERO_VEC38 };
19642
19828
  frameLoop.reset(save.level.timeSeconds * 1e3);
19643
19829
  }
19644
19830
  };