quake2ts 0.0.437 → 0.0.440

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.
@@ -2469,6 +2469,11 @@ __export(index_exports, {
2469
2469
  AmmoType: () => AmmoType,
2470
2470
  ArmorType: () => ArmorType,
2471
2471
  AttackState: () => AttackState,
2472
+ BOTTOM_EMPTY: () => BOTTOM_EMPTY,
2473
+ BOTTOM_LAVA: () => BOTTOM_LAVA,
2474
+ BOTTOM_SLIME: () => BOTTOM_SLIME,
2475
+ BOTTOM_SOLID: () => BOTTOM_SOLID,
2476
+ BOTTOM_WATER: () => BOTTOM_WATER,
2472
2477
  BlockedJumpResult: () => BlockedJumpResult,
2473
2478
  CheckGround: () => CheckGround,
2474
2479
  DamageFlags: () => DamageFlags,
@@ -2490,6 +2495,7 @@ __export(index_exports, {
2490
2495
  M_CheckAttack: () => M_CheckAttack,
2491
2496
  M_CheckAttack_Base: () => M_CheckAttack_Base,
2492
2497
  M_CheckBottom: () => M_CheckBottom,
2498
+ M_CheckBottomEx: () => M_CheckBottomEx,
2493
2499
  M_MoveFrame: () => M_MoveFrame,
2494
2500
  M_MoveStep: () => M_MoveStep,
2495
2501
  M_MoveToGoal: () => M_MoveToGoal,
@@ -2800,6 +2806,11 @@ var TraceMask = /* @__PURE__ */ ((TraceMask2) => {
2800
2806
  TraceMask2[TraceMask2["Window"] = 2] = "Window";
2801
2807
  return TraceMask2;
2802
2808
  })(TraceMask || {});
2809
+ var BOTTOM_EMPTY = 0;
2810
+ var BOTTOM_SOLID = 1;
2811
+ var BOTTOM_WATER = 2;
2812
+ var BOTTOM_SLIME = 3;
2813
+ var BOTTOM_LAVA = 4;
2803
2814
 
2804
2815
  // src/entities/entity.ts
2805
2816
  var MoveType = /* @__PURE__ */ ((MoveType3) => {
@@ -3713,7 +3724,7 @@ function CheckGround(self, context) {
3713
3724
  }
3714
3725
  }
3715
3726
  }
3716
- function M_CheckBottom(self, context) {
3727
+ function M_CheckBottomEx(self, context) {
3717
3728
  const mins = {
3718
3729
  x: self.origin.x + self.mins.x,
3719
3730
  y: self.origin.y + self.mins.y,
@@ -3725,26 +3736,72 @@ function M_CheckBottom(self, context) {
3725
3736
  z: self.origin.z + self.maxs.z
3726
3737
  };
3727
3738
  let start = { x: 0, y: 0, z: 0 };
3728
- let stop = { x: 0, y: 0, z: 0 };
3729
- for (let i = 0; i < 2; i++) {
3730
- if (i === 1) start = { x: mins.x, y: mins.y, z: 0 };
3731
- else start = { x: maxs.x, y: mins.y, z: 0 };
3732
- start.z = mins.z - 1;
3733
- if (context.pointcontents(start) !== 0) return true;
3734
- stop = { ...start };
3735
- stop.z = start.z - 60;
3736
- const trace = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3737
- if (trace.fraction < 1) return true;
3738
- if (i === 1) start = { x: mins.x, y: maxs.y, z: 0 };
3739
- else start = { x: maxs.x, y: maxs.y, z: 0 };
3740
- start.z = mins.z - 1;
3741
- if (context.pointcontents(start) !== 0) return true;
3742
- stop = { ...start };
3743
- stop.z = start.z - 60;
3744
- const trace2 = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3745
- if (trace2.fraction < 1) return true;
3739
+ let allSolid = true;
3740
+ for (let x = 0; x <= 1; x++) {
3741
+ for (let y = 0; y <= 1; y++) {
3742
+ start.x = x ? maxs.x : mins.x;
3743
+ start.y = y ? maxs.y : mins.y;
3744
+ start.z = mins.z - 1;
3745
+ const content = context.pointcontents(start);
3746
+ if (content !== CONTENTS_SOLID) {
3747
+ allSolid = false;
3748
+ break;
3749
+ }
3750
+ }
3751
+ if (!allSolid) break;
3752
+ }
3753
+ if (allSolid) return BOTTOM_SOLID;
3754
+ start.x = self.origin.x;
3755
+ start.y = self.origin.y;
3756
+ start.z = self.origin.z + self.mins.z;
3757
+ const stop = { ...start };
3758
+ stop.z = start.z - STEPSIZE * 2;
3759
+ const trace = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3760
+ if (trace.fraction === 1) return BOTTOM_EMPTY;
3761
+ const mid = trace.endpos.z;
3762
+ const bottomType = context.pointcontents(trace.endpos);
3763
+ let result = BOTTOM_SOLID;
3764
+ if (bottomType & CONTENTS_WATER) result = BOTTOM_WATER;
3765
+ else if (bottomType & CONTENTS_SLIME) result = BOTTOM_SLIME;
3766
+ else if (bottomType & CONTENTS_LAVA) result = BOTTOM_LAVA;
3767
+ const stepQuadrantSize = {
3768
+ x: (self.maxs.x - self.mins.x) * 0.5,
3769
+ y: (self.maxs.y - self.mins.y) * 0.5
3770
+ };
3771
+ const halfStepQuadrant = {
3772
+ x: stepQuadrantSize.x * 0.5,
3773
+ y: stepQuadrantSize.y * 0.5,
3774
+ z: 0
3775
+ };
3776
+ const halfStepQuadrantMins = {
3777
+ x: -halfStepQuadrant.x,
3778
+ y: -halfStepQuadrant.y,
3779
+ z: 0
3780
+ };
3781
+ const centerStart = {
3782
+ x: self.origin.x + (self.mins.x + self.maxs.x) * 0.5,
3783
+ y: self.origin.y + (self.mins.y + self.maxs.y) * 0.5,
3784
+ z: 0
3785
+ };
3786
+ for (let x = 0; x <= 1; x++) {
3787
+ for (let y = 0; y <= 1; y++) {
3788
+ const quadrantStart = { ...centerStart };
3789
+ if (x) quadrantStart.x += halfStepQuadrant.x;
3790
+ else quadrantStart.x -= halfStepQuadrant.x;
3791
+ if (y) quadrantStart.y += halfStepQuadrant.y;
3792
+ else quadrantStart.y -= halfStepQuadrant.y;
3793
+ quadrantStart.z = start.z;
3794
+ const quadrantEnd = { ...quadrantStart, z: stop.z };
3795
+ const subTrace = context.trace(quadrantStart, halfStepQuadrantMins, halfStepQuadrant, quadrantEnd, self, MASK_MONSTERSOLID);
3796
+ if (subTrace.fraction === 1 || mid - subTrace.endpos.z > STEPSIZE) {
3797
+ return BOTTOM_EMPTY;
3798
+ }
3799
+ }
3746
3800
  }
3747
- return false;
3801
+ return result;
3802
+ }
3803
+ function M_CheckBottom(self, context) {
3804
+ return M_CheckBottomEx(self, context) !== BOTTOM_EMPTY;
3748
3805
  }
3749
3806
  function M_MoveStep(self, move, relink, context) {
3750
3807
  if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0) && self.movetype !== 1 /* Noclip */) {
@@ -4550,6 +4607,41 @@ var SpatialGrid = class {
4550
4607
  }
4551
4608
  };
4552
4609
 
4610
+ // src/scripting/hooks.ts
4611
+ var ScriptHookRegistry = class {
4612
+ constructor() {
4613
+ this.hooks = {};
4614
+ }
4615
+ register(hooks) {
4616
+ this.hooks = { ...this.hooks, ...hooks };
4617
+ }
4618
+ // Getters for specific hooks to avoid full object access if performance critical
4619
+ get onMapLoad() {
4620
+ return this.hooks.onMapLoad;
4621
+ }
4622
+ get onMapUnload() {
4623
+ return this.hooks.onMapUnload;
4624
+ }
4625
+ get onPlayerSpawn() {
4626
+ return this.hooks.onPlayerSpawn;
4627
+ }
4628
+ get onPlayerDeath() {
4629
+ return this.hooks.onPlayerDeath;
4630
+ }
4631
+ get onEntitySpawn() {
4632
+ return this.hooks.onEntitySpawn;
4633
+ }
4634
+ get onEntityRemove() {
4635
+ return this.hooks.onEntityRemove;
4636
+ }
4637
+ get onDamage() {
4638
+ return this.hooks.onDamage;
4639
+ }
4640
+ get onPickup() {
4641
+ return this.hooks.onPickup;
4642
+ }
4643
+ };
4644
+
4553
4645
  // src/entities/system.ts
4554
4646
  function computeBounds(entity) {
4555
4647
  return {
@@ -4608,6 +4700,7 @@ var EntitySystem = class {
4608
4700
  this.currentTimeSeconds = 0;
4609
4701
  this.frameNumber = 0;
4610
4702
  this.spawnCount = 0;
4703
+ this.scriptHooks = new ScriptHookRegistry();
4611
4704
  // Persistent state for cross-level logic
4612
4705
  this.crossLevelFlags = 0;
4613
4706
  this.crossUnitFlags = 0;
@@ -4710,6 +4803,9 @@ var EntitySystem = class {
4710
4803
  setSpawnRegistry(registry) {
4711
4804
  this.spawnRegistry = registry;
4712
4805
  }
4806
+ registerEntityClass(classname, factory) {
4807
+ this.spawnRegistry?.register(classname, factory);
4808
+ }
4713
4809
  getSpawnFunction(classname) {
4714
4810
  return this.spawnRegistry?.get(classname);
4715
4811
  }
@@ -4760,9 +4856,11 @@ var EntitySystem = class {
4760
4856
  this.spawnCount++;
4761
4857
  ent.spawn_count = this.spawnCount;
4762
4858
  ent.timestamp = this.currentTimeSeconds;
4859
+ this.scriptHooks.onEntitySpawn?.(ent);
4763
4860
  return ent;
4764
4861
  }
4765
4862
  free(entity) {
4863
+ this.scriptHooks.onEntityRemove?.(entity);
4766
4864
  this.unregisterTarget(entity);
4767
4865
  this.thinkScheduler.cancel(entity);
4768
4866
  this.spatialGrid.remove(entity);
@@ -25996,6 +26094,11 @@ function createGame(imports, engine, options) {
25996
26094
  AmmoType,
25997
26095
  ArmorType,
25998
26096
  AttackState,
26097
+ BOTTOM_EMPTY,
26098
+ BOTTOM_LAVA,
26099
+ BOTTOM_SLIME,
26100
+ BOTTOM_SOLID,
26101
+ BOTTOM_WATER,
25999
26102
  BlockedJumpResult,
26000
26103
  CheckGround,
26001
26104
  DamageFlags,
@@ -26017,6 +26120,7 @@ function createGame(imports, engine, options) {
26017
26120
  M_CheckAttack,
26018
26121
  M_CheckAttack_Base,
26019
26122
  M_CheckBottom,
26123
+ M_CheckBottomEx,
26020
26124
  M_MoveFrame,
26021
26125
  M_MoveStep,
26022
26126
  M_MoveToGoal,