diff --git a/src/common/pmove.c b/src/common/pmove.c index 57d61192..965d8482 100644 --- a/src/common/pmove.c +++ b/src/common/pmove.c @@ -1,35 +1,42 @@ /* -Copyright (C) 1997-2001 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Player movement code. This is the core of Quake IIs legendary physics + * engine + * + * ======================================================================= + */ #include "qcommon.h" -#define STEPSIZE 18 +#define STEPSIZE 18 -// all of the locals will be zeroed before each -// pmove, just to make damn sure we don't have -// any differences when running on client or server +/* all of the locals will be zeroed before each + pmove, just to make damn sure we don't have + any differences when running on client or server */ typedef struct { - vec3_t origin; // full float precision - vec3_t velocity; // full float precision + vec3_t origin; /* full float precision */ + vec3_t velocity; /* full float precision */ vec3_t forward, right, up; float frametime; @@ -46,7 +53,7 @@ typedef struct pmove_t *pm; pml_t pml; -// movement parameters +/* movement parameters */ float pm_stopspeed = 100; float pm_maxspeed = 300; float pm_duckspeed = 100; @@ -58,20 +65,10 @@ float pm_waterfriction = 1; float pm_waterspeed = 400; /* + * Slide off of the impacting object + * returns the blocked flags (1 = floor, 2 = step / wall) + */ - walking up a step should kill some velocity - -*/ - - -/* -================== -PM_ClipVelocity - -Slide off of the impacting object -returns the blocked flags (1 = floor, 2 = step / wall) -================== -*/ #define STOP_EPSILON 0.1 void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce) @@ -79,30 +76,27 @@ void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce) float backoff; float change; int i; - + backoff = DotProduct (in, normal) * overbounce; for (i=0 ; i<3 ; i++) { change = normal[i]*backoff; out[i] = in[i] - change; + if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON) out[i] = 0; } } /* -================== -PM_StepSlideMove - -Each intersection will try to step over the obstruction instead of -sliding along it. - -Returns a new origin, velocity, and contact entity -Does not modify any world state? -================== -*/ -#define MIN_STEP_NORMAL 0.7 // can't step up onto very steep slopes + * Each intersection will try to step over the obstruction instead of + * sliding along it. + * + * Returns a new origin, velocity, and contact entity + * Does not modify any world state? + */ +#define MIN_STEP_NORMAL 0.7 /* can't step up onto very steep slopes */ #define MAX_CLIP_PLANES 5 void PM_StepSlideMove_ (void) { @@ -116,12 +110,12 @@ void PM_StepSlideMove_ (void) trace_t trace; vec3_t end; float time_left; - + numbumps = 4; - + VectorCopy (pml.velocity, primal_velocity); numplanes = 0; - + time_left = pml.frametime; for (bumpcount=0 ; bumpcounttrace (pml.origin, pm->mins, pm->maxs, end); if (trace.allsolid) - { // entity is trapped in another solid - pml.velocity[2] = 0; // don't build up falling damage + { + /* entity is trapped in another solid */ + pml.velocity[2] = 0; /* don't build up falling damage */ return; } if (trace.fraction > 0) - { // actually covered some distance + { + /* actually covered some distance */ VectorCopy (trace.endpos, pml.origin); numplanes = 0; } if (trace.fraction == 1) - break; // moved the entire distance + break; /* moved the entire distance */ - // save entity for contact + /* save entity for contact */ if (pm->numtouch < MAXTOUCH && trace.ent) { pm->touchents[pm->numtouch] = trace.ent; pm->numtouch++; } - + time_left -= time_left * trace.fraction; - // slide along this plane + /* slide along this plane */ if (numplanes >= MAX_CLIP_PLANES) - { // this shouldn't really happen + { + /* this shouldn't really happen */ VectorCopy (vec3_origin, pml.velocity); break; } @@ -165,41 +162,42 @@ void PM_StepSlideMove_ (void) VectorCopy (trace.plane.normal, planes[numplanes]); numplanes++; - // - // modify original_velocity so it parallels all of the clip planes - // + /* modify original_velocity so it parallels all of the clip planes */ for (i=0 ; itrace (up, pm->mins, pm->maxs, up); - if (trace.allsolid) - return; // can't step up - // try sliding above + if (trace.allsolid) + return; /* can't step up */ + + /* try sliding above */ VectorCopy (up, pml.origin); VectorCopy (start_v, pml.velocity); PM_StepSlideMove_ (); - // push down the final amount + /* push down the final amount */ VectorCopy (pml.origin, down); down[2] -= STEPSIZE; trace = pm->trace (pml.origin, pm->mins, pm->maxs, down); + if (!trace.allsolid) { VectorCopy (trace.endpos, pml.origin); @@ -259,11 +253,11 @@ void PM_StepSlideMove (void) VectorCopy(pml.origin, up); - // decide which one went farther - down_dist = (down_o[0] - start_o[0])*(down_o[0] - start_o[0]) - + (down_o[1] - start_o[1])*(down_o[1] - start_o[1]); - up_dist = (up[0] - start_o[0])*(up[0] - start_o[0]) - + (up[1] - start_o[1])*(up[1] - start_o[1]); + /* decide which one went farther */ + down_dist = (down_o[0] - start_o[0])*(down_o[0] - start_o[0]) + + (down_o[1] - start_o[1])*(down_o[1] - start_o[1]); + up_dist = (up[0] - start_o[0])*(up[0] - start_o[0]) + + (up[1] - start_o[1])*(up[1] - start_o[1]); if (down_dist > up_dist || trace.plane.normal[2] < MIN_STEP_NORMAL) { @@ -271,29 +265,24 @@ void PM_StepSlideMove (void) VectorCopy (down_v, pml.velocity); return; } - //!! Special case - // if we were walking along a plane, then we need to copy the Z over + pml.velocity[2] = down_v[2]; } - /* -================== -PM_Friction - -Handles both ground friction and water friction -================== -*/ + * Handles both ground friction and water friction + */ void PM_Friction (void) { float *vel; float speed, newspeed, control; float friction; float drop; - + vel = pml.velocity; - + speed = (float)sqrt(vel[0]*vel[0] +vel[1]*vel[1] + vel[2]*vel[2]); + if (speed < 1) { vel[0] = 0; @@ -303,7 +292,7 @@ void PM_Friction (void) drop = 0; - // apply ground friction + /* apply ground friction */ if ((pm->groundentity && pml.groundsurface && !(pml.groundsurface->flags & SURF_SLICK) ) || (pml.ladder) ) { friction = pm_friction; @@ -311,16 +300,18 @@ void PM_Friction (void) drop += control*friction*pml.frametime; } - // apply water friction + /* apply water friction */ if (pm->waterlevel && !pml.ladder) drop += speed*pm_waterfriction*pm->waterlevel*pml.frametime; - // scale the velocity + /* scale the velocity */ newspeed = speed - drop; + if (newspeed < 0) { newspeed = 0; } + newspeed /= speed; vel[0] = vel[0] * newspeed; @@ -329,12 +320,8 @@ void PM_Friction (void) } /* -============== -PM_Accelerate - -Handles user intended acceleration -============== -*/ + * Handles user intended acceleration + */ void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel) { int i; @@ -342,135 +329,137 @@ void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel) currentspeed = DotProduct (pml.velocity, wishdir); addspeed = wishspeed - currentspeed; + if (addspeed <= 0) return; + accelspeed = accel*pml.frametime*wishspeed; + if (accelspeed > addspeed) accelspeed = addspeed; - + for (i=0 ; i<3 ; i++) - pml.velocity[i] += accelspeed*wishdir[i]; + pml.velocity[i] += accelspeed*wishdir[i]; } void PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel) { int i; float addspeed, accelspeed, currentspeed, wishspd = wishspeed; - + if (wishspd > 30) wishspd = 30; + currentspeed = DotProduct (pml.velocity, wishdir); addspeed = wishspd - currentspeed; + if (addspeed <= 0) return; + accelspeed = accel * wishspeed * pml.frametime; + if (accelspeed > addspeed) accelspeed = addspeed; - + for (i=0 ; i<3 ; i++) - pml.velocity[i] += accelspeed*wishdir[i]; + pml.velocity[i] += accelspeed*wishdir[i]; } -/* -============= -PM_AddCurrents -============= -*/ void PM_AddCurrents (vec3_t wishvel) { vec3_t v; float s; - // - // account for ladders - // - + /* account for ladders */ if (pml.ladder && fabs(pml.velocity[2]) <= 200) { if ((pm->viewangles[PITCH] <= -15) && (pm->cmd.forwardmove > 0)) wishvel[2] = 200; + else if ((pm->viewangles[PITCH] >= 15) && (pm->cmd.forwardmove > 0)) wishvel[2] = -200; + else if (pm->cmd.upmove > 0) wishvel[2] = 200; + else if (pm->cmd.upmove < 0) wishvel[2] = -200; + else wishvel[2] = 0; - // limit horizontal speed when on a ladder + /* limit horizontal speed when on a ladder */ if (wishvel[0] < -25) wishvel[0] = -25; + else if (wishvel[0] > 25) wishvel[0] = 25; if (wishvel[1] < -25) wishvel[1] = -25; + else if (wishvel[1] > 25) wishvel[1] = 25; } - - // - // add water currents - // - + /* add water currents */ if (pm->watertype & MASK_CURRENT) { VectorClear (v); if (pm->watertype & CONTENTS_CURRENT_0) v[0] += 1; + if (pm->watertype & CONTENTS_CURRENT_90) v[1] += 1; + if (pm->watertype & CONTENTS_CURRENT_180) v[0] -= 1; + if (pm->watertype & CONTENTS_CURRENT_270) v[1] -= 1; + if (pm->watertype & CONTENTS_CURRENT_UP) v[2] += 1; + if (pm->watertype & CONTENTS_CURRENT_DOWN) v[2] -= 1; s = pm_waterspeed; + if ((pm->waterlevel == 1) && (pm->groundentity)) s /= 2; VectorMA (wishvel, s, v, wishvel); } - // - // add conveyor belt velocities - // - + /* add conveyor belt velocities */ if (pm->groundentity) { VectorClear (v); if (pml.groundcontents & CONTENTS_CURRENT_0) v[0] += 1; + if (pml.groundcontents & CONTENTS_CURRENT_90) v[1] += 1; + if (pml.groundcontents & CONTENTS_CURRENT_180) v[0] -= 1; + if (pml.groundcontents & CONTENTS_CURRENT_270) v[1] -= 1; + if (pml.groundcontents & CONTENTS_CURRENT_UP) v[2] += 1; + if (pml.groundcontents & CONTENTS_CURRENT_DOWN) v[2] -= 1; - VectorMA (wishvel, 100 /* pm->groundentity->speed */, v, wishvel); + VectorMA (wishvel, 100, v, wishvel); } } - -/* -=================== -PM_WaterMove - -=================== -*/ void PM_WaterMove (void) { int i; @@ -478,14 +467,13 @@ void PM_WaterMove (void) float wishspeed; vec3_t wishdir; - // - // user intentions - // + /* user intentions */ for (i=0 ; i<3 ; i++) wishvel[i] = pml.forward[i]*pm->cmd.forwardmove + pml.right[i]*pm->cmd.sidemove; if (!pm->cmd.forwardmove && !pm->cmd.sidemove && !pm->cmd.upmove) - wishvel[2] -= 60; // drift towards bottom + wishvel[2] -= 60; /* drift towards bottom */ + else wishvel[2] += pm->cmd.upmove; @@ -499,6 +487,7 @@ void PM_WaterMove (void) VectorScale (wishvel, pm_maxspeed/wishspeed, wishvel); wishspeed = pm_maxspeed; } + wishspeed *= 0.5; PM_Accelerate (wishdir, wishspeed, pm_wateraccelerate); @@ -506,13 +495,6 @@ void PM_WaterMove (void) PM_StepSlideMove (); } - -/* -=================== -PM_AirMove - -=================== -*/ void PM_AirMove (void) { int i; @@ -527,6 +509,7 @@ void PM_AirMove (void) for (i=0 ; i<2 ; i++) wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove; + wishvel[2] = 0; PM_AddCurrents (wishvel); @@ -534,9 +517,7 @@ void PM_AirMove (void) VectorCopy (wishvel, wishdir); wishspeed = VectorNormalize(wishdir); - // - // clamp to server defined max speed - // + /* clamp to server defined max speed */ maxspeed = (pm->s.pm_flags & PMF_DUCKED) ? pm_duckspeed : pm_maxspeed; if (wishspeed > maxspeed) @@ -544,60 +525,66 @@ void PM_AirMove (void) VectorScale (wishvel, maxspeed/wishspeed, wishvel); wishspeed = maxspeed; } - + if ( pml.ladder ) { PM_Accelerate (wishdir, wishspeed, pm_accelerate); + if (!wishvel[2]) { if (pml.velocity[2] > 0) { pml.velocity[2] -= pm->s.gravity * pml.frametime; + if (pml.velocity[2] < 0) pml.velocity[2] = 0; } + else { pml.velocity[2] += pm->s.gravity * pml.frametime; + if (pml.velocity[2] > 0) pml.velocity[2] = 0; } } + PM_StepSlideMove (); } + else if ( pm->groundentity ) - { // walking on ground - pml.velocity[2] = 0; //!!! this is before the accel + { + /* walking on ground */ + pml.velocity[2] = 0; PM_Accelerate (wishdir, wishspeed, pm_accelerate); - // PGM -- fix for negative trigger_gravity fields if(pm->s.gravity > 0) pml.velocity[2] = 0; + else pml.velocity[2] -= pm->s.gravity * pml.frametime; - // PGM if (!pml.velocity[0] && !pml.velocity[1]) return; + PM_StepSlideMove (); } + else - { // not on ground, so little effect on velocity + { + /* not on ground, so little effect on velocity */ if (pm_airaccelerate) PM_AirAccelerate (wishdir, wishspeed, pm_accelerate); + else PM_Accelerate (wishdir, wishspeed, 1); - // add gravity + + /* add gravity */ pml.velocity[2] -= pm->s.gravity * pml.frametime; PM_StepSlideMove (); } } -/* -============= -PM_CatagorizePosition -============= -*/ void PM_CatagorizePosition (void) { vec3_t point; @@ -606,18 +593,20 @@ void PM_CatagorizePosition (void) float sample1; float sample2; - // if the player hull point one unit down is solid, the player - // is on ground + /* if the player hull point one unit down + is solid, the player is on ground */ - // see if standing on something solid + /* see if standing on something solid */ point[0] = pml.origin[0]; point[1] = pml.origin[1]; point[2] = pml.origin[2] - 0.25f; - if (pml.velocity[2] > 180) //!!ZOID changed from 100 to 180 (ramp accel) + + if (pml.velocity[2] > 180) { pm->s.pm_flags &= ~PMF_ON_GROUND; pm->groundentity = NULL; } + else { trace = pm->trace (pml.origin, pm->mins, pm->maxs, point); @@ -630,11 +619,12 @@ void PM_CatagorizePosition (void) pm->groundentity = NULL; pm->s.pm_flags &= ~PMF_ON_GROUND; } + else { pm->groundentity = trace.ent; - // hitting solid ground will end a waterjump + /* hitting solid ground will end a waterjump */ if (pm->s.pm_flags & PMF_TIME_WATERJUMP) { pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); @@ -642,15 +632,19 @@ void PM_CatagorizePosition (void) } if (! (pm->s.pm_flags & PMF_ON_GROUND) ) - { // just hit the ground + { + /* just hit the ground */ pm->s.pm_flags |= PMF_ON_GROUND; - // don't do landing time if we were just going down a slope + + /* don't do landing time if we were just going down a slope */ if (pml.velocity[2] < -200) { pm->s.pm_flags |= PMF_TIME_LAND; - // don't allow another jump for a little while + + /* don't allow another jump for a little while */ if (pml.velocity[2] < -400) - pm->s.pm_time = 25; + pm->s.pm_time = 25; + else pm->s.pm_time = 18; } @@ -664,16 +658,14 @@ void PM_CatagorizePosition (void) } } - // - // get waterlevel, accounting for ducking - // + /* get waterlevel, accounting for ducking */ pm->waterlevel = 0; pm->watertype = 0; sample2 = pm->viewheight - pm->mins[2]; sample1 = sample2 / 2; - point[2] = pml.origin[2] + pm->mins[2] + 1; + point[2] = pml.origin[2] + pm->mins[2] + 1; cont = pm->pointcontents (point); if (cont & MASK_WATER) @@ -682,11 +674,13 @@ void PM_CatagorizePosition (void) pm->waterlevel = 1; point[2] = pml.origin[2] + pm->mins[2] + sample1; cont = pm->pointcontents (point); + if (cont & MASK_WATER) { pm->waterlevel = 2; point[2] = pml.origin[2] + pm->mins[2] + sample2; cont = pm->pointcontents (point); + if (cont & MASK_WATER) pm->waterlevel = 3; } @@ -694,25 +688,22 @@ void PM_CatagorizePosition (void) } -/* -============= -PM_CheckJump -============= -*/ void PM_CheckJump (void) { if (pm->s.pm_flags & PMF_TIME_LAND) - { // hasn't been long enough since landing to jump again + { + /* hasn't been long enough since landing to jump again */ return; } if (pm->cmd.upmove < 10) - { // not holding jump + { + /* not holding jump */ pm->s.pm_flags &= ~PMF_JUMP_HELD; return; } - // must wait for jump to be released + /* must wait for jump to be released */ if (pm->s.pm_flags & PMF_JUMP_HELD) return; @@ -720,7 +711,8 @@ void PM_CheckJump (void) return; if (pm->waterlevel >= 2) - { // swimming, not jumping + { + /* swimming, not jumping */ pm->groundentity = NULL; if (pml.velocity[2] <= -300) @@ -728,30 +720,28 @@ void PM_CheckJump (void) if (pm->watertype == CONTENTS_WATER) pml.velocity[2] = 100; + else if (pm->watertype == CONTENTS_SLIME) pml.velocity[2] = 80; + else pml.velocity[2] = 50; + return; } if (pm->groundentity == NULL) - return; // in air, so no effect + return; /* in air, so no effect */ pm->s.pm_flags |= PMF_JUMP_HELD; pm->groundentity = NULL; pml.velocity[2] += 270; + if (pml.velocity[2] < 270) pml.velocity[2] = 270; } - -/* -============= -PM_CheckSpecialMovement -============= -*/ void PM_CheckSpecialMovement (void) { vec3_t spot; @@ -764,7 +754,7 @@ void PM_CheckSpecialMovement (void) pml.ladder = false; - // check for ladder + /* check for ladder */ flatforward[0] = pml.forward[0]; flatforward[1] = pml.forward[1]; flatforward[2] = 0; @@ -772,24 +762,28 @@ void PM_CheckSpecialMovement (void) VectorMA (pml.origin, 1, flatforward, spot); trace = pm->trace (pml.origin, pm->mins, pm->maxs, spot); + if ((trace.fraction < 1) && (trace.contents & CONTENTS_LADDER)) pml.ladder = true; - // check for water jump + /* check for water jump */ if (pm->waterlevel != 2) return; VectorMA (pml.origin, 30, flatforward, spot); spot[2] += 4; cont = pm->pointcontents (spot); + if (!(cont & CONTENTS_SOLID)) return; spot[2] += 16; cont = pm->pointcontents (spot); + if (cont) return; - // jump out of water + + /* jump out of water */ VectorScale (flatforward, 50, pml.velocity); pml.velocity[2] = 350; @@ -797,12 +791,6 @@ void PM_CheckSpecialMovement (void) pm->s.pm_time = 255; } - -/* -=============== -PM_FlyMove -=============== -*/ void PM_FlyMove (qboolean doclip) { float speed, drop, friction, control, newspeed; @@ -817,86 +805,89 @@ void PM_FlyMove (qboolean doclip) pm->viewheight = 22; - // friction - + /* friction */ speed = VectorLength (pml.velocity); + if (speed < 1) { VectorCopy (vec3_origin, pml.velocity); } + else { drop = 0; - friction = pm_friction*1.5f; // extra friction + friction = pm_friction*1.5f; /* extra friction */ control = speed < pm_stopspeed ? pm_stopspeed : speed; drop += control*friction*pml.frametime; - // scale the velocity + /* scale the velocity */ newspeed = speed - drop; + if (newspeed < 0) newspeed = 0; + newspeed /= speed; VectorScale (pml.velocity, newspeed, pml.velocity); } - // accelerate + /* accelerate */ fmove = pm->cmd.forwardmove; smove = pm->cmd.sidemove; - + VectorNormalize (pml.forward); VectorNormalize (pml.right); for (i=0 ; i<3 ; i++) wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove; + wishvel[2] += pm->cmd.upmove; VectorCopy (wishvel, wishdir); wishspeed = VectorNormalize(wishdir); - // - // clamp to server defined max speed - // + /* clamp to server defined max speed */ if (wishspeed > pm_maxspeed) { VectorScale (wishvel, pm_maxspeed/wishspeed, wishvel); wishspeed = pm_maxspeed; } - currentspeed = DotProduct(pml.velocity, wishdir); addspeed = wishspeed - currentspeed; + if (addspeed <= 0) return; + accelspeed = pm_accelerate*pml.frametime*wishspeed; + if (accelspeed > addspeed) accelspeed = addspeed; - - for (i=0 ; i<3 ; i++) - pml.velocity[i] += accelspeed*wishdir[i]; - if (doclip) { + for (i=0 ; i<3 ; i++) + pml.velocity[i] += accelspeed*wishdir[i]; + + if (doclip) + { for (i=0 ; i<3 ; i++) end[i] = pml.origin[i] + pml.frametime * pml.velocity[i]; trace = pm->trace (pml.origin, pm->mins, pm->maxs, end); VectorCopy (trace.endpos, pml.origin); - } else { - // move + } + + else + { + /* move */ VectorMA (pml.origin, pml.frametime, pml.velocity, pml.origin); } } - /* -============== -PM_CheckDuck - -Sets mins, maxs, and pm->viewheight -============== -*/ + * Sets mins, maxs, and pm->viewheight + */ void PM_CheckDuck (void) { trace_t trace; @@ -921,17 +912,22 @@ void PM_CheckDuck (void) { pm->s.pm_flags |= PMF_DUCKED; } + else if (pm->cmd.upmove < 0 && (pm->s.pm_flags & PMF_ON_GROUND) ) - { // duck + { + /* duck */ pm->s.pm_flags |= PMF_DUCKED; } + else - { // stand up if possible + { + /* stand up if possible */ if (pm->s.pm_flags & PMF_DUCKED) { - // try to stand up + /* try to stand up */ pm->maxs[2] = 32; trace = pm->trace (pml.origin, pm->mins, pm->maxs, pml.origin); + if (!trace.allsolid) pm->s.pm_flags &= ~PMF_DUCKED; } @@ -942,6 +938,7 @@ void PM_CheckDuck (void) pm->maxs[2] = 4; pm->viewheight = -2; } + else { pm->maxs[2] = 32; @@ -949,12 +946,6 @@ void PM_CheckDuck (void) } } - -/* -============== -PM_DeadMove -============== -*/ void PM_DeadMove (void) { float forward; @@ -962,14 +953,15 @@ void PM_DeadMove (void) if (!pm->groundentity) return; - // extra friction - + /* extra friction */ forward = VectorLength (pml.velocity); forward -= 20; + if (forward <= 0) { VectorClear (pml.velocity); } + else { VectorNormalize (pml.velocity); @@ -977,7 +969,6 @@ void PM_DeadMove (void) } } - qboolean PM_GoodPosition (void) { trace_t trace; @@ -989,28 +980,25 @@ qboolean PM_GoodPosition (void) for (i=0 ; i<3 ; i++) origin[i] = end[i] = pm->s.origin[i]*0.125f; + trace = pm->trace (origin, pm->mins, pm->maxs, end); return !trace.allsolid; } /* -================ -PM_SnapPosition - -On exit, the origin will have a value that is pre-quantized to the 0.125 -precision of the network channel and in a valid position. -================ -*/ + * On exit, the origin will have a value that is pre-quantized to the 0.125 + * precision of the network channel and in a valid position. + */ void PM_SnapPosition (void) { int sign[3]; int i, j, bits; short base[3]; - // try all single bits first + /* try all single bits first */ static int jitterbits[8] = {0,4,1,2,3,5,6,7}; - // snap velocity to eigths + /* snap velocity to eigths */ for (i=0 ; i<3 ; i++) pm->s.velocity[i] = (int)(pml.velocity[i]*8); @@ -1018,19 +1006,24 @@ void PM_SnapPosition (void) { if (pml.origin[i] >= 0) sign[i] = 1; - else + + else sign[i] = -1; + pm->s.origin[i] = (int)(pml.origin[i]*8); + if (pm->s.origin[i]*0.125f == pml.origin[i]) sign[i] = 0; } + VectorCopy (pm->s.origin, base); - // try all combinations + /* try all combinations */ for (j=0 ; j<8 ; j++) { bits = jitterbits[j]; VectorCopy (base, pm->s.origin); + for (i=0 ; i<3 ; i++) if (bits & (1<s.origin[i] += sign[i]; @@ -1039,16 +1032,10 @@ void PM_SnapPosition (void) return; } - // go back to the last position + /* go back to the last position */ VectorCopy (pml.previous_origin, pm->s.origin); } -/* -================ -PM_InitialSnapPosition - -================ -*/ void PM_InitialSnapPosition(void) { int x, y, z; @@ -1057,13 +1044,20 @@ void PM_InitialSnapPosition(void) VectorCopy (pm->s.origin, base); - for ( z = 0; z < 3; z++ ) { + for ( z = 0; z < 3; z++ ) + { pm->s.origin[2] = base[2] + offset[ z ]; - for ( y = 0; y < 3; y++ ) { + + for ( y = 0; y < 3; y++ ) + { pm->s.origin[1] = base[1] + offset[ y ]; - for ( x = 0; x < 3; x++ ) { + + for ( x = 0; x < 3; x++ ) + { pm->s.origin[0] = base[0] + offset[ x ]; - if (PM_GoodPosition ()) { + + if (PM_GoodPosition ()) + { pml.origin[0] = pm->s.origin[0]*0.125f; pml.origin[1] = pm->s.origin[1]*0.125f; pml.origin[2] = pm->s.origin[2]*0.125f; @@ -1077,12 +1071,6 @@ void PM_InitialSnapPosition(void) Com_DPrintf ("Bad InitialSnapPosition\n"); } -/* -================ -PM_ClampAngles - -================ -*/ void PM_ClampAngles (void) { short temp; @@ -1094,36 +1082,35 @@ void PM_ClampAngles (void) pm->viewangles[PITCH] = 0; pm->viewangles[ROLL] = 0; } + else { - // circularly clamp the angles with deltas + /* circularly clamp the angles with deltas */ for (i=0 ; i<3 ; i++) { temp = pm->cmd.angles[i] + pm->s.delta_angles[i]; pm->viewangles[i] = SHORT2ANGLE(temp); } - // don't let the player look up or down more than 90 degrees + /* don't let the player look up or down more than 90 degrees */ if (pm->viewangles[PITCH] > 89 && pm->viewangles[PITCH] < 180) pm->viewangles[PITCH] = 89; + else if (pm->viewangles[PITCH] < 271 && pm->viewangles[PITCH] >= 180) pm->viewangles[PITCH] = 271; } + AngleVectors (pm->viewangles, pml.forward, pml.right, pml.up); } /* -================ -Pmove - -Can be called by either the server or the client -================ -*/ + * Can be called by either the server or the client + */ void Pmove (pmove_t *pmove) { pm = pmove; - // clear results + /* clear results */ pm->numtouch = 0; VectorClear (pm->viewangles); pm->viewheight = 0; @@ -1131,10 +1118,10 @@ void Pmove (pmove_t *pmove) pm->watertype = 0; pm->waterlevel = 0; - // clear all pmove local vars + /* clear all pmove local vars */ memset (&pml, 0, sizeof(pml)); - // convert origin and velocity to float values + /* convert origin and velocity to float values */ pml.origin[0] = pm->s.origin[0]*0.125f; pml.origin[1] = pm->s.origin[1]*0.125f; pml.origin[2] = pm->s.origin[2]*0.125f; @@ -1143,7 +1130,7 @@ void Pmove (pmove_t *pmove) pml.velocity[1] = pm->s.velocity[1]*0.125f; pml.velocity[2] = pm->s.velocity[2]*0.125f; - // save old org in case we get stuck + /* save old org in case we get stuck */ VectorCopy (pm->s.origin, pml.previous_origin); pml.frametime = pm->cmd.msec * 0.001f; @@ -1165,15 +1152,15 @@ void Pmove (pmove_t *pmove) } if (pm->s.pm_type == PM_FREEZE) - return; // no movement at all + return; /* no movement at all */ - // set mins, maxs, and viewheight + /* set mins, maxs, and viewheight */ PM_CheckDuck (); if (pm->snapinitial) PM_InitialSnapPosition (); - // set groundentity, watertype, and waterlevel + /* set groundentity, watertype, and waterlevel */ PM_CatagorizePosition (); if (pm->s.pm_type == PM_DEAD) @@ -1181,31 +1168,38 @@ void Pmove (pmove_t *pmove) PM_CheckSpecialMovement (); - // drop timing counter + /* drop timing counter */ if (pm->s.pm_time) { int msec; msec = pm->cmd.msec >> 3; + if (!msec) msec = 1; - if ( msec >= pm->s.pm_time) + + if ( msec >= pm->s.pm_time) { pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); pm->s.pm_time = 0; } + else pm->s.pm_time -= msec; } if (pm->s.pm_flags & PMF_TIME_TELEPORT) - { // teleport pause stays exactly in place + { + /* teleport pause stays exactly in place */ } else if (pm->s.pm_flags & PMF_TIME_WATERJUMP) - { // waterjump has no control, but falls + { + /* waterjump has no control, but falls */ pml.velocity[2] -= pm->s.gravity * pml.frametime; + if (pml.velocity[2] < 0) - { // cancel as soon as we are falling down again + { + /* cancel as soon as we are falling down again */ pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); pm->s.pm_time = 0; } @@ -1220,12 +1214,16 @@ void Pmove (pmove_t *pmove) if (pm->waterlevel >= 2) PM_WaterMove (); - else { + + else + { vec3_t angles; VectorCopy(pm->viewangles, angles); + if (angles[PITCH] > 180) angles[PITCH] = angles[PITCH] - 360; + angles[PITCH] /= 3; AngleVectors (angles, pml.forward, pml.right, pml.up); @@ -1234,9 +1232,8 @@ void Pmove (pmove_t *pmove) } } - // set groundentity, watertype, and waterlevel for final spot + /* set groundentity, watertype, and waterlevel for final spot */ PM_CatagorizePosition (); PM_SnapPosition (); } -