2016-06-04 15:24:23 +02:00
|
|
|
/***
|
|
|
|
*
|
|
|
|
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
|
|
|
*
|
|
|
|
* This product contains software technology licensed from Id
|
|
|
|
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use, distribution, and modification of this source code and/or resulting
|
|
|
|
* object code is restricted to non-commercial enhancements to products from
|
|
|
|
* Valve LLC. All other use, distribution, or modification is prohibited
|
|
|
|
* without written permission from Valve LLC.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2019-10-13 15:37:32 +02:00
|
|
|
//#include <stdio.h> // NULL
|
|
|
|
#include <math.h> // sqrt
|
|
|
|
#include <string.h> // strcpy
|
|
|
|
#include <stdlib.h> // atoi
|
|
|
|
#include <ctype.h> // isspace
|
2016-06-04 15:24:23 +02:00
|
|
|
#include "mathlib.h"
|
2021-06-07 02:05:58 +02:00
|
|
|
#if HAVE_TGMATH_H
|
2019-10-13 15:37:32 +02:00
|
|
|
#include <tgmath.h>
|
|
|
|
#endif
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
#include "const.h"
|
|
|
|
#include "usercmd.h"
|
|
|
|
#include "pm_defs.h"
|
|
|
|
#include "pm_shared.h"
|
|
|
|
#include "pm_movevars.h"
|
|
|
|
#include "pm_debug.h"
|
|
|
|
|
2021-06-07 02:05:58 +02:00
|
|
|
#if CLIENT_DLL
|
2017-07-05 20:50:55 +02:00
|
|
|
// Spectator Mode
|
|
|
|
int iJumpSpectator;
|
|
|
|
extern float vJumpOrigin[3];
|
|
|
|
extern float vJumpAngles[3];
|
2016-06-04 15:24:23 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int pm_shared_initialized = 0;
|
|
|
|
|
2021-06-07 02:05:58 +02:00
|
|
|
#if _MSC_VER
|
2016-06-04 15:24:23 +02:00
|
|
|
#pragma warning( disable : 4305 )
|
2017-06-29 15:56:03 +02:00
|
|
|
#endif
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
playermove_t *pmove = NULL;
|
|
|
|
|
|
|
|
// Ducking time
|
2019-10-13 13:49:25 +02:00
|
|
|
#define TIME_TO_DUCK 0.4f
|
2016-06-04 15:24:23 +02:00
|
|
|
#define VEC_DUCK_HULL_MIN -18
|
|
|
|
#define VEC_DUCK_HULL_MAX 18
|
|
|
|
#define VEC_DUCK_VIEW 12
|
|
|
|
#define PM_DEAD_VIEWHEIGHT -8
|
2016-07-31 15:48:50 +02:00
|
|
|
#define MAX_CLIMB_SPEED 200
|
|
|
|
#define STUCK_MOVEUP 1
|
|
|
|
#define STUCK_MOVEDOWN -1
|
2016-06-04 15:24:23 +02:00
|
|
|
#define VEC_HULL_MIN -36
|
|
|
|
#define VEC_HULL_MAX 36
|
2016-07-31 15:48:50 +02:00
|
|
|
#define VEC_VIEW 28
|
2019-10-13 13:49:25 +02:00
|
|
|
#define STOP_EPSILON 0.1f
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
#define CTEXTURESMAX 512 // max number of textures loaded
|
2021-04-04 04:18:32 +02:00
|
|
|
#include "pm_materials.h"
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
#define STEP_CONCRETE 0 // default step sound
|
2016-06-04 15:24:23 +02:00
|
|
|
#define STEP_METAL 1 // metal floor
|
|
|
|
#define STEP_DIRT 2 // dirt, sand, rock
|
|
|
|
#define STEP_VENT 3 // ventillation duct
|
|
|
|
#define STEP_GRATE 4 // metal grating
|
|
|
|
#define STEP_TILE 5 // floor tiles
|
|
|
|
#define STEP_SLOSH 6 // shallow liquid puddle
|
|
|
|
#define STEP_WADE 7 // wading in liquid
|
|
|
|
#define STEP_LADDER 8 // climbing ladder
|
|
|
|
|
|
|
|
#define PLAYER_FATAL_FALL_SPEED 1024// approx 60 feet
|
|
|
|
#define PLAYER_MAX_SAFE_FALL_SPEED 580// approx 20 feet
|
|
|
|
#define DAMAGE_FOR_FALL_SPEED (float) 100 / ( PLAYER_FATAL_FALL_SPEED - PLAYER_MAX_SAFE_FALL_SPEED )// damage per unit per second.
|
|
|
|
#define PLAYER_MIN_BOUNCE_SPEED 200
|
2016-07-31 15:48:50 +02:00
|
|
|
#define PLAYER_FALL_PUNCH_THRESHHOLD (float)350 // won't punch player's screen/make scrape noise unless player falling at least this fast.
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
#define PLAYER_LONGJUMP_SPEED 350 // how fast we longjump
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
#define PLAYER_DUCKING_MULTIPLIER 0.333f
|
2017-06-26 02:47:19 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// double to float warning
|
2021-06-07 02:05:58 +02:00
|
|
|
#if _MSC_VER
|
2016-06-04 15:24:23 +02:00
|
|
|
#pragma warning(disable : 4244)
|
2017-06-29 15:56:03 +02:00
|
|
|
#endif
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
// up / down
|
2016-07-31 15:48:50 +02:00
|
|
|
#define PITCH 0
|
2016-06-04 15:24:23 +02:00
|
|
|
// left / right
|
|
|
|
#define YAW 1
|
|
|
|
// fall over
|
2016-07-31 15:48:50 +02:00
|
|
|
#define ROLL 2
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
#define MAX_CLIENTS 32
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
#define CONTENTS_CURRENT_0 -9
|
|
|
|
#define CONTENTS_CURRENT_90 -10
|
2016-07-31 15:48:50 +02:00
|
|
|
#define CONTENTS_CURRENT_180 -11
|
|
|
|
#define CONTENTS_CURRENT_270 -12
|
2016-06-04 15:24:23 +02:00
|
|
|
#define CONTENTS_CURRENT_UP -13
|
2016-07-31 15:48:50 +02:00
|
|
|
#define CONTENTS_CURRENT_DOWN -14
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
#define CONTENTS_TRANSLUCENT -15
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
static vec3_t rgv3tStuckTable[54];
|
|
|
|
static int rgStuckLast[MAX_CLIENTS][2];
|
|
|
|
|
|
|
|
// Texture names
|
|
|
|
static int gcTextures = 0;
|
|
|
|
static char grgszTextureName[CTEXTURESMAX][CBTEXTURENAMEMAX];
|
|
|
|
static char grgchTextureType[CTEXTURESMAX];
|
|
|
|
|
|
|
|
int g_onladder = 0;
|
|
|
|
|
2022-07-27 07:24:10 +02:00
|
|
|
static void PM_InitTrace( trace_t *trace, const vec3_t end )
|
2022-07-21 16:23:09 +02:00
|
|
|
{
|
|
|
|
memset( trace, 0, sizeof( *trace ));
|
|
|
|
VectorCopy( end, trace->endpos );
|
|
|
|
trace->allsolid = true;
|
|
|
|
trace->fraction = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PM_TraceModel( physent_t *pe, float *start, float *end, trace_t *trace )
|
|
|
|
{
|
|
|
|
PM_InitTrace( trace, end );
|
|
|
|
pmove->PM_TraceModel(pe, start, end, trace);
|
|
|
|
}
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
void PM_SwapTextures( int i, int j )
|
|
|
|
{
|
|
|
|
char chTemp;
|
2016-07-31 15:48:50 +02:00
|
|
|
char szTemp[CBTEXTURENAMEMAX];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
strcpy( szTemp, grgszTextureName[i] );
|
|
|
|
chTemp = grgchTextureType[i];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
strcpy( grgszTextureName[i], grgszTextureName[j] );
|
|
|
|
grgchTextureType[i] = grgchTextureType[j];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
strcpy( grgszTextureName[j], szTemp );
|
|
|
|
grgchTextureType[j] = chTemp;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PM_SortTextures( void )
|
|
|
|
{
|
|
|
|
// Bubble sort, yuck, but this only occurs at startup and it's only 512 elements...
|
|
|
|
//
|
|
|
|
int i, j;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < gcTextures; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( j = i + 1; j < gcTextures; j++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( stricmp( grgszTextureName[i], grgszTextureName[j] ) > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Swap
|
|
|
|
//
|
|
|
|
PM_SwapTextures( i, j );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_InitTextureTypes( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
char buffer[512];
|
|
|
|
int i, j;
|
|
|
|
byte *pMemFile;
|
2018-04-07 03:21:16 +02:00
|
|
|
int fileSize, filePos = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
static qboolean bTextureTypeInit = false;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( bTextureTypeInit )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2018-04-07 03:21:16 +02:00
|
|
|
memset(&( grgszTextureName[0][0] ), 0, sizeof( grgszTextureName ) );
|
|
|
|
memset( grgchTextureType, 0, sizeof( grgchTextureType ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
gcTextures = 0;
|
|
|
|
|
2018-04-07 03:21:16 +02:00
|
|
|
pMemFile = pmove->COM_LoadFile( "sound/materials.txt", 5, &fileSize );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pMemFile )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2018-04-07 03:21:16 +02:00
|
|
|
memset( buffer, 0, sizeof( buffer ) );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// for each line in the file...
|
2016-07-31 15:48:50 +02:00
|
|
|
while( pmove->memfgets( pMemFile, fileSize, &filePos, buffer, 511 ) != NULL && (gcTextures < CTEXTURESMAX ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// skip whitespace
|
|
|
|
i = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
while( buffer[i] && isspace( buffer[i] ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
i++;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
if( !buffer[i] )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// skip comment lines
|
2016-07-31 15:48:50 +02:00
|
|
|
if( buffer[i] == '/' || !isalpha( buffer[i] ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// get texture type
|
2016-07-31 15:48:50 +02:00
|
|
|
grgchTextureType[gcTextures] = toupper( buffer[i++] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// skip whitespace
|
2016-07-31 15:48:50 +02:00
|
|
|
while( buffer[i] && isspace( buffer[i] ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
i++;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !buffer[i] )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// get sentence name
|
|
|
|
j = i;
|
2016-07-31 15:48:50 +02:00
|
|
|
while( buffer[j] && !isspace( buffer[j] ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
j++;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !buffer[j] )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// null-terminate name and save in sentences array
|
2016-07-31 15:48:50 +02:00
|
|
|
j = min( j, CBTEXTURENAMEMAX - 1 + i );
|
2016-06-04 15:24:23 +02:00
|
|
|
buffer[j] = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
strcpy( &( grgszTextureName[gcTextures++][0] ), &( buffer[i] ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Must use engine to free since we are in a .dll
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->COM_FreeFile( pMemFile );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PM_SortTextures();
|
|
|
|
|
|
|
|
bTextureTypeInit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
char PM_FindTextureType( char *name )
|
|
|
|
{
|
|
|
|
int left, right, pivot;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
assert( pm_shared_initialized );
|
|
|
|
|
|
|
|
left = 0;
|
|
|
|
right = gcTextures - 1;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
while( left <= right )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pivot = ( left + right ) / 2;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
val = strnicmp( name, grgszTextureName[pivot], CBTEXTURENAMEMAX - 1 );
|
|
|
|
if( val == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
return grgchTextureType[pivot];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( val > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
left = pivot + 1;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( val < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
right = pivot - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CHAR_TEX_CONCRETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_PlayStepSound( int step, float fvol )
|
|
|
|
{
|
|
|
|
static int iSkipStep = 0;
|
|
|
|
int irand;
|
|
|
|
vec3_t hvel;
|
|
|
|
|
|
|
|
pmove->iStepLeft = !pmove->iStepLeft;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->runfuncs )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
irand = pmove->RandomLong( 0, 1 ) + ( pmove->iStepLeft * 2 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// FIXME mp_footsteps needs to be a movevar
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->multiplayer && !pmove->movevars->footsteps )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
VectorCopy( pmove->velocity, hvel );
|
2019-10-13 13:49:25 +02:00
|
|
|
hvel[2] = 0.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->multiplayer && ( !g_onladder && Length( hvel ) <= 220 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// irand - 0,1 for right foot, 2,3 for left foot
|
|
|
|
// used to alternate left and right foot
|
|
|
|
// FIXME, move to player state
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( step )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case STEP_CONCRETE:
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_step1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_step3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_step2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_step4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_METAL:
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_metal4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_DIRT:
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_dirt4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_VENT:
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_duct4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_GRATE:
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_grate4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_TILE:
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->RandomLong( 0, 4 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
irand = 4;
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_tile5.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_SLOSH:
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_slosh4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_WADE:
|
2016-07-31 15:48:50 +02:00
|
|
|
if( iSkipStep == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
iSkipStep++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( iSkipStep++ == 3 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
iSkipStep = 0;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_LADDER:
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( irand )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// right foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder1.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder3.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
// left foot
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder2.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_ladder4.wav", fvol, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int PM_MapTextureTypeStepType( char chTextureType )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( chTextureType )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
default:
|
2016-07-31 15:48:50 +02:00
|
|
|
case CHAR_TEX_CONCRETE:
|
|
|
|
return STEP_CONCRETE;
|
|
|
|
case CHAR_TEX_METAL:
|
|
|
|
return STEP_METAL;
|
|
|
|
case CHAR_TEX_DIRT:
|
|
|
|
return STEP_DIRT;
|
|
|
|
case CHAR_TEX_VENT:
|
|
|
|
return STEP_VENT;
|
|
|
|
case CHAR_TEX_GRATE:
|
|
|
|
return STEP_GRATE;
|
|
|
|
case CHAR_TEX_TILE:
|
|
|
|
return STEP_TILE;
|
|
|
|
case CHAR_TEX_SLOSH:
|
|
|
|
return STEP_SLOSH;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
PM_CatagorizeTextureType
|
|
|
|
|
|
|
|
Determine texture info for the texture we are standing on.
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void PM_CatagorizeTextureType( void )
|
|
|
|
{
|
|
|
|
vec3_t start, end;
|
|
|
|
const char *pTextureName;
|
|
|
|
|
|
|
|
VectorCopy( pmove->origin, start );
|
|
|
|
VectorCopy( pmove->origin, end );
|
|
|
|
|
|
|
|
// Straight down
|
|
|
|
end[2] -= 64;
|
|
|
|
|
|
|
|
// Fill in default values, just in case.
|
|
|
|
pmove->sztexturename[0] = '\0';
|
|
|
|
pmove->chtexturetype = CHAR_TEX_CONCRETE;
|
|
|
|
|
|
|
|
pTextureName = pmove->PM_TraceTexture( pmove->onground, start, end );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pTextureName )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// strip leading '-0' or '+0~' or '{' or '!'
|
2016-07-31 15:48:50 +02:00
|
|
|
if( *pTextureName == '-' || *pTextureName == '+' )
|
2016-06-04 15:24:23 +02:00
|
|
|
pTextureName += 2;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( *pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ' )
|
2016-06-04 15:24:23 +02:00
|
|
|
pTextureName++;
|
|
|
|
// '}}'
|
|
|
|
|
|
|
|
strcpy( pmove->sztexturename, pTextureName);
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->sztexturename[CBTEXTURENAMEMAX - 1] = 0;
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// get texture type
|
|
|
|
pmove->chtexturetype = PM_FindTextureType( pmove->sztexturename );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_UpdateStepSound( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int fWalking;
|
2016-06-04 15:24:23 +02:00
|
|
|
float fvol;
|
|
|
|
vec3_t knee;
|
|
|
|
vec3_t feet;
|
2017-06-29 15:56:03 +02:00
|
|
|
//vec3_t center;
|
2016-06-04 15:24:23 +02:00
|
|
|
float height;
|
|
|
|
float speed;
|
|
|
|
float velrun;
|
|
|
|
float velwalk;
|
|
|
|
float flduck;
|
2016-07-31 15:48:50 +02:00
|
|
|
int fLadder;
|
2016-06-04 15:24:23 +02:00
|
|
|
int step;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flTimeStepSound > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flags & FL_FROZEN )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
PM_CatagorizeTextureType();
|
|
|
|
|
|
|
|
speed = Length( pmove->velocity );
|
|
|
|
|
|
|
|
// determine if we are on a ladder
|
|
|
|
fLadder = ( pmove->movetype == MOVETYPE_FLY );// IsOnLadder();
|
|
|
|
|
|
|
|
// UNDONE: need defined numbers for run, walk, crouch, crouch run velocities!!!!
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( pmove->flags & FL_DUCKING) || fLadder )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
velwalk = 60; // These constants should be based on cl_movespeedkey * cl_forwardspeed somehow
|
|
|
|
velrun = 80; // UNDONE: Move walking to server
|
|
|
|
flduck = 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
velwalk = 120;
|
|
|
|
velrun = 210;
|
|
|
|
flduck = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're on a ladder or on the ground, and we're moving fast enough,
|
|
|
|
// play step sound. Also, if pmove->flTimeStepSound is zero, get the new
|
|
|
|
// sound right away - we just started moving in new level.
|
2019-10-13 13:49:25 +02:00
|
|
|
if( ( fLadder || ( pmove->onground != -1 ) ) && ( Length( pmove->velocity ) > 0.0f ) && ( speed >= velwalk || !pmove->flTimeStepSound ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
fWalking = speed < velrun;
|
|
|
|
|
2017-06-29 15:56:03 +02:00
|
|
|
//VectorCopy( pmove->origin, center );
|
2016-06-04 15:24:23 +02:00
|
|
|
VectorCopy( pmove->origin, knee );
|
|
|
|
VectorCopy( pmove->origin, feet );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
height = pmove->player_maxs[pmove->usehull][2] - pmove->player_mins[pmove->usehull][2];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
knee[2] = pmove->origin[2] - 0.3f * height;
|
|
|
|
feet[2] = pmove->origin[2] - 0.5f * height;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// find out what we're stepping in or on...
|
2016-07-31 15:48:50 +02:00
|
|
|
if( fLadder )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
step = STEP_LADDER;
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = 0.35f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = 350;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->PM_PointContents( knee, NULL ) == CONTENTS_WATER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
step = STEP_WADE;
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = 0.65f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = 600;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->PM_PointContents( feet, NULL ) == CONTENTS_WATER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
step = STEP_SLOSH;
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.2f : 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// find texture under player, if different from current texture,
|
|
|
|
// get material type
|
|
|
|
step = PM_MapTextureTypeStepType( pmove->chtexturetype );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( pmove->chtexturetype )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case CHAR_TEX_CONCRETE:
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.2f : 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
break;
|
|
|
|
case CHAR_TEX_METAL:
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.2f : 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
break;
|
|
|
|
case CHAR_TEX_DIRT:
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.25f : 0.55f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
break;
|
|
|
|
case CHAR_TEX_VENT:
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.4f : 0.7f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
break;
|
|
|
|
case CHAR_TEX_GRATE:
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.2f : 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
break;
|
|
|
|
case CHAR_TEX_TILE:
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.2f : 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
break;
|
|
|
|
case CHAR_TEX_SLOSH:
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = fWalking ? 0.2f : 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound = fWalking ? 400 : 300;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flTimeStepSound += flduck; // slower step time if ducking
|
|
|
|
|
|
|
|
// play the sound
|
|
|
|
// 35% volume if ducking
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flags & FL_DUCKING )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol *= 0.35f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PM_PlayStepSound( step, fvol );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
PM_AddToTouched
|
|
|
|
|
|
|
|
Add's the trace result to touch list, if contact is not already in list.
|
|
|
|
================
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
qboolean PM_AddToTouched( pmtrace_t tr, vec3_t impactvelocity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < pmove->numtouch; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->touchindex[i].ent == tr.ent )
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( i != pmove->numtouch ) // Already in list.
|
2016-06-04 15:24:23 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
VectorCopy( impactvelocity, tr.deltavelocity );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->numtouch >= MAX_PHYSENTS )
|
|
|
|
pmove->Con_DPrintf( "Too many entities were touched!\n" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pmove->touchindex[pmove->numtouch++] = tr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
PM_CheckVelocity
|
|
|
|
|
|
|
|
See if the player has a bogus velocity value.
|
|
|
|
================
|
|
|
|
*/
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_CheckVelocity( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int i;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// bound velocity
|
|
|
|
//
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// See if it's bogus.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( IS_NAN( pmove->velocity[i] ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->Con_Printf( "PM Got a NaN velocity %i\n", i );
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[i] = 0;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( IS_NAN( pmove->origin[i] ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->Con_Printf( "PM Got a NaN origin on %i\n", i );
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->origin[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bound it.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->velocity[i] > pmove->movevars->maxvelocity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->Con_DPrintf( "PM Got a velocity too high on %i\n", i );
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[i] = pmove->movevars->maxvelocity;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->velocity[i] < -pmove->movevars->maxvelocity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->Con_DPrintf( "PM Got a velocity too low on %i\n", i );
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[i] = -pmove->movevars->maxvelocity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
PM_ClipVelocity
|
|
|
|
|
|
|
|
Slide off of the impacting object
|
|
|
|
returns the blocked flags:
|
|
|
|
0x01 == floor
|
|
|
|
0x02 == step / wall
|
|
|
|
==================
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
int PM_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overbounce )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float backoff;
|
|
|
|
float change;
|
2016-06-04 15:24:23 +02:00
|
|
|
float angle;
|
2016-07-31 15:48:50 +02:00
|
|
|
int i, blocked;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
angle = normal[2];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
blocked = 0x00; // Assume unblocked.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( angle > 0 ) // If the plane that is blocking us has a positive z component, then assume it's a floor.
|
|
|
|
blocked |= 0x01;
|
|
|
|
if( !angle ) // If the plane has no Z, it is vertical (wall/step)
|
|
|
|
blocked |= 0x02;
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Determine how far along plane to slide based on incoming direction.
|
|
|
|
// Scale by overbounce factor.
|
2016-07-31 15:48:50 +02:00
|
|
|
backoff = DotProduct( in, normal ) * overbounce;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
change = normal[i] * backoff;
|
2016-06-04 15:24:23 +02:00
|
|
|
out[i] = in[i] - change;
|
|
|
|
// If out velocity is too small, zero it out.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON )
|
2016-06-04 15:24:23 +02:00
|
|
|
out[i] = 0;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Return blocking flags.
|
|
|
|
return blocked;
|
|
|
|
}
|
|
|
|
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_AddCorrectGravity( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float ent_gravity;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->gravity )
|
2016-06-04 15:24:23 +02:00
|
|
|
ent_gravity = pmove->gravity;
|
|
|
|
else
|
2019-10-13 13:49:25 +02:00
|
|
|
ent_gravity = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Add gravity so they'll be in the correct position during movement
|
|
|
|
// yes, this 0.5 looks wrong, but it's not.
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->velocity[2] -= ( ent_gravity * pmove->movevars->gravity * 0.5f * pmove->frametime );
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[2] += pmove->basevelocity[2] * pmove->frametime;
|
|
|
|
pmove->basevelocity[2] = 0;
|
|
|
|
|
|
|
|
PM_CheckVelocity();
|
|
|
|
}
|
|
|
|
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_FixupGravityVelocity( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float ent_gravity;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->gravity )
|
2016-06-04 15:24:23 +02:00
|
|
|
ent_gravity = pmove->gravity;
|
|
|
|
else
|
2019-10-13 13:49:25 +02:00
|
|
|
ent_gravity = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Get the correct velocity for the end of the dt
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->velocity[2] -= ( ent_gravity * pmove->movevars->gravity * pmove->frametime * 0.5f );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PM_CheckVelocity();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PM_FlyMove
|
|
|
|
|
|
|
|
The basic solid body movement clip that slides along multiple planes
|
|
|
|
============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
int PM_FlyMove( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int bumpcount, numbumps;
|
|
|
|
vec3_t dir;
|
|
|
|
float d;
|
|
|
|
int numplanes;
|
|
|
|
vec3_t planes[MAX_CLIP_PLANES];
|
|
|
|
vec3_t primal_velocity, original_velocity;
|
|
|
|
vec3_t new_velocity;
|
|
|
|
int i, j;
|
|
|
|
pmtrace_t trace;
|
|
|
|
vec3_t end;
|
|
|
|
float time_left, allFraction;
|
|
|
|
int blocked;
|
|
|
|
|
|
|
|
numbumps = 4; // Bump up to four times
|
|
|
|
|
|
|
|
blocked = 0; // Assume not blocked
|
2016-06-04 15:24:23 +02:00
|
|
|
numplanes = 0; // and not sliding along any planes
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( pmove->velocity, original_velocity ); // Store original velocity
|
|
|
|
VectorCopy( pmove->velocity, primal_velocity );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
allFraction = 0;
|
|
|
|
time_left = pmove->frametime; // Total time for this movement operation.
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( bumpcount = 0; bumpcount < numbumps; bumpcount++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->velocity[0] && !pmove->velocity[1] && !pmove->velocity[2] )
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Assume we can move all the way from the current origin to the
|
|
|
|
// end point.
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0;i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
end[i] = pmove->origin[i] + time_left * pmove->velocity[i];
|
|
|
|
|
|
|
|
// See if we can make it from origin to end point.
|
2016-07-31 15:48:50 +02:00
|
|
|
trace = pmove->PM_PlayerTrace( pmove->origin, end, PM_NORMAL, -1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
allFraction += trace.fraction;
|
|
|
|
// If we started in a solid object, or we were in solid space
|
|
|
|
// the whole way, zero out our velocity and return that we
|
|
|
|
// are blocked by floor and wall.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( trace.allsolid )
|
2016-06-04 15:24:23 +02:00
|
|
|
{ // entity is trapped in another solid
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
|
|
|
//Con_DPrintf( "Trapped 4\n" );
|
2016-06-04 15:24:23 +02:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we moved some portion of the total distance, then
|
|
|
|
// copy the end position into the pmove->origin and
|
|
|
|
// zero the plane counter.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( trace.fraction > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{ // actually covered some distance
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( trace.endpos, pmove->origin );
|
|
|
|
VectorCopy( pmove->velocity, original_velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
numplanes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we covered the entire distance, we are done
|
|
|
|
// and can return.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( trace.fraction == 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
break; // moved the entire distance
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//if( !trace.ent )
|
|
|
|
// Sys_Error( "PM_PlayerTrace: !trace.ent" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Save entity that blocked us (since fraction was < 1.0)
|
|
|
|
// for contact
|
|
|
|
// Add it if it's not already in the list!!!
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_AddToTouched( trace, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// If the plane we hit has a high z component in the normal, then
|
|
|
|
// it's probably a floor
|
2019-10-13 13:49:25 +02:00
|
|
|
if( trace.plane.normal[2] > 0.7f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
blocked |= 1; // floor
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
// If the plane has a zero z component in the normal, then it's a
|
|
|
|
// step or wall
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !trace.plane.normal[2] )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
blocked |= 2; // step / wall
|
|
|
|
//Con_DPrintf( "Blocked by %i\n", trace.ent );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce amount of pmove->frametime left by total time left * fraction
|
|
|
|
// that we covered.
|
|
|
|
time_left -= time_left * trace.fraction;
|
|
|
|
|
|
|
|
// Did we run out of planes to clip against?
|
2016-07-31 15:48:50 +02:00
|
|
|
if( numplanes >= MAX_CLIP_PLANES )
|
2016-06-04 15:24:23 +02:00
|
|
|
{ // this shouldn't really happen
|
|
|
|
// Stop our movement if so.
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
|
|
|
//Con_DPrintf( "Too many planes 4\n" );
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up next clipping plane
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( trace.plane.normal, planes[numplanes] );
|
2016-06-04 15:24:23 +02:00
|
|
|
numplanes++;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// modify original_velocity so it parallels all of the clip planes
|
|
|
|
//
|
|
|
|
if( pmove->movetype == MOVETYPE_WALK && ( ( pmove->onground == -1 ) || ( pmove->friction != 1 ) ) ) // relfect player velocity
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < numplanes; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
if( planes[i][2] > 0.7f )
|
2016-07-31 15:48:50 +02:00
|
|
|
{
|
|
|
|
// floor or slope
|
2016-06-04 15:24:23 +02:00
|
|
|
PM_ClipVelocity( original_velocity, planes[i], new_velocity, 1 );
|
|
|
|
VectorCopy( new_velocity, original_velocity );
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else
|
2019-10-13 13:49:25 +02:00
|
|
|
PM_ClipVelocity( original_velocity, planes[i], new_velocity, 1.0f + pmove->movevars->bounce * ( 1 - pmove->friction ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VectorCopy( new_velocity, pmove->velocity );
|
|
|
|
VectorCopy( new_velocity, original_velocity );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < numplanes; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_ClipVelocity( original_velocity, planes[i], pmove->velocity, 1 );
|
|
|
|
for( j = 0; j < numplanes; j++ )
|
|
|
|
if( j != i )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Are we now moving against this plane?
|
2016-07-31 15:48:50 +02:00
|
|
|
if( DotProduct( pmove->velocity, planes[j] ) < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
break; // not ok
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( j == numplanes ) // Didn't have to clip, so we're ok
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Did we go all the way through plane set
|
2016-07-31 15:48:50 +02:00
|
|
|
if( i != numplanes )
|
|
|
|
{
|
|
|
|
// go along this plane
|
|
|
|
// pmove->velocity is set in clipping call, no need to set again.
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // go along the crease
|
2016-07-31 15:48:50 +02:00
|
|
|
if( numplanes != 2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
//Con_Printf( "clip velocity, numplanes == %i\n",numplanes );
|
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
|
|
|
//Con_DPrintf( "Trapped 4\n" );
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
CrossProduct( planes[0], planes[1], dir );
|
|
|
|
d = DotProduct( dir, pmove->velocity );
|
|
|
|
VectorScale( dir, d, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//
|
|
|
|
// if original velocity is against the original velocity, stop dead
|
|
|
|
// to avoid tiny occilations in sloping corners
|
|
|
|
//
|
|
|
|
if( DotProduct( pmove->velocity, primal_velocity ) <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
//Con_DPrintf( "Back\n" );
|
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( allFraction == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
//Con_DPrintf( "Don't stick\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return blocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
PM_Accelerate
|
|
|
|
==============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_Accelerate( vec3_t wishdir, float wishspeed, float accel )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int i;
|
|
|
|
float addspeed, accelspeed, currentspeed;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Dead player's don't accelerate
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->dead )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// If waterjumping, don't accelerate
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// See if we are changing direction a bit
|
2016-07-31 15:48:50 +02:00
|
|
|
currentspeed = DotProduct( pmove->velocity, wishdir );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Reduce wishspeed by the amount of veer.
|
|
|
|
addspeed = wishspeed - currentspeed;
|
|
|
|
|
|
|
|
// If not going to add any speed, done.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( addspeed <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Determine amount of accleration.
|
|
|
|
accelspeed = accel * pmove->frametime * wishspeed * pmove->friction;
|
|
|
|
|
|
|
|
// Cap at addspeed
|
2016-07-31 15:48:50 +02:00
|
|
|
if( accelspeed > addspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
accelspeed = addspeed;
|
|
|
|
|
|
|
|
// Adjust velocity.
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->velocity[i] += accelspeed * wishdir[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
PM_WalkMove
|
|
|
|
|
|
|
|
Only used by players. Moves along the ground when player is a MOVETYPE_WALK.
|
|
|
|
======================
|
|
|
|
*/
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_WalkMove( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2017-06-29 15:56:03 +02:00
|
|
|
//int clip;
|
2016-07-31 15:48:50 +02:00
|
|
|
int oldonground;
|
2016-06-04 15:24:23 +02:00
|
|
|
int i;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t wishvel;
|
|
|
|
float spd;
|
|
|
|
float fmove, smove;
|
|
|
|
vec3_t wishdir;
|
|
|
|
float wishspeed;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2017-06-29 15:56:03 +02:00
|
|
|
vec3_t dest; //, start;
|
2016-06-04 15:24:23 +02:00
|
|
|
vec3_t original, originalvel;
|
|
|
|
vec3_t down, downvel;
|
|
|
|
float downdist, updist;
|
|
|
|
|
|
|
|
pmtrace_t trace;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Copy movement amounts
|
|
|
|
fmove = pmove->cmd.forwardmove;
|
|
|
|
smove = pmove->cmd.sidemove;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Zero out z components of movement vectors
|
|
|
|
pmove->forward[2] = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->right[2] = 0;
|
|
|
|
|
|
|
|
VectorNormalize( pmove->forward ); // Normalize remainder of vectors.
|
|
|
|
VectorNormalize( pmove->right ); //
|
|
|
|
|
|
|
|
for( i = 0; i < 2; i++ ) // Determine x and y parts of velocity
|
|
|
|
wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
wishvel[2] = 0; // Zero out z part of velocity
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( wishvel, wishdir ); // Determine maginitude of speed of move
|
|
|
|
wishspeed = VectorNormalize( wishdir );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//
|
|
|
|
// Clamp to server defined max speed
|
|
|
|
//
|
|
|
|
if( wishspeed > pmove->maxspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( wishvel, pmove->maxspeed / wishspeed, wishvel );
|
2016-06-04 15:24:23 +02:00
|
|
|
wishspeed = pmove->maxspeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set pmove velocity
|
|
|
|
pmove->velocity[2] = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_Accelerate( wishdir, wishspeed, pmove->movevars->accelerate );
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[2] = 0;
|
|
|
|
|
|
|
|
// Add in any base velocity to the current velocity.
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
spd = Length( pmove->velocity );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( spd < 1.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorClear( pmove->velocity );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are not moving, do nothing
|
2016-07-31 15:48:50 +02:00
|
|
|
//if( !pmove->velocity[0] && !pmove->velocity[1] && !pmove->velocity[2] )
|
2016-06-04 15:24:23 +02:00
|
|
|
// return;
|
|
|
|
|
|
|
|
oldonground = pmove->onground;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// first try just moving to the destination
|
|
|
|
dest[0] = pmove->origin[0] + pmove->velocity[0] * pmove->frametime;
|
|
|
|
dest[1] = pmove->origin[1] + pmove->velocity[1] * pmove->frametime;
|
2016-06-04 15:24:23 +02:00
|
|
|
dest[2] = pmove->origin[2];
|
|
|
|
|
|
|
|
// first try moving directly to the next spot
|
2017-06-29 15:56:03 +02:00
|
|
|
//VectorCopy( dest, start );
|
2016-07-31 15:48:50 +02:00
|
|
|
trace = pmove->PM_PlayerTrace( pmove->origin, dest, PM_NORMAL, -1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
// If we made it all the way, then copy trace end
|
|
|
|
// as new player position.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( trace.fraction == 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( trace.endpos, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// Don't walk up stairs if not on ground.
|
|
|
|
if( oldonground == -1 && pmove->waterlevel == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime ) // If we are jumping out of water, don't do anything more.
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Try sliding forward both on ground and up 16 pixels
|
|
|
|
// take the move that goes farthest
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( pmove->origin, original ); // Save out original pos &
|
|
|
|
VectorCopy( pmove->velocity, originalvel ); // velocity.
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Slide move
|
2017-06-29 15:56:03 +02:00
|
|
|
//clip = PM_FlyMove();
|
|
|
|
PM_FlyMove();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Copy the results out
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( pmove->origin, down );
|
|
|
|
VectorCopy( pmove->velocity, downvel );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Reset original values.
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( original, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( originalvel, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Start out up one stair height
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( pmove->origin, dest );
|
2016-06-04 15:24:23 +02:00
|
|
|
dest[2] += pmove->movevars->stepsize;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
trace = pmove->PM_PlayerTrace( pmove->origin, dest, PM_NORMAL, -1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
// If we started okay and made it part of the way at least,
|
|
|
|
// copy the results to the movement start position and then
|
|
|
|
// run another move try.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !trace.startsolid && !trace.allsolid )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( trace.endpos, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// slide move the rest of the way.
|
2017-06-29 15:56:03 +02:00
|
|
|
//clip = PM_FlyMove();
|
|
|
|
PM_FlyMove();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// Now try going back down from the end point
|
|
|
|
// press down the stepheight
|
|
|
|
VectorCopy( pmove->origin, dest );
|
2016-06-04 15:24:23 +02:00
|
|
|
dest[2] -= pmove->movevars->stepsize;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
trace = pmove->PM_PlayerTrace( pmove->origin, dest, PM_NORMAL, -1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// If we are not on the ground any more then
|
|
|
|
// use the original movement attempt
|
2019-10-13 13:49:25 +02:00
|
|
|
if( trace.plane.normal[2] < 0.7f )
|
2016-06-04 15:24:23 +02:00
|
|
|
goto usedown;
|
2019-10-13 13:49:25 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// If the trace ended up in empty space, copy the end
|
|
|
|
// over to the origin.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !trace.startsolid && !trace.allsolid )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( trace.endpos, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
// Copy this origion to up.
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( pmove->origin, pmove->up );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// decide which one went farther
|
2016-07-31 15:48:50 +02:00
|
|
|
downdist = ( down[0] - original[0] ) * ( down[0] - original[0] )
|
|
|
|
+ ( down[1] - original[1] ) * ( down[1] - original[1] );
|
|
|
|
updist = ( pmove->up[0] - original[0] ) * ( pmove->up[0] - original[0] )
|
|
|
|
+ ( pmove->up[1] - original[1] ) * ( pmove->up[1] - original[1] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( downdist > updist )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
usedown:
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( down, pmove->origin );
|
|
|
|
VectorCopy( downvel, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
} else // copy z value from slide move
|
|
|
|
pmove->velocity[2] = downvel[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
PM_Friction
|
|
|
|
|
|
|
|
Handles both ground friction and water friction
|
|
|
|
==================
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_Friction( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float *vel;
|
|
|
|
float speed, newspeed, control;
|
|
|
|
float friction;
|
|
|
|
float drop;
|
2016-06-04 15:24:23 +02:00
|
|
|
vec3_t newvel;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// If we are in water jump cycle, don't apply friction
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Get velocity
|
|
|
|
vel = pmove->velocity;
|
|
|
|
|
|
|
|
// Calculate speed
|
2016-07-31 15:48:50 +02:00
|
|
|
speed = sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// If too slow, return
|
2016-07-31 15:48:50 +02:00
|
|
|
if( speed < 0.1f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
drop = 0;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// apply ground friction
|
|
|
|
if( pmove->onground != -1 ) // On an entity that is the ground
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
vec3_t start, stop;
|
|
|
|
pmtrace_t trace;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
start[0] = stop[0] = pmove->origin[0] + vel[0] / speed * 16;
|
|
|
|
start[1] = stop[1] = pmove->origin[1] + vel[1] / speed * 16;
|
2016-06-04 15:24:23 +02:00
|
|
|
start[2] = pmove->origin[2] + pmove->player_mins[pmove->usehull][2];
|
|
|
|
stop[2] = start[2] - 34;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
trace = pmove->PM_PlayerTrace( start, stop, PM_NORMAL, -1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( trace.fraction == 1.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
friction = pmove->movevars->friction*pmove->movevars->edgefriction;
|
|
|
|
else
|
|
|
|
friction = pmove->movevars->friction;
|
|
|
|
|
|
|
|
// Grab friction value.
|
|
|
|
//friction = pmove->movevars->friction;
|
|
|
|
|
|
|
|
friction *= pmove->friction; // player friction?
|
|
|
|
|
|
|
|
// Bleed off some speed, but if we have less than the bleed
|
|
|
|
// threshhold, bleed the theshold amount.
|
2016-07-31 15:48:50 +02:00
|
|
|
control = ( speed < pmove->movevars->stopspeed ) ? pmove->movevars->stopspeed : speed;
|
2016-06-04 15:24:23 +02:00
|
|
|
// Add the amount to t'he drop amount.
|
2016-07-31 15:48:50 +02:00
|
|
|
drop += control * friction * pmove->frametime;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// apply water friction
|
|
|
|
//if( pmove->waterlevel )
|
|
|
|
// drop += speed * pmove->movevars->waterfriction * waterlevel * pmove->frametime;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// scale the velocity
|
2016-06-04 15:24:23 +02:00
|
|
|
newspeed = speed - drop;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( newspeed < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
newspeed = 0;
|
|
|
|
|
|
|
|
// Determine proportion of old speed we are using.
|
|
|
|
newspeed /= speed;
|
|
|
|
|
|
|
|
// Adjust velocity according to proportion.
|
|
|
|
newvel[0] = vel[0] * newspeed;
|
|
|
|
newvel[1] = vel[1] * newspeed;
|
|
|
|
newvel[2] = vel[2] * newspeed;
|
|
|
|
|
|
|
|
VectorCopy( newvel, pmove->velocity );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_AirAccelerate( vec3_t wishdir, float wishspeed, float accel )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int i;
|
|
|
|
float addspeed, accelspeed, currentspeed, wishspd = wishspeed;
|
|
|
|
|
|
|
|
if( pmove->dead )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Cap speed
|
2016-07-31 15:48:50 +02:00
|
|
|
//wishspd = VectorNormalize( pmove->wishveloc );
|
|
|
|
|
|
|
|
if( wishspd > 30 )
|
2016-06-04 15:24:23 +02:00
|
|
|
wishspd = 30;
|
|
|
|
// Determine veer amount
|
2016-07-31 15:48:50 +02:00
|
|
|
currentspeed = DotProduct( pmove->velocity, wishdir );
|
2016-06-04 15:24:23 +02:00
|
|
|
// See how much to add
|
|
|
|
addspeed = wishspd - currentspeed;
|
|
|
|
// If not adding any, done.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( addspeed <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
// Determine acceleration speed after acceleration
|
|
|
|
|
|
|
|
accelspeed = accel * wishspeed * pmove->frametime * pmove->friction;
|
|
|
|
// Cap it
|
2016-07-31 15:48:50 +02:00
|
|
|
if( accelspeed > addspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
accelspeed = addspeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Adjust pmove vel.
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->velocity[i] += accelspeed * wishdir[i];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
PM_WaterMove
|
|
|
|
|
|
|
|
===================
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_WaterMove( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int i;
|
|
|
|
vec3_t wishvel;
|
|
|
|
float wishspeed;
|
|
|
|
vec3_t wishdir;
|
|
|
|
vec3_t start, dest;
|
|
|
|
vec3_t temp;
|
|
|
|
pmtrace_t trace;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
float speed, newspeed, addspeed, accelspeed;
|
|
|
|
|
|
|
|
//
|
|
|
|
// user intentions
|
|
|
|
//
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
wishvel[i] = pmove->forward[i] * pmove->cmd.forwardmove + pmove->right[i] * pmove->cmd.sidemove;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Sinking after no other movement occurs
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->cmd.forwardmove && !pmove->cmd.sidemove && !pmove->cmd.upmove )
|
2016-06-04 15:24:23 +02:00
|
|
|
wishvel[2] -= 60; // drift towards bottom
|
|
|
|
else // Go straight up by upmove amount.
|
|
|
|
wishvel[2] += pmove->cmd.upmove;
|
|
|
|
|
|
|
|
// Copy it over and determine speed
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( wishvel, wishdir );
|
|
|
|
wishspeed = VectorNormalize( wishdir );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Cap speed.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( wishspeed > pmove->maxspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( wishvel, pmove->maxspeed / wishspeed, wishvel );
|
2016-06-04 15:24:23 +02:00
|
|
|
wishspeed = pmove->maxspeed;
|
|
|
|
}
|
|
|
|
// Slow us down a bit.
|
2019-10-13 13:49:25 +02:00
|
|
|
wishspeed *= 0.8f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
|
|
|
|
|
|
|
// Water friction
|
|
|
|
VectorCopy( pmove->velocity, temp );
|
|
|
|
speed = VectorNormalize( temp );
|
|
|
|
if( speed )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
newspeed = speed - pmove->frametime * speed * pmove->movevars->friction * pmove->friction;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( newspeed < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
newspeed = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( pmove->velocity, newspeed / speed, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
newspeed = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// water acceleration
|
|
|
|
//
|
2016-07-31 15:48:50 +02:00
|
|
|
if( wishspeed < 0.1f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addspeed = wishspeed - newspeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( addspeed > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorNormalize( wishvel );
|
2016-06-04 15:24:23 +02:00
|
|
|
accelspeed = pmove->movevars->accelerate * wishspeed * pmove->frametime * pmove->friction;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( accelspeed > addspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
accelspeed = addspeed;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[i] += accelspeed * wishvel[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now move
|
|
|
|
// assume it is a stair or a slope, so press down from stepheight above
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorMA( pmove->origin, pmove->frametime, pmove->velocity, dest );
|
|
|
|
VectorCopy( dest, start );
|
2016-06-04 15:24:23 +02:00
|
|
|
start[2] += pmove->movevars->stepsize + 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
trace = pmove->PM_PlayerTrace( start, dest, PM_NORMAL, -1 );
|
|
|
|
if( !trace.startsolid && !trace.allsolid ) // FIXME: check steep slope?
|
2016-06-04 15:24:23 +02:00
|
|
|
{ // walked up the step, so just keep result and exit
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( trace.endpos, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Try moving straight along out normal path.
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_FlyMove();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
PM_AirMove
|
|
|
|
|
|
|
|
===================
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_AirMove( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int i;
|
|
|
|
vec3_t wishvel;
|
|
|
|
float fmove, smove;
|
|
|
|
vec3_t wishdir;
|
|
|
|
float wishspeed;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Copy movement amounts
|
|
|
|
fmove = pmove->cmd.forwardmove;
|
|
|
|
smove = pmove->cmd.sidemove;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Zero out z components of movement vectors
|
|
|
|
pmove->forward[2] = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->right[2] = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
// Renormalize
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorNormalize( pmove->forward );
|
|
|
|
VectorNormalize( pmove->right );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Determine x and y parts of velocity
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 2; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
// Zero out z part of velocity
|
2016-07-31 15:48:50 +02:00
|
|
|
wishvel[2] = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Determine maginitude of speed of move
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( wishvel, wishdir );
|
|
|
|
wishspeed = VectorNormalize( wishdir );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Clamp to server defined max speed
|
2016-07-31 15:48:50 +02:00
|
|
|
if( wishspeed > pmove->maxspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( wishvel, pmove->maxspeed/wishspeed, wishvel );
|
2016-06-04 15:24:23 +02:00
|
|
|
wishspeed = pmove->maxspeed;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_AirAccelerate( wishdir, wishspeed, pmove->movevars->airaccelerate );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Add in any base velocity to the current velocity.
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_FlyMove();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qboolean PM_InWater( void )
|
|
|
|
{
|
|
|
|
return ( pmove->waterlevel > 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
PM_CheckWater
|
|
|
|
|
|
|
|
Sets pmove->waterlevel and pmove->watertype values.
|
|
|
|
=============
|
|
|
|
*/
|
2024-02-18 21:46:19 +01:00
|
|
|
qboolean PM_CheckWater( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t point;
|
|
|
|
int cont;
|
|
|
|
int truecont;
|
|
|
|
float height;
|
|
|
|
float heightover2;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Pick a spot just above the players feet.
|
2019-10-13 13:49:25 +02:00
|
|
|
point[0] = pmove->origin[0] + ( pmove->player_mins[pmove->usehull][0] + pmove->player_maxs[pmove->usehull][0] ) * 0.5f;
|
|
|
|
point[1] = pmove->origin[1] + ( pmove->player_mins[pmove->usehull][1] + pmove->player_maxs[pmove->usehull][1] ) * 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
point[2] = pmove->origin[2] + pmove->player_mins[pmove->usehull][2] + 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Assume that we are not in water at all.
|
|
|
|
pmove->waterlevel = 0;
|
|
|
|
pmove->watertype = CONTENTS_EMPTY;
|
|
|
|
|
|
|
|
// Grab point contents.
|
|
|
|
cont = pmove->PM_PointContents (point, &truecont );
|
|
|
|
// Are we under water? (not solid and not empty?)
|
2016-07-31 15:48:50 +02:00
|
|
|
if( cont <= CONTENTS_WATER && cont > CONTENTS_TRANSLUCENT )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Set water type
|
|
|
|
pmove->watertype = cont;
|
|
|
|
|
|
|
|
// We are at least at level one
|
|
|
|
pmove->waterlevel = 1;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
height = ( pmove->player_mins[pmove->usehull][2] + pmove->player_maxs[pmove->usehull][2] );
|
2019-10-13 13:49:25 +02:00
|
|
|
heightover2 = height * 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Now check a point that is at the player hull midpoint.
|
|
|
|
point[2] = pmove->origin[2] + heightover2;
|
2016-07-31 15:48:50 +02:00
|
|
|
cont = pmove->PM_PointContents( point, NULL );
|
2016-06-04 15:24:23 +02:00
|
|
|
// If that point is also under water...
|
2016-07-31 15:48:50 +02:00
|
|
|
if( cont <= CONTENTS_WATER && cont > CONTENTS_TRANSLUCENT )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Set a higher water level.
|
|
|
|
pmove->waterlevel = 2;
|
|
|
|
|
|
|
|
// Now check the eye position. (view_ofs is relative to the origin)
|
|
|
|
point[2] = pmove->origin[2] + pmove->view_ofs[2];
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
cont = pmove->PM_PointContents( point, NULL );
|
|
|
|
if( cont <= CONTENTS_WATER && cont > CONTENTS_TRANSLUCENT )
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->waterlevel = 3; // In over our eyes
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust velocity based on water current, if any.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( truecont <= CONTENTS_CURRENT_0 ) && ( truecont >= CONTENTS_CURRENT_DOWN ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// The deeper we are, the stronger the current.
|
|
|
|
static vec3_t current_table[] =
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
{1, 0, 0},
|
|
|
|
{0, 1, 0},
|
|
|
|
{-1, 0, 0},
|
|
|
|
{0, -1, 0},
|
|
|
|
{0, 0, 1},
|
|
|
|
{0, 0, -1}
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorMA( pmove->basevelocity, 50.0*pmove->waterlevel, current_table[CONTENTS_CURRENT_0 - truecont], pmove->basevelocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pmove->waterlevel > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
PM_CatagorizePosition
|
|
|
|
=============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_CatagorizePosition( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t point;
|
|
|
|
pmtrace_t tr;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// if the player hull point one unit down is solid, the player
|
|
|
|
// is on ground
|
|
|
|
|
|
|
|
// see if standing on something solid
|
|
|
|
|
|
|
|
// Doing this before we move may introduce a potential latency in water detection, but
|
|
|
|
// doing it after can get us stuck on the bottom in water if the amount we move up
|
|
|
|
// is less than the 1 pixel 'threshold' we're about to snap to. Also, we'll call
|
|
|
|
// this several times per frame, so we really need to avoid sticking to the bottom of
|
|
|
|
// water on each call, and the converse case will correct itself if called twice.
|
|
|
|
PM_CheckWater();
|
|
|
|
|
|
|
|
point[0] = pmove->origin[0];
|
|
|
|
point[1] = pmove->origin[1];
|
|
|
|
point[2] = pmove->origin[2] - 2;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->velocity[2] > 180 ) // Shooting up really fast. Definitely not on ground.
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->onground = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Try and move down.
|
2016-07-31 15:48:50 +02:00
|
|
|
tr = pmove->PM_PlayerTrace( pmove->origin, point, PM_NORMAL, -1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
// If we hit a steep plane, we are not on ground
|
2019-10-13 13:49:25 +02:00
|
|
|
if( tr.plane.normal[2] < 0.7f )
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->onground = -1; // too steep
|
|
|
|
else
|
|
|
|
pmove->onground = tr.ent; // Otherwise, point to index of ent under us.
|
|
|
|
|
|
|
|
// If we are on something...
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Then we are not in water jump sequence
|
|
|
|
pmove->waterjumptime = 0;
|
|
|
|
// If we could make the move, drop us down that 1 pixel
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterlevel < 2 && !tr.startsolid && !tr.allsolid )
|
|
|
|
VectorCopy( tr.endpos, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Standing on an entity other than the world
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr.ent > 0 ) // So signal that we are touching something.
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_AddToTouched( tr, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
PM_GetRandomStuckOffsets
|
|
|
|
|
|
|
|
When a player is stuck, it's costly to try and unstick them
|
|
|
|
Grab a test offset for the player based on a passed in index
|
|
|
|
=================
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
int PM_GetRandomStuckOffsets( int nIndex, int server, vec3_t offset )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
// Last time we did a full
|
2016-06-04 15:24:23 +02:00
|
|
|
int idx;
|
|
|
|
idx = rgStuckLast[nIndex][server]++;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( rgv3tStuckTable[idx % 54], offset );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
return ( idx % 54 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_ResetStuckOffsets( int nIndex, int server )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgStuckLast[nIndex][server] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
NudgePosition
|
|
|
|
|
|
|
|
If pmove->origin is in a solid position,
|
|
|
|
try nudging slightly on all axis to
|
|
|
|
allow for the cut precision of the net coordinates
|
|
|
|
=================
|
|
|
|
*/
|
2019-10-13 13:49:25 +02:00
|
|
|
#define PM_CHECKSTUCK_MINTIME 0.05f // Don't check again too quickly.
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int PM_CheckStuck( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t base;
|
|
|
|
vec3_t offset;
|
|
|
|
vec3_t test;
|
|
|
|
int hitent;
|
|
|
|
int idx;
|
|
|
|
float fTime;
|
2016-06-04 15:24:23 +02:00
|
|
|
int i;
|
|
|
|
pmtrace_t traceresult;
|
|
|
|
|
|
|
|
static float rgStuckCheckTime[MAX_CLIENTS][2]; // Last time we did a full
|
|
|
|
|
|
|
|
// If position is okay, exit
|
2016-07-31 15:48:50 +02:00
|
|
|
hitent = pmove->PM_TestPlayerPosition( pmove->origin, &traceresult );
|
|
|
|
if( hitent == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_ResetStuckOffsets( pmove->player_index, pmove->server );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( pmove->origin, base );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//
|
2016-06-04 15:24:23 +02:00
|
|
|
// Deal with precision error in network.
|
2016-07-31 15:48:50 +02:00
|
|
|
//
|
2024-02-04 01:26:45 +01:00
|
|
|
if( !( pmove->server && pmove->multiplayer ))
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// World or BSP model
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( hitent == 0 ) || ( pmove->physents[hitent].model != NULL ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
int nReps = 0;
|
|
|
|
PM_ResetStuckOffsets( pmove->player_index, pmove->server );
|
|
|
|
do
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
i = PM_GetRandomStuckOffsets( pmove->player_index, pmove->server, offset );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( base, offset, test );
|
|
|
|
if( pmove->PM_TestPlayerPosition( test, &traceresult ) == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_ResetStuckOffsets( pmove->player_index, pmove->server );
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
VectorCopy( test, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
nReps++;
|
2016-07-31 15:48:50 +02:00
|
|
|
} while( nReps < 54 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only an issue on the client.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->server )
|
2016-06-04 15:24:23 +02:00
|
|
|
idx = 0;
|
|
|
|
else
|
|
|
|
idx = 1;
|
|
|
|
|
|
|
|
fTime = pmove->Sys_FloatTime();
|
|
|
|
// Too soon?
|
2016-07-31 15:48:50 +02:00
|
|
|
if( rgStuckCheckTime[pmove->player_index][idx] >= ( fTime - PM_CHECKSTUCK_MINTIME ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
rgStuckCheckTime[pmove->player_index][idx] = fTime;
|
|
|
|
|
|
|
|
pmove->PM_StuckTouch( hitent, &traceresult );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
i = PM_GetRandomStuckOffsets( pmove->player_index, pmove->server, offset );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( base, offset, test );
|
|
|
|
if( ( hitent = pmove->PM_TestPlayerPosition( test, NULL ) ) == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
//Con_DPrintf( "Nudged\n" );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PM_ResetStuckOffsets( pmove->player_index, pmove->server );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( test, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If player is flailing while stuck in another player ( should never happen ), then see
|
|
|
|
// if we can't "unstick" them forceably.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & ( IN_JUMP | IN_DUCK | IN_ATTACK ) && ( pmove->physents[hitent].player != 0 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
float x, y, z;
|
2019-10-13 13:49:25 +02:00
|
|
|
float xystep = 8.0f;
|
|
|
|
float zstep = 18.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
float xyminmax = xystep;
|
|
|
|
float zminmax = 4 * zstep;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
for( z = 0; z <= zminmax; z += zstep )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( x = -xyminmax; x <= xyminmax; x += xystep )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( y = -xyminmax; y <= xyminmax; y += xystep )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorCopy( base, test );
|
|
|
|
test[0] += x;
|
|
|
|
test[1] += y;
|
|
|
|
test[2] += z;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->PM_TestPlayerPosition( test, NULL ) == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorCopy( test, pmove->origin );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//VectorCopy( base, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
PM_SpectatorMove
|
|
|
|
===============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_SpectatorMove( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float speed, drop, friction, control, newspeed;
|
|
|
|
//float accel;
|
|
|
|
float currentspeed, addspeed, accelspeed;
|
|
|
|
int i;
|
|
|
|
vec3_t wishvel;
|
|
|
|
float fmove, smove;
|
|
|
|
vec3_t wishdir;
|
|
|
|
float wishspeed;
|
2016-06-04 15:24:23 +02:00
|
|
|
// this routine keeps track of the spectators psoition
|
|
|
|
// there a two different main move types : track player or moce freely (OBS_ROAMING)
|
|
|
|
// doesn't need excate track position, only to generate PVS, so just copy
|
|
|
|
// targets position and real view position is calculated on client (saves server CPU)
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->iuser1 == OBS_ROAMING )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2021-06-07 02:05:58 +02:00
|
|
|
#if CLIENT_DLL
|
2016-06-04 15:24:23 +02:00
|
|
|
// jump only in roaming mode
|
2016-07-31 15:48:50 +02:00
|
|
|
if( iJumpSpectator )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorCopy( vJumpOrigin, pmove->origin );
|
|
|
|
VectorCopy( vJumpAngles, pmove->angles );
|
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
|
|
|
iJumpSpectator = 0;
|
|
|
|
return;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
#endif
|
2016-06-04 15:24:23 +02:00
|
|
|
// Move around in normal spectator method
|
2016-07-31 15:48:50 +02:00
|
|
|
speed = Length( pmove->velocity );
|
|
|
|
if( speed < 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( vec3_origin, pmove->velocity )
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drop = 0;
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
friction = pmove->movevars->friction * 1.5f; // extra friction
|
2016-06-04 15:24:23 +02:00
|
|
|
control = speed < pmove->movevars->stopspeed ? pmove->movevars->stopspeed : speed;
|
2016-07-31 15:48:50 +02:00
|
|
|
drop += control * friction*pmove->frametime;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// scale the velocity
|
|
|
|
newspeed = speed - drop;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( newspeed < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
newspeed = 0;
|
|
|
|
newspeed /= speed;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( pmove->velocity, newspeed, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// accelerate
|
|
|
|
fmove = pmove->cmd.forwardmove;
|
|
|
|
smove = pmove->cmd.sidemove;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorNormalize( pmove->forward );
|
|
|
|
VectorNormalize( pmove->right );
|
|
|
|
|
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
wishvel[2] += pmove->cmd.upmove;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( wishvel, wishdir );
|
|
|
|
wishspeed = VectorNormalize( wishdir );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// clamp to server defined max speed
|
|
|
|
//
|
2016-07-31 15:48:50 +02:00
|
|
|
if( wishspeed > pmove->movevars->spectatormaxspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( wishvel, pmove->movevars->spectatormaxspeed/wishspeed, wishvel );
|
2016-06-04 15:24:23 +02:00
|
|
|
wishspeed = pmove->movevars->spectatormaxspeed;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
currentspeed = DotProduct( pmove->velocity, wishdir );
|
2016-06-04 15:24:23 +02:00
|
|
|
addspeed = wishspeed - currentspeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( addspeed <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
accelspeed = pmove->movevars->accelerate * pmove->frametime * wishspeed;
|
|
|
|
if( accelspeed > addspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
accelspeed = addspeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
pmove->velocity[i] += accelspeed*wishdir[i];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// move
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorMA( pmove->origin, pmove->frametime, pmove->velocity, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// all other modes just track some kind of target, so spectator PVS = target PVS
|
|
|
|
|
|
|
|
int target;
|
|
|
|
|
|
|
|
// no valid target ?
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->iuser2 <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Find the client this player's targeting
|
2016-07-31 15:48:50 +02:00
|
|
|
for( target = 0; target < pmove->numphysent; target++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->physents[target].info == pmove->iuser2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( target == pmove->numphysent )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// use targets position as own origin for PVS
|
|
|
|
VectorCopy( pmove->physents[target].angles, pmove->angles );
|
|
|
|
VectorCopy( pmove->physents[target].origin, pmove->origin );
|
|
|
|
|
|
|
|
// no velocity
|
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
PM_SplineFraction
|
|
|
|
|
|
|
|
Use for ease-in, ease-out style interpolation (accel/decel)
|
|
|
|
Used by ducking code.
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
float PM_SplineFraction( float value, float scale )
|
|
|
|
{
|
|
|
|
float valueSquared;
|
|
|
|
|
|
|
|
value = scale * value;
|
|
|
|
valueSquared = value * value;
|
|
|
|
|
|
|
|
// Nice little ease-in, ease-out spline-like curve
|
|
|
|
return 3 * valueSquared - 2 * valueSquared * value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_FixPlayerCrouchStuck( int direction )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int hitent;
|
2016-06-04 15:24:23 +02:00
|
|
|
int i;
|
|
|
|
vec3_t test;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
hitent = pmove->PM_TestPlayerPosition( pmove->origin, NULL );
|
|
|
|
if( hitent == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
VectorCopy( pmove->origin, test );
|
|
|
|
for( i = 0; i < 36; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->origin[2] += direction;
|
2016-07-31 15:48:50 +02:00
|
|
|
hitent = pmove->PM_TestPlayerPosition( pmove->origin, NULL );
|
|
|
|
if( hitent == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorCopy( test, pmove->origin ); // Failed
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_UnDuck( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
pmtrace_t trace;
|
|
|
|
vec3_t newOrigin;
|
|
|
|
|
|
|
|
VectorCopy( pmove->origin, newOrigin );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
newOrigin[i] += ( pmove->player_mins[1][i] - pmove->player_mins[0][i] );
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
trace = pmove->PM_PlayerTrace( newOrigin, newOrigin, PM_NORMAL, -1 );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !trace.startsolid )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->usehull = 0;
|
|
|
|
|
|
|
|
// Oh, no, changing hulls stuck us into something, try unsticking downward first.
|
2016-07-31 15:48:50 +02:00
|
|
|
trace = pmove->PM_PlayerTrace( newOrigin, newOrigin, PM_NORMAL, -1 );
|
|
|
|
if( trace.startsolid )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// See if we are stuck? If so, stay ducked with the duck hull until we have a clear spot
|
|
|
|
//Con_Printf( "unstick got stuck\n" );
|
|
|
|
pmove->usehull = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmove->flags &= ~FL_DUCKING;
|
|
|
|
pmove->bInDuck = false;
|
|
|
|
pmove->view_ofs[2] = VEC_VIEW;
|
|
|
|
pmove->flDuckTime = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
VectorCopy( newOrigin, pmove->origin );
|
|
|
|
|
|
|
|
// Recatagorize position since ducking can change origin
|
|
|
|
PM_CatagorizePosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_Duck( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float time;
|
|
|
|
float duckFraction;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int buttonsChanged = ( pmove->oldbuttons ^ pmove->cmd.buttons ); // These buttons have changed this frame
|
|
|
|
int nButtonPressed = buttonsChanged & pmove->cmd.buttons; // The changed ones still down are "pressed"
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2017-06-29 15:56:03 +02:00
|
|
|
//int duckchange = buttonsChanged & IN_DUCK ? 1 : 0;
|
|
|
|
//int duckpressed = nButtonPressed & IN_DUCK ? 1 : 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_DUCK )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->oldbuttons |= IN_DUCK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pmove->oldbuttons &= ~IN_DUCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent ducking if the iuser3 variable is set
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->iuser3 || pmove->dead )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Try to unduck
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flags & FL_DUCKING )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_UnDuck();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flags & FL_DUCKING )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2017-06-26 02:47:19 +02:00
|
|
|
pmove->cmd.forwardmove *= PLAYER_DUCKING_MULTIPLIER;
|
|
|
|
pmove->cmd.sidemove *= PLAYER_DUCKING_MULTIPLIER;
|
|
|
|
pmove->cmd.upmove *= PLAYER_DUCKING_MULTIPLIER;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( pmove->cmd.buttons & IN_DUCK ) || ( pmove->bInDuck ) || ( pmove->flags & FL_DUCKING ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_DUCK )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( (nButtonPressed & IN_DUCK ) && !( pmove->flags & FL_DUCKING ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Use 1 second so super long jump will work
|
|
|
|
pmove->flDuckTime = 1000;
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->bInDuck = true;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
time = max( 0.0f, ( 1.0f - (float)pmove->flDuckTime / 1000.0f ) );
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
if( pmove->bInDuck )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Finish ducking immediately if duck time is over or not on ground
|
2019-10-13 13:49:25 +02:00
|
|
|
if( ( (float)pmove->flDuckTime / 1000.0f <= ( 1.0f - TIME_TO_DUCK ) ) || ( pmove->onground == -1 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->usehull = 1;
|
|
|
|
pmove->view_ofs[2] = VEC_DUCK_VIEW;
|
|
|
|
pmove->flags |= FL_DUCKING;
|
|
|
|
pmove->bInDuck = false;
|
|
|
|
|
|
|
|
// HACKHACK - Fudge for collision bug - no time to fix this properly
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->origin[i] -= ( pmove->player_mins[1][i] - pmove->player_mins[0][i] );
|
|
|
|
}
|
|
|
|
// See if we are stuck?
|
|
|
|
PM_FixPlayerCrouchStuck( STUCK_MOVEUP );
|
|
|
|
|
|
|
|
// Recatagorize position since ducking can change origin
|
|
|
|
PM_CatagorizePosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float fMore = VEC_DUCK_HULL_MIN - VEC_HULL_MIN;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Calc parametric time
|
2019-10-13 13:49:25 +02:00
|
|
|
duckFraction = PM_SplineFraction( time, ( 1.0f / TIME_TO_DUCK ) );
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->view_ofs[2] = ( ( VEC_DUCK_VIEW - fMore ) * duckFraction ) + ( VEC_VIEW * ( 1 - duckFraction ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Try to unduck
|
|
|
|
PM_UnDuck();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_LadderMove( physent_t *pLadder )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t ladderCenter;
|
|
|
|
trace_t trace;
|
|
|
|
qboolean onFloor;
|
|
|
|
vec3_t floor;
|
|
|
|
vec3_t modelmins, modelmaxs;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->movetype == MOVETYPE_NOCLIP )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
pmove->PM_GetModelBounds( pLadder->model, modelmins, modelmaxs );
|
|
|
|
|
|
|
|
VectorAdd( modelmins, modelmaxs, ladderCenter );
|
|
|
|
VectorScale( ladderCenter, 0.5, ladderCenter );
|
|
|
|
|
|
|
|
pmove->movetype = MOVETYPE_FLY;
|
|
|
|
|
|
|
|
// On ladder, convert movement to be relative to the ladder
|
|
|
|
VectorCopy( pmove->origin, floor );
|
|
|
|
floor[2] += pmove->player_mins[pmove->usehull][2] - 1;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->PM_PointContents( floor, NULL ) == CONTENTS_SOLID )
|
2016-06-04 15:24:23 +02:00
|
|
|
onFloor = true;
|
|
|
|
else
|
|
|
|
onFloor = false;
|
|
|
|
|
|
|
|
pmove->gravity = 0;
|
2022-07-21 16:23:09 +02:00
|
|
|
PM_TraceModel(pLadder, pmove->origin, ladderCenter, &trace);
|
2019-10-13 13:49:25 +02:00
|
|
|
if( trace.fraction != 1.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
float forward = 0, right = 0;
|
|
|
|
vec3_t vpn, v_right;
|
2017-06-26 02:47:19 +02:00
|
|
|
float flSpeed = MAX_CLIMB_SPEED;
|
|
|
|
|
|
|
|
// they shouldn't be able to move faster than their maxspeed
|
|
|
|
if( flSpeed > pmove->maxspeed )
|
|
|
|
flSpeed = pmove->maxspeed;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
AngleVectors( pmove->angles, vpn, v_right, NULL );
|
2017-06-26 02:47:19 +02:00
|
|
|
|
|
|
|
if( pmove->flags & FL_DUCKING )
|
|
|
|
flSpeed *= PLAYER_DUCKING_MULTIPLIER;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_BACK )
|
2017-06-26 02:47:19 +02:00
|
|
|
forward -= flSpeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_FORWARD )
|
2017-06-26 02:47:19 +02:00
|
|
|
forward += flSpeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_MOVELEFT )
|
2017-06-26 02:47:19 +02:00
|
|
|
right -= flSpeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_MOVERIGHT )
|
2017-06-26 02:47:19 +02:00
|
|
|
right += flSpeed;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_JUMP )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->movetype = MOVETYPE_WALK;
|
|
|
|
VectorScale( trace.plane.normal, 270, pmove->velocity );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( forward != 0 || right != 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
vec3_t velocity, perp, cross, lateral, tmp;
|
|
|
|
float normal;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//ALERT( at_console, "pev %.2f %.2f %.2f - ",
|
|
|
|
// pev->velocity.x, pev->velocity.y, pev->velocity.z );
|
2016-06-04 15:24:23 +02:00
|
|
|
// Calculate player's intended velocity
|
2016-07-31 15:48:50 +02:00
|
|
|
//Vector velocity = ( forward * gpGlobals->v_forward ) + ( right * gpGlobals->v_right );
|
2016-06-04 15:24:23 +02:00
|
|
|
VectorScale( vpn, forward, velocity );
|
|
|
|
VectorMA( velocity, right, v_right, velocity );
|
|
|
|
|
|
|
|
// Perpendicular in the ladder plane
|
2016-07-31 15:48:50 +02:00
|
|
|
// Vector perp = CrossProduct( Vector( 0, 0, 1 ), trace.vecPlaneNormal );
|
|
|
|
// perp = perp.Normalize();
|
2016-06-04 15:24:23 +02:00
|
|
|
VectorClear( tmp );
|
|
|
|
tmp[2] = 1;
|
|
|
|
CrossProduct( tmp, trace.plane.normal, perp );
|
|
|
|
VectorNormalize( perp );
|
|
|
|
|
|
|
|
// decompose velocity into ladder plane
|
|
|
|
normal = DotProduct( velocity, trace.plane.normal );
|
|
|
|
// This is the velocity into the face of the ladder
|
|
|
|
VectorScale( trace.plane.normal, normal, cross );
|
|
|
|
|
|
|
|
// This is the player's additional velocity
|
|
|
|
VectorSubtract( velocity, cross, lateral );
|
|
|
|
|
|
|
|
// This turns the velocity into the face of the ladder into velocity that
|
|
|
|
// is roughly vertically perpendicular to the face of the ladder.
|
|
|
|
// NOTE: It IS possible to face up and move down or face down and move up
|
|
|
|
// because the velocity is a sum of the directional velocity and the converted
|
|
|
|
// velocity through the face of the ladder -- by design.
|
|
|
|
CrossProduct( trace.plane.normal, perp, tmp );
|
|
|
|
VectorMA( lateral, -normal, tmp, pmove->velocity );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( onFloor && normal > 0 ) // On ground moving away from the ladder
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorMA( pmove->velocity, MAX_CLIMB_SPEED, trace.plane.normal, pmove->velocity );
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
//pev->velocity = lateral - ( CrossProduct( trace.vecPlaneNormal, perp ) * normal );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VectorClear( pmove->velocity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
physent_t *PM_Ladder( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int i;
|
|
|
|
physent_t *pe;
|
|
|
|
hull_t *hull;
|
|
|
|
int num;
|
|
|
|
vec3_t test;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < pmove->nummoveent; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pe = &pmove->moveents[i];
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
if( pe->model && (modtype_t)pmove->PM_GetModelType( pe->model ) == mod_brush && pe->skin == CONTENTS_LADDER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
hull = (hull_t *)pmove->PM_HullForBsp( pe, test );
|
|
|
|
num = hull->firstclipnode;
|
|
|
|
|
|
|
|
// Offset the test point appropriately for this hull.
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorSubtract( pmove->origin, test, test );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Test the player's hull for intersection with this model
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->PM_HullPointContents( hull, num, test ) == CONTENTS_EMPTY )
|
2016-06-04 15:24:23 +02:00
|
|
|
continue;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_WaterJump( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime > 10000 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->waterjumptime = 10000;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
pmove->waterjumptime -= pmove->cmd.msec;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime < 0 || !pmove->waterlevel )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->waterjumptime = 0;
|
|
|
|
pmove->flags &= ~FL_WATERJUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmove->velocity[0] = pmove->movedir[0];
|
|
|
|
pmove->velocity[1] = pmove->movedir[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PM_AddGravity
|
|
|
|
|
|
|
|
============
|
|
|
|
*/
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_AddGravity( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float ent_gravity;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->gravity )
|
2016-06-04 15:24:23 +02:00
|
|
|
ent_gravity = pmove->gravity;
|
|
|
|
else
|
2019-10-13 13:49:25 +02:00
|
|
|
ent_gravity = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Add gravity incorrectly
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->velocity[2] -= ( ent_gravity * pmove->movevars->gravity * pmove->frametime );
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[2] += pmove->basevelocity[2] * pmove->frametime;
|
|
|
|
pmove->basevelocity[2] = 0;
|
|
|
|
PM_CheckVelocity();
|
|
|
|
}
|
2017-06-29 15:56:03 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
/*
|
|
|
|
============
|
|
|
|
PM_PushEntity
|
|
|
|
|
|
|
|
Does not change the entities velocity at all
|
|
|
|
============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
pmtrace_t PM_PushEntity( vec3_t push )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmtrace_t trace;
|
|
|
|
vec3_t end;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( pmove->origin, push, end );
|
|
|
|
|
|
|
|
trace = pmove->PM_PlayerTrace( pmove->origin, end, PM_NORMAL, -1 );
|
|
|
|
|
|
|
|
VectorCopy( trace.endpos, pmove->origin );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// So we can run impact function afterwards.
|
2019-10-13 13:49:25 +02:00
|
|
|
if( trace.fraction < 1.0f && !trace.allsolid )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_AddToTouched( trace, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PM_Physics_Toss()
|
|
|
|
|
|
|
|
Dead player flying through air., e.g.
|
|
|
|
============
|
|
|
|
*/
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_Physics_Toss( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmtrace_t trace;
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t move;
|
|
|
|
float backoff;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PM_CheckWater();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->velocity[2] > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->onground = -1;
|
|
|
|
|
|
|
|
// If on ground and not moving, return.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( VectorCompare( pmove->basevelocity, vec3_origin ) && VectorCompare( pmove->velocity, vec3_origin ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_CheckVelocity();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// add gravity
|
|
|
|
if( pmove->movetype != MOVETYPE_FLY && pmove->movetype != MOVETYPE_BOUNCEMISSILE && pmove->movetype != MOVETYPE_FLYMISSILE )
|
2016-06-04 15:24:23 +02:00
|
|
|
PM_AddGravity ();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// move origin
|
2016-06-04 15:24:23 +02:00
|
|
|
// Base velocity is not properly accounted for since this entity will move again after the bounce without
|
|
|
|
// taking it into account
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
PM_CheckVelocity();
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( pmove->velocity, pmove->frametime, move );
|
|
|
|
VectorSubtract( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
trace = PM_PushEntity( move ); // Should this clear basevelocity
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PM_CheckVelocity();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( trace.allsolid )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// entity is trapped in another solid
|
|
|
|
pmove->onground = trace.ent;
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( trace.fraction == 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_CheckWater();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->movetype == MOVETYPE_BOUNCE )
|
2019-10-13 13:49:25 +02:00
|
|
|
backoff = 2.0f - pmove->friction;
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->movetype == MOVETYPE_BOUNCEMISSILE )
|
2019-10-13 13:49:25 +02:00
|
|
|
backoff = 2.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
else
|
2019-10-13 13:49:25 +02:00
|
|
|
backoff = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_ClipVelocity( pmove->velocity, trace.plane.normal, pmove->velocity, backoff );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// stop if on ground
|
2019-10-13 13:49:25 +02:00
|
|
|
if( trace.plane.normal[2] > 0.7f )
|
2016-07-31 15:48:50 +02:00
|
|
|
{
|
2016-06-04 15:24:23 +02:00
|
|
|
float vel;
|
|
|
|
vec3_t base;
|
|
|
|
|
|
|
|
VectorClear( base );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->velocity[2] < pmove->movevars->gravity * pmove->frametime )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// we're rolling on the ground, add static friction.
|
|
|
|
pmove->onground = trace.ent;
|
|
|
|
pmove->velocity[2] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vel = DotProduct( pmove->velocity, pmove->velocity );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
// Con_DPrintf( "%f %f: %.0f %.0f %.0f\n", vel, trace.fraction, ent->velocity[0], ent->velocity[1], ent->velocity[2] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( vel < ( 30 * 30 ) || ( pmove->movetype != MOVETYPE_BOUNCE && pmove->movetype != MOVETYPE_BOUNCEMISSILE ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->onground = trace.ent;
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( vec3_origin, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
VectorScale( pmove->velocity, ( 1.0f - trace.fraction) * pmove->frametime * 0.9f, move );
|
2016-07-31 15:48:50 +02:00
|
|
|
trace = PM_PushEntity( move );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
VectorSubtract( pmove->velocity, base, pmove->velocity )
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
// check for in water
|
2016-06-04 15:24:23 +02:00
|
|
|
PM_CheckWater();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
PM_NoClip
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
2024-02-18 21:46:19 +01:00
|
|
|
void PM_NoClip( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int i;
|
|
|
|
vec3_t wishvel;
|
|
|
|
float fmove, smove;
|
|
|
|
//float currentspeed, addspeed, accelspeed;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Copy movement amounts
|
|
|
|
fmove = pmove->cmd.forwardmove;
|
|
|
|
smove = pmove->cmd.sidemove;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorNormalize( pmove->forward );
|
|
|
|
VectorNormalize( pmove->right );
|
|
|
|
|
|
|
|
for( i = 0; i < 3; i++ ) // Determine x and y parts of velocity
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
wishvel[2] += pmove->cmd.upmove;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorMA (pmove->origin, pmove->frametime, wishvel, pmove->origin );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Zero out the velocity so that we don't accumulate a huge downward velocity from
|
2016-07-31 15:48:50 +02:00
|
|
|
// gravity, etc.
|
2016-06-04 15:24:23 +02:00
|
|
|
VectorClear( pmove->velocity );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only allow bunny jumping up to 1.7x server / player maxspeed setting
|
|
|
|
#define BUNNYJUMP_MAX_SPEED_FACTOR 1.7f
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Corrects bunny jumping ( where player initiates a bunny jump before other
|
|
|
|
// movement logic runs, thus making onground == -1 thus making PM_Friction get skipped and
|
|
|
|
// running PM_AirMove, which doesn't crop velocity to maxspeed like the ground / other
|
|
|
|
// movement logic does.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void PM_PreventMegaBunnyJumping( void )
|
|
|
|
{
|
|
|
|
// Current player speed
|
|
|
|
float spd;
|
|
|
|
// If we have to crop, apply this cropping fraction to velocity
|
|
|
|
float fraction;
|
|
|
|
// Speed at which bunny jumping is limited
|
|
|
|
float maxscaledspeed;
|
|
|
|
|
|
|
|
maxscaledspeed = BUNNYJUMP_MAX_SPEED_FACTOR * pmove->maxspeed;
|
|
|
|
|
|
|
|
// Don't divide by zero
|
2016-07-31 15:48:50 +02:00
|
|
|
if( maxscaledspeed <= 0.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
spd = Length( pmove->velocity );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( spd <= maxscaledspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
fraction = ( maxscaledspeed / spd ) * 0.65f; //Returns the modifier for the velocity
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
VectorScale( pmove->velocity, fraction, pmove->velocity ); //Crop it down!.
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
PM_Jump
|
|
|
|
=============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_Jump( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
int i;
|
2023-04-09 23:25:44 +02:00
|
|
|
qboolean bunnyjump = false;
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
qboolean tfc = false;
|
|
|
|
|
|
|
|
qboolean cansuperjump = false;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->dead )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->oldbuttons |= IN_JUMP; // don't jump again until released
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tfc = atoi( pmove->PM_Info_ValueForKey( pmove->physinfo, "tfc" ) ) == 1 ? true : false;
|
|
|
|
|
|
|
|
// Spy that's feigning death cannot jump
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tfc && ( pmove->deadflag == ( DEAD_DISCARDBODY + 1 ) ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we are waterjumping. If so, decrement count and return.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->waterjumptime -= pmove->cmd.msec;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->waterjumptime = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are in the water most of the way...
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterlevel >= 2 )
|
|
|
|
{
|
|
|
|
// swimming, not jumping
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->onground = -1;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->watertype == CONTENTS_WATER ) // We move up a certain amount
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[2] = 100;
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->watertype == CONTENTS_SLIME )
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[2] = 80;
|
2016-07-31 15:48:50 +02:00
|
|
|
else // LAVA
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->velocity[2] = 50;
|
|
|
|
|
|
|
|
// play swiming sound
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flSwimTime <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Don't play sound again for 1 second
|
|
|
|
pmove->flSwimTime = 1000;
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( pmove->RandomLong( 0, 3 ) )
|
|
|
|
{
|
2016-06-04 15:24:23 +02:00
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade1.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade2.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade3.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade4.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No more effect
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Flag that we jumped.
|
|
|
|
// HACK HACK HACK
|
|
|
|
// Remove this when the game .dll no longer does physics code!!!!
|
|
|
|
pmove->oldbuttons |= IN_JUMP; // don't jump again until released
|
|
|
|
return; // in air, so no effect
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->oldbuttons & IN_JUMP )
|
2016-06-04 15:24:23 +02:00
|
|
|
return; // don't pogo stick
|
|
|
|
|
|
|
|
// In the air now.
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->onground = -1;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2023-04-09 23:25:44 +02:00
|
|
|
if( pmove->multiplayer )
|
|
|
|
bunnyjump = atoi( pmove->PM_Info_ValueForKey( pmove->physinfo, "bj" ) ) ? true : false;
|
|
|
|
|
|
|
|
if( !bunnyjump )
|
2017-07-05 20:50:55 +02:00
|
|
|
PM_PreventMegaBunnyJumping();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2024-02-18 22:23:22 +01:00
|
|
|
// Don't play jump sounds while frozen.
|
|
|
|
if( !( pmove->flags & FL_FROZEN ))
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2024-02-18 22:23:22 +01:00
|
|
|
if( tfc )
|
|
|
|
{
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/plyrjmp8.wav", 0.5, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PM_PlayStepSound( PM_MapTextureTypeStepType( pmove->chtexturetype ), 1.0f );
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if user can super long jump?
|
|
|
|
cansuperjump = atoi( pmove->PM_Info_ValueForKey( pmove->physinfo, "slj" ) ) == 1 ? true : false;
|
|
|
|
|
|
|
|
// Acclerate upward
|
|
|
|
// If we are ducking...
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( pmove->bInDuck ) || ( pmove->flags & FL_DUCKING ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Adjust for super long jump module
|
|
|
|
// UNDONE -- note this should be based on forward angles, not current velocity.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( cansuperjump && ( pmove->cmd.buttons & IN_DUCK ) && ( pmove->flDuckTime > 0 ) &&
|
2016-06-04 15:24:23 +02:00
|
|
|
Length( pmove->velocity ) > 50 )
|
|
|
|
{
|
|
|
|
pmove->punchangle[0] = -5;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 2; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->velocity[i] = pmove->forward[i] * PLAYER_LONGJUMP_SPEED * 1.6f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->velocity[2] = sqrt( 2.0f * 800.0f * 56.0f );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->velocity[2] = sqrt( 2.0f * 800.0f * 45.0f );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->velocity[2] = sqrt( 2.0f * 800.0f * 45.0f );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decay it for simulation
|
|
|
|
PM_FixupGravityVelocity();
|
|
|
|
|
|
|
|
// Flag that we jumped.
|
|
|
|
pmove->oldbuttons |= IN_JUMP; // don't jump again until released
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
PM_CheckWaterJump
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
#define WJ_HEIGHT 8
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_CheckWaterJump( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t vecStart, vecEnd;
|
|
|
|
vec3_t flatforward;
|
|
|
|
vec3_t flatvelocity;
|
2016-06-04 15:24:23 +02:00
|
|
|
float curspeed;
|
|
|
|
pmtrace_t tr;
|
2016-07-31 15:48:50 +02:00
|
|
|
int savehull;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Already water jumping.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't hop out if we just jumped in
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->velocity[2] < -180 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return; // only hop out if we are moving up
|
|
|
|
|
|
|
|
// See if we are backing up
|
|
|
|
flatvelocity[0] = pmove->velocity[0];
|
|
|
|
flatvelocity[1] = pmove->velocity[1];
|
|
|
|
flatvelocity[2] = 0;
|
|
|
|
|
|
|
|
// Must be moving
|
|
|
|
curspeed = VectorNormalize( flatvelocity );
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// see if near an edge
|
|
|
|
flatforward[0] = pmove->forward[0];
|
|
|
|
flatforward[1] = pmove->forward[1];
|
|
|
|
flatforward[2] = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorNormalize( flatforward );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Are we backing into water from steps or something? If so, don't pop forward
|
2019-10-13 13:49:25 +02:00
|
|
|
if( curspeed != 0.0f && ( DotProduct( flatvelocity, flatforward ) < 0.0f ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
VectorCopy( pmove->origin, vecStart );
|
|
|
|
vecStart[2] += WJ_HEIGHT;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorMA( vecStart, 24, flatforward, vecEnd );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Trace, this trace should use the point sized collision hull
|
|
|
|
savehull = pmove->usehull;
|
|
|
|
pmove->usehull = 2;
|
|
|
|
tr = pmove->PM_PlayerTrace( vecStart, vecEnd, PM_NORMAL, -1 );
|
2019-10-13 13:49:25 +02:00
|
|
|
if( tr.fraction < 1.0f && fabs( tr.plane.normal[2] ) < 0.1f ) // Facing a near vertical wall?
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vecStart[2] += pmove->player_maxs[savehull][2] - WJ_HEIGHT;
|
2016-06-04 15:24:23 +02:00
|
|
|
VectorMA( vecStart, 24, flatforward, vecEnd );
|
|
|
|
VectorMA( vec3_origin, -50, tr.plane.normal, pmove->movedir );
|
|
|
|
|
|
|
|
tr = pmove->PM_PlayerTrace( vecStart, vecEnd, PM_NORMAL, -1 );
|
2019-10-13 13:49:25 +02:00
|
|
|
if( tr.fraction == 1.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->waterjumptime = 2000;
|
|
|
|
pmove->velocity[2] = 225;
|
|
|
|
pmove->oldbuttons |= IN_JUMP;
|
|
|
|
pmove->flags |= FL_WATERJUMP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the collision hull
|
|
|
|
pmove->usehull = savehull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_CheckFalling( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 && !pmove->dead && pmove->flFallVelocity >= PLAYER_FALL_PUNCH_THRESHHOLD )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
float fvol = 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterlevel > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->flFallVelocity > PLAYER_MAX_SAFE_FALL_SPEED )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
// NOTE: In the original game dll, there were no breaks after these cases, causing the first one to
|
2016-06-04 15:24:23 +02:00
|
|
|
// cascade into the second
|
2016-07-31 15:48:50 +02:00
|
|
|
//switch( RandomLong( 0, 1 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
//{
|
|
|
|
//case 0:
|
|
|
|
//pmove->PM_PlaySound( CHAN_VOICE, "player/pl_fallpain2.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
//break;
|
|
|
|
//case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_VOICE, "player/pl_fallpain3.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
// break;
|
|
|
|
//}
|
2019-10-13 13:49:25 +02:00
|
|
|
fvol = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->flFallVelocity > PLAYER_MAX_SAFE_FALL_SPEED / 2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
qboolean tfc = false;
|
|
|
|
tfc = atoi( pmove->PM_Info_ValueForKey( pmove->physinfo, "tfc" ) ) == 1 ? true : false;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tfc )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->PM_PlaySound( CHAN_VOICE, "player/pl_fallpain3.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
}
|
|
|
|
|
|
|
|
fvol = 0.85;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->flFallVelocity < PLAYER_MIN_BOUNCE_SPEED )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
fvol = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( fvol > 0.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Play landing step right away
|
|
|
|
pmove->flTimeStepSound = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
PM_UpdateStepSound();
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// play step sound for current texture
|
|
|
|
PM_PlayStepSound( PM_MapTextureTypeStepType( pmove->chtexturetype ), fvol );
|
|
|
|
|
|
|
|
// Knock the screen around a little bit, temporary effect
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->punchangle[2] = pmove->flFallVelocity * 0.013f; // punch z axis
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->punchangle[0] > 8 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->punchangle[0] = 8;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
|
|
|
{
|
2016-06-04 15:24:23 +02:00
|
|
|
pmove->flFallVelocity = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
PM_PlayWaterSounds
|
|
|
|
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void PM_PlayWaterSounds( void )
|
|
|
|
{
|
|
|
|
// Did we enter or leave water?
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( pmove->oldwaterlevel == 0 && pmove->waterlevel != 0 ) || ( pmove->oldwaterlevel != 0 && pmove->waterlevel == 0 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( pmove->RandomLong( 0, 3 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade1.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade2.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade3.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pmove->PM_PlaySound( CHAN_BODY, "player/pl_wade4.wav", 1, ATTN_NORM, 0, PITCH_NORM );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
PM_CalcRoll
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
float PM_CalcRoll( vec3_t angles, vec3_t velocity, float rollangle, float rollspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float sign;
|
|
|
|
float side;
|
|
|
|
float value;
|
|
|
|
vec3_t forward, right, up;
|
|
|
|
|
|
|
|
AngleVectors( angles, forward, right, up );
|
|
|
|
|
|
|
|
side = DotProduct( velocity, right );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
sign = side < 0 ? -1 : 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
side = fabs( side );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
value = rollangle;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
if( side < rollspeed )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
side = side * value / rollspeed;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
side = value;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
return side * sign;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
PM_DropPunchAngle
|
|
|
|
|
|
|
|
=============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_DropPunchAngle( vec3_t punchangle )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
float len;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
len = VectorNormalize( punchangle );
|
2019-10-13 13:49:25 +02:00
|
|
|
len -= ( 10.0f + len * 0.5f ) * pmove->frametime;
|
|
|
|
len = max( len, 0.0f );
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorScale( punchangle, len, punchangle );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
PM_CheckParamters
|
|
|
|
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void PM_CheckParamters( void )
|
|
|
|
{
|
|
|
|
float spd;
|
|
|
|
float maxspeed;
|
2016-07-31 15:48:50 +02:00
|
|
|
vec3_t v_angle;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
spd = ( pmove->cmd.forwardmove * pmove->cmd.forwardmove ) + ( pmove->cmd.sidemove * pmove->cmd.sidemove ) +
|
|
|
|
( pmove->cmd.upmove * pmove->cmd.upmove );
|
2016-06-04 15:24:23 +02:00
|
|
|
spd = sqrt( spd );
|
|
|
|
|
|
|
|
maxspeed = pmove->clientmaxspeed; //atof( pmove->PM_Info_ValueForKey( pmove->physinfo, "maxspd" ) );
|
2019-10-13 13:49:25 +02:00
|
|
|
if( maxspeed != 0.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->maxspeed = min( maxspeed, pmove->maxspeed );
|
|
|
|
}
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( ( spd != 0.0f ) && ( spd > pmove->maxspeed ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
float fRatio = pmove->maxspeed / spd;
|
|
|
|
pmove->cmd.forwardmove *= fRatio;
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->cmd.sidemove *= fRatio;
|
|
|
|
pmove->cmd.upmove *= fRatio;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flags & FL_FROZEN || pmove->flags & FL_ONTRAIN || pmove->dead )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->cmd.forwardmove = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->cmd.sidemove = 0;
|
|
|
|
pmove->cmd.upmove = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PM_DropPunchAngle( pmove->punchangle );
|
|
|
|
|
|
|
|
// Take angles from command.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->dead )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorCopy( pmove->cmd.viewangles, v_angle );
|
2016-06-04 15:24:23 +02:00
|
|
|
VectorAdd( v_angle, pmove->punchangle, v_angle );
|
|
|
|
|
|
|
|
// Set up view angles.
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->angles[ROLL] = PM_CalcRoll( v_angle, pmove->velocity, pmove->movevars->rollangle, pmove->movevars->rollspeed ) * 4;
|
|
|
|
pmove->angles[PITCH] = v_angle[PITCH];
|
|
|
|
pmove->angles[YAW] = v_angle[YAW];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VectorCopy( pmove->oldangles, pmove->angles );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set dead player view_offset
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->dead )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->view_ofs[2] = PM_DEAD_VIEWHEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust client view angles to match values used on server.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->angles[YAW] > 180.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->angles[YAW] -= 360.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_ReduceTimers( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flTimeStepSound > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flTimeStepSound -= pmove->cmd.msec;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flTimeStepSound < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flTimeStepSound = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flDuckTime > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flDuckTime -= pmove->cmd.msec;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flDuckTime < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flDuckTime = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flSwimTime > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flSwimTime -= pmove->cmd.msec;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->flSwimTime < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flSwimTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
PlayerMove
|
|
|
|
|
|
|
|
Returns with origin, angles, and velocity modified in place.
|
|
|
|
|
|
|
|
Numtouch and touchindex[] will be set if any of the physents
|
|
|
|
were contacted during the move.
|
|
|
|
=============
|
|
|
|
*/
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_PlayerMove( qboolean server )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
physent_t *pLadder = NULL;
|
|
|
|
|
|
|
|
// Are we running server code?
|
|
|
|
pmove->server = server;
|
|
|
|
|
|
|
|
// Adjust speeds etc.
|
|
|
|
PM_CheckParamters();
|
|
|
|
|
|
|
|
// Assume we don't touch anything
|
|
|
|
pmove->numtouch = 0;
|
|
|
|
|
|
|
|
// # of msec to apply movement
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->frametime = pmove->cmd.msec * 0.001f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PM_ReduceTimers();
|
|
|
|
|
|
|
|
// Convert view angles to vectors
|
2016-07-31 15:48:50 +02:00
|
|
|
AngleVectors( pmove->angles, pmove->forward, pmove->right, pmove->up );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// PM_ShowClipBox();
|
|
|
|
|
|
|
|
// Special handling for spectator and observers. (iuser1 is set if the player's in observer mode)
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->spectator || pmove->iuser1 > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_SpectatorMove();
|
|
|
|
PM_CatagorizePosition();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always try and unstick us unless we are in NOCLIP mode
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->movetype != MOVETYPE_NOCLIP && pmove->movetype != MOVETYPE_NONE )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( PM_CheckStuck() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return; // Can't move, we're stuck
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we are "unstuck", see where we are ( waterlevel and type, pmove->onground ).
|
|
|
|
PM_CatagorizePosition();
|
|
|
|
|
|
|
|
// Store off the starting water level
|
|
|
|
pmove->oldwaterlevel = pmove->waterlevel;
|
|
|
|
|
|
|
|
// If we are not on ground, store off how fast we are moving down
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flFallVelocity = -pmove->velocity[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
g_onladder = 0;
|
|
|
|
// Don't run ladder code if dead or on a train
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->dead && !( pmove->flags & FL_ONTRAIN ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pLadder = PM_Ladder();
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pLadder )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
g_onladder = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PM_UpdateStepSound();
|
|
|
|
|
|
|
|
PM_Duck();
|
|
|
|
|
|
|
|
// Don't run ladder code if dead or on a train
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pmove->dead && !( pmove->flags & FL_ONTRAIN ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pLadder )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_LadderMove( pLadder );
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pmove->movetype != MOVETYPE_WALK && pmove->movetype != MOVETYPE_NOCLIP )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Clear ladder stuff unless player is noclipping
|
|
|
|
// it will be set immediately again next frame if necessary
|
|
|
|
pmove->movetype = MOVETYPE_WALK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow down, I'm pulling it! (a box maybe) but only when I'm standing on ground
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( pmove->onground != -1 ) && ( pmove->cmd.buttons & IN_USE ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorScale( pmove->velocity, 0.3, pmove->velocity );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle movement
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( pmove->movetype )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
default:
|
2016-07-31 15:48:50 +02:00
|
|
|
pmove->Con_DPrintf( "Bogus pmove player movetype %i on (%i) 0=cl 1=sv\n", pmove->movetype, pmove->server );
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
case MOVETYPE_NONE:
|
|
|
|
break;
|
|
|
|
case MOVETYPE_NOCLIP:
|
|
|
|
PM_NoClip();
|
|
|
|
break;
|
|
|
|
case MOVETYPE_TOSS:
|
|
|
|
case MOVETYPE_BOUNCE:
|
|
|
|
PM_Physics_Toss();
|
|
|
|
break;
|
|
|
|
case MOVETYPE_FLY:
|
|
|
|
PM_CheckWater();
|
|
|
|
|
|
|
|
// Was jump button pressed?
|
|
|
|
// If so, set velocity to 270 away from ladder. This is currently wrong.
|
|
|
|
// Also, set MOVE_TYPE to walk, too.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_JUMP )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pLadder )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_Jump();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pmove->oldbuttons &= ~IN_JUMP;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Perform the move accounting for any base velocity.
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorAdd( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
|
|
|
PM_FlyMove();
|
|
|
|
VectorSubtract( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
case MOVETYPE_WALK:
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !PM_InWater() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_AddCorrectGravity();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are leaping out of the water, just update the counters.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_WaterJump();
|
|
|
|
PM_FlyMove();
|
|
|
|
|
|
|
|
// Make sure waterlevel is set correctly
|
|
|
|
PM_CheckWater();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are swimming in the water, see if we are nudging against a place we can jump up out
|
|
|
|
// of, and, if so, start out jump. Otherwise, if we are not moving up, then reset jump timer to 0
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterlevel >= 2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->waterlevel == 2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_CheckWaterJump();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are falling again, then we must not trying to jump out of water any more.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->velocity[2] < 0 && pmove->waterjumptime )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->waterjumptime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Was jump button pressed?
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_JUMP )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_Jump();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pmove->oldbuttons &= ~IN_JUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform regular water movement
|
|
|
|
PM_WaterMove();
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
VectorSubtract( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Get a final position
|
|
|
|
PM_CatagorizePosition();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// Not underwater
|
|
|
|
{
|
|
|
|
// Was jump button pressed?
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->cmd.buttons & IN_JUMP )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pLadder )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PM_Jump();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pmove->oldbuttons &= ~IN_JUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fricion is handled before we add in any base velocity. That way, if we are on a conveyor,
|
|
|
|
// we don't slow when standing still, relative to the conveyor.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pmove->velocity[2] = 0.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
PM_Friction();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure velocity is valid.
|
|
|
|
PM_CheckVelocity();
|
|
|
|
|
|
|
|
// Are we on ground now
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_WalkMove();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PM_AirMove(); // Take into account movement when in air.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set final flags.
|
|
|
|
PM_CatagorizePosition();
|
|
|
|
|
|
|
|
// Now pull the base velocity back out.
|
|
|
|
// Base velocity is set if you are on a moving object, like
|
|
|
|
// a conveyor (or maybe another monster?)
|
2016-07-31 15:48:50 +02:00
|
|
|
VectorSubtract( pmove->velocity, pmove->basevelocity, pmove->velocity );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Make sure velocity is valid.
|
|
|
|
PM_CheckVelocity();
|
|
|
|
|
|
|
|
// Add any remaining gravitational component.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !PM_InWater() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
PM_FixupGravityVelocity();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are on ground, no downward velocity.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->velocity[2] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we landed on the ground with enough force to play
|
|
|
|
// a landing sound.
|
|
|
|
PM_CheckFalling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Did we enter or leave the water?
|
|
|
|
PM_PlayWaterSounds();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_CreateStuckTable( void )
|
|
|
|
{
|
|
|
|
float x, y, z;
|
|
|
|
int idx;
|
|
|
|
int i;
|
|
|
|
float zi[3];
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
memset( rgv3tStuckTable, 0, 54 * sizeof(vec3_t) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
// Little Moves.
|
|
|
|
x = y = 0;
|
|
|
|
// Z moves
|
2019-10-13 13:49:25 +02:00
|
|
|
for( z = -0.125f; z <= 0.125f; z += 0.125f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
x = z = 0;
|
|
|
|
// Y moves
|
2019-10-13 13:49:25 +02:00
|
|
|
for( y = -0.125f; y <= 0.125f; y += 0.125f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
y = z = 0;
|
|
|
|
// X moves
|
2019-10-13 13:49:25 +02:00
|
|
|
for( x = -0.125f; x <= 0.125f; x += 0.125f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remaining multi axis nudges.
|
2019-10-13 13:49:25 +02:00
|
|
|
for( x = - 0.125f; x <= 0.125f; x += 0.250f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
for( y = - 0.125f; y <= 0.125f; y += 0.250f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
for( z = - 0.125f; z <= 0.125f; z += 0.250f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Big Moves.
|
|
|
|
x = y = 0;
|
|
|
|
zi[0] = 0.0f;
|
|
|
|
zi[1] = 1.0f;
|
|
|
|
zi[2] = 6.0f;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Z moves
|
|
|
|
z = zi[i];
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = z = 0;
|
|
|
|
|
|
|
|
// Y moves
|
2019-10-13 13:49:25 +02:00
|
|
|
for( y = -2.0f; y <= 2.0f; y += 2.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
y = z = 0;
|
|
|
|
// X moves
|
2019-10-13 13:49:25 +02:00
|
|
|
for( x = -2.0f; x <= 2.0f; x += 2.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remaining multi axis nudges.
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0 ; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
z = zi[i];
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
for( x = -2.0f; x <= 2.0f; x += 2.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
for( y = -2.0f; y <= 2.0f; y += 2.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
rgv3tStuckTable[idx][0] = x;
|
|
|
|
rgv3tStuckTable[idx][1] = y;
|
|
|
|
rgv3tStuckTable[idx][2] = z;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This modume implements the shared player physics code between any particular game and
|
|
|
|
the engine. The same PM_Move routine is built into the game .dll and the client .dll and is
|
|
|
|
invoked by each side as appropriate. There should be no distinction, internally, between server
|
|
|
|
and client. This will ensure that prediction behaves appropriately.
|
|
|
|
*/
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void PM_Move( struct playermove_s *ppmove, int server )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
assert( pm_shared_initialized );
|
|
|
|
|
|
|
|
pmove = ppmove;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
//pmove->Con_Printf( "PM_Move: %g, frametime %g, onground %i\n", pmove->time, pmove->frametime, pmove->onground );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
PM_PlayerMove( ( server != 0 ) ? true : false );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pmove->onground != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->flags |= FL_ONGROUND;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pmove->flags &= ~FL_ONGROUND;
|
|
|
|
}
|
|
|
|
|
2018-02-15 13:52:07 +01:00
|
|
|
// Reset friction after each movement to FrictionModifier Triggers work still.
|
2023-04-09 22:53:41 +02:00
|
|
|
// Use movevar to avoid lags with different clients and servers.
|
|
|
|
if( !( pmove->multiplayer && atoi( pmove->PM_Info_ValueForKey( pmove->physinfo, "fr" )) == 0 ) && pmove->movetype == MOVETYPE_WALK )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pmove->friction = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PM_GetVisEntInfo( int ent )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ent >= 0 && ent <= pmove->numvisent )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
return pmove->visents[ent].info;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PM_GetPhysEntInfo( int ent )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ent >= 0 && ent <= pmove->numphysent )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
return pmove->physents[ent].info;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PM_Init( struct playermove_s *ppmove )
|
|
|
|
{
|
|
|
|
assert( !pm_shared_initialized );
|
|
|
|
|
|
|
|
pmove = ppmove;
|
|
|
|
|
|
|
|
PM_CreateStuckTable();
|
|
|
|
PM_InitTextureTypes();
|
|
|
|
|
|
|
|
pm_shared_initialized = 1;
|
|
|
|
}
|