quake2ts 0.0.85 → 0.0.86

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.
@@ -27,6 +27,7 @@ __export(index_exports, {
27
27
  AmmoItemId: () => AmmoItemId,
28
28
  AmmoType: () => AmmoType,
29
29
  ArmorType: () => ArmorType,
30
+ CheckGround: () => CheckGround,
30
31
  DamageFlags: () => DamageFlags,
31
32
  DamageMod: () => DamageMod,
32
33
  DeadFlag: () => DeadFlag,
@@ -40,7 +41,9 @@ __export(index_exports, {
40
41
  HEALTH_ITEMS: () => HEALTH_ITEMS,
41
42
  KEY_ITEMS: () => KEY_ITEMS,
42
43
  KeyId: () => KeyId,
44
+ M_CheckBottom: () => M_CheckBottom,
43
45
  M_MoveFrame: () => M_MoveFrame,
46
+ M_walkmove: () => M_walkmove,
44
47
  MoveType: () => MoveType,
45
48
  ORDERED_DAMAGE_MODS: () => ORDERED_DAMAGE_MODS,
46
49
  POWERUP_ITEMS: () => POWERUP_ITEMS,
@@ -51,6 +54,8 @@ __export(index_exports, {
51
54
  RangeCategory: () => RangeCategory,
52
55
  SAVE_FORMAT_VERSION: () => SAVE_FORMAT_VERSION,
53
56
  SPAWNFLAG_MONSTER_AMBUSH: () => SPAWNFLAG_MONSTER_AMBUSH,
57
+ SV_NewChaseDir: () => SV_NewChaseDir,
58
+ SV_StepDirection: () => SV_StepDirection,
54
59
  SaveStorage: () => SaveStorage,
55
60
  ServerFlags: () => ServerFlags,
56
61
  Solid: () => Solid,
@@ -3810,6 +3815,131 @@ function ai_charge(self, distance2, deltaSeconds) {
3810
3815
  walkMove(self, self.angles.y, distance2);
3811
3816
  }
3812
3817
  }
3818
+ function CheckGround(self, context) {
3819
+ if (self.movetype === 1 /* Noclip */) {
3820
+ return;
3821
+ }
3822
+ const point = {
3823
+ x: self.origin.x,
3824
+ y: self.origin.y,
3825
+ z: self.origin.z + self.mins.z - 1
3826
+ };
3827
+ const trace = context.trace(self.origin, self.mins, self.maxs, point, self, MASK_MONSTERSOLID);
3828
+ self.groundentity = trace.ent;
3829
+ if (!self.groundentity && !trace.allsolid && !trace.startsolid && trace.fraction === 1) {
3830
+ const content = context.pointcontents(point);
3831
+ if (content & MASK_WATER) {
3832
+ self.waterlevel = 1;
3833
+ self.watertype = content;
3834
+ } else {
3835
+ self.waterlevel = 0;
3836
+ self.watertype = 0;
3837
+ }
3838
+ }
3839
+ }
3840
+ function M_CheckBottom(self, context) {
3841
+ const mins = {
3842
+ x: self.origin.x + self.mins.x,
3843
+ y: self.origin.y + self.mins.y,
3844
+ z: self.origin.z + self.mins.z
3845
+ };
3846
+ const maxs = {
3847
+ x: self.origin.x + self.maxs.x,
3848
+ y: self.origin.y + self.maxs.y,
3849
+ z: self.origin.z + self.maxs.z
3850
+ };
3851
+ let start = { x: 0, y: 0, z: 0 };
3852
+ let stop = { x: 0, y: 0, z: 0 };
3853
+ for (let i = 0; i < 2; i++) {
3854
+ if (i === 1) start = { x: mins.x, y: mins.y, z: 0 };
3855
+ else start = { x: maxs.x, y: mins.y, z: 0 };
3856
+ start.z = mins.z - 1;
3857
+ if (context.pointcontents(start) !== 0) return true;
3858
+ stop = { ...start };
3859
+ stop.z = start.z - 60;
3860
+ const trace = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3861
+ if (trace.fraction < 1) return true;
3862
+ if (i === 1) start = { x: mins.x, y: maxs.y, z: 0 };
3863
+ else start = { x: maxs.x, y: maxs.y, z: 0 };
3864
+ start.z = mins.z - 1;
3865
+ if (context.pointcontents(start) !== 0) return true;
3866
+ stop = { ...start };
3867
+ stop.z = start.z - 60;
3868
+ const trace2 = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3869
+ if (trace2.fraction < 1) return true;
3870
+ }
3871
+ return false;
3872
+ }
3873
+ function M_walkmove(self, yawDegrees, distance2, context) {
3874
+ if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0) && self.movetype !== 1 /* Noclip */) {
3875
+ if (!self.groundentity && self.waterlevel === 0) {
3876
+ return false;
3877
+ }
3878
+ }
3879
+ const delta = yawVector(yawDegrees, distance2);
3880
+ if ((self.monsterinfo.aiflags & 1024 /* NoStep */) !== 0 && (self.monsterinfo.aiflags & 1073741824 /* Pathing */) !== 0) {
3881
+ }
3882
+ const dest = {
3883
+ x: self.origin.x + delta.x,
3884
+ y: self.origin.y + delta.y,
3885
+ z: self.origin.z + delta.z
3886
+ };
3887
+ const trace = context.trace(self.origin, self.mins, self.maxs, dest, self, MASK_MONSTERSOLID);
3888
+ if (trace.fraction < 1) {
3889
+ return false;
3890
+ }
3891
+ const oldOrigin = { ...self.origin };
3892
+ self.origin.x = dest.x;
3893
+ self.origin.y = dest.y;
3894
+ self.origin.z = dest.z;
3895
+ if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0) && self.movetype !== 1 /* Noclip */) {
3896
+ if (!M_CheckBottom(self, context)) {
3897
+ self.origin.x = oldOrigin.x;
3898
+ self.origin.y = oldOrigin.y;
3899
+ self.origin.z = oldOrigin.z;
3900
+ return false;
3901
+ }
3902
+ }
3903
+ if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0)) {
3904
+ CheckGround(self, context);
3905
+ }
3906
+ return true;
3907
+ }
3908
+ function SV_StepDirection(self, yaw, dist, context) {
3909
+ for (let i = 0; i <= 90; i += 45) {
3910
+ if (M_walkmove(self, yaw + i, dist, context)) {
3911
+ if (i !== 0) {
3912
+ self.ideal_yaw = angleMod(yaw + i);
3913
+ }
3914
+ return true;
3915
+ }
3916
+ if (i !== 0) {
3917
+ if (M_walkmove(self, yaw - i, dist, context)) {
3918
+ self.ideal_yaw = angleMod(yaw - i);
3919
+ return true;
3920
+ }
3921
+ }
3922
+ }
3923
+ return false;
3924
+ }
3925
+ function SV_NewChaseDir(self, enemy, dist, context) {
3926
+ if (!enemy) return;
3927
+ const olddir = angleMod(self.ideal_yaw - self.angles.y);
3928
+ const turnaround = Math.abs(olddir - 180) < 20;
3929
+ const dx = enemy.origin.x - self.origin.x;
3930
+ const dy = enemy.origin.y - self.origin.y;
3931
+ if (Math.abs(dx) > Math.abs(dy)) {
3932
+ if (dx > 0) self.ideal_yaw = 0;
3933
+ else self.ideal_yaw = 180;
3934
+ } else {
3935
+ if (dy > 0) self.ideal_yaw = 90;
3936
+ else self.ideal_yaw = 270;
3937
+ }
3938
+ if (turnaround) {
3939
+ self.ideal_yaw = angleMod(self.ideal_yaw + 180);
3940
+ }
3941
+ SV_StepDirection(self, self.ideal_yaw, dist, context);
3942
+ }
3813
3943
 
