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.
@@ -2623,6 +2623,11 @@ var TraceMask = /* @__PURE__ */ ((TraceMask2) => {
2623
2623
  TraceMask2[TraceMask2["Window"] = 2] = "Window";
2624
2624
  return TraceMask2;
2625
2625
  })(TraceMask || {});
2626
+ var BOTTOM_EMPTY = 0;
2627
+ var BOTTOM_SOLID = 1;
2628
+ var BOTTOM_WATER = 2;
2629
+ var BOTTOM_SLIME = 3;
2630
+ var BOTTOM_LAVA = 4;
2626
2631
 
2627
2632
  // src/entities/entity.ts
2628
2633
  var MoveType = /* @__PURE__ */ ((MoveType3) => {
@@ -3536,7 +3541,7 @@ function CheckGround(self, context) {
3536
3541
  }
3537
3542
  }
3538
3543
  }
3539
- function M_CheckBottom(self, context) {
3544
+ function M_CheckBottomEx(self, context) {
3540
3545
  const mins = {
3541
3546
  x: self.origin.x + self.mins.x,
3542
3547
  y: self.origin.y + self.mins.y,
@@ -3548,26 +3553,72 @@ function M_CheckBottom(self, context) {
3548
3553
  z: self.origin.z + self.maxs.z
3549
3554
  };
3550
3555
  let start = { x: 0, y: 0, z: 0 };
3551
- let stop = { x: 0, y: 0, z: 0 };
3552
- for (let i = 0; i < 2; i++) {
3553
- if (i === 1) start = { x: mins.x, y: mins.y, z: 0 };
3554
- else start = { x: maxs.x, y: mins.y, z: 0 };
3555
- start.z = mins.z - 1;
3556
- if (context.pointcontents(start) !== 0) return true;
3557
- stop = { ...start };
3558
- stop.z = start.z - 60;
3559
- const trace = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3560
- if (trace.fraction < 1) return true;
3561
- if (i === 1) start = { x: mins.x, y: maxs.y, z: 0 };
3562
- else start = { x: maxs.x, y: maxs.y, z: 0 };
3563
- start.z = mins.z - 1;
3564
- if (context.pointcontents(start) !== 0) return true;
3565
- stop = { ...start };
3566
- stop.z = start.z - 60;
3567
- const trace2 = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3568
- if (trace2.fraction < 1) return true;
3556
+ let allSolid = true;
3557
+ for (let x = 0; x <= 1; x++) {
3558
+ for (let y = 0; y <= 1; y++) {
3559
+ start.x = x ? maxs.x : mins.x;
3560
+ start.y = y ? maxs.y : mins.y;
3561
+ start.z = mins.z - 1;
3562
+ const content = context.pointcontents(start);
3563
+ if (content !== CONTENTS_SOLID) {
3564
+ allSolid = false;
3565
+ break;
3566
+ }
3567
+ }
3568
+ if (!allSolid) break;
3569
+ }
3570
+ if (allSolid) return BOTTOM_SOLID;
3571
+ start.x = self.origin.x;
3572
+ start.y = self.origin.y;
3573
+ start.z = self.origin.z + self.mins.z;
3574
+ const stop = { ...start };
3575
+ stop.z = start.z - STEPSIZE * 2;
3576
+ const trace = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3577
+ if (trace.fraction === 1) return BOTTOM_EMPTY;
3578
+ const mid = trace.endpos.z;
3579
+ const bottomType = context.pointcontents(trace.endpos);
3580
+ let result = BOTTOM_SOLID;
3581
+ if (bottomType & CONTENTS_WATER) result = BOTTOM_WATER;
3582
+ else if (bottomType & CONTENTS_SLIME) result = BOTTOM_SLIME;
3583
+ else if (bottomType & CONTENTS_LAVA) result = BOTTOM_LAVA;
3584
+ const stepQuadrantSize = {
3585
+ x: (self.maxs.x - self.mins.x) * 0.5,
3586
+ y: (self.maxs.y - self.mins.y) * 0.5
3587
+ };
3588
+ const halfStepQuadrant = {
3589
+ x: stepQuadrantSize.x * 0.5,
3590
+ y: stepQuadrantSize.y * 0.5,
3591
+ z: 0
3592
+ };
3593
+ const halfStepQuadrantMins = {
3594
+ x: -halfStepQuadrant.x,
3595
+ y: -halfStepQuadrant.y,
3596
+ z: 0
3597
+ };
3598
+ const centerStart = {
3599
+ x: self.origin.x + (self.mins.x + self.maxs.x) * 0.5,
3600
+ y: self.origin.y + (self.mins.y + self.maxs.y) * 0.5,
3601
+ z: 0
3602
+ };
3603
+ for (let x = 0; x <= 1; x++) {
3604
+ for (let y = 0; y <= 1; y++) {
3605
+ const quadrantStart = { ...centerStart };
3606
+ if (x) quadrantStart.x += halfStepQuadrant.x;
3607
+ else quadrantStart.x -= halfStepQuadrant.x;
3608
+ if (y) quadrantStart.y += halfStepQuadrant.y;
3609
+ else quadrantStart.y -= halfStepQuadrant.y;
3610
+ quadrantStart.z = start.z;
3611
+ const quadrantEnd = { ...quadrantStart, z: stop.z };
3612
+ const subTrace = context.trace(quadrantStart, halfStepQuadrantMins, halfStepQuadrant, quadrantEnd, self, MASK_MONSTERSOLID);
3613
+ if (subTrace.fraction === 1 || mid - subTrace.endpos.z > STEPSIZE) {
3614
+ return BOTTOM_EMPTY;
3615
+ }
3616
+ }
3569
3617
  }
3570
- return false;
3618
+ return result;
3619
+ }
3620
+ function M_CheckBottom(self, context) {
3621
+ return M_CheckBottomEx(self, context) !== BOTTOM_EMPTY;
3571
3622
  }
3572
3623
  function M_MoveStep(self, move, relink, context) {
3573
3624
  if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0) && self.movetype !== 1 /* Noclip */) {
@@ -4373,6 +4424,41 @@ var SpatialGrid = class {
4373
4424
  }
4374
4425
  };
4375
4426
 
4427
+ // src/scripting/hooks.ts
4428
+ var ScriptHookRegistry = class {
4429
+ constructor() {
4430
+ this.hooks = {};
4431
+ }
4432
+ register(hooks) {
4433
+ this.hooks = { ...this.hooks, ...hooks };
4434
+ }
4435
+ // Getters for specific hooks to avoid full object access if performance critical
4436
+ get onMapLoad() {
4437
+ return this.hooks.onMapLoad;
4438
+ }
4439
+ get onMapUnload() {
4440
+ return this.hooks.onMapUnload;
4441
+ }
4442
+ get onPlayerSpawn() {
4443
+ return this.hooks.onPlayerSpawn;
4444
+ }
4445
+ get onPlayerDeath() {
4446
+ return this.hooks.onPlayerDeath;
4447
+ }
4448
+ get onEntitySpawn() {
4449
+ return this.hooks.onEntitySpawn;
4450
+ }
4451
+ get onEntityRemove() {
4452
+ return this.hooks.onEntityRemove;
4453
+ }
4454
+ get onDamage() {
4455
+ return this.hooks.onDamage;
4456
+ }
4457
+ get onPickup() {
4458
+ return this.hooks.onPickup;
4459
+ }
4460
+ };
4461
+
4376
4462
  // src/entities/system.ts
4377
4463
  function computeBounds(entity) {
4378
4464
  return {
@@ -4431,6 +4517,7 @@ var EntitySystem = class {
4431
4517
  this.currentTimeSeconds = 0;
4432
4518
  this.frameNumber = 0;
4433
4519
  this.spawnCount = 0;
4520
+ this.scriptHooks = new ScriptHookRegistry();
4434
4521
  // Persistent state for cross-level logic
4435
4522
  this.crossLevelFlags = 0;
4436
4523
  this.crossUnitFlags = 0;
@@ -4533,6 +4620,9 @@ var EntitySystem = class {
4533
4620
  setSpawnRegistry(registry) {
4534
4621
  this.spawnRegistry = registry;
4535
4622
  }
4623
+ registerEntityClass(classname, factory) {
4624
+ this.spawnRegistry?.register(classname, factory);
4625
+ }
4536
4626
  getSpawnFunction(classname) {
4537
4627
  return this.spawnRegistry?.get(classname);
4538
4628
  }
@@ -4583,9 +4673,11 @@ var EntitySystem = class {
4583
4673
  this.spawnCount++;
4584
4674
  ent.spawn_count = this.spawnCount;
4585
4675
  ent.timestamp = this.currentTimeSeconds;
4676
+ this.scriptHooks.onEntitySpawn?.(ent);
4586
4677
  return ent;
4587
4678
  }
4588
4679
  free(entity) {
4680
+ this.scriptHooks.onEntityRemove?.(entity);
4589
4681
  this.unregisterTarget(entity);
4590
4682
  this.thinkScheduler.cancel(entity);
4591
4683
  this.spatialGrid.remove(entity);
@@ -25818,6 +25910,11 @@ export {
25818
25910
  AmmoType,
25819
25911
  ArmorType,
25820
25912
  AttackState,
25913
+ BOTTOM_EMPTY,
25914
+ BOTTOM_LAVA,
25915
+ BOTTOM_SLIME,
25916
+ BOTTOM_SOLID,
25917
+ BOTTOM_WATER,
25821
25918
  BlockedJumpResult,
25822
25919
  CheckGround,
25823
25920
  DamageFlags,
@@ -25839,6 +25936,7 @@ export {
25839
25936
  M_CheckAttack,
25840
25937
  M_CheckAttack_Base,
25841
25938
  M_CheckBottom,
25939
+ M_CheckBottomEx,
25842
25940
  M_MoveFrame,
25843
25941
  M_MoveStep,
25844
25942
  M_MoveToGoal,