newtree/source/pmove.c

916 lines
20 KiB
C
Raw Normal View History

/*
pmove.c
(description)
Copyright (C) 1996-1997 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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
2000-05-10 11:29:38 +00:00
2000-05-17 10:03:19 +00:00
#ifdef HAVE_CONFIG_H
# include "config.h"
2000-05-17 10:03:19 +00:00
#endif
#include <math.h>
2000-05-10 11:29:38 +00:00
2000-12-30 02:16:36 +00:00
#include "client.h"
#include "compat.h"
#include "cvar.h"
#include "pmove.h"
#include "qtypes.h"
cvar_t *no_pogo_stick;
movevars_t movevars;
2000-05-10 11:29:38 +00:00
playermove_t pmove;
2000-05-10 11:29:38 +00:00
int onground;
int waterlevel;
int watertype;
2000-05-10 11:29:38 +00:00
float frametime;
2000-05-10 11:29:38 +00:00
vec3_t forward, right, up;
2000-05-10 11:29:38 +00:00
vec3_t player_mins = { -16, -16, -24 };
vec3_t player_maxs = { 16, 16, 32 };
2000-05-10 11:29:38 +00:00
void PM_InitBoxHull (void);
void PM_CategorizePosition (void);
2000-05-10 11:29:38 +00:00
void
Pmove_Init (void)
2000-05-10 11:29:38 +00:00
{
PM_InitBoxHull ();
}
void
Pmove_Init_Cvars (void)
{
no_pogo_stick = Cvar_Get ("no_pogo_stick", "0", CVAR_SERVERINFO,
"disable the ability to pogo stick");
2000-05-10 11:29:38 +00:00
}
#define STEPSIZE 18
#define BUTTON_JUMP 2
/*
2001-02-09 02:53:09 +00:00
PM_ClipVelocity
2000-05-10 11:29:38 +00:00
2001-02-09 02:53:09 +00:00
Slide off of the impacting object
returns the blocked flags (1 = floor, 2 = step / wall)
2000-05-10 11:29:38 +00:00
*/
int
PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
2000-05-10 11:29:38 +00:00
{
float backoff;
float change;
int i, blocked;
2000-05-10 11:29:38 +00:00
blocked = 0;
if (normal[2] > 0)
blocked |= 1; // floor
2000-05-10 11:29:38 +00:00
if (!normal[2])
blocked |= 2; // step
2000-05-10 11:29:38 +00:00
backoff = DotProduct (in, normal) * overbounce;
for (i = 0; i < 3; i++) {
change = normal[i] * backoff;
2000-05-10 11:29:38 +00:00
out[i] = in[i] - change;
if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
out[i] = 0;
}
2000-05-10 11:29:38 +00:00
return blocked;
}
/*
2001-02-09 02:53:09 +00:00
PM_FlyMove
2000-05-10 11:29:38 +00:00
2001-02-09 02:53:09 +00:00
The basic solid body movement clip that slides along multiple planes
2000-05-10 11:29:38 +00:00
*/
#define MAX_CLIP_PLANES 5
int
PM_FlyMove (void)
2000-05-10 11:29:38 +00:00
{
int bumpcount, numbumps;
vec3_t dir;
float d;
int numplanes;
vec3_t planes[MAX_CLIP_PLANES];
vec3_t primal_velocity, original_velocity;
int i, j;
pmtrace_t trace;
vec3_t end;
float time_left;
int blocked;
2000-05-10 11:29:38 +00:00
numbumps = 4;
2000-05-10 11:29:38 +00:00
blocked = 0;
VectorCopy (pmove.velocity, original_velocity);
VectorCopy (pmove.velocity, primal_velocity);
numplanes = 0;
2000-05-10 11:29:38 +00:00
time_left = frametime;
for (bumpcount = 0; bumpcount < numbumps; bumpcount++) {
for (i = 0; i < 3; i++)
2000-05-10 11:29:38 +00:00
end[i] = pmove.origin[i] + time_left * pmove.velocity[i];
trace = PM_PlayerMove (pmove.origin, end);
if (trace.startsolid || trace.allsolid) { // entity is trapped in
// another solid
2000-05-10 11:29:38 +00:00
VectorCopy (vec3_origin, pmove.velocity);
return 3;
}
if (trace.fraction > 0) { // actually covered some distance
2000-05-10 11:29:38 +00:00
VectorCopy (trace.endpos, pmove.origin);
numplanes = 0;
}
if (trace.fraction == 1)
break; // moved the entire distance
2000-05-10 11:29:38 +00:00
// save entity for contact
pmove.touchindex[pmove.numtouch] = trace.ent;
pmove.numtouch++;
if (trace.plane.normal[2] > 0.7) {
blocked |= 1; // floor
2000-05-10 11:29:38 +00:00
}
if (!trace.plane.normal[2]) {
blocked |= 2; // step
2000-05-10 11:29:38 +00:00
}
time_left -= time_left * trace.fraction;
// cliped to another plane
if (numplanes >= MAX_CLIP_PLANES) { // this shouldn't really happen
2000-05-10 11:29:38 +00:00
VectorCopy (vec3_origin, pmove.velocity);
break;
}
VectorCopy (trace.plane.normal, planes[numplanes]);
numplanes++;
//
// modify original_velocity so it parallels all of the clip planes
//
for (i = 0; i < numplanes; i++) {
2000-05-10 11:29:38 +00:00
PM_ClipVelocity (original_velocity, planes[i], pmove.velocity, 1);
for (j = 0; j < numplanes; j++)
if (j != i) {
2000-05-10 11:29:38 +00:00
if (DotProduct (pmove.velocity, planes[j]) < 0)
break; // not ok
2000-05-10 11:29:38 +00:00
}
if (j == numplanes)
break;
}
if (i != numplanes) { // go along this plane
} else { // go along the crease
if (numplanes != 2) {
// Con_Printf ("clip velocity, numplanes == %i\n",numplanes);
2000-05-10 11:29:38 +00:00
VectorCopy (vec3_origin, pmove.velocity);
break;
}
CrossProduct (planes[0], planes[1], dir);
d = DotProduct (dir, pmove.velocity);
VectorScale (dir, d, pmove.velocity);
}
//
// if original velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
//
if (DotProduct (pmove.velocity, primal_velocity) <= 0) {
2000-05-10 11:29:38 +00:00
VectorCopy (vec3_origin, pmove.velocity);
break;
}
}
if (pmove.waterjumptime) {
2000-05-10 11:29:38 +00:00
VectorCopy (primal_velocity, pmove.velocity);
}
return blocked;
}
2000-05-13 22:51:05 +00:00
void PM_Accelerate (vec3_t, float, float);
2000-05-13 22:51:05 +00:00
/*
PM_FlymodeMove
Pre-PM_FlyMove function for MOVETYPE_FLY players. Could have altered
other physics to fit this in, but that's to easy to screw up. --KB
*/
void
PM_FlymodeMove (void)
2000-05-13 22:51:05 +00:00
{
vec3_t start, dest, pmvel, pmtmp;
pmtrace_t trace;
float pmspeed;
pmvel[0] =
forward[0] * pmove.cmd.forwardmove + right[0] * pmove.cmd.sidemove;
pmvel[1] =
forward[1] * pmove.cmd.forwardmove + right[1] * pmove.cmd.sidemove;
pmvel[2] =
forward[2] * pmove.cmd.forwardmove + right[2] * pmove.cmd.sidemove +
pmove.cmd.upmove;
2000-05-13 22:51:05 +00:00
VectorCopy (pmvel, pmtmp);
pmspeed = VectorNormalize (pmtmp); // don't alter pmvel
2000-05-13 22:51:05 +00:00
if (pmspeed > movevars.maxspeed) // there IS a spoon, Neo..
2000-05-13 22:51:05 +00:00
{
VectorScale (pmvel, movevars.maxspeed / pmspeed, pmvel);
pmspeed = movevars.maxspeed;
}
PM_Accelerate (pmtmp, pmspeed, movevars.wateraccelerate);
VectorMA (pmove.origin, frametime, pmove.velocity, dest);
VectorCopy (dest, start);
start[2] += STEPSIZE + 1;
trace = PM_PlayerMove (start, dest);
if (!trace.startsolid && !trace.allsolid) {
2000-05-13 22:51:05 +00:00
VectorCopy (trace.endpos, pmove.origin);
return; // just step up
2000-05-13 22:51:05 +00:00
}
PM_FlyMove (); // NOW we fly.
2000-05-13 22:51:05 +00:00
}
2000-05-10 11:29:38 +00:00
/*
2001-02-09 02:53:09 +00:00
PM_GroundMove
2000-05-10 11:29:38 +00:00
2001-02-09 02:53:09 +00:00
Player is on ground, with no upwards velocity
2000-05-10 11:29:38 +00:00
*/
void
PM_GroundMove (void)
2000-05-10 11:29:38 +00:00
{
vec3_t start, dest;
pmtrace_t trace;
vec3_t original, originalvel, down, up, downvel;
float downdist, updist;
2000-05-10 11:29:38 +00:00
pmove.velocity[2] = 0;
if (!pmove.velocity[0] && !pmove.velocity[1] && !pmove.velocity[2])
return;
// first try just moving to the destination
dest[0] = pmove.origin[0] + pmove.velocity[0] * frametime;
dest[1] = pmove.origin[1] + pmove.velocity[1] * frametime;
2000-05-10 11:29:38 +00:00
dest[2] = pmove.origin[2];
// first try moving directly to the next spot
VectorCopy (dest, start);
trace = PM_PlayerMove (pmove.origin, dest);
if (trace.fraction == 1) {
2000-05-10 11:29:38 +00:00
VectorCopy (trace.endpos, pmove.origin);
return;
}
// try sliding forward both on ground and up 16 pixels
// take the move that goes farthest
VectorCopy (pmove.origin, original);
VectorCopy (pmove.velocity, originalvel);
// slide move
PM_FlyMove ();
VectorCopy (pmove.origin, down);
VectorCopy (pmove.velocity, downvel);
VectorCopy (original, pmove.origin);
VectorCopy (originalvel, pmove.velocity);
// move up a stair height
VectorCopy (pmove.origin, dest);
dest[2] += STEPSIZE;
trace = PM_PlayerMove (pmove.origin, dest);
if (!trace.startsolid && !trace.allsolid) {
2000-05-10 11:29:38 +00:00
VectorCopy (trace.endpos, pmove.origin);
}
// slide move
PM_FlyMove ();
// press down the stepheight
VectorCopy (pmove.origin, dest);
dest[2] -= STEPSIZE;
trace = PM_PlayerMove (pmove.origin, dest);
if (trace.plane.normal[2] < 0.7)
2000-05-10 11:29:38 +00:00
goto usedown;
if (!trace.startsolid && !trace.allsolid) {
2000-05-10 11:29:38 +00:00
VectorCopy (trace.endpos, pmove.origin);
}
VectorCopy (pmove.origin, up);
// decide which one went farther
downdist = (down[0] - original[0]) * (down[0] - original[0])
+ (down[1] - original[1]) * (down[1] - original[1]);
updist = (up[0] - original[0]) * (up[0] - original[0])
+ (up[1] - original[1]) * (up[1] - original[1]);
2000-05-10 11:29:38 +00:00
if (downdist > updist) {
usedown:
2000-05-10 11:29:38 +00:00
VectorCopy (down, pmove.origin);
VectorCopy (downvel, pmove.velocity);
} else // copy z value from slide move
2000-05-10 11:29:38 +00:00
pmove.velocity[2] = downvel[2];
// if at a dead stop, retry the move with nudges to get around lips
}
/*
2001-02-09 02:53:09 +00:00
PM_Friction
2000-05-10 11:29:38 +00:00
2001-02-09 02:53:09 +00:00
Handles both ground friction and water friction
2000-05-10 11:29:38 +00:00
*/
void
PM_Friction (void)
2000-05-10 11:29:38 +00:00
{
float *vel;
float speed, newspeed;
float friction;
float drop;
vec3_t start, stop;
pmtrace_t trace;
2000-05-10 11:29:38 +00:00
if (pmove.waterjumptime)
return;
vel = pmove.velocity;
speed = sqrt (vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]);
if (speed < 1) {
2000-05-10 11:29:38 +00:00
vel[0] = 0;
vel[1] = 0;
return;
}
friction = movevars.friction;
// if the leading edge is over a dropoff, increase friction
if (onground != -1) {
start[0] = stop[0] = pmove.origin[0] + vel[0] / speed * 16;
start[1] = stop[1] = pmove.origin[1] + vel[1] / speed * 16;
2000-05-10 11:29:38 +00:00
start[2] = pmove.origin[2] + player_mins[2];
stop[2] = start[2] - 34;
trace = PM_PlayerMove (start, stop);
if (trace.fraction == 1) {
friction *= 2;
}
}
drop = 0;
if (waterlevel >= 2) // apply water friction
drop += speed * movevars.waterfriction * waterlevel * frametime;
else if (pmove.flying) // apply flying friction
drop += max (movevars.stopspeed, speed) * friction * frametime;
else if (onground != -1) // apply ground friction
drop += max (movevars.stopspeed, speed) * friction * frametime;
2000-05-10 11:29:38 +00:00
// scale the velocity
newspeed = speed - drop;
if (newspeed < 0)
newspeed = 0;
newspeed /= speed;
vel[0] = vel[0] * newspeed;
vel[1] = vel[1] * newspeed;
vel[2] = vel[2] * newspeed;
}
/*
2001-02-09 02:53:09 +00:00
PM_Accelerate
2000-05-10 11:29:38 +00:00
*/
void
PM_Accelerate (vec3_t wishdir, float wishspeed, float accel)
2000-05-10 11:29:38 +00:00
{
int i;
float addspeed, accelspeed, currentspeed;
2000-05-10 11:29:38 +00:00
if (pmove.dead)
return;
if (pmove.waterjumptime)
return;
currentspeed = DotProduct (pmove.velocity, wishdir);
addspeed = wishspeed - currentspeed;
if (addspeed <= 0)
return;
accelspeed = accel * frametime * wishspeed;
2000-05-10 11:29:38 +00:00
if (accelspeed > addspeed)
accelspeed = addspeed;
for (i = 0; i < 3; i++)
pmove.velocity[i] += accelspeed * wishdir[i];
2000-05-10 11:29:38 +00:00
}
void
PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel)
2000-05-10 11:29:38 +00:00
{
int i;
float addspeed, accelspeed, currentspeed, wishspd = wishspeed;
2000-05-10 11:29:38 +00:00
if (pmove.dead)
return;
if (pmove.waterjumptime)
return;
if (wishspd > 30)
wishspd = 30;
currentspeed = DotProduct (pmove.velocity, wishdir);
addspeed = wishspd - currentspeed;
if (addspeed <= 0)
return;
accelspeed = accel * wishspeed * frametime;
if (accelspeed > addspeed)
accelspeed = addspeed;
for (i = 0; i < 3; i++)
pmove.velocity[i] += accelspeed * wishdir[i];
2000-05-10 11:29:38 +00:00
}
/*
2001-02-09 02:53:09 +00:00
PM_WaterMove
2000-05-10 11:29:38 +00:00
*/
void
PM_WaterMove (void)
2000-05-10 11:29:38 +00:00
{
int i;
vec3_t wishvel;
float wishspeed;
vec3_t wishdir;
vec3_t start, dest;
pmtrace_t trace;
2000-05-10 11:29:38 +00:00
//
// user intentions
//
for (i = 0; i < 3; i++)
wishvel[i] =
forward[i] * pmove.cmd.forwardmove + right[i] * pmove.cmd.sidemove;
2000-05-10 11:29:38 +00:00
if (!pmove.cmd.forwardmove && !pmove.cmd.sidemove && !pmove.cmd.upmove)
wishvel[2] -= 60; // drift towards bottom
2000-05-10 11:29:38 +00:00
else
wishvel[2] += pmove.cmd.upmove;
VectorCopy (wishvel, wishdir);
wishspeed = VectorNormalize (wishdir);
2000-05-10 11:29:38 +00:00
if (wishspeed > movevars.maxspeed) {
VectorScale (wishvel, movevars.maxspeed / wishspeed, wishvel);
2000-05-10 11:29:38 +00:00
wishspeed = movevars.maxspeed;
}
wishspeed *= 0.7;
//
// water acceleration
//
// if (pmove.waterjumptime)
// Con_Printf ("wm->%f, %f, %f\n", pmove.velocity[0], pmove.velocity[1], pmove.velocity[2]);
2000-05-10 11:29:38 +00:00
PM_Accelerate (wishdir, wishspeed, movevars.wateraccelerate);
// assume it is a stair or a slope, so press down from stepheight above
VectorMA (pmove.origin, frametime, pmove.velocity, dest);
VectorCopy (dest, start);
start[2] += STEPSIZE + 1;
trace = PM_PlayerMove (start, dest);
if (!trace.startsolid && !trace.allsolid) // FIXME: check steep slope?
{ // walked up the step
2000-05-10 11:29:38 +00:00
VectorCopy (trace.endpos, pmove.origin);
return;
}
2000-05-10 11:29:38 +00:00
PM_FlyMove ();
}
/*
2001-02-09 02:53:09 +00:00
PM_AirMove
2000-05-10 11:29:38 +00:00
*/
void
PM_AirMove (void)
2000-05-10 11:29:38 +00:00
{
int i;
vec3_t wishvel;
float fmove, smove;
vec3_t wishdir;
float wishspeed;
vec3_t original;
2000-05-10 11:29:38 +00:00
fmove = pmove.cmd.forwardmove;
smove = pmove.cmd.sidemove;
2000-05-10 11:29:38 +00:00
forward[2] = 0;
right[2] = 0;
VectorNormalize (forward);
VectorNormalize (right);
for (i = 0; i < 2; i++)
wishvel[i] = forward[i] * fmove + right[i] * smove;
2000-05-10 11:29:38 +00:00
wishvel[2] = 0;
VectorCopy (wishvel, wishdir);
wishspeed = VectorNormalize (wishdir);
2000-05-10 11:29:38 +00:00
//
// clamp to server defined max speed
//
if (wishspeed > movevars.maxspeed) {
VectorScale (wishvel, movevars.maxspeed / wishspeed, wishvel);
2000-05-10 11:29:38 +00:00
wishspeed = movevars.maxspeed;
}
if (onground != -1) {
2000-05-10 11:29:38 +00:00
pmove.velocity[2] = 0;
PM_Accelerate (wishdir, wishspeed, movevars.accelerate);
pmove.velocity[2] -= movevars.entgravity * movevars.gravity * frametime;
PM_GroundMove ();
} else if (pmove.flying) {
2000-05-13 22:51:05 +00:00
PM_AirAccelerate (wishdir, wishspeed, movevars.accelerate);
PM_FlyMove ();
} else {
// not on ground, so little effect on velocity
2000-05-10 11:29:38 +00:00
PM_AirAccelerate (wishdir, wishspeed, movevars.accelerate);
// add gravity
pmove.velocity[2] -= movevars.entgravity * movevars.gravity * frametime;
if (!PM_FlyMove ()) {
// the move didn't get blocked
PM_CategorizePosition ();
if (onground != -1) // but we're on ground now
{
// This is a hack to fix the jumping bug
VectorCopy (pmove.origin, original);
// Calculate correct velocity
if (!PM_FlyMove ()) {
// This shouldn't probably happen (?)
if (pmove.velocity[2] < 0)
pmove.velocity[2] = 0;
}
VectorCopy (original, pmove.origin);
}
}
2000-05-10 11:29:38 +00:00
}
}
/*
2001-02-09 02:53:09 +00:00
PM_CategorizePosition
2000-05-10 11:29:38 +00:00
*/
void
PM_CategorizePosition (void)
2000-05-10 11:29:38 +00:00
{
vec3_t point;
int cont;
pmtrace_t tr;
2000-05-10 11:29:38 +00:00
// if the player hull point one unit down is solid, the player
// is on ground
// see if standing on something solid
2000-05-10 11:29:38 +00:00
point[0] = pmove.origin[0];
point[1] = pmove.origin[1];
point[2] = pmove.origin[2] - 1;
if (pmove.velocity[2] > 180) {
2000-05-10 11:29:38 +00:00
onground = -1;
} else {
2000-05-10 11:29:38 +00:00
tr = PM_PlayerMove (pmove.origin, point);
if (tr.plane.normal[2] < 0.7)
onground = -1; // too steep
2000-05-10 11:29:38 +00:00
else
onground = tr.ent;
if (onground != -1) {
2000-05-10 11:29:38 +00:00
pmove.waterjumptime = 0;
if (!tr.startsolid && !tr.allsolid)
VectorCopy (tr.endpos, pmove.origin);
}
// standing on an entity other than the world
if (tr.ent > 0) {
2000-05-10 11:29:38 +00:00
pmove.touchindex[pmove.numtouch] = tr.ent;
pmove.numtouch++;
}
}
//
// get waterlevel
//
waterlevel = 0;
watertype = CONTENTS_EMPTY;
point[2] = pmove.origin[2] + player_mins[2] + 1;
2000-05-10 11:29:38 +00:00
cont = PM_PointContents (point);
if (cont <= CONTENTS_WATER) {
2000-05-10 11:29:38 +00:00
watertype = cont;
waterlevel = 1;
point[2] = pmove.origin[2] + (player_mins[2] + player_maxs[2]) * 0.5;
2000-05-10 11:29:38 +00:00
cont = PM_PointContents (point);
if (cont <= CONTENTS_WATER) {
2000-05-10 11:29:38 +00:00
waterlevel = 2;
point[2] = pmove.origin[2] + 22;
cont = PM_PointContents (point);
if (cont <= CONTENTS_WATER)
waterlevel = 3;
}
}
}
/*
JumpButton
2000-05-10 11:29:38 +00:00
*/
void
JumpButton (void)
2000-05-10 11:29:38 +00:00
{
if (pmove.dead) {
pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until
// released
2000-05-10 11:29:38 +00:00
return;
}
if (pmove.waterjumptime) {
2000-05-10 11:29:38 +00:00
pmove.waterjumptime -= frametime;
if (pmove.waterjumptime < 0)
pmove.waterjumptime = 0;
return;
}
if (waterlevel >= 2) { // swimming, not jumping
2000-05-10 11:29:38 +00:00
onground = -1;
if (watertype == CONTENTS_WATER)
pmove.velocity[2] = 100;
else if (watertype == CONTENTS_SLIME)
pmove.velocity[2] = 80;
else
pmove.velocity[2] = 50;
return;
}
if (onground == -1) {
if (no_pogo_stick->int_val)
pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until
// released
return; // in air, so no effect
}
2000-05-10 11:29:38 +00:00
if (pmove.oldbuttons & BUTTON_JUMP)
return; // don't pogo stick
2000-05-10 11:29:38 +00:00
onground = -1;
pmove.velocity[2] += 270;
pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until released
}
/*
2001-02-09 02:53:09 +00:00
CheckWaterJump
2000-05-10 11:29:38 +00:00
*/
void
CheckWaterJump (void)
2000-05-10 11:29:38 +00:00
{
vec3_t spot;
int cont;
vec3_t flatforward;
2000-05-10 11:29:38 +00:00
2000-05-13 22:51:05 +00:00
if (pmove.waterjumptime || pmove.flying)
2000-05-10 11:29:38 +00:00
return;
// ZOID, don't hop out if we just jumped in
if (pmove.velocity[2] < -180)
return; // only hop out if we are moving up
2000-05-10 11:29:38 +00:00
// see if near an edge
flatforward[0] = forward[0];
flatforward[1] = forward[1];
flatforward[2] = 0;
VectorNormalize (flatforward);
VectorMA (pmove.origin, 24, flatforward, spot);
spot[2] += 8;
cont = PM_PointContents (spot);
if (cont != CONTENTS_SOLID)
return;
spot[2] += 24;
cont = PM_PointContents (spot);
if (cont != CONTENTS_EMPTY)
return;
// jump out of water
VectorScale (flatforward, 50, pmove.velocity);
pmove.velocity[2] = 310;
pmove.waterjumptime = 2; // safety net
2000-05-10 11:29:38 +00:00
pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until released
}
/*
2001-02-09 02:53:09 +00:00
NudgePosition
2000-05-10 11:29:38 +00:00
2001-02-09 02:53:09 +00:00
If pmove.origin is in a solid position,
try nudging slightly on all axis to
allow for the cut precision of the net coordinates
2000-05-10 11:29:38 +00:00
*/
void
NudgePosition (void)
2000-05-10 11:29:38 +00:00
{
vec3_t base;
int x, y, z;
int i;
static int sign[3] = { 0, -1, 1 };
2000-05-10 11:29:38 +00:00
VectorCopy (pmove.origin, base);
for (i = 0; i < 3; i++)
pmove.origin[i] = ((int) (pmove.origin[i] * 8)) * 0.125;
// pmove.origin[2] += 0.124;
// if (pmove.dead)
// return; // might be a squished point, so don'y bother
// if (PM_TestPlayerPosition (pmove.origin) )
// return;
for (z = 0; z <= 2; z++) {
for (x = 0; x <= 2; x++) {
for (y = 0; y <= 2; y++) {
pmove.origin[0] = base[0] + (sign[x] * 1.0 / 8);
pmove.origin[1] = base[1] + (sign[y] * 1.0 / 8);
pmove.origin[2] = base[2] + (sign[z] * 1.0 / 8);
2000-05-10 11:29:38 +00:00
if (PM_TestPlayerPosition (pmove.origin))
return;
}
}
}
VectorCopy (base, pmove.origin);
// Con_DPrintf ("NudgePosition: stuck\n");
2000-05-10 11:29:38 +00:00
}
/*
2001-02-09 02:53:09 +00:00
SpectatorMove
2000-05-10 11:29:38 +00:00
*/
void
SpectatorMove (void)
2000-05-10 11:29:38 +00:00
{
float speed, drop, friction, control, newspeed;
float currentspeed, addspeed, accelspeed;
int i;
vec3_t wishvel;
float fmove, smove;
vec3_t wishdir;
float wishspeed;
2000-05-10 11:29:38 +00:00
// friction
speed = Length (pmove.velocity);
if (speed < 1) {
2000-05-10 11:29:38 +00:00
VectorCopy (vec3_origin, pmove.velocity)
} else {
2000-05-10 11:29:38 +00:00
drop = 0;
friction = movevars.friction * 1.5; // extra friction
2000-05-10 11:29:38 +00:00
control = speed < movevars.stopspeed ? movevars.stopspeed : speed;
drop += control * friction * frametime;
2000-05-10 11:29:38 +00:00
// scale the velocity
newspeed = speed - drop;
if (newspeed < 0)
newspeed = 0;
newspeed /= speed;
VectorScale (pmove.velocity, newspeed, pmove.velocity);
}
// accelerate
fmove = pmove.cmd.forwardmove;
smove = pmove.cmd.sidemove;
2000-05-10 11:29:38 +00:00
VectorNormalize (forward);
VectorNormalize (right);
for (i = 0; i < 3; i++)
wishvel[i] = forward[i] * fmove + right[i] * smove;
2000-05-10 11:29:38 +00:00
wishvel[2] += pmove.cmd.upmove;
VectorCopy (wishvel, wishdir);
wishspeed = VectorNormalize (wishdir);
2000-05-10 11:29:38 +00:00
//
2000-05-10 11:29:38 +00:00
// clamp to server defined max speed
//
if (wishspeed > movevars.spectatormaxspeed) {
VectorScale (wishvel, movevars.spectatormaxspeed / wishspeed, wishvel);
2000-05-10 11:29:38 +00:00
wishspeed = movevars.spectatormaxspeed;
}
currentspeed = DotProduct (pmove.velocity, wishdir);
2000-05-10 11:29:38 +00:00
addspeed = wishspeed - currentspeed;
if (addspeed <= 0)
return;
accelspeed = movevars.accelerate * frametime * wishspeed;
2000-05-10 11:29:38 +00:00
if (accelspeed > addspeed)
accelspeed = addspeed;
for (i = 0; i < 3; i++)
pmove.velocity[i] += accelspeed * wishdir[i];
2000-05-10 11:29:38 +00:00
// move
VectorMA (pmove.origin, frametime, pmove.velocity, pmove.origin);
}
/*
2001-02-09 02:53:09 +00:00
PlayerMove
2000-05-10 11:29:38 +00:00
2001-02-09 02:53:09 +00:00
Returns with origin, angles, and velocity modified in place.
2000-05-10 11:29:38 +00:00
2001-02-09 02:53:09 +00:00
Numtouch and touchindex[] will be set if any of the physents
were contacted during the move.
2000-05-10 11:29:38 +00:00
*/
void
PlayerMove (void)
2000-05-10 11:29:38 +00:00
{
frametime = pmove.cmd.msec * 0.001;
pmove.numtouch = 0;
AngleVectors (pmove.angles, forward, right, up);
if (pmove.spectator) {
2000-05-10 11:29:38 +00:00
SpectatorMove ();
return;
}
NudgePosition ();
// take angles directly from command
VectorCopy (pmove.cmd.angles, pmove.angles);
// set onground, watertype, and waterlevel
PM_CategorizePosition ();
2000-05-10 11:29:38 +00:00
if (waterlevel == 2)
CheckWaterJump ();
if (pmove.velocity[2] < 0)
pmove.waterjumptime = 0;
if (pmove.cmd.buttons & BUTTON_JUMP)
JumpButton ();
else
pmove.oldbuttons &= ~BUTTON_JUMP;
PM_Friction ();
if (waterlevel >= 2)
PM_WaterMove ();
2000-05-13 22:51:05 +00:00
else if (pmove.flying)
PM_FlymodeMove ();
2000-05-10 11:29:38 +00:00
else
PM_AirMove ();
// set onground, watertype, and waterlevel for final spot
PM_CategorizePosition ();
2000-05-10 11:29:38 +00:00
}