3814
3944
  // src/ai/targeting.ts
3815
3945
  function setIdealYawTowards2(self, other) {
@@ -6115,6 +6245,7 @@ function createGame({ trace, pointcontents }, engine, options) {
6115
6245
  AmmoItemId,
6116
6246
  AmmoType,
6117
6247
  ArmorType,
6248
+ CheckGround,
6118
6249
  DamageFlags,
6119
6250
  DamageMod,
6120
6251
  DeadFlag,
@@ -6128,7 +6259,9 @@ function createGame({ trace, pointcontents }, engine, options) {
6128
6259
  HEALTH_ITEMS,
6129
6260
  KEY_ITEMS,
6130
6261
  KeyId,
6262
+ M_CheckBottom,
6131
6263
  M_MoveFrame,
6264
+ M_walkmove,
6132
6265
  MoveType,
6133
6266
  ORDERED_DAMAGE_MODS,
6134
6267
  POWERUP_ITEMS,
@@ -6139,6 +6272,8 @@ function createGame({ trace, pointcontents }, engine, options) {
6139
6272
  RangeCategory,
6140
6273
  SAVE_FORMAT_VERSION,
6141
6274
  SPAWNFLAG_MONSTER_AMBUSH,
6275
+ SV_NewChaseDir,
6276
+ SV_StepDirection,
6142
6277
  SaveStorage,
6143
6278
  ServerFlags,
6144
6279
  Solid,