SERVER: Wrap stance changing for readability, ensure beta precautions

This commit is contained in:
cypress 2023-12-30 10:17:05 -05:00
parent b6f4676a5c
commit c1b68a8cda
4 changed files with 107 additions and 98 deletions

View file

@ -194,12 +194,7 @@ void() GetDown =
push_away_zombies();
// Force the player to prone.
if (self.stance == 2) self.new_ofs_z = self.view_ofs_z - (PLAYER_CROUCH_HEIGHT + PLAYER_PRONE_HEIGHT);
if (self.stance == 1) self.new_ofs_z = self.view_ofs_z - PLAYER_CROUCH_HEIGHT;
self.stance = 0;
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_CROUCHING, PLAYER_MAXS_CROUCHING);
Player_SetStance(self, PLAYER_STANCE_PRONE, false);
// Get rid of Mule Kick Weapon
for(float i = 0; i < MAX_PLAYER_WEAPONS; i++) {
@ -348,20 +343,11 @@ void () GetUp =
// Play Getting Up Animation
PAnim_GetUp();
if (map_compatibility_mode != MAP_COMPAT_BETA) {
// Player is able to get up from here
if (Player_CanStandHere(self)) {
self.new_ofs_z = self.view_ofs_z + PLAYER_CROUCH_HEIGHT + PLAYER_PRONE_HEIGHT;
self.stance = 2;
setsize(self, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING);
}
// They can't, so make them crouch instead
else {
self.new_ofs_z = self.view_ofs_z + PLAYER_PRONE_HEIGHT;
self.stance = 1;
PAnim_CrouchWalk7(); // bad hack so they dont just end up fucking standing in a wall.
}
}
Player_SetStance(self, PLAYER_STANCE_STAND, false);
// Bad hack: if we're crouching, just play some dummy crouchwalk frames.
if (self.stance == PLAYER_STANCE_CROUCH)
PAnim_CrouchWalk7();
self.health = 100;
self.downedloop = 0; // used for death timing vs endgame

View file

@ -34,8 +34,8 @@ void() rec_downed;
#define PLAYER_START_HEALTH 100
#define PLAYER_CROUCH_HEIGHT 25
#define PLAYER_PRONE_HEIGHT 23
#define PLAYER_CROUCH_DIFFERENCE 25
#define PLAYER_PRONE_DIFFERENCE 23
#define PLAYER_ANIM_WALK 1
#define PLAYER_ANIM_SPRINT 2
@ -267,11 +267,84 @@ float(float dir) checkMovement =
//
float(entity who) Player_CanStandHere =
{
// There shouldn't be any real reason we'd care about this since beta maps don't support
// stance changing impacting the bbox, but still, consistency..
if (map_compatibility_mode == MAP_COMPAT_BETA)
tracebox(who.origin, PLAYER_MINS_QUAKE, PLAYER_MAXS_QUAKE, who.origin, true, who);
else
tracebox(who.origin, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING, who.origin, true, who);
return !trace_startsolid;
}
//
// Player_SetStance(who, preferred_stance, play_animation)
// Lowers the camera height as needed, registers
// preferred stance, plays animation, and sets
// bounding box (if applicable).
//
void(entity who, float preferred_stance, float play_animation) Player_SetStance =
{
// Don't bother if we're already the desired stance, or if it wasn't valid
if (who.stance == preferred_stance || preferred_stance < 0 || preferred_stance > 2)
return;
// First check -- if we want to stand, only crouch if there
// is no space for it.
if (preferred_stance == PLAYER_STANCE_STAND && !Player_CanStandHere(who))
preferred_stance = PLAYER_STANCE_CROUCH;
// Set the bounding box
if (map_compatibility_mode != MAP_COMPAT_BETA) {
if (preferred_stance != PLAYER_STANCE_STAND)
setsize(self, PLAYER_MINS_CROUCHING, PLAYER_MAXS_CROUCHING);
else
setsize(self, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING);
}
// Prone while standing? Lower to crouch + prone height.
if (who.stance == PLAYER_STANCE_STAND && preferred_stance == PLAYER_STANCE_PRONE)
who.new_ofs_z = who.view_ofs_z - (PLAYER_CROUCH_DIFFERENCE + PLAYER_CROUCH_DIFFERENCE);
// Prone while crouching? Lower to prone height.
else if (who.stance == PLAYER_STANCE_CROUCH && preferred_stance == PLAYER_STANCE_PRONE)
who.new_ofs_z = who.view_ofs_z - PLAYER_PRONE_DIFFERENCE;
// Crouch while proning? Raise to crouch height/take away prone difference.
else if (who.stance == PLAYER_STANCE_PRONE && preferred_stance == PLAYER_STANCE_CROUCH)
who.new_ofs_z = who.view_ofs_z + PLAYER_PRONE_DIFFERENCE;
// Crouch while standing? Lower to crouch height.
else if (who.stance == PLAYER_STANCE_STAND && preferred_stance == PLAYER_STANCE_CROUCH)
who.new_ofs_z = who.view_ofs_z - PLAYER_CROUCH_DIFFERENCE;
// Stand while crouching? Raise to stand height/take away crouch difference.
else if (who.stance == PLAYER_STANCE_CROUCH && preferred_stance == PLAYER_STANCE_STAND)
who.new_ofs_z = who.view_ofs_z + PLAYER_CROUCH_DIFFERENCE;
// Stand while proning? Raise to stand height/take away crouch + prone difference.
else if (who.stance == PLAYER_STANCE_PRONE && preferred_stance == PLAYER_STANCE_STAND)
who.new_ofs_z = who.view_ofs_z + (PLAYER_CROUCH_DIFFERENCE + PLAYER_CROUCH_DIFFERENCE);
// Set the stance value
who.stance = preferred_stance;
// Animation playback
if (play_animation == true) {
entity tempe = self;
self = who;
switch(who.stance) {
case PLAYER_STANCE_STAND: PAnim_Stand(); break;
case PLAYER_STANCE_CROUCH: PAnim_Crouch(); break;
case PLAYER_STANCE_PRONE: PAnim_Prone(); break;
default: break;
}
self = tempe;
}
}
void() PlayerJump =
{
if (!(self.flags & FL_ONGROUND)
@ -304,27 +377,14 @@ void(float override) JumpCheck =
if (self.downed)
return;
if (self.stance == 2) {
if (self.stance == PLAYER_STANCE_STAND) {
// naievil -- stop sprinting if we jump, which is a real mechanic from the game that we never implemented
if (self.sprinting) {
W_SprintStop();
}
PlayerJump();
} else if (self.view_ofs_z == self.new_ofs_z && (self.flags & FL_ONGROUND) && Player_CanStandHere(self)) {
switch(self.stance) {
case 0:
self.new_ofs_z = self.view_ofs_z + PLAYER_CROUCH_HEIGHT + PLAYER_PRONE_HEIGHT;
self.stance = 2;
break;
case 1:
self.new_ofs_z = self.view_ofs_z + PLAYER_CROUCH_HEIGHT;
self.stance = 2;
break;
default: break;
}
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING);
} else if (self.view_ofs_z == self.new_ofs_z && (self.flags & FL_ONGROUND)) {
Player_SetStance(self, PLAYER_STANCE_STAND, true);
}
} else
self.flags = self.flags | FL_JUMPRELEASED;
@ -337,6 +397,7 @@ void() PlayerPreThink =
self.maxspeed = 30;
} else {
// Walk slower to account for NZ:P Beta Scaling.
if (map_compatibility_mode == MAP_COMPAT_BETA)
self.maxspeed = 150;
else
@ -791,6 +852,7 @@ void() PlayerSpawn =
self.fixangle = true;
// NZ:P Beta used Quake BSP 29, so set bounding box accordingly.
if (map_compatibility_mode == MAP_COMPAT_BETA) {
self.view_ofs = VIEW_OFS_QK;
setsize(self, PLAYER_MINS_QUAKE, PLAYER_MAXS_QUAKE);

View file

@ -1531,55 +1531,31 @@ void() Change_Stance = {
return;
switch(self.stance) {
case 2:
self.new_ofs_z = self.view_ofs_z - PLAYER_CROUCH_HEIGHT;
self.stance = 1;
PAnim_Crouch();
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_CROUCHING, PLAYER_MAXS_CROUCHING);
case PLAYER_STANCE_STAND:
Player_SetStance(self, PLAYER_STANCE_CROUCH, true);
break;
case 1:
// Prohibit Proning if Drinking a Perk-A-Cola
if (self.isBuying && Player_CanStandHere(self)) {
self.stance = 2;
self.new_ofs_z = self.view_ofs_z + PLAYER_CROUCH_HEIGHT;
PAnim_Stand();
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING);
// Prohibit Proning if Drinking a Perk-A-Cola, just stand.
if (self.isBuying) {
Player_SetStance(self, PLAYER_STANCE_STAND, true);
}
// Stance flag isn't set, so go Prone.
else if (!self.stancereset) {
self.new_ofs_z = self.view_ofs_z - PLAYER_PRONE_HEIGHT;
self.stance = 0;
PAnim_Prone();
Player_SetStance(self, PLAYER_STANCE_PRONE, true);
}
// Stance flag IS set, so stand if applicable.
else if (Player_CanStandHere(self)) {
self.new_ofs_z = self.view_ofs_z + PLAYER_CROUCH_HEIGHT;
self.stance = 2;
self.stancereset = 0;
PAnim_Stand();
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING);
Player_SetStance(self, PLAYER_STANCE_STAND, true);
self.stancereset = false;
}
// There's no room to stand, just prone again.
else {
self.new_ofs_z = self.view_ofs_z - PLAYER_PRONE_HEIGHT;
self.stance = 0;
PAnim_Prone();
Player_SetStance(self, PLAYER_STANCE_PRONE, true);
}
break;
case 0:
self.new_ofs_z = self.view_ofs_z + PLAYER_PRONE_HEIGHT;
self.stance = self.stancereset = 1;
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_CROUCHING, PLAYER_MAXS_CROUCHING);
PAnim_UpCrouch();
Player_SetStance(self, PLAYER_STANCE_CROUCH, true);
self.stancereset = true;
break;
default: break;
}
@ -1626,11 +1602,7 @@ void() dolphin_dive = //naievil
sound(self, CHAN_VOICE, "sounds/player/jump.wav", 1, 1);
self.oldz = self.origin_z;
self.new_ofs_z = self.view_ofs_z - (PLAYER_CROUCH_HEIGHT + PLAYER_PRONE_HEIGHT);
self.stance = 0;
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_CROUCHING, PLAYER_MAXS_CROUCHING);
Player_SetStance(self, PLAYER_STANCE_PRONE, false);
}
@ -1665,23 +1637,8 @@ void () Impulse_Functions =
if (self.dive || self.downed || !Player_CanStandHere(self))
return;
switch(self.stance) {
case 0:
self.new_ofs_z = self.view_ofs_z + PLAYER_CROUCH_HEIGHT + PLAYER_PRONE_HEIGHT;
self.stance = 2;
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING);
break;
case 1:
self.new_ofs_z = self.view_ofs_z + PLAYER_CROUCH_HEIGHT;
self.stance = 2;
if (map_compatibility_mode != MAP_COMPAT_BETA)
setsize(self, PLAYER_MINS_STANDING, PLAYER_MAXS_STANDING);
break;
default: break;
}
Player_SetStance(self, PLAYER_STANCE_STAND, false);
self.sprintflag = true;
W_SprintStart();
break;

View file

@ -82,6 +82,10 @@ const float EVENT_MAPTYPE = 49;
#define PLAYER_MINS_CROUCHING '-16 -16 -32'
#define PLAYER_MAXS_CROUCHING '16 16 4'
#define PLAYER_STANCE_STAND 2
#define PLAYER_STANCE_CROUCH 1
#define PLAYER_STANCE_PRONE 0
// map compatibility
#define MAP_COMPAT_BETA 1
float map_compatibility_mode;