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.
@@ -3661,6 +3661,131 @@ function ai_charge(self, distance2, deltaSeconds) {
3661
3661
  walkMove(self, self.angles.y, distance2);
3662
3662
  }
3663
3663
  }
3664
+ function CheckGround(self, context) {
3665
+ if (self.movetype === 1 /* Noclip */) {
3666
+ return;
3667
+ }
3668
+ const point = {
3669
+ x: self.origin.x,
3670
+ y: self.origin.y,
3671
+ z: self.origin.z + self.mins.z - 1
3672
+ };
3673
+ const trace = context.trace(self.origin, self.mins, self.maxs, point, self, MASK_MONSTERSOLID);
3674
+ self.groundentity = trace.ent;
3675
+ if (!self.groundentity && !trace.allsolid && !trace.startsolid && trace.fraction === 1) {
3676
+ const content = context.pointcontents(point);
3677
+ if (content & MASK_WATER) {
3678
+ self.waterlevel = 1;
3679
+ self.watertype = content;
3680
+ } else {
3681
+ self.waterlevel = 0;
3682
+ self.watertype = 0;
3683
+ }
3684
+ }
3685
+ }
3686
+ function M_CheckBottom(self, context) {
3687
+ const mins = {
3688
+ x: self.origin.x + self.mins.x,
3689
+ y: self.origin.y + self.mins.y,
3690
+ z: self.origin.z + self.mins.z
3691
+ };
3692
+ const maxs = {
3693
+ x: self.origin.x + self.maxs.x,
3694
+ y: self.origin.y + self.maxs.y,
3695
+ z: self.origin.z + self.maxs.z
3696
+ };
3697
+ let start = { x: 0, y: 0, z: 0 };
3698
+ let stop = { x: 0, y: 0, z: 0 };
3699
+ for (let i = 0; i < 2; i++) {
3700
+ if (i === 1) start = { x: mins.x, y: mins.y, z: 0 };
3701
+ else start = { x: maxs.x, y: mins.y, z: 0 };
3702
+ start.z = mins.z - 1;
3703
+ if (context.pointcontents(start) !== 0) return true;
3704
+ stop = { ...start };
3705
+ stop.z = start.z - 60;
3706
+ const trace = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3707
+ if (trace.fraction < 1) return true;
3708
+ if (i === 1) start = { x: mins.x, y: maxs.y, z: 0 };
3709
+ else start = { x: maxs.x, y: maxs.y, z: 0 };
3710
+ start.z = mins.z - 1;
3711
+ if (context.pointcontents(start) !== 0) return true;
3712
+ stop = { ...start };
3713
+ stop.z = start.z - 60;
3714
+ const trace2 = context.trace(start, null, null, stop, self, MASK_MONSTERSOLID);
3715
+ if (trace2.fraction < 1) return true;
3716
+ }
3717
+ return false;
3718
+ }
3719
+ function M_walkmove(self, yawDegrees, distance2, context) {
3720
+ if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0) && self.movetype !== 1 /* Noclip */) {
3721
+ if (!self.groundentity && self.waterlevel === 0) {
3722
+ return false;
3723
+ }
3724
+ }
3725
+ const delta = yawVector(yawDegrees, distance2);
3726
+ if ((self.monsterinfo.aiflags & 1024 /* NoStep */) !== 0 && (self.monsterinfo.aiflags & 1073741824 /* Pathing */) !== 0) {
3727
+ }
3728
+ const dest = {
3729
+ x: self.origin.x + delta.x,
3730
+ y: self.origin.y + delta.y,
3731
+ z: self.origin.z + delta.z
3732
+ };
3733
+ const trace = context.trace(self.origin, self.mins, self.maxs, dest, self, MASK_MONSTERSOLID);
3734
+ if (trace.fraction < 1) {
3735
+ return false;
3736
+ }
3737
+ const oldOrigin = { ...self.origin };
3738
+ self.origin.x = dest.x;
3739
+ self.origin.y = dest.y;
3740
+ self.origin.z = dest.z;
3741
+ if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0) && self.movetype !== 1 /* Noclip */) {
3742
+ if (!M_CheckBottom(self, context)) {
3743
+ self.origin.x = oldOrigin.x;
3744
+ self.origin.y = oldOrigin.y;
3745
+ self.origin.z = oldOrigin.z;
3746
+ return false;
3747
+ }
3748
+ }
3749
+ if (!((self.flags & (2 /* Swim */ | 1 /* Fly */)) !== 0)) {
3750
+ CheckGround(self, context);
3751
+ }
3752
+ return true;
3753
+ }
3754
+ function SV_StepDirection(self, yaw, dist, context) {
3755
+ for (let i = 0; i <= 90; i += 45) {
3756
+ if (M_walkmove(self, yaw + i, dist, context)) {
3757
+ if (i !== 0) {
3758
+ self.ideal_yaw = angleMod(yaw + i);
3759
+ }
3760
+ return true;
3761
+ }
3762
+ if (i !== 0) {
3763
+ if (M_walkmove(self, yaw - i, dist, context)) {
3764
+ self.ideal_yaw = angleMod(yaw - i);
3765
+ return true;
3766
+ }
3767
+ }
3768
+ }
3769
+ return false;
3770
+ }
3771
+ function SV_NewChaseDir(self, enemy, dist, context) {
3772
+ if (!enemy) return;
3773
+ const olddir = angleMod(self.ideal_yaw - self.angles.y);
3774
+ const turnaround = Math.abs(olddir - 180) < 20;
3775
+ const dx = enemy.origin.x - self.origin.x;
3776
+ const dy = enemy.origin.y - self.origin.y;
3777
+ if (Math.abs(dx) > Math.abs(dy)) {
3778
+ if (dx > 0) self.ideal_yaw = 0;
3779
+ else self.ideal_yaw = 180;
3780
+ } else {
3781
+ if (dy > 0) self.ideal_yaw = 90;
3782
+ else self.ideal_yaw = 270;
3783
+ }
3784
+ if (turnaround) {
3785
+ self.ideal_yaw = angleMod(self.ideal_yaw + 180);
3786
+ }
3787
+ SV_StepDirection(self, self.ideal_yaw, dist, context);
3788
+ }
3664
3789
 
3665
3790
  // src/ai/targeting.ts
3666
3791
  function setIdealYawTowards2(self, other) {
@@ -5965,6 +6090,7 @@ export {
5965
6090
  AmmoItemId,
5966
6091
  AmmoType,
5967
6092
  ArmorType,
6093
+ CheckGround,
5968
6094
  DamageFlags,
5969
6095
  DamageMod,
5970
6096
  DeadFlag,
@@ -5978,7 +6104,9 @@ export {
5978
6104
  HEALTH_ITEMS,
5979
6105
  KEY_ITEMS,
5980
6106
  KeyId,
6107
+ M_CheckBottom,
5981
6108
  M_MoveFrame,
6109
+ M_walkmove,
5982
6110
  MoveType,
5983
6111
  ORDERED_DAMAGE_MODS,
5984
6112
  POWERUP_ITEMS,
@@ -5989,6 +6117,8 @@ export {
5989
6117
  RangeCategory,
5990
6118
  SAVE_FORMAT_VERSION,
5991
6119
  SPAWNFLAG_MONSTER_AMBUSH,
6120
+ SV_NewChaseDir,
6121
+ SV_StepDirection,
5992
6122
  SaveStorage,
5993
6123
  ServerFlags,
5994
6124
  Solid,