quake2ts 0.0.227 → 0.0.228

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.
@@ -38,9 +38,6 @@ function lengthVec3(a) {
38
38
  function distance(a, b) {
39
39
  return lengthVec3(subtractVec3(a, b));
40
40
  }
41
- function vec3Equals(a, b) {
42
- return a.x === b.x && a.y === b.y && a.z === b.z;
43
- }
44
41
  function normalizeVec3(a) {
45
42
  const len = lengthVec3(a);
46
43
  return len === 0 ? a : scaleVec3(a, 1 / len);
@@ -3751,6 +3748,30 @@ function multiTrigger(self, entities) {
3751
3748
  if (self.nextthink > entities.timeSeconds) {
3752
3749
  return;
3753
3750
  }
3751
+ let noise = "";
3752
+ switch (self.sounds) {
3753
+ case 1:
3754
+ noise = "misc/secret.wav";
3755
+ break;
3756
+ case 2:
3757
+ noise = "misc/talk.wav";
3758
+ break;
3759
+ case 3:
3760
+ noise = "misc/trigger1.wav";
3761
+ break;
3762
+ case 4:
3763
+ noise = "switches/butn2.wav";
3764
+ break;
3765
+ }
3766
+ if (noise) {
3767
+ entities.sound(self, 0, noise, 1, 1, 0);
3768
+ }
3769
+ if (self.message && self.activator && self.activator.client) {
3770
+ entities.engine.centerprintf?.(self.activator, self.message);
3771
+ if (self.sounds === 2) {
3772
+ entities.sound(self.activator, 0, "misc/talk.wav", 1, 1, 0);
3773
+ }
3774
+ }
3754
3775
  entities.useTargets(self, self.activator);
3755
3776
  if (self.wait > 0) {
3756
3777
  self.think = multiWait;
@@ -3790,6 +3811,9 @@ function registerTriggerMultiple(registry) {
3790
3811
  if (entity.wait === 0) {
3791
3812
  entity.wait = 0.2;
3792
3813
  }
3814
+ if (entity.spawnflags & TRIGGER_SPAWNFLAGS.Clip) {
3815
+ entity.solid = 3 /* Bsp */;
3816
+ }
3793
3817
  if (entity.spawnflags & TRIGGER_SPAWNFLAGS.Latched) {
3794
3818
  }
3795
3819
  if (entity.spawnflags & (TRIGGER_SPAWNFLAGS.Triggered | TRIGGER_SPAWNFLAGS.Toggle)) {
@@ -3816,6 +3840,12 @@ function registerTriggerRelay(registry) {
3816
3840
  entity.noise_index = -1;
3817
3841
  }
3818
3842
  entity.use = (self, _other, activator) => {
3843
+ if (!(self.spawnflags & RELAY_SPAWNFLAGS.NoSound)) {
3844
+ context.entities.sound(self, 0, "misc/trigger1.wav", 1, 1, 0);
3845
+ }
3846
+ if (self.message && activator && activator.client) {
3847
+ context.entities.engine.centerprintf?.(activator, self.message);
3848
+ }
3819
3849
  context.entities.useTargets(self, activator ?? self);
3820
3850
  };
3821
3851
  });
@@ -4659,6 +4689,41 @@ function registerItemSpawns(game, registry) {
4659
4689
  }
4660
4690
 
4661
4691
  // src/entities/funcs.ts
4692
+ function move_calc(ent, dest, context, done) {
4693
+ const dt = 0.1;
4694
+ const vec = subtractVec3(dest, ent.origin);
4695
+ const dist = lengthVec3(vec);
4696
+ const dir = normalizeVec3(vec);
4697
+ const speed = ent.speed || 100;
4698
+ let currentSpeed = lengthVec3(ent.velocity);
4699
+ if (ent.accel) {
4700
+ currentSpeed += ent.accel * dt;
4701
+ } else {
4702
+ currentSpeed = speed;
4703
+ }
4704
+ if (ent.decel) {
4705
+ const distToStop = currentSpeed * currentSpeed / (2 * ent.decel);
4706
+ if (dist <= distToStop) {
4707
+ currentSpeed -= ent.decel * dt;
4708
+ if (currentSpeed < 10) currentSpeed = 10;
4709
+ }
4710
+ }
4711
+ if (currentSpeed > speed) currentSpeed = speed;
4712
+ const move = currentSpeed * dt;
4713
+ if (dist <= move) {
4714
+ ent.velocity = scaleVec3(dir, dist / dt);
4715
+ ent.think = (e) => {
4716
+ e.velocity = { x: 0, y: 0, z: 0 };
4717
+ e.origin = { ...dest };
4718
+ context.linkentity(e);
4719
+ done(e, context);
4720
+ };
4721
+ context.scheduleThink(ent, context.timeSeconds + dt);
4722
+ } else {
4723
+ ent.velocity = scaleVec3(dir, currentSpeed);
4724
+ context.scheduleThink(ent, context.timeSeconds + dt);
4725
+ }
4726
+ }
4662
4727
  function door_blocked(self, other) {
4663
4728
  if (other && other.takedamage) {
4664
4729
  const damage = self.dmg || 2;
@@ -4672,34 +4737,25 @@ function door_blocked(self, other) {
4672
4737
  self.think = door_go_up;
4673
4738
  }
4674
4739
  }
4675
- function door_go_down(door, context) {
4676
- if (vec3Equals(door.origin, door.pos1)) {
4677
- door.state = 2 /* Closed */;
4678
- door.velocity = { x: 0, y: 0, z: 0 };
4740
+ function door_hit_top(ent, context) {
4741
+ ent.state = 0 /* Open */;
4742
+ if (ent.spawnflags & 32) {
4679
4743
  return;
4680
4744
  }
4681
- const move = distance(door.origin, door.pos1);
4682
- const speed = Math.min(door.speed, move);
4683
- door.velocity = scaleVec3(normalizeVec3(subtractVec3(door.pos1, door.origin)), speed);
4684
- if (move <= door.speed * 0.1) {
4685
- door.velocity = scaleVec3(subtractVec3(door.pos1, door.origin), 10);
4745
+ if (ent.wait === -1) {
4746
+ return;
4686
4747
  }
4687
- context?.scheduleThink(door, context.timeSeconds + 0.1);
4748
+ ent.think = door_go_down;
4749
+ context.scheduleThink(ent, context.timeSeconds + ent.wait);
4750
+ }
4751
+ function door_hit_bottom(ent, context) {
4752
+ ent.state = 2 /* Closed */;
4753
+ }
4754
+ function door_go_down(door, context) {
4755
+ move_calc(door, door.pos1, context, door_hit_bottom);
4688
4756
  }
4689
4757
  function door_go_up(door, context) {
4690
- if (vec3Equals(door.origin, door.pos2)) {
4691
- door.state = 0 /* Open */;
4692
- door.velocity = { x: 0, y: 0, z: 0 };
4693
- context?.scheduleThink(door, context.timeSeconds + door.wait);
4694
- door.think = door_go_down;
4695
- return;
4696
- }
4697
- const move = distance(door.origin, door.pos2);
4698
- door.velocity = scaleVec3(normalizeVec3(subtractVec3(door.pos2, door.origin)), door.speed);
4699
- if (move <= door.speed * 0.1) {
4700
- door.velocity = scaleVec3(subtractVec3(door.pos2, door.origin), 10);
4701
- }
4702
- context?.scheduleThink(door, context.timeSeconds + 0.1);
4758
+ move_calc(door, door.pos2, context, door_hit_top);
4703
4759
  }
4704
4760
  var func_door = (entity, context) => {
4705
4761
  entity.movedir = setMovedir(entity.angles);
@@ -4846,35 +4902,21 @@ var func_train = (entity, context) => {
4846
4902
  entity.think = (self) => train_find(self, context.entities);
4847
4903
  context.entities.scheduleThink(entity, context.entities.timeSeconds + 0.1);
4848
4904
  };
4849
- function plat_go_down(ent, context) {
4850
- if (vec3Equals(ent.origin, ent.pos2)) {
4851
- ent.state = 1 /* Down */;
4852
- ent.velocity = { x: 0, y: 0, z: 0 };
4853
- return;
4854
- }
4855
- const move = distance(ent.origin, ent.pos2);
4856
- ent.velocity = scaleVec3(normalizeVec3(subtractVec3(ent.pos2, ent.origin)), ent.speed);
4857
- if (move <= ent.speed * 0.1) {
4858
- ent.velocity = scaleVec3(subtractVec3(ent.pos2, ent.origin), 10);
4905
+ function plat_hit_top(ent, context) {
4906
+ ent.state = 0 /* Up */;
4907
+ if (!(ent.spawnflags & 1)) {
4908
+ ent.think = plat_wait_top;
4909
+ context.scheduleThink(ent, context.timeSeconds + ent.wait);
4859
4910
  }
4860
- context.scheduleThink(ent, context.timeSeconds + 0.1);
4911
+ }
4912
+ function plat_hit_bottom(ent, context) {
4913
+ ent.state = 1 /* Down */;
4914
+ }
4915
+ function plat_go_down(ent, context) {
4916
+ move_calc(ent, ent.pos2, context, plat_hit_bottom);
4861
4917
  }
4862
4918
  function plat_go_up(ent, context) {
4863
- if (vec3Equals(ent.origin, ent.pos1)) {
4864
- ent.state = 0 /* Up */;
4865
- ent.velocity = { x: 0, y: 0, z: 0 };
4866
- if (!(ent.spawnflags & 1)) {
4867
- ent.think = plat_wait_top;
4868
- context.scheduleThink(ent, context.timeSeconds + ent.wait);
4869
- }
4870
- return;
4871
- }
4872
- const move = distance(ent.origin, ent.pos1);
4873
- ent.velocity = scaleVec3(normalizeVec3(subtractVec3(ent.pos1, ent.origin)), ent.speed);
4874
- if (move <= ent.speed * 0.1) {
4875
- ent.velocity = scaleVec3(subtractVec3(ent.pos1, ent.origin), 10);
4876
- }
4877
- context.scheduleThink(ent, context.timeSeconds + 0.1);
4919
+ move_calc(ent, ent.pos1, context, plat_hit_top);
4878
4920
  }
4879
4921
  function plat_wait_top(ent, context) {
4880
4922
  ent.state = 3 /* GoingDown */;