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.
@@ -6464,7 +6464,7 @@ var FRAME_MACHINEGUN_ACTIVATE_LAST = 3;
6464
6464
  var FRAME_MACHINEGUN_FIRE_LAST = 23;
6465
6465
  var FRAME_MACHINEGUN_IDLE_LAST = 52;
6466
6466
  var FRAME_MACHINEGUN_DEACTIVATE_LAST = 61;
6467
- var FRAME_CHAINGUN_FIRE_FRAME = 5;
6467
+ var FRAME_CHAINGUN_ACTIVATE_LAST = 4;
6468
6468
  var FRAME_CHAINGUN_FIRE_LAST = 21;
6469
6469
  var FRAME_CHAINGUN_IDLE_LAST = 52;
6470
6470
  var FRAME_CHAINGUN_DEACTIVATE_LAST = 61;
@@ -6476,7 +6476,7 @@ var FRAME_ROCKET_ACTIVATE_LAST = 3;
6476
6476
  var FRAME_ROCKET_FIRE_LAST = 12;
6477
6477
  var FRAME_ROCKET_IDLE_LAST = 34;
6478
6478
  var FRAME_ROCKET_DEACTIVATE_LAST = 38;
6479
- var FRAME_HYPERBLASTER_FIRE_FRAME = 6;
6479
+ var FRAME_HYPERBLASTER_ACTIVATE_LAST = 5;
6480
6480
  var FRAME_HYPERBLASTER_FIRE_LAST = 9;
6481
6481
  var FRAME_HYPERBLASTER_IDLE_LAST = 28;
6482
6482
  var FRAME_HYPERBLASTER_DEACTIVATE_LAST = 32;
