quake2ts 0.0.240 → 0.0.241

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.
@@ -4929,37 +4929,53 @@ function move_calc(ent, dest, context, done) {
4929
4929
  context.scheduleThink(ent, context.timeSeconds + dt);
4930
4930
  }
4931
4931
  }
4932
- function door_blocked(self, other) {
4933
- if (other && other.takedamage) {
4934
- const damage = self.dmg || 2;
4935
- other.health -= damage;
4936
- }
4937
- if (self.state === 1 /* Opening */) {
4938
- self.state = 3 /* Closing */;
4939
- self.think = door_go_down;
4940
- } else if (self.state === 3 /* Closing */) {
4941
- self.state = 1 /* Opening */;
4942
- self.think = door_go_up;
4943
- }
4932
+ var SPAWNFLAG_DOOR_START_OPEN = 1;
4933
+ var SPAWNFLAG_DOOR_CRUSHER = 4;
4934
+ var SPAWNFLAG_DOOR_NOMONSTER = 8;
4935
+ var SPAWNFLAG_DOOR_ANIMATED = 16;
4936
+ var SPAWNFLAG_DOOR_TOGGLE = 32;
4937
+ var SPAWNFLAG_DOOR_ANIMATED_FAST = 64;
4938
+ var EF_ANIM_ALL = 4;
4939
+ var EF_ANIM_ALLFAST = 8;
4940
+ function getMoveInfo(ent) {
4941
+ return ent.moveinfo;
4944
4942
  }
4945
4943
  function door_hit_top(ent, context) {
4944
+ const moveinfo = getMoveInfo(ent);
4945
+ if (moveinfo && moveinfo.sound_end) {
4946
+ context.sound(ent, 0, moveinfo.sound_end, 1, 1, 0);
4947
+ }
4946
4948
  ent.state = 0 /* Open */;
4947
- if (ent.spawnflags & 32) {
4949
+ if (ent.spawnflags & SPAWNFLAG_DOOR_TOGGLE) {
4948
4950
  return;
4949
4951
  }
4950
4952
  if (ent.wait === -1) {
4951
4953
  return;
4952
4954
  }
4953
- ent.think = door_go_down;
4955
+ ent.think = (e) => door_go_down(e, context);
4954
4956
  context.scheduleThink(ent, context.timeSeconds + ent.wait);
4955
4957
  }
4956
4958
  function door_hit_bottom(ent, context) {
4959
+ const moveinfo = getMoveInfo(ent);
4960
+ if (moveinfo && moveinfo.sound_end) {
4961
+ context.sound(ent, 0, moveinfo.sound_end, 1, 1, 0);
4962
+ }
4957
4963
  ent.state = 2 /* Closed */;
4958
4964
  }
4959
4965
  function door_go_down(door, context) {
4966
+ door.think = (e) => door_go_down(e, context);
4967
+ const moveinfo = getMoveInfo(door);
4968
+ if (moveinfo && moveinfo.sound_start) {
4969
+ context.sound(door, 0, moveinfo.sound_start, 1, 1, 0);
4970
+ }
4960
4971
  move_calc(door, door.pos1, context, door_hit_bottom);
4961
4972
  }
4962
4973
  function door_go_up(door, context) {
4974
+ door.think = (e) => door_go_up(e, context);
4975
+ const moveinfo = getMoveInfo(door);
4976
+ if (moveinfo && moveinfo.sound_start) {
4977
+ context.sound(door, 0, moveinfo.sound_start, 1, 1, 0);
4978
+ }
4963
4979
  move_calc(door, door.pos2, context, door_hit_top);
4964
4980
  }
4965
4981
  var func_door = (entity, context) => {
@@ -4971,15 +4987,51 @@ var func_door = (entity, context) => {
4971
4987
  if (!entity.health) entity.health = 0;
4972
4988
  entity.solid = 3 /* Bsp */;
4973
4989
  entity.movetype = 2 /* Push */;
4974
- entity.blocked = door_blocked;
4990
+ entity.blocked = (self, other) => {
4991
+ if (other && other.takedamage) {
4992
+ const damage = self.dmg || 2;
4993
+ if (self.spawnflags & SPAWNFLAG_DOOR_CRUSHER) {
4994
+ other.health -= damage;
4995
+ } else {
4996
+ other.health -= damage;
4997
+ }
4998
+ }
4999
+ if (self.spawnflags & SPAWNFLAG_DOOR_CRUSHER) {
5000
+ return;
5001
+ }
5002
+ if (self.state === 1 /* Opening */) {
5003
+ self.state = 3 /* Closing */;
5004
+ door_go_down(self, context.entities);
5005
+ } else if (self.state === 3 /* Closing */) {
5006
+ self.state = 1 /* Opening */;
5007
+ door_go_up(self, context.entities);
5008
+ }
5009
+ };
4975
5010
  entity.state = 2 /* Closed */;
4976
5011
  entity.pos1 = { ...entity.origin };
4977
5012
  const move = entity.movedir.x * (Math.abs(entity.maxs.x - entity.mins.x) - entity.lip) + entity.movedir.y * (Math.abs(entity.maxs.y - entity.mins.y) - entity.lip) + entity.movedir.z * (Math.abs(entity.maxs.z - entity.mins.z) - entity.lip);
4978
5013
  entity.pos2 = addVec3(entity.pos1, scaleVec3(entity.movedir, move));
4979
- if (entity.spawnflags & 1) {
5014
+ const moveinfo = {
5015
+ sound_start: null,
5016
+ sound_middle: null,
5017
+ sound_end: null
5018
+ };
5019
+ if (entity.sounds !== 1) {
5020
+ moveinfo.sound_start = "doors/dr1_strt.wav";
5021
+ moveinfo.sound_middle = "doors/dr1_mid.wav";
5022
+ moveinfo.sound_end = "doors/dr1_end.wav";
5023
+ }
5024
+ entity.moveinfo = moveinfo;
5025
+ if (entity.spawnflags & SPAWNFLAG_DOOR_START_OPEN) {
4980
5026
  entity.origin = { ...entity.pos2 };
4981
5027
  entity.state = 0 /* Open */;
4982
5028
  }
5029
+ if (entity.spawnflags & SPAWNFLAG_DOOR_ANIMATED) {
5030
+ entity.effects |= EF_ANIM_ALL;
5031
+ }
5032
+ if (entity.spawnflags & SPAWNFLAG_DOOR_ANIMATED_FAST) {
5033
+ entity.effects |= EF_ANIM_ALLFAST;
5034
+ }
4983
5035
  if (entity.health > 0) {
4984
5036
  entity.takedamage = true;
4985
5037
  entity.max_health = entity.health;
@@ -4990,46 +5042,27 @@ var func_door = (entity, context) => {
4990
5042
  };
4991
5043
  }
4992
5044
  entity.use = (self, other, activator) => {
4993
- if (entity.spawnflags & 32) {
5045
+ if (entity.spawnflags & SPAWNFLAG_DOOR_TOGGLE) {
4994
5046
  if (self.state === 2 /* Closed */) {
4995
5047
  self.state = 1 /* Opening */;
4996
- self.think = door_go_up;
4997
- context.entities.scheduleThink(self, context.entities.timeSeconds + 0.1);
5048
+ door_go_up(self, context.entities);
4998
5049
  } else if (self.state === 0 /* Open */) {
4999
5050
  self.state = 3 /* Closing */;
5000
- self.think = door_go_down;
5001
- context.entities.scheduleThink(self, context.entities.timeSeconds + 0.1);
5051
+ door_go_down(self, context.entities);
5002
5052
  }
5003
5053
  return;
5004
5054
  }
5005
5055
  if (self.state !== 2 /* Closed */) return;
5006
5056
  self.state = 1 /* Opening */;
5007
- self.think = door_go_up;
5008
- context.entities.scheduleThink(self, context.entities.timeSeconds + 0.1);
5009
- let soundName = "doors/dr1_strt.wav";
5010
- if (entity.sounds) {
5011
- switch (entity.sounds) {
5012
- case 1:
5013
- soundName = "doors/dr1_strt.wav";
5014
- break;
5015
- case 2:
5016
- soundName = "doors/dr2_strt.wav";
5017
- break;
5018
- case 3:
5019
- soundName = "doors/dr3_strt.wav";
5020
- break;
5021
- case 4:
5022
- soundName = "doors/dr4_strt.wav";
5023
- break;
5024
- default:
5025
- soundName = "doors/dr1_strt.wav";
5026
- }
5027
- }
5028
- context.entities.sound(self, 0, soundName, 1, 1, 0);
5057
+ door_go_up(self, context.entities);
5029
5058
  };
5030
5059
  if (entity.health <= 0 && !entity.targetname) {
5031
5060
  entity.touch = (self, other) => {
5032
- if (!other || other.classname !== "player") return;
5061
+ if (!other) return;
5062
+ if (self.spawnflags & SPAWNFLAG_DOOR_NOMONSTER) {
5063
+ if (other.svflags & 4 /* Monster */) return;
5064
+ }
5065
+ if (other.classname !== "player" && !(other.svflags & 4 /* Monster */)) return;
5033
5066
  self.use?.(self, other, other);
5034
5067
  };
5035
5068
  }