@@ -6875,7 +6875,7 @@ function Weapon_Generic(ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LA
6875
6875
  if (pause_frames) {
6876
6876
  for (const frame of pause_frames) {
6877
6877
  if (client.gun_frame === frame) {
6878
- if (random2.frandom() < 0.5) {
6878
+ if (random2.frandom() < 0.9375) {
6879
6879
  return;
6880
6880
  }
6881
6881
  }
@@ -6907,12 +6907,13 @@ function Weapon_Generic(ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LA
6907
6907
  return;
6908
6908
  }
6909
6909
  }
6910
- function Weapon_Repeating(ent, FRAME_FIRE_FRAME, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_PAUSE, FRAME_NOOP, fire, sys) {
6910
+ function Weapon_Repeating(ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause_frames, fire, sys) {
6911
6911
  if (!ent.client) return;
6912
6912
  const client = ent.client;
6913
+ const FRAME_FIRE_FIRST = FRAME_ACTIVATE_LAST + 1;
6913
6914
  if (client.weaponstate === 3 /* WEAPON_FIRING */) {
6914
6915
  if (client.gun_frame === FRAME_FIRE_LAST || client.gun_frame === FRAME_IDLE_LAST) {
6915
- client.gun_frame = FRAME_FIRE_FRAME;
6916
+ client.gun_frame = FRAME_FIRE_FIRST;
6916
6917
  } else {
6917
6918
  client.gun_frame++;
6918
6919
  }
@@ -6923,14 +6924,15 @@ function Weapon_Repeating(ent, FRAME_FIRE_FRAME, FRAME_FIRE_LAST, FRAME_IDLE_LAS
6923
6924
  client.gun_frame = FRAME_IDLE_LAST + 1;
6924
6925
  client.weaponstate = 0 /* WEAPON_READY */;
6925
6926
  }
6927
+ client.weapon_think_time = sys.timeSeconds + Weapon_AnimationTime(ent);
6926
6928
  } else {
6927
6929
  Weapon_Generic(
6928
6930
  ent,
6929
- FRAME_FIRE_FRAME - 1,
6931
+ FRAME_ACTIVATE_LAST,
6930
6932
  FRAME_FIRE_LAST,
6931
6933
  FRAME_IDLE_LAST,
6932
- FRAME_PAUSE,
6933
- null,
6934
+ FRAME_DEACTIVATE_LAST,
6935
+ pause_frames,
6934
6936
  null,
6935
6937
  fire,
6936
6938
  sys
@@ -6939,6 +6941,7 @@ function Weapon_Repeating(ent, FRAME_FIRE_FRAME, FRAME_FIRE_LAST, FRAME_IDLE_LAS
6939
6941
  }
6940
6942
 
6941
6943
  // src/combat/weapons/chaingun.ts
6944
+ var CHAINGUN_PAUSE_FRAMES = [38, 43, 51, 61];
6942
6945
  function chaingunThink(player, sys) {
6943
6946
  const weaponState = getWeaponState(player.client.weaponStates, WeaponId.Chaingun);
6944
6947
  if (!(player.client.buttons & BUTTON_ATTACK) && weaponState.spinupCount && weaponState.spinupCount > 0) {
@@ -6947,12 +6950,11 @@ function chaingunThink(player, sys) {
6947
6950
  }
6948
6951
  Weapon_Repeating(
6949
6952
  player,
6950
- FRAME_CHAINGUN_FIRE_FRAME,
6953
+ FRAME_CHAINGUN_ACTIVATE_LAST,
6951
6954
  FRAME_CHAINGUN_FIRE_LAST,
6952
6955
  FRAME_CHAINGUN_IDLE_LAST,
6953
6956
  FRAME_CHAINGUN_DEACTIVATE_LAST,
6954
- 0,
6955
- // FRAME_NOOP
6957
+ CHAINGUN_PAUSE_FRAMES,
6956
6958
  (ent) => fireChaingun(sys.game, ent),
6957
6959
  sys
6958
6960
  );
@@ -7030,12 +7032,12 @@ function rocketLauncherThink(player, sys) {
7030
7032
  function hyperBlasterThink(player, sys) {
7031
7033
  Weapon_Repeating(
7032
7034
  player,
7033
- FRAME_HYPERBLASTER_FIRE_FRAME,
7035
+ FRAME_HYPERBLASTER_ACTIVATE_LAST,
7034
7036
  FRAME_HYPERBLASTER_FIRE_LAST,
7035
7037
  FRAME_HYPERBLASTER_IDLE_LAST,
7036
7038
  FRAME_HYPERBLASTER_DEACTIVATE_LAST,
7037
- 0,
7038
- // FRAME_NOOP
7039
+ null,
7040
+ // No pause frames
7039
7041
  (ent) => fireHyperBlaster(sys.game, ent),
7040
7042
  sys
7041
7043
  );
@@ -7109,6 +7111,178 @@ function blasterThink(player, sys) {
7109
7111
  );
7110
7112
  }
7111
7113
 
7114
+ // src/combat/weapons/chainfist.ts
7115
+ init_esm();
7116
+
7117
+ // src/combat/weapons/common.ts
7118
+ function applyKick2(player, pitch, yaw = 0, kickOrigin = 0) {
7119
+ if (player.client) {
7120
+ player.client.kick_angles = { x: pitch, y: yaw, z: 0 };
7121
+ player.client.kick_origin = { x: kickOrigin, y: 0, z: 0 };
7122
+ }
7123
+ }
7124
+
7125
+ // src/combat/weapons/chainfist.ts
7126
+ var CHAINFIST_REACH = 24;
7127
+ function firePlayerMeleeBoxFilter(check, data) {
7128
+ if (!check.inUse || !check.takedamage || check === data.self) {
7129
+ return false;
7130
+ }
7131
+ const closestPointToBox2 = (p, min, max) => {
7132
+ return {
7133
+ x: Math.max(min.x, Math.min(p.x, max.x)),
7134
+ y: Math.max(min.y, Math.min(p.y, max.y)),
7135
+ z: Math.max(min.z, Math.min(p.z, max.z))
7136
+ };
7137
+ };
7138
+ const closestPointToCheck = closestPointToBox2(
7139
+ data.start,
7140
+ { x: check.origin.x + check.mins.x, y: check.origin.y + check.mins.y, z: check.origin.z + check.mins.z },
7141
+ { x: check.origin.x + check.maxs.x, y: check.origin.y + check.maxs.y, z: check.origin.z + check.maxs.z }
7142
+ );
7143
+ const closestPointToSelf = closestPointToBox2(
7144
+ closestPointToCheck,
7145
+ { 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 },
7146
+ { 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 }
7147
+ );
7148
+ const dir = subtractVec3(closestPointToCheck, closestPointToSelf);
7149
+ const len = lengthVec3(dir);
7150
+ if (len > data.reach) {
7151
+ return false;
7152
+ }
7153
+ const checkCenter = {
7154
+ x: check.origin.x + (check.mins.x + check.maxs.x) * 0.5,
7155
+ y: check.origin.y + (check.mins.y + check.maxs.y) * 0.5,
7156
+ z: check.origin.z + (check.mins.z + check.maxs.z) * 0.5
7157
+ };
7158
+ const dirToTarget = normalizeVec3(subtractVec3(checkCenter, data.start));
7159
+ if (dotVec3(dirToTarget, data.aim) < 0.7) {
7160
+ if (len > 1) {
7161
+ return false;
7162
+ }
7163
+ }
7164
+ return true;
7165
+ }
7166
+ function firePlayerMelee(game, self, start, aim, reach, damage, kick, mod) {
7167
+ const reachVec = { x: reach, y: reach, z: reach };
7168
+ const absmin = {
7169
+ x: self.origin.x + self.mins.x - reach,
7170
+ y: self.origin.y + self.mins.y - reach,
7171
+ z: self.origin.z + self.mins.z - reach
7172
+ };
7173
+ const absmax = {
7174
+ x: self.origin.x + self.maxs.x + reach,
7175
+ y: self.origin.y + self.maxs.y + reach,
7176
+ z: self.origin.z + self.maxs.z + reach
7177
+ };
7178
+ const candidates = game.entities.findInBox(absmin, absmax);
7179
+ const data = { self, start, aim, reach };
7180
+ let wasHit = false;
7181
+ const closestPointToBox2 = (p, min, max) => {
7182
+ return {
7183
+ x: Math.max(min.x, Math.min(p.x, max.x)),
7184
+ y: Math.max(min.y, Math.min(p.y, max.y)),
7185
+ z: Math.max(min.z, Math.min(p.z, max.z))
7186
+ };
7187
+ };
7188
+ for (const hit of candidates) {
7189
+ if (!firePlayerMeleeBoxFilter(hit, data)) continue;
7190
+ const hitMins = { x: hit.origin.x + hit.mins.x, y: hit.origin.y + hit.mins.y, z: hit.origin.z + hit.mins.z };
7191
+ const hitMaxs = { x: hit.origin.x + hit.maxs.x, y: hit.origin.y + hit.maxs.y, z: hit.origin.z + hit.maxs.z };
7192
+ const closestPoint = closestPointToBox2(start, hitMins, hitMaxs);
7193
+ T_Damage(
7194
+ hit,
7195
+ self,
7196
+ self,
7197
+ aim,
7198
+ closestPoint,
7199
+ scaleVec3(aim, -1),
7200
+ damage,
7201
+ kick / 2,
7202
+ 8 /* NO_KNOCKBACK */,
7203
+ mod,
7204
+ game.time,
7205
+ game.multicast
7206
+ );
7207
+ wasHit = true;
7208
+ }
7209
+ return wasHit;
7210
+ }
7211
+ function chainfistSmoke(game, ent) {
7212
+ const forward = { x: 0, y: 0, z: 0 };
7213
+ const right = { x: 0, y: 0, z: 0 };
7214
+ const up = { x: 0, y: 0, z: 0 };
7215
+ const angles = ent.client ? ent.client.v_angle : ent.angles;
7216
+ const vectors = angleVectors(angles || { x: 0, y: 0, z: 0 });
7217
+ const offset = { x: 8, y: 8, z: -4 };
7218
+ const start = {
7219
+ x: ent.origin.x + ent.viewheight * 0 + vectors.forward.x * offset.x + vectors.right.x * offset.y + vectors.up.x * offset.z,
7220
+ y: ent.origin.y + ent.viewheight * 0 + vectors.forward.y * offset.x + vectors.right.y * offset.y + vectors.up.y * offset.z,
7221
+ z: ent.origin.z + ent.viewheight * 1 + vectors.forward.z * offset.x + vectors.right.z * offset.y + vectors.up.z * offset.z
7222
+ };
7223
+ game.multicast(start, 1 /* Pvs */, ServerCommand.temp_entity, TempEntity.CHAINFIST_SMOKE, start);
7224
+ }
7225
+ function fireChainfist(game, player, inventory, weaponState, start, forward) {
7226
+ let damage = 7;
7227
+ if (game.deathmatch) damage = 15;
7228
+ if (player.client && player.client.quad_time && player.client.quad_time > game.time) {
7229
+ damage *= 4;
7230
+ }
7231
+ const hit = firePlayerMelee(game, player, start, forward, CHAINFIST_REACH, damage, 100, 41 /* CHAINFIST */);
7232
+ if (hit) {
7233
+ }
7234
+ applyKick2(player, -0.5, 0, 0);
7235
+ }
7236
+ function Weapon_ChainFist(player, sys) {
7237
+ const game = sys.game;
7238
+ const pause_frames = [];
7239
+ const fireCallback = (ent) => {
7240
+ const angles = ent.client ? ent.client.v_angle : ent.angles;
7241
+ const vectors = angleVectors(angles || { x: 0, y: 0, z: 0 });
7242
+ const forward = vectors.forward;
7243
+ const start = {
7244
+ x: ent.origin.x,
7245
+ y: ent.origin.y,
7246
+ z: ent.origin.z + (ent.viewheight || 0)
7247
+ };
7248
+ const inventory = ent.client ? ent.client.inventory : { ammo: { counts: [] } };
7249
+ const weaponState = {};
7250
+ fireChainfist(game, ent, inventory, weaponState, start, forward);
7251
+ if (ent.client) {
7252
+ const client = ent.client;
7253
+ const BUTTON_ATTACK2 = 1;
7254
+ const buttons = client.buttons;
7255
+ if (buttons & BUTTON_ATTACK2) {
7256
+ if (client.gun_frame === 12) client.gun_frame = 14;
7257
+ else if (client.gun_frame === 22) client.gun_frame = 24;
7258
+ else if (client.gun_frame >= 32) client.gun_frame = 7;
7259
+ } else {
7260
+ if (client.gun_frame === 13 || client.gun_frame === 23 || client.gun_frame >= 32) {
7261
+ client.gun_frame = 33;
7262
+ }
7263
+ }
7264
+ }
7265
+ };
7266
+ Weapon_Repeating(
7267
+ player,
7268
+ 4,
7269
+ 32,
7270
+ 57,
7271
+ 60,
7272
+ pause_frames,
7273
+ fireCallback,
7274
+ sys
7275
+ );
7276
+ if (player.client) {
7277
+ const gunframe = player.client.gun_frame;
7278
+ if ((gunframe === 42 || gunframe === 51) && Math.random() < 0.125) {
7279
+ if (Math.random() < 0.4) {
7280
+ chainfistSmoke(game, player);
7281
+ }
7282
+ }
7283
+ }
7284
+ }
7285
+
7112
7286
  // src/inventory/items.ts
7113
7287
  var WEAPON_ITEMS = {
7114
7288
  "weapon_blaster": {
@@ -7232,6 +7406,18 @@ var WEAPON_ITEMS = {
7232
7406
  think: bfgThink2
7233
7407
  },
7234
7408
  // Rogue Weapons
7409
+ "weapon_chainfist": {
7410
+ type: "weapon",
7411
+ id: "weapon_chainfist",
7412
+ name: "Chainfist",
7413
+ weaponId: WeaponId.ChainFist,
7414
+ ammoType: null,
7415
+ initialAmmo: 0,
7416
+ pickupAmmo: 0,
7417
+ fireRate: 0.1,
7418
+ // Depends on animation
7419
+ think: Weapon_ChainFist
7420
+ },
7235
7421
  "weapon_boomer": {
7236
7422
  type: "weapon",
7237
7423
  id: "weapon_boomer",
@@ -19449,7 +19635,7 @@ var WEAPONS = {
19449
19635
  };
19450
19636
 
19451
19637
  // src/index.ts
19452
- var ZERO_VEC37 = { x: 0, y: 0, z: 0 };
19638
+ var ZERO_VEC38 = { x: 0, y: 0, z: 0 };
19453
19639
  function createGame(imports, engine, options) {
19454
19640
  const gravity = options.gravity;
19455
19641
  const deathmatch = options.deathmatch ?? false;
@@ -19528,8 +19714,8 @@ function createGame(imports, engine, options) {
19528
19714
  };
19529
19715
  entities.runFrame();
19530
19716
  });
19531
- let origin = { ...ZERO_VEC37 };
19532
- let velocity = { ...ZERO_VEC37 };
19717
+ let origin = { ...ZERO_VEC38 };
19718
+ let velocity = { ...ZERO_VEC38 };
19533
19719
  const calculateBlend = (player, time) => {
19534
19720
  const blend = [0, 0, 0, 0];
19535
19721
  if (!player || !player.client) return blend;
@@ -19611,10 +19797,10 @@ function createGame(imports, engine, options) {
19611
19797
  // TODO
19612
19798
  damageIndicators: [],
19613
19799
  stats: player ? populatePlayerStats(player, levelClock.current.timeSeconds) : [],
19614
- kick_angles: player?.client?.kick_angles ?? ZERO_VEC37,
19615
- kick_origin: player?.client?.kick_origin ?? ZERO_VEC37,
19616
- gunoffset: ZERO_VEC37,
19617
- gunangles: ZERO_VEC37,
19800
+ kick_angles: player?.client?.kick_angles ?? ZERO_VEC38,
19801
+ kick_origin: player?.client?.kick_origin ?? ZERO_VEC38,
19802
+ gunoffset: ZERO_VEC38,
19803
+ gunangles: ZERO_VEC38,
19618
19804
  gunindex: 0,
19619
19805
  gun_frame: player?.client?.gun_frame ?? 0,
19620
19806
  rdflags: player?.client?.rdflags ?? 0,
@@ -19628,8 +19814,8 @@ function createGame(imports, engine, options) {
19628
19814
  const resetState = (startTimeMs) => {
19629
19815
  frameLoop.reset(startTimeMs);
19630
19816
  levelClock.start(startTimeMs);
19631
- origin = { ...ZERO_VEC37 };
19632
- velocity = { ...ZERO_VEC37 };
19817
+ origin = { ...ZERO_VEC38 };
19818
+ velocity = { ...ZERO_VEC38 };
19633
19819
  entities.beginFrame(startTimeMs / 1e3);
19634
19820
  entities.runFrame();
19635
19821
  };
@@ -19657,10 +19843,10 @@ function createGame(imports, engine, options) {
19657
19843
  blend: [0, 0, 0, 0],
19658
19844
  // Stubs
19659
19845
  stats: populatePlayerStats(player, levelClock.current.timeSeconds),
19660
- kick_angles: ZERO_VEC37,
19661
- kick_origin: ZERO_VEC37,
19662
- gunoffset: ZERO_VEC37,
19663
- gunangles: ZERO_VEC37,
19846
+ kick_angles: ZERO_VEC38,
19847
+ kick_origin: ZERO_VEC38,
19848
+ gunoffset: ZERO_VEC38,
19849
+ gunangles: ZERO_VEC38,
19664
19850
  gunindex: 0,
19665
19851
  pm_type: 0,
19666
19852
  pm_time: 0,
@@ -19796,8 +19982,8 @@ function createGame(imports, engine, options) {
19796
19982
  rng,
19797
19983
  player: player?.client?.inventory
19798
19984
  });
19799
- origin = player ? { ...player.origin } : { ...ZERO_VEC37 };
19800
- velocity = player ? { ...player.velocity } : { ...ZERO_VEC37 };
19985
+ origin = player ? { ...player.origin } : { ...ZERO_VEC38 };
19986
+ velocity = player ? { ...player.velocity } : { ...ZERO_VEC38 };
19801
19987
  frameLoop.reset(save.level.timeSeconds * 1e3);
19802
19988
  }
19803
19989
